@@ -0,0 +1,10 | |||||
|
1 | class Version < ActiveRecord::Base | |||
|
2 | generator_for :name, :method => :next_name | |||
|
3 | ||||
|
4 | def self.next_name | |||
|
5 | @last_name ||= 'Version 1.0.0' | |||
|
6 | @last_name.succ! | |||
|
7 | @last_name | |||
|
8 | end | |||
|
9 | ||||
|
10 | end |
@@ -348,10 +348,44 class Project < ActiveRecord::Base | |||||
348 | project = project.is_a?(Project) ? project : Project.find(project) |
|
348 | project = project.is_a?(Project) ? project : Project.find(project) | |
349 |
|
349 | |||
350 | Project.transaction do |
|
350 | Project.transaction do | |
|
351 | # Wikis | |||
|
352 | self.wiki = Wiki.new(project.wiki.attributes.dup.except("project_id")) | |||
|
353 | project.wiki.pages.each do |page| | |||
|
354 | new_wiki_content = WikiContent.new(page.content.attributes.dup.except("page_id")) | |||
|
355 | new_wiki_page = WikiPage.new(page.attributes.dup.except("wiki_id")) | |||
|
356 | new_wiki_page.content = new_wiki_content | |||
|
357 | ||||
|
358 | self.wiki.pages << new_wiki_page | |||
|
359 | end | |||
|
360 | ||||
|
361 | # Versions | |||
|
362 | project.versions.each do |version| | |||
|
363 | new_version = Version.new | |||
|
364 | new_version.attributes = version.attributes.dup.except("project_id") | |||
|
365 | self.versions << new_version | |||
|
366 | end | |||
|
367 | ||||
|
368 | project.issue_categories.each do |issue_category| | |||
|
369 | new_issue_category = IssueCategory.new | |||
|
370 | new_issue_category.attributes = issue_category.attributes.dup.except("project_id") | |||
|
371 | self.issue_categories << new_issue_category | |||
|
372 | end | |||
|
373 | ||||
351 | # Issues |
|
374 | # Issues | |
352 | project.issues.each do |issue| |
|
375 | project.issues.each do |issue| | |
353 | new_issue = Issue.new |
|
376 | new_issue = Issue.new | |
354 | new_issue.copy_from(issue) |
|
377 | new_issue.copy_from(issue) | |
|
378 | # Reassign fixed_versions by name, since names are unique per | |||
|
379 | # project and the versions for self are not yet saved | |||
|
380 | if issue.fixed_version | |||
|
381 | new_issue.fixed_version = self.versions.select {|v| v.name == issue.fixed_version.name}.first | |||
|
382 | end | |||
|
383 | # Reassign the category by name, since names are unique per | |||
|
384 | # project and the categories for self are not yet saved | |||
|
385 | if issue.category | |||
|
386 | new_issue.category = self.issue_categories.select {|c| c.name == issue.category.name}.first | |||
|
387 | end | |||
|
388 | ||||
355 | self.issues << new_issue |
|
389 | self.issues << new_issue | |
356 | end |
|
390 | end | |
357 |
|
391 |
@@ -1,4 +1,4 | |||||
1 |
class User < |
|
1 | class User < Principal | |
2 | generator_for :login, :method => :next_email |
|
2 | generator_for :login, :method => :next_email | |
3 | generator_for :mail, :method => :next_email |
|
3 | generator_for :mail, :method => :next_email | |
4 | generator_for :firstname, :method => :next_firstname |
|
4 | generator_for :firstname, :method => :next_firstname |
@@ -21,6 +21,19 require 'test_help' | |||||
21 | require File.expand_path(File.dirname(__FILE__) + '/helper_testcase') |
|
21 | require File.expand_path(File.dirname(__FILE__) + '/helper_testcase') | |
22 | require File.join(RAILS_ROOT,'test', 'mocks', 'open_id_authentication_mock.rb') |
|
22 | require File.join(RAILS_ROOT,'test', 'mocks', 'open_id_authentication_mock.rb') | |
23 |
|
23 | |||
|
24 | # TODO: The gem or official version of ObjectDaddy doesn't set | |||
|
25 | # protected attributes so they need to be wrapped. | |||
|
26 | def User.generate_with_protected!(attributes={}) | |||
|
27 | user = User.spawn(attributes) do |user| | |||
|
28 | user.login = User.next_login | |||
|
29 | attributes.each do |attr,v| | |||
|
30 | user.send("#{attr}=", v) | |||
|
31 | end | |||
|
32 | end | |||
|
33 | user.save! | |||
|
34 | user | |||
|
35 | end | |||
|
36 | ||||
24 | class ActiveSupport::TestCase |
|
37 | class ActiveSupport::TestCase | |
25 | # Transactional fixtures accelerate your tests by wrapping each test method |
|
38 | # Transactional fixtures accelerate your tests by wrapping each test method | |
26 | # in a transaction that's rolled back on completion. This ensures that the |
|
39 | # in a transaction that's rolled back on completion. This ensures that the |
@@ -290,7 +290,7 class ProjectTest < ActiveSupport::TestCase | |||||
290 | assert_equal 1, copied_project.status |
|
290 | assert_equal 1, copied_project.status | |
291 | end |
|
291 | end | |
292 |
|
292 | |||
293 | context "#copy" do |
|
293 | context "Project#copy" do | |
294 | setup do |
|
294 | setup do | |
295 | ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests |
|
295 | ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests | |
296 | Project.destroy_all :identifier => "copy-test" |
|
296 | Project.destroy_all :identifier => "copy-test" | |
@@ -313,6 +313,25 class ProjectTest < ActiveSupport::TestCase | |||||
313 | end |
|
313 | end | |
314 | end |
|
314 | end | |
315 |
|
315 | |||
|
316 | should "change the new issues to use the copied version" do | |||
|
317 | assigned_version = Version.generate!(:name => "Assigned Issues") | |||
|
318 | @source_project.versions << assigned_version | |||
|
319 | assert_equal 1, @source_project.versions.size | |||
|
320 | @source_project.issues << Issue.generate!(:fixed_version_id => assigned_version.id, | |||
|
321 | :subject => "change the new issues to use the copied version", | |||
|
322 | :tracker_id => 1, | |||
|
323 | :project_id => @source_project.id) | |||
|
324 | ||||
|
325 | assert @project.copy(@source_project) | |||
|
326 | @project.reload | |||
|
327 | copied_issue = @project.issues.first(:conditions => {:subject => "change the new issues to use the copied version"}) | |||
|
328 | ||||
|
329 | assert copied_issue | |||
|
330 | assert copied_issue.fixed_version | |||
|
331 | 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 | |||
|
333 | end | |||
|
334 | ||||
316 | should "copy members" do |
|
335 | should "copy members" do | |
317 | assert @project.valid? |
|
336 | assert @project.valid? | |
318 | assert @project.members.empty? |
|
337 | assert @project.members.empty? | |
@@ -337,6 +356,67 class ProjectTest < ActiveSupport::TestCase | |||||
337 | end |
|
356 | end | |
338 | end |
|
357 | end | |
339 |
|
358 | |||
|
359 | should "copy versions" do | |||
|
360 | @source_project.versions << Version.generate! | |||
|
361 | @source_project.versions << Version.generate! | |||
|
362 | ||||
|
363 | assert @project.versions.empty? | |||
|
364 | assert @project.copy(@source_project) | |||
|
365 | ||||
|
366 | assert_equal @source_project.versions.size, @project.versions.size | |||
|
367 | @project.versions.each do |version| | |||
|
368 | assert version | |||
|
369 | assert_equal @project, version.project | |||
|
370 | end | |||
|
371 | end | |||
|
372 | ||||
|
373 | should "copy wiki" do | |||
|
374 | assert @project.copy(@source_project) | |||
|
375 | ||||
|
376 | assert @project.wiki | |||
|
377 | assert_not_equal @source_project.wiki, @project.wiki | |||
|
378 | assert_equal "Start page", @project.wiki.start_page | |||
|
379 | end | |||
|
380 | ||||
|
381 | should "copy wiki pages and content" do | |||
|
382 | assert @project.copy(@source_project) | |||
|
383 | ||||
|
384 | assert @project.wiki | |||
|
385 | assert_equal 1, @project.wiki.pages.length | |||
|
386 | ||||
|
387 | @project.wiki.pages.each do |wiki_page| | |||
|
388 | assert wiki_page.content | |||
|
389 | assert !@source_project.wiki.pages.include?(wiki_page) | |||
|
390 | end | |||
|
391 | end | |||
|
392 | ||||
|
393 | should "copy custom fields" | |||
|
394 | ||||
|
395 | should "copy issue categories" do | |||
|
396 | assert @project.copy(@source_project) | |||
|
397 | ||||
|
398 | assert_equal 2, @project.issue_categories.size | |||
|
399 | @project.issue_categories.each do |issue_category| | |||
|
400 | assert !@source_project.issue_categories.include?(issue_category) | |||
|
401 | end | |||
|
402 | end | |||
|
403 | ||||
|
404 | should "change the new issues to use the copied issue categories" do | |||
|
405 | issue = Issue.find(4) | |||
|
406 | issue.update_attribute(:category_id, 3) | |||
|
407 | ||||
|
408 | assert @project.copy(@source_project) | |||
|
409 | ||||
|
410 | @project.issues.each do |issue| | |||
|
411 | assert issue.category | |||
|
412 | assert_equal "Stock management", issue.category.name # Same name | |||
|
413 | assert_not_equal IssueCategory.find(3), issue.category # Different record | |||
|
414 | end | |||
|
415 | end | |||
|
416 | ||||
|
417 | should "copy issue relations" | |||
|
418 | should "link issue relations if cross project issue relations are valid" | |||
|
419 | ||||
340 | end |
|
420 | end | |
341 |
|
421 | |||
342 | end |
|
422 | end |
General Comments 0
You need to be logged in to leave comments.
Login now