Commit d9101085 authored by Dmitry Gruzd's avatar Dmitry Gruzd

Fix ActiveRecord::Records flaky spec

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