diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-09-05 15:33:48 -0700 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-09-05 15:33:48 -0700 |
commit | 2197d61c69d3e1d536dc54e2c0994d2adbe40d18 (patch) | |
tree | 1afdd6d6a63d8ab869c6307a373774aa623cf96e /activerecord | |
parent | ebc4d8cede42b2e199a589904ceac6b4dc69eab5 (diff) | |
parent | 20f943ffd86ae3f74cc16c6f85fb7cc2a43da388 (diff) | |
download | rails-2197d61c69d3e1d536dc54e2c0994d2adbe40d18.tar.gz rails-2197d61c69d3e1d536dc54e2c0994d2adbe40d18.tar.bz2 rails-2197d61c69d3e1d536dc54e2c0994d2adbe40d18.zip |
Merge pull request #7532 from al2o3cr/fix_store_bugs
correct handling of changes in AR::Store, combine multiple store_accessors
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/store.rb | 5 | ||||
-rw-r--r-- | activerecord/test/cases/store_test.rb | 10 | ||||
-rw-r--r-- | activerecord/test/models/admin/user.rb | 1 |
3 files changed, 12 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/store.rb b/activerecord/lib/active_record/store.rb index b4013ecc1e..25f528498e 100644 --- a/activerecord/lib/active_record/store.rb +++ b/activerecord/lib/active_record/store.rb @@ -57,8 +57,8 @@ module ActiveRecord define_method("#{key}=") do |value| attribute = initialize_store_attribute(store_attribute) if value != attribute[key] - attribute[key] = value send :"#{store_attribute}_will_change!" + attribute[key] = value end end @@ -67,7 +67,8 @@ module ActiveRecord end end - self.stored_attributes[store_attribute] = keys + self.stored_attributes[store_attribute] ||= [] + self.stored_attributes[store_attribute] |= keys end end diff --git a/activerecord/test/cases/store_test.rb b/activerecord/test/cases/store_test.rb index fb0d116c08..2741f223da 100644 --- a/activerecord/test/cases/store_test.rb +++ b/activerecord/test/cases/store_test.rb @@ -34,6 +34,12 @@ class StoreTest < ActiveRecord::TestCase assert @john.settings_changed? end + test "updating the store populates the changed array correctly" do + @john.color = 'red' + assert_equal 'black', @john.settings_change[0]['color'] + assert_equal 'red', @john.settings_change[1]['color'] + end + test "updating the store won't mark it as changed if an attribute isn't changed" do @john.color = @john.color assert !@john.settings_changed? @@ -117,8 +123,8 @@ class StoreTest < ActiveRecord::TestCase assert_equal false, @john.is_a_good_guy end - test "stored attributes are returned" do - assert_equal [:color, :homepage], Admin::User.stored_attributes[:settings] + test "all stored attributes are returned" do + assert_equal [:color, :homepage, :favorite_food], Admin::User.stored_attributes[:settings] end test "stores_attributes are class level settings" do diff --git a/activerecord/test/models/admin/user.rb b/activerecord/test/models/admin/user.rb index ad30039304..6c4eb03b06 100644 --- a/activerecord/test/models/admin/user.rb +++ b/activerecord/test/models/admin/user.rb @@ -1,6 +1,7 @@ class Admin::User < ActiveRecord::Base belongs_to :account store :settings, :accessors => [ :color, :homepage ] + store_accessor :settings, :favorite_food store :preferences, :accessors => [ :remember_login ] store :json_data, :accessors => [ :height, :weight ], :coder => JSON store :json_data_empty, :accessors => [ :is_a_good_guy ], :coder => JSON |