2011-08-10 16:26:29 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe "a stubbed instance" do
|
|
|
|
include FactoryGirl::Syntax::Methods
|
|
|
|
|
|
|
|
before do
|
|
|
|
define_model('User')
|
|
|
|
|
2012-03-09 17:20:38 -05:00
|
|
|
define_model('Post', user_id: :integer) do
|
2011-08-10 16:26:29 -04:00
|
|
|
belongs_to :user
|
|
|
|
end
|
|
|
|
|
|
|
|
FactoryGirl.define do
|
|
|
|
factory :user
|
|
|
|
|
|
|
|
factory :post do
|
|
|
|
user
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { build_stubbed(:post) }
|
|
|
|
|
|
|
|
it "acts as if it came from the database" do
|
|
|
|
should_not be_new_record
|
|
|
|
end
|
|
|
|
|
|
|
|
it "assigns associations and acts as if it is saved" do
|
2013-01-18 13:27:57 -05:00
|
|
|
expect(subject.user).to be_kind_of(User)
|
|
|
|
expect(subject.user).not_to be_new_record
|
2011-08-10 16:26:29 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-02-17 11:29:11 -05:00
|
|
|
describe "a stubbed instance overriding strategy" do
|
2011-08-10 16:26:29 -04:00
|
|
|
include FactoryGirl::Syntax::Methods
|
|
|
|
|
2012-03-09 15:42:28 -05:00
|
|
|
before do
|
|
|
|
define_model('User')
|
2012-03-09 17:20:38 -05:00
|
|
|
define_model('Post', user_id: :integer) do
|
2012-03-09 15:42:28 -05:00
|
|
|
belongs_to :user
|
2011-08-10 16:26:29 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
FactoryGirl.define do
|
|
|
|
factory :user
|
|
|
|
|
|
|
|
factory :post do
|
2012-03-09 17:20:38 -05:00
|
|
|
association(:user, strategy: :build)
|
2011-08-10 16:26:29 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-03-09 15:42:28 -05:00
|
|
|
subject { build_stubbed(:post) }
|
2012-02-17 11:29:11 -05:00
|
|
|
|
2012-03-09 15:42:28 -05:00
|
|
|
it "acts as if it is saved in the database" do
|
|
|
|
should_not be_new_record
|
2011-08-10 16:26:29 -04:00
|
|
|
end
|
|
|
|
|
2012-03-09 15:42:28 -05:00
|
|
|
it "assigns associations and acts as if it is saved" do
|
2013-01-18 13:27:57 -05:00
|
|
|
expect(subject.user).to be_kind_of(User)
|
|
|
|
expect(subject.user).not_to be_new_record
|
2012-02-17 11:29:11 -05:00
|
|
|
end
|
2011-08-10 16:26:29 -04:00
|
|
|
end
|