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

17 commits

Author SHA1 Message Date
Daniel Colson
630aca4b87 Fix violations for latest version of standard 2021-02-20 17:22:31 -05:00
Daniel Colson
5f1a1de114 Run standardrb
This commit applies the changes from running `standardrb --fix`
2020-06-10 17:11:39 -04:00
Nate Holland
0e7c6e60f1
Run automatic cop fixes
This runs all of the automatic cops that came in since rubocop 0.68.
None of these changes were manual.
2020-01-17 14:43:34 -05:00
Oliver Peate
ecb56565a1 Use temporary assignment helper to silence deprecations in specs 2019-08-12 18:54:53 +01:00
Oliver Peate
7722017bc7 Adjust use_parent_strategy safely in specs
Uses a block-based helper so we can remove a global around hook.
2019-08-12 18:54:53 +01:00
Oliver Peate
05bf5a3713 Use sqlite in-memory DB in specs
https://www.sqlite.org/inmemorydb.html
2019-08-01 10:31:46 +01:00
Daniel Colson
5a3247dd8c Avoid stubbing id for records without primary key
Fixes #1305

Before Rails 6 when the build_stubbed strategy assigned an id on a
record without a primary key column, the `id=` method would no-op, and
the record would end up looking like a new_record (i.e. `new_record?`
would return true because the id was nil).

This problem surfaced because of a [change in Rails 6][rails], which
caused `id=` to raise a potentially confusing
`ActiveModel::MissingAttributeError: can't write unknown attribute ''`
for records without a primary key column.

Since build_stubbed stubbed was calling `id=` for all instances,
regardless of whether they had primary keys, it was raising the above
error.

To avoid this error, we check whether the instance has a primary_key
defined before setting the id.

We also changed `persisted?` and `new_record?` to be less dependent on
the id. That way those methods will work as expected for records without
primary keys.

[rails]: b6828fc915

Co-authored-by: Jesse Bailey <jbailey117@gmail.com>
2019-07-19 15:18:11 -04:00
kvokka
87d1b42ff5 Refactor define constant macros 2019-07-19 14:24:13 -04:00
Alejandro Dustet
99ac02400f Move and deprecate trait methods from FactoryBot
Why:
These are essentially internal methods that should not be publicly
available from the base namespace.
One thing worth noticing is that the use of this methods internally was
almost exclusively in the `syntax/default` except for one use on the
`factory_bot/definition`.
Also the deprecation silencing module was referring to the singleton
instance of the ```ActiveRecord::Deprecation``` class and not to the new
deprecation instance that was being used in the ```FactoryBot``` module.

This PR:
- Moves the `trait_by_name` and `register_trait` into the
`FactoryBot::Internal` module
- Deprecates uses of `trait_by_name`, `register_trait` and `traits` from
the `FactoryBot` module.
- Rename DEPRECATOR => Deprecation

This is one of the steps towards fixing [this
issue](https://github.com/thoughtbot/factory_bot/issues/1281)
2019-04-26 16:03:22 -04:00
Susan Wright
c22c9ab052 Rubocop: Fix Style/StringLiterals Offenses (#1216) 2018-10-07 21:45:51 -04:00
Hunter Braun
89ee4a4524 [Rubocop] Style Cop Offenses (#1208) 2018-10-07 18:02:54 -04:00
Hunter Braun
6a25e989b6 [Rubocop] Lint Cop Offenses (#1207) 2018-10-05 14:54:08 -04:00
Daniel Colson
c9989e99e0
Use dedicated methods for memoized values (#1211)
RuboCop didn't seem to like having memoization in the
`default_constants` method that didn't match the method name. This
satisfies RuboCop, and saves us an array allocation or two when we run
specs that don't use any of these helpers.
2018-10-05 11:19:48 -04:00
Julien Vanier
e84bfeba9b Deprecate factory lookup by class
This PR deprecates the ability to look up a factory based on class instead of symbol.

- The acceptance test `keyed_by_class_spec.rb` tests lookup by class
- Add flag `allow_class_lookup` (default `true`)
- Show a deprecation on class lookup warning when flag is true
- Raise an exception on class lookup when flag is false
- Silence deprecation warnings in tests

Fixes #871

Revert Hound formatting recommendation
2016-03-09 05:29:15 -05:00
Joshua Clayton
18a512576f Fix warnings
[Closes #463]
2013-01-18 13:58:14 -05:00
Joshua Clayton
6c29b11477 Use 1.9 hash syntax 2012-03-16 16:43:23 -04:00
Joshua Clayton
0b2c4da0a4 Move DefineConstant code into macro 2011-08-19 17:21:54 -04:00