From b102840f5b6bc8526fbabae6005ff8de00391795 Mon Sep 17 00:00:00 2001 From: Marius BALTEANU Date: Sun, 24 Mar 2019 08:41:59 +0000 Subject: [PATCH] Project search should select subprojects scope when the project has subprojects (#30923) --- app/views/layouts/base.html.erb | 2 +- test/functional/projects_controller_test.rb | 87 +++++++++++++++++++---------- 2 files changed, 60 insertions(+), 29 deletions(-) diff --git a/app/views/layouts/base.html.erb b/app/views/layouts/base.html.erb index b2911b4..5c8be88 100644 --- a/app/views/layouts/base.html.erb +++ b/app/views/layouts/base.html.erb @@ -78,7 +78,7 @@ <%= hidden_field_tag 'scope', default_search_project_scope, :id => nil %> <%= hidden_field_tag(controller.default_search_scope, 1, :id => nil) if controller.default_search_scope %> <%= text_field_tag 'q', @question, :size => 20, :class => 'small', :accesskey => accesskey(:quick_search) %> <% end %> diff --git a/test/functional/projects_controller_test.rb b/test/functional/projects_controller_test.rb index 84f8cac..e1a1705 100644 --- a/test/functional/projects_controller_test.rb +++ b/test/functional/projects_controller_test.rb @@ -173,8 +173,8 @@ class ProjectsControllerTest < Redmine::ControllerTest :identifier => "blog", :is_public => 1, :custom_field_values => { - '3' => 'Beta' - }, + '3' => 'Beta' + }, :tracker_ids => ['1', '3'], # an issue custom field that is not for all project :issue_custom_field_ids => ['9'], @@ -207,10 +207,10 @@ class ProjectsControllerTest < Redmine::ControllerTest :identifier => "blog", :is_public => 1, :custom_field_values => { - '3' => 'Beta' - }, + '3' => 'Beta' + }, :parent_id => 1 - + } } assert_redirected_to '/projects/blog/settings' @@ -229,7 +229,7 @@ class ProjectsControllerTest < Redmine::ControllerTest :project => { :name => "blog", :identifier => "blog" - }, + }, :continue => 'Create and continue' } end @@ -247,11 +247,11 @@ class ProjectsControllerTest < Redmine::ControllerTest :identifier => "blog", :is_public => 1, :custom_field_values => { - '3' => 'Beta' - }, + '3' => 'Beta' + }, :tracker_ids => ['1', '3'], :enabled_module_names => ['issue_tracking', 'news', 'repository'] - + } } @@ -282,10 +282,10 @@ class ProjectsControllerTest < Redmine::ControllerTest :identifier => "blog", :is_public => 1, :custom_field_values => { - '3' => 'Beta' - }, + '3' => 'Beta' + }, :parent_id => 1 - + } } end @@ -305,10 +305,10 @@ class ProjectsControllerTest < Redmine::ControllerTest :identifier => "blog", :is_public => 1, :custom_field_values => { - '3' => 'Beta' - }, + '3' => 'Beta' + }, :parent_id => 1 - + } } assert_redirected_to '/projects/blog/settings' @@ -329,9 +329,9 @@ class ProjectsControllerTest < Redmine::ControllerTest :identifier => "blog", :is_public => 1, :custom_field_values => { - '3' => 'Beta' - } - + '3' => 'Beta' + } + } } end @@ -353,10 +353,10 @@ class ProjectsControllerTest < Redmine::ControllerTest :identifier => "blog", :is_public => 1, :custom_field_values => { - '3' => 'Beta' - }, + '3' => 'Beta' + }, :parent_id => 6 - + } } end @@ -377,7 +377,7 @@ class ProjectsControllerTest < Redmine::ControllerTest :name => "blog1", :identifier => "blog1", :enabled_module_names => ["issue_tracking", "repository"] - + } } end @@ -390,7 +390,7 @@ class ProjectsControllerTest < Redmine::ControllerTest :name => "blog2", :identifier => "blog2", :enabled_module_names => ["issue_tracking", "repository"] - + } } end @@ -410,7 +410,7 @@ class ProjectsControllerTest < Redmine::ControllerTest :identifier => 'inherited', :parent_id => parent.id, :inherit_members => '1' - + } } assert_response 302 @@ -432,7 +432,7 @@ class ProjectsControllerTest < Redmine::ControllerTest :name => "blog", :identifier => "", :enabled_module_names => %w(issue_tracking news) - + } } end @@ -542,7 +542,7 @@ class ProjectsControllerTest < Redmine::ControllerTest @request.session[:user_id] = 1 project = Project.find_by_identifier('ecookbook') project.archive - + get :show, :params => { :id => 'ecookbook' } @@ -960,8 +960,8 @@ class ProjectsControllerTest < Redmine::ControllerTest :identifier => 'unique-copy', :tracker_ids => ['1', '2', '3', ''], :enabled_module_names => %w(issue_tracking time_tracking) - - }, + + }, :only => %w(issues versions) } end @@ -1044,4 +1044,35 @@ class ProjectsControllerTest < Redmine::ControllerTest } assert_select 'body.project-ecookbook' end + + def test_default_search_scope_in_global_page + get :index + + assert_select 'div#quick-search form' do + assert_select 'input[name=scope][type=hidden]' + assert_select 'a[href=?]', '/search' + end + end + + def test_default_search_scope_for_project_without_subprojects + get :show, :params => { + :id => 4, + } + + assert_select 'div#quick-search form' do + assert_select 'input[name=scope][type=hidden]' + assert_select 'a[href=?]', '/projects/subproject2/search' + end + end + + def test_default_search_scope_for_project_with_subprojects + get :show, :params => { + :id => 1, + } + + assert_select 'div#quick-search form' do + assert_select 'input[name=scope][type=hidden][value=subprojects]' + assert_select 'a[href=?]', '/projects/ecookbook/search?scope=subprojects' + end + end end -- 2.1.4