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

Context helpers for callbacks: #1695

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

CodeMeister
Copy link

Fixes: #1694
Fixes: #1649

Context is provided as a block parameter in callbacks. This pull requests adds some helper methods to context, making it easier to detect the strategy used and identify which attributes were defined by the user / factory.

Methods included are:

  • :stategy
  • :defined_attributes
  • :user_defined_attributes
  • :factory_defined_attributes

All can be queried:

context.strategy         #=> 'build'
context.strategy.build?  #=> true

context.user_defined_attributes           #=> [:age, :name]
context.user_defined_attributes.age?      #=> true
context.user_defined_attributes.height?   #=> false

Although the Evaluator class is marked @api private, being included as a callback parameter means users are already accessing it. Making it easier to use can only be a good thing.

Tests and documentation added.

- :stategy
- :defined_attributes
- :user_defined_attributes
- :factory_defined_attributes
@CodeMeister
Copy link
Author

Hi @sarahraqueld & @smaboshe, any chance of reviewing the pull request?

I have another request ready to go, but it uses some of the same code from this one, so need this one approved (or rejected) first.

😄

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.

Make strategy used easier to detect in callbacks Expose which keys were overridden by the user
1 participant