From 04f97f03f6158eba6ca29bedbe916a79e280f9dd Mon Sep 17 00:00:00 2001 From: Dan Pickett Date: Sat, 8 Aug 2009 16:28:47 -0400 Subject: [PATCH] stringify keys for active resource --- activeresource/lib/active_resource/base.rb | 8 +++++++- activeresource/test/base_test.rb | 8 ++++++++ 2 files changed, 15 insertions(+), 1 deletions(-) diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index 4a4ee9f..a56a290 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -635,7 +635,13 @@ module ActiveResource end end - attr_accessor :attributes #:nodoc: + attr_reader :attributes #:nodoc: + def attributes=(new_attributes) + return if new_attributes.nil? + @attributes = new_attributes.dup + @attributes.stringify_keys! + end + attr_accessor :prefix_options #:nodoc: # Constructor method for \new resources; the optional +attributes+ parameter takes a \hash diff --git a/activeresource/test/base_test.rb b/activeresource/test/base_test.rb index 6ed6f1a..2f740b3 100644 --- a/activeresource/test/base_test.rb +++ b/activeresource/test/base_test.rb @@ -888,4 +888,12 @@ class BaseTest < Test::Unit::TestCase end end end + + def test_should_stringify_keys_when_attrs_are_mass_assigned + @person = Person.new(:age => 14) + + @person.attributes.keys.each do |key| + assert key.is_a?(String) + end + end end -- 1.5.6.1