Skip to content

Instantly share code, notes, and snippets.

@tubbo
Forked from drager/create_user.rb
Created April 29, 2014 16:24
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 tubbo/11405232 to your computer and use it in GitHub Desktop.
Save tubbo/11405232 to your computer and use it in GitHub Desktop.
require 'spec_helper'
describe User do
it "has a valid factory" do
build(:user).should be_valid
end
it "is invalid without an email" do
build(:user, email: nil).should_not be_valid
end
it "is invalid if the username is shorter than 3 characters" do
build(:user, username: 'ln').should_not be_valid
end
it "is invalid if password is shorter than 6 characters" do
build(:user, password: '12345', password_confirmation: '12345').should_not be_valid
end
it "is invalid if password doesn't match" do
build(:user, password: 'test123', password_confirmation: 'test321').should_not be_valid
end
it "is invalid if username is not unique" do
create(:user, username: 'ellen.u').should be_valid
create(:user, username: 'ellen.u').should be_valid
end
it "is invalid if email is not unique" do
create(:user, email: 'ellen.u@lnu.se').should be_valid
create(:user, email: 'ellen.u@lnu.se').should be_valid
end
end
require 'faker'
FactoryGirl.define do
factory :user do
email {Faker::Internet.email}
username {Faker::Internet.user_name}
first_name {Faker::Name.first_name}
last_name {Faker::Name.last_name}
password 'test123'
password_confirmation 'test123'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment