ruby on rails - Chewy RSpec Test - Expected index `client#person_client` to be updated, but it was not -
i using chewy interacting elasticsearch in rails app. trying add rspec test index (clientindex), think doing wrong here.
my model client
:
class client < activerecord::base update_index('client#person_client') { self } end
my clientindex
:
class clientindex < chewy::index settings analysis: { # ... } define_type client, name: 'person_client' field :id, value: ->(client) { client.id } field :name, search_analyzer: 'str_search_analyzer', index_analyzer: 'index_analyzer' field :name_sorted, value: ->(client) { client.name } field :email, search_analyzer: 'str_search_analyzer', index_analyzer: 'index_analyzer' field :created_at, type: 'date' end end
and rspec test:
rspec.describe clientindex "update index after save" client = fabricate.build(:client, id: 10) expect { client.save! }.to update_index('client#person_client') end end
result:
failures: 1) clientindex update index after save failure/error: expect { client.save! }.to update_index('client#person_client') expected index `client#person_client` updated, not
any suggestions here?
thanks
i think found solution. in spec_helper.rb
, had choose indexation strategy of chewy. put:
chewy.root_strategy = :urgent
and works now.
if don't chose indexation strategy, raises error in callback, it's silent when create on object.
i hope helps.
Comments
Post a Comment