class Proofreader < Role
has_many :proofreading_jobs, :class_name => 'ProofreadingJob', :foreign_key => 'proofreader_id'
end
class ProofreadingJob < ApplicationRecord
belongs_to :proofreader, class_name: 'Role', foreign_key: :proofreader_id, optional: true
belongs_to :client, class_name: 'Role', foreign_key: :client_id
end
class Role < ApplicationRecord
belongs_to :user
end
proofreaders factory:
FactoryBot.define do
factory :proofreader do
type { 'Proofreader'}
hourly_rate { 15 }
association :user, factory: :employee_user
factory :proofreader_with_work_events do
after :create do |proofreader|
create(:user_event, :recurring_mwf, user: proofreader.user)
end
end
end
end
spec / model_roles / proofreader_spec.rb
RSpec.describe 'Proofreader', type: :model do
describe "Associations" do
it { should have_many(:proofreading_jobs) }
end
end
Сбой теста с:
Failure/Error: it { should have_many(:proofreading_jobs) }
expected Associations to respond to `has_many?`
Очевидно, что класс ProofreadingJob имеет ассоциацию там.Как я могу написать этот тест, чтобы он прошел?