Closed nroose closed 1 month ago
Which cop is the topic about?
Oh, sorry. FactoryBot/IdSequence
Sorry, can you please be more specific?
What are your tests like? records = create_list(:record, 10); first = Record.find(1)
?
Honestly, I am not really sure why or what is happening. We are getting failures just in the factorybot code itself.
undefined method `id' for an instance of FactoryBot::SyntaxRunner
The cop in question suggests removing the sequence :id
, right?
Are you saying that this removal is causibg such an error?
I’m puzzled, how this can happen?
At this point we’ll need more evidence to take any action. Are you willing to provide a reproduction example in a form of a repository or a runnable self-contained script?
Well, after doing that, I am not sure it's worth it to you, but https://github.com/nroose/autocorrect/blob/main/spec/factories.rb.
I don’t know what issue first_or_initialize
is supposed to solve, but it is inherently non-deterministic, and this hints abount non-canonical use of factories.
I suggest you to turn the cop off, or to fix specs to behave deterministically.
My guess is that it’s to implement a fixtures-like aapproach. And to save on the expensive setup before each example. There are better approaches to that, specifically fixtures themselves, or test-prof’s ‘before_all’ and ‘let_it_be’.
This is labeled as safe autocorrect? It's definitely not safe for us. Perhaps it is important, and a great idea to adhere to, and maybe if you don't set the start id, it's safe. But it's definitely breaking all the tests it updates for us. We have legacy tests that do set the sequence for the id and use it accordingly. And it would be a bunch of work to re-work that, which we, in our infinite wisdom have decided not to do.