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

73 lines
2.9 KiB
Ruby
Raw Normal View History

require 'spec_helper'
2009-04-11 11:27:23 -04:00
shared_examples "disabled persistence method" do |method_name|
let(:instance) { described_class.new.result(evaluation) }
describe "overriding persistence method: ##{method_name}" do
it "overrides the method with any arity" do
method = instance.method(method_name)
expect(method.arity).to eq(-1)
end
it "raises an informative error if the method is called" do
expect { instance.send(method_name) }.to raise_error(
RuntimeError,
"stubbed models are not allowed to access the database - #{instance.class}##{method_name}()",
)
end
end
end
2012-02-08 10:17:57 -05:00
describe FactoryGirl::Strategy::Stub do
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
it_should_behave_like "strategy with strategy: :build", :build_stubbed
2011-08-12 22:06:10 -04:00
context "asking for a result" do
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
let(:evaluation) { stub("evaluation", object: result_instance, notify: true) }
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 }
2017-01-15 08:26:03 -05:00
it { expect(subject.result(evaluation)).not_to be_destroyed }
2011-08-12 22:06:10 -04:00
it "assigns created_at" do
created_at = subject.result(evaluation).created_at
2013-01-18 13:27:57 -05:00
expect(created_at).to eq Time.now
Timecop.travel(150000)
2013-01-18 13:27:57 -05:00
expect(subject.result(evaluation).created_at).to eq created_at
end
include_examples "disabled persistence method", :connection
include_examples "disabled persistence method", :decrement
include_examples "disabled persistence method", :decrement!
include_examples "disabled persistence method", :delete
include_examples "disabled persistence method", :destroy
include_examples "disabled persistence method", :destroy!
include_examples "disabled persistence method", :increment
include_examples "disabled persistence method", :increment!
include_examples "disabled persistence method", :reload
include_examples "disabled persistence method", :save
include_examples "disabled persistence method", :save!
include_examples "disabled persistence method", :toggle
include_examples "disabled persistence method", :toggle!
include_examples "disabled persistence method", :touch
include_examples "disabled persistence method", :update
include_examples "disabled persistence method", :update!
include_examples "disabled persistence method", :update_attribute
include_examples "disabled persistence method", :update_attributes
include_examples "disabled persistence method", :update_attributes!
include_examples "disabled persistence method", :update_column
include_examples "disabled persistence method", :update_columns
2009-04-11 11:27:23 -04:00
end
end