Project

General

Profile

Feature #4138 » 0001-Make-time-entries-searchable-by-their-comments-hours.patch

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

View differences:

app/controllers/timelog_controller.rb
class TimelogController < ApplicationController
menu_item :time_entries
default_search_scope :time_entries
before_action :find_time_entry, :only => [:show, :edit, :update]
before_action :check_editability, :only => [:edit, :update]
app/models/time_entry.rb
:group => :issue,
:description => :comments
)
acts_as_searchable :columns => ['comments', 'hours', 'spent_on'],
:preload => [:project, :issue, {:issue => :status}]
acts_as_activity_provider :timestamp => "#{table_name}.created_on",
:author_key => :user_id,
:scope => proc {joins(:project).preload(:project)}
lib/redmine.rb
search.register :changesets
search.register :wiki_pages
search.register :messages
search.register :time_entries
search.register :projects
end
test/functional/search_controller_test.rb
assert_response :success
assert_select '#search-results' do
assert_select 'dt.issue a', :text => /Feature request #2/
assert_select 'dt.issue a', :text => /Bug #1/
assert_select 'dt.issue a', :text => /Bug #5/
assert_select 'dt.changeset a', :text => /Revision 1/
assert_select 'dt.issue a', :text => /Add ingredients categories/
assert_select 'dd', :text => /should be classified by categories/
assert_select 'dt.issue a', :text => /Cannot print recipes/
assert_select 'dd', :text => /Unable to print recipes/
end
assert_select '#search-results-counts' do
......
end
end
def test_search_time_entries_comments_on_project
get :index, :params => {:id => 1, :q => 'hours'}
assert_response :success
assert_select '#search-results' do
assert_select 'dt.time-entry', 1
assert_select 'dt.time-entry span.project', 0
assert_select 'dt.time-entry a', :text => /Bug #1 \(New\)/
assert_select 'dd', :text => /My hours/
end
end
def test_search_time_entries_comments_on_project_with_subprojects_scope
get :index, :params => {:id => 1, :q => 'time spent', :scope => 'subprojects', :time_entries => 1}
assert_response :success
assert_select '#search-results' do
assert_select 'dt.time-entry', 1
assert_select 'dt.time-entry span.project', 1
assert_select 'dt.time-entry a', :text => /\(Project: eCookbook Subproject 1\)/
assert_select 'dd', :text => /Time spent on a subproject/
end
end
def test_search_time_entries_comments_on_all_projects
get :index, :params => {:q => 'recipe subproject commit', :all_words => ''}
assert_response :success
assert_select '#search-results' do
assert_select 'dt.time-entry', 1
assert_select 'dt.time-entry span.project', 1
assert_select 'dt.time-entry a', :text => /7.65 hours \(Project: eCookbook Subproject 1\)/
assert_select 'dd', :text => /Time spent on a subproject/
end
end
def test_search_time_entries_hours_on_project
get :index, :params => {:id => 1, :q => '"150"'}
assert_response :success
assert_select '#search-results' do
assert_select 'dt.time-entry', 1
assert_select 'dt.time-entry span.project', 0
assert_select 'dt.time-entry a', :text => /150.00 hours \(Bug #1 \(New\): Cannot print recipes\)/
end
end
def test_search_time_entries_spent_on_on_project
get :index, :params => {:id => 1, :q => '2007-03-12'}
assert_response :success
assert_select '#search-results' do
assert_select 'dt.time-entry', 1
assert_select 'dt.time-entry span.project', 0
assert_select 'dt.time-entry a', :text => /150.00 hours \(Bug #1 \(New\): Cannot print recipes\)/
end
end
def test_search_all_projects_with_scope_param
get :index, :params => {:q => 'issue', :scope => 'all'}
assert_response :success
test/functional/timelog_controller_test.rb
assert_response :success
assert_select "td.issue_cf_#{field.id}", :text => 'This is a long text'
end
def test_default_search_scope
get :index
assert_select 'div#quick-search form' do
assert_select 'input[name=time_entries][value=1][type=hidden]'
end
end
end
(3-3/4)