summaryrefslogtreecommitdiffstats
path: root/test/unit/issue_nested_set_test.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2014-01-31 18:13:42 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2014-01-31 18:13:42 +0000
commitd651b93eff58c12b10b152aa95d2f9a875885c70 (patch)
tree408c5c7cc26d6958ba28f314e2b2caaf77f867f2 /test/unit/issue_nested_set_test.rb
parent888823a449d9694060a22c09d8d73b2f652e62bb (diff)
downloadredmine-d651b93eff58c12b10b152aa95d2f9a875885c70.tar.gz
redmine-d651b93eff58c12b10b152aa95d2f9a875885c70.zip
Adds some test helpers to cleanup tests.
git-svn-id: http://svn.redmine.org/redmine/trunk@12746 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/unit/issue_nested_set_test.rb')
-rw-r--r--test/unit/issue_nested_set_test.rb120
1 files changed, 58 insertions, 62 deletions
diff --git a/test/unit/issue_nested_set_test.rb b/test/unit/issue_nested_set_test.rb
index 4a41c49db..495d3b785 100644
--- a/test/unit/issue_nested_set_test.rb
+++ b/test/unit/issue_nested_set_test.rb
@@ -43,7 +43,7 @@ class IssueNestedSetTest < ActiveSupport::TestCase
def test_create_child_issue
lft = new_issue_lft
parent = Issue.generate!
- child = Issue.generate!(:parent_issue_id => parent.id)
+ child = parent.generate_child!
parent.reload
child.reload
assert_equal [parent.id, nil, lft, lft + 3], [parent.root_id, parent.parent_id, parent.lft, parent.rgt]
@@ -70,7 +70,7 @@ class IssueNestedSetTest < ActiveSupport::TestCase
lft = new_issue_lft
parent1 = Issue.generate!
parent2 = Issue.generate!
- child = Issue.generate!(:parent_issue_id => parent1.id)
+ child = parent1.generate_child!
parent2.parent_issue_id = parent1.id
parent2.save!
child.reload
@@ -86,7 +86,7 @@ class IssueNestedSetTest < ActiveSupport::TestCase
parent1 = Issue.generate!
lft2 = new_issue_lft
parent2 = Issue.generate!
- child = Issue.generate!(:parent_issue_id => parent1.id)
+ child = parent1.generate_child!
child.parent_issue_id = nil
child.save!
child.reload
@@ -102,7 +102,7 @@ class IssueNestedSetTest < ActiveSupport::TestCase
parent1 = Issue.generate!
lft2 = new_issue_lft
parent2 = Issue.generate!
- child = Issue.generate!(:parent_issue_id => parent1.id)
+ child = parent1.generate_child!
child.parent_issue_id = parent2.id
child.save!
child.reload
@@ -118,8 +118,8 @@ class IssueNestedSetTest < ActiveSupport::TestCase
parent1 = Issue.generate!
lft2 = new_issue_lft
parent2 = Issue.generate!
- child = Issue.generate!(:parent_issue_id => parent1.id)
- grandchild = Issue.generate!(:parent_issue_id => child.id)
+ child = parent1.generate_child!
+ grandchild = child.generate_child!
parent1.reload
parent2.reload
child.reload
@@ -143,8 +143,8 @@ class IssueNestedSetTest < ActiveSupport::TestCase
def test_move_a_child_with_descendants_to_another_project
lft1 = new_issue_lft
parent1 = Issue.generate!
- child = Issue.generate!(:parent_issue_id => parent1.id)
- grandchild = Issue.generate!(:parent_issue_id => child.id)
+ child = parent1.generate_child!
+ grandchild = child.generate_child!
child.reload
child.project = Project.find(2)
assert child.save
@@ -159,8 +159,8 @@ class IssueNestedSetTest < ActiveSupport::TestCase
def test_moving_an_issue_to_a_descendant_should_not_validate
parent1 = Issue.generate!
parent2 = Issue.generate!
- child = Issue.generate!(:parent_issue_id => parent1.id)
- grandchild = Issue.generate!(:parent_issue_id => child.id)
+ child = parent1.generate_child!
+ grandchild = child.generate_child!
child.reload
child.parent_issue_id = grandchild.id
@@ -207,8 +207,8 @@ class IssueNestedSetTest < ActiveSupport::TestCase
lft1 = new_issue_lft
issue1 = Issue.generate!
issue2 = Issue.generate!
- issue3 = Issue.generate!(:parent_issue_id => issue2.id)
- issue4 = Issue.generate!(:parent_issue_id => issue1.id)
+ issue3 = issue2.generate_child!
+ issue4 = issue1.generate_child!
issue3.init_journal(User.find(2))
issue3.subject = 'child with journal'
issue3.save!
@@ -230,8 +230,8 @@ class IssueNestedSetTest < ActiveSupport::TestCase
def test_destroy_child_should_update_parent
lft1 = new_issue_lft
issue = Issue.generate!
- child1 = Issue.generate!(:parent_issue_id => issue.id)
- child2 = Issue.generate!(:parent_issue_id => issue.id)
+ child1 = issue.generate_child!
+ child2 = issue.generate_child!
issue.reload
assert_equal [issue.id, lft1, lft1 + 5], [issue.root_id, issue.lft, issue.rgt]
child2.reload.destroy
@@ -241,8 +241,8 @@ class IssueNestedSetTest < ActiveSupport::TestCase
def test_destroy_parent_issue_updated_during_children_destroy
parent = Issue.generate!
- Issue.generate!(:start_date => Date.today, :parent_issue_id => parent.id)
- Issue.generate!(:start_date => 2.days.from_now, :parent_issue_id => parent.id)
+ parent.generate_child!(:start_date => Date.today)
+ parent.generate_child!(:start_date => 2.days.from_now)
assert_difference 'Issue.count', -3 do
Issue.find(parent.id).destroy
@@ -250,9 +250,9 @@ class IssueNestedSetTest < ActiveSupport::TestCase
end
def test_destroy_child_issue_with_children
- root = Issue.create!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'root')
- child = Issue.create!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => root.id)
- leaf = Issue.create!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'leaf', :parent_issue_id => child.id)
+ root = Issue.generate!
+ child = root.generate_child!
+ leaf = child.generate_child!
leaf.init_journal(User.find(2))
leaf.subject = 'leaf with journal'
leaf.save!
@@ -272,10 +272,10 @@ class IssueNestedSetTest < ActiveSupport::TestCase
def test_destroy_issue_with_grand_child
lft1 = new_issue_lft
parent = Issue.generate!
- issue = Issue.generate!(:parent_issue_id => parent.id)
- child = Issue.generate!(:parent_issue_id => issue.id)
- grandchild1 = Issue.generate!(:parent_issue_id => child.id)
- grandchild2 = Issue.generate!(:parent_issue_id => child.id)
+ issue = parent.generate_child!
+ child = issue.generate_child!
+ grandchild1 = child.generate_child!
+ grandchild2 = child.generate_child!
assert_difference 'Issue.count', -4 do
Issue.find(issue.id).destroy
parent.reload
@@ -286,12 +286,12 @@ class IssueNestedSetTest < ActiveSupport::TestCase
def test_parent_priority_should_be_the_highest_child_priority
parent = Issue.generate!(:priority => IssuePriority.find_by_name('Normal'))
# Create children
- child1 = Issue.generate!(:priority => IssuePriority.find_by_name('High'), :parent_issue_id => parent.id)
+ child1 = parent.generate_child!(:priority => IssuePriority.find_by_name('High'))
assert_equal 'High', parent.reload.priority.name
- child2 = Issue.generate!(:priority => IssuePriority.find_by_name('Immediate'), :parent_issue_id => child1.id)
+ child2 = child1.generate_child!(:priority => IssuePriority.find_by_name('Immediate'))
assert_equal 'Immediate', child1.reload.priority.name
assert_equal 'Immediate', parent.reload.priority.name
- child3 = Issue.generate!(:priority => IssuePriority.find_by_name('Low'), :parent_issue_id => parent.id)
+ child3 = parent.generate_child!(:priority => IssuePriority.find_by_name('Low'))
assert_equal 'Immediate', parent.reload.priority.name
# Destroy a child
child1.destroy
@@ -304,9 +304,9 @@ class IssueNestedSetTest < ActiveSupport::TestCase
def test_parent_dates_should_be_lowest_start_and_highest_due_dates
parent = Issue.generate!
- Issue.generate!(:start_date => '2010-01-25', :due_date => '2010-02-15', :parent_issue_id => parent.id)
- Issue.generate!( :due_date => '2010-02-13', :parent_issue_id => parent.id)
- Issue.generate!(:start_date => '2010-02-01', :due_date => '2010-02-22', :parent_issue_id => parent.id)
+ parent.generate_child!(:start_date => '2010-01-25', :due_date => '2010-02-15')
+ parent.generate_child!( :due_date => '2010-02-13')
+ parent.generate_child!(:start_date => '2010-02-01', :due_date => '2010-02-22')
parent.reload
assert_equal Date.parse('2010-01-25'), parent.start_date
assert_equal Date.parse('2010-02-22'), parent.due_date
@@ -314,76 +314,72 @@ class IssueNestedSetTest < ActiveSupport::TestCase
def test_parent_done_ratio_should_be_average_done_ratio_of_leaves
parent = Issue.generate!
- Issue.generate!(:done_ratio => 20, :parent_issue_id => parent.id)
+ parent.generate_child!(:done_ratio => 20)
assert_equal 20, parent.reload.done_ratio
- Issue.generate!(:done_ratio => 70, :parent_issue_id => parent.id)
+ parent.generate_child!(:done_ratio => 70)
assert_equal 45, parent.reload.done_ratio
- child = Issue.generate!(:done_ratio => 0, :parent_issue_id => parent.id)
+ child = parent.generate_child!(:done_ratio => 0)
assert_equal 30, parent.reload.done_ratio
- Issue.generate!(:done_ratio => 30, :parent_issue_id => child.id)
+ child.generate_child!(:done_ratio => 30)
assert_equal 30, child.reload.done_ratio
assert_equal 40, parent.reload.done_ratio
end
def test_parent_done_ratio_should_be_weighted_by_estimated_times_if_any
parent = Issue.generate!
- Issue.generate!(:estimated_hours => 10, :done_ratio => 20, :parent_issue_id => parent.id)
+ parent.generate_child!(:estimated_hours => 10, :done_ratio => 20)
assert_equal 20, parent.reload.done_ratio
- Issue.generate!(:estimated_hours => 20, :done_ratio => 50, :parent_issue_id => parent.id)
+ parent.generate_child!(:estimated_hours => 20, :done_ratio => 50)
assert_equal (50 * 20 + 20 * 10) / 30, parent.reload.done_ratio
end
def test_parent_done_ratio_with_child_estimate_to_0_should_reach_100
parent = Issue.generate!
- issue1 = Issue.generate!(:parent_issue_id => parent.id)
- issue2 = Issue.generate!(:parent_issue_id => parent.id, :estimated_hours => 0)
+ issue1 = parent.generate_child!
+ issue2 = parent.generate_child!(:estimated_hours => 0)
assert_equal 0, parent.reload.done_ratio
- issue1.reload.update_attribute :status_id, 5
+ issue1.reload.close!
assert_equal 50, parent.reload.done_ratio
- issue2.reload.update_attribute :status_id, 5
+ issue2.reload.close!
assert_equal 100, parent.reload.done_ratio
end
def test_parent_estimate_should_be_sum_of_leaves
parent = Issue.generate!
- Issue.generate!(:estimated_hours => nil, :parent_issue_id => parent.id)
+ parent.generate_child!(:estimated_hours => nil)
assert_equal nil, parent.reload.estimated_hours
- Issue.generate!(:estimated_hours => 5, :parent_issue_id => parent.id)
+ parent.generate_child!(:estimated_hours => 5)
assert_equal 5, parent.reload.estimated_hours
- Issue.generate!(:estimated_hours => 7, :parent_issue_id => parent.id)
+ parent.generate_child!(:estimated_hours => 7)
assert_equal 12, parent.reload.estimated_hours
end
def test_done_ratio_of_parent_with_a_child_without_estimated_time_should_not_exceed_100
parent = Issue.generate!
- Issue.generate!(:estimated_hours => 40, :parent_issue_id => parent.id)
- Issue.generate!(:estimated_hours => 40, :parent_issue_id => parent.id)
- Issue.generate!(:estimated_hours => 20, :parent_issue_id => parent.id)
- Issue.generate!(:parent_issue_id => parent.id)
- parent.reload.children.each do |child|
- child.update_attribute :status_id, 5
- end
+ parent.generate_child!(:estimated_hours => 40)
+ parent.generate_child!(:estimated_hours => 40)
+ parent.generate_child!(:estimated_hours => 20)
+ parent.generate_child!
+ parent.reload.children.each(&:close!)
assert_equal 100, parent.reload.done_ratio
end
def test_done_ratio_of_parent_with_a_child_with_estimated_time_at_0_should_not_exceed_100
parent = Issue.generate!
- Issue.generate!(:estimated_hours => 40, :parent_issue_id => parent.id)
- Issue.generate!(:estimated_hours => 40, :parent_issue_id => parent.id)
- Issue.generate!(:estimated_hours => 20, :parent_issue_id => parent.id)
- Issue.generate!(:estimated_hours => 0, :parent_issue_id => parent.id)
- parent.reload.children.each do |child|
- child.update_attribute :status_id, 5
- end
+ parent.generate_child!(:estimated_hours => 40)
+ parent.generate_child!(:estimated_hours => 40)
+ parent.generate_child!(:estimated_hours => 20)
+ parent.generate_child!(:estimated_hours => 0)
+ parent.reload.children.each(&:close!)
assert_equal 100, parent.reload.done_ratio
end
def test_move_parent_updates_old_parent_attributes
first_parent = Issue.generate!
second_parent = Issue.generate!
- child = Issue.generate!(:estimated_hours => 5, :parent_issue_id => first_parent.id)
+ child = first_parent.generate_child!(:estimated_hours => 5)
assert_equal 5, first_parent.reload.estimated_hours
child.update_attributes(:estimated_hours => 7, :parent_issue_id => second_parent.id)
assert_equal 7, second_parent.reload.estimated_hours
@@ -392,8 +388,8 @@ class IssueNestedSetTest < ActiveSupport::TestCase
def test_reschuling_a_parent_should_reschedule_subtasks
parent = Issue.generate!
- c1 = Issue.generate!(:start_date => '2010-05-12', :due_date => '2010-05-18', :parent_issue_id => parent.id)
- c2 = Issue.generate!(:start_date => '2010-06-03', :due_date => '2010-06-10', :parent_issue_id => parent.id)
+ c1 = parent.generate_child!(:start_date => '2010-05-12', :due_date => '2010-05-18')
+ c2 = parent.generate_child!(:start_date => '2010-06-03', :due_date => '2010-06-10')
parent.reload
parent.reschedule_on!(Date.parse('2010-06-02'))
c1.reload
@@ -407,9 +403,9 @@ class IssueNestedSetTest < ActiveSupport::TestCase
def test_project_copy_should_copy_issue_tree
p = Project.create!(:name => 'Tree copy', :identifier => 'tree-copy', :tracker_ids => [1, 2])
i1 = Issue.generate!(:project => p, :subject => 'i1')
- i2 = Issue.generate!(:project => p, :subject => 'i2', :parent_issue_id => i1.id)
- i3 = Issue.generate!(:project => p, :subject => 'i3', :parent_issue_id => i1.id)
- i4 = Issue.generate!(:project => p, :subject => 'i4', :parent_issue_id => i2.id)
+ i2 = i1.generate_child!(:project => p, :subject => 'i2')
+ i3 = i1.generate_child!(:project => p, :subject => 'i3')
+ i4 = i2.generate_child!(:project => p, :subject => 'i4')
i5 = Issue.generate!(:project => p, :subject => 'i5')
c = Project.new(:name => 'Copy', :identifier => 'copy', :tracker_ids => [1, 2])
c.copy(p, :only => 'issues')