@@ -1,140 +1,140 | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 | require File.expand_path('../../test_helper', __FILE__) |
|
2 | require File.expand_path('../../test_helper', __FILE__) | |
3 |
|
3 | |||
4 | class TimeEntryReportsControllerTest < ActionController::TestCase |
|
4 | class TimeEntryReportsControllerTest < ActionController::TestCase | |
5 | fixtures :projects, :enabled_modules, :roles, :members, :member_roles, :issues, :time_entries, :users, :trackers, :enumerations, :issue_statuses, :custom_fields, :custom_values |
|
5 | fixtures :projects, :enabled_modules, :roles, :members, :member_roles, :issues, :time_entries, :users, :trackers, :enumerations, :issue_statuses, :custom_fields, :custom_values | |
6 |
|
6 | |||
7 | def test_report_at_project_level |
|
7 | def test_report_at_project_level | |
8 | get :report, :project_id => 'ecookbook' |
|
8 | get :report, :project_id => 'ecookbook' | |
9 | assert_response :success |
|
9 | assert_response :success | |
10 | assert_template 'report' |
|
10 | assert_template 'report' | |
11 | assert_tag :form, |
|
11 | assert_tag :form, | |
12 | :attributes => {:action => "/projects/ecookbook/time_entries/report", :id => 'query_form'} |
|
12 | :attributes => {:action => "/projects/ecookbook/time_entries/report", :id => 'query_form'} | |
13 | end |
|
13 | end | |
14 |
|
14 | |||
15 | def test_report_all_projects |
|
15 | def test_report_all_projects | |
16 | get :report |
|
16 | get :report | |
17 | assert_response :success |
|
17 | assert_response :success | |
18 | assert_template 'report' |
|
18 | assert_template 'report' | |
19 | assert_tag :form, |
|
19 | assert_tag :form, | |
20 | :attributes => {:action => "/time_entries/report", :id => 'query_form'} |
|
20 | :attributes => {:action => "/time_entries/report", :id => 'query_form'} | |
21 | end |
|
21 | end | |
22 |
|
22 | |||
23 | def test_report_all_projects_denied |
|
23 | def test_report_all_projects_denied | |
24 | r = Role.anonymous |
|
24 | r = Role.anonymous | |
25 | r.permissions.delete(:view_time_entries) |
|
25 | r.permissions.delete(:view_time_entries) | |
26 | r.permissions_will_change! |
|
26 | r.permissions_will_change! | |
27 | r.save |
|
27 | r.save | |
28 | get :report |
|
28 | get :report | |
29 | assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Ftime_entries%2Freport' |
|
29 | assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Ftime_entries%2Freport' | |
30 | end |
|
30 | end | |
31 |
|
31 | |||
32 | def test_report_all_projects_one_criteria |
|
32 | def test_report_all_projects_one_criteria | |
33 | get :report, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criterias => ['project'] |
|
33 | get :report, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criterias => ['project'] | |
34 | assert_response :success |
|
34 | assert_response :success | |
35 | assert_template 'report' |
|
35 | assert_template 'report' | |
36 | assert_not_nil assigns(:total_hours) |
|
36 | assert_not_nil assigns(:total_hours) | |
37 | assert_equal "8.65", "%.2f" % assigns(:total_hours) |
|
37 | assert_equal "8.65", "%.2f" % assigns(:total_hours) | |
38 | end |
|
38 | end | |
39 |
|
39 | |||
40 | def test_report_all_time |
|
40 | def test_report_all_time | |
41 | get :report, :project_id => 1, :criterias => ['project', 'issue'] |
|
41 | get :report, :project_id => 1, :criterias => ['project', 'issue'] | |
42 | assert_response :success |
|
42 | assert_response :success | |
43 | assert_template 'report' |
|
43 | assert_template 'report' | |
44 | assert_not_nil assigns(:total_hours) |
|
44 | assert_not_nil assigns(:total_hours) | |
45 | assert_equal "162.90", "%.2f" % assigns(:total_hours) |
|
45 | assert_equal "162.90", "%.2f" % assigns(:total_hours) | |
46 | end |
|
46 | end | |
47 |
|
47 | |||
48 | def test_report_all_time_by_day |
|
48 | def test_report_all_time_by_day | |
49 | get :report, :project_id => 1, :criterias => ['project', 'issue'], :columns => 'day' |
|
49 | get :report, :project_id => 1, :criterias => ['project', 'issue'], :columns => 'day' | |
50 | assert_response :success |
|
50 | assert_response :success | |
51 | assert_template 'report' |
|
51 | assert_template 'report' | |
52 | assert_not_nil assigns(:total_hours) |
|
52 | assert_not_nil assigns(:total_hours) | |
53 | assert_equal "162.90", "%.2f" % assigns(:total_hours) |
|
53 | assert_equal "162.90", "%.2f" % assigns(:total_hours) | |
54 | assert_tag :tag => 'th', :content => '2007-03-12' |
|
54 | assert_tag :tag => 'th', :content => '2007-03-12' | |
55 | end |
|
55 | end | |
56 |
|
56 | |||
57 | def test_report_one_criteria |
|
57 | def test_report_one_criteria | |
58 | get :report, :project_id => 1, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criterias => ['project'] |
|
58 | get :report, :project_id => 1, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criterias => ['project'] | |
59 | assert_response :success |
|
59 | assert_response :success | |
60 | assert_template 'report' |
|
60 | assert_template 'report' | |
61 | assert_not_nil assigns(:total_hours) |
|
61 | assert_not_nil assigns(:total_hours) | |
62 | assert_equal "8.65", "%.2f" % assigns(:total_hours) |
|
62 | assert_equal "8.65", "%.2f" % assigns(:total_hours) | |
63 | end |
|
63 | end | |
64 |
|
64 | |||
65 | def test_report_two_criterias |
|
65 | def test_report_two_criterias | |
66 | get :report, :project_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criterias => ["member", "activity"] |
|
66 | get :report, :project_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criterias => ["member", "activity"] | |
67 | assert_response :success |
|
67 | assert_response :success | |
68 | assert_template 'report' |
|
68 | assert_template 'report' | |
69 | assert_not_nil assigns(:total_hours) |
|
69 | assert_not_nil assigns(:total_hours) | |
70 | assert_equal "162.90", "%.2f" % assigns(:total_hours) |
|
70 | assert_equal "162.90", "%.2f" % assigns(:total_hours) | |
71 | end |
|
71 | end | |
72 |
|
72 | |||
73 | def test_report_one_day |
|
73 | def test_report_one_day | |
74 | get :report, :project_id => 1, :columns => 'day', :from => "2007-03-23", :to => "2007-03-23", :criterias => ["member", "activity"] |
|
74 | get :report, :project_id => 1, :columns => 'day', :from => "2007-03-23", :to => "2007-03-23", :criterias => ["member", "activity"] | |
75 | assert_response :success |
|
75 | assert_response :success | |
76 | assert_template 'report' |
|
76 | assert_template 'report' | |
77 | assert_not_nil assigns(:total_hours) |
|
77 | assert_not_nil assigns(:total_hours) | |
78 | assert_equal "4.25", "%.2f" % assigns(:total_hours) |
|
78 | assert_equal "4.25", "%.2f" % assigns(:total_hours) | |
79 | end |
|
79 | end | |
80 |
|
80 | |||
81 | def test_report_at_issue_level |
|
81 | def test_report_at_issue_level | |
82 | get :report, :project_id => 1, :issue_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criterias => ["member", "activity"] |
|
82 | get :report, :project_id => 1, :issue_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criterias => ["member", "activity"] | |
83 | assert_response :success |
|
83 | assert_response :success | |
84 | assert_template 'report' |
|
84 | assert_template 'report' | |
85 | assert_not_nil assigns(:total_hours) |
|
85 | assert_not_nil assigns(:total_hours) | |
86 | assert_equal "154.25", "%.2f" % assigns(:total_hours) |
|
86 | assert_equal "154.25", "%.2f" % assigns(:total_hours) | |
87 | assert_tag :form, |
|
87 | assert_tag :form, | |
88 | :attributes => {:action => "/projects/ecookbook/issues/1/time_entries/report", :id => 'query_form'} |
|
88 | :attributes => {:action => "/projects/ecookbook/issues/1/time_entries/report", :id => 'query_form'} | |
89 | end |
|
89 | end | |
90 |
|
90 | |||
91 | def test_report_custom_field_criteria |
|
91 | def test_report_custom_field_criteria | |
92 | get :report, :project_id => 1, :criterias => ['project', 'cf_1', 'cf_7'] |
|
92 | get :report, :project_id => 1, :criterias => ['project', 'cf_1', 'cf_7'] | |
93 | assert_response :success |
|
93 | assert_response :success | |
94 | assert_template 'report' |
|
94 | assert_template 'report' | |
95 | assert_not_nil assigns(:total_hours) |
|
95 | assert_not_nil assigns(:total_hours) | |
96 | assert_not_nil assigns(:criterias) |
|
96 | assert_not_nil assigns(:criterias) | |
97 | assert_equal 3, assigns(:criterias).size |
|
97 | assert_equal 3, assigns(:criterias).size | |
98 | assert_equal "162.90", "%.2f" % assigns(:total_hours) |
|
98 | assert_equal "162.90", "%.2f" % assigns(:total_hours) | |
99 | # Custom field column |
|
99 | # Custom field column | |
100 | assert_tag :tag => 'th', :content => 'Database' |
|
100 | assert_tag :tag => 'th', :content => 'Database' | |
101 | # Custom field row |
|
101 | # Custom field row | |
102 | assert_tag :tag => 'td', :content => 'MySQL', |
|
102 | assert_tag :tag => 'td', :content => 'MySQL', | |
103 | :sibling => { :tag => 'td', :attributes => { :class => 'hours' }, |
|
103 | :sibling => { :tag => 'td', :attributes => { :class => 'hours' }, | |
104 | :child => { :tag => 'span', :attributes => { :class => 'hours hours-int' }, |
|
104 | :child => { :tag => 'span', :attributes => { :class => 'hours hours-int' }, | |
105 | :content => '1' }} |
|
105 | :content => '1' }} | |
106 | # Second custom field column |
|
106 | # Second custom field column | |
107 | assert_tag :tag => 'th', :content => 'Billable' |
|
107 | assert_tag :tag => 'th', :content => 'Billable' | |
108 | end |
|
108 | end | |
109 |
|
109 | |||
110 | def test_report_one_criteria_no_result |
|
110 | def test_report_one_criteria_no_result | |
111 | get :report, :project_id => 1, :columns => 'week', :from => "1998-04-01", :to => "1998-04-30", :criterias => ['project'] |
|
111 | get :report, :project_id => 1, :columns => 'week', :from => "1998-04-01", :to => "1998-04-30", :criterias => ['project'] | |
112 | assert_response :success |
|
112 | assert_response :success | |
113 | assert_template 'report' |
|
113 | assert_template 'report' | |
114 | assert_not_nil assigns(:total_hours) |
|
114 | assert_not_nil assigns(:total_hours) | |
115 | assert_equal "0.00", "%.2f" % assigns(:total_hours) |
|
115 | assert_equal "0.00", "%.2f" % assigns(:total_hours) | |
116 | end |
|
116 | end | |
117 |
|
117 | |||
118 | def test_report_all_projects_csv_export |
|
118 | def test_report_all_projects_csv_export | |
119 | get :report, :columns => 'month', :from => "2007-01-01", :to => "2007-06-30", :criterias => ["project", "member", "activity"], :format => "csv" |
|
119 | get :report, :columns => 'month', :from => "2007-01-01", :to => "2007-06-30", :criterias => ["project", "member", "activity"], :format => "csv" | |
120 | assert_response :success |
|
120 | assert_response :success | |
121 | assert_equal 'text/csv', @response.content_type |
|
121 | assert_equal 'text/csv', @response.content_type | |
122 | lines = @response.body.chomp.split("\n") |
|
122 | lines = @response.body.chomp.split("\n") | |
123 | # Headers |
|
123 | # Headers | |
124 | assert_equal 'Project,Member,Activity,2007-1,2007-2,2007-3,2007-4,2007-5,2007-6,Total', lines.first |
|
124 | assert_equal 'Project,Member,Activity,2007-1,2007-2,2007-3,2007-4,2007-5,2007-6,Total', lines.first | |
125 | # Total row |
|
125 | # Total row | |
126 | assert_equal 'Total,"","","","",154.25,8.65,"","",162.90', lines.last |
|
126 | assert_equal 'Total,"","","","",154.25,8.65,"","",162.90', lines.last | |
127 | end |
|
127 | end | |
128 |
|
128 | |||
129 | def test_report_csv_export |
|
129 | def test_report_csv_export | |
130 | get :report, :project_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-06-30", :criterias => ["project", "member", "activity"], :format => "csv" |
|
130 | get :report, :project_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-06-30", :criterias => ["project", "member", "activity"], :format => "csv" | |
131 | assert_response :success |
|
131 | assert_response :success | |
132 | assert_equal 'text/csv', @response.content_type |
|
132 | assert_equal 'text/csv', @response.content_type | |
133 | lines = @response.body.chomp.split("\n") |
|
133 | lines = @response.body.chomp.split("\n") | |
134 | # Headers |
|
134 | # Headers | |
135 | assert_equal 'Project,Member,Activity,2007-1,2007-2,2007-3,2007-4,2007-5,2007-6,Total', lines.first |
|
135 | assert_equal 'Project,Member,Activity,2007-1,2007-2,2007-3,2007-4,2007-5,2007-6,Total', lines.first | |
136 | # Total row |
|
136 | # Total row | |
137 | assert_equal 'Total,"","","","",154.25,8.65,"","",162.90', lines.last |
|
137 | assert_equal 'Total,"","","","",154.25,8.65,"","",162.90', lines.last | |
138 | end |
|
138 | end | |
139 |
|
139 | |||
140 | end |
|
140 | end |
General Comments 0
You need to be logged in to leave comments.
Login now