Created
June 20, 2011 20:33
-
-
Save coryschires/1036509 to your computer and use it in GitHub Desktop.
apply_role.rb
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
| describe "AFTER CREATE apply_member_role" do | |
| it "should apply the role of 'user' to the newly created user" do | |
| user = Factory(:user) | |
| user.role?('member').should be_true | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
require 'spec_helper'
Factory.sequence :role_name do |i|
"role-#{i}"
end
Factory.define :role do |r|
r.name { Factory.next :role_name }
end
Factory.define :user do |u|
u.name 'XYZ'
u.email '[email protected]'
u.password '123456'
u.password_confirmation '123456'
u.after_build { |r| r.roles << Factory.create(:role) }
end
describe User do
context "For User," do
specify "name should be present" do
t = User.create({ :email => '[email protected]',
:password => '123456',
:password_confirmation => '123456' })
t.should_not be_valid
t.name = 'A Rose by any other name smell like a Rose!'
t.should be_valid
end
specify "name should be unique" do
t = Factory(:user)
t.should be_valid
t2 = Factory.build(:user, :email => t.email + '.uk', :name => t.name + 'Sir' )
t2.should be_valid
t2.name = t.name
t2.should_not be_valid
end
specify "email should be unique" do
t = Factory(:user)
t.should be_valid
t2 = Factory.build(:user, :email => t.email + '.uk', :name => t.name + 'Sir' )
t2.should be_valid
t2.email = t.email
t2.should_not be_valid
end
specify "role should be user" do
t = User.create({ :email => '[email protected]',
:password => '123456',
:password_confirmation => '123456' })
t.should_not be_valid
t.name = 'A Rose by any other name smell like a Rose!'
t.role_ids.shoud_equal [1]
end
end
end
Failures:
User For User, name should be unique
Failure/Error: t = Factory(:user)
RuntimeError:
Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id
./app/models/user.rb:32:in `setup_role'
./spec/models/user_spec.rb:32
User For User, email should be unique
Failure/Error: t = Factory(:user)
RuntimeError:
Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id
./app/models/user.rb:32:in `setup_role'
./spec/models/user_spec.rb:40
User For User, role should be user
Failure/Error: t.role_ids.shoud_equal [1]
NoMethodError:
undefined method `shoud_equal' for []:Array
./spec/models/user_spec.rb:53
Finished in 0.44602 seconds
4 examples, 3 failures