Skip to content

Instantly share code, notes, and snippets.

@r00k
Created November 29, 2011 16:49
Show Gist options
  • Save r00k/1405490 to your computer and use it in GitHub Desktop.
Save r00k/1405490 to your computer and use it in GitHub Desktop.
class Cycle < ActiveRecord::Base
belongs_to :user
belongs_to :decision, polymorphic: true
validates :user_id, presence: true
validates :decision_id, presence: true
validates :decision_type, presence: true
validates :effective_at, presence: true
end
FactoryGirl.define do
#...
factory :rental do
product
end
factory :cycle do
user
decision rental
effective_at { Date.beginning_of_this_month }
end
end
class Rental < ActiveRecord::Base
has_one :cycle, as: :decision
belongs_to :product
end
@r00k
Copy link
Author

r00k commented Nov 29, 2011

Removing line 11 in factories.rb stops the error.

@r00k
Copy link
Author

r00k commented Nov 29, 2011

Just in case someone else finds this someday: the issue was the association in the cycle factory needed to be declared like

factory :cycle do
  user
  association :decision, factory: rental # this is the change
  effective_at { Date.beginning_of_month }
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment