Skip to content

Commit

Permalink
Don't mark the store as changed if an attribute isn't changed.
Browse files Browse the repository at this point in the history
  • Loading branch information
kennyj committed Jul 3, 2012
1 parent 215d41d commit 9196b93
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 5 additions & 2 deletions activerecord/lib/active_record/store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,11 @@ def store_accessor(store_attribute, *keys)
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
Expand Down
5 changes: 5 additions & 0 deletions activerecord/test/cases/store_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9196b93

Please sign in to comment.