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