Ruby on rails 我如何让shoulda识别我的多态性关联

Ruby on rails 我如何让shoulda识别我的多态性关联,ruby-on-rails,rspec,polymorphic-associations,shoulda,Ruby On Rails,Rspec,Polymorphic Associations,Shoulda,以前有人问过一个几乎相同的问题(),但没有明确的答案可以帮助我,所以我现在再试一次 我正在使用shoulda测试我的关联,以下测试失败 require 'spec_helper' describe LabourEpidural do before {@treatment = FactoryGirl.build :treatment} subject {@treatment} it{should have_many :complications} end 此操作失败,并显示以下消息

以前有人问过一个几乎相同的问题(),但没有明确的答案可以帮助我,所以我现在再试一次

我正在使用shoulda测试我的关联,以下测试失败

require 'spec_helper'

describe LabourEpidural do
  before {@treatment = FactoryGirl.build :treatment}
  subject {@treatment}
  it{should have_many :complications}
end
此操作失败,并显示以下消息

Failure/Error: it{should have_many :complications}
   Expected Treatment to have a has_many association called complications (Complication does not have a complicatable_id foreign key.)
问题是,我的复杂度表确实有一个复杂度_id列。以下是我的模型的相关部分

class Treatment < ActiveRecord::Base
  has_many :complications, as: :complicatable, dependent: :destroy
end

class Complication < ActiveRecord::Base
  belongs_to :complicatable, polymorphic: true
end

就我所知,一切都准备好了,应该通过考试,为什么不呢?Shoulda matchers应该“只处理”多态关联。如果我进入控制台,我可以很容易地创造并发症的治疗。有什么想法吗?

在测试数据库上运行迁移

…我犯了很多次的错误


(Peter Alfvin应该打勾)

您是否尝试从控制台访问关联,它们是否有效?您是否在测试数据库上运行了迁移?是的,我在控制台中尝试了关联,是的,它们确实有效。呃,不,我没有在测试数据库中运行迁移。哎呀。现在一切都好了。写下来作为答案,你会得到一个漂亮的闪亮的绿色勾号。(羞愧地低着头走开了)。
create_table "complications", :force => true do |t|
  t.string   "name"
  t.datetime "created_at"
  t.datetime "updated_at"
  t.integer  "complicatable_id"
  t.string   "complicatable_type"
end