I am switching old systems created with php to Rails.
I want to use the table ‘servicename_user’ of the previous system in the User model.
There is no problem with the console or controller, but when I try to create the rspec test, I get the following error message:
Failure/Error: it { should validate_presence_of(:email) }
LoadError:
Unable to autoload constant USER, expected /Users/injung/Github/api/app/models/user.rb to define it
``
However, my user.rb file is located exactly where the error message was mentioned.
For reference, the test was written as follows.
require_relative ‘…/…/app/models/user’
describe User, type: :model do
context ‘validation’ do
it { should validate_presence_of(:author) }
it { should validate_presence_of(:email) }
end
end
``
The user model is as follows.
class User < ApplicationRecord
self.table_name = ‘servicename_user’
end
``
After some search, I found out that If my table name is servicename_user, my user model should be in app/models/servicename/user, but I do not want to do like this. Is there any good way?
It is difficult to change the table name because it references a lot on older systems.