diff options
author | Clement Ho <clemmakesapps@gmail.com> | 2017-02-08 19:35:23 +0000 |
---|---|---|
committer | Clement Ho <clemmakesapps@gmail.com> | 2017-02-08 19:35:23 +0000 |
commit | 6d97120139cd5d07856b27b88386105acd6e7913 (patch) | |
tree | ce5669923df05fe3fc9f94f2a72471784f9c9822 | |
parent | ece75a89ffb29754c1e7fee8afe18c0a31551f6b (diff) | |
parent | 73bcfe324884aba19bc9d806514e8e9b910dfd8d (diff) | |
download | gitlab-ce-6d97120139cd5d07856b27b88386105acd6e7913.tar.gz |
Merge branch '27756-fix-json-404-response' into 'master'
Fixes ajax requests when current URL has a trailing slash
Closes #27756
See merge request !9010
4 files changed, 28 insertions, 5 deletions
diff --git a/app/assets/javascripts/filtered_search/filtered_search_dropdown_manager.js.es6 b/app/assets/javascripts/filtered_search/filtered_search_dropdown_manager.js.es6 index 547989a6ff5..8ce4cf4fc36 100644 --- a/app/assets/javascripts/filtered_search/filtered_search_dropdown_manager.js.es6 +++ b/app/assets/javascripts/filtered_search/filtered_search_dropdown_manager.js.es6 @@ -2,7 +2,8 @@ (() => { class FilteredSearchDropdownManager { - constructor() { + constructor(baseEndpoint = '') { + this.baseEndpoint = baseEndpoint.replace(/\/$/, ''); this.tokenizer = gl.FilteredSearchTokenizer; this.filteredSearchInput = document.querySelector('.filtered-search'); @@ -38,13 +39,13 @@ milestone: { reference: null, gl: 'DropdownNonUser', - extraArguments: ['milestones.json', '%'], + extraArguments: [`${this.baseEndpoint}/milestones.json`, '%'], element: document.querySelector('#js-dropdown-milestone'), }, label: { reference: null, gl: 'DropdownNonUser', - extraArguments: ['labels.json', '~'], + extraArguments: [`${this.baseEndpoint}/labels.json`, '~'], element: document.querySelector('#js-dropdown-label'), }, hint: { diff --git a/app/assets/javascripts/filtered_search/filtered_search_manager.js.es6 b/app/assets/javascripts/filtered_search/filtered_search_manager.js.es6 index 4e02ab7c8c1..ffc7d29e4c5 100644 --- a/app/assets/javascripts/filtered_search/filtered_search_manager.js.es6 +++ b/app/assets/javascripts/filtered_search/filtered_search_manager.js.es6 @@ -6,7 +6,7 @@ if (this.filteredSearchInput) { this.tokenizer = gl.FilteredSearchTokenizer; - this.dropdownManager = new gl.FilteredSearchDropdownManager(); + this.dropdownManager = new gl.FilteredSearchDropdownManager(this.filteredSearchInput.getAttribute('data-base-endpoint') || ''); this.bindEvents(); this.loadSearchParamsFromURL(); diff --git a/app/views/shared/issuable/_search_bar.html.haml b/app/views/shared/issuable/_search_bar.html.haml index 173fa922f56..6e417aa2251 100644 --- a/app/views/shared/issuable/_search_bar.html.haml +++ b/app/views/shared/issuable/_search_bar.html.haml @@ -11,7 +11,7 @@ class: "check_all_issues left" .issues-other-filters.filtered-search-container .filtered-search-input-container - %input.form-control.filtered-search{ placeholder: 'Search or filter results...', 'data-id' => 'filtered-search', 'data-project-id' => @project.id, 'data-username-params' => @users.to_json(only: [:id, :username]) } + %input.form-control.filtered-search{ placeholder: 'Search or filter results...', 'data-id' => 'filtered-search', 'data-project-id' => @project.id, 'data-username-params' => @users.to_json(only: [:id, :username]), 'data-base-endpoint' => namespace_project_path(@project.namespace, @project) } = icon('filter') %button.clear-search.hidden{ type: 'button' } = icon('times') diff --git a/spec/features/issues/filtered_search/filter_issues_spec.rb b/spec/features/issues/filtered_search/filter_issues_spec.rb index 3f70a6aa75f..6f7046c8461 100644 --- a/spec/features/issues/filtered_search/filter_issues_spec.rb +++ b/spec/features/issues/filtered_search/filter_issues_spec.rb @@ -801,4 +801,26 @@ describe 'Filter issues', js: true, feature: true do expect(auto_discovery_params).to include('assignee_id' => [user.id.to_s]) end end + + context 'URL has a trailing slash' do + before do + visit "#{namespace_project_issues_path(project.namespace, project)}/" + end + + it 'milestone dropdown loads milestones' do + input_filtered_search("milestone:", submit: false) + + within('#js-dropdown-milestone') do + expect(page).to have_selector('.filter-dropdown .filter-dropdown-item', count: 2) + end + end + + it 'label dropdown load labels' do + input_filtered_search("label:", submit: false) + + within('#js-dropdown-label') do + expect(page).to have_selector('.filter-dropdown .filter-dropdown-item', count: 5) + end + end + end end |