Created
May 29, 2012 20:33
-
-
Save traviskroberts/2830535 to your computer and use it in GitHub Desktop.
FactoryGirl Polymorphic Association
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Alert < ActiveRecord::Base | |
belongs_to :alertable, :polymorphic => true | |
end | |
class Region < ActiveRecord::Base | |
has_many :alerts, :as => :alertable | |
end | |
FactoryGirl.define do | |
Factory.define :alert do |alert| | |
alert.alertable { |a| a.association(:region) } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There is the fix form factory_bot documents
Polymorphic associations can be handled with traits:
This allows us to do: