【发布时间】:2016-04-08 10:30:38
【问题描述】:
我收到以下错误:
1) Admin should belong to hospital
Failure/Error: it {should belong_to(:hospital).with_foreign_key('medical_facility_id') }
Expected Admin to have a belongs_to association called hospital ()
与:
#admin_spec.rb
it {should belong_to(:hospital).with_foreign_key('medical_facility_id') }
型号是:
class Admin < ActiveRecord::Base
belongs_to :hospital
end
class Hospital < MedicalFacility
end
在schema.rb:
create_table "admins", force: :cascade do |t|
t.integer "user_id", null: false
t.string "role", null: false
t.integer "medical_facility_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
如何正确编写此模型的测试?也许我应该添加 `class_name:"MedicalFacility" 到 Admin 模型?
【问题讨论】:
标签: ruby-on-rails rspec shoulda