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

Set use_parent_strategy default to true explicitly

The `default:` option of `mattr_accessor` wasn't added until Rails 5.2,
which means it has no effect on older versions and the default value of
`FactoryBot.use_parent_strategy` in 5.0.0.rc1 is nil on those versions.
This commit is contained in:
Eugene Kenny 2019-01-11 06:39:39 +00:00 committed by Daniel Colson
parent e3c65b197c
commit 54f37563cd
3 changed files with 17 additions and 2 deletions

View file

@ -57,7 +57,8 @@ module FactoryBot
@configuration = nil
end
mattr_accessor :use_parent_strategy, instance_accessor: false, default: true
mattr_accessor :use_parent_strategy, instance_accessor: false
self.use_parent_strategy = true
# Look for errors in factories and (optionally) their traits.
# Parameters:

View file

@ -17,4 +17,10 @@ describe FactoryBot do
FactoryBot.register_trait(trait)
expect(FactoryBot.trait_by_name(trait.name)).to eq trait
end
describe ".use_parent_strategy" do
it "is true by default" do
expect(FactoryBot.use_parent_strategy).to be true
end
end
end

View file

@ -20,13 +20,21 @@ RSpec.configure do |config|
config.before do
FactoryBot.reload
FactoryBot.use_parent_strategy = true
end
config.after do
Timecop.return
end
config.around do |example|
begin
previous_use_parent_strategy = FactoryBot.use_parent_strategy
example.run
ensure
FactoryBot.use_parent_strategy = previous_use_parent_strategy
end
end
config.order = :random
Kernel.srand config.seed