-
-
Save jcf/569812 to your computer and use it in GitHub Desktop.
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
Factory.define :post do |post_factory| | |
post_factory.user { Factory.build(:user) } | |
end |
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 Post < ActiveRecord::Base | |
belongs_to :user | |
validates_presence_of :user_id | |
end |
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
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