alexandernst alexandernst - 1 month ago 18
Ruby Question

uninitialized constant ApplicationRecord caused by factory girl?

I get

uninitialized constant ApplicationRecord
whenever I try to run
rails db:migrate
and the backtrace seems to be pointing to a spec of
factory_girl
. The exact line that causes the error is

factory :test_user, class: User do


Why is that happening? How is that
ApplicationRecord
isn't defined when that spec is parsed? How can I fix it?

Answer

Since Rails 5 a model file application_record.rb with class ApplicationRecord is generated. Every new model should inherit from that class instead of ActiveRecord::Base to prevent mokey patching of ActiveRecord::Base. ApplicationRecord is the new entry point for extensions.

Comments