##// END OF EJS Templates
Code cleanup, use named routes....
Jean-Philippe Lang -
r10841:ad246e81ad52
parent child
Show More

The requested changes are too big and content was truncated. Show full diff

@@ -1,150 +1,150
1 <h2><%= @copy ? l(:button_copy) : l(:label_bulk_edit_selected_issues) %></h2>
1 <h2><%= @copy ? l(:button_copy) : l(:label_bulk_edit_selected_issues) %></h2>
2
2
3 <ul>
3 <ul id="bulk-selection">
4 <% @issues.each do |issue| %>
4 <% @issues.each do |issue| %>
5 <%= content_tag 'li', link_to_issue(issue) %>
5 <%= content_tag 'li', link_to_issue(issue) %>
6 <% end %>
6 <% end %>
7 </ul>
7 </ul>
8
8
9 <%= form_tag({:action => 'bulk_update'}, :id => 'bulk_edit_form') do %>
9 <%= form_tag(bulk_update_issues_path, :id => 'bulk_edit_form') do %>
10 <%= @issues.collect {|i| hidden_field_tag('ids[]', i.id)}.join("\n").html_safe %>
10 <%= @issues.collect {|i| hidden_field_tag('ids[]', i.id)}.join("\n").html_safe %>
11 <div class="box tabular">
11 <div class="box tabular">
12 <fieldset class="attributes">
12 <fieldset class="attributes">
13 <legend><%= l(:label_change_properties) %></legend>
13 <legend><%= l(:label_change_properties) %></legend>
14
14
15 <div class="splitcontentleft">
15 <div class="splitcontentleft">
16 <% if @allowed_projects.present? %>
16 <% if @allowed_projects.present? %>
17 <p>
17 <p>
18 <label for="issue_project_id"><%= l(:field_project) %></label>
18 <label for="issue_project_id"><%= l(:field_project) %></label>
19 <%= select_tag('issue[project_id]', content_tag('option', l(:label_no_change_option), :value => '') + project_tree_options_for_select(@allowed_projects, :selected => @target_project),
19 <%= select_tag('issue[project_id]', content_tag('option', l(:label_no_change_option), :value => '') + project_tree_options_for_select(@allowed_projects, :selected => @target_project),
20 :onchange => "updateBulkEditFrom('#{escape_javascript url_for(:action => 'bulk_edit', :format => 'js')}')") %>
20 :onchange => "updateBulkEditFrom('#{escape_javascript url_for(:action => 'bulk_edit', :format => 'js')}')") %>
21 </p>
21 </p>
22 <% end %>
22 <% end %>
23 <p>
23 <p>
24 <label for="issue_tracker_id"><%= l(:field_tracker) %></label>
24 <label for="issue_tracker_id"><%= l(:field_tracker) %></label>
25 <%= select_tag('issue[tracker_id]', content_tag('option', l(:label_no_change_option), :value => '') + options_from_collection_for_select(@trackers, :id, :name)) %>
25 <%= select_tag('issue[tracker_id]', content_tag('option', l(:label_no_change_option), :value => '') + options_from_collection_for_select(@trackers, :id, :name)) %>
26 </p>
26 </p>
27 <% if @available_statuses.any? %>
27 <% if @available_statuses.any? %>
28 <p>
28 <p>
29 <label for='issue_status_id'><%= l(:field_status) %></label>
29 <label for='issue_status_id'><%= l(:field_status) %></label>
30 <%= select_tag('issue[status_id]',content_tag('option', l(:label_no_change_option), :value => '') + options_from_collection_for_select(@available_statuses, :id, :name)) %>
30 <%= select_tag('issue[status_id]',content_tag('option', l(:label_no_change_option), :value => '') + options_from_collection_for_select(@available_statuses, :id, :name)) %>
31 </p>
31 </p>
32 <% end %>
32 <% end %>
33
33
34 <% if @safe_attributes.include?('priority_id') -%>
34 <% if @safe_attributes.include?('priority_id') -%>
35 <p>
35 <p>
36 <label for='issue_priority_id'><%= l(:field_priority) %></label>
36 <label for='issue_priority_id'><%= l(:field_priority) %></label>
37 <%= select_tag('issue[priority_id]', content_tag('option', l(:label_no_change_option), :value => '') + options_from_collection_for_select(IssuePriority.active, :id, :name)) %>
37 <%= select_tag('issue[priority_id]', content_tag('option', l(:label_no_change_option), :value => '') + options_from_collection_for_select(IssuePriority.active, :id, :name)) %>
38 </p>
38 </p>
39 <% end %>
39 <% end %>
40
40
41 <% if @safe_attributes.include?('assigned_to_id') -%>
41 <% if @safe_attributes.include?('assigned_to_id') -%>
42 <p>
42 <p>
43 <label for='issue_assigned_to_id'><%= l(:field_assigned_to) %></label>
43 <label for='issue_assigned_to_id'><%= l(:field_assigned_to) %></label>
44 <%= select_tag('issue[assigned_to_id]', content_tag('option', l(:label_no_change_option), :value => '') +
44 <%= select_tag('issue[assigned_to_id]', content_tag('option', l(:label_no_change_option), :value => '') +
45 content_tag('option', l(:label_nobody), :value => 'none') +
45 content_tag('option', l(:label_nobody), :value => 'none') +
46 principals_options_for_select(@assignables)) %>
46 principals_options_for_select(@assignables)) %>
47 </p>
47 </p>
48 <% end %>
48 <% end %>
49
49
50 <% if @safe_attributes.include?('category_id') -%>
50 <% if @safe_attributes.include?('category_id') -%>
51 <p>
51 <p>
52 <label for='issue_category_id'><%= l(:field_category) %></label>
52 <label for='issue_category_id'><%= l(:field_category) %></label>
53 <%= select_tag('issue[category_id]', content_tag('option', l(:label_no_change_option), :value => '') +
53 <%= select_tag('issue[category_id]', content_tag('option', l(:label_no_change_option), :value => '') +
54 content_tag('option', l(:label_none), :value => 'none') +
54 content_tag('option', l(:label_none), :value => 'none') +
55 options_from_collection_for_select(@categories, :id, :name)) %>
55 options_from_collection_for_select(@categories, :id, :name)) %>
56 </p>
56 </p>
57 <% end %>
57 <% end %>
58
58
59 <% if @safe_attributes.include?('fixed_version_id') -%>
59 <% if @safe_attributes.include?('fixed_version_id') -%>
60 <p>
60 <p>
61 <label for='issue_fixed_version_id'><%= l(:field_fixed_version) %></label>
61 <label for='issue_fixed_version_id'><%= l(:field_fixed_version) %></label>
62 <%= select_tag('issue[fixed_version_id]', content_tag('option', l(:label_no_change_option), :value => '') +
62 <%= select_tag('issue[fixed_version_id]', content_tag('option', l(:label_no_change_option), :value => '') +
63 content_tag('option', l(:label_none), :value => 'none') +
63 content_tag('option', l(:label_none), :value => 'none') +
64 version_options_for_select(@versions.sort)) %>
64 version_options_for_select(@versions.sort)) %>
65 </p>
65 </p>
66 <% end %>
66 <% end %>
67
67
68 <% @custom_fields.each do |custom_field| %>
68 <% @custom_fields.each do |custom_field| %>
69 <p><label><%= h(custom_field.name) %></label> <%= custom_field_tag_for_bulk_edit('issue', custom_field, @projects) %></p>
69 <p><label><%= h(custom_field.name) %></label> <%= custom_field_tag_for_bulk_edit('issue', custom_field, @projects) %></p>
70 <% end %>
70 <% end %>
71
71
72 <% if @copy && @attachments_present %>
72 <% if @copy && @attachments_present %>
73 <p>
73 <p>
74 <label for='copy_attachments'><%= l(:label_copy_attachments) %></label>
74 <label for='copy_attachments'><%= l(:label_copy_attachments) %></label>
75 <%= check_box_tag 'copy_attachments', '1', true %>
75 <%= check_box_tag 'copy_attachments', '1', true %>
76 </p>
76 </p>
77 <% end %>
77 <% end %>
78
78
79 <% if @copy && @subtasks_present %>
79 <% if @copy && @subtasks_present %>
80 <p>
80 <p>
81 <label for='copy_subtasks'><%= l(:label_copy_subtasks) %></label>
81 <label for='copy_subtasks'><%= l(:label_copy_subtasks) %></label>
82 <%= check_box_tag 'copy_subtasks', '1', true %>
82 <%= check_box_tag 'copy_subtasks', '1', true %>
83 </p>
83 </p>
84 <% end %>
84 <% end %>
85
85
86 <%= call_hook(:view_issues_bulk_edit_details_bottom, { :issues => @issues }) %>
86 <%= call_hook(:view_issues_bulk_edit_details_bottom, { :issues => @issues }) %>
87 </div>
87 </div>
88
88
89 <div class="splitcontentright">
89 <div class="splitcontentright">
90 <% if @safe_attributes.include?('is_private') %>
90 <% if @safe_attributes.include?('is_private') %>
91 <p>
91 <p>
92 <label for='issue_is_private'><%= l(:field_is_private) %></label>
92 <label for='issue_is_private'><%= l(:field_is_private) %></label>
93 <%= select_tag('issue[is_private]', content_tag('option', l(:label_no_change_option), :value => '') +
93 <%= select_tag('issue[is_private]', content_tag('option', l(:label_no_change_option), :value => '') +
94 content_tag('option', l(:general_text_Yes), :value => '1') +
94 content_tag('option', l(:general_text_Yes), :value => '1') +
95 content_tag('option', l(:general_text_No), :value => '0')) %>
95 content_tag('option', l(:general_text_No), :value => '0')) %>
96 </p>
96 </p>
97 <% end %>
97 <% end %>
98
98
99 <% if @safe_attributes.include?('parent_issue_id') && @project %>
99 <% if @safe_attributes.include?('parent_issue_id') && @project %>
100 <p>
100 <p>
101 <label for='issue_parent_issue_id'><%= l(:field_parent_issue) %></label>
101 <label for='issue_parent_issue_id'><%= l(:field_parent_issue) %></label>
102 <%= text_field_tag 'issue[parent_issue_id]', '', :size => 10 %>
102 <%= text_field_tag 'issue[parent_issue_id]', '', :size => 10 %>
103 </p>
103 </p>
104 <%= javascript_tag "observeAutocompleteField('issue_parent_issue_id', '#{escape_javascript auto_complete_issues_path(:project_id => @project)}')" %>
104 <%= javascript_tag "observeAutocompleteField('issue_parent_issue_id', '#{escape_javascript auto_complete_issues_path(:project_id => @project)}')" %>
105 <% end %>
105 <% end %>
106
106
107 <% if @safe_attributes.include?('start_date') %>
107 <% if @safe_attributes.include?('start_date') %>
108 <p>
108 <p>
109 <label for='issue_start_date'><%= l(:field_start_date) %></label>
109 <label for='issue_start_date'><%= l(:field_start_date) %></label>
110 <%= text_field_tag 'issue[start_date]', '', :size => 10 %><%= calendar_for('issue_start_date') %>
110 <%= text_field_tag 'issue[start_date]', '', :size => 10 %><%= calendar_for('issue_start_date') %>
111 </p>
111 </p>
112 <% end %>
112 <% end %>
113
113
114 <% if @safe_attributes.include?('due_date') %>
114 <% if @safe_attributes.include?('due_date') %>
115 <p>
115 <p>
116 <label for='issue_due_date'><%= l(:field_due_date) %></label>
116 <label for='issue_due_date'><%= l(:field_due_date) %></label>
117 <%= text_field_tag 'issue[due_date]', '', :size => 10 %><%= calendar_for('issue_due_date') %>
117 <%= text_field_tag 'issue[due_date]', '', :size => 10 %><%= calendar_for('issue_due_date') %>
118 </p>
118 </p>
119 <% end %>
119 <% end %>
120
120
121 <% if @safe_attributes.include?('done_ratio') && Issue.use_field_for_done_ratio? %>
121 <% if @safe_attributes.include?('done_ratio') && Issue.use_field_for_done_ratio? %>
122 <p>
122 <p>
123 <label for='issue_done_ratio'><%= l(:field_done_ratio) %></label>
123 <label for='issue_done_ratio'><%= l(:field_done_ratio) %></label>
124 <%= select_tag 'issue[done_ratio]', options_for_select([[l(:label_no_change_option), '']] + (0..10).to_a.collect {|r| ["#{r*10} %", r*10] }) %>
124 <%= select_tag 'issue[done_ratio]', options_for_select([[l(:label_no_change_option), '']] + (0..10).to_a.collect {|r| ["#{r*10} %", r*10] }) %>
125 </p>
125 </p>
126 <% end %>
126 <% end %>
127 </div>
127 </div>
128
128
129 </fieldset>
129 </fieldset>
130
130
131 <fieldset><legend><%= l(:field_notes) %></legend>
131 <fieldset><legend><%= l(:field_notes) %></legend>
132 <%= text_area_tag 'notes', @notes, :cols => 60, :rows => 10, :class => 'wiki-edit' %>
132 <%= text_area_tag 'notes', @notes, :cols => 60, :rows => 10, :class => 'wiki-edit' %>
133 <%= wikitoolbar_for 'notes' %>
133 <%= wikitoolbar_for 'notes' %>
134 </fieldset>
134 </fieldset>
135 </div>
135 </div>
136
136
137 <p>
137 <p>
138 <% if @copy %>
138 <% if @copy %>
139 <%= hidden_field_tag 'copy', '1' %>
139 <%= hidden_field_tag 'copy', '1' %>
140 <%= submit_tag l(:button_copy) %>
140 <%= submit_tag l(:button_copy) %>
141 <%= submit_tag l(:button_copy_and_follow), :name => 'follow' %>
141 <%= submit_tag l(:button_copy_and_follow), :name => 'follow' %>
142 <% elsif @target_project %>
142 <% elsif @target_project %>
143 <%= submit_tag l(:button_move) %>
143 <%= submit_tag l(:button_move) %>
144 <%= submit_tag l(:button_move_and_follow), :name => 'follow' %>
144 <%= submit_tag l(:button_move_and_follow), :name => 'follow' %>
145 <% else %>
145 <% else %>
146 <%= submit_tag l(:button_submit) %>
146 <%= submit_tag l(:button_submit) %>
147 <% end %>
147 <% end %>
148 </p>
148 </p>
149
149
150 <% end %>
150 <% end %>
@@ -1,50 +1,50
1 <h2><%= l(:label_bulk_edit_selected_time_entries) %></h2>
1 <h2><%= l(:label_bulk_edit_selected_time_entries) %></h2>
2
2
3 <ul>
3 <ul id="bulk-selection">
4 <% @time_entries.each do |entry| %>
4 <% @time_entries.each do |entry| %>
5 <%= content_tag 'li',
5 <%= content_tag 'li',
6 link_to("#{format_date(entry.spent_on)} - #{entry.project}: #{l(:label_f_hour_plural, :value => entry.hours)}", edit_time_entry_path(entry)) %>
6 link_to("#{format_date(entry.spent_on)} - #{entry.project}: #{l(:label_f_hour_plural, :value => entry.hours)}", edit_time_entry_path(entry)) %>
7 <% end %>
7 <% end %>
8 </ul>
8 </ul>
9
9
10 <%= form_tag(:action => 'bulk_update') do %>
10 <%= form_tag(bulk_update_time_entries_path, :id => 'bulk_edit_form') do %>
11 <%= @time_entries.collect {|i| hidden_field_tag('ids[]', i.id)}.join.html_safe %>
11 <%= @time_entries.collect {|i| hidden_field_tag('ids[]', i.id)}.join.html_safe %>
12 <div class="box tabular">
12 <div class="box tabular">
13 <div>
13 <div>
14 <p>
14 <p>
15 <label><%= l(:field_issue) %></label>
15 <label><%= l(:field_issue) %></label>
16 <%= text_field :time_entry, :issue_id, :size => 6 %>
16 <%= text_field :time_entry, :issue_id, :size => 6 %>
17 </p>
17 </p>
18
18
19 <p>
19 <p>
20 <label><%= l(:field_spent_on) %></label>
20 <label><%= l(:field_spent_on) %></label>
21 <%= text_field :time_entry, :spent_on, :size => 10 %><%= calendar_for('time_entry_spent_on') %>
21 <%= text_field :time_entry, :spent_on, :size => 10 %><%= calendar_for('time_entry_spent_on') %>
22 </p>
22 </p>
23
23
24 <p>
24 <p>
25 <label><%= l(:field_hours) %></label>
25 <label><%= l(:field_hours) %></label>
26 <%= text_field :time_entry, :hours, :size => 6 %>
26 <%= text_field :time_entry, :hours, :size => 6 %>
27 </p>
27 </p>
28
28
29 <% if @available_activities.any? %>
29 <% if @available_activities.any? %>
30 <p>
30 <p>
31 <label><%= l(:field_activity) %></label>
31 <label><%= l(:field_activity) %></label>
32 <%= select_tag('time_entry[activity_id]', content_tag('option', l(:label_no_change_option), :value => '') + options_from_collection_for_select(@available_activities, :id, :name)) %>
32 <%= select_tag('time_entry[activity_id]', content_tag('option', l(:label_no_change_option), :value => '') + options_from_collection_for_select(@available_activities, :id, :name)) %>
33 </p>
33 </p>
34 <% end %>
34 <% end %>
35
35
36 <p>
36 <p>
37 <label><%= l(:field_comments) %></label>
37 <label><%= l(:field_comments) %></label>
38 <%= text_field(:time_entry, :comments, :size => 100) %>
38 <%= text_field(:time_entry, :comments, :size => 100) %>
39 </p>
39 </p>
40
40
41 <% @custom_fields.each do |custom_field| %>
41 <% @custom_fields.each do |custom_field| %>
42 <p><label><%= h(custom_field.name) %></label> <%= custom_field_tag_for_bulk_edit('time_entry', custom_field, @projects) %></p>
42 <p><label><%= h(custom_field.name) %></label> <%= custom_field_tag_for_bulk_edit('time_entry', custom_field, @projects) %></p>
43 <% end %>
43 <% end %>
44
44
45 <%= call_hook(:view_time_entries_bulk_edit_details_bottom, { :time_entries => @time_entries }) %>
45 <%= call_hook(:view_time_entries_bulk_edit_details_bottom, { :time_entries => @time_entries }) %>
46 </div>
46 </div>
47 </div>
47 </div>
48
48
49 <p><%= submit_tag l(:button_submit) %></p>
49 <p><%= submit_tag l(:button_submit) %></p>
50 <% end %>
50 <% end %>
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
@@ -1,705 +1,712
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 # Redmine - project management software
2 # Redmine - project management software
3 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 # Copyright (C) 2006-2012 Jean-Philippe Lang
4 #
4 #
5 # This program is free software; you can redistribute it and/or
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
8 # of the License, or (at your option) any later version.
9 #
9 #
10 # This program is distributed in the hope that it will be useful,
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
13 # GNU General Public License for more details.
14 #
14 #
15 # You should have received a copy of the GNU General Public License
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
18
19 require File.expand_path('../../test_helper', __FILE__)
19 require File.expand_path('../../test_helper', __FILE__)
20
20
21 class TimelogControllerTest < ActionController::TestCase
21 class TimelogControllerTest < ActionController::TestCase
22 fixtures :projects, :enabled_modules, :roles, :members,
22 fixtures :projects, :enabled_modules, :roles, :members,
23 :member_roles, :issues, :time_entries, :users,
23 :member_roles, :issues, :time_entries, :users,
24 :trackers, :enumerations, :issue_statuses,
24 :trackers, :enumerations, :issue_statuses,
25 :custom_fields, :custom_values
25 :custom_fields, :custom_values
26
26
27 include Redmine::I18n
27 include Redmine::I18n
28
28
29 def test_new_with_project_id
29 def test_new_with_project_id
30 @request.session[:user_id] = 3
30 @request.session[:user_id] = 3
31 get :new, :project_id => 1
31 get :new, :project_id => 1
32 assert_response :success
32 assert_response :success
33 assert_template 'new'
33 assert_template 'new'
34 assert_select 'select[name=?]', 'time_entry[project_id]', 0
34 assert_select 'select[name=?]', 'time_entry[project_id]', 0
35 assert_select 'input[name=?][value=1][type=hidden]', 'time_entry[project_id]'
35 assert_select 'input[name=?][value=1][type=hidden]', 'time_entry[project_id]'
36 end
36 end
37
37
38 def test_new_with_issue_id
38 def test_new_with_issue_id
39 @request.session[:user_id] = 3
39 @request.session[:user_id] = 3
40 get :new, :issue_id => 2
40 get :new, :issue_id => 2
41 assert_response :success
41 assert_response :success
42 assert_template 'new'
42 assert_template 'new'
43 assert_select 'select[name=?]', 'time_entry[project_id]', 0
43 assert_select 'select[name=?]', 'time_entry[project_id]', 0
44 assert_select 'input[name=?][value=1][type=hidden]', 'time_entry[project_id]'
44 assert_select 'input[name=?][value=1][type=hidden]', 'time_entry[project_id]'
45 end
45 end
46
46
47 def test_new_without_project
47 def test_new_without_project
48 @request.session[:user_id] = 3
48 @request.session[:user_id] = 3
49 get :new
49 get :new
50 assert_response :success
50 assert_response :success
51 assert_template 'new'
51 assert_template 'new'
52 assert_select 'select[name=?]', 'time_entry[project_id]'
52 assert_select 'select[name=?]', 'time_entry[project_id]'
53 assert_select 'input[name=?]', 'time_entry[project_id]', 0
53 assert_select 'input[name=?]', 'time_entry[project_id]', 0
54 end
54 end
55
55
56 def test_new_without_project_should_prefill_the_form
56 def test_new_without_project_should_prefill_the_form
57 @request.session[:user_id] = 3
57 @request.session[:user_id] = 3
58 get :new, :time_entry => {:project_id => '1'}
58 get :new, :time_entry => {:project_id => '1'}
59 assert_response :success
59 assert_response :success
60 assert_template 'new'
60 assert_template 'new'
61 assert_select 'select[name=?]', 'time_entry[project_id]' do
61 assert_select 'select[name=?]', 'time_entry[project_id]' do
62 assert_select 'option[value=1][selected=selected]'
62 assert_select 'option[value=1][selected=selected]'
63 end
63 end
64 assert_select 'input[name=?]', 'time_entry[project_id]', 0
64 assert_select 'input[name=?]', 'time_entry[project_id]', 0
65 end
65 end
66
66
67 def test_new_without_project_should_deny_without_permission
67 def test_new_without_project_should_deny_without_permission
68 Role.all.each {|role| role.remove_permission! :log_time}
68 Role.all.each {|role| role.remove_permission! :log_time}
69 @request.session[:user_id] = 3
69 @request.session[:user_id] = 3
70
70
71 get :new
71 get :new
72 assert_response 403
72 assert_response 403
73 end
73 end
74
74
75 def test_new_should_select_default_activity
75 def test_new_should_select_default_activity
76 @request.session[:user_id] = 3
76 @request.session[:user_id] = 3
77 get :new, :project_id => 1
77 get :new, :project_id => 1
78 assert_response :success
78 assert_response :success
79 assert_select 'select[name=?]', 'time_entry[activity_id]' do
79 assert_select 'select[name=?]', 'time_entry[activity_id]' do
80 assert_select 'option[selected=selected]', :text => 'Development'
80 assert_select 'option[selected=selected]', :text => 'Development'
81 end
81 end
82 end
82 end
83
83
84 def test_new_should_only_show_active_time_entry_activities
84 def test_new_should_only_show_active_time_entry_activities
85 @request.session[:user_id] = 3
85 @request.session[:user_id] = 3
86 get :new, :project_id => 1
86 get :new, :project_id => 1
87 assert_response :success
87 assert_response :success
88 assert_no_tag 'option', :content => 'Inactive Activity'
88 assert_no_tag 'option', :content => 'Inactive Activity'
89 end
89 end
90
90
91 def test_get_edit_existing_time
91 def test_get_edit_existing_time
92 @request.session[:user_id] = 2
92 @request.session[:user_id] = 2
93 get :edit, :id => 2, :project_id => nil
93 get :edit, :id => 2, :project_id => nil
94 assert_response :success
94 assert_response :success
95 assert_template 'edit'
95 assert_template 'edit'
96 # Default activity selected
96 # Default activity selected
97 assert_tag :tag => 'form', :attributes => { :action => '/projects/ecookbook/time_entries/2' }
97 assert_tag :tag => 'form', :attributes => { :action => '/projects/ecookbook/time_entries/2' }
98 end
98 end
99
99
100 def test_get_edit_with_an_existing_time_entry_with_inactive_activity
100 def test_get_edit_with_an_existing_time_entry_with_inactive_activity
101 te = TimeEntry.find(1)
101 te = TimeEntry.find(1)
102 te.activity = TimeEntryActivity.find_by_name("Inactive Activity")
102 te.activity = TimeEntryActivity.find_by_name("Inactive Activity")
103 te.save!
103 te.save!
104
104
105 @request.session[:user_id] = 1
105 @request.session[:user_id] = 1
106 get :edit, :project_id => 1, :id => 1
106 get :edit, :project_id => 1, :id => 1
107 assert_response :success
107 assert_response :success
108 assert_template 'edit'
108 assert_template 'edit'
109 # Blank option since nothing is pre-selected
109 # Blank option since nothing is pre-selected
110 assert_tag :tag => 'option', :content => '--- Please select ---'
110 assert_tag :tag => 'option', :content => '--- Please select ---'
111 end
111 end
112
112
113 def test_post_create
113 def test_post_create
114 # TODO: should POST to issues’ time log instead of project. change form
114 # TODO: should POST to issues’ time log instead of project. change form
115 # and routing
115 # and routing
116 @request.session[:user_id] = 3
116 @request.session[:user_id] = 3
117 post :create, :project_id => 1,
117 post :create, :project_id => 1,
118 :time_entry => {:comments => 'Some work on TimelogControllerTest',
118 :time_entry => {:comments => 'Some work on TimelogControllerTest',
119 # Not the default activity
119 # Not the default activity
120 :activity_id => '11',
120 :activity_id => '11',
121 :spent_on => '2008-03-14',
121 :spent_on => '2008-03-14',
122 :issue_id => '1',
122 :issue_id => '1',
123 :hours => '7.3'}
123 :hours => '7.3'}
124 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
124 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
125
125
126 i = Issue.find(1)
126 i = Issue.find(1)
127 t = TimeEntry.find_by_comments('Some work on TimelogControllerTest')
127 t = TimeEntry.find_by_comments('Some work on TimelogControllerTest')
128 assert_not_nil t
128 assert_not_nil t
129 assert_equal 11, t.activity_id
129 assert_equal 11, t.activity_id
130 assert_equal 7.3, t.hours
130 assert_equal 7.3, t.hours
131 assert_equal 3, t.user_id
131 assert_equal 3, t.user_id
132 assert_equal i, t.issue
132 assert_equal i, t.issue
133 assert_equal i.project, t.project
133 assert_equal i.project, t.project
134 end
134 end
135
135
136 def test_post_create_with_blank_issue
136 def test_post_create_with_blank_issue
137 # TODO: should POST to issues’ time log instead of project. change form
137 # TODO: should POST to issues’ time log instead of project. change form
138 # and routing
138 # and routing
139 @request.session[:user_id] = 3
139 @request.session[:user_id] = 3
140 post :create, :project_id => 1,
140 post :create, :project_id => 1,
141 :time_entry => {:comments => 'Some work on TimelogControllerTest',
141 :time_entry => {:comments => 'Some work on TimelogControllerTest',
142 # Not the default activity
142 # Not the default activity
143 :activity_id => '11',
143 :activity_id => '11',
144 :issue_id => '',
144 :issue_id => '',
145 :spent_on => '2008-03-14',
145 :spent_on => '2008-03-14',
146 :hours => '7.3'}
146 :hours => '7.3'}
147 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
147 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
148
148
149 t = TimeEntry.find_by_comments('Some work on TimelogControllerTest')
149 t = TimeEntry.find_by_comments('Some work on TimelogControllerTest')
150 assert_not_nil t
150 assert_not_nil t
151 assert_equal 11, t.activity_id
151 assert_equal 11, t.activity_id
152 assert_equal 7.3, t.hours
152 assert_equal 7.3, t.hours
153 assert_equal 3, t.user_id
153 assert_equal 3, t.user_id
154 end
154 end
155
155
156 def test_create_and_continue
156 def test_create_and_continue
157 @request.session[:user_id] = 2
157 @request.session[:user_id] = 2
158 post :create, :project_id => 1,
158 post :create, :project_id => 1,
159 :time_entry => {:activity_id => '11',
159 :time_entry => {:activity_id => '11',
160 :issue_id => '',
160 :issue_id => '',
161 :spent_on => '2008-03-14',
161 :spent_on => '2008-03-14',
162 :hours => '7.3'},
162 :hours => '7.3'},
163 :continue => '1'
163 :continue => '1'
164 assert_redirected_to '/projects/ecookbook/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D='
164 assert_redirected_to '/projects/ecookbook/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D='
165 end
165 end
166
166
167 def test_create_and_continue_with_issue_id
167 def test_create_and_continue_with_issue_id
168 @request.session[:user_id] = 2
168 @request.session[:user_id] = 2
169 post :create, :project_id => 1,
169 post :create, :project_id => 1,
170 :time_entry => {:activity_id => '11',
170 :time_entry => {:activity_id => '11',
171 :issue_id => '1',
171 :issue_id => '1',
172 :spent_on => '2008-03-14',
172 :spent_on => '2008-03-14',
173 :hours => '7.3'},
173 :hours => '7.3'},
174 :continue => '1'
174 :continue => '1'
175 assert_redirected_to '/projects/ecookbook/issues/1/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=1'
175 assert_redirected_to '/projects/ecookbook/issues/1/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=1'
176 end
176 end
177
177
178 def test_create_and_continue_without_project
178 def test_create_and_continue_without_project
179 @request.session[:user_id] = 2
179 @request.session[:user_id] = 2
180 post :create, :time_entry => {:project_id => '1',
180 post :create, :time_entry => {:project_id => '1',
181 :activity_id => '11',
181 :activity_id => '11',
182 :issue_id => '',
182 :issue_id => '',
183 :spent_on => '2008-03-14',
183 :spent_on => '2008-03-14',
184 :hours => '7.3'},
184 :hours => '7.3'},
185 :continue => '1'
185 :continue => '1'
186
186
187 assert_redirected_to '/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=&time_entry%5Bproject_id%5D=1'
187 assert_redirected_to '/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=&time_entry%5Bproject_id%5D=1'
188 end
188 end
189
189
190 def test_create_without_log_time_permission_should_be_denied
190 def test_create_without_log_time_permission_should_be_denied
191 @request.session[:user_id] = 2
191 @request.session[:user_id] = 2
192 Role.find_by_name('Manager').remove_permission! :log_time
192 Role.find_by_name('Manager').remove_permission! :log_time
193 post :create, :project_id => 1,
193 post :create, :project_id => 1,
194 :time_entry => {:activity_id => '11',
194 :time_entry => {:activity_id => '11',
195 :issue_id => '',
195 :issue_id => '',
196 :spent_on => '2008-03-14',
196 :spent_on => '2008-03-14',
197 :hours => '7.3'}
197 :hours => '7.3'}
198
198
199 assert_response 403
199 assert_response 403
200 end
200 end
201
201
202 def test_create_with_failure
202 def test_create_with_failure
203 @request.session[:user_id] = 2
203 @request.session[:user_id] = 2
204 post :create, :project_id => 1,
204 post :create, :project_id => 1,
205 :time_entry => {:activity_id => '',
205 :time_entry => {:activity_id => '',
206 :issue_id => '',
206 :issue_id => '',
207 :spent_on => '2008-03-14',
207 :spent_on => '2008-03-14',
208 :hours => '7.3'}
208 :hours => '7.3'}
209
209
210 assert_response :success
210 assert_response :success
211 assert_template 'new'
211 assert_template 'new'
212 end
212 end
213
213
214 def test_create_without_project
214 def test_create_without_project
215 @request.session[:user_id] = 2
215 @request.session[:user_id] = 2
216 assert_difference 'TimeEntry.count' do
216 assert_difference 'TimeEntry.count' do
217 post :create, :time_entry => {:project_id => '1',
217 post :create, :time_entry => {:project_id => '1',
218 :activity_id => '11',
218 :activity_id => '11',
219 :issue_id => '',
219 :issue_id => '',
220 :spent_on => '2008-03-14',
220 :spent_on => '2008-03-14',
221 :hours => '7.3'}
221 :hours => '7.3'}
222 end
222 end
223
223
224 assert_redirected_to '/projects/ecookbook/time_entries'
224 assert_redirected_to '/projects/ecookbook/time_entries'
225 time_entry = TimeEntry.first(:order => 'id DESC')
225 time_entry = TimeEntry.first(:order => 'id DESC')
226 assert_equal 1, time_entry.project_id
226 assert_equal 1, time_entry.project_id
227 end
227 end
228
228
229 def test_create_without_project_should_fail_with_issue_not_inside_project
229 def test_create_without_project_should_fail_with_issue_not_inside_project
230 @request.session[:user_id] = 2
230 @request.session[:user_id] = 2
231 assert_no_difference 'TimeEntry.count' do
231 assert_no_difference 'TimeEntry.count' do
232 post :create, :time_entry => {:project_id => '1',
232 post :create, :time_entry => {:project_id => '1',
233 :activity_id => '11',
233 :activity_id => '11',
234 :issue_id => '5',
234 :issue_id => '5',
235 :spent_on => '2008-03-14',
235 :spent_on => '2008-03-14',
236 :hours => '7.3'}
236 :hours => '7.3'}
237 end
237 end
238
238
239 assert_response :success
239 assert_response :success
240 assert assigns(:time_entry).errors[:issue_id].present?
240 assert assigns(:time_entry).errors[:issue_id].present?
241 end
241 end
242
242
243 def test_create_without_project_should_deny_without_permission
243 def test_create_without_project_should_deny_without_permission
244 @request.session[:user_id] = 2
244 @request.session[:user_id] = 2
245 Project.find(3).disable_module!(:time_tracking)
245 Project.find(3).disable_module!(:time_tracking)
246
246
247 assert_no_difference 'TimeEntry.count' do
247 assert_no_difference 'TimeEntry.count' do
248 post :create, :time_entry => {:project_id => '3',
248 post :create, :time_entry => {:project_id => '3',
249 :activity_id => '11',
249 :activity_id => '11',
250 :issue_id => '',
250 :issue_id => '',
251 :spent_on => '2008-03-14',
251 :spent_on => '2008-03-14',
252 :hours => '7.3'}
252 :hours => '7.3'}
253 end
253 end
254
254
255 assert_response 403
255 assert_response 403
256 end
256 end
257
257
258 def test_create_without_project_with_failure
258 def test_create_without_project_with_failure
259 @request.session[:user_id] = 2
259 @request.session[:user_id] = 2
260 assert_no_difference 'TimeEntry.count' do
260 assert_no_difference 'TimeEntry.count' do
261 post :create, :time_entry => {:project_id => '1',
261 post :create, :time_entry => {:project_id => '1',
262 :activity_id => '11',
262 :activity_id => '11',
263 :issue_id => '',
263 :issue_id => '',
264 :spent_on => '2008-03-14',
264 :spent_on => '2008-03-14',
265 :hours => ''}
265 :hours => ''}
266 end
266 end
267
267
268 assert_response :success
268 assert_response :success
269 assert_tag 'select', :attributes => {:name => 'time_entry[project_id]'},
269 assert_tag 'select', :attributes => {:name => 'time_entry[project_id]'},
270 :child => {:tag => 'option', :attributes => {:value => '1', :selected => 'selected'}}
270 :child => {:tag => 'option', :attributes => {:value => '1', :selected => 'selected'}}
271 end
271 end
272
272
273 def test_update
273 def test_update
274 entry = TimeEntry.find(1)
274 entry = TimeEntry.find(1)
275 assert_equal 1, entry.issue_id
275 assert_equal 1, entry.issue_id
276 assert_equal 2, entry.user_id
276 assert_equal 2, entry.user_id
277
277
278 @request.session[:user_id] = 1
278 @request.session[:user_id] = 1
279 put :update, :id => 1,
279 put :update, :id => 1,
280 :time_entry => {:issue_id => '2',
280 :time_entry => {:issue_id => '2',
281 :hours => '8'}
281 :hours => '8'}
282 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
282 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
283 entry.reload
283 entry.reload
284
284
285 assert_equal 8, entry.hours
285 assert_equal 8, entry.hours
286 assert_equal 2, entry.issue_id
286 assert_equal 2, entry.issue_id
287 assert_equal 2, entry.user_id
287 assert_equal 2, entry.user_id
288 end
288 end
289
289
290 def test_get_bulk_edit
290 def test_get_bulk_edit
291 @request.session[:user_id] = 2
291 @request.session[:user_id] = 2
292 get :bulk_edit, :ids => [1, 2]
292 get :bulk_edit, :ids => [1, 2]
293 assert_response :success
293 assert_response :success
294 assert_template 'bulk_edit'
294 assert_template 'bulk_edit'
295
295
296 # System wide custom field
296 assert_select 'ul#bulk-selection' do
297 assert_tag :select, :attributes => {:name => 'time_entry[custom_field_values][10]'}
297 assert_select 'li', 2
298 assert_select 'li a', :text => '03/23/2007 - eCookbook: 4.25 hours'
299 end
298
300
299 # Activities
301 assert_select 'form#bulk_edit_form[action=?]', '/time_entries/bulk_update' do
300 assert_select 'select[name=?]', 'time_entry[activity_id]' do
302 # System wide custom field
301 assert_select 'option[value=]', :text => '(No change)'
303 assert_select 'select[name=?]', 'time_entry[custom_field_values][10]'
302 assert_select 'option[value=9]', :text => 'Design'
304
305 # Activities
306 assert_select 'select[name=?]', 'time_entry[activity_id]' do
307 assert_select 'option[value=]', :text => '(No change)'
308 assert_select 'option[value=9]', :text => 'Design'
309 end
303 end
310 end
304 end
311 end
305
312
306 def test_get_bulk_edit_on_different_projects
313 def test_get_bulk_edit_on_different_projects
307 @request.session[:user_id] = 2
314 @request.session[:user_id] = 2
308 get :bulk_edit, :ids => [1, 2, 6]
315 get :bulk_edit, :ids => [1, 2, 6]
309 assert_response :success
316 assert_response :success
310 assert_template 'bulk_edit'
317 assert_template 'bulk_edit'
311 end
318 end
312
319
313 def test_bulk_update
320 def test_bulk_update
314 @request.session[:user_id] = 2
321 @request.session[:user_id] = 2
315 # update time entry activity
322 # update time entry activity
316 post :bulk_update, :ids => [1, 2], :time_entry => { :activity_id => 9}
323 post :bulk_update, :ids => [1, 2], :time_entry => { :activity_id => 9}
317
324
318 assert_response 302
325 assert_response 302
319 # check that the issues were updated
326 # check that the issues were updated
320 assert_equal [9, 9], TimeEntry.find_all_by_id([1, 2]).collect {|i| i.activity_id}
327 assert_equal [9, 9], TimeEntry.find_all_by_id([1, 2]).collect {|i| i.activity_id}
321 end
328 end
322
329
323 def test_bulk_update_with_failure
330 def test_bulk_update_with_failure
324 @request.session[:user_id] = 2
331 @request.session[:user_id] = 2
325 post :bulk_update, :ids => [1, 2], :time_entry => { :hours => 'A'}
332 post :bulk_update, :ids => [1, 2], :time_entry => { :hours => 'A'}
326
333
327 assert_response 302
334 assert_response 302
328 assert_match /Failed to save 2 time entrie/, flash[:error]
335 assert_match /Failed to save 2 time entrie/, flash[:error]
329 end
336 end
330
337
331 def test_bulk_update_on_different_projects
338 def test_bulk_update_on_different_projects
332 @request.session[:user_id] = 2
339 @request.session[:user_id] = 2
333 # makes user a manager on the other project
340 # makes user a manager on the other project
334 Member.create!(:user_id => 2, :project_id => 3, :role_ids => [1])
341 Member.create!(:user_id => 2, :project_id => 3, :role_ids => [1])
335
342
336 # update time entry activity
343 # update time entry activity
337 post :bulk_update, :ids => [1, 2, 4], :time_entry => { :activity_id => 9 }
344 post :bulk_update, :ids => [1, 2, 4], :time_entry => { :activity_id => 9 }
338
345
339 assert_response 302
346 assert_response 302
340 # check that the issues were updated
347 # check that the issues were updated
341 assert_equal [9, 9, 9], TimeEntry.find_all_by_id([1, 2, 4]).collect {|i| i.activity_id}
348 assert_equal [9, 9, 9], TimeEntry.find_all_by_id([1, 2, 4]).collect {|i| i.activity_id}
342 end
349 end
343
350
344 def test_bulk_update_on_different_projects_without_rights
351 def test_bulk_update_on_different_projects_without_rights
345 @request.session[:user_id] = 3
352 @request.session[:user_id] = 3
346 user = User.find(3)
353 user = User.find(3)
347 action = { :controller => "timelog", :action => "bulk_update" }
354 action = { :controller => "timelog", :action => "bulk_update" }
348 assert user.allowed_to?(action, TimeEntry.find(1).project)
355 assert user.allowed_to?(action, TimeEntry.find(1).project)
349 assert ! user.allowed_to?(action, TimeEntry.find(5).project)
356 assert ! user.allowed_to?(action, TimeEntry.find(5).project)
350 post :bulk_update, :ids => [1, 5], :time_entry => { :activity_id => 9 }
357 post :bulk_update, :ids => [1, 5], :time_entry => { :activity_id => 9 }
351 assert_response 403
358 assert_response 403
352 end
359 end
353
360
354 def test_bulk_update_custom_field
361 def test_bulk_update_custom_field
355 @request.session[:user_id] = 2
362 @request.session[:user_id] = 2
356 post :bulk_update, :ids => [1, 2], :time_entry => { :custom_field_values => {'10' => '0'} }
363 post :bulk_update, :ids => [1, 2], :time_entry => { :custom_field_values => {'10' => '0'} }
357
364
358 assert_response 302
365 assert_response 302
359 assert_equal ["0", "0"], TimeEntry.find_all_by_id([1, 2]).collect {|i| i.custom_value_for(10).value}
366 assert_equal ["0", "0"], TimeEntry.find_all_by_id([1, 2]).collect {|i| i.custom_value_for(10).value}
360 end
367 end
361
368
362 def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter
369 def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter
363 @request.session[:user_id] = 2
370 @request.session[:user_id] = 2
364 post :bulk_update, :ids => [1,2], :back_url => '/time_entries'
371 post :bulk_update, :ids => [1,2], :back_url => '/time_entries'
365
372
366 assert_response :redirect
373 assert_response :redirect
367 assert_redirected_to '/time_entries'
374 assert_redirected_to '/time_entries'
368 end
375 end
369
376
370 def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
377 def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
371 @request.session[:user_id] = 2
378 @request.session[:user_id] = 2
372 post :bulk_update, :ids => [1,2], :back_url => 'http://google.com'
379 post :bulk_update, :ids => [1,2], :back_url => 'http://google.com'
373
380
374 assert_response :redirect
381 assert_response :redirect
375 assert_redirected_to :controller => 'timelog', :action => 'index', :project_id => Project.find(1).identifier
382 assert_redirected_to :controller => 'timelog', :action => 'index', :project_id => Project.find(1).identifier
376 end
383 end
377
384
378 def test_post_bulk_update_without_edit_permission_should_be_denied
385 def test_post_bulk_update_without_edit_permission_should_be_denied
379 @request.session[:user_id] = 2
386 @request.session[:user_id] = 2
380 Role.find_by_name('Manager').remove_permission! :edit_time_entries
387 Role.find_by_name('Manager').remove_permission! :edit_time_entries
381 post :bulk_update, :ids => [1,2]
388 post :bulk_update, :ids => [1,2]
382
389
383 assert_response 403
390 assert_response 403
384 end
391 end
385
392
386 def test_destroy
393 def test_destroy
387 @request.session[:user_id] = 2
394 @request.session[:user_id] = 2
388 delete :destroy, :id => 1
395 delete :destroy, :id => 1
389 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
396 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
390 assert_equal I18n.t(:notice_successful_delete), flash[:notice]
397 assert_equal I18n.t(:notice_successful_delete), flash[:notice]
391 assert_nil TimeEntry.find_by_id(1)
398 assert_nil TimeEntry.find_by_id(1)
392 end
399 end
393
400
394 def test_destroy_should_fail
401 def test_destroy_should_fail
395 # simulate that this fails (e.g. due to a plugin), see #5700
402 # simulate that this fails (e.g. due to a plugin), see #5700
396 TimeEntry.any_instance.expects(:destroy).returns(false)
403 TimeEntry.any_instance.expects(:destroy).returns(false)
397
404
398 @request.session[:user_id] = 2
405 @request.session[:user_id] = 2
399 delete :destroy, :id => 1
406 delete :destroy, :id => 1
400 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
407 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
401 assert_equal I18n.t(:notice_unable_delete_time_entry), flash[:error]
408 assert_equal I18n.t(:notice_unable_delete_time_entry), flash[:error]
402 assert_not_nil TimeEntry.find_by_id(1)
409 assert_not_nil TimeEntry.find_by_id(1)
403 end
410 end
404
411
405 def test_index_all_projects
412 def test_index_all_projects
406 get :index
413 get :index
407 assert_response :success
414 assert_response :success
408 assert_template 'index'
415 assert_template 'index'
409 assert_not_nil assigns(:total_hours)
416 assert_not_nil assigns(:total_hours)
410 assert_equal "162.90", "%.2f" % assigns(:total_hours)
417 assert_equal "162.90", "%.2f" % assigns(:total_hours)
411 assert_tag :form,
418 assert_tag :form,
412 :attributes => {:action => "/time_entries", :id => 'query_form'}
419 :attributes => {:action => "/time_entries", :id => 'query_form'}
413 end
420 end
414
421
415 def test_index_all_projects_should_show_log_time_link
422 def test_index_all_projects_should_show_log_time_link
416 @request.session[:user_id] = 2
423 @request.session[:user_id] = 2
417 get :index
424 get :index
418 assert_response :success
425 assert_response :success
419 assert_template 'index'
426 assert_template 'index'
420 assert_tag 'a', :attributes => {:href => '/time_entries/new'}, :content => /Log time/
427 assert_tag 'a', :attributes => {:href => '/time_entries/new'}, :content => /Log time/
421 end
428 end
422
429
423 def test_index_at_project_level
430 def test_index_at_project_level
424 get :index, :project_id => 'ecookbook'
431 get :index, :project_id => 'ecookbook'
425 assert_response :success
432 assert_response :success
426 assert_template 'index'
433 assert_template 'index'
427 assert_not_nil assigns(:entries)
434 assert_not_nil assigns(:entries)
428 assert_equal 4, assigns(:entries).size
435 assert_equal 4, assigns(:entries).size
429 # project and subproject
436 # project and subproject
430 assert_equal [1, 3], assigns(:entries).collect(&:project_id).uniq.sort
437 assert_equal [1, 3], assigns(:entries).collect(&:project_id).uniq.sort
431 assert_not_nil assigns(:total_hours)
438 assert_not_nil assigns(:total_hours)
432 assert_equal "162.90", "%.2f" % assigns(:total_hours)
439 assert_equal "162.90", "%.2f" % assigns(:total_hours)
433 assert_tag :form,
440 assert_tag :form,
434 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
441 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
435 end
442 end
436
443
437 def test_index_at_project_level_with_date_range
444 def test_index_at_project_level_with_date_range
438 get :index, :project_id => 'ecookbook',
445 get :index, :project_id => 'ecookbook',
439 :f => ['spent_on'],
446 :f => ['spent_on'],
440 :op => {'spent_on' => '><'},
447 :op => {'spent_on' => '><'},
441 :v => {'spent_on' => ['2007-03-20', '2007-04-30']}
448 :v => {'spent_on' => ['2007-03-20', '2007-04-30']}
442 assert_response :success
449 assert_response :success
443 assert_template 'index'
450 assert_template 'index'
444 assert_not_nil assigns(:entries)
451 assert_not_nil assigns(:entries)
445 assert_equal 3, assigns(:entries).size
452 assert_equal 3, assigns(:entries).size
446 assert_not_nil assigns(:total_hours)
453 assert_not_nil assigns(:total_hours)
447 assert_equal "12.90", "%.2f" % assigns(:total_hours)
454 assert_equal "12.90", "%.2f" % assigns(:total_hours)
448 assert_tag :form,
455 assert_tag :form,
449 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
456 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
450 end
457 end
451
458
452 def test_index_at_project_level_with_date_range_using_from_and_to_params
459 def test_index_at_project_level_with_date_range_using_from_and_to_params
453 get :index, :project_id => 'ecookbook', :from => '2007-03-20', :to => '2007-04-30'
460 get :index, :project_id => 'ecookbook', :from => '2007-03-20', :to => '2007-04-30'
454 assert_response :success
461 assert_response :success
455 assert_template 'index'
462 assert_template 'index'
456 assert_not_nil assigns(:entries)
463 assert_not_nil assigns(:entries)
457 assert_equal 3, assigns(:entries).size
464 assert_equal 3, assigns(:entries).size
458 assert_not_nil assigns(:total_hours)
465 assert_not_nil assigns(:total_hours)
459 assert_equal "12.90", "%.2f" % assigns(:total_hours)
466 assert_equal "12.90", "%.2f" % assigns(:total_hours)
460 assert_tag :form,
467 assert_tag :form,
461 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
468 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
462 end
469 end
463
470
464 def test_index_at_project_level_with_period
471 def test_index_at_project_level_with_period
465 get :index, :project_id => 'ecookbook',
472 get :index, :project_id => 'ecookbook',
466 :f => ['spent_on'],
473 :f => ['spent_on'],
467 :op => {'spent_on' => '>t-'},
474 :op => {'spent_on' => '>t-'},
468 :v => {'spent_on' => ['7']}
475 :v => {'spent_on' => ['7']}
469 assert_response :success
476 assert_response :success
470 assert_template 'index'
477 assert_template 'index'
471 assert_not_nil assigns(:entries)
478 assert_not_nil assigns(:entries)
472 assert_not_nil assigns(:total_hours)
479 assert_not_nil assigns(:total_hours)
473 assert_tag :form,
480 assert_tag :form,
474 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
481 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
475 end
482 end
476
483
477 def test_index_at_issue_level
484 def test_index_at_issue_level
478 get :index, :issue_id => 1
485 get :index, :issue_id => 1
479 assert_response :success
486 assert_response :success
480 assert_template 'index'
487 assert_template 'index'
481 assert_not_nil assigns(:entries)
488 assert_not_nil assigns(:entries)
482 assert_equal 2, assigns(:entries).size
489 assert_equal 2, assigns(:entries).size
483 assert_not_nil assigns(:total_hours)
490 assert_not_nil assigns(:total_hours)
484 assert_equal 154.25, assigns(:total_hours)
491 assert_equal 154.25, assigns(:total_hours)
485 # display all time
492 # display all time
486 assert_nil assigns(:from)
493 assert_nil assigns(:from)
487 assert_nil assigns(:to)
494 assert_nil assigns(:to)
488 # TODO: remove /projects/:project_id/issues/:issue_id/time_entries routes
495 # TODO: remove /projects/:project_id/issues/:issue_id/time_entries routes
489 # to use /issues/:issue_id/time_entries
496 # to use /issues/:issue_id/time_entries
490 assert_tag :form,
497 assert_tag :form,
491 :attributes => {:action => "/projects/ecookbook/issues/1/time_entries", :id => 'query_form'}
498 :attributes => {:action => "/projects/ecookbook/issues/1/time_entries", :id => 'query_form'}
492 end
499 end
493
500
494 def test_index_should_sort_by_spent_on_and_created_on
501 def test_index_should_sort_by_spent_on_and_created_on
495 t1 = TimeEntry.create!(:user => User.find(1), :project => Project.find(1), :hours => 1, :spent_on => '2012-06-16', :created_on => '2012-06-16 20:00:00', :activity_id => 10)
502 t1 = TimeEntry.create!(:user => User.find(1), :project => Project.find(1), :hours => 1, :spent_on => '2012-06-16', :created_on => '2012-06-16 20:00:00', :activity_id => 10)
496 t2 = TimeEntry.create!(:user => User.find(1), :project => Project.find(1), :hours => 1, :spent_on => '2012-06-16', :created_on => '2012-06-16 20:05:00', :activity_id => 10)
503 t2 = TimeEntry.create!(:user => User.find(1), :project => Project.find(1), :hours => 1, :spent_on => '2012-06-16', :created_on => '2012-06-16 20:05:00', :activity_id => 10)
497 t3 = TimeEntry.create!(:user => User.find(1), :project => Project.find(1), :hours => 1, :spent_on => '2012-06-15', :created_on => '2012-06-16 20:10:00', :activity_id => 10)
504 t3 = TimeEntry.create!(:user => User.find(1), :project => Project.find(1), :hours => 1, :spent_on => '2012-06-15', :created_on => '2012-06-16 20:10:00', :activity_id => 10)
498
505
499 get :index, :project_id => 1,
506 get :index, :project_id => 1,
500 :f => ['spent_on'],
507 :f => ['spent_on'],
501 :op => {'spent_on' => '><'},
508 :op => {'spent_on' => '><'},
502 :v => {'spent_on' => ['2012-06-15', '2012-06-16']}
509 :v => {'spent_on' => ['2012-06-15', '2012-06-16']}
503 assert_response :success
510 assert_response :success
504 assert_equal [t2, t1, t3], assigns(:entries)
511 assert_equal [t2, t1, t3], assigns(:entries)
505
512
506 get :index, :project_id => 1,
513 get :index, :project_id => 1,
507 :f => ['spent_on'],
514 :f => ['spent_on'],
508 :op => {'spent_on' => '><'},
515 :op => {'spent_on' => '><'},
509 :v => {'spent_on' => ['2012-06-15', '2012-06-16']},
516 :v => {'spent_on' => ['2012-06-15', '2012-06-16']},
510 :sort => 'spent_on'
517 :sort => 'spent_on'
511 assert_response :success
518 assert_response :success
512 assert_equal [t3, t1, t2], assigns(:entries)
519 assert_equal [t3, t1, t2], assigns(:entries)
513 end
520 end
514
521
515 def test_index_atom_feed
522 def test_index_atom_feed
516 get :index, :project_id => 1, :format => 'atom'
523 get :index, :project_id => 1, :format => 'atom'
517 assert_response :success
524 assert_response :success
518 assert_equal 'application/atom+xml', @response.content_type
525 assert_equal 'application/atom+xml', @response.content_type
519 assert_not_nil assigns(:items)
526 assert_not_nil assigns(:items)
520 assert assigns(:items).first.is_a?(TimeEntry)
527 assert assigns(:items).first.is_a?(TimeEntry)
521 end
528 end
522
529
523 def test_index_all_projects_csv_export
530 def test_index_all_projects_csv_export
524 Setting.date_format = '%m/%d/%Y'
531 Setting.date_format = '%m/%d/%Y'
525 get :index, :format => 'csv'
532 get :index, :format => 'csv'
526 assert_response :success
533 assert_response :success
527 assert_equal 'text/csv; header=present', @response.content_type
534 assert_equal 'text/csv; header=present', @response.content_type
528 assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment,Overtime\n")
535 assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment,Overtime\n")
529 assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\",\"\"\n")
536 assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\",\"\"\n")
530 end
537 end
531
538
532 def test_index_csv_export
539 def test_index_csv_export
533 Setting.date_format = '%m/%d/%Y'
540 Setting.date_format = '%m/%d/%Y'
534 get :index, :project_id => 1, :format => 'csv'
541 get :index, :project_id => 1, :format => 'csv'
535 assert_response :success
542 assert_response :success
536 assert_equal 'text/csv; header=present', @response.content_type
543 assert_equal 'text/csv; header=present', @response.content_type
537 assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment,Overtime\n")
544 assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment,Overtime\n")
538 assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\",\"\"\n")
545 assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\",\"\"\n")
539 end
546 end
540
547
541 def test_index_csv_export_with_multi_custom_field
548 def test_index_csv_export_with_multi_custom_field
542 field = TimeEntryCustomField.create!(:name => 'Test', :field_format => 'list',
549 field = TimeEntryCustomField.create!(:name => 'Test', :field_format => 'list',
543 :multiple => true, :possible_values => ['value1', 'value2'])
550 :multiple => true, :possible_values => ['value1', 'value2'])
544 entry = TimeEntry.find(1)
551 entry = TimeEntry.find(1)
545 entry.custom_field_values = {field.id => ['value1', 'value2']}
552 entry.custom_field_values = {field.id => ['value1', 'value2']}
546 entry.save!
553 entry.save!
547
554
548 get :index, :project_id => 1, :format => 'csv'
555 get :index, :project_id => 1, :format => 'csv'
549 assert_response :success
556 assert_response :success
550 assert_include '"value1, value2"', @response.body
557 assert_include '"value1, value2"', @response.body
551 end
558 end
552
559
553 def test_csv_big_5
560 def test_csv_big_5
554 user = User.find_by_id(3)
561 user = User.find_by_id(3)
555 user.language = "zh-TW"
562 user.language = "zh-TW"
556 assert user.save
563 assert user.save
557 str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88"
564 str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88"
558 str_big5 = "\xa4@\xa4\xeb"
565 str_big5 = "\xa4@\xa4\xeb"
559 if str_utf8.respond_to?(:force_encoding)
566 if str_utf8.respond_to?(:force_encoding)
560 str_utf8.force_encoding('UTF-8')
567 str_utf8.force_encoding('UTF-8')
561 str_big5.force_encoding('Big5')
568 str_big5.force_encoding('Big5')
562 end
569 end
563 @request.session[:user_id] = 3
570 @request.session[:user_id] = 3
564 post :create, :project_id => 1,
571 post :create, :project_id => 1,
565 :time_entry => {:comments => str_utf8,
572 :time_entry => {:comments => str_utf8,
566 # Not the default activity
573 # Not the default activity
567 :activity_id => '11',
574 :activity_id => '11',
568 :issue_id => '',
575 :issue_id => '',
569 :spent_on => '2011-11-10',
576 :spent_on => '2011-11-10',
570 :hours => '7.3'}
577 :hours => '7.3'}
571 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
578 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
572
579
573 t = TimeEntry.find_by_comments(str_utf8)
580 t = TimeEntry.find_by_comments(str_utf8)
574 assert_not_nil t
581 assert_not_nil t
575 assert_equal 11, t.activity_id
582 assert_equal 11, t.activity_id
576 assert_equal 7.3, t.hours
583 assert_equal 7.3, t.hours
577 assert_equal 3, t.user_id
584 assert_equal 3, t.user_id
578
585
579 get :index, :project_id => 1, :format => 'csv',
586 get :index, :project_id => 1, :format => 'csv',
580 :from => '2011-11-10', :to => '2011-11-10'
587 :from => '2011-11-10', :to => '2011-11-10'
581 assert_response :success
588 assert_response :success
582 assert_equal 'text/csv; header=present', @response.content_type
589 assert_equal 'text/csv; header=present', @response.content_type
583 ar = @response.body.chomp.split("\n")
590 ar = @response.body.chomp.split("\n")
584 s1 = "\xa4\xe9\xb4\xc1"
591 s1 = "\xa4\xe9\xb4\xc1"
585 if str_utf8.respond_to?(:force_encoding)
592 if str_utf8.respond_to?(:force_encoding)
586 s1.force_encoding('Big5')
593 s1.force_encoding('Big5')
587 end
594 end
588 assert ar[0].include?(s1)
595 assert ar[0].include?(s1)
589 assert ar[1].include?(str_big5)
596 assert ar[1].include?(str_big5)
590 end
597 end
591
598
592 def test_csv_cannot_convert_should_be_replaced_big_5
599 def test_csv_cannot_convert_should_be_replaced_big_5
593 user = User.find_by_id(3)
600 user = User.find_by_id(3)
594 user.language = "zh-TW"
601 user.language = "zh-TW"
595 assert user.save
602 assert user.save
596 str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85"
603 str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85"
597 if str_utf8.respond_to?(:force_encoding)
604 if str_utf8.respond_to?(:force_encoding)
598 str_utf8.force_encoding('UTF-8')
605 str_utf8.force_encoding('UTF-8')
599 end
606 end
600 @request.session[:user_id] = 3
607 @request.session[:user_id] = 3
601 post :create, :project_id => 1,
608 post :create, :project_id => 1,
602 :time_entry => {:comments => str_utf8,
609 :time_entry => {:comments => str_utf8,
603 # Not the default activity
610 # Not the default activity
604 :activity_id => '11',
611 :activity_id => '11',
605 :issue_id => '',
612 :issue_id => '',
606 :spent_on => '2011-11-10',
613 :spent_on => '2011-11-10',
607 :hours => '7.3'}
614 :hours => '7.3'}
608 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
615 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
609
616
610 t = TimeEntry.find_by_comments(str_utf8)
617 t = TimeEntry.find_by_comments(str_utf8)
611 assert_not_nil t
618 assert_not_nil t
612 assert_equal 11, t.activity_id
619 assert_equal 11, t.activity_id
613 assert_equal 7.3, t.hours
620 assert_equal 7.3, t.hours
614 assert_equal 3, t.user_id
621 assert_equal 3, t.user_id
615
622
616 get :index, :project_id => 1, :format => 'csv',
623 get :index, :project_id => 1, :format => 'csv',
617 :from => '2011-11-10', :to => '2011-11-10'
624 :from => '2011-11-10', :to => '2011-11-10'
618 assert_response :success
625 assert_response :success
619 assert_equal 'text/csv; header=present', @response.content_type
626 assert_equal 'text/csv; header=present', @response.content_type
620 ar = @response.body.chomp.split("\n")
627 ar = @response.body.chomp.split("\n")
621 s1 = "\xa4\xe9\xb4\xc1"
628 s1 = "\xa4\xe9\xb4\xc1"
622 if str_utf8.respond_to?(:force_encoding)
629 if str_utf8.respond_to?(:force_encoding)
623 s1.force_encoding('Big5')
630 s1.force_encoding('Big5')
624 end
631 end
625 assert ar[0].include?(s1)
632 assert ar[0].include?(s1)
626 s2 = ar[1].split(",")[8]
633 s2 = ar[1].split(",")[8]
627 if s2.respond_to?(:force_encoding)
634 if s2.respond_to?(:force_encoding)
628 s3 = "\xa5H?"
635 s3 = "\xa5H?"
629 s3.force_encoding('Big5')
636 s3.force_encoding('Big5')
630 assert_equal s3, s2
637 assert_equal s3, s2
631 elsif RUBY_PLATFORM == 'java'
638 elsif RUBY_PLATFORM == 'java'
632 assert_equal "??", s2
639 assert_equal "??", s2
633 else
640 else
634 assert_equal "\xa5H???", s2
641 assert_equal "\xa5H???", s2
635 end
642 end
636 end
643 end
637
644
638 def test_csv_tw
645 def test_csv_tw
639 with_settings :default_language => "zh-TW" do
646 with_settings :default_language => "zh-TW" do
640 str1 = "test_csv_tw"
647 str1 = "test_csv_tw"
641 user = User.find_by_id(3)
648 user = User.find_by_id(3)
642 te1 = TimeEntry.create(:spent_on => '2011-11-10',
649 te1 = TimeEntry.create(:spent_on => '2011-11-10',
643 :hours => 999.9,
650 :hours => 999.9,
644 :project => Project.find(1),
651 :project => Project.find(1),
645 :user => user,
652 :user => user,
646 :activity => TimeEntryActivity.find_by_name('Design'),
653 :activity => TimeEntryActivity.find_by_name('Design'),
647 :comments => str1)
654 :comments => str1)
648 te2 = TimeEntry.find_by_comments(str1)
655 te2 = TimeEntry.find_by_comments(str1)
649 assert_not_nil te2
656 assert_not_nil te2
650 assert_equal 999.9, te2.hours
657 assert_equal 999.9, te2.hours
651 assert_equal 3, te2.user_id
658 assert_equal 3, te2.user_id
652
659
653 get :index, :project_id => 1, :format => 'csv',
660 get :index, :project_id => 1, :format => 'csv',
654 :from => '2011-11-10', :to => '2011-11-10'
661 :from => '2011-11-10', :to => '2011-11-10'
655 assert_response :success
662 assert_response :success
656 assert_equal 'text/csv; header=present', @response.content_type
663 assert_equal 'text/csv; header=present', @response.content_type
657
664
658 ar = @response.body.chomp.split("\n")
665 ar = @response.body.chomp.split("\n")
659 s2 = ar[1].split(",")[7]
666 s2 = ar[1].split(",")[7]
660 assert_equal '999.9', s2
667 assert_equal '999.9', s2
661
668
662 str_tw = "Traditional Chinese (\xe7\xb9\x81\xe9\xab\x94\xe4\xb8\xad\xe6\x96\x87)"
669 str_tw = "Traditional Chinese (\xe7\xb9\x81\xe9\xab\x94\xe4\xb8\xad\xe6\x96\x87)"
663 if str_tw.respond_to?(:force_encoding)
670 if str_tw.respond_to?(:force_encoding)
664 str_tw.force_encoding('UTF-8')
671 str_tw.force_encoding('UTF-8')
665 end
672 end
666 assert_equal str_tw, l(:general_lang_name)
673 assert_equal str_tw, l(:general_lang_name)
667 assert_equal ',', l(:general_csv_separator)
674 assert_equal ',', l(:general_csv_separator)
668 assert_equal '.', l(:general_csv_decimal_separator)
675 assert_equal '.', l(:general_csv_decimal_separator)
669 end
676 end
670 end
677 end
671
678
672 def test_csv_fr
679 def test_csv_fr
673 with_settings :default_language => "fr" do
680 with_settings :default_language => "fr" do
674 str1 = "test_csv_fr"
681 str1 = "test_csv_fr"
675 user = User.find_by_id(3)
682 user = User.find_by_id(3)
676 te1 = TimeEntry.create(:spent_on => '2011-11-10',
683 te1 = TimeEntry.create(:spent_on => '2011-11-10',
677 :hours => 999.9,
684 :hours => 999.9,
678 :project => Project.find(1),
685 :project => Project.find(1),
679 :user => user,
686 :user => user,
680 :activity => TimeEntryActivity.find_by_name('Design'),
687 :activity => TimeEntryActivity.find_by_name('Design'),
681 :comments => str1)
688 :comments => str1)
682 te2 = TimeEntry.find_by_comments(str1)
689 te2 = TimeEntry.find_by_comments(str1)
683 assert_not_nil te2
690 assert_not_nil te2
684 assert_equal 999.9, te2.hours
691 assert_equal 999.9, te2.hours
685 assert_equal 3, te2.user_id
692 assert_equal 3, te2.user_id
686
693
687 get :index, :project_id => 1, :format => 'csv',
694 get :index, :project_id => 1, :format => 'csv',
688 :from => '2011-11-10', :to => '2011-11-10'
695 :from => '2011-11-10', :to => '2011-11-10'
689 assert_response :success
696 assert_response :success
690 assert_equal 'text/csv; header=present', @response.content_type
697 assert_equal 'text/csv; header=present', @response.content_type
691
698
692 ar = @response.body.chomp.split("\n")
699 ar = @response.body.chomp.split("\n")
693 s2 = ar[1].split(";")[7]
700 s2 = ar[1].split(";")[7]
694 assert_equal '999,9', s2
701 assert_equal '999,9', s2
695
702
696 str_fr = "Fran\xc3\xa7ais"
703 str_fr = "Fran\xc3\xa7ais"
697 if str_fr.respond_to?(:force_encoding)
704 if str_fr.respond_to?(:force_encoding)
698 str_fr.force_encoding('UTF-8')
705 str_fr.force_encoding('UTF-8')
699 end
706 end
700 assert_equal str_fr, l(:general_lang_name)
707 assert_equal str_fr, l(:general_lang_name)
701 assert_equal ';', l(:general_csv_separator)
708 assert_equal ';', l(:general_csv_separator)
702 assert_equal ',', l(:general_csv_decimal_separator)
709 assert_equal ',', l(:general_csv_decimal_separator)
703 end
710 end
704 end
711 end
705 end
712 end
General Comments 0
You need to be logged in to leave comments. Login now