Project

General

Profile

Feature #9909 » 9909_set_default_search_scope_to_project_and_its_subprojects.patch

Marius BĂLTEANU, 2017-04-11 00:07

View differences:

app/controllers/search_controller.rb
48 48
        nil
49 49
      when 'my_projects'
50 50
        User.current.projects
51
      when 'subprojects'
52
        @project ? (@project.self_and_descendants.active.to_a) : nil
53
      else
51
      when 'project'
54 52
        @project
53
      else
54
        @project ? (@project.self_and_descendants.active.to_a) : nil
55 55
      end
56 56

  
57 57
    @object_types = Redmine::Search.available_search_types.dup
app/helpers/search_helper.rb
46 46
  def project_select_tag
47 47
    options = [[l(:label_project_all), 'all']]
48 48
    options << [l(:label_my_projects), 'my_projects'] unless User.current.memberships.empty?
49
    options << [l(:label_and_its_subprojects, @project.name), 'subprojects'] unless @project.nil? || @project.descendants.active.empty?
50
    options << [@project.name, ''] unless @project.nil?
49
    options << [l(:label_and_its_subprojects, @project.name), ''] unless @project.nil? || @project.descendants.active.empty?
50
    options << [@project.name, 'project'] unless @project.nil?
51 51
    label_tag("scope", l(:description_project_scope), :class => "hidden-for-sighted") +
52 52
    select_tag('scope', options_for_select(options, params[:scope].to_s)) if options.size > 1
53 53
  end
......
63 63
                       :all_words => params[:all_words], :scope => params[:scope], t => 1)
64 64
    end
65 65
    ('<ul>'.html_safe +
66
        links.map {|link| content_tag('li', link)}.join(' ').html_safe + 
66
        links.map {|link| content_tag('li', link)}.join(' ').html_safe +
67 67
        '</ul>'.html_safe) unless links.empty?
68 68
  end
69 69
end
test/functional/search_controller_test.rb
169 169
    end
170 170
  end
171 171

  
172
  def test_search_project_and_subprojects
173
    get :index, :params => {:id => 1, :q => 'recipe subproject', :scope => 'subprojects', :all_words => ''}
172
  def test_search_only_in_project
173
    get :index, :params => {:id => 1, :q => 'recipe subproject', :scope => 'project', :all_words => ''}
174 174
    assert_response :success
175 175

  
176 176
    assert_select '#search-results' do
177 177
      assert_select 'dt.issue', :text => /Bug #1/
178
      assert_select 'dt.issue a[href="/issues/5"]', 0
179
    end
180
  end
181

  
182
  def test_search_default_scope_should_search_in_project_and_subprojects
183
    get :index, :params => {:id => 1, :q => 'recipe subproject', :all_words => ''}
184
    assert_response :success
185

  
186
    assert_select '#scope option[selected=selected]', :text => 'eCookbook and its subprojects'
187
    assert_select '#search-results' do
188
      assert_select 'dt.issue', :text => /Bug #1/
178 189
      assert_select 'dt.issue', :text => /Bug #5/
179 190
    end
180 191
  end
......
270 281
    assert_select 'input[name=all_words]:not([checked])'
271 282
    assert_select '#search-results' do
272 283
      assert_select 'dt.issue', :text => / #3 /
273
      assert_select 'dt', 3
284
      assert_select 'dt', 4
274 285
    end
275 286
  end
276 287

  
(1-1/2)