Commit 575a7e16 authored by Sean McGivern's avatar Sean McGivern

Merge branch '291032-fix-flaky-spec' into 'master'

Fix ActiveRecord::Records flaky spec

See merge request gitlab-org/gitlab!51909
parents 6a6979a7 d9101085
......@@ -3,39 +3,23 @@
require 'spec_helper'
RSpec.describe Elasticsearch::Model::Adapter::ActiveRecord::Records, :elastic do
before do
stub_ee_application_setting(elasticsearch_indexing: true)
end
describe '#records' do
let(:user) { create(:user) }
let(:search_options) { { options: { current_user: user, project_ids: :any } } }
before do
stub_ee_application_setting(elasticsearch_indexing: true)
@middle_relevant = create(
:issue,
title: 'Sorting could improve', # Some keywords in title
description: 'I think you could make it better'
)
@least_relevant = create(
:issue,
title: 'I love GitLab', # No keywords in title
description: 'There is so much to love! For example, you could not possibly make sorting any better'
)
let(:search_options) { { options: { current_user: user, project_ids: :any, order_by: 'created_at', sort: 'desc' } } }
let(:results) { Issue.elastic_search('*', **search_options).records.to_a }
@most_relevant = create(
:issue,
title: 'Make sorting better', # All keywords in title
description: 'This issue is here to make the sorting better'
)
let!(:new_issue) { create(:issue) }
let!(:recent_issue) { create(:issue, created_at: 1.hour.ago) }
let!(:old_issue) { create(:issue, created_at: 7.days.ago) }
it 'returns results in the same sorted order as they come back from Elasticsearch' do
ensure_elasticsearch_index!
end
it 'returns results in the same sorted order as they come back from Elasticsearch' do
expect(Issue.elastic_search('make sorting better', **search_options).records.to_a).to eq([
@most_relevant,
@middle_relevant,
@least_relevant
])
expect(results).to eq([new_issue, recent_issue, old_issue])
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