Created
April 3, 2012 08:36
-
-
Save terenceponce/2290470 to your computer and use it in GitHub Desktop.
Unit testing validatable module of Devise
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Failures: | |
1) User when email address is already taken | |
Failure/Error: it { should_not be_valid } | |
expected valid? to return false, got true | |
# ./spec/models/user_spec.rb:73:in `block (3 levels) in <top (required)>' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
devise :database_authenticatable, :registerable, | |
:recoverable, :rememberable, :trackable, :validatable | |
attr_accessible :email, :password, :password_confirmation, :remember_me | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe User do | |
before do | |
@user = Fabricate(:user) | |
end | |
subject { @user } | |
describe 'when email address is already taken' do | |
before do | |
user_with_same_email = @user.dup | |
user_with_same_email.email = @user.email.upcase | |
user_with_same_email.save | |
end | |
it { should_not be_valid } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As sevenseacat on IRC pointed out, the test was still asserting
@user
instead ofuser_with_same_email
. That's why it was returning true. Knowing that, I adjusted the test to be like this:This solution got the test to pass.