Skip to content

Commit

Permalink
Fix that changing a store should mark the store attribute as changed
Browse files Browse the repository at this point in the history
  • Loading branch information
dhh committed Oct 25, 2011
1 parent 85b64f9 commit 5daf077
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions activerecord/lib/active_record/store.rb
Expand Up @@ -37,6 +37,7 @@ def store_accessor(store_attribute, *keys)
Array(keys).flatten.each do |key|
define_method("#{key}=") do |value|
send(store_attribute)[key] = value
send("#{store_attribute}_will_change!")
end

define_method(key) do
Expand Down
5 changes: 5 additions & 0 deletions activerecord/test/cases/store_test.rb
Expand Up @@ -26,4 +26,9 @@ class StoreTest < ActiveRecord::TestCase

assert 'graeters', @john.reload.settings[:icecream]
end

test "updating the store will mark it as changed" do
@john.color = 'red'
assert @john.settings_changed?
end
end

2 comments on commit 5daf077

@gamov
Copy link

@gamov gamov commented on 5daf077 Oct 25, 2012

Choose a reason for hiding this comment

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

Shouldn't we check if store_attribute[key] != value before triggering "#{store_attribute}_will_change! ?

@Crunch09
Copy link
Contributor

Choose a reason for hiding this comment

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

Please sign in to comment.