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

Stub out ActiveRecord::Base#persisted?

This commit is contained in:
Bradley Priest 2017-01-15 21:26:03 +08:00 committed by Joshua Clayton
parent 5312fad41d
commit 168bbf8e34
No known key found for this signature in database
GPG key ID: 5B6558F77E9A8118
2 changed files with 5 additions and 2 deletions

View file

@ -10,7 +10,6 @@ module FactoryGirl
:delete,
:destroy!,
:destroy,
:destroyed?,
:increment!,
:increment,
:reload,
@ -58,6 +57,10 @@ module FactoryGirl
id.nil?
end
def destroyed?
nil
end
DISABLED_PERSISTENCE_METHODS.each do |write_method|
define_singleton_method(write_method) do |*args|
raise "stubbed models are not allowed to access the database - #{self.class}##{write_method}(#{args.join(",")})"

View file

@ -36,6 +36,7 @@ describe FactoryGirl::Strategy::Stub do
it { expect(subject.result(evaluation)).not_to be_new_record }
it { expect(subject.result(evaluation)).to be_persisted }
it { expect(subject.result(evaluation)).not_to be_destroyed }
it "assigns created_at" do
created_at = subject.result(evaluation).created_at
@ -52,7 +53,6 @@ describe FactoryGirl::Strategy::Stub do
include_examples "disabled persistence method", :delete
include_examples "disabled persistence method", :destroy
include_examples "disabled persistence method", :destroy!
include_examples "disabled persistence method", :destroyed?
include_examples "disabled persistence method", :increment
include_examples "disabled persistence method", :increment!
include_examples "disabled persistence method", :reload