Skip to content

Instantly share code, notes, and snippets.

@easante
Created June 27, 2013 10:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save easante/5875458 to your computer and use it in GitHub Desktop.
Save easante/5875458 to your computer and use it in GitHub Desktop.
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