我有一个类似这样的用户的 rails 结构:
User.create(
email: 'asdf@test.com',
password: 'testtest',
password_confirmation: 'testtest'
).memberships.create(
role_id: 1
)
在哪里,
Role.create(
name: 'admin'
)
如何在 FactoryGirl 中创建此关联?
楷模:
用户.rb
has_many :memberships
has_many :roles, through: :memberships
会员资格.rb
belongs_to :user
belongs_to :role, dependent: :destroy
角色.rb
has_many :memberships, dependent: :destroy
has_many :users, through: :memberships