Commit a2a62867 authored by Dylan Griffith's avatar Dylan Griffith

Fix incorrectly passing issue spec for Elasticsearch indexing

This spec was passing incorrectly ever since we introduced the redis
sorted sets for keeping track of indexing. The test was like an
integration test and was relying on Sidekiq.disable! to ensure the
comments were never indexed to begin with and thereby confirming they
were re-indexed when updating the issues. But as we later changed the
code the comments were ending up in the index regardless of updating the
issues as they were waiting in the sorted set. Thus the assertion about
them being found by search was redundant. The other assertion about not
finding it, as it turns, out was only passing because the issue was
confidential and was not found in a search by an anonymous user.

So in the end I've made the specs more like a unit test that hopefully
would not risk having these kinds of issues in future. I did also
backfill a missing spec for when author_id is changed. I attempted to do
the same for changing assignees but ran into some issues with the
update being called multiple times so don't want to tackle that along
with this MR.
parent fb2c3abc
......@@ -489,36 +489,33 @@ RSpec.describe Issue do
context 'when updating an Issue' do
let(:project) { create(:project, :public) }
let(:issue) { create(:issue, project: project, confidential: true) }
let!(:note) { create(:note, noteable: issue, project: project) }
let!(:system_note) { create(:note, :system, noteable: issue, project: project) }
before do
Sidekiq::Testing.disable! do
create(:note, note: 'the_normal_note', noteable: issue, project: project)
end
Sidekiq::Testing.inline! do
project.maintain_elasticsearch_update
context 'when changing the confidential value' do
it 'updates issue notes excluding system notes' do
expect_any_instance_of(Note).to receive(:maintain_elasticsearch_update) do |instance|
expect(instance.id).to eq(note.id)
end
issue.update!(update_field => update_value)
ensure_elasticsearch_index!
issue.update!(confidential: false)
end
end
context 'when changing the confidential value' do
let(:update_field) { :confidential }
let(:update_value) { false }
context 'when changing the author' do
it 'updates issue notes excluding system notes' do
expect(issue.elasticsearch_issue_notes_need_updating?).to eq(true)
expect(Note.elastic_search('the_normal_note', options: { project_ids: [issue.project.id] }).present?).to eq(true)
expect_any_instance_of(Note).to receive(:maintain_elasticsearch_update) do |instance|
expect(instance.id).to eq(note.id)
end
issue.update!(author: create(:user))
end
end
context 'when changing the title' do
let(:update_field) { :title }
let(:update_value) { 'abc' }
it 'does not update issue notes' do
expect(issue.elasticsearch_issue_notes_need_updating?).to eq(false)
expect(Note.elastic_search('the_normal_note', options: { project_ids: [issue.project.id] }).present?).to eq(false)
expect_any_instance_of(Note).not_to receive(:maintain_elasticsearch_update)
issue.update!(title: 'the new title')
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment