New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add FactoryBot.get_factory_default #262
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR!
This is useful feature; let's just polish the API a bit (see the comments).
@@ -168,6 +168,10 @@ def set_factory_default(name, obj, preserve_traits: FactoryDefault.config.preser | |||
) | |||
end | |||
|
|||
def get_factory_default(name, *args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's call it #fetch_factory_default
@@ -168,6 +168,10 @@ def set_factory_default(name, obj, preserve_traits: FactoryDefault.config.preser | |||
) | |||
end | |||
|
|||
def get_factory_default(name, *args) | |||
FactoryDefault.get(name, args, args.extract_options!, false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can't we use *args, **kwargs
instead of #extract_options!
? No need to support legacy Hash-to-kwarg conversion, it's a new API method.
@@ -236,7 +240,7 @@ def register(name, obj, **options) | |||
obj | |||
end | |||
|
|||
def get(name, traits = nil, overrides = nil) | |||
def get(name, traits = nil, overrides = nil, write_stats = true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's rename to skip_stats
and turn this option into a keyword argument.
f6d4418
to
3dfe1cf
Compare
Adds a
FactoryBot.get_factory_default
method that allows users to retrieve the default for a given setup. Useful in cases where the factory default is desired but the record isn't directly created through factory bot (such as an after build hook)