Skip to content

Instantly share code, notes, and snippets.

@jcf
Forked from jferris/factories.rb
Created September 8, 2010 08:25
Show Gist options
  • Save jcf/569812 to your computer and use it in GitHub Desktop.
Save jcf/569812 to your computer and use it in GitHub Desktop.
Factory.define :post do |post_factory|
post_factory.user { Factory.build(:user) }
end
class Post < ActiveRecord::Base
belongs_to :user
validates_presence_of :user_id
end
describe Post, "factory" do
subject { Factory.build(:post) }
it { should_not be_valid }
end
describe Post, "valid factory with stubbed ID" do
subject { Factory.build(:post, :user_id => 1) }
it { should be_valid }
end
describe Post, "valid factory with created association" do
subject { Factory.build(:post, :user => Factory.create(:user)) }
it { should be_valid }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment