To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / test / functional / .svn / text-base / time_entry_reports_controller_test.rb.svn-base @ 442:753f1380d6bc

History | View | Annotate | Download (5.65 KB)

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