Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Namespaced models and deprecation warnings by class lookup #1130

Closed
michaelfich opened this issue May 15, 2018 · 5 comments
Closed

Namespaced models and deprecation warnings by class lookup #1130

michaelfich opened this issue May 15, 2018 · 5 comments

Comments

@michaelfich
Copy link

I have models which are namespaced such as this:

class Vehicle < ActiveRecord::Base; end

class Vehicle::Car < Vehicle; end
class Vehicle::Train < Vehicle; end
class Vehicle::Jet < Vehicle; end

When creating factories for these models, they were set up in the following way:

factory :vehicle_car, class: Vehicle::Car do; end
factory :vehicle_train, class: Vehicle::Train do; end
factory :vehicle_jet, class: Vehicle::Jet do; end

This produces the following deprecation warning:

DEPRECATION WARNING: Looking up factories by class is deprecated and will be removed in 5.0. Use symbols instead and set FactoryBot.allow_class_lookup = false.

Is there a format for writing a symbol to name these factories such that I do not need to use the class name to comply with the deprecation warning?

@korotindev
Copy link

korotindev commented Jun 2, 2018

Could anyone pay attention to this issue, please?
It is important for my current project. 😄

@michaelfich
Copy link
Author

@soxat after posting here, i noticed that this repo doesn't have very expedient replies so i tried stackoverflow to see if anyone could help there. here's that post:

https://stackoverflow.com/questions/50437961/factorybot-namespaced-models-without-class-name

in FactoryBot 4.10 its viable to add the class name as a string, so instead of Vehicle::Car (from my example above) you could simply do 'vehicle/car' which seems to work without deprecation warnings.

@korotindev
Copy link

@michaelfich Thanks!

@composerinteralia
Copy link
Collaborator

Thanks for the help. I am going to leave this issue open because there is definitely room for documentation improvements here.

@composerinteralia
Copy link
Collaborator

I added some documentation for using strings instead of classes in ef5c4ba

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants