spec/models/user_spec.rb in clearance-1.0.0.rc7 vs spec/models/user_spec.rb in clearance-1.0.0.rc8
- old
+ new
@@ -40,11 +40,11 @@
it 'is authenticated with correct uppercased email and correct password' do
User.authenticate(@user.email.upcase, @password).should eq(@user)
@user.should be_authenticated(@password)
end
- it 'is authenticated with incorrect credentials' do
+ it 'is not authenticated with incorrect credentials' do
User.authenticate(@user.email, 'bad_password').should be_nil
@user.should_not be_authenticated('bad password')
end
it 'is retrieved via a case-insensitive search' do
@@ -124,11 +124,11 @@
before do
@user.update_password ''
end
it 'does not change encrypted password' do
- @user.encrypted_password.should == @old_encrypted_password
+ @user.encrypted_password.to_s.should == @old_encrypted_password
end
it 'does not clear confirmation token' do
@user.confirmation_token.should_not be_nil
end
@@ -152,27 +152,10 @@
it { should allow_value(nil).for(:email) }
it { should allow_value('').for(:email) }
end
- describe 'a user with an optional password' do
- before do
- @user = User.new
-
- class << @user
- def password_optional?
- true
- end
- end
- end
-
- subject { @user }
-
- it { should allow_value(nil).for(:password) }
- it { should allow_value('').for(:password) }
- end
-
describe 'user factory' do
it 'should create a valid user with just an overridden password' do
build(:user, :password => 'test').should be_valid
end
end
@@ -194,7 +177,18 @@
end
it 'also sets encrypted_password' do
subject.encrypted_password.should_not be_nil
end
+ end
+end
+
+describe UserWithOptionalPassword do
+ it { should allow_value(nil).for(:password) }
+ it { should allow_value('').for(:password) }
+
+ it 'cannot authenticate with blank password' do
+ user = create(:user_with_optional_password)
+
+ UserWithOptionalPassword.authenticate(user.email, '').should be_nil
end
end