Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

john-h-k
Copy link

@john-h-k john-h-k commented Feb 8, 2023

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)

Copy link
Collaborator

@palkan palkan left a 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)
Copy link
Collaborator

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)
Copy link
Collaborator

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)
Copy link
Collaborator

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.

@palkan palkan force-pushed the master branch 3 times, most recently from f6d4418 to 3dfe1cf Compare November 15, 2023 01:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants