mirror of
https://github.com/thoughtbot/factory_bot.git
synced 2022-11-09 11:43:51 -05:00
Do not raise error for valid build_stubbed methods
decrement, increment, and toggle do not persist the toggled values, so there is not reason to disable those methods. Co-authored-by: Alex Tsui <alextsui05@gmail.com>
This commit is contained in:
parent
5191056e1c
commit
3db8a120ba
3 changed files with 26 additions and 9 deletions
|
@ -6,17 +6,14 @@ module FactoryBot
|
|||
DISABLED_PERSISTENCE_METHODS = [
|
||||
:connection,
|
||||
:decrement!,
|
||||
:decrement,
|
||||
:delete,
|
||||
:destroy!,
|
||||
:destroy,
|
||||
:increment!,
|
||||
:increment,
|
||||
:reload,
|
||||
:save!,
|
||||
:save,
|
||||
:toggle!,
|
||||
:toggle,
|
||||
:touch,
|
||||
:update!,
|
||||
:update,
|
||||
|
|
|
@ -7,7 +7,8 @@ describe "a generated stub instance" do
|
|||
define_model('Post', title: :string,
|
||||
body: :string,
|
||||
age: :integer,
|
||||
user_id: :integer) do
|
||||
user_id: :integer,
|
||||
draft: :boolean) do
|
||||
belongs_to :user
|
||||
end
|
||||
|
||||
|
@ -77,13 +78,35 @@ describe "a generated stub instance" do
|
|||
expect { subject.save }.to raise_error(RuntimeError)
|
||||
end
|
||||
|
||||
it "disables increment" do
|
||||
it "disables increment!" do
|
||||
expect { subject.increment!(:age) }.to raise_error(RuntimeError)
|
||||
end
|
||||
|
||||
it "disables decrement" do
|
||||
it "disables decrement!" do
|
||||
expect { subject.decrement!(:age) }.to raise_error(RuntimeError)
|
||||
end
|
||||
|
||||
it "disables toggle!" do
|
||||
expect { subject.toggle!(:draft) }.to raise_error(RuntimeError)
|
||||
end
|
||||
|
||||
it "allows increment" do
|
||||
subject.age = 1
|
||||
subject.increment(:age)
|
||||
expect(subject.age).to eq(2)
|
||||
end
|
||||
|
||||
it "allows decrement" do
|
||||
subject.age = 1
|
||||
subject.decrement(:age)
|
||||
expect(subject.age).to eq(0)
|
||||
end
|
||||
|
||||
it "allows toggle" do
|
||||
subject.draft = true
|
||||
subject.toggle(:draft)
|
||||
expect(subject).not_to be_draft
|
||||
end
|
||||
end
|
||||
|
||||
describe "calling `build_stubbed` with a block" do
|
||||
|
|
|
@ -48,17 +48,14 @@ describe FactoryBot::Strategy::Stub do
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue