Skip to content

Commit

Permalink
Make AR::Base#changed_attributes to return indifferent hash
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdan committed May 13, 2013
1 parent b44f086 commit 064b0d4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion activemodel/lib/active_model/dirty.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def previous_changes
# person.name = 'robert'
# person.changed_attributes # => {"name" => "bob"}
def changed_attributes
@changed_attributes ||= {}
@changed_attributes ||= HashWithIndifferentAccess.new
end

private
Expand Down
6 changes: 6 additions & 0 deletions activemodel/test/cases/dirty_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,10 @@ def save
assert_equal ["Otto", "Mr. Manfredgensonton"], @model.name_change
assert_equal @model.name_was, "Otto"
end

test "changed_attributes" do
@model.name = "Otto"
assert_equal nil, @model.changed_attributes["name"]
assert_equal nil, @model.changed_attributes[:name]
end
end

1 comment on commit 064b0d4

@aditya-kapoor
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is required to return HashWithIndifferentAccess instead of just plain regular Hash???
I mean what value does it bring in to the code???

Please sign in to comment.