Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require File.join( File.dirname(__FILE__), "..", "spec_helper" )
- describe User do
- before(:all) do
- load_fixtures(:users)
- end
- after(:all) do
- User.delete_all
- end
- it "should require an email address" do
- user = User.new(valid_attrs.except(:email))
- user.should_not be_valid
- user.errors.full_messages.first.should eql("Email must not be blank")
- end
- it "should require a valid email address" do
- user = User.new(valid_attrs.with(:email => 'cameroncox@gmail'))
- user.should_not be_valid
- user.errors.full_messages.first.should eql("Email is invalid")
- end
- it "should ensure email addresses are unique" do
- user = User.new(valid_attrs.with(:email => 'john-doe@gmail.com'))
- user.should_not be_valid
- user.errors.full_messages.first.should eql("Email has already been taken")
- end
- it "should ensure usernames are unique" do
- user = User.new(valid_attrs.with(:username => 'john-doe'))
- user.should_not be_valid
- user.errors.full_messages.first.should eql("Username has already been taken")
- end
- it "should require an username" do
- user = User.new(valid_attrs.except(:username))
- user.should_not be_valid
- user.errors.full_messages.first.should eql("Username must not be blank")
- end
- it "should ensure that usernames are between 4 and 25 characters long" do
- user = User.new(valid_attrs.with(:username => 'bob'))
- user.should_not be_valid
- user.errors.full_messages.first.should eql("Username must be between 4 and 25 characters long")
- user.username = 'supercalifragilicousexpialidocious' # I -totally- spelled that wrong :D
- user.should_not be_valid
- user.errors.full_messages.first.should eql("Username must be between 4 and 25 characters long")
- end
- it "should require password attribute when crypted password is blank" do
- user = User.new(valid_attrs.except(:password))
- user.should_not be_valid
- user.errors.full_messages.first.should eql("Password must not be blank")
- end
- it "should not require password attribute when crypted password is not blank" do
- user = User.new(valid_attrs.except(:password).with(:crypted_password => "testing"))
- user.should be_valid
- end
- it "should require password to be more than 5 characters long" do
- user = User.new(valid_attrs.with(:password => 'short', :password_confirmation => 'short'))
- user.should_not be_valid
- user.errors.full_messages.first.should eql("Password must be more than 5 characters long")
- end
- it "should should require confirmation of password" do
- user = User.new(valid_attrs.with(:password_confirmation => '@gonow'))
- user.should_not be_valid
- user.errors.full_messages.first.should eql("Password does not match the confirmation")
- end
- it "should set salt before saving" do
- user = User.new(valid_attrs)
- user.should be_valid
- user.salt.blank?.should eql(nil)
- end
- it "should encrypt password before saving" do
- user = User.new(valid_attrs)
- user.should be_valid
- user.crypted_password.blank?.should eql(nil)
- end
- it "should ensure a username does not contain a restricted keyword that is a String" do
- user = User.new(valid_attrs.with(:username => 'root'))
- user.should_not be_valid
- user.errors.full_messages.first.should eql("Username cannot contain the phrase 'root'")
- end
- it "should ensure a username does not contain a restricted keyword that is a Regexp" do
- user = User.new(valid_attrs.with(:username => 'wolfadmin'))
- user.should_not be_valid
- user.errors.full_messages.first.should eql("Username cannot contain the phrase 'admin'")
- end
- it "should have an activation code before create" do
- user = User.new(valid_attrs)
- user.should be_valid
- user.save
- user.activation_code.blank?.should eql(nil)
- end
- it "should have an activation code if inactive" do
- user = User.first :conditions => ["username = ?", 'cameroncox']
- user.deactivate
- user.active?.should eql(nil)
- user.activation_code.blank?.should_not eql(true)
- end
- it "should not have an activation code if active" do
- user = User.first :conditions => ["username = ?", 'cameroncox']
- user.activate
- user.active?.should_not eql(nil)
- user.activation_code.blank?.should eql(true)
- end
- protected
- def valid_attrs
- { :username => 'cameroncox', :password => '!@gonow', :password_confirmation => '!@gonow', :email => 'cameroncox@gmail.com' }
- end
- end
Add Comment
Please, Sign In to add comment