Commit Graph

17 Commits

Author SHA1 Message Date
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
Daniel Colson 8e7e339323
Name first arg of DefinitionProxy#method_missing
This code was a bit confusing before this change.

The only time we care about `args.first` is if we are creating an
association, so this PR gives `args.first` the name
`association_options` to reflect that.

The PR also pulls out a predicate method to give a name to the step of
validating that `args.first` are in indeed association options.
2019-04-26 12:47:12 -04:00
Daniel Colson f898371f8f
Improve error for static attribute attempts
Some people upgrade straight from factory_bot < 4.11 to factory_bot >=
5.0 and miss the deprecation cycle for static attributes. I have gotten
some feedback that the NoMethodError is confusing. Since we know that in
most cases people are seeing the NoMethodError when trying to define
static attributes, we offer them a "Did you mean?"-style suggestion for
how they might update to dynamic attributes.

I removed the extra test for setter methods. It was a remnant of
something I had removed in #1200. I see no reason to have special
treatment for setters at this point.

Closes https://github.com/thoughtbot/factory_bot/issues/1272
2019-04-26 12:47:12 -04:00
Daniel Colson 79331a3863 Allow inline sequences in traits to have same name
Fixes #1257

When sequence rewinding was first introduced in #1078 it only applied to
globally defined sequences. To get rewinding to work for inline
sequences as well we registered them "privately" in the global registry
in #1164. Unfortunately in #1164 we did not take inline sequences inside
traits into consideration. Since trait names are not unique, it is
possibly to get a `FactoryBot::DuplicateDefinitionError` when defining
two sequences that have the same name in two traits that have the same
name.

This PR abandons the idea of "privately" registering inline sequences,
and instead keeps a separate list of all the inline sequences just for
the purpose of rewinding them.
2019-02-15 17:10:27 -05:00
Daniel Colson cb9eb551c8
Arrest lines of an unsavory length
We had configured RuboCop to allow lines with up to 142 characters. This
PR fixes a few of the worst offenders so we can bring that number down
to 110.
2018-12-12 11:05:13 -05:00
Daniel Colson 6afa639804
Improve documentation around implicit attributes
[skip ci]

Closes #1017
2018-11-25 22:16:22 -05: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
Jared Beck bfeec78f29 Raise helpful error block given to association
Closes #1033

> Arguably, association should raise and let the developer know
> they're using it in an unexpected way. I'd love to see a PR for
> that (with a test!), so if you're interested in contributing that,
> please do!
> https://github.com/thoughtbot/factory_girl/issues/1032#issuecomment-329297006

Co-authored-by: Daniel Colson <danieljamescolson@gmail.com>
2018-10-28 19:12:34 -04:00
Hunter Braun 89ee4a4524 [Rubocop] Style Cop Offenses (#1208) 2018-10-07 18:02:54 -04:00
Daniel Colson 512ebf938f Manually raise NoMethodError in definition proxy
Inside `super` Ruby calls `inspect`, but since we have undefined
`inspect` on the definition proxy we end up declaring an implicit
`inspect` attribute. We do the same thing with `methods` and
`singleton_methods`, and then `inspect` again. By the time we finally
see the NoMethodError, we see it on a
`FactoryBot::Declaration::Implicit` instead of the definition proxy.

By raising the NoMethodError manually we avoid this nonsense and have
the added benefit of showing the name of the factory where the missing
method came from.
2018-09-28 15:57:58 -04:00
Daniel Colson f69220678a Update documentation for adding attributes
I am leaving the Static Attributes section in the README for now, since
it might still be helpful for people upgrading, but I took out the
example because I don't want to show invalid code.

I removed reference to static attributes in the definition_proxy
documentation, and updated the signature of add_attributes. I also
got rid of the bit about yielding a FactoryBot::Strategy, which is not
correct. We document correctly in the GETTING_STARTED that we yield an
evaluator instance.
2018-09-14 19:27:13 +00:00
Daniel Colson 805933eed2 Remove static attributes from the definition proxy
This changes the signature of `add_attribute`, so if you pass a value at
all you will now get an `ArgumentError`. Any `method_missing`-style
static attribute definitions will become `NoMethodError`s.
2018-09-14 19:27:13 +00:00
Daniel Colson bc11d13c0f Remove deprecated methods
Since we have started work on factory_bot 5, we no longer need to keep
these deprecated methods around.
2018-09-14 18:58:03 +00:00
Daniel Colson f1d7ae3cc1 Register inline sequence to allow for rewinding
This was originally opened as #1078, but this addresses the review
comments on that PR.

By registering the inline sequences, we allow them to get rewound with
`FactoryBot.rewind_sequences`. We register them with
`__#{factory_name}_#{sequence_name}__` to avoid conflicting with any
reasonably named global sequences, and to hint that we should not be
generating values from these sequences directly.

Co-authored-by: Damian Le Nouaille <dam@dln.name>
Co-authored-by: Damian Galarza <galarza.d@gmail.com>
2018-09-08 02:29:30 +00:00
Daniel Colson dabacdace6 Include rubocop-rspec autocorrect in deprecation
Fixes #1160

https://github.com/rubocop-hq/rubocop-rspec/pull/666 was merged. I
would like to wait until the next version version of rubocop-rspec is
released, then release factory_bot 4.11 with this deprecation.
2018-08-15 10:19:06 -04:00
Oliver Peate 91d3fd9ca4 Deprecate static attributes (#1135)
For further background on the motivation behind this change, see this commit: eaf2b40
2018-08-01 17:45:38 -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/definition_proxy.rb (Browse further)