@@ -1,131 +1,145 | |||
|
1 | 1 | --- |
|
2 | 2 | custom_fields_001: |
|
3 | 3 | name: Database |
|
4 | 4 | min_length: 0 |
|
5 | 5 | regexp: "" |
|
6 | 6 | is_for_all: true |
|
7 | 7 | is_filter: true |
|
8 | 8 | type: IssueCustomField |
|
9 | 9 | max_length: 0 |
|
10 | 10 | possible_values: |
|
11 | 11 | - MySQL |
|
12 | 12 | - PostgreSQL |
|
13 | 13 | - Oracle |
|
14 | 14 | id: 1 |
|
15 | 15 | is_required: false |
|
16 | 16 | field_format: list |
|
17 | 17 | default_value: "" |
|
18 | 18 | editable: true |
|
19 | 19 | custom_fields_002: |
|
20 | 20 | name: Searchable field |
|
21 | 21 | min_length: 1 |
|
22 | 22 | regexp: "" |
|
23 | 23 | is_for_all: true |
|
24 | 24 | type: IssueCustomField |
|
25 | 25 | max_length: 100 |
|
26 | 26 | possible_values: "" |
|
27 | 27 | id: 2 |
|
28 | 28 | is_required: false |
|
29 | 29 | field_format: string |
|
30 | 30 | searchable: true |
|
31 | 31 | default_value: "Default string" |
|
32 | 32 | editable: true |
|
33 | 33 | custom_fields_003: |
|
34 | 34 | name: Development status |
|
35 | 35 | min_length: 0 |
|
36 | 36 | regexp: "" |
|
37 | 37 | is_for_all: false |
|
38 | 38 | is_filter: true |
|
39 | 39 | type: ProjectCustomField |
|
40 | 40 | max_length: 0 |
|
41 | 41 | possible_values: |
|
42 | 42 | - Stable |
|
43 | 43 | - Beta |
|
44 | 44 | - Alpha |
|
45 | 45 | - Planning |
|
46 | 46 | id: 3 |
|
47 | 47 | is_required: false |
|
48 | 48 | field_format: list |
|
49 | 49 | default_value: "" |
|
50 | 50 | editable: true |
|
51 | 51 | custom_fields_004: |
|
52 | 52 | name: Phone number |
|
53 | 53 | min_length: 0 |
|
54 | 54 | regexp: "" |
|
55 | 55 | is_for_all: false |
|
56 | 56 | type: UserCustomField |
|
57 | 57 | max_length: 0 |
|
58 | 58 | possible_values: "" |
|
59 | 59 | id: 4 |
|
60 | 60 | is_required: false |
|
61 | 61 | field_format: string |
|
62 | 62 | default_value: "" |
|
63 | 63 | editable: true |
|
64 | 64 | custom_fields_005: |
|
65 | 65 | name: Money |
|
66 | 66 | min_length: 0 |
|
67 | 67 | regexp: "" |
|
68 | 68 | is_for_all: false |
|
69 | 69 | type: UserCustomField |
|
70 | 70 | max_length: 0 |
|
71 | 71 | possible_values: "" |
|
72 | 72 | id: 5 |
|
73 | 73 | is_required: false |
|
74 | 74 | field_format: float |
|
75 | 75 | default_value: "" |
|
76 | 76 | editable: true |
|
77 | 77 | custom_fields_006: |
|
78 | 78 | name: Float field |
|
79 | 79 | min_length: 0 |
|
80 | 80 | regexp: "" |
|
81 | 81 | is_for_all: true |
|
82 | 82 | type: IssueCustomField |
|
83 | 83 | max_length: 0 |
|
84 | 84 | possible_values: "" |
|
85 | 85 | id: 6 |
|
86 | 86 | is_required: false |
|
87 | 87 | field_format: float |
|
88 | 88 | default_value: "" |
|
89 | 89 | editable: true |
|
90 | 90 | custom_fields_007: |
|
91 | 91 | name: Billable |
|
92 | 92 | min_length: 0 |
|
93 | 93 | regexp: "" |
|
94 | 94 | is_for_all: false |
|
95 | 95 | is_filter: true |
|
96 | 96 | type: TimeEntryActivityCustomField |
|
97 | 97 | max_length: 0 |
|
98 | 98 | possible_values: "" |
|
99 | 99 | id: 7 |
|
100 | 100 | is_required: false |
|
101 | 101 | field_format: bool |
|
102 | 102 | default_value: "" |
|
103 | 103 | editable: true |
|
104 | 104 | custom_fields_008: |
|
105 | 105 | name: Custom date |
|
106 | 106 | min_length: 0 |
|
107 | 107 | regexp: "" |
|
108 | 108 | is_for_all: true |
|
109 | 109 | is_filter: false |
|
110 | 110 | type: IssueCustomField |
|
111 | 111 | max_length: 0 |
|
112 | 112 | possible_values: "" |
|
113 | 113 | id: 8 |
|
114 | 114 | is_required: false |
|
115 | 115 | field_format: date |
|
116 | 116 | default_value: "" |
|
117 | 117 | editable: true |
|
118 | 118 | custom_fields_009: |
|
119 | 119 | name: Project 1 cf |
|
120 | 120 | min_length: 0 |
|
121 | 121 | regexp: "" |
|
122 | 122 | is_for_all: false |
|
123 | 123 | is_filter: true |
|
124 | 124 | type: IssueCustomField |
|
125 | 125 | max_length: 0 |
|
126 | 126 | possible_values: "" |
|
127 | 127 | id: 9 |
|
128 | 128 | is_required: false |
|
129 | 129 | field_format: date |
|
130 | 130 | default_value: "" |
|
131 | 131 | editable: true |
|
132 | custom_fields_010: | |
|
133 | name: Overtime | |
|
134 | min_length: 0 | |
|
135 | regexp: "" | |
|
136 | is_for_all: false | |
|
137 | is_filter: false | |
|
138 | type: TimeEntryCustomField | |
|
139 | max_length: 0 | |
|
140 | possible_values: "" | |
|
141 | id: 10 | |
|
142 | is_required: false | |
|
143 | field_format: bool | |
|
144 | default_value: 0 | |
|
145 | editable: true |
@@ -1,58 +1,72 | |||
|
1 | 1 | --- |
|
2 | 2 | time_entries_001: |
|
3 | 3 | created_on: 2007-03-23 12:54:18 +01:00 |
|
4 | 4 | tweek: 12 |
|
5 | 5 | tmonth: 3 |
|
6 | 6 | project_id: 1 |
|
7 | 7 | comments: My hours |
|
8 | 8 | updated_on: 2007-03-23 12:54:18 +01:00 |
|
9 | 9 | activity_id: 9 |
|
10 | 10 | spent_on: 2007-03-23 |
|
11 | 11 | issue_id: 1 |
|
12 | 12 | id: 1 |
|
13 | 13 | hours: 4.25 |
|
14 | 14 | user_id: 2 |
|
15 | 15 | tyear: 2007 |
|
16 | 16 | time_entries_002: |
|
17 | 17 | created_on: 2007-03-23 14:11:04 +01:00 |
|
18 | 18 | tweek: 11 |
|
19 | 19 | tmonth: 3 |
|
20 | 20 | project_id: 1 |
|
21 | 21 | comments: "" |
|
22 | 22 | updated_on: 2007-03-23 14:11:04 +01:00 |
|
23 | 23 | activity_id: 9 |
|
24 | 24 | spent_on: 2007-03-12 |
|
25 | 25 | issue_id: 1 |
|
26 | 26 | id: 2 |
|
27 | 27 | hours: 150.0 |
|
28 | 28 | user_id: 1 |
|
29 | 29 | tyear: 2007 |
|
30 | 30 | time_entries_003: |
|
31 | 31 | created_on: 2007-04-21 12:20:48 +02:00 |
|
32 | 32 | tweek: 16 |
|
33 | 33 | tmonth: 4 |
|
34 | 34 | project_id: 1 |
|
35 | 35 | comments: "" |
|
36 | 36 | updated_on: 2007-04-21 12:20:48 +02:00 |
|
37 | 37 | activity_id: 9 |
|
38 | 38 | spent_on: 2007-04-21 |
|
39 | 39 | issue_id: 3 |
|
40 | 40 | id: 3 |
|
41 | 41 | hours: 1.0 |
|
42 | 42 | user_id: 1 |
|
43 | 43 | tyear: 2007 |
|
44 | 44 | time_entries_004: |
|
45 | 45 | created_on: 2007-04-22 12:20:48 +02:00 |
|
46 | 46 | tweek: 16 |
|
47 | 47 | tmonth: 4 |
|
48 | 48 | project_id: 3 |
|
49 | 49 | comments: Time spent on a subproject |
|
50 | 50 | updated_on: 2007-04-22 12:20:48 +02:00 |
|
51 | 51 | activity_id: 10 |
|
52 | 52 | spent_on: 2007-04-22 |
|
53 | 53 | issue_id: |
|
54 | 54 | id: 4 |
|
55 | 55 | hours: 7.65 |
|
56 | 56 | user_id: 1 |
|
57 | 57 | tyear: 2007 |
|
58 | time_entries_005: | |
|
59 | created_on: 2011-03-22 12:20:48 +02:00 | |
|
60 | tweek: 12 | |
|
61 | tmonth: 3 | |
|
62 | project_id: 5 | |
|
63 | comments: Time spent on a subproject | |
|
64 | updated_on: 2011-03-22 12:20:48 +02:00 | |
|
65 | activity_id: 10 | |
|
66 | spent_on: 2011-03-22 | |
|
67 | issue_id: | |
|
68 | id: 5 | |
|
69 | hours: 7.65 | |
|
70 | user_id: 1 | |
|
71 | tyear: 2011 | |
|
58 | 72 |
@@ -1,265 +1,336 | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | # redMine - project management software |
|
3 | 3 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
4 | 4 | # |
|
5 | 5 | # This program is free software; you can redistribute it and/or |
|
6 | 6 | # modify it under the terms of the GNU General Public License |
|
7 | 7 | # as published by the Free Software Foundation; either version 2 |
|
8 | 8 | # of the License, or (at your option) any later version. |
|
9 | 9 | # |
|
10 | 10 | # This program is distributed in the hope that it will be useful, |
|
11 | 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 | 13 | # GNU General Public License for more details. |
|
14 | 14 | # |
|
15 | 15 | # You should have received a copy of the GNU General Public License |
|
16 | 16 | # along with this program; if not, write to the Free Software |
|
17 | 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
18 | 18 | |
|
19 | 19 | require File.expand_path('../../test_helper', __FILE__) |
|
20 | 20 | require 'timelog_controller' |
|
21 | 21 | |
|
22 | 22 | # Re-raise errors caught by the controller. |
|
23 | 23 | class TimelogController; def rescue_action(e) raise e end; end |
|
24 | 24 | |
|
25 | 25 | class TimelogControllerTest < ActionController::TestCase |
|
26 | 26 | fixtures :projects, :enabled_modules, :roles, :members, :member_roles, :issues, :time_entries, :users, :trackers, :enumerations, :issue_statuses, :custom_fields, :custom_values |
|
27 | 27 | |
|
28 | 28 | def setup |
|
29 | 29 | @controller = TimelogController.new |
|
30 | 30 | @request = ActionController::TestRequest.new |
|
31 | 31 | @response = ActionController::TestResponse.new |
|
32 | 32 | end |
|
33 | 33 | |
|
34 | 34 | def test_get_new |
|
35 | 35 | @request.session[:user_id] = 3 |
|
36 | 36 | get :new, :project_id => 1 |
|
37 | 37 | assert_response :success |
|
38 | 38 | assert_template 'edit' |
|
39 | 39 | # Default activity selected |
|
40 | 40 | assert_tag :tag => 'option', :attributes => { :selected => 'selected' }, |
|
41 | 41 | :content => 'Development' |
|
42 | 42 | end |
|
43 | 43 | |
|
44 | 44 | def test_get_new_should_only_show_active_time_entry_activities |
|
45 | 45 | @request.session[:user_id] = 3 |
|
46 | 46 | get :new, :project_id => 1 |
|
47 | 47 | assert_response :success |
|
48 | 48 | assert_template 'edit' |
|
49 | 49 | assert_no_tag :tag => 'option', :content => 'Inactive Activity' |
|
50 | 50 | |
|
51 | 51 | end |
|
52 | 52 | |
|
53 | 53 | def test_get_edit_existing_time |
|
54 | 54 | @request.session[:user_id] = 2 |
|
55 | 55 | get :edit, :id => 2, :project_id => nil |
|
56 | 56 | assert_response :success |
|
57 | 57 | assert_template 'edit' |
|
58 | 58 | # Default activity selected |
|
59 | 59 | assert_tag :tag => 'form', :attributes => { :action => '/projects/ecookbook/time_entries/2' } |
|
60 | 60 | end |
|
61 | 61 | |
|
62 | 62 | def test_get_edit_with_an_existing_time_entry_with_inactive_activity |
|
63 | 63 | te = TimeEntry.find(1) |
|
64 | 64 | te.activity = TimeEntryActivity.find_by_name("Inactive Activity") |
|
65 | 65 | te.save! |
|
66 | 66 | |
|
67 | 67 | @request.session[:user_id] = 1 |
|
68 | 68 | get :edit, :project_id => 1, :id => 1 |
|
69 | 69 | assert_response :success |
|
70 | 70 | assert_template 'edit' |
|
71 | 71 | # Blank option since nothing is pre-selected |
|
72 | 72 | assert_tag :tag => 'option', :content => '--- Please select ---' |
|
73 | 73 | end |
|
74 | 74 | |
|
75 | 75 | def test_post_create |
|
76 | 76 | # TODO: should POST to issuesβ time log instead of project. change form |
|
77 | 77 | # and routing |
|
78 | 78 | @request.session[:user_id] = 3 |
|
79 | 79 | post :create, :project_id => 1, |
|
80 | 80 | :time_entry => {:comments => 'Some work on TimelogControllerTest', |
|
81 | 81 | # Not the default activity |
|
82 | 82 | :activity_id => '11', |
|
83 | 83 | :spent_on => '2008-03-14', |
|
84 | 84 | :issue_id => '1', |
|
85 | 85 | :hours => '7.3'} |
|
86 | 86 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
87 | 87 | |
|
88 | 88 | i = Issue.find(1) |
|
89 | 89 | t = TimeEntry.find_by_comments('Some work on TimelogControllerTest') |
|
90 | 90 | assert_not_nil t |
|
91 | 91 | assert_equal 11, t.activity_id |
|
92 | 92 | assert_equal 7.3, t.hours |
|
93 | 93 | assert_equal 3, t.user_id |
|
94 | 94 | assert_equal i, t.issue |
|
95 | 95 | assert_equal i.project, t.project |
|
96 | 96 | end |
|
97 | 97 | |
|
98 | 98 | def test_post_create_with_blank_issue |
|
99 | 99 | # TODO: should POST to issuesβ time log instead of project. change form |
|
100 | 100 | # and routing |
|
101 | 101 | @request.session[:user_id] = 3 |
|
102 | 102 | post :create, :project_id => 1, |
|
103 | 103 | :time_entry => {:comments => 'Some work on TimelogControllerTest', |
|
104 | 104 | # Not the default activity |
|
105 | 105 | :activity_id => '11', |
|
106 | 106 | :issue_id => '', |
|
107 | 107 | :spent_on => '2008-03-14', |
|
108 | 108 | :hours => '7.3'} |
|
109 | 109 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
110 | 110 | |
|
111 | 111 | t = TimeEntry.find_by_comments('Some work on TimelogControllerTest') |
|
112 | 112 | assert_not_nil t |
|
113 | 113 | assert_equal 11, t.activity_id |
|
114 | 114 | assert_equal 7.3, t.hours |
|
115 | 115 | assert_equal 3, t.user_id |
|
116 | 116 | end |
|
117 | 117 | |
|
118 | 118 | def test_update |
|
119 | 119 | entry = TimeEntry.find(1) |
|
120 | 120 | assert_equal 1, entry.issue_id |
|
121 | 121 | assert_equal 2, entry.user_id |
|
122 | 122 | |
|
123 | 123 | @request.session[:user_id] = 1 |
|
124 | 124 | put :update, :id => 1, |
|
125 | 125 | :time_entry => {:issue_id => '2', |
|
126 | 126 | :hours => '8'} |
|
127 | 127 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
128 | 128 | entry.reload |
|
129 | 129 | |
|
130 | 130 | assert_equal 8, entry.hours |
|
131 | 131 | assert_equal 2, entry.issue_id |
|
132 | 132 | assert_equal 2, entry.user_id |
|
133 | 133 | end |
|
134 | ||
|
135 | def test_get_bulk_edit | |
|
136 | @request.session[:user_id] = 2 | |
|
137 | get :bulk_edit, :ids => [1, 2] | |
|
138 | assert_response :success | |
|
139 | assert_template 'bulk_edit' | |
|
140 | ||
|
141 | # System wide custom field | |
|
142 | assert_tag :select, :attributes => {:name => 'time_entry[custom_field_values][10]'} | |
|
143 | end | |
|
144 | ||
|
145 | def test_get_bulk_edit_on_different_projects | |
|
146 | @request.session[:user_id] = 2 | |
|
147 | get :bulk_edit, :ids => [1, 2, 6] | |
|
148 | assert_response :success | |
|
149 | assert_template 'bulk_edit' | |
|
150 | end | |
|
151 | ||
|
152 | def test_bulk_update | |
|
153 | @request.session[:user_id] = 2 | |
|
154 | # update time entry activity | |
|
155 | post :bulk_update, :ids => [1, 2], :time_entry => { :activity_id => 9} | |
|
156 | ||
|
157 | assert_response 302 | |
|
158 | # check that the issues were updated | |
|
159 | assert_equal [9, 9], TimeEntry.find_all_by_id([1, 2]).collect {|i| i.activity_id} | |
|
160 | end | |
|
161 | ||
|
162 | def test_bulk_update_on_different_projects | |
|
163 | @request.session[:user_id] = 2 | |
|
164 | # update time entry activity | |
|
165 | post :bulk_update, :ids => [1, 2, 4], :time_entry => { :activity_id => 9 } | |
|
166 | ||
|
167 | assert_response 302 | |
|
168 | # check that the issues were updated | |
|
169 | assert_equal [9, 9, 9], TimeEntry.find_all_by_id([1, 2, 4]).collect {|i| i.activity_id} | |
|
170 | end | |
|
171 | ||
|
172 | def test_bulk_update_on_different_projects_without_rights | |
|
173 | @request.session[:user_id] = 3 | |
|
174 | user = User.find(3) | |
|
175 | action = { :controller => "timelog", :action => "bulk_update" } | |
|
176 | assert user.allowed_to?(action, TimeEntry.find(1).project) | |
|
177 | assert ! user.allowed_to?(action, TimeEntry.find(5).project) | |
|
178 | post :bulk_update, :ids => [1, 5], :time_entry => { :activity_id => 9 } | |
|
179 | assert_response 403 | |
|
180 | end | |
|
181 | ||
|
182 | def test_bulk_update_custom_field | |
|
183 | @request.session[:user_id] = 2 | |
|
184 | post :bulk_update, :ids => [1, 2], :time_entry => { :custom_field_values => {'10' => '0'} } | |
|
185 | ||
|
186 | assert_response 302 | |
|
187 | assert_equal ["0", "0"], TimeEntry.find_all_by_id([1, 2]).collect {|i| i.custom_value_for(10).value} | |
|
188 | end | |
|
189 | ||
|
190 | def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter | |
|
191 | @request.session[:user_id] = 2 | |
|
192 | post :bulk_update, :ids => [1,2], :back_url => '/time_entries' | |
|
193 | ||
|
194 | assert_response :redirect | |
|
195 | assert_redirected_to '/time_entries' | |
|
196 | end | |
|
197 | ||
|
198 | def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host | |
|
199 | @request.session[:user_id] = 2 | |
|
200 | post :bulk_update, :ids => [1,2], :back_url => 'http://google.com' | |
|
201 | ||
|
202 | assert_response :redirect | |
|
203 | assert_redirected_to :controller => 'timelog', :action => 'index', :project_id => Project.find(1).identifier | |
|
204 | end | |
|
134 | 205 | |
|
135 | 206 | def test_destroy |
|
136 | 207 | @request.session[:user_id] = 2 |
|
137 | 208 | delete :destroy, :id => 1 |
|
138 | 209 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
139 | 210 | assert_equal I18n.t(:notice_successful_delete), flash[:notice] |
|
140 | 211 | assert_nil TimeEntry.find_by_id(1) |
|
141 | 212 | end |
|
142 | 213 | |
|
143 | 214 | def test_destroy_should_fail |
|
144 | 215 | # simulate that this fails (e.g. due to a plugin), see #5700 |
|
145 | 216 | TimeEntry.class_eval do |
|
146 | 217 | before_destroy :stop_callback_chain |
|
147 | 218 | def stop_callback_chain ; return false ; end |
|
148 | 219 | end |
|
149 | 220 | |
|
150 | 221 | @request.session[:user_id] = 2 |
|
151 | 222 | delete :destroy, :id => 1 |
|
152 | 223 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
153 | 224 | assert_equal I18n.t(:notice_unable_delete_time_entry), flash[:error] |
|
154 | 225 | assert_not_nil TimeEntry.find_by_id(1) |
|
155 | 226 | |
|
156 | 227 | # remove the simulation |
|
157 | 228 | TimeEntry.before_destroy.reject! {|callback| callback.method == :stop_callback_chain } |
|
158 | 229 | end |
|
159 | 230 | |
|
160 | 231 | def test_index_all_projects |
|
161 | 232 | get :index |
|
162 | 233 | assert_response :success |
|
163 | 234 | assert_template 'index' |
|
164 | 235 | assert_not_nil assigns(:total_hours) |
|
165 | 236 | assert_equal "162.90", "%.2f" % assigns(:total_hours) |
|
166 | 237 | assert_tag :form, |
|
167 | 238 | :attributes => {:action => "/time_entries", :id => 'query_form'} |
|
168 | 239 | end |
|
169 | 240 | |
|
170 | 241 | def test_index_at_project_level |
|
171 | 242 | get :index, :project_id => 'ecookbook' |
|
172 | 243 | assert_response :success |
|
173 | 244 | assert_template 'index' |
|
174 | 245 | assert_not_nil assigns(:entries) |
|
175 | 246 | assert_equal 4, assigns(:entries).size |
|
176 | 247 | # project and subproject |
|
177 | 248 | assert_equal [1, 3], assigns(:entries).collect(&:project_id).uniq.sort |
|
178 | 249 | assert_not_nil assigns(:total_hours) |
|
179 | 250 | assert_equal "162.90", "%.2f" % assigns(:total_hours) |
|
180 | 251 | # display all time by default |
|
181 | 252 | assert_equal '2007-03-12'.to_date, assigns(:from) |
|
182 | 253 | assert_equal '2007-04-22'.to_date, assigns(:to) |
|
183 | 254 | assert_tag :form, |
|
184 | 255 | :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'} |
|
185 | 256 | end |
|
186 | 257 | |
|
187 | 258 | def test_index_at_project_level_with_date_range |
|
188 | 259 | get :index, :project_id => 'ecookbook', :from => '2007-03-20', :to => '2007-04-30' |
|
189 | 260 | assert_response :success |
|
190 | 261 | assert_template 'index' |
|
191 | 262 | assert_not_nil assigns(:entries) |
|
192 | 263 | assert_equal 3, assigns(:entries).size |
|
193 | 264 | assert_not_nil assigns(:total_hours) |
|
194 | 265 | assert_equal "12.90", "%.2f" % assigns(:total_hours) |
|
195 | 266 | assert_equal '2007-03-20'.to_date, assigns(:from) |
|
196 | 267 | assert_equal '2007-04-30'.to_date, assigns(:to) |
|
197 | 268 | assert_tag :form, |
|
198 | 269 | :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'} |
|
199 | 270 | end |
|
200 | 271 | |
|
201 | 272 | def test_index_at_project_level_with_period |
|
202 | 273 | get :index, :project_id => 'ecookbook', :period => '7_days' |
|
203 | 274 | assert_response :success |
|
204 | 275 | assert_template 'index' |
|
205 | 276 | assert_not_nil assigns(:entries) |
|
206 | 277 | assert_not_nil assigns(:total_hours) |
|
207 | 278 | assert_equal Date.today - 7, assigns(:from) |
|
208 | 279 | assert_equal Date.today, assigns(:to) |
|
209 | 280 | assert_tag :form, |
|
210 | 281 | :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'} |
|
211 | 282 | end |
|
212 | 283 | |
|
213 | 284 | def test_index_one_day |
|
214 | 285 | get :index, :project_id => 'ecookbook', :from => "2007-03-23", :to => "2007-03-23" |
|
215 | 286 | assert_response :success |
|
216 | 287 | assert_template 'index' |
|
217 | 288 | assert_not_nil assigns(:total_hours) |
|
218 | 289 | assert_equal "4.25", "%.2f" % assigns(:total_hours) |
|
219 | 290 | assert_tag :form, |
|
220 | 291 | :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'} |
|
221 | 292 | end |
|
222 | 293 | |
|
223 | 294 | def test_index_at_issue_level |
|
224 | 295 | get :index, :issue_id => 1 |
|
225 | 296 | assert_response :success |
|
226 | 297 | assert_template 'index' |
|
227 | 298 | assert_not_nil assigns(:entries) |
|
228 | 299 | assert_equal 2, assigns(:entries).size |
|
229 | 300 | assert_not_nil assigns(:total_hours) |
|
230 | 301 | assert_equal 154.25, assigns(:total_hours) |
|
231 | 302 | # display all time based on what's been logged |
|
232 | 303 | assert_equal '2007-03-12'.to_date, assigns(:from) |
|
233 | 304 | assert_equal '2007-04-22'.to_date, assigns(:to) |
|
234 | 305 | # TODO: remove /projects/:project_id/issues/:issue_id/time_entries routes |
|
235 | 306 | # to use /issues/:issue_id/time_entries |
|
236 | 307 | assert_tag :form, |
|
237 | 308 | :attributes => {:action => "/projects/ecookbook/issues/1/time_entries", :id => 'query_form'} |
|
238 | 309 | end |
|
239 | 310 | |
|
240 | 311 | def test_index_atom_feed |
|
241 | 312 | get :index, :project_id => 1, :format => 'atom' |
|
242 | 313 | assert_response :success |
|
243 | 314 | assert_equal 'application/atom+xml', @response.content_type |
|
244 | 315 | assert_not_nil assigns(:items) |
|
245 | 316 | assert assigns(:items).first.is_a?(TimeEntry) |
|
246 | 317 | end |
|
247 | 318 | |
|
248 | 319 | def test_index_all_projects_csv_export |
|
249 | 320 | Setting.date_format = '%m/%d/%Y' |
|
250 | 321 | get :index, :format => 'csv' |
|
251 | 322 | assert_response :success |
|
252 | 323 | assert_equal 'text/csv', @response.content_type |
|
253 | assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment\n") | |
|
254 | assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\"\n") | |
|
324 | assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment,Overtime\n") | |
|
325 | assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\",\"\"\n") | |
|
255 | 326 | end |
|
256 | 327 | |
|
257 | 328 | def test_index_csv_export |
|
258 | 329 | Setting.date_format = '%m/%d/%Y' |
|
259 | 330 | get :index, :project_id => 1, :format => 'csv' |
|
260 | 331 | assert_response :success |
|
261 | 332 | assert_equal 'text/csv', @response.content_type |
|
262 | assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment\n") | |
|
263 | assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\"\n") | |
|
333 | assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment,Overtime\n") | |
|
334 | assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\",\"\"\n") | |
|
264 | 335 | end |
|
265 | 336 | end |
@@ -1,85 +1,85 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006-2008 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.expand_path('../../test_helper', __FILE__) |
|
19 | 19 | |
|
20 | 20 | class TimeEntryActivityTest < ActiveSupport::TestCase |
|
21 | 21 | fixtures :enumerations, :time_entries |
|
22 | 22 | |
|
23 | 23 | def test_should_be_an_enumeration |
|
24 | 24 | assert TimeEntryActivity.ancestors.include?(Enumeration) |
|
25 | 25 | end |
|
26 | ||
|
26 | ||
|
27 | 27 | def test_objects_count |
|
28 | 28 | assert_equal 3, TimeEntryActivity.find_by_name("Design").objects_count |
|
29 |
assert_equal |
|
|
29 | assert_equal 2, TimeEntryActivity.find_by_name("Development").objects_count | |
|
30 | 30 | end |
|
31 | 31 | |
|
32 | 32 | def test_option_name |
|
33 | 33 | assert_equal :enumeration_activities, TimeEntryActivity.new.option_name |
|
34 | 34 | end |
|
35 | 35 | |
|
36 | 36 | def test_create_with_custom_field |
|
37 | 37 | field = TimeEntryActivityCustomField.find_by_name('Billable') |
|
38 | 38 | e = TimeEntryActivity.new(:name => 'Custom Data') |
|
39 | 39 | e.custom_field_values = {field.id => "1"} |
|
40 | 40 | assert e.save |
|
41 | 41 | |
|
42 | 42 | e.reload |
|
43 | 43 | assert_equal "1", e.custom_value_for(field).value |
|
44 | 44 | end |
|
45 | 45 | |
|
46 | 46 | def test_create_without_required_custom_field_should_fail |
|
47 | 47 | field = TimeEntryActivityCustomField.find_by_name('Billable') |
|
48 | 48 | field.update_attribute(:is_required, true) |
|
49 | 49 | |
|
50 | 50 | e = TimeEntryActivity.new(:name => 'Custom Data') |
|
51 | 51 | assert !e.save |
|
52 | 52 | assert_equal I18n.translate('activerecord.errors.messages.invalid'), e.errors.on(:custom_values) |
|
53 | 53 | end |
|
54 | 54 | |
|
55 | 55 | def test_create_with_required_custom_field_should_succeed |
|
56 | 56 | field = TimeEntryActivityCustomField.find_by_name('Billable') |
|
57 | 57 | field.update_attribute(:is_required, true) |
|
58 | 58 | |
|
59 | 59 | e = TimeEntryActivity.new(:name => 'Custom Data') |
|
60 | 60 | e.custom_field_values = {field.id => "1"} |
|
61 | 61 | assert e.save |
|
62 | 62 | end |
|
63 | 63 | |
|
64 | 64 | def test_update_issue_with_required_custom_field_change |
|
65 | 65 | field = TimeEntryActivityCustomField.find_by_name('Billable') |
|
66 | 66 | field.update_attribute(:is_required, true) |
|
67 | 67 | |
|
68 | 68 | e = TimeEntryActivity.find(10) |
|
69 | 69 | assert e.available_custom_fields.include?(field) |
|
70 | 70 | # No change to custom field, record can be saved |
|
71 | 71 | assert e.save |
|
72 | 72 | # Blanking custom field, save should fail |
|
73 | 73 | e.custom_field_values = {field.id => ""} |
|
74 | 74 | assert !e.save |
|
75 | 75 | assert e.errors.on(:custom_values) |
|
76 | 76 | |
|
77 | 77 | # Update custom field to valid value, save should succeed |
|
78 | 78 | e.custom_field_values = {field.id => "0"} |
|
79 | 79 | assert e.save |
|
80 | 80 | e.reload |
|
81 | 81 | assert_equal "0", e.custom_value_for(field).value |
|
82 | 82 | end |
|
83 | 83 | |
|
84 | 84 | end |
|
85 | 85 |
General Comments 0
You need to be logged in to leave comments.
Login now