Skip to content

Commit

Permalink
has_secure_password should not raise a 'digest missing' error if the …
Browse files Browse the repository at this point in the history
…calling class has specified for validations to be skipped.
  • Loading branch information
freerobby committed Jul 31, 2012
1 parent c102022 commit ad7f9cd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions activemodel/lib/active_model/secure_password.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ def has_secure_password(options = {})
if options.fetch(:validations, true)
validates_confirmation_of :password
validates_presence_of :password, :on => :create

before_create { raise "Password digest missing on new record" if password_digest.blank? }
end

before_create { raise "Password digest missing on new record" if password_digest.blank? }

include InstanceMethodsOnActivation

Expand Down
8 changes: 8 additions & 0 deletions activemodel/test/cases/secure_password_test.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'cases/helper'
require 'models/user'
require 'models/oauthed_user'
require 'models/visitor'
require 'models/administrator'

Expand All @@ -8,6 +9,7 @@ class SecurePasswordTest < ActiveModel::TestCase
setup do
@user = User.new
@visitor = Visitor.new
@oauthed_user = OauthedUser.new
end

test "blank password" do
Expand Down Expand Up @@ -73,4 +75,10 @@ class SecurePasswordTest < ActiveModel::TestCase
@user.run_callbacks :create
end
end

test "Oauthed user can be created with blank digest" do
assert_nothing_raised do
@oauthed_user.run_callbacks :create
end
end
end
11 changes: 11 additions & 0 deletions activemodel/test/models/oauthed_user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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

0 comments on commit ad7f9cd

Please sign in to comment.