如何在Rails的灯具中正确设置has_many_through关系

时间:2019-02-11 23:00:08

标签: ruby-on-rails testing capybara fixtures

我想测试一个应用,并且我具有has_many_through关系。我真的无法正常工作,所以这里是我的设置。

Agent: 
 has_many :memberships
 has_many :organizations, through: :memberships
 belongs_to :current_organization

Organizations:
 has_many :memberships
 has_many :agents, through: :memberships

Memberships: 
 belongs_to :organization
 belongs_to :agent

到目前为止,这是我所拥有的,但是不起作用:(请注意,我尽量避免引用ID)

agents.yml
PistolPete: 
  current_organization: one
  email: pistol@pete.com
  encrypted_password: <%= Devise::Encryptor.digest(Agent, '123456789')%>

memberships.yml
membership: 
  agent: PistolPete
  organization: one
  role: <%= Membership.roles[:agent] %>

organizations.yml
one:
  name: "Pete's shop"

感谢您的帮助或提示!

0 个答案:

没有答案