0001-Make-time-entries-searchable-by-their-comments-hours.patch

Patch against trunk @ r21200. - Mischa The Evil, 2021-08-26 10:32

Download (5.89 KB)

View differences:

app/controllers/timelog_controller.rb
19 19

  
20 20
class TimelogController < ApplicationController
21 21
  menu_item :time_entries
22
  default_search_scope :time_entries
22 23

  
23 24
  before_action :find_time_entry, :only => [:show, :edit, :update]
24 25
  before_action :check_editability, :only => [:edit, :update]
app/models/time_entry.rb
43 43
    :group => :issue,
44 44
    :description => :comments
45 45
  )
46
  acts_as_searchable :columns => ['comments', 'hours', 'spent_on'],
47
                     :preload => [:project, :issue, {:issue => :status}]
46 48
  acts_as_activity_provider :timestamp => "#{table_name}.created_on",
47 49
                            :author_key => :user_id,
48 50
                            :scope => proc {joins(:project).preload(:project)}
lib/redmine.rb
441 441
  search.register :changesets
442 442
  search.register :wiki_pages
443 443
  search.register :messages
444
  search.register :time_entries
444 445
  search.register :projects
445 446
end
446 447

  
test/functional/search_controller_test.rb
74 74
    assert_response :success
75 75

  
76 76
    assert_select '#search-results' do
77
      assert_select 'dt.issue a', :text => /Feature request #2/
77
      assert_select 'dt.issue a', :text => /Bug #1/
78 78
      assert_select 'dt.issue a', :text => /Bug #5/
79 79
      assert_select 'dt.changeset a', :text => /Revision 1/
80 80

  
81
      assert_select 'dt.issue a', :text => /Add ingredients categories/
82
      assert_select 'dd', :text => /should be classified by categories/
81
      assert_select 'dt.issue a', :text => /Cannot print recipes/
82
      assert_select 'dd', :text => /Unable to print recipes/
83 83
    end
84 84

  
85 85
    assert_select '#search-results-counts' do
......
143 143
    end
144 144
  end
145 145

  
146
  def test_search_time_entries_comments_on_project
147
    get :index, :params => {:id => 1, :q => 'hours'}
148
    assert_response :success
149

  
150
    assert_select '#search-results' do
151
      assert_select 'dt.time-entry', 1
152
      assert_select 'dt.time-entry span.project', 0
153
      assert_select 'dt.time-entry a', :text => /Bug #1 \(New\)/
154
      assert_select 'dd', :text => /My hours/
155
    end
156
  end
157

  
158
  def test_search_time_entries_comments_on_project_with_subprojects_scope
159
    get :index, :params => {:id => 1, :q => 'time spent', :scope => 'subprojects', :time_entries => 1}
160
    assert_response :success
161

  
162
    assert_select '#search-results' do
163
      assert_select 'dt.time-entry', 1
164
      assert_select 'dt.time-entry span.project', 1
165
      assert_select 'dt.time-entry a', :text => /\(Project: eCookbook Subproject 1\)/
166
      assert_select 'dd', :text => /Time spent on a subproject/
167
    end
168
  end
169

  
170
  def test_search_time_entries_comments_on_all_projects
171
    get :index, :params => {:q => 'recipe subproject commit', :all_words => ''}
172
    assert_response :success
173

  
174
    assert_select '#search-results' do
175
      assert_select 'dt.time-entry', 1
176
      assert_select 'dt.time-entry span.project', 1
177
      assert_select 'dt.time-entry a', :text => /7.65 hours \(Project: eCookbook Subproject 1\)/
178
      assert_select 'dd', :text => /Time spent on a subproject/
179
    end
180
  end
181

  
182
  def test_search_time_entries_hours_on_project
183
    get :index, :params => {:id => 1, :q => '"150"'}
184
    assert_response :success
185

  
186
    assert_select '#search-results' do
187
      assert_select 'dt.time-entry', 1
188
      assert_select 'dt.time-entry span.project', 0
189
      assert_select 'dt.time-entry a', :text => /150.00 hours \(Bug #1 \(New\): Cannot print recipes\)/
190
    end
191
  end
192

  
193
  def test_search_time_entries_spent_on_on_project
194
    get :index, :params => {:id => 1, :q => '2007-03-12'}
195
    assert_response :success
196

  
197
    assert_select '#search-results' do
198
      assert_select 'dt.time-entry', 1
199
      assert_select 'dt.time-entry span.project', 0
200
      assert_select 'dt.time-entry a', :text => /150.00 hours \(Bug #1 \(New\): Cannot print recipes\)/
201
    end
202
  end
203

  
146 204
  def test_search_all_projects_with_scope_param
147 205
    get :index, :params => {:q => 'issue', :scope => 'all'}
148 206
    assert_response :success
test/functional/timelog_controller_test.rb
1653 1653
    assert_response :success
1654 1654
    assert_select "td.issue_cf_#{field.id}", :text => 'This is a long text'
1655 1655
  end
1656

  
1657
  def test_default_search_scope
1658
    get :index
1659
    assert_select 'div#quick-search form' do
1660
      assert_select 'input[name=time_entries][value=1][type=hidden]'
1661
    end
1662
  end
1656 1663
end
1657
-