Mercurial > hg > soundsoftware-site
comparison test/functional/time_entry_reports_controller_test.rb @ 37:94944d00e43c
* Update to SVN trunk rev 4411
author | Chris Cannam <chris.cannam@soundsoftware.ac.uk> |
---|---|
date | Fri, 19 Nov 2010 13:24:41 +0000 |
parents | |
children | af80e5618e9b |
comparison
equal
deleted
inserted
replaced
22:40f7cfd4df19 | 37:94944d00e43c |
---|---|
1 # -*- coding: utf-8 -*- | |
2 require File.dirname(__FILE__) + '/../test_helper' | |
3 | |
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 | |
6 | |
7 def test_report_no_criteria | |
8 get :report, :project_id => 1 | |
9 assert_response :success | |
10 assert_template 'report' | |
11 end | |
12 | |
13 def test_report_all_projects | |
14 get :report | |
15 assert_response :success | |
16 assert_template 'report' | |
17 end | |
18 | |
19 def test_report_all_projects_denied | |
20 r = Role.anonymous | |
21 r.permissions.delete(:view_time_entries) | |
22 r.permissions_will_change! | |
23 r.save | |
24 get :report | |
25 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Ftime_entries%2Freport' | |
26 end | |
27 | |
28 def test_report_all_projects_one_criteria | |
29 get :report, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criterias => ['project'] | |
30 assert_response :success | |
31 assert_template 'report' | |
32 assert_not_nil assigns(:total_hours) | |
33 assert_equal "8.65", "%.2f" % assigns(:total_hours) | |
34 end | |
35 | |
36 def test_report_all_time | |
37 get :report, :project_id => 1, :criterias => ['project', 'issue'] | |
38 assert_response :success | |
39 assert_template 'report' | |
40 assert_not_nil assigns(:total_hours) | |
41 assert_equal "162.90", "%.2f" % assigns(:total_hours) | |
42 end | |
43 | |
44 def test_report_all_time_by_day | |
45 get :report, :project_id => 1, :criterias => ['project', 'issue'], :columns => 'day' | |
46 assert_response :success | |
47 assert_template 'report' | |
48 assert_not_nil assigns(:total_hours) | |
49 assert_equal "162.90", "%.2f" % assigns(:total_hours) | |
50 assert_tag :tag => 'th', :content => '2007-03-12' | |
51 end | |
52 | |
53 def test_report_one_criteria | |
54 get :report, :project_id => 1, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criterias => ['project'] | |
55 assert_response :success | |
56 assert_template 'report' | |
57 assert_not_nil assigns(:total_hours) | |
58 assert_equal "8.65", "%.2f" % assigns(:total_hours) | |
59 end | |
60 | |
61 def test_report_two_criterias | |
62 get :report, :project_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criterias => ["member", "activity"] | |
63 assert_response :success | |
64 assert_template 'report' | |
65 assert_not_nil assigns(:total_hours) | |
66 assert_equal "162.90", "%.2f" % assigns(:total_hours) | |
67 end | |
68 | |
69 def test_report_one_day | |
70 get :report, :project_id => 1, :columns => 'day', :from => "2007-03-23", :to => "2007-03-23", :criterias => ["member", "activity"] | |
71 assert_response :success | |
72 assert_template 'report' | |
73 assert_not_nil assigns(:total_hours) | |
74 assert_equal "4.25", "%.2f" % assigns(:total_hours) | |
75 end | |
76 | |
77 def test_report_at_issue_level | |
78 get :report, :project_id => 1, :issue_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criterias => ["member", "activity"] | |
79 assert_response :success | |
80 assert_template 'report' | |
81 assert_not_nil assigns(:total_hours) | |
82 assert_equal "154.25", "%.2f" % assigns(:total_hours) | |
83 end | |
84 | |
85 def test_report_custom_field_criteria | |
86 get :report, :project_id => 1, :criterias => ['project', 'cf_1', 'cf_7'] | |
87 assert_response :success | |
88 assert_template 'report' | |
89 assert_not_nil assigns(:total_hours) | |
90 assert_not_nil assigns(:criterias) | |
91 assert_equal 3, assigns(:criterias).size | |
92 assert_equal "162.90", "%.2f" % assigns(:total_hours) | |
93 # Custom field column | |
94 assert_tag :tag => 'th', :content => 'Database' | |
95 # Custom field row | |
96 assert_tag :tag => 'td', :content => 'MySQL', | |
97 :sibling => { :tag => 'td', :attributes => { :class => 'hours' }, | |
98 :child => { :tag => 'span', :attributes => { :class => 'hours hours-int' }, | |
99 :content => '1' }} | |
100 # Second custom field column | |
101 assert_tag :tag => 'th', :content => 'Billable' | |
102 end | |
103 | |
104 def test_report_one_criteria_no_result | |
105 get :report, :project_id => 1, :columns => 'week', :from => "1998-04-01", :to => "1998-04-30", :criterias => ['project'] | |
106 assert_response :success | |
107 assert_template 'report' | |
108 assert_not_nil assigns(:total_hours) | |
109 assert_equal "0.00", "%.2f" % assigns(:total_hours) | |
110 end | |
111 | |
112 def test_report_all_projects_csv_export | |
113 get :report, :columns => 'month', :from => "2007-01-01", :to => "2007-06-30", :criterias => ["project", "member", "activity"], :format => "csv" | |
114 assert_response :success | |
115 assert_equal 'text/csv', @response.content_type | |
116 lines = @response.body.chomp.split("\n") | |
117 # Headers | |
118 assert_equal 'Project,Member,Activity,2007-1,2007-2,2007-3,2007-4,2007-5,2007-6,Total', lines.first | |
119 # Total row | |
120 assert_equal 'Total,"","","","",154.25,8.65,"","",162.90', lines.last | |
121 end | |
122 | |
123 def test_report_csv_export | |
124 get :report, :project_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-06-30", :criterias => ["project", "member", "activity"], :format => "csv" | |
125 assert_response :success | |
126 assert_equal 'text/csv', @response.content_type | |
127 lines = @response.body.chomp.split("\n") | |
128 # Headers | |
129 assert_equal 'Project,Member,Activity,2007-1,2007-2,2007-3,2007-4,2007-5,2007-6,Total', lines.first | |
130 # Total row | |
131 assert_equal 'Total,"","","","",154.25,8.65,"","",162.90', lines.last | |
132 end | |
133 | |
134 end |