[Fix #80] Ability to preserve traits #83
Conversation
end | ||
|
||
def set_factory_default(name, obj) | ||
FactoryDefault.register(name, obj) | ||
def set_factory_default(name, obj, preserve_traits = nil) |
palkan
Jun 28, 2018
Collaborator
Let's make it a keyword argument and pass it as .register(name, obj, options)
. We'll probably have more options in the future.
Let's make it a keyword argument and pass it as .register(name, obj, options)
. We'll probably have more options in the future.
def register(name, obj, preserve_traits = nil) | ||
unless FactoryDefault.preserve_traits | ||
@store_preserve_traits[name] ||= true if preserve_traits | ||
end | ||
store[name] = obj |
palkan
Jun 28, 2018
Collaborator
What about storing the options along with the object itself, i.e.:
store[name] = { record: obj, **options}
What about storing the options along with the object itself, i.e.:
store[name] = { record: obj, **options}
Vasfed
Jun 28, 2018
Author
Contributor
First thought was to save some hash allocations, but agree, no point in chasing those several dozens additional hashes, also if we decide to make some default-for-trait-objects they can be stored in the same hash under special keys.
First thought was to save some hash allocations, but agree, no point in chasing those several dozens additional hashes, also if we decide to make some default-for-trait-objects they can be stored in the same hash under special keys.
@@ -6,6 +6,6 @@ | |||
specify "RSpec integration", :aggregate_failures do | |||
output = run_rspec('factory_default') | |||
|
|||
expect(output).to include("5 examples, 0 failures") | |||
expect(output).to include(" examples, 0 failures") |
palkan
Jun 28, 2018
Collaborator
?
?
Vasfed
Jun 28, 2018
Author
Contributor
here we are interested more in the spec passing, thought it is redundant to update test count each time the fixture spec has a test added, restored to explicit count
here we are interested more in the spec passing, thought it is redundant to update test count each time the fixture spec has a test added, restored to explicit count
@palkan please see new commit |
if traits && !traits.empty? | ||
return false if FactoryDefault.preserve_traits || @store_preserve_traits[name] | ||
return nil if FactoryDefault.preserve_traits || record[:preserve_traits] |
palkan
Jun 28, 2018
Collaborator
Unnecessary nil
Unnecessary nil
Vasfed
Jun 28, 2018
Author
Contributor
Enabled rubocop to check for that
Enabled rubocop to check for that
record[:object] | ||
end | ||
|
||
def exists?(name, traits = nil) |
palkan
Jun 28, 2018
Collaborator
Do we use exists?
anywhere?
Do we use exists?
anywhere?
Vasfed
Jun 28, 2018
Author
Contributor
No, we don't, can be safely removed - left it for compatibility. It was public and appeared in generated documentation, someone could have used it for some test suite debugging. (sure I doubt it too)
No, we don't, can be safely removed - left it for compatibility. It was public and appeared in generated documentation, someone could have used it for some test suite debugging. (sure I doubt it too)
palkan
Jun 28, 2018
Collaborator
Let's remove then
Let's remove then
Vasfed
Jun 28, 2018
Author
Contributor
Ok, done
Ok, done
Thanks! Great job! |
Hey @Vasfed! Could you please send me your actual email address to |
@palkan Hey! Sent email, e064395fd8a88d6d6c887132d7e1e39035e841a12fc6c5f28cc348ffb4c62b16 |
Fixes #80.
This adds option to
TestProf::FactoryDefault
to revert to default behaviour when factories have traits for association.