##// END OF EJS Templates
Added some tests for projects controller and helper....
Jean-Philippe Lang -
r976:eb7cbd481e44
parent child
Show More
@@ -0,0 +1,41
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 require File.dirname(__FILE__) + '/../../test_helper'
19
20 class ProjectsHelperTest < HelperTestCase
21 include ProjectsHelper
22 include ActionView::Helpers::TextHelper
23 fixtures :projects, :trackers, :issue_statuses, :issues, :enumerations, :users, :issue_categories
24
25 def setup
26 super
27 end
28
29 if Object.const_defined?(:Magick)
30 def test_gantt_image
31 assert gantt_image(Issue.find(:all, :conditions => "start_date IS NOT NULL AND due_date IS NOT NULL"), Date.today, 6, 2)
32 end
33
34 def test_gantt_image_with_days
35 assert gantt_image(Issue.find(:all, :conditions => "start_date IS NOT NULL AND due_date IS NOT NULL"), Date.today, 3, 4)
36 end
37 else
38 puts "RMagick not installed. Skipping tests !!!"
39 def test_fake; assert true end
40 end
41 end
@@ -1,199 +1,199
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006 Jean-Philippe Lang
2 # Copyright (C) 2006 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 module ProjectsHelper
18 module ProjectsHelper
19 def link_to_version(version, options = {})
19 def link_to_version(version, options = {})
20 return '' unless version && version.is_a?(Version)
20 return '' unless version && version.is_a?(Version)
21 link_to version.name, {:controller => 'projects',
21 link_to version.name, {:controller => 'projects',
22 :action => 'roadmap',
22 :action => 'roadmap',
23 :id => version.project_id,
23 :id => version.project_id,
24 :completed => (version.completed? ? 1 : nil),
24 :completed => (version.completed? ? 1 : nil),
25 :anchor => version.name
25 :anchor => version.name
26 }, options
26 }, options
27 end
27 end
28
28
29 def project_settings_tabs
29 def project_settings_tabs
30 tabs = [{:name => 'info', :action => :edit_project, :partial => 'projects/edit', :label => :label_information_plural},
30 tabs = [{:name => 'info', :action => :edit_project, :partial => 'projects/edit', :label => :label_information_plural},
31 {:name => 'modules', :action => :select_project_modules, :partial => 'projects/settings/modules', :label => :label_module_plural},
31 {:name => 'modules', :action => :select_project_modules, :partial => 'projects/settings/modules', :label => :label_module_plural},
32 {:name => 'members', :action => :manage_members, :partial => 'projects/settings/members', :label => :label_member_plural},
32 {:name => 'members', :action => :manage_members, :partial => 'projects/settings/members', :label => :label_member_plural},
33 {:name => 'versions', :action => :manage_versions, :partial => 'projects/settings/versions', :label => :label_version_plural},
33 {:name => 'versions', :action => :manage_versions, :partial => 'projects/settings/versions', :label => :label_version_plural},
34 {:name => 'categories', :action => :manage_categories, :partial => 'projects/settings/issue_categories', :label => :label_issue_category_plural},
34 {:name => 'categories', :action => :manage_categories, :partial => 'projects/settings/issue_categories', :label => :label_issue_category_plural},
35 {:name => 'wiki', :action => :manage_wiki, :partial => 'projects/settings/wiki', :label => :label_wiki},
35 {:name => 'wiki', :action => :manage_wiki, :partial => 'projects/settings/wiki', :label => :label_wiki},
36 {:name => 'repository', :action => :manage_repository, :partial => 'projects/settings/repository', :label => :label_repository},
36 {:name => 'repository', :action => :manage_repository, :partial => 'projects/settings/repository', :label => :label_repository},
37 {:name => 'boards', :action => :manage_boards, :partial => 'projects/settings/boards', :label => :label_board_plural}
37 {:name => 'boards', :action => :manage_boards, :partial => 'projects/settings/boards', :label => :label_board_plural}
38 ]
38 ]
39 tabs.select {|tab| User.current.allowed_to?(tab[:action], @project)}
39 tabs.select {|tab| User.current.allowed_to?(tab[:action], @project)}
40 end
40 end
41
41
42 # Generates a gantt image
42 # Generates a gantt image
43 # Only defined if RMagick is avalaible
43 # Only defined if RMagick is avalaible
44 def gantt_image(events, date_from, months, zoom)
44 def gantt_image(events, date_from, months, zoom)
45 date_to = (date_from >> months)-1
45 date_to = (date_from >> months)-1
46 show_weeks = zoom > 1
46 show_weeks = zoom > 1
47 show_days = zoom > 2
47 show_days = zoom > 2
48
48
49 subject_width = 320
49 subject_width = 320
50 header_heigth = 18
50 header_heigth = 18
51 # width of one day in pixels
51 # width of one day in pixels
52 zoom = zoom*2
52 zoom = zoom*2
53 g_width = (date_to - date_from + 1)*zoom
53 g_width = (date_to - date_from + 1)*zoom
54 g_height = 20 * events.length + 20
54 g_height = 20 * events.length + 20
55 headers_heigth = (show_weeks ? 2*header_heigth : header_heigth)
55 headers_heigth = (show_weeks ? 2*header_heigth : header_heigth)
56 height = g_height + headers_heigth
56 height = g_height + headers_heigth
57
57
58 imgl = Magick::ImageList.new
58 imgl = Magick::ImageList.new
59 imgl.new_image(subject_width+g_width+1, height)
59 imgl.new_image(subject_width+g_width+1, height)
60 gc = Magick::Draw.new
60 gc = Magick::Draw.new
61
61
62 # Subjects
62 # Subjects
63 top = headers_heigth + 20
63 top = headers_heigth + 20
64 gc.fill('black')
64 gc.fill('black')
65 gc.stroke('transparent')
65 gc.stroke('transparent')
66 gc.stroke_width(1)
66 gc.stroke_width(1)
67 events.each do |i|
67 events.each do |i|
68 gc.text(4, top + 2, (i.is_a?(Issue) ? i.subject : i.name))
68 gc.text(4, top + 2, (i.is_a?(Issue) ? i.subject : i.name))
69 top = top + 20
69 top = top + 20
70 end
70 end
71
71
72 # Months headers
72 # Months headers
73 month_f = date_from
73 month_f = date_from
74 left = subject_width
74 left = subject_width
75 months.times do
75 months.times do
76 width = ((month_f >> 1) - month_f) * zoom
76 width = ((month_f >> 1) - month_f) * zoom
77 gc.fill('white')
77 gc.fill('white')
78 gc.stroke('grey')
78 gc.stroke('grey')
79 gc.stroke_width(1)
79 gc.stroke_width(1)
80 gc.rectangle(left, 0, left + width, height)
80 gc.rectangle(left, 0, left + width, height)
81 gc.fill('black')
81 gc.fill('black')
82 gc.stroke('transparent')
82 gc.stroke('transparent')
83 gc.stroke_width(1)
83 gc.stroke_width(1)
84 gc.text(left.round + 8, 14, "#{month_f.year}-#{month_f.month}")
84 gc.text(left.round + 8, 14, "#{month_f.year}-#{month_f.month}")
85 left = left + width
85 left = left + width
86 month_f = month_f >> 1
86 month_f = month_f >> 1
87 end
87 end
88
88
89 # Weeks headers
89 # Weeks headers
90 if show_weeks
90 if show_weeks
91 left = subject_width
91 left = subject_width
92 height = header_heigth
92 height = header_heigth
93 if date_from.cwday == 1
93 if date_from.cwday == 1
94 # date_from is monday
94 # date_from is monday
95 week_f = date_from
95 week_f = date_from
96 else
96 else
97 # find next monday after date_from
97 # find next monday after date_from
98 week_f = date_from + (7 - date_from.cwday + 1)
98 week_f = date_from + (7 - date_from.cwday + 1)
99 width = (7 - date_from.cwday + 1) * zoom
99 width = (7 - date_from.cwday + 1) * zoom
100 gc.fill('white')
100 gc.fill('white')
101 gc.stroke('grey')
101 gc.stroke('grey')
102 gc.stroke_width(1)
102 gc.stroke_width(1)
103 gc.rectangle(left, header_heigth, left + width, 2*header_heigth + g_height-1)
103 gc.rectangle(left, header_heigth, left + width, 2*header_heigth + g_height-1)
104 left = left + width
104 left = left + width
105 end
105 end
106 while week_f <= date_to
106 while week_f <= date_to
107 width = (week_f + 6 <= date_to) ? 7 * zoom : (date_to - week_f + 1) * zoom
107 width = (week_f + 6 <= date_to) ? 7 * zoom : (date_to - week_f + 1) * zoom
108 gc.fill('white')
108 gc.fill('white')
109 gc.stroke('grey')
109 gc.stroke('grey')
110 gc.stroke_width(1)
110 gc.stroke_width(1)
111 gc.rectangle(left.round, header_heigth, left.round + width, 2*header_heigth + g_height-1)
111 gc.rectangle(left.round, header_heigth, left.round + width, 2*header_heigth + g_height-1)
112 gc.fill('black')
112 gc.fill('black')
113 gc.stroke('transparent')
113 gc.stroke('transparent')
114 gc.stroke_width(1)
114 gc.stroke_width(1)
115 gc.text(left.round + 2, header_heigth + 14, week_f.cweek.to_s)
115 gc.text(left.round + 2, header_heigth + 14, week_f.cweek.to_s)
116 left = left + width
116 left = left + width
117 week_f = week_f+7
117 week_f = week_f+7
118 end
118 end
119 end
119 end
120
120
121 # Days details (week-end in grey)
121 # Days details (week-end in grey)
122 if show_days
122 if show_days
123 left = subject_width
123 left = subject_width
124 height = g_height + header_heigth - 1
124 height = g_height + header_heigth - 1
125 wday = date_from.cwday
125 wday = date_from.cwday
126 (date_to - date_from + 1).to_i.times do
126 (date_to - date_from + 1).to_i.times do
127 width = zoom
127 width = zoom
128 gc.fill(wday == 6 || wday == 7 ? '#eee' : 'white')
128 gc.fill(wday == 6 || wday == 7 ? '#eee' : 'white')
129 gc.stroke('grey')
129 gc.stroke('grey')
130 gc.stroke_width(1)
130 gc.stroke_width(1)
131 gc.rectangle(left, 2*header_heigth, left + width, 2*header_heigth + g_height-1)
131 gc.rectangle(left, 2*header_heigth, left + width, 2*header_heigth + g_height-1)
132 left = left + width
132 left = left + width
133 wday = wday + 1
133 wday = wday + 1
134 wday = 1 if wday > 7
134 wday = 1 if wday > 7
135 end
135 end
136 end
136 end
137
137
138 # border
138 # border
139 gc.fill('transparent')
139 gc.fill('transparent')
140 gc.stroke('grey')
140 gc.stroke('grey')
141 gc.stroke_width(1)
141 gc.stroke_width(1)
142 gc.rectangle(0, 0, subject_width+g_width, headers_heigth)
142 gc.rectangle(0, 0, subject_width+g_width, headers_heigth)
143 gc.stroke('black')
143 gc.stroke('black')
144 gc.rectangle(0, 0, subject_width+g_width, g_height+ headers_heigth-1)
144 gc.rectangle(0, 0, subject_width+g_width, g_height+ headers_heigth-1)
145
145
146 # content
146 # content
147 top = headers_heigth + 20
147 top = headers_heigth + 20
148 gc.stroke('transparent')
148 gc.stroke('transparent')
149 events.each do |i|
149 events.each do |i|
150 if i.is_a?(Issue)
150 if i.is_a?(Issue)
151 i_start_date = (i.start_date >= date_from ? i.start_date : date_from )
151 i_start_date = (i.start_date >= date_from ? i.start_date : date_from )
152 i_end_date = (i.due_date <= date_to ? i.due_date : date_to )
152 i_end_date = (i.due_date <= date_to ? i.due_date : date_to )
153 i_done_date = i.start_date + ((i.due_date - i.start_date+1)*i.done_ratio/100).floor
153 i_done_date = i.start_date + ((i.due_date - i.start_date+1)*i.done_ratio/100).floor
154 i_done_date = (i_done_date <= date_from ? date_from : i_done_date )
154 i_done_date = (i_done_date <= date_from ? date_from : i_done_date )
155 i_done_date = (i_done_date >= date_to ? date_to : i_done_date )
155 i_done_date = (i_done_date >= date_to ? date_to : i_done_date )
156 i_late_date = [i_end_date, Date.today].min if i_start_date < Date.today
156 i_late_date = [i_end_date, Date.today].min if i_start_date < Date.today
157
157
158 i_left = subject_width + ((i_start_date - date_from)*zoom).floor
158 i_left = subject_width + ((i_start_date - date_from)*zoom).floor
159 i_width = ((i_end_date - i_start_date + 1)*zoom).floor # total width of the issue
159 i_width = ((i_end_date - i_start_date + 1)*zoom).floor # total width of the issue
160 d_width = ((i_done_date - i_start_date)*zoom).floor # done width
160 d_width = ((i_done_date - i_start_date)*zoom).floor # done width
161 l_width = i_late_date ? ((i_late_date - i_start_date+1)*zoom).floor : 0 # delay width
161 l_width = i_late_date ? ((i_late_date - i_start_date+1)*zoom).floor : 0 # delay width
162
162
163 gc.fill('grey')
163 gc.fill('grey')
164 gc.rectangle(i_left, top, i_left + i_width, top - 6)
164 gc.rectangle(i_left, top, i_left + i_width, top - 6)
165 gc.fill('red')
165 gc.fill('red')
166 gc.rectangle(i_left, top, i_left + l_width, top - 6) if l_width > 0
166 gc.rectangle(i_left, top, i_left + l_width, top - 6) if l_width > 0
167 gc.fill('blue')
167 gc.fill('blue')
168 gc.rectangle(i_left, top, i_left + d_width, top - 6) if d_width > 0
168 gc.rectangle(i_left, top, i_left + d_width, top - 6) if d_width > 0
169 gc.fill('black')
169 gc.fill('black')
170 gc.text(i_left + i_width + 5,top + 1, "#{i.status.name} #{i.done_ratio}%")
170 gc.text(i_left + i_width + 5,top + 1, "#{i.status.name} #{i.done_ratio}%")
171 else
171 else
172 i_left = subject_width + ((i.start_date - date_from)*zoom).floor
172 i_left = subject_width + ((i.start_date - date_from)*zoom).floor
173 gc.fill('green')
173 gc.fill('green')
174 gc.rectangle(i_left, top, i_left + 6, top - 6)
174 gc.rectangle(i_left, top, i_left + 6, top - 6)
175 gc.fill('black')
175 gc.fill('black')
176 gc.text(i_left + 11, top + 1, i.name)
176 gc.text(i_left + 11, top + 1, i.name)
177 end
177 end
178 top = top + 20
178 top = top + 20
179 end
179 end
180
180
181 # today red line
181 # today red line
182 if Date.today >= @date_from and Date.today <= @date_to
182 if Date.today >= date_from and Date.today <= date_to
183 gc.stroke('red')
183 gc.stroke('red')
184 x = (Date.today-@date_from+1)*zoom + subject_width
184 x = (Date.today-date_from+1)*zoom + subject_width
185 gc.line(x, headers_heigth, x, headers_heigth + g_height-1)
185 gc.line(x, headers_heigth, x, headers_heigth + g_height-1)
186 end
186 end
187
187
188 gc.draw(imgl)
188 gc.draw(imgl)
189 imgl
189 imgl
190 end if Object.const_defined?(:Magick)
190 end if Object.const_defined?(:Magick)
191
191
192 def new_issue_selector
192 def new_issue_selector
193 trackers = @project.trackers
193 trackers = @project.trackers
194 # can't use form tag inside helper
194 # can't use form tag inside helper
195 content_tag('form',
195 content_tag('form',
196 select_tag('tracker_id', '<option></option>' + options_from_collection_for_select(trackers, 'id', 'name'), :onchange => "if (this.value != '') {this.form.submit()}"),
196 select_tag('tracker_id', '<option></option>' + options_from_collection_for_select(trackers, 'id', 'name'), :onchange => "if (this.value != '') {this.form.submit()}"),
197 :action => url_for(:controller => 'projects', :action => 'add_issue', :id => @project), :method => 'get')
197 :action => url_for(:controller => 'projects', :action => 'add_issue', :id => @project), :method => 'get')
198 end
198 end
199 end
199 end
@@ -1,58 +1,60
1 ---
1 ---
2 issues_001:
2 issues_001:
3 created_on: <%= 3.days.ago.to_date.to_s(:db) %>
3 created_on: <%= 3.days.ago.to_date.to_s(:db) %>
4 project_id: 1
4 project_id: 1
5 updated_on: <%= 1.day.ago.to_date.to_s(:db) %>
5 updated_on: <%= 1.day.ago.to_date.to_s(:db) %>
6 priority_id: 4
6 priority_id: 4
7 subject: Can't print recipes
7 subject: Can't print recipes
8 id: 1
8 id: 1
9 fixed_version_id:
9 fixed_version_id:
10 category_id: 1
10 category_id: 1
11 description: Unable to print recipes
11 description: Unable to print recipes
12 tracker_id: 1
12 tracker_id: 1
13 assigned_to_id:
13 assigned_to_id:
14 author_id: 2
14 author_id: 2
15 status_id: 1
15 status_id: 1
16 issues_002:
16 issues_002:
17 created_on: 2006-07-19 21:04:21 +02:00
17 created_on: 2006-07-19 21:04:21 +02:00
18 project_id: 1
18 project_id: 1
19 updated_on: 2006-07-19 21:09:50 +02:00
19 updated_on: 2006-07-19 21:09:50 +02:00
20 priority_id: 5
20 priority_id: 5
21 subject: Add ingredients categories
21 subject: Add ingredients categories
22 id: 2
22 id: 2
23 fixed_version_id:
23 fixed_version_id:
24 category_id:
24 category_id:
25 description: Ingredients should be classified by categories
25 description: Ingredients should be classified by categories
26 tracker_id: 2
26 tracker_id: 2
27 assigned_to_id: 3
27 assigned_to_id: 3
28 author_id: 2
28 author_id: 2
29 status_id: 2
29 status_id: 2
30 issues_003:
30 issues_003:
31 created_on: 2006-07-19 21:07:27 +02:00
31 created_on: 2006-07-19 21:07:27 +02:00
32 project_id: 1
32 project_id: 1
33 updated_on: 2006-07-19 21:07:27 +02:00
33 updated_on: 2006-07-19 21:07:27 +02:00
34 priority_id: 4
34 priority_id: 4
35 subject: Error 281 when updating a recipe
35 subject: Error 281 when updating a recipe
36 id: 3
36 id: 3
37 fixed_version_id:
37 fixed_version_id:
38 category_id:
38 category_id:
39 description: Error 281 is encountered when saving a recipe
39 description: Error 281 is encountered when saving a recipe
40 tracker_id: 1
40 tracker_id: 1
41 assigned_to_id:
41 assigned_to_id:
42 author_id: 2
42 author_id: 2
43 status_id: 1
43 status_id: 1
44 start_date: <%= 1.day.from_now.to_date.to_s(:db) %>
45 due_date: <%= 40.day.ago.to_date.to_s(:db) %>
44 issues_004:
46 issues_004:
45 created_on: 2006-07-19 21:07:27 +02:00
47 created_on: 2006-07-19 21:07:27 +02:00
46 project_id: 2
48 project_id: 2
47 updated_on: 2006-07-19 21:07:27 +02:00
49 updated_on: 2006-07-19 21:07:27 +02:00
48 priority_id: 4
50 priority_id: 4
49 subject: Issue on project 2
51 subject: Issue on project 2
50 id: 4
52 id: 4
51 fixed_version_id:
53 fixed_version_id:
52 category_id:
54 category_id:
53 description: Issue on project 2
55 description: Issue on project 2
54 tracker_id: 1
56 tracker_id: 1
55 assigned_to_id:
57 assigned_to_id:
56 author_id: 2
58 author_id: 2
57 status_id: 1
59 status_id: 1
58
60
@@ -1,211 +1,257
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.dirname(__FILE__) + '/../test_helper'
18 require File.dirname(__FILE__) + '/../test_helper'
19 require 'projects_controller'
19 require 'projects_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class ProjectsController; def rescue_action(e) raise e end; end
22 class ProjectsController; def rescue_action(e) raise e end; end
23
23
24 class ProjectsControllerTest < Test::Unit::TestCase
24 class ProjectsControllerTest < Test::Unit::TestCase
25 fixtures :projects, :versions, :users, :roles, :members, :issues, :journals, :journal_details, :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations
25 fixtures :projects, :versions, :users, :roles, :members, :issues, :journals, :journal_details, :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations
26
26
27 def setup
27 def setup
28 @controller = ProjectsController.new
28 @controller = ProjectsController.new
29 @request = ActionController::TestRequest.new
29 @request = ActionController::TestRequest.new
30 @response = ActionController::TestResponse.new
30 @response = ActionController::TestResponse.new
31 end
31 end
32
32
33 def test_index
33 def test_index
34 get :index
34 get :index
35 assert_response :success
35 assert_response :success
36 assert_template 'list'
36 assert_template 'list'
37 end
37 end
38
38
39 def test_list
39 def test_list
40 get :list
40 get :list
41 assert_response :success
41 assert_response :success
42 assert_template 'list'
42 assert_template 'list'
43 assert_not_nil assigns(:project_tree)
43 assert_not_nil assigns(:project_tree)
44 # Root project as hash key
44 # Root project as hash key
45 assert assigns(:project_tree).has_key?(Project.find(1))
45 assert assigns(:project_tree).has_key?(Project.find(1))
46 # Subproject in corresponding value
46 # Subproject in corresponding value
47 assert assigns(:project_tree)[Project.find(1)].include?(Project.find(3))
47 assert assigns(:project_tree)[Project.find(1)].include?(Project.find(3))
48 end
48 end
49
49
50 def test_show
50 def test_show
51 get :show, :id => 1
51 get :show, :id => 1
52 assert_response :success
52 assert_response :success
53 assert_template 'show'
53 assert_template 'show'
54 assert_not_nil assigns(:project)
54 assert_not_nil assigns(:project)
55 end
56
57 def test_settings
58 @request.session[:user_id] = 2 # manager
59 get :settings, :id => 1
60 assert_response :success
61 assert_template 'settings'
62 end
63
64 def test_edit
65 @request.session[:user_id] = 2 # manager
66 post :edit, :id => 1, :project => {:name => 'Test changed name'}
67 assert_redirected_to 'projects/settings/1'
68 project = Project.find(1)
69 assert_equal 'Test changed name', project.name
70 end
71
72 def test_get_destroy
73 @request.session[:user_id] = 1 # admin
74 get :destroy, :id => 1
75 assert_response :success
76 assert_template 'destroy'
77 assert_not_nil Project.find_by_id(1)
55 end
78 end
79
80 def test_post_destroy
81 @request.session[:user_id] = 1 # admin
82 post :destroy, :id => 1, :confirm => 1
83 assert_redirected_to 'admin/projects'
84 assert_nil Project.find_by_id(1)
85 end
56
86
57 def test_list_documents
87 def test_list_documents
58 get :list_documents, :id => 1
88 get :list_documents, :id => 1
59 assert_response :success
89 assert_response :success
60 assert_template 'list_documents'
90 assert_template 'list_documents'
61 assert_not_nil assigns(:grouped)
91 assert_not_nil assigns(:grouped)
62 end
92 end
63
93
64 def test_bulk_edit_issues
94 def test_bulk_edit_issues
65 @request.session[:user_id] = 2
95 @request.session[:user_id] = 2
66 # update issues priority
96 # update issues priority
67 post :bulk_edit_issues, :id => 1, :issue_ids => [1, 2], :priority_id => 7, :notes => 'Bulk editing', :assigned_to_id => ''
97 post :bulk_edit_issues, :id => 1, :issue_ids => [1, 2], :priority_id => 7, :notes => 'Bulk editing', :assigned_to_id => ''
68 assert_response 302
98 assert_response 302
69 # check that the issues were updated
99 # check that the issues were updated
70 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
100 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
71 assert_equal 'Bulk editing', Issue.find(1).journals.find(:first, :order => 'created_on DESC').notes
101 assert_equal 'Bulk editing', Issue.find(1).journals.find(:first, :order => 'created_on DESC').notes
72 end
102 end
73
103
104 def test_move_issues_to_another_project
105 @request.session[:user_id] = 1
106 post :move_issues, :id => 1, :issue_ids => [1, 2], :new_project_id => 2
107 assert_redirected_to 'projects/1/issues'
108 assert_equal 2, Issue.find(1).project_id
109 assert_equal 2, Issue.find(2).project_id
110 end
111
112 def test_move_issues_to_another_tracker
113 @request.session[:user_id] = 1
114 post :move_issues, :id => 1, :issue_ids => [1, 2], :new_tracker_id => 3
115 assert_redirected_to 'projects/1/issues'
116 assert_equal 3, Issue.find(1).tracker_id
117 assert_equal 3, Issue.find(2).tracker_id
118 end
119
74 def test_list_files
120 def test_list_files
75 get :list_files, :id => 1
121 get :list_files, :id => 1
76 assert_response :success
122 assert_response :success
77 assert_template 'list_files'
123 assert_template 'list_files'
78 assert_not_nil assigns(:versions)
124 assert_not_nil assigns(:versions)
79 end
125 end
80
126
81 def test_changelog
127 def test_changelog
82 get :changelog, :id => 1
128 get :changelog, :id => 1
83 assert_response :success
129 assert_response :success
84 assert_template 'changelog'
130 assert_template 'changelog'
85 assert_not_nil assigns(:versions)
131 assert_not_nil assigns(:versions)
86 end
132 end
87
133
88 def test_roadmap
134 def test_roadmap
89 get :roadmap, :id => 1
135 get :roadmap, :id => 1
90 assert_response :success
136 assert_response :success
91 assert_template 'roadmap'
137 assert_template 'roadmap'
92 assert_not_nil assigns(:versions)
138 assert_not_nil assigns(:versions)
93 # Version with no date set appears
139 # Version with no date set appears
94 assert assigns(:versions).include?(Version.find(3))
140 assert assigns(:versions).include?(Version.find(3))
95 # Completed version doesn't appear
141 # Completed version doesn't appear
96 assert !assigns(:versions).include?(Version.find(1))
142 assert !assigns(:versions).include?(Version.find(1))
97 end
143 end
98
144
99 def test_roadmap_with_completed_versions
145 def test_roadmap_with_completed_versions
100 get :roadmap, :id => 1, :completed => 1
146 get :roadmap, :id => 1, :completed => 1
101 assert_response :success
147 assert_response :success
102 assert_template 'roadmap'
148 assert_template 'roadmap'
103 assert_not_nil assigns(:versions)
149 assert_not_nil assigns(:versions)
104 # Version with no date set appears
150 # Version with no date set appears
105 assert assigns(:versions).include?(Version.find(3))
151 assert assigns(:versions).include?(Version.find(3))
106 # Completed version appears
152 # Completed version appears
107 assert assigns(:versions).include?(Version.find(1))
153 assert assigns(:versions).include?(Version.find(1))
108 end
154 end
109
155
110 def test_activity
156 def test_activity
111 get :activity, :id => 1, :year => 2.days.ago.to_date.year, :month => 2.days.ago.to_date.month
157 get :activity, :id => 1, :year => 2.days.ago.to_date.year, :month => 2.days.ago.to_date.month
112 assert_response :success
158 assert_response :success
113 assert_template 'activity'
159 assert_template 'activity'
114 assert_not_nil assigns(:events_by_day)
160 assert_not_nil assigns(:events_by_day)
115
161
116 assert_tag :tag => "h3",
162 assert_tag :tag => "h3",
117 :content => /#{2.days.ago.to_date.day}/,
163 :content => /#{2.days.ago.to_date.day}/,
118 :sibling => { :tag => "ul",
164 :sibling => { :tag => "ul",
119 :child => { :tag => "li",
165 :child => { :tag => "li",
120 :child => { :tag => "p",
166 :child => { :tag => "p",
121 :content => /(#{IssueStatus.find(2).name})/,
167 :content => /(#{IssueStatus.find(2).name})/,
122 }
168 }
123 }
169 }
124 }
170 }
125
171
126 get :activity, :id => 1, :year => 3.days.ago.to_date.year, :month => 3.days.ago.to_date.month
172 get :activity, :id => 1, :year => 3.days.ago.to_date.year, :month => 3.days.ago.to_date.month
127 assert_response :success
173 assert_response :success
128 assert_template 'activity'
174 assert_template 'activity'
129 assert_not_nil assigns(:events_by_day)
175 assert_not_nil assigns(:events_by_day)
130
176
131 assert_tag :tag => "h3",
177 assert_tag :tag => "h3",
132 :content => /#{3.day.ago.to_date.day}/,
178 :content => /#{3.day.ago.to_date.day}/,
133 :sibling => { :tag => "ul",
179 :sibling => { :tag => "ul",
134 :child => { :tag => "li",
180 :child => { :tag => "li",
135 :child => { :tag => "p",
181 :child => { :tag => "p",
136 :content => /#{Issue.find(1).subject}/,
182 :content => /#{Issue.find(1).subject}/,
137 }
183 }
138 }
184 }
139 }
185 }
140 end
186 end
141
187
142 def test_calendar
188 def test_calendar
143 get :calendar, :id => 1
189 get :calendar, :id => 1
144 assert_response :success
190 assert_response :success
145 assert_template 'calendar'
191 assert_template 'calendar'
146 assert_not_nil assigns(:calendar)
192 assert_not_nil assigns(:calendar)
147 end
193 end
148
194
149 def test_calendar_with_subprojects
195 def test_calendar_with_subprojects
150 get :calendar, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2]
196 get :calendar, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2]
151 assert_response :success
197 assert_response :success
152 assert_template 'calendar'
198 assert_template 'calendar'
153 assert_not_nil assigns(:calendar)
199 assert_not_nil assigns(:calendar)
154 end
200 end
155
201
156 def test_gantt
202 def test_gantt
157 get :gantt, :id => 1
203 get :gantt, :id => 1
158 assert_response :success
204 assert_response :success
159 assert_template 'gantt.rhtml'
205 assert_template 'gantt.rhtml'
160 assert_not_nil assigns(:events)
206 assert_not_nil assigns(:events)
161 end
207 end
162
208
163 def test_gantt_with_subprojects
209 def test_gantt_with_subprojects
164 get :gantt, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2]
210 get :gantt, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2]
165 assert_response :success
211 assert_response :success
166 assert_template 'gantt.rhtml'
212 assert_template 'gantt.rhtml'
167 assert_not_nil assigns(:events)
213 assert_not_nil assigns(:events)
168 end
214 end
169
215
170 def test_gantt_export_to_pdf
216 def test_gantt_export_to_pdf
171 get :gantt, :id => 1, :format => 'pdf'
217 get :gantt, :id => 1, :format => 'pdf'
172 assert_response :success
218 assert_response :success
173 assert_template 'gantt.rfpdf'
219 assert_template 'gantt.rfpdf'
174 assert_equal 'application/pdf', @response.content_type
220 assert_equal 'application/pdf', @response.content_type
175 assert_not_nil assigns(:events)
221 assert_not_nil assigns(:events)
176 end
222 end
177
223
178 def test_archive
224 def test_archive
179 @request.session[:user_id] = 1 # admin
225 @request.session[:user_id] = 1 # admin
180 post :archive, :id => 1
226 post :archive, :id => 1
181 assert_redirected_to 'admin/projects'
227 assert_redirected_to 'admin/projects'
182 assert !Project.find(1).active?
228 assert !Project.find(1).active?
183 end
229 end
184
230
185 def test_unarchive
231 def test_unarchive
186 @request.session[:user_id] = 1 # admin
232 @request.session[:user_id] = 1 # admin
187 Project.find(1).archive
233 Project.find(1).archive
188 post :unarchive, :id => 1
234 post :unarchive, :id => 1
189 assert_redirected_to 'admin/projects'
235 assert_redirected_to 'admin/projects'
190 assert Project.find(1).active?
236 assert Project.find(1).active?
191 end
237 end
192
238
193 def test_add_issue
239 def test_add_issue
194 @request.session[:user_id] = 2
240 @request.session[:user_id] = 2
195 get :add_issue, :id => 1, :tracker_id => 1
241 get :add_issue, :id => 1, :tracker_id => 1
196 assert_response :success
242 assert_response :success
197 assert_template 'add_issue'
243 assert_template 'add_issue'
198 post :add_issue, :id => 1, :issue => {:tracker_id => 1, :subject => 'This is the test_add_issue issue', :description => 'This is the description', :priority_id => 5}
244 post :add_issue, :id => 1, :issue => {:tracker_id => 1, :subject => 'This is the test_add_issue issue', :description => 'This is the description', :priority_id => 5}
199 assert_redirected_to 'projects/1/issues'
245 assert_redirected_to 'projects/1/issues'
200 assert Issue.find_by_subject('This is the test_add_issue issue')
246 assert Issue.find_by_subject('This is the test_add_issue issue')
201 end
247 end
202
248
203 def test_copy_issue
249 def test_copy_issue
204 @request.session[:user_id] = 2
250 @request.session[:user_id] = 2
205 get :add_issue, :id => 1, :copy_from => 1
251 get :add_issue, :id => 1, :copy_from => 1
206 assert_template 'add_issue'
252 assert_template 'add_issue'
207 assert_not_nil assigns(:issue)
253 assert_not_nil assigns(:issue)
208 orig = Issue.find(1)
254 orig = Issue.find(1)
209 assert_equal orig.subject, assigns(:issue).subject
255 assert_equal orig.subject, assigns(:issue).subject
210 end
256 end
211 end
257 end
General Comments 0
You need to be logged in to leave comments. Login now