Skip to content

Instantly share code, notes, and snippets.

@goganchic
Created November 23, 2011 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goganchic/1389720 to your computer and use it in GitHub Desktop.
Save goganchic/1389720 to your computer and use it in GitHub Desktop.
class Room < ActiveRecord::Base
has_many :auctions
end
class Auction < ActiveRecord::Base
belongs_to :room
validates :room, :presence => true
end
FactoryGirl.define do
factory :room do
group
factory :room_with_auctions do
after_build do |r|
r.auctions = [Factory.build(:auction, :room => nil)]
end
end
end
end
FactoryGirl.define do
factory :auction do
room
end
end
Failure/Error: let(:room) { Factory(:room_with_auctions) }
ActiveRecord::RecordInvalid:
Validation failed: Auctions is invalid
ree-1.8.7-2011.03 :005 > r = Factory(:room, :auctions => [a])
ActiveRecord::RecordInvalid: Validation failed: Auctions is invalid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment