FactoryGirl協會,我有以下的關聯 class Training < ApplicationRecord
has_many :attendances
has_many :attendees, through: :attendances
end
class Attendance < ApplicationRecord
belongs_to :trainin
假設我有以下Rails模型,並且顯示的方法已經過測試。現在 class Employee < ActiveRecord::Base
has_many :jobs
def total_annual_income
jobs.collect { |j| j.annual_salary}.sum
# Or some other AR magic to do it
無論何時我試圖運行rails db:migrate並且回溯似乎指向factory_girl的規格,我都會得到uninitialized constant ApplicationRecord。導致錯誤的確切行是 factory :test_user, class: User do
爲什麼會發生這種情況?在解析規範時,ApplicationRecord未被定義如何?我該如何解決它?
測試代碼: context 'validations' do
let(:super_campaign){FactoryGirl.create(:super_campaign)}
context 'package' do
it "Package should be present" do
expect(super_campaign.package).to be_val