diff options
Diffstat (limited to 'activemodel')
-rw-r--r-- | activemodel/lib/active_model/errors.rb | 4 | ||||
-rw-r--r-- | activemodel/lib/active_model/model.rb | 16 | ||||
-rw-r--r-- | activemodel/lib/active_model/observing.rb | 6 | ||||
-rw-r--r-- | activemodel/lib/active_model/secure_password.rb | 8 | ||||
-rw-r--r-- | activemodel/lib/active_model/validations/callbacks.rb | 3 | ||||
-rw-r--r-- | activemodel/test/cases/secure_password_test.rb | 6 |
6 files changed, 24 insertions, 19 deletions
diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb index 016bf87d86..0c628c33c2 100644 --- a/activemodel/lib/active_model/errors.rb +++ b/activemodel/lib/active_model/errors.rb @@ -130,12 +130,12 @@ module ActiveModel # has more than one error message, yields once for each error message. # # p.errors.add(:name, "can't be blank") - # p.errors.each do |attribute, errors_array| + # p.errors.each do |attribute, error| # # Will yield :name and "can't be blank" # end # # p.errors.add(:name, "must be specified") - # p.errors.each do |attribute, errors_array| + # p.errors.each do |attribute, error| # # Will yield :name and "can't be blank" # # then yield :name and "must be specified" # end diff --git a/activemodel/lib/active_model/model.rb b/activemodel/lib/active_model/model.rb index 6825fdc653..3af95b09b0 100644 --- a/activemodel/lib/active_model/model.rb +++ b/activemodel/lib/active_model/model.rb @@ -2,11 +2,11 @@ module ActiveModel # == Active Model Basic Model # - # Includes the required interface for an object to interact with +ActionPack+, - # using different +ActiveModel+ modules. It includes model name introspections, + # Includes the required interface for an object to interact with <tt>ActionPack</tt>, + # using different <tt>ActiveModel</tt> modules. It includes model name introspections, # conversions, translations and validations. Besides that, it allows you to # initialize the object with a hash of attributes, pretty much like - # +ActiveRecord+ does. + # <tt>ActiveRecord</tt> does. # # A minimal implementation could be: # @@ -19,8 +19,8 @@ module ActiveModel # person.name # => 'bob' # person.age # => 18 # - # Note that, by default, +ActiveModel::Model+ implements +persisted?+ to - # return +false+, which is the most common case. You may want to override it + # Note that, by default, <tt>ActiveModel::Model</tt> implements <tt>persisted?</tt> to + # return <tt>false</tt>, which is the most common case. You may want to override it # in your class to simulate a different scenario: # # class Person @@ -35,14 +35,14 @@ module ActiveModel # person = Person.new(:id => 1, :name => 'bob') # person.persisted? # => true # - # Also, if for some reason you need to run code on +initialize+, make sure you + # Also, if for some reason you need to run code on <tt>initialize</tt>, make sure you # call super if you want the attributes hash initialization to happen. # # class Person # include ActiveModel::Model # attr_accessor :id, :name, :omg # - # def initialize(attributes) + # def initialize(attributes={}) # super # @omg ||= true # end @@ -52,7 +52,7 @@ module ActiveModel # person.omg # => true # # For more detailed information on other functionalities available, please refer - # to the specific modules included in +ActiveModel::Model+ (see below). + # to the specific modules included in <tt>ActiveModel::Model</tt> (see below). module Model def self.included(base) base.class_eval do diff --git a/activemodel/lib/active_model/observing.rb b/activemodel/lib/active_model/observing.rb index b905d2b6d2..a6b6dfafe7 100644 --- a/activemodel/lib/active_model/observing.rb +++ b/activemodel/lib/active_model/observing.rb @@ -70,8 +70,8 @@ module ActiveModel end # Notify list of observers of a change. - def notify_observers(*arg) - observer_instances.each { |observer| observer.update(*arg) } + def notify_observers(*args) + observer_instances.each { |observer| observer.update(*args) } end # Total number of observers. @@ -221,6 +221,7 @@ module ActiveModel end # Start observing the declared classes and their subclasses. + # Called automatically by the instance method. def initialize observed_classes.each { |klass| add_observer!(klass) } end @@ -249,6 +250,7 @@ module ActiveModel klass.add_observer(self) end + # Returns true if notifications are disabled for this object. def disabled_for?(object) klass = object.class return false unless klass.respond_to?(:observers) diff --git a/activemodel/lib/active_model/secure_password.rb b/activemodel/lib/active_model/secure_password.rb index e7a57cf691..ff2213231f 100644 --- a/activemodel/lib/active_model/secure_password.rb +++ b/activemodel/lib/active_model/secure_password.rb @@ -55,17 +55,13 @@ module ActiveModel module InstanceMethodsOnActivation # Returns self if the password is correct, otherwise false. def authenticate(unencrypted_password) - if BCrypt::Password.new(password_digest) == unencrypted_password - self - else - false - end + BCrypt::Password.new(password_digest) == unencrypted_password && self end # Encrypts the password into the password_digest attribute. def password=(unencrypted_password) - @password = unencrypted_password unless unencrypted_password.blank? + @password = unencrypted_password self.password_digest = BCrypt::Password.create(unencrypted_password) end end diff --git a/activemodel/lib/active_model/validations/callbacks.rb b/activemodel/lib/active_model/validations/callbacks.rb index c39c85e1af..dbafd0bd1a 100644 --- a/activemodel/lib/active_model/validations/callbacks.rb +++ b/activemodel/lib/active_model/validations/callbacks.rb @@ -8,7 +8,8 @@ module ActiveModel # Provides an interface for any class to have <tt>before_validation</tt> and # <tt>after_validation</tt> callbacks. # - # First, extend ActiveModel::Callbacks from the class you are creating: + # First, include ActiveModel::Validations::Callbacks from the class you are + # creating: # # class MyModel # include ActiveModel::Validations::Callbacks diff --git a/activemodel/test/cases/secure_password_test.rb b/activemodel/test/cases/secure_password_test.rb index 4338a3fc53..c451cc1aca 100644 --- a/activemodel/test/cases/secure_password_test.rb +++ b/activemodel/test/cases/secure_password_test.rb @@ -19,6 +19,12 @@ class SecurePasswordTest < ActiveModel::TestCase assert !@user.valid?, 'user should be invalid' end + test "blank password doesn't override previous password" do + @user.password = 'test' + @user.password = '' + assert_equal @user.password, 'test' + end + test "password must be present" do assert !@user.valid? assert_equal 1, @user.errors.size |