2010-06-10 13:37:51 -04:00
|
|
|
require 'spec_helper'
|
2009-04-11 11:27:23 -04:00
|
|
|
|
2012-02-08 10:17:57 -05:00
|
|
|
describe FactoryGirl::Strategy::Stub do
|
2012-05-04 13:36:46 -04:00
|
|
|
it_should_behave_like "strategy with association support", :build_stubbed
|
2012-02-08 10:17:57 -05:00
|
|
|
it_should_behave_like "strategy with callbacks", :after_stub
|
2012-05-04 13:36:46 -04:00
|
|
|
it_should_behave_like "strategy with strategy: :build", :build_stubbed
|
2011-08-12 22:06:10 -04:00
|
|
|
|
2011-08-16 23:08:24 -04:00
|
|
|
context "asking for a result" do
|
2011-09-02 16:22:53 -04:00
|
|
|
before { Timecop.freeze(Time.now) }
|
2011-12-16 14:10:25 -05:00
|
|
|
let(:result_instance) do
|
|
|
|
define_class("ResultInstance") do
|
|
|
|
attr_accessor :id
|
|
|
|
end.new
|
|
|
|
end
|
|
|
|
|
2012-04-13 14:20:19 -04:00
|
|
|
let(:evaluation) { stub("evaluation", object: result_instance, notify: true) }
|
2011-09-02 16:22:53 -04:00
|
|
|
|
2013-01-18 13:27:57 -05:00
|
|
|
it { expect(subject.result(evaluation)).not_to be_new_record }
|
|
|
|
it { expect(subject.result(evaluation)).to be_persisted }
|
2011-08-12 22:06:10 -04:00
|
|
|
|
2011-09-02 16:22:53 -04:00
|
|
|
it "assigns created_at" do
|
2012-04-13 14:20:19 -04:00
|
|
|
created_at = subject.result(evaluation).created_at
|
2013-01-18 13:27:57 -05:00
|
|
|
expect(created_at).to eq Time.now
|
2011-09-02 16:22:53 -04:00
|
|
|
|
|
|
|
Timecop.travel(150000)
|
|
|
|
|
2013-01-18 13:27:57 -05:00
|
|
|
expect(subject.result(evaluation).created_at).to eq created_at
|
2011-09-02 16:22:53 -04:00
|
|
|
end
|
|
|
|
|
2014-03-13 12:44:24 -04:00
|
|
|
[:save, :destroy, :connection, :reload, :update_attribute, :update_column].each do |database_method|
|
2011-08-16 23:08:24 -04:00
|
|
|
it "raises when attempting to connect to the database by calling #{database_method}" do
|
|
|
|
expect do
|
2012-04-13 14:20:19 -04:00
|
|
|
subject.result(evaluation).send(database_method)
|
2014-03-13 12:44:24 -04:00
|
|
|
end.to raise_error(RuntimeError, "stubbed models are not allowed to access the database - #{subject.result(evaluation).class}##{database_method}()")
|
2011-08-12 22:06:10 -04:00
|
|
|
end
|
2009-04-28 10:39:32 -04:00
|
|
|
end
|
2014-11-18 01:20:51 -05:00
|
|
|
|
|
|
|
it "raises when attempting to connect to the database by calling reload with optional lock:true" do
|
|
|
|
expect do
|
|
|
|
subject.result(evaluation).reload(lock: true)
|
|
|
|
end.to raise_error(RuntimeError, "stubbed models are not allowed to access the database - #{subject.result(evaluation).class}#reload()")
|
|
|
|
end
|
|
|
|
|
2009-04-11 11:27:23 -04:00
|
|
|
end
|
|
|
|
end
|