aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2017-04-14 10:27:47 -0700
committerGitHub <noreply@github.com>2017-04-14 10:27:47 -0700
commite447c8c80a3f99a29286661eb47762535c249181 (patch)
tree7532907156d21f973f2187745e9c5996cdf0469d /activemodel/lib
parent851b7f866e13518d900407c78dcd6eb477afad06 (diff)
parentb5eb3215a68f94bb8cb20739366232c415744b83 (diff)
downloadrails-e447c8c80a3f99a29286661eb47762535c249181.tar.gz
rails-e447c8c80a3f99a29286661eb47762535c249181.tar.bz2
rails-e447c8c80a3f99a29286661eb47762535c249181.zip
Merge pull request #28661 from bogdanvlviv/fix-dirty-attributes-if-override-attr_accessor
Fix inconsistency with changed attributes when overriding AR attribute reader
Diffstat (limited to 'activemodel/lib')
-rw-r--r--activemodel/lib/active_model/dirty.rb12
1 files changed, 8 insertions, 4 deletions
diff --git a/activemodel/lib/active_model/dirty.rb b/activemodel/lib/active_model/dirty.rb
index 6e0af99ad7..37b51ad354 100644
--- a/activemodel/lib/active_model/dirty.rb
+++ b/activemodel/lib/active_model/dirty.rb
@@ -179,13 +179,13 @@ module ActiveModel
# Handles <tt>*_changed?</tt> for +method_missing+.
def attribute_changed?(attr, from: OPTION_NOT_GIVEN, to: OPTION_NOT_GIVEN) # :nodoc:
!!changes_include?(attr) &&
- (to == OPTION_NOT_GIVEN || to == __send__(attr)) &&
+ (to == OPTION_NOT_GIVEN || to == _attributes(attr)) &&
(from == OPTION_NOT_GIVEN || from == changed_attributes[attr])
end
# Handles <tt>*_was</tt> for +method_missing+.
def attribute_was(attr) # :nodoc:
- attribute_changed?(attr) ? changed_attributes[attr] : __send__(attr)
+ attribute_changed?(attr) ? changed_attributes[attr] : _attributes(attr)
end
# Handles <tt>*_previously_changed?</tt> for +method_missing+.
@@ -226,7 +226,7 @@ module ActiveModel
# Handles <tt>*_change</tt> for +method_missing+.
def attribute_change(attr)
- [changed_attributes[attr], __send__(attr)] if attribute_changed?(attr)
+ [changed_attributes[attr], _attributes(attr)] if attribute_changed?(attr)
end
# Handles <tt>*_previous_change</tt> for +method_missing+.
@@ -239,7 +239,7 @@ module ActiveModel
return if attribute_changed?(attr)
begin
- value = __send__(attr)
+ value = _attributes(attr)
value = value.duplicable? ? value.clone : value
rescue TypeError, NoMethodError
end
@@ -268,5 +268,9 @@ module ActiveModel
def clear_attribute_changes(attributes) # :doc:
attributes_changed_by_setter.except!(*attributes)
end
+
+ def _attributes(attr)
+ __send__(attr)
+ end
end
end