diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb old mode 100644 new mode 100755 index 4b35cd8..ce0fb9c --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -48,10 +48,10 @@ class SearchController < ApplicationController nil when 'my_projects' User.current.projects - when 'subprojects' - @project ? (@project.self_and_descendants.active.to_a) : nil - else + when 'project' @project + else + @project ? (@project.self_and_descendants.active.to_a) : nil end @object_types = Redmine::Search.available_search_types.dup diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb old mode 100644 new mode 100755 index 2554cf9..84a4f92 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -46,8 +46,8 @@ module SearchHelper def project_select_tag options = [[l(:label_project_all), 'all']] options << [l(:label_my_projects), 'my_projects'] unless User.current.memberships.empty? - options << [l(:label_and_its_subprojects, @project.name), 'subprojects'] unless @project.nil? || @project.descendants.active.empty? - options << [@project.name, ''] unless @project.nil? + options << [l(:label_and_its_subprojects, @project.name), ''] unless @project.nil? || @project.descendants.active.empty? + options << [@project.name, 'project'] unless @project.nil? label_tag("scope", l(:description_project_scope), :class => "hidden-for-sighted") + select_tag('scope', options_for_select(options, params[:scope].to_s)) if options.size > 1 end @@ -63,7 +63,7 @@ module SearchHelper :all_words => params[:all_words], :scope => params[:scope], t => 1) end (''.html_safe) unless links.empty? end end diff --git a/test/functional/search_controller_test.rb b/test/functional/search_controller_test.rb old mode 100644 new mode 100755 index 720d62d..bfd33f6 --- a/test/functional/search_controller_test.rb +++ b/test/functional/search_controller_test.rb @@ -169,12 +169,23 @@ class SearchControllerTest < Redmine::ControllerTest end end - def test_search_project_and_subprojects - get :index, :params => {:id => 1, :q => 'recipe subproject', :scope => 'subprojects', :all_words => ''} + def test_search_only_in_project + get :index, :params => {:id => 1, :q => 'recipe subproject', :scope => 'project', :all_words => ''} assert_response :success assert_select '#search-results' do assert_select 'dt.issue', :text => /Bug #1/ + assert_select 'dt.issue a[href="/issues/5"]', 0 + end + end + + def test_search_default_scope_should_search_in_project_and_subprojects + get :index, :params => {:id => 1, :q => 'recipe subproject', :all_words => ''} + assert_response :success + + assert_select '#scope option[selected=selected]', :text => 'eCookbook and its subprojects' + assert_select '#search-results' do + assert_select 'dt.issue', :text => /Bug #1/ assert_select 'dt.issue', :text => /Bug #5/ end end @@ -270,7 +281,7 @@ class SearchControllerTest < Redmine::ControllerTest assert_select 'input[name=all_words]:not([checked])' assert_select '#search-results' do assert_select 'dt.issue', :text => / #3 / - assert_select 'dt', 3 + assert_select 'dt', 4 end end