Read more

Cucumber Factory: How to assign polymorphic associations

Emanuel
November 30, 2018Software engineer at makandra GmbH

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

Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

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
Posted by Emanuel to makandra dev (2018-11-30 17:32)