lundi 11 février 2019

How to set up a has_many_through relation correctly in fixtures in Rails

I want to test an app and I have a has_many_through relationship. I can't really get it to work, so heres my setup.

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


Here is what I have so far, but it doesn't work: (Note that I try to avoid referring to Ids)


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"


Thanks for any help or hints!

Aucun commentaire:

Enregistrer un commentaire