Searchkick: Searchkick breaks my rspec request tests

Created on 30 Jan 2017  路  5Comments  路  Source: ankane/searchkick

Hello guys,

Something strange is happening, when I put gem 'searchkick' in my gemfile, some of my tests just break.

I do not have anything searchkick related in my code, no callback, nothing...
I was trying to write my first tests for searchkick before writing my code, I ran my tests before doing anything, and a single line was enough to break my tests (the Gemfile one).

It breaks tests for 3 models (only 4 tests out of ~130)

One of those tests:

it 'does not update the experience and responds with :unprocessable_entity and an error' do
  payload = {
    experience: {
      candidate_id: nil
    }
  }
  expect(experience.candidate.id).not_to eq(candidate.id)
  patch v1_experience_url(id: experience.id, subdomain: :api), params: payload, headers: auth_headers
  expect(response).to have_http_status(:unprocessable_entity)
  expect(json_body).to eq({ candidate: ['must exist'] }.as_json)
end

expected the response to have status code :unprocessable_entity (422) but it was :ok (200)

When I comment the gem 'searchkick', the tests are green !!! 馃槺

I found out that only the tests for presence of belongs_to fail.

Any idea of what's happening ?

PS: Sorry for the last issue, bad account

--

Edit:

I have to put validates_presence_of :model, message: 'must exist' to the model to get my green tests back.

Does searchkick override Rails 5 default behavior for belongs_to ? (which is to validate the presence of association)

awaiting response

All 5 comments

Hey @terry90, not sure why that would be. Searchkick doesn't override any Rails behavior.

@ankane Just ran into this also. It seems belongs_to :user, optional: false which is the new rails default is getting removed.

Looks like these validators are being removed.

Invite.validators
[
  [0] #<ActiveRecord::Validations::PresenceValidator:0x007fb6f229b1d8 @attributes=[:sender], @options={:message=>:required}>,
  [1] #<ActiveRecord::Validations::PresenceValidator:0x007fb6f228b670 @attributes=[:organization], @options={:message=>:required}>
]

Hey @terry90 or @vwall, any update?

Cleaning up stale issues

Was this page helpful?
0 / 5 - 0 ratings