Created
June 27, 2013 10:29
-
-
Save easante/5875458 to your computer and use it in GitHub Desktop.
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 | |
describe "password" do | |
it "needs a password and confirmation to save" do | |
u = User.new(name: "steve", email: "steve@example.com") | |
u.save | |
expect(u).to_not be_valid | |
u.password = "password" | |
u.password_confirmation = "" | |
u.save | |
#expect(u).to_not be_true | |
u.password_confirmation = "password" | |
u.save | |
expect(u).to be_valid | |
end | |
it "needs a password and confirmation to match" do | |
u = User.create( | |
name: "steve", | |
password: "hunter2", | |
password_confirmation: "hunter") | |
expect(u).to_not be_valid | |
end | |
it "requires an email" do | |
u = User.new( | |
name: "steve", | |
password: "hunter2", | |
password_confirmation: "hunter2") | |
u.save | |
expect(u).to_not be_valid | |
u.email = "steve@example.com" | |
u.save | |
expect(u).to be_valid | |
end | |
end | |
describe "authentication" do | |
let(:user) { User.create( | |
name: "steve", | |
email: "steve@example.com", | |
password: "hunter2", | |
password_confirmation: "hunter2") } | |
it "authenticates with a correct password" do | |
expect(user.authenticate("hunter2")).to be_valid | |
end | |
it "does not authenticate with an incorrect password" do | |
expect(user.authenticate("hunter1")).to_not be_true | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment