diff options
Diffstat (limited to 'spec/services/search')
-rw-r--r-- | spec/services/search/global_service_spec.rb | 30 | ||||
-rw-r--r-- | spec/services/search/group_service_spec.rb | 32 |
2 files changed, 62 insertions, 0 deletions
diff --git a/spec/services/search/global_service_spec.rb b/spec/services/search/global_service_spec.rb index 90ad18e5571..7b914a4d3d6 100644 --- a/spec/services/search/global_service_spec.rb +++ b/spec/services/search/global_service_spec.rb @@ -52,4 +52,34 @@ RSpec.describe Search::GlobalService do end end end + + context 'issues' do + let(:scope) { 'issues' } + + context 'sort by created_at' do + let!(:project) { create(:project, :public) } + let!(:old_result) { create(:issue, project: project, title: 'sorted old', created_at: 1.month.ago) } + let!(:new_result) { create(:issue, project: project, title: 'sorted recent', created_at: 1.day.ago) } + let!(:very_old_result) { create(:issue, project: project, title: 'sorted very old', created_at: 1.year.ago) } + + include_examples 'search results sorted' do + let(:results) { described_class.new(nil, search: 'sorted', sort: sort).execute } + end + end + end + + context 'merge_request' do + let(:scope) { 'merge_requests' } + + context 'sort by created_at' do + let!(:project) { create(:project, :public) } + let!(:old_result) { create(:merge_request, :opened, source_project: project, source_branch: 'old-1', title: 'sorted old', created_at: 1.month.ago) } + let!(:new_result) { create(:merge_request, :opened, source_project: project, source_branch: 'new-1', title: 'sorted recent', created_at: 1.day.ago) } + let!(:very_old_result) { create(:merge_request, :opened, source_project: project, source_branch: 'very-old-1', title: 'sorted very old', created_at: 1.year.ago) } + + include_examples 'search results sorted' do + let(:results) { described_class.new(nil, search: 'sorted', sort: sort).execute } + end + end + end end diff --git a/spec/services/search/group_service_spec.rb b/spec/services/search/group_service_spec.rb index d3026d158d4..2bfe714f393 100644 --- a/spec/services/search/group_service_spec.rb +++ b/spec/services/search/group_service_spec.rb @@ -40,4 +40,36 @@ RSpec.describe Search::GroupService do describe 'basic search' do include_examples 'group search' end + + context 'issues' do + let(:scope) { 'issues' } + + context 'sort by created_at' do + let!(:group) { create(:group) } + let!(:project) { create(:project, :public, group: group) } + let!(:old_result) { create(:issue, project: project, title: 'sorted old', created_at: 1.month.ago) } + let!(:new_result) { create(:issue, project: project, title: 'sorted recent', created_at: 1.day.ago) } + let!(:very_old_result) { create(:issue, project: project, title: 'sorted very old', created_at: 1.year.ago) } + + include_examples 'search results sorted' do + let(:results) { described_class.new(nil, group, search: 'sorted', sort: sort).execute } + end + end + end + + context 'merge requests' do + let(:scope) { 'merge_requests' } + + context 'sort by created_at' do + let!(:group) { create(:group) } + let!(:project) { create(:project, :public, group: group) } + let!(:old_result) { create(:merge_request, :opened, source_project: project, source_branch: 'old-1', title: 'sorted old', created_at: 1.month.ago) } + let!(:new_result) { create(:merge_request, :opened, source_project: project, source_branch: 'new-1', title: 'sorted recent', created_at: 1.day.ago) } + let!(:very_old_result) { create(:merge_request, :opened, source_project: project, source_branch: 'very-old-1', title: 'sorted very old', created_at: 1.year.ago) } + + include_examples 'search results sorted' do + let(:results) { described_class.new(nil, group, search: 'sorted', sort: sort).execute } + end + end + end end |