diff options
author | Janko Marohnić <janko.marohnic@gmail.com> | 2013-04-29 20:39:18 +0200 |
---|---|---|
committer | Janko Marohnić <janko.marohnic@gmail.com> | 2013-04-29 20:39:52 +0200 |
commit | 5519468523b2017df7b36e608c977920f5a54a88 (patch) | |
tree | 95e7a0a76182a22c9e32addfb3c595684620ebb9 | |
parent | 9d7a748a5174224ead4d44aedc3849d1d1e37b18 (diff) | |
download | rails-5519468523b2017df7b36e608c977920f5a54a88.tar.gz rails-5519468523b2017df7b36e608c977920f5a54a88.tar.bz2 rails-5519468523b2017df7b36e608c977920f5a54a88.zip |
Fix ActiveRecord::Store not tracking changes
-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 bf6a26b1be..0d3852f199 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -42,6 +42,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 |