Posted 5 months 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

Once an application no longer requires constant development, it needs periodic maintenance for stable and secure operation. makandra offers monthly maintenance contracts that let you focus on your business while we make sure the lights stay on.

Owner of this card:

Avatar
Emanuel De
Last edit:
4 months 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