Posted almost 3 years ago. Visible to the public.

Cucumber Factory: How to assign polymorphic associations

Cucumber factory Archive 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
Growing Rails Applications in Practice
Check out our new e-book:
Learn to structure large Ruby on Rails codebases with the tools you already know and love.

Owner of this card:

Avatar
Emanuel De
Last edit:
8 days ago
by Tobias Kraze
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 short-lived cookies to improve usability.
Accept or learn more