![](/img/trans.png)
[英]rspec failing - “Couldn't find table”, but rake db:test:prepare doesn't fix it
[英]sunspot and rspec test failing as solr doesn't find any results
我正在用Rspec测试我的黑子solr配置。
我有:
before(:each) do
@company = create :company
end
describe "GET index" do
it "assigns all companies as @companies" do
get :index, {}, valid_session
expect(assigns(:companies)).to eq([@company])
end
end
和我的索引控制器:
def index
@search = Company.search do
fulltext params[:search]
end
@companies = @search.results
end
测试失败并显示:
Failure/Error: expect(assigns(:companies)).to eq([@company])
expected: [#<Company id: 613, name: "company 1", description: "description company 1", size: nil, company_link: "www.company1.com", created_at: "2015-04-13 12:52:56", updated_at: "2015-04-13 12:52:56">]
got: []
有什么线索吗?
您很可能具有RSpec的config.use_transactional_fixtures = true
。 在这种情况下,可以将以下内容添加到要建立索引的工厂中:
after(:create) { |c| c.index! }
添加到我的factory_girl工厂
after(:create) { Company.reindex }
解决了该问题,Solr现在在每次创建后重新索引所有内容,以便索引始终保持一致。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.