【问题标题】:Tire gem: is document exists in index?轮胎宝石:索引中是否存在文档?
【发布时间】:2019-05-04 23:23:03
【问题描述】:

如何使用tire gem 签入rspec 测试:文档是否存在于 ElasticSearch 索引中?

例子:

#model
class Car
  include Mongoid::Document
  include include Tire::Model::Search
  include Tire::Model::Callbacks
  #...
end

#spec
record = Car.first
record.tire.exist_in_index?.should be_true #wrong code

或者任何其他解决方法。

【问题讨论】:

  • 你的代码有问题,或者你到底想要什么?
  • @phoet 这只是一个例子,我想知道如何检查:文档是否存储在 ElasticSearch 索引中。
  • 这在很大程度上取决于您使用轮胎的方式。即当使用Tire::Persistance 时,您应该能够在模型上检查persisted?
  • @phoet 我编辑了问题,了解更多信息。

标签: ruby rspec elasticsearch


【解决方案1】:

您应该创建自定义匹配器:

RSpec::Matchers.define :be_in_search_index do |expected|
  match do |actual|
    !!actual.tire.index.retrieve(actual.class.name.underscore, actual.id.to_s)
  end
end

#...
record.should be_in_search_index

【讨论】:

    猜你喜欢
    • 2012-08-24
    • 1970-01-01
    • 2014-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-20
    • 2012-01-25
    • 1970-01-01
    相关资源
    最近更新 更多