提交 fb08039c 编写于 作者: C Carlos Antonio da Silva

Merge pull request #7217 from freerobby/no_password_requirement_if_validations_skipped

has_secure_password should not raise a 'digest missing' error if the calling class has specified for validations to be skipped.
...@@ -43,9 +43,9 @@ def has_secure_password(options = {}) ...@@ -43,9 +43,9 @@ def has_secure_password(options = {})
if options.fetch(:validations, true) if options.fetch(:validations, true)
validates_confirmation_of :password validates_confirmation_of :password
validates_presence_of :password, :on => :create validates_presence_of :password, :on => :create
before_create { raise "Password digest missing on new record" if password_digest.blank? }
end end
before_create { raise "Password digest missing on new record" if password_digest.blank? }
include InstanceMethodsOnActivation include InstanceMethodsOnActivation
......
require 'cases/helper' require 'cases/helper'
require 'models/user' require 'models/user'
require 'models/oauthed_user'
require 'models/visitor' require 'models/visitor'
require 'models/administrator' require 'models/administrator'
...@@ -8,6 +9,7 @@ class SecurePasswordTest < ActiveModel::TestCase ...@@ -8,6 +9,7 @@ class SecurePasswordTest < ActiveModel::TestCase
setup do setup do
@user = User.new @user = User.new
@visitor = Visitor.new @visitor = Visitor.new
@oauthed_user = OauthedUser.new
end end
test "blank password" do test "blank password" do
...@@ -73,4 +75,10 @@ class SecurePasswordTest < ActiveModel::TestCase ...@@ -73,4 +75,10 @@ class SecurePasswordTest < ActiveModel::TestCase
@user.run_callbacks :create @user.run_callbacks :create
end end
end end
test "Oauthed user can be created with blank digest" do
assert_nothing_raised do
@oauthed_user.run_callbacks :create
end
end
end end
class OauthedUser
extend ActiveModel::Callbacks
include ActiveModel::Validations
include ActiveModel::SecurePassword
define_model_callbacks :create
has_secure_password(validations: false)
attr_accessor :password_digest, :password_salt
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册