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

13 commits

Author SHA1 Message Date
Josh Clayton
1b81d5dc25
Fix strategy tracking through associations
What?
=====

Within FactoryBot::Evaluator, the build strategy was reported either as
a class OR symbol.

A side-effect of this is misreporting within
ActiveSupport::Notifications hooks, since the instrumentation payload
may have strategies listed as e.g. `:create` or
`FactoryBot::Strategy::Create`, even though they semantically represent
the same information.

This introduces a new instance method for all strategies, `to_sym`,
to be called rather than `class`.
2022-03-07 21:23:47 -05:00
Peter Goldstein
b7eb4db87c
Add Ruby 3.1 and Rails 7 to CI (#1526)
This PR adds the Ruby 3.1 and Rails 7 elements to the CI matrix.  To support those changes a number of other changes were required:

- Adding a basic Rails 7 Gemfile and updating `Appraisals`
- Quoting 3.0 in the `.github/workflows/build.yml` file so that this entry pulls Ruby 3.0.x and not Ruby 3.1
- Adding the "--disable-error_highlight" value for RUBYOPT in the build environment to disable Ruby 3.1 error highlighting
- Bumping the version of `standard` and configuring it to run against our oldest supported version
2022-01-14 15:08:08 -05:00
Benoit Daloze
6f3fe876f8 Fix delegation
* (*args, **kwargs) is incorrect in 2.7, only ruby2_keywords works on 2.7.
* See https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/
2021-05-07 10:21:12 -04:00
Daniel Colson
ebc4cd5b84 Make the evaluator instance public
closes #1309

It has come up several times over the years that folks want direct
access to the evaluator instance, in most cases to build up more complex
networks of associations. Some folks are already doing this with the
less public `@instance` instance variable.

Given that this is such a minimal change, and it makes the library more
flexible for these more complex use cases, this commit adds an
`attr_reader` for the evaluator instance. Now folks can reference it
without reaching into the private api.

Documentation to follow as part of
https://github.com/thoughtbot/factory_bot/issues/1268
2020-07-08 12:41:06 -04:00
Adam Hess
5c071d42fd Fix ruby 2.7 kwargs warning
Ruby 2.7 deprecated passing kwargs when the method expects a hash or passing a hash when the method expects kwargs. In factory_bot, this creates the warning:

```
/Users/hparker/code/factory_bot/lib/factory_bot/decorator/new_constructor.rb:9: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
/Users/hparker/code/factory_bot/spec/acceptance/initialize_with_spec.rb:220: warning: The called method `initialize' is defined here
```

We can fix this warning by updating the syntax. We need to include `**kwargs` in the `method_missing` calls when we are on ruby 2.7 or later.
In decorator.rb, adding `**kwargs` alone doesn't work since adding `**kwargs` can change what arguments remain in the `args`.

In this case we have to class eval the method if we are running ruby 2.7. This way the syntax is valid in previous versions and we can use the `...` operator which allows us to avoid changing the arguments passed on in method missing.

Co-authored-by: Lee Quarella <leequarella@gmail.com>
2020-06-24 18:27:38 -04:00
Daniel Colson
5f1a1de114 Run standardrb
This commit applies the changes from running `standardrb --fix`
2020-06-10 17:11:39 -04:00
Daniel Colson
102d7f7606 Prepare for factory_bot 6
Closes #1336

* removes all the deprecated methods
* removes Ruby 2.3, 2.4 and Rails 4.2 from travis
* bundle updates the test gemfiles
* Removes some pre-5.0 logic from a test helper
* Targets Ruby 2.5 with rubocop and fixes violations

We could also remove support for Rails 5.0 and 5.1, which are now EOL,
but I don't see a strong reason to do that. We don't seem to have to do
anything special to support those versions.
2020-05-01 17:43:10 -04:00
Nate Holland
cef7ec75b8
Adjust for split from Style/MethodMissing into two cops
In this PR the cop Style/MethodMissing was split into
Style/MethodMissingSuper and Style/MissingRespondToMissing.
https://github.com/rubocop-hq/rubocop/pull/5811

This commit goes through the disables and updates them to reflect the
appropriate new Cops.
2020-01-17 14:43:34 -05:00
Eugene Kenny
e7ddcbccc5 Only undefine methods that were previously defined
In 241e8e5fb4, this call to `undef_method`
was introduced to suppress the warning printed by Ruby when a method is
redefined.

That warning is only printed when the method is already defined on the
class in question; it isn't printed when the method was inherited from
an ancestor, since overriding methods by shadowing them is a feature.

However, `method_defined?` returns true for inherited methods, which
means we're sometimes undefining methods that wouldn't cause a warning.

If a factory defines an attribute named `object_id` (admittedly not a
great idea), we will undefine the `object_id` method inherited from the
`Object` class, and the following warning will be printed:

    factory_bot/evaluator.rb:70: warning: undefining `object_id' may cause serious problems

By only undefining the method if it's defined on the current class, we
can avoid undefining inherited methods and triggering this warning.
2019-03-22 10:30:08 -04:00
Claire
c71aded778
Inline disabling Style/MethodMissing Cop
To make it obvious that these are non-standard cases.

Also add respond_to_missing? to the decorator.

We are using Style/MethodMissing rather than
Style/MethodMissingSuper and Style/MissingRespondToMissing because we
are still on RuboCop 0.54.
2018-11-12 15:01:23 -08:00
Susan Wright
c22c9ab052 Rubocop: Fix Style/StringLiterals Offenses (#1216) 2018-10-07 21:45:51 -04:00
Hunter Braun
6a25e989b6 [Rubocop] Lint Cop Offenses (#1207) 2018-10-05 14:54:08 -04:00
Avielle
c716ce01b4 Replace 'girl' with 'bot' everywhere (#1051)
Also: add a deprecation warning to factory_girl, asking users to switch to
factory_bot

https://github.com/thoughtbot/factory_girl/issues/921
2017-10-20 15:20:28 -04:00
Renamed from lib/factory_girl/evaluator.rb (Browse further)