djezzzl / factory_trace

Simple tool to maintain factories and traits from FactoryBot
MIT License
381 stars 7 forks source link

Fixed unused factory processor to support aliases #5

Closed dmitry-ilyashevich closed 5 years ago

dmitry-ilyashevich commented 5 years ago

Unused factory processor fails on factory aliases

Factory example to reproduce:

FactoryBot.define do
  factory :user, aliases: %i[author] do
    email                 { Faker::Internet.email }
  end
end

FactoryBot.define do
  factory :post do
    author

    title { 'Title' }
  end
end

got:

NoMethodError:
  undefined method `parent_name' for nil:NilClass
djezzzl commented 5 years ago

Hi @dmitry-ilyashevich , thank you for pointing this out!

Let's polish a bit the PR and I'll merge it 👍

BTW, I bit misunderstand why the error is happening. I'll try to reproduce it.

dmitry-ilyashevich commented 5 years ago

@djezzzl I believe it fails with aliases because it try to find factory by name, not by one of the names https://github.com/djezzzl/factory_trace/pull/5/files#diff-3ed8df2bd98b9999e8ac5ca6e6787c7bL106

djezzzl commented 5 years ago

If you're out of time, I can merge as it is because you fix a problem and then can do small fixes myself.

WDYT?

dmitry-ilyashevich commented 5 years ago

@djezzzl My goal is to get this work, but I have some free time to polish. So any option is OK for me.

djezzzl commented 5 years ago

Okay, then the last thing I'd like to ask you is:

Check spec/factories.rb file and your case there. Then you'll have some specs are failing but the main idea is to cover this situation for everything: processors/preprocessors/writers/readers/converts/trackers.

Then we're fully done 👍 Let me know if you'll try to do so. If not, I just merge and finish that part myself.

djezzzl commented 5 years ago

Well done 👍 I'll review and release it today.

djezzzl commented 5 years ago

@dmitry-ilyashevich Could you please have a look at this PR: https://github.com/djezzzl/factory_trace/pull/6. Try it for your project and say if it helps?

Support of indirect usage will be fixed in this branch soon https://github.com/djezzzl/factory_trace/tree/catch-indirectly-used-traits:

factory :post

factory :comment do
  post
end

build(:comment) => # post is actually used, but for now it will be showed as not used 
djezzzl commented 5 years ago

This spec shows it should help: https://github.com/djezzzl/factory_trace/pull/6/files#diff-84f01422b671cb52407e0b7a8518d309R25