Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

ActiveModel::Dirty#changes should return a HashWithIndifferentAccess [#…

…4157 state:resolved]

Keep the Rails style of inject

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
commit a5d637d86c02d911b07d48bdbfbc4f23fb59d720 1 parent 140cc9c
@jacobat jacobat authored josevalim committed
View
2  activemodel/lib/active_model/dirty.rb
@@ -107,7 +107,7 @@ def changed
# person.name = 'bob'
# person.changes # => { 'name' => ['bill', 'bob'] }
def changes
- changed.inject({}) { |h, attr| h[attr] = attribute_change(attr); h }
+ changed.inject(HashWithIndifferentAccess.new){ |h, attr| h[attr] = attribute_change(attr); h }
end
# Map of attributes that were changed when the model was saved.
View
29 activemodel/test/cases/dirty_test.rb
@@ -0,0 +1,29 @@
+require "cases/helper"
+
+class DirtyTest < ActiveModel::TestCase
+ class DirtyModel
+ include ActiveModel::Dirty
+ define_attribute_methods [:name]
+
+ def initialize
+ @name = nil
+ end
+
+ def name
+ @name
+ end
+
+ def name=(val)
+ name_will_change!
+ @name = val
+ end
+ end
+
+ test "changes accessible through both strings and symbols" do
+ model = DirtyModel.new
+ model.name = "David"
+ assert !model.changes[:name].nil?
+ assert !model.changes['name'].nil?
+ end
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.