我想在我的Practice Management应用程序中创建用于搜索患者的功能规格。
到目前为止,我已经搜索了网络,并遵循了以下建议的解决方案:
http://bitsandbit.es/post/11295134047/unit-testing-with-tire-and-elastic-search#disqus_thread
和
https://github.com/karmi/tire/wiki/Integration-Testing-Rails-Models-with-Tire
这两篇文章都向ElasticSearch和轮胎的spec_helper.rb推荐了配置。由于Searchkick是基于Tire的,所以我将解决方案应用于Patient类,这是我使用Searchkick的唯一模型。
但是,对于每个配置,我都会得到一个“NoMEthodError”。例如,使用以下代码:
spec_helper.rb
RSpec.configure do |config| do
.
.
.
config.before :each do
Patient.index.delete
Patient.create_elasticsearch_index
end
config.before :all do
Patient.index_name('test' + Patient.model_name.plural)
end
end我得到以下错误:
Failure/Error: Unable to find matching line from backtrace
NoMethodError:
undefined method `index_name' “index”和“create_elasticsearch_index”方法也是如此。
我是RoR的新手,老实说,我不确定我在这里做错了什么,除了假设我可以在Searchkick上使用轮胎解决方案。所以任何帮助都是非常感谢的!
发布于 2014-02-17 04:53:18
Searchkick需要更好的测试文档,但它的要点如下:
Searchkick在每个环境中自动使用不同的索引名,因此不需要进行任何设置。在控制台中运行Patient.searchkick_index.name进行确认。
您可以只调用reindex,而不是删除并重新创建索引。
RSpec.configure do |config| do
config.before :each do
Patient.reindex
end
end最后,在插入数据之后,在调用Patient.search之前调用Patient.searchkick_index.refresh。这告诉Elasticsearch立即更新索引(而不是在刷新间隔之后更新索引,刷新间隔默认为1秒)。
发布于 2014-02-17 01:47:49
即使Searchkick是基于Tire的,这并不意味着Tire的方法在你的模型上是可用的。有关可用方法的文档,请参阅https://github.com/ankane/searchkick。关于使用Searchkick和使用轮胎之间的对比,请特别参阅小节https://github.com/ankane/searchkick#migrating-from-tire。
https://stackoverflow.com/questions/21814473
复制相似问题