diff options
-rw-r--r-- | activerecord/CHANGELOG.md | 5 | ||||
-rw-r--r-- | activerecord/lib/active_record/store.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/store_test.rb | 7 |
3 files changed, 13 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 581391a84c..0e8fe55e84 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -111,6 +111,11 @@ *kennyj* +* Fix `ActiveRecord::Store` incorrectly tracking changes of its attributes. + Fixes #10373. + + *Janko Marohnić* + ## Rails 3.2.13 (Mar 18, 2013) ## diff --git a/activerecord/lib/active_record/store.rb b/activerecord/lib/active_record/store.rb index 49d01de365..bacb78e2e1 100644 --- a/activerecord/lib/active_record/store.rb +++ b/activerecord/lib/active_record/store.rb @@ -37,8 +37,8 @@ module ActiveRecord Array(keys).flatten.each do |key| define_method("#{key}=") do |value| send("#{store_attribute}=", {}) unless send(store_attribute).is_a?(Hash) - send(store_attribute)[key] = value send("#{store_attribute}_will_change!") + send(store_attribute)[key] = value end define_method(key) do diff --git a/activerecord/test/cases/store_test.rb b/activerecord/test/cases/store_test.rb index 277fc9d676..bbcbeac959 100644 --- a/activerecord/test/cases/store_test.rb +++ b/activerecord/test/cases/store_test.rb @@ -40,4 +40,11 @@ class StoreTest < ActiveRecord::TestCase @john.remember_login = false assert_equal false, @john.remember_login end + + test "updating the store will track changes correctly" do + @john.color = "blue" + assert_equal [{:color => "black"}, {:color => "blue"}], @john.settings_change + @john.homepage = "37signals.com" + assert_equal [{:color => "black"}, {:color => "blue", :homepage => "37signals.com"}], @john.settings_change + end end |