From 9196b93111b5f89f030b089d32d7a3a9d49b0df9 Mon Sep 17 00:00:00 2001 From: kennyj Date: Tue, 3 Jul 2012 01:29:37 +0900 Subject: Don't mark the store as changed if an attribute isn't changed. --- activerecord/lib/active_record/store.rb | 7 +++++-- activerecord/test/cases/store_test.rb | 5 +++++ 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/store.rb b/activerecord/lib/active_record/store.rb index d13491502e..2af5b02fb7 100644 --- a/activerecord/lib/active_record/store.rb +++ b/activerecord/lib/active_record/store.rb @@ -58,8 +58,11 @@ module ActiveRecord keys.each do |key| define_method("#{key}=") do |value| initialize_store_attribute(store_attribute) - send(store_attribute)[key] = value - send :"#{store_attribute}_will_change!" + attribute = send(store_attribute) + if value != attribute[key] + attribute[key] = value + send :"#{store_attribute}_will_change!" + end end define_method(key) do diff --git a/activerecord/test/cases/store_test.rb b/activerecord/test/cases/store_test.rb index e401dd4b12..7f2b8945f9 100644 --- a/activerecord/test/cases/store_test.rb +++ b/activerecord/test/cases/store_test.rb @@ -34,6 +34,11 @@ class StoreTest < ActiveRecord::TestCase assert @john.settings_changed? 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? + end + test "object initialization with not nullable column" do assert_equal true, @john.remember_login end -- cgit v1.2.3