Posted 11 days ago. Visible to the public.

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 customer with the name "Nice customer" And there is a building with the owner "Nice customer"

Does not work

Copy
Given there is a customer with the name "Nice customer" 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:
11 days 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