1
0
Fork 0
mirror of https://github.com/thoughtbot/factory_bot.git synced 2022-11-09 11:43:51 -05:00
thoughtbot--factory_bot/spec/factory_girl/strategy/stub_spec.rb

40 lines
1.3 KiB
Ruby
Raw Normal View History

require 'spec_helper'
2009-04-11 11:27:23 -04:00
2012-02-08 10:17:57 -05:00
describe FactoryGirl::Strategy::Stub do
it_should_behave_like "strategy with association support", FactoryGirl::Strategy::Stub
it_should_behave_like "strategy with callbacks", :after_stub
2012-03-09 17:20:38 -05:00
it_should_behave_like "strategy with strategy: :build", FactoryGirl::Strategy::Stub
2011-08-12 22:06:10 -04:00
context "asking for a result" do
before { Timecop.freeze(Time.now) }
after { Timecop.return }
2011-12-16 14:10:25 -05:00
let(:result_instance) do
define_class("ResultInstance") do
attr_accessor :id
end.new
end
let(:evaluation) { stub("evaluation", object: result_instance, notify: true) }
it { subject.result(evaluation).should_not be_new_record }
it { subject.result(evaluation).should be_persisted }
2011-08-12 22:06:10 -04:00
it "assigns created_at" do
created_at = subject.result(evaluation).created_at
created_at.should == Time.now
Timecop.travel(150000)
subject.result(evaluation).created_at.should == created_at
end
[:save, :destroy, :connection, :reload, :update_attribute].each do |database_method|
it "raises when attempting to connect to the database by calling #{database_method}" do
expect do
subject.result(evaluation).send(database_method)
end.to raise_error(RuntimeError, "stubbed models are not allowed to access the database")
2011-08-12 22:06:10 -04:00
end
end
2009-04-11 11:27:23 -04:00
end
end