Cucumber Factory: How to assign polymorphic associations

Posted Over 5 years ago. Visible to the public.

Cucumber factory Show archive.org snapshot supports polymorphic associations out of the box. Just keep in mind that you need to use named associations for this purpose.

class Person < ApplicationModel
  has_many :buildings, inverse_of: :owner
end

class Company < ApplicationModel
  has_many :buildings, inverse_of: :owner
end

class Building < ApplicationModel
  belongs_to :owner, optional: true, polymorphic: true
end

Works

Given there is a person with the name "Nice person"
  And there is a building with the owner "Nice person"

Does not work

Given there is a person with the name "Nice person"
  And there is a building with the owner above
Last edit
Over 1 year ago
Michael Leimstädtner
License
Source code in this card is licensed under the MIT License.
Posted by Emanuel to makandra dev (2018-11-30 16:32)