Posted about 1 month ago. Visible to the public. Repeats.

Cucumber Factory: How to assign polymorphic associations

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

Copy
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

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

Does not work

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

Does your version of Ruby on Rails still receive security updates?
Rails LTS provides security patches for old versions of Ruby on Rails (3.2 and 2.3).

Owner of this card:

Avatar
Emanuel De
Last edit:
about 1 month ago
by Emanuel De
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Emanuel De to makandra dev
This website uses cookies to improve usability and analyze traffic.
Accept or learn more