Ruby on rails Chewy RSpec测试-预期“客户机/个人/客户机”索引将更新,但未更新
我正在使用Chewy与Rails应用程序中的ElasticSearch进行交互。我试图在我的索引(ClientIndex)中添加一个RSpec测试,但我认为我在这里做错了什么 我的型号Ruby on rails Chewy RSpec测试-预期“客户机/个人/客户机”索引将更新,但未更新,ruby-on-rails,rspec,
elasticsearch,Ruby On Rails,Rspec,
elasticsearch,我正在使用Chewy与Rails应用程序中的ElasticSearch进行交互。我试图在我的索引(ClientIndex)中添加一个RSpec测试,但我认为我在这里做错了什么 我的型号客户机: class Client < ActiveRecord::Base update_index('client#person_client') { self } end 以及我的RSpec测试: RSpec.describe ClientIndex do it "update index a
客户机
:
class Client < ActiveRecord::Base
update_index('client#person_client') { self }
end
以及我的RSpec测试:
RSpec.describe ClientIndex do
it "update index after save" do
client = Fabricate.build(:client, id: 10)
expect { client.save! }.to update_index('client#person_client')
end
end
结果:
Failures:
1) ClientIndex update index after save
Failure/Error: expect { client.save! }.to update_index('client#person_client')
Expected index `client#person_client` to be updated, but it was not
有什么建议吗
谢谢我想我找到了解决办法。在
spec\u helper.rb
中,我不得不选择chewy的指数化策略。我说:
Chewy.root_strategy = :urgent
现在它可以工作了
如果您没有选择索引化策略,它会在回调中引发错误,但在对象上创建时它是静默的
我希望这会有所帮助。您使用的是哪种耐嚼版本?0.6.2或0.7.0?@cbliard(版本为0.6.2)可以正常工作
Chewy.root_strategy = :urgent