Permalink
Browse files

Fix ActiveRecord::Store not tracking changes

  • Loading branch information...
janko-m committed Apr 29, 2013
1 parent 9d7a748 commit 5519468523b2017df7b36e608c977920f5a54a88
Showing with 13 additions and 1 deletion.
  1. +5 −0 activerecord/CHANGELOG.md
  2. +1 −1 activerecord/lib/active_record/store.rb
  3. +7 −0 activerecord/test/cases/store_test.rb
@@ -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) ##
@@ -37,8 +37,8 @@ def store_accessor(store_attribute, *keys)
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
@@ -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

0 comments on commit 5519468

Please sign in to comment.