Project

General

Profile

Feature #4138 » rm4138-make_time_entries_and_their_custom_fields_searchable-trunk_r12406.diff

Mischa The Evil, 2013-12-16 11:48

View differences:

app/controllers/timelog_controller.rb (working copy)
class TimelogController < ApplicationController
menu_item :issues
default_search_scope :time_entries
before_filter :find_project_for_new_time_entry, :only => [:create]
before_filter :find_time_entry, :only => [:show, :edit, :update]
app/models/time_entry.rb (working copy)
:author => :user,
:group => :issue,
:description => :comments
acts_as_searchable :columns => 'comments'
acts_as_activity_provider :timestamp => "#{table_name}.created_on",
:author_key => :user_id,
:find_options => {:include => :project}
app/views/custom_fields/_form.html.erb (working copy)
<% when "TimeEntryCustomField" %>
<p><%= f.check_box :is_required %></p>
<p><%= f.check_box :is_filter %></p>
<% if @custom_field.format.searchable_supported %>
<p><%= f.check_box :searchable %></p>
<% end %>
<% else %>
<p><%= f.check_box :is_required %></p>
lib/redmine.rb (working copy)
search.register :changesets
search.register :wiki_pages
search.register :messages
search.register :time_entries
search.register :projects
end
test/fixtures/custom_fields.yml (working copy)
SGXDqWzDp2prc2Tigqw2NTTDuQ==
- Other value
field_format: list
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
test/fixtures/custom_values.yml (working copy)
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"
test/functional/search_controller_test.rb (working copy)
fixtures :projects, :enabled_modules, :roles, :users, :members, :member_roles,
:issues, :trackers, :issue_statuses, :enumerations,
:custom_fields, :custom_values,
:repositories, :changesets
:repositories, :changesets,
:time_entries
def setup
User.current = nil
......
assert_response :success
assert_template 'index'
assert assigns(:results).include?(Issue.find(2))
assert assigns(:results).include?(Issue.find(3))
assert assigns(:results).include?(Issue.find(5))
assert assigns(:results).include?(Changeset.find(101))
assert_tag :dt, :attributes => { :class => /issue/ },
:child => { :tag => 'a', :content => /Add ingredients categories/ },
:sibling => { :tag => 'dd', :content => /should be classified by categories/ }
:child => { :tag => 'a', :content => /Error 281 when updating a/ },
:sibling => { :tag => 'dd', :content => /Error 281 is encountered when/ }
assert assigns(:results_by_type).is_a?(Hash)
assert_equal 5, assigns(:results_by_type)['changesets']
......
assert_not_include Issue.find(2), assigns(:results)
end
def test_search_time_entries_on_project
get :index, :id => 1, :q => 'hours'
assert_response :success
assert_template 'index'
results = assigns(:results)
assert_not_nil results
assert_equal 1, results.size
assert assigns(:results).include?(TimeEntry.find(1))
assert_tag :dt, :attributes => { :class => /time-entry/ },
:child => { :tag => 'a', :content => /\(Bug #1 \(New\): Can&#x27;t print recipes\)/ },
:sibling => { :tag => 'dd', :content => /My/ }
end
def test_search_time_entries_on_project_with_subprojects_scope
get :index, :id => 1, :q => 'time spent', :scope => 'subprojects', :time_entries => 1
assert_response :success
assert_template 'index'
results = assigns(:results)
assert_not_nil results
assert_equal 1, results.size
assert assigns(:results).include?(TimeEntry.find(4))
assert_tag :dt, :attributes => { :class => /time-entry/ },
:child => { :tag => 'a', :content => /\(Project: eCookbook Subproject 1\)/ },
:sibling => { :tag => 'dd', :content => /on a subproject/ }
end
def test_search_time_entries_on_all_projects
get :index, :q => 'recipe subproject commit', :all_words => ''
assert_response :success
assert_template 'index'
assert assigns(:results).include?(TimeEntry.find(4))
assert_tag :dt, :attributes => { :class => /time-entry/ },
:child => { :tag => 'a', :content => /7.65 hours/ },
:sibling => { :tag => 'dd', :content => /Time spent on a/ }
assert_equal 1, assigns(:results_by_type)['time_entries']
end
def test_search_all_projects_with_scope_param
get :index, :q => 'issue', :scope => 'all'
assert_response :success
......
assert results.include?(Issue.find(7))
end
def test_search_time_entries_with_searchable_custom_fields
get :index, :id => 1, :q => "stringfortimeentry", :time_entries => 1
assert_response :success
results = assigns(:results)
assert_not_nil results
assert_equal 1, results.size
assert results.include?(TimeEntry.find(2))
end
def test_search_all_words
# 'all words' is on by default
get :index, :id => 1, :q => 'recipe updating saving', :all_words => '1'
test/functional/timelog_controller_test.rb (working copy)
assert_response :success
assert_equal 'text/csv; header=present', response.content_type
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-2/4)