From 5d8a838be077d8f8f9ec8b9f270252854acc44fa Mon Sep 17 00:00:00 2001 From: Mischa The Evil Date: Wed, 25 Aug 2021 20:13:15 +0200 Subject: [PATCH 1/2] Make time entries searchable by their 'comments', 'hours' and 'spent_on' attributes. --- app/controllers/timelog_controller.rb | 1 + app/models/time_entry.rb | 2 + lib/redmine.rb | 1 + test/functional/search_controller_test.rb | 64 +++++++++++++++++++++- test/functional/timelog_controller_test.rb | 7 +++ 5 files changed, 72 insertions(+), 3 deletions(-) diff --git a/app/controllers/timelog_controller.rb b/app/controllers/timelog_controller.rb index 3c3dc9df3..d6a8b5176 100644 --- a/app/controllers/timelog_controller.rb +++ b/app/controllers/timelog_controller.rb @@ -19,6 +19,7 @@ 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] diff --git a/app/models/time_entry.rb b/app/models/time_entry.rb index b5926c612..1ee57b0d9 100644 --- a/app/models/time_entry.rb +++ b/app/models/time_entry.rb @@ -43,6 +43,8 @@ class TimeEntry < ActiveRecord::Base :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)} diff --git a/lib/redmine.rb b/lib/redmine.rb index 684d484b5..4c1a1a72f 100644 --- a/lib/redmine.rb +++ b/lib/redmine.rb @@ -441,6 +441,7 @@ Redmine::Search.map do |search| search.register :changesets search.register :wiki_pages search.register :messages + search.register :time_entries search.register :projects end diff --git a/test/functional/search_controller_test.rb b/test/functional/search_controller_test.rb index afe037a05..9a62b710c 100644 --- a/test/functional/search_controller_test.rb +++ b/test/functional/search_controller_test.rb @@ -74,12 +74,12 @@ class SearchControllerTest < Redmine::ControllerTest 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 @@ -143,6 +143,64 @@ class SearchControllerTest < Redmine::ControllerTest 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 diff --git a/test/functional/timelog_controller_test.rb b/test/functional/timelog_controller_test.rb index b1a4899cc..429633849 100644 --- a/test/functional/timelog_controller_test.rb +++ b/test/functional/timelog_controller_test.rb @@ -1653,4 +1653,11 @@ class TimelogControllerTest < Redmine::ControllerTest 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 -- 2.26.0.windows.1