elasticsearch,Ruby On Rails,Rspec,elasticsearch" /> elasticsearch,Ruby On Rails,Rspec,elasticsearch" />

Ruby on rails Elasticsearch:未定义的方法&x27;执行';对于#<;索引器…>;[测试环境]

Ruby on rails Elasticsearch:未定义的方法&x27;执行';对于#<;索引器…>;[测试环境],ruby-on-rails,rspec,elasticsearch,Ruby On Rails,Rspec,elasticsearch,我正在为我的应用程序编写测试(在Rspec中),花了一整天的时间试图找出我在水豚身上犯的错误。我注意到,当调用一个操作(change_status)时,test.log中会出现以下错误: undefined method `perform' for #<Indexer:0x000000095d9680> 有什么建议吗?除此之外,日志是无用的 编辑: 如果您丢失了#执行它会提示您执行一些后台工作来重新编制索引。雷斯克?西德基?在您的代码中(可能是一个清理程序)的某个地方调用了Inde

我正在为我的应用程序编写测试(在Rspec中),花了一整天的时间试图找出我在水豚身上犯的错误。我注意到,当调用一个操作(change_status)时,test.log中会出现以下错误:

undefined method `perform' for #<Indexer:0x000000095d9680>
有什么建议吗?除此之外,日志是无用的

编辑:


如果您丢失了#执行它会提示您执行一些后台工作来重新编制索引。雷斯克?西德基?在您的代码中(可能是一个清理程序)的某个地方调用了Indexer#在代码更改后执行。@MilanVladimirovic刚刚检查了Sidekiq。不,我正在重新检查代码。顺便说一句,在开发环境中一切都很好。Pozdrav[iz PG];)检查异步回调上的elasticsearch模型自述:这里有一个带有#perform方法和示例perform_异步回调的索引器类示例。检查这是否适用于您的项目。在未准备在后台作业中运行的类上执行缺少的静止点。它可以通过perform直接调用,也可以通过sidekiq worker通过perform\u async间接调用。dev和test之间的差异可能是由spec\u helper中的sidekiq设置导致的。在开发模式下,索引器将被放置在队列中并在那里执行,您可能不会注意到缺少的perform方法和导致的异常,而在测试模式下,您可能会注意到,因为它将直接执行。
def change_status
  product = Product.find_by(id: params[:id])
  product.update_attribute(:status, params[:product][:status])
  if params[:product][:status] == "accepted"
    kind = Kind.where(name: "title").first
    product.author.change_points({points: 2, kind: kind.id})
  elsif params[:product][:status] == "rejected"
    kind = Kind.where(name: "title").first
    product.author.change_points({points: 1, kind: kind.id})
    product.author.change_points({points: -3, kind: kind.id})
  end

  user_id = product.author_id
  products = Product.where(author_id: user_id)
  if products.where(status: "accepted").count == 3
    user = User.find_by(id: user_id)
    user.update_attribute(:approved, true)
    kind = Kind.where(name: "title").first
    user.change_points({points: 1, kind: kind.id})
    redirect_to products_path
  else
    redirect_to action: "pending_products", id: user_id
  end
end
class Indexer
  include Sidekiq::Worker

  sidekiq_options queue: 'elasticsearch', retry: false, backtrace: true

  Logger = Sidekiq.logger.level == Logger::DEBUG ? Sidekiq.logger : nil
  Client = Elasticsearch::Client.new host: (ENV['ELASTICSEARCH_URL'] || 'http://localhost:9200'), logger: Logger

  def perform(operation, klass, record_id, options={})
    logger.debug [operation, "#{klass}##{record_id} #{options.inspect}"]

    case operation.to_s
      when /index|update/
        record = klass.constantize.find(record_id)
        record.__elasticsearch__.client = Client
        record.__elasticsearch__.__send__ "#{operation}_document"
      when /delete/
        Client.delete index: klass.constantize.index_name, type: klass.constantize.document_type, id: record_id
      else raise ArgumentError, "Unknown operation '#{operation}'"
    end
  end
end