From bc9da9e05642776a6f2fefec736182f413182624 Mon Sep 17 00:00:00 2001 From: Mischa The Evil Date: Wed, 25 Aug 2021 20:18:19 +0200 Subject: [PATCH 2/2] Make time entries searchable by their custom field values. --- app/views/custom_fields/_form.html.erb | 2 +- test/fixtures/custom_fields.yml | 14 ++++++++++++++ test/fixtures/custom_values.yml | 6 ++++++ test/functional/search_controller_test.rb | 11 +++++++++++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/app/views/custom_fields/_form.html.erb b/app/views/custom_fields/_form.html.erb index a7af54a07..2f2ebff8d 100644 --- a/app/views/custom_fields/_form.html.erb +++ b/app/views/custom_fields/_form.html.erb @@ -47,7 +47,7 @@

<%= f.check_box :is_filter %>

<% end %> - <% if %w(IssueCustomField ProjectCustomField).include?(@custom_field.class.name) && @custom_field.format.searchable_supported %> + <% if %w(IssueCustomField ProjectCustomField TimeEntryCustomField).include?(@custom_field.class.name) && @custom_field.format.searchable_supported %>

<%= f.check_box :searchable %>

<% end %> <%= call_hook(:"view_custom_fields_form_#{@custom_field.type.to_s.underscore}", :custom_field => @custom_field, :form => f) %> diff --git a/test/fixtures/custom_fields.yml b/test/fixtures/custom_fields.yml index 98dccdfcb..1bf5859e8 100644 --- a/test/fixtures/custom_fields.yml +++ b/test/fixtures/custom_fields.yml @@ -146,3 +146,17 @@ custom_fields_011: - Other value field_format: list position: 1 +custom_fields_012: + name: Searchable time entry field + regexp: "" + is_for_all: false + is_filter: false + type: TimeEntryCustomField + possible_values: "" + id: 12 + is_required: false + field_format: string + searchable: true + default_value: "" + editable: true + position: 2 diff --git a/test/fixtures/custom_values.yml b/test/fixtures/custom_values.yml index d0dfe3a55..9d12f9b83 100644 --- a/test/fixtures/custom_values.yml +++ b/test/fixtures/custom_values.yml @@ -101,3 +101,9 @@ custom_values_017: customized_id: 1 id: 17 value: '2009-12-01' +custom_values_018: + customized_type: TimeEntry + custom_field_id: 12 + customized_id: 2 + id: 18 + value: "stringfortimeentry custom field search" diff --git a/test/functional/search_controller_test.rb b/test/functional/search_controller_test.rb index 9a62b710c..2b01f9873 100644 --- a/test/functional/search_controller_test.rb +++ b/test/functional/search_controller_test.rb @@ -201,6 +201,17 @@ class SearchControllerTest < Redmine::ControllerTest end end + def test_search_time_entries_searchable_custom_fields_on_project + get :index, :params => {:id => 1, :q => "stringfortimeentry", :time_entries => 1} + 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 -- 2.26.0.windows.1