diff --git a/CHANGELOG-EE b/CHANGELOG-EE index d98e145439c27b973c4bec52da3c7031e3221ab4..09c445485f85ebb6a86e43fbd3978a7007c5224b 100644 --- a/CHANGELOG-EE +++ b/CHANGELOG-EE @@ -4,6 +4,7 @@ v 8.11.0 (unreleased) v 8.10.2 (unreleased) - Dicouple an ES index update from RepositoryUpdateMirrorWorker + - Fix pagination on search result page when ES search is enabled v 8.10.1 - No EE-specific changes diff --git a/lib/gitlab/elastic/project_search_results.rb b/lib/gitlab/elastic/project_search_results.rb index ed79389192512f3d911412b813018b99b981daeb..07944b82fc2902763f972eb86b4b5aeae3efa5ca 100644 --- a/lib/gitlab/elastic/project_search_results.rb +++ b/lib/gitlab/elastic/project_search_results.rb @@ -21,7 +21,7 @@ def initialize(current_user, project_id, query, repository_ref = nil) def objects(scope, page = nil) case scope when 'notes' - notes.records.page(page).per(per_page) + notes.page(page).per(per_page).records when 'blobs' blobs.page(page).per(per_page) when 'wiki_blobs' diff --git a/lib/gitlab/elastic/search_results.rb b/lib/gitlab/elastic/search_results.rb index 37ddd1c13c7621bc25d699cace755957b0429a07..f075995ea54915bcd6fad1eb7a9c93879190396e 100644 --- a/lib/gitlab/elastic/search_results.rb +++ b/lib/gitlab/elastic/search_results.rb @@ -16,13 +16,13 @@ def initialize(current_user, limit_project_ids, query) def objects(scope, page = nil) case scope when 'projects' - projects.records.page(page).per(per_page) + projects.page(page).per(per_page).records when 'issues' - issues.records.page(page).per(per_page) + issues.page(page).per(per_page).records when 'merge_requests' - merge_requests.records.page(page).per(per_page) + merge_requests.page(page).per(per_page).records when 'milestones' - milestones.records.page(page).per(per_page) + milestones.page(page).per(per_page).records else Kaminari.paginate_array([]) end diff --git a/lib/gitlab/elastic/snippet_search_results.rb b/lib/gitlab/elastic/snippet_search_results.rb index 4be0357fc66d8ba97b78afb9e2c4d671b15e592e..f8088ecdad684bb61bfc2f75ab1dc8eef2ed03ed 100644 --- a/lib/gitlab/elastic/snippet_search_results.rb +++ b/lib/gitlab/elastic/snippet_search_results.rb @@ -9,9 +9,9 @@ def initialize(user, query) def objects(scope, page = nil) case scope when 'snippet_titles' - snippet_titles.records.page(page).per(per_page) + snippet_titles.page(page).per(per_page).records when 'snippet_blobs' - snippet_blobs.records.page(page).per(per_page) + snippet_blobs.page(page).per(per_page).records else super end diff --git a/spec/features/projects/elastic/global_search_spec.rb b/spec/features/projects/elastic/global_search_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..e3e33c84c8a5f17bbf4022209aeb86b0d7cf2bc3 --- /dev/null +++ b/spec/features/projects/elastic/global_search_spec.rb @@ -0,0 +1,46 @@ +require 'spec_helper' + +feature 'Global elastic search', feature: true do + let(:user) { create(:user) } + let(:project) { create(:project, namespace: user.namespace) } + + before do + stub_application_setting(elasticsearch_search: true, elasticsearch_indexing: true) + + project.team << [user, :master] + login_with(user) + end + + after do + stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false) + end + + describe 'I search through the issues and I see pagination' do + before do + [::Project, Issue, MergeRequest, Milestone].each do |model| + model.__elasticsearch__.create_index! + end + + create_list(:issue, 21, project: project, title: 'initial') + + Issue.__elasticsearch__.refresh_index! + end + + after do + [::Project, Issue, MergeRequest, Milestone].each do |model| + model.__elasticsearch__.delete_index! + end + end + + it "has a pagination" do + visit dashboard_projects_path + + fill_in "search", with: "initial" + click_button "Go" + + select_filter("Issues") + expect(page).to have_selector('.gl-pagination .page', count: 2) + end + end + +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 98bf93797c5e9bab901b0afe42ffe2a69516b35a..0690d4f3db9a7e888bf8cb6af8d7418538c2f9b2 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -31,6 +31,7 @@ config.include Devise::TestHelpers, type: :controller config.include LoginHelpers, type: :feature config.include LoginHelpers, type: :request + config.include SearchHelpers, type: :feature config.include StubConfiguration config.include EmailHelpers config.include TestEnv diff --git a/spec/support/search_helpers.rb b/spec/support/search_helpers.rb new file mode 100644 index 0000000000000000000000000000000000000000..abbbb636d66c6607b10028065f6f869e7ad83003 --- /dev/null +++ b/spec/support/search_helpers.rb @@ -0,0 +1,5 @@ +module SearchHelpers + def select_filter(name) + find(:xpath, "//ul[contains(@class, 'search-filter')]//a[contains(.,'#{name}')]").click + end +end