aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2013-06-25 22:03:01 -0300
committerCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2013-06-25 22:03:01 -0300
commit07c6262c253cd60780735ab813bc255b606facbc (patch)
tree5811d731cbd122331f071bfcad9bfd4cd160f7c8
parent27b38838467cf47f83caefbddcdb96aceca052ee (diff)
parent5519468523b2017df7b36e608c977920f5a54a88 (diff)
downloadrails-07c6262c253cd60780735ab813bc255b606facbc.tar.gz
rails-07c6262c253cd60780735ab813bc255b606facbc.tar.bz2
rails-07c6262c253cd60780735ab813bc255b606facbc.zip
Merge pull request #10373 from janko-m/fix-store-accessor
Fix a bug in ActiveRecord::Store accessors
-rw-r--r--activerecord/CHANGELOG.md5
-rw-r--r--activerecord/lib/active_record/store.rb2
-rw-r--r--activerecord/test/cases/store_test.rb7
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