2010-11-12 15:58:25 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
require 'acceptance/acceptance_helper'
|
|
|
|
|
|
|
|
describe "a created instance" do
|
2011-01-19 19:47:49 -05:00
|
|
|
include FactoryGirl::Syntax::Methods
|
|
|
|
|
2010-11-12 15:58:25 -05:00
|
|
|
before do
|
|
|
|
define_model('User')
|
|
|
|
|
|
|
|
define_model('Post', :user_id => :integer) do
|
|
|
|
belongs_to :user
|
|
|
|
end
|
|
|
|
|
|
|
|
FactoryGirl.define do
|
|
|
|
factory :user do
|
|
|
|
end
|
|
|
|
|
|
|
|
factory :post do
|
|
|
|
user
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-01-19 19:47:49 -05:00
|
|
|
subject { create('post') }
|
2010-11-12 15:58:25 -05:00
|
|
|
|
|
|
|
it "saves" do
|
|
|
|
should_not be_new_record
|
|
|
|
end
|
|
|
|
|
|
|
|
it "assigns and saves associations" do
|
|
|
|
subject.user.should be_kind_of(User)
|
|
|
|
subject.user.should_not be_new_record
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-11-12 16:21:16 -05:00
|
|
|
describe "a custom create" do
|
2011-01-19 19:47:49 -05:00
|
|
|
include FactoryGirl::Syntax::Methods
|
|
|
|
|
2010-11-12 16:21:16 -05:00
|
|
|
before do
|
|
|
|
define_class('User') do
|
|
|
|
def initialize
|
|
|
|
@persisted = false
|
|
|
|
end
|
|
|
|
|
|
|
|
def persist
|
|
|
|
@persisted = true
|
|
|
|
end
|
|
|
|
|
|
|
|
def persisted?
|
|
|
|
@persisted
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
FactoryGirl.define do
|
|
|
|
factory :user do
|
|
|
|
to_create do |user|
|
|
|
|
user.persist
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "uses the custom create block instead of save" do
|
2011-01-26 20:55:06 -05:00
|
|
|
FactoryGirl.create(:user).should be_persisted
|
2010-11-12 16:21:16 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|