diff options
Diffstat (limited to 'activemodel/lib/active_model')
-rw-r--r-- | activemodel/lib/active_model/dirty.rb | 8 | ||||
-rw-r--r-- | activemodel/lib/active_model/secure_password.rb | 20 | ||||
-rw-r--r-- | activemodel/lib/active_model/type/float.rb | 2 |
3 files changed, 19 insertions, 11 deletions
diff --git a/activemodel/lib/active_model/dirty.rb b/activemodel/lib/active_model/dirty.rb index aaefe00c83..245616502d 100644 --- a/activemodel/lib/active_model/dirty.rb +++ b/activemodel/lib/active_model/dirty.rb @@ -84,6 +84,7 @@ module ActiveModel # person.previous_changes # => {"name" => [nil, "Bill"]} # person.name_previously_changed? # => true # person.name_previous_change # => [nil, "Bill"] + # person.name_previously_was # => nil # person.reload! # person.previous_changes # => {} # @@ -122,7 +123,7 @@ module ActiveModel included do attribute_method_suffix "_changed?", "_change", "_will_change!", "_was" - attribute_method_suffix "_previously_changed?", "_previous_change" + attribute_method_suffix "_previously_changed?", "_previous_change", "_previously_was" attribute_method_affix prefix: "restore_", suffix: "!" end @@ -180,6 +181,11 @@ module ActiveModel mutations_before_last_save.changed?(attr_name.to_s) end + # Dispatch target for <tt>*_previously_was</tt> attribute methods. + def attribute_previously_was(attr_name) # :nodoc: + mutations_before_last_save.original_value(attr_name.to_s) + end + # Restore all previous data of the provided attributes. def restore_attributes(attr_names = changed) attr_names.each { |attr_name| restore_attribute!(attr_name) } diff --git a/activemodel/lib/active_model/secure_password.rb b/activemodel/lib/active_model/secure_password.rb index 5f409326bd..c177d771ad 100644 --- a/activemodel/lib/active_model/secure_password.rb +++ b/activemodel/lib/active_model/secure_password.rb @@ -45,19 +45,19 @@ module ActiveModel # end # # user = User.new(name: 'david', password: '', password_confirmation: 'nomatch') - # user.save # => false, password required + # user.save # => false, password required # user.password = 'mUc3m00RsqyRe' - # user.save # => false, confirmation doesn't match + # user.save # => false, confirmation doesn't match # user.password_confirmation = 'mUc3m00RsqyRe' - # user.save # => true + # user.save # => true # user.recovery_password = "42password" - # user.recovery_password_digest # => "$2a$04$iOfhwahFymCs5weB3BNH/uXkTG65HR.qpW.bNhEjFP3ftli3o5DQC" - # user.save # => true - # user.authenticate('notright') # => false - # user.authenticate('mUc3m00RsqyRe') # => user - # user.authenticate_recovery_password('42password') # => user - # User.find_by(name: 'david').try(:authenticate, 'notright') # => false - # User.find_by(name: 'david').try(:authenticate, 'mUc3m00RsqyRe') # => user + # user.recovery_password_digest # => "$2a$04$iOfhwahFymCs5weB3BNH/uXkTG65HR.qpW.bNhEjFP3ftli3o5DQC" + # user.save # => true + # user.authenticate('notright') # => false + # user.authenticate('mUc3m00RsqyRe') # => user + # user.authenticate_recovery_password('42password') # => user + # User.find_by(name: 'david')&.authenticate('notright') # => false + # User.find_by(name: 'david')&.authenticate('mUc3m00RsqyRe') # => user def has_secure_password(attribute = :password, validations: true) # Load bcrypt gem only when has_secure_password is used. # This is to avoid ActiveModel (and by extension the entire framework) diff --git a/activemodel/lib/active_model/type/float.rb b/activemodel/lib/active_model/type/float.rb index 36c7a5103c..435e39b2c9 100644 --- a/activemodel/lib/active_model/type/float.rb +++ b/activemodel/lib/active_model/type/float.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require "active_support/core_ext/object/try" + module ActiveModel module Type class Float < Value # :nodoc: |