行,所以我想测试我们需要一个管理员用户的特点和我试图以管理员身份登录,但为了做到这一点,我需要有一个管理员用户如何使用Factory Girl创建管理员角色?
这里是我的代码
let(:user) { FactoryGirl.create(:user) }
let(:admin_role) { FactoryGirl.create(:role) }
FactoryGirl.define do
factory :user do
first_name "John"
last_name "Doe"
email "[email protected]"
end
factory :role do
name "Admin"
end
end
我如何连接这些我想user.roles << user_role
,但得到这个错误
/Users/matt/Sites/application/spec/controllers/directory_controller_spec.rb:16:in `block (3 levels) in <top (required)>': undefined local variable or method `user' for #<Class:0x007fa550890d80> (NameError)
这里是我的模型
class User < ActiveRecord::Base
has_many :roles, :through => :role_users
has_many :role_users
...
class Role < ActiveRecord::Base
has_many :users, :through => :role_users
has_many :role_users
...
class RoleUser < ActiveRecord::Base
belongs_to :role
belongs_to :user
end
你会如何使用这个在描述 – Trace 2012-04-12 21:25:32
您是否正在寻找的anwser FactoryGirl.create(:admin_user) – 2012-04-13 14:01:58
我试过了,并获得和错误....我会贴现在 – Trace 2012-04-13 14:14:15