diff options
author | Rafael Mendonça França <rafael.franca@plataformatec.com.br> | 2014-08-17 22:38:22 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafael.franca@plataformatec.com.br> | 2014-08-17 22:38:22 -0300 |
commit | c78da4d5c472f7254ed609ef753d7b1719732802 (patch) | |
tree | f04630ac62d08a49744b90bdf20bf75dcb883838 /activemodel | |
parent | 4e4913462104df89f1bee08faeb4ba5aab8c9228 (diff) | |
parent | 7ee055076ec2c5b2e9c110f821c10fe06bf38a1c (diff) | |
download | rails-c78da4d5c472f7254ed609ef753d7b1719732802.tar.gz rails-c78da4d5c472f7254ed609ef753d7b1719732802.tar.bz2 rails-c78da4d5c472f7254ed609ef753d7b1719732802.zip |
Merge branch 'master' into loofah
Conflicts:
actionpack/CHANGELOG.md
Diffstat (limited to 'activemodel')
-rw-r--r-- | activemodel/lib/active_model/dirty.rb | 18 | ||||
-rw-r--r-- | activemodel/test/cases/helper.rb | 5 |
2 files changed, 16 insertions, 7 deletions
diff --git a/activemodel/lib/active_model/dirty.rb b/activemodel/lib/active_model/dirty.rb index d11243c4c0..ca04f48c1c 100644 --- a/activemodel/lib/active_model/dirty.rb +++ b/activemodel/lib/active_model/dirty.rb @@ -219,7 +219,7 @@ module ActiveModel rescue TypeError, NoMethodError end - changed_attributes[attr] = value + set_attribute_was(attr, value) end # Handle <tt>reset_*!</tt> for +method_missing+. @@ -233,8 +233,22 @@ module ActiveModel def restore_attribute!(attr) if attribute_changed?(attr) __send__("#{attr}=", changed_attributes[attr]) - changed_attributes.delete(attr) + clear_attribute_changes([attr]) end end + + # This is necessary because `changed_attributes` might be overridden in + # other implemntations (e.g. in `ActiveRecord`) + alias_method :attributes_changed_by_setter, :changed_attributes # :nodoc: + + # Force an attribute to have a particular "before" value + def set_attribute_was(attr, old_value) + attributes_changed_by_setter[attr] = old_value + end + + # Remove changes information for the provided attributes. + def clear_attribute_changes(attributes) + attributes_changed_by_setter.except!(*attributes) + end end end diff --git a/activemodel/test/cases/helper.rb b/activemodel/test/cases/helper.rb index 5e80353836..804e0c24f6 100644 --- a/activemodel/test/cases/helper.rb +++ b/activemodel/test/cases/helper.rb @@ -13,8 +13,3 @@ I18n.enforce_available_locales = false require 'active_support/testing/autorun' require 'mocha/setup' # FIXME: stop using mocha - -# FIXME: we have tests that depend on run order, we should fix that and -# remove this method call. -require 'active_support/test_case' -ActiveSupport::TestCase.my_tests_are_order_dependent! |