Skip to content

Commit

Permalink
adding test for blank password confirmation
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Croak committed May 12, 2009
1 parent bf2fb32 commit 884eadd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/clearance/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ def self.included(model)
attr_accessor :password, :password_confirmation

validates_presence_of :email
validates_presence_of :password, :if => :password_required?
validates_confirmation_of :password, :if => :password_required?
validates_uniqueness_of :email, :case_sensitive => false
validates_format_of :email, :with => %r{.+@.+\..+}

validates_presence_of :password, :if => :password_required?
validates_confirmation_of :password, :if => :password_required?

before_save :initialize_salt, :encrypt_password, :initialize_token
end
end
Expand Down
7 changes: 7 additions & 0 deletions test/models/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ class UserTest < ActiveSupport::TestCase
assert user.errors.on(:password)
end

should "require non blank password confirmation on create" do
user = Factory.build(:user, :password => 'blah',
:password_confirmation => '')
assert ! user.save
assert user.errors.on(:password)
end

should "initialize salt" do
assert_not_nil Factory(:user).salt
end
Expand Down

0 comments on commit 884eadd

Please sign in to comment.