##// END OF EJS Templates
Replaced a custom test with a shoulda macro....
Eric Davis -
r2821:257c92f8f910
parent child
Show More
@@ -1,422 +1,421
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
19
20 class ProjectTest < ActiveSupport::TestCase
20 class ProjectTest < ActiveSupport::TestCase
21 fixtures :projects, :enabled_modules,
21 fixtures :projects, :enabled_modules,
22 :issues, :issue_statuses, :journals, :journal_details,
22 :issues, :issue_statuses, :journals, :journal_details,
23 :users, :members, :member_roles, :roles, :projects_trackers, :trackers, :boards,
23 :users, :members, :member_roles, :roles, :projects_trackers, :trackers, :boards,
24 :queries
24 :queries
25
25
26 def setup
26 def setup
27 @ecookbook = Project.find(1)
27 @ecookbook = Project.find(1)
28 @ecookbook_sub1 = Project.find(3)
28 @ecookbook_sub1 = Project.find(3)
29 end
29 end
30
30
31 should_validate_presence_of :name
32 should_validate_presence_of :identifier
33
34 should_validate_uniqueness_of :name
35 should_validate_uniqueness_of :identifier
36
31 def test_truth
37 def test_truth
32 assert_kind_of Project, @ecookbook
38 assert_kind_of Project, @ecookbook
33 assert_equal "eCookbook", @ecookbook.name
39 assert_equal "eCookbook", @ecookbook.name
34 end
40 end
35
41
36 def test_update
42 def test_update
37 assert_equal "eCookbook", @ecookbook.name
43 assert_equal "eCookbook", @ecookbook.name
38 @ecookbook.name = "eCook"
44 @ecookbook.name = "eCook"
39 assert @ecookbook.save, @ecookbook.errors.full_messages.join("; ")
45 assert @ecookbook.save, @ecookbook.errors.full_messages.join("; ")
40 @ecookbook.reload
46 @ecookbook.reload
41 assert_equal "eCook", @ecookbook.name
47 assert_equal "eCook", @ecookbook.name
42 end
48 end
43
49
44 def test_validate
45 @ecookbook.name = ""
46 assert !@ecookbook.save
47 assert_equal 1, @ecookbook.errors.count
48 assert_equal I18n.translate('activerecord.errors.messages.blank'), @ecookbook.errors.on(:name)
49 end
50
51 def test_validate_identifier
50 def test_validate_identifier
52 to_test = {"abc" => true,
51 to_test = {"abc" => true,
53 "ab12" => true,
52 "ab12" => true,
54 "ab-12" => true,
53 "ab-12" => true,
55 "12" => false,
54 "12" => false,
56 "new" => false}
55 "new" => false}
57
56
58 to_test.each do |identifier, valid|
57 to_test.each do |identifier, valid|
59 p = Project.new
58 p = Project.new
60 p.identifier = identifier
59 p.identifier = identifier
61 p.valid?
60 p.valid?
62 assert_equal valid, p.errors.on('identifier').nil?
61 assert_equal valid, p.errors.on('identifier').nil?
63 end
62 end
64 end
63 end
65
64
66 def test_members_should_be_active_users
65 def test_members_should_be_active_users
67 Project.all.each do |project|
66 Project.all.each do |project|
68 assert_nil project.members.detect {|m| !(m.user.is_a?(User) && m.user.active?) }
67 assert_nil project.members.detect {|m| !(m.user.is_a?(User) && m.user.active?) }
69 end
68 end
70 end
69 end
71
70
72 def test_users_should_be_active_users
71 def test_users_should_be_active_users
73 Project.all.each do |project|
72 Project.all.each do |project|
74 assert_nil project.users.detect {|u| !(u.is_a?(User) && u.active?) }
73 assert_nil project.users.detect {|u| !(u.is_a?(User) && u.active?) }
75 end
74 end
76 end
75 end
77
76
78 def test_archive
77 def test_archive
79 user = @ecookbook.members.first.user
78 user = @ecookbook.members.first.user
80 @ecookbook.archive
79 @ecookbook.archive
81 @ecookbook.reload
80 @ecookbook.reload
82
81
83 assert !@ecookbook.active?
82 assert !@ecookbook.active?
84 assert !user.projects.include?(@ecookbook)
83 assert !user.projects.include?(@ecookbook)
85 # Subproject are also archived
84 # Subproject are also archived
86 assert !@ecookbook.children.empty?
85 assert !@ecookbook.children.empty?
87 assert @ecookbook.descendants.active.empty?
86 assert @ecookbook.descendants.active.empty?
88 end
87 end
89
88
90 def test_unarchive
89 def test_unarchive
91 user = @ecookbook.members.first.user
90 user = @ecookbook.members.first.user
92 @ecookbook.archive
91 @ecookbook.archive
93 # A subproject of an archived project can not be unarchived
92 # A subproject of an archived project can not be unarchived
94 assert !@ecookbook_sub1.unarchive
93 assert !@ecookbook_sub1.unarchive
95
94
96 # Unarchive project
95 # Unarchive project
97 assert @ecookbook.unarchive
96 assert @ecookbook.unarchive
98 @ecookbook.reload
97 @ecookbook.reload
99 assert @ecookbook.active?
98 assert @ecookbook.active?
100 assert user.projects.include?(@ecookbook)
99 assert user.projects.include?(@ecookbook)
101 # Subproject can now be unarchived
100 # Subproject can now be unarchived
102 @ecookbook_sub1.reload
101 @ecookbook_sub1.reload
103 assert @ecookbook_sub1.unarchive
102 assert @ecookbook_sub1.unarchive
104 end
103 end
105
104
106 def test_destroy
105 def test_destroy
107 # 2 active members
106 # 2 active members
108 assert_equal 2, @ecookbook.members.size
107 assert_equal 2, @ecookbook.members.size
109 # and 1 is locked
108 # and 1 is locked
110 assert_equal 3, Member.find(:all, :conditions => ['project_id = ?', @ecookbook.id]).size
109 assert_equal 3, Member.find(:all, :conditions => ['project_id = ?', @ecookbook.id]).size
111 # some boards
110 # some boards
112 assert @ecookbook.boards.any?
111 assert @ecookbook.boards.any?
113
112
114 @ecookbook.destroy
113 @ecookbook.destroy
115 # make sure that the project non longer exists
114 # make sure that the project non longer exists
116 assert_raise(ActiveRecord::RecordNotFound) { Project.find(@ecookbook.id) }
115 assert_raise(ActiveRecord::RecordNotFound) { Project.find(@ecookbook.id) }
117 # make sure related data was removed
116 # make sure related data was removed
118 assert Member.find(:all, :conditions => ['project_id = ?', @ecookbook.id]).empty?
117 assert Member.find(:all, :conditions => ['project_id = ?', @ecookbook.id]).empty?
119 assert Board.find(:all, :conditions => ['project_id = ?', @ecookbook.id]).empty?
118 assert Board.find(:all, :conditions => ['project_id = ?', @ecookbook.id]).empty?
120 end
119 end
121
120
122 def test_move_an_orphan_project_to_a_root_project
121 def test_move_an_orphan_project_to_a_root_project
123 sub = Project.find(2)
122 sub = Project.find(2)
124 sub.set_parent! @ecookbook
123 sub.set_parent! @ecookbook
125 assert_equal @ecookbook.id, sub.parent.id
124 assert_equal @ecookbook.id, sub.parent.id
126 @ecookbook.reload
125 @ecookbook.reload
127 assert_equal 4, @ecookbook.children.size
126 assert_equal 4, @ecookbook.children.size
128 end
127 end
129
128
130 def test_move_an_orphan_project_to_a_subproject
129 def test_move_an_orphan_project_to_a_subproject
131 sub = Project.find(2)
130 sub = Project.find(2)
132 assert sub.set_parent!(@ecookbook_sub1)
131 assert sub.set_parent!(@ecookbook_sub1)
133 end
132 end
134
133
135 def test_move_a_root_project_to_a_project
134 def test_move_a_root_project_to_a_project
136 sub = @ecookbook
135 sub = @ecookbook
137 assert sub.set_parent!(Project.find(2))
136 assert sub.set_parent!(Project.find(2))
138 end
137 end
139
138
140 def test_should_not_move_a_project_to_its_children
139 def test_should_not_move_a_project_to_its_children
141 sub = @ecookbook
140 sub = @ecookbook
142 assert !(sub.set_parent!(Project.find(3)))
141 assert !(sub.set_parent!(Project.find(3)))
143 end
142 end
144
143
145 def test_set_parent_should_add_roots_in_alphabetical_order
144 def test_set_parent_should_add_roots_in_alphabetical_order
146 ProjectCustomField.delete_all
145 ProjectCustomField.delete_all
147 Project.delete_all
146 Project.delete_all
148 Project.create!(:name => 'Project C', :identifier => 'project-c').set_parent!(nil)
147 Project.create!(:name => 'Project C', :identifier => 'project-c').set_parent!(nil)
149 Project.create!(:name => 'Project B', :identifier => 'project-b').set_parent!(nil)
148 Project.create!(:name => 'Project B', :identifier => 'project-b').set_parent!(nil)
150 Project.create!(:name => 'Project D', :identifier => 'project-d').set_parent!(nil)
149 Project.create!(:name => 'Project D', :identifier => 'project-d').set_parent!(nil)
151 Project.create!(:name => 'Project A', :identifier => 'project-a').set_parent!(nil)
150 Project.create!(:name => 'Project A', :identifier => 'project-a').set_parent!(nil)
152
151
153 assert_equal 4, Project.count
152 assert_equal 4, Project.count
154 assert_equal Project.all.sort_by(&:name), Project.all.sort_by(&:lft)
153 assert_equal Project.all.sort_by(&:name), Project.all.sort_by(&:lft)
155 end
154 end
156
155
157 def test_set_parent_should_add_children_in_alphabetical_order
156 def test_set_parent_should_add_children_in_alphabetical_order
158 ProjectCustomField.delete_all
157 ProjectCustomField.delete_all
159 parent = Project.create!(:name => 'Parent', :identifier => 'parent')
158 parent = Project.create!(:name => 'Parent', :identifier => 'parent')
160 Project.create!(:name => 'Project C', :identifier => 'project-c').set_parent!(parent)
159 Project.create!(:name => 'Project C', :identifier => 'project-c').set_parent!(parent)
161 Project.create!(:name => 'Project B', :identifier => 'project-b').set_parent!(parent)
160 Project.create!(:name => 'Project B', :identifier => 'project-b').set_parent!(parent)
162 Project.create!(:name => 'Project D', :identifier => 'project-d').set_parent!(parent)
161 Project.create!(:name => 'Project D', :identifier => 'project-d').set_parent!(parent)
163 Project.create!(:name => 'Project A', :identifier => 'project-a').set_parent!(parent)
162 Project.create!(:name => 'Project A', :identifier => 'project-a').set_parent!(parent)
164
163
165 parent.reload
164 parent.reload
166 assert_equal 4, parent.children.size
165 assert_equal 4, parent.children.size
167 assert_equal parent.children.sort_by(&:name), parent.children
166 assert_equal parent.children.sort_by(&:name), parent.children
168 end
167 end
169
168
170 def test_rebuild_should_sort_children_alphabetically
169 def test_rebuild_should_sort_children_alphabetically
171 ProjectCustomField.delete_all
170 ProjectCustomField.delete_all
172 parent = Project.create!(:name => 'Parent', :identifier => 'parent')
171 parent = Project.create!(:name => 'Parent', :identifier => 'parent')
173 Project.create!(:name => 'Project C', :identifier => 'project-c').move_to_child_of(parent)
172 Project.create!(:name => 'Project C', :identifier => 'project-c').move_to_child_of(parent)
174 Project.create!(:name => 'Project B', :identifier => 'project-b').move_to_child_of(parent)
173 Project.create!(:name => 'Project B', :identifier => 'project-b').move_to_child_of(parent)
175 Project.create!(:name => 'Project D', :identifier => 'project-d').move_to_child_of(parent)
174 Project.create!(:name => 'Project D', :identifier => 'project-d').move_to_child_of(parent)
176 Project.create!(:name => 'Project A', :identifier => 'project-a').move_to_child_of(parent)
175 Project.create!(:name => 'Project A', :identifier => 'project-a').move_to_child_of(parent)
177
176
178 Project.update_all("lft = NULL, rgt = NULL")
177 Project.update_all("lft = NULL, rgt = NULL")
179 Project.rebuild!
178 Project.rebuild!
180
179
181 parent.reload
180 parent.reload
182 assert_equal 4, parent.children.size
181 assert_equal 4, parent.children.size
183 assert_equal parent.children.sort_by(&:name), parent.children
182 assert_equal parent.children.sort_by(&:name), parent.children
184 end
183 end
185
184
186 def test_parent
185 def test_parent
187 p = Project.find(6).parent
186 p = Project.find(6).parent
188 assert p.is_a?(Project)
187 assert p.is_a?(Project)
189 assert_equal 5, p.id
188 assert_equal 5, p.id
190 end
189 end
191
190
192 def test_ancestors
191 def test_ancestors
193 a = Project.find(6).ancestors
192 a = Project.find(6).ancestors
194 assert a.first.is_a?(Project)
193 assert a.first.is_a?(Project)
195 assert_equal [1, 5], a.collect(&:id)
194 assert_equal [1, 5], a.collect(&:id)
196 end
195 end
197
196
198 def test_root
197 def test_root
199 r = Project.find(6).root
198 r = Project.find(6).root
200 assert r.is_a?(Project)
199 assert r.is_a?(Project)
201 assert_equal 1, r.id
200 assert_equal 1, r.id
202 end
201 end
203
202
204 def test_children
203 def test_children
205 c = Project.find(1).children
204 c = Project.find(1).children
206 assert c.first.is_a?(Project)
205 assert c.first.is_a?(Project)
207 assert_equal [5, 3, 4], c.collect(&:id)
206 assert_equal [5, 3, 4], c.collect(&:id)
208 end
207 end
209
208
210 def test_descendants
209 def test_descendants
211 d = Project.find(1).descendants
210 d = Project.find(1).descendants
212 assert d.first.is_a?(Project)
211 assert d.first.is_a?(Project)
213 assert_equal [5, 6, 3, 4], d.collect(&:id)
212 assert_equal [5, 6, 3, 4], d.collect(&:id)
214 end
213 end
215
214
216 def test_users_by_role
215 def test_users_by_role
217 users_by_role = Project.find(1).users_by_role
216 users_by_role = Project.find(1).users_by_role
218 assert_kind_of Hash, users_by_role
217 assert_kind_of Hash, users_by_role
219 role = Role.find(1)
218 role = Role.find(1)
220 assert_kind_of Array, users_by_role[role]
219 assert_kind_of Array, users_by_role[role]
221 assert users_by_role[role].include?(User.find(2))
220 assert users_by_role[role].include?(User.find(2))
222 end
221 end
223
222
224 def test_rolled_up_trackers
223 def test_rolled_up_trackers
225 parent = Project.find(1)
224 parent = Project.find(1)
226 parent.trackers = Tracker.find([1,2])
225 parent.trackers = Tracker.find([1,2])
227 child = parent.children.find(3)
226 child = parent.children.find(3)
228
227
229 assert_equal [1, 2], parent.tracker_ids
228 assert_equal [1, 2], parent.tracker_ids
230 assert_equal [2, 3], child.trackers.collect(&:id)
229 assert_equal [2, 3], child.trackers.collect(&:id)
231
230
232 assert_kind_of Tracker, parent.rolled_up_trackers.first
231 assert_kind_of Tracker, parent.rolled_up_trackers.first
233 assert_equal Tracker.find(1), parent.rolled_up_trackers.first
232 assert_equal Tracker.find(1), parent.rolled_up_trackers.first
234
233
235 assert_equal [1, 2, 3], parent.rolled_up_trackers.collect(&:id)
234 assert_equal [1, 2, 3], parent.rolled_up_trackers.collect(&:id)
236 assert_equal [2, 3], child.rolled_up_trackers.collect(&:id)
235 assert_equal [2, 3], child.rolled_up_trackers.collect(&:id)
237 end
236 end
238
237
239 def test_rolled_up_trackers_should_ignore_archived_subprojects
238 def test_rolled_up_trackers_should_ignore_archived_subprojects
240 parent = Project.find(1)
239 parent = Project.find(1)
241 parent.trackers = Tracker.find([1,2])
240 parent.trackers = Tracker.find([1,2])
242 child = parent.children.find(3)
241 child = parent.children.find(3)
243 child.trackers = Tracker.find([1,3])
242 child.trackers = Tracker.find([1,3])
244 parent.children.each(&:archive)
243 parent.children.each(&:archive)
245
244
246 assert_equal [1,2], parent.rolled_up_trackers.collect(&:id)
245 assert_equal [1,2], parent.rolled_up_trackers.collect(&:id)
247 end
246 end
248
247
249 def test_next_identifier
248 def test_next_identifier
250 ProjectCustomField.delete_all
249 ProjectCustomField.delete_all
251 Project.create!(:name => 'last', :identifier => 'p2008040')
250 Project.create!(:name => 'last', :identifier => 'p2008040')
252 assert_equal 'p2008041', Project.next_identifier
251 assert_equal 'p2008041', Project.next_identifier
253 end
252 end
254
253
255 def test_next_identifier_first_project
254 def test_next_identifier_first_project
256 Project.delete_all
255 Project.delete_all
257 assert_nil Project.next_identifier
256 assert_nil Project.next_identifier
258 end
257 end
259
258
260
259
261 def test_enabled_module_names_should_not_recreate_enabled_modules
260 def test_enabled_module_names_should_not_recreate_enabled_modules
262 project = Project.find(1)
261 project = Project.find(1)
263 # Remove one module
262 # Remove one module
264 modules = project.enabled_modules.slice(0..-2)
263 modules = project.enabled_modules.slice(0..-2)
265 assert modules.any?
264 assert modules.any?
266 assert_difference 'EnabledModule.count', -1 do
265 assert_difference 'EnabledModule.count', -1 do
267 project.enabled_module_names = modules.collect(&:name)
266 project.enabled_module_names = modules.collect(&:name)
268 end
267 end
269 project.reload
268 project.reload
270 # Ids should be preserved
269 # Ids should be preserved
271 assert_equal project.enabled_module_ids.sort, modules.collect(&:id).sort
270 assert_equal project.enabled_module_ids.sort, modules.collect(&:id).sort
272 end
271 end
273
272
274 def test_copy_from_existing_project
273 def test_copy_from_existing_project
275 source_project = Project.find(1)
274 source_project = Project.find(1)
276 copied_project = Project.copy_from(1)
275 copied_project = Project.copy_from(1)
277
276
278 assert copied_project
277 assert copied_project
279 # Cleared attributes
278 # Cleared attributes
280 assert copied_project.id.blank?
279 assert copied_project.id.blank?
281 assert copied_project.name.blank?
280 assert copied_project.name.blank?
282 assert copied_project.identifier.blank?
281 assert copied_project.identifier.blank?
283
282
284 # Duplicated attributes
283 # Duplicated attributes
285 assert_equal source_project.description, copied_project.description
284 assert_equal source_project.description, copied_project.description
286 assert_equal source_project.enabled_modules, copied_project.enabled_modules
285 assert_equal source_project.enabled_modules, copied_project.enabled_modules
287 assert_equal source_project.trackers, copied_project.trackers
286 assert_equal source_project.trackers, copied_project.trackers
288
287
289 # Default attributes
288 # Default attributes
290 assert_equal 1, copied_project.status
289 assert_equal 1, copied_project.status
291 end
290 end
292
291
293 context "Project#copy" do
292 context "Project#copy" do
294 setup do
293 setup do
295 ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests
294 ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests
296 Project.destroy_all :identifier => "copy-test"
295 Project.destroy_all :identifier => "copy-test"
297 @source_project = Project.find(2)
296 @source_project = Project.find(2)
298 @project = Project.new(:name => 'Copy Test', :identifier => 'copy-test')
297 @project = Project.new(:name => 'Copy Test', :identifier => 'copy-test')
299 @project.trackers = @source_project.trackers
298 @project.trackers = @source_project.trackers
300 @project.enabled_modules = @source_project.enabled_modules
299 @project.enabled_modules = @source_project.enabled_modules
301 end
300 end
302
301
303 should "copy issues" do
302 should "copy issues" do
304 assert @project.valid?
303 assert @project.valid?
305 assert @project.issues.empty?
304 assert @project.issues.empty?
306 assert @project.copy(@source_project)
305 assert @project.copy(@source_project)
307
306
308 assert_equal @source_project.issues.size, @project.issues.size
307 assert_equal @source_project.issues.size, @project.issues.size
309 @project.issues.each do |issue|
308 @project.issues.each do |issue|
310 assert issue.valid?
309 assert issue.valid?
311 assert ! issue.assigned_to.blank?
310 assert ! issue.assigned_to.blank?
312 assert_equal @project, issue.project
311 assert_equal @project, issue.project
313 end
312 end
314 end
313 end
315
314
316 should "change the new issues to use the copied version" do
315 should "change the new issues to use the copied version" do
317 assigned_version = Version.generate!(:name => "Assigned Issues")
316 assigned_version = Version.generate!(:name => "Assigned Issues")
318 @source_project.versions << assigned_version
317 @source_project.versions << assigned_version
319 assert_equal 1, @source_project.versions.size
318 assert_equal 1, @source_project.versions.size
320 @source_project.issues << Issue.generate!(:fixed_version_id => assigned_version.id,
319 @source_project.issues << Issue.generate!(:fixed_version_id => assigned_version.id,
321 :subject => "change the new issues to use the copied version",
320 :subject => "change the new issues to use the copied version",
322 :tracker_id => 1,
321 :tracker_id => 1,
323 :project_id => @source_project.id)
322 :project_id => @source_project.id)
324
323
325 assert @project.copy(@source_project)
324 assert @project.copy(@source_project)
326 @project.reload
325 @project.reload
327 copied_issue = @project.issues.first(:conditions => {:subject => "change the new issues to use the copied version"})
326 copied_issue = @project.issues.first(:conditions => {:subject => "change the new issues to use the copied version"})
328
327
329 assert copied_issue
328 assert copied_issue
330 assert copied_issue.fixed_version
329 assert copied_issue.fixed_version
331 assert_equal "Assigned Issues", copied_issue.fixed_version.name # Same name
330 assert_equal "Assigned Issues", copied_issue.fixed_version.name # Same name
332 assert_not_equal assigned_version.id, copied_issue.fixed_version.id # Different record
331 assert_not_equal assigned_version.id, copied_issue.fixed_version.id # Different record
333 end
332 end
334
333
335 should "copy members" do
334 should "copy members" do
336 assert @project.valid?
335 assert @project.valid?
337 assert @project.members.empty?
336 assert @project.members.empty?
338 assert @project.copy(@source_project)
337 assert @project.copy(@source_project)
339
338
340 assert_equal @source_project.members.size, @project.members.size
339 assert_equal @source_project.members.size, @project.members.size
341 @project.members.each do |member|
340 @project.members.each do |member|
342 assert member
341 assert member
343 assert_equal @project, member.project
342 assert_equal @project, member.project
344 end
343 end
345 end
344 end
346
345
347 should "copy project specific queries" do
346 should "copy project specific queries" do
348 assert @project.valid?
347 assert @project.valid?
349 assert @project.queries.empty?
348 assert @project.queries.empty?
350 assert @project.copy(@source_project)
349 assert @project.copy(@source_project)
351
350
352 assert_equal @source_project.queries.size, @project.queries.size
351 assert_equal @source_project.queries.size, @project.queries.size
353 @project.queries.each do |query|
352 @project.queries.each do |query|
354 assert query
353 assert query
355 assert_equal @project, query.project
354 assert_equal @project, query.project
356 end
355 end
357 end
356 end
358
357
359 should "copy versions" do
358 should "copy versions" do
360 @source_project.versions << Version.generate!
359 @source_project.versions << Version.generate!
361 @source_project.versions << Version.generate!
360 @source_project.versions << Version.generate!
362
361
363 assert @project.versions.empty?
362 assert @project.versions.empty?
364 assert @project.copy(@source_project)
363 assert @project.copy(@source_project)
365
364
366 assert_equal @source_project.versions.size, @project.versions.size
365 assert_equal @source_project.versions.size, @project.versions.size
367 @project.versions.each do |version|
366 @project.versions.each do |version|
368 assert version
367 assert version
369 assert_equal @project, version.project
368 assert_equal @project, version.project
370 end
369 end
371 end
370 end
372
371
373 should "copy wiki" do
372 should "copy wiki" do
374 assert @project.copy(@source_project)
373 assert @project.copy(@source_project)
375
374
376 assert @project.wiki
375 assert @project.wiki
377 assert_not_equal @source_project.wiki, @project.wiki
376 assert_not_equal @source_project.wiki, @project.wiki
378 assert_equal "Start page", @project.wiki.start_page
377 assert_equal "Start page", @project.wiki.start_page
379 end
378 end
380
379
381 should "copy wiki pages and content" do
380 should "copy wiki pages and content" do
382 assert @project.copy(@source_project)
381 assert @project.copy(@source_project)
383
382
384 assert @project.wiki
383 assert @project.wiki
385 assert_equal 1, @project.wiki.pages.length
384 assert_equal 1, @project.wiki.pages.length
386
385
387 @project.wiki.pages.each do |wiki_page|
386 @project.wiki.pages.each do |wiki_page|
388 assert wiki_page.content
387 assert wiki_page.content
389 assert !@source_project.wiki.pages.include?(wiki_page)
388 assert !@source_project.wiki.pages.include?(wiki_page)
390 end
389 end
391 end
390 end
392
391
393 should "copy custom fields"
392 should "copy custom fields"
394
393
395 should "copy issue categories" do
394 should "copy issue categories" do
396 assert @project.copy(@source_project)
395 assert @project.copy(@source_project)
397
396
398 assert_equal 2, @project.issue_categories.size
397 assert_equal 2, @project.issue_categories.size
399 @project.issue_categories.each do |issue_category|
398 @project.issue_categories.each do |issue_category|
400 assert !@source_project.issue_categories.include?(issue_category)
399 assert !@source_project.issue_categories.include?(issue_category)
401 end
400 end
402 end
401 end
403
402
404 should "change the new issues to use the copied issue categories" do
403 should "change the new issues to use the copied issue categories" do
405 issue = Issue.find(4)
404 issue = Issue.find(4)
406 issue.update_attribute(:category_id, 3)
405 issue.update_attribute(:category_id, 3)
407
406
408 assert @project.copy(@source_project)
407 assert @project.copy(@source_project)
409
408
410 @project.issues.each do |issue|
409 @project.issues.each do |issue|
411 assert issue.category
410 assert issue.category
412 assert_equal "Stock management", issue.category.name # Same name
411 assert_equal "Stock management", issue.category.name # Same name
413 assert_not_equal IssueCategory.find(3), issue.category # Different record
412 assert_not_equal IssueCategory.find(3), issue.category # Different record
414 end
413 end
415 end
414 end
416
415
417 should "copy issue relations"
416 should "copy issue relations"
418 should "link issue relations if cross project issue relations are valid"
417 should "link issue relations if cross project issue relations are valid"
419
418
420 end
419 end
421
420
422 end
421 end
General Comments 0
You need to be logged in to leave comments. Login now