Created
August 12, 2015 14:40
-
-
Save sprite2005/6a299e17087b27f6b65a to your computer and use it in GitHub Desktop.
This file contains hidden or 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 'rails_helper' | |
RSpec.describe User, type: :model do | |
context "factories" do | |
it "has a valid user factory" do | |
expect(build(:user)).to be_valid | |
expect(build(:user)).to be_member | |
end | |
it "has a valid vip user factory" do | |
expect(build(:vip_user)).to be_valid | |
expect(build(:vip_user)).to be_vip | |
end | |
it "has a valid moderator user factory" do | |
expect(build(:moderator_user)).to be_valid | |
expect(build(:moderator_user)).to be_moderator | |
end | |
it "has a valid admin user factory" do | |
expect(build(:admin_user)).to be_valid | |
expect(build(:admin_user)).to be_admin | |
end | |
end | |
context "validations" do | |
let(:user) { create(:user) } | |
it { should_not allow_value('nonemail').for(:email) } | |
it { should allow_value('[email protected]').for(:email) } | |
it { should allow_value('sprite', 'sprite2005', 'sprite_2005').for(:username) } | |
it { should_not allow_value('spr', 'spr!t3').for(:username) } | |
it { should validate_uniqueness_of(:username) } | |
it { should validate_uniqueness_of(:email) } | |
it { should validate_presence_of(:birth_date) } | |
it { should allow_value(17.years.ago.to_date).for(:birth_date) } | |
it { should allow_value(20.years.ago.to_date).for(:birth_date) } | |
it { should_not allow_value((17.years.ago + 1.day).to_date).for(:birth_date) } | |
end | |
context "defaults" do | |
it "should default to :member role" do | |
user = build(:user) | |
expect(user.member?).to be true | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment