Removed issue_create! helper in favour of Issue.generate!

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10613 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2012-10-12 09:02:25 +00:00
parent 51818cbbb6
commit 92391abd1e
2 changed files with 79 additions and 89 deletions

View File

@ -28,8 +28,8 @@ class IssueNestedSetTest < ActiveSupport::TestCase
:time_entries
def test_create_root_issue
issue1 = create_issue!
issue2 = create_issue!
issue1 = Issue.generate!
issue2 = Issue.generate!
issue1.reload
issue2.reload
@ -38,8 +38,8 @@ class IssueNestedSetTest < ActiveSupport::TestCase
end
def test_create_child_issue
parent = create_issue!
child = create_issue!(:parent_issue_id => parent.id)
parent = Issue.generate!
child = Issue.generate!(:parent_issue_id => parent.id)
parent.reload
child.reload
@ -48,7 +48,7 @@ class IssueNestedSetTest < ActiveSupport::TestCase
end
def test_creating_a_child_in_a_subproject_should_validate
issue = create_issue!
issue = Issue.generate!
child = Issue.new(:project_id => 3, :tracker_id => 2, :author_id => 1,
:subject => 'child', :parent_issue_id => issue.id)
assert_save child
@ -56,7 +56,7 @@ class IssueNestedSetTest < ActiveSupport::TestCase
end
def test_creating_a_child_in_an_invalid_project_should_not_validate
issue = create_issue!
issue = Issue.generate!
child = Issue.new(:project_id => 2, :tracker_id => 1, :author_id => 1,
:subject => 'child', :parent_issue_id => issue.id)
assert !child.save
@ -64,9 +64,9 @@ class IssueNestedSetTest < ActiveSupport::TestCase
end
def test_move_a_root_to_child
parent1 = create_issue!
parent2 = create_issue!
child = create_issue!(:parent_issue_id => parent1.id)
parent1 = Issue.generate!
parent2 = Issue.generate!
child = Issue.generate!(:parent_issue_id => parent1.id)
parent2.parent_issue_id = parent1.id
parent2.save!
@ -80,9 +80,9 @@ class IssueNestedSetTest < ActiveSupport::TestCase
end
def test_move_a_child_to_root
parent1 = create_issue!
parent2 = create_issue!
child = create_issue!(:parent_issue_id => parent1.id)
parent1 = Issue.generate!
parent2 = Issue.generate!
child = Issue.generate!(:parent_issue_id => parent1.id)
child.parent_issue_id = nil
child.save!
@ -96,9 +96,9 @@ class IssueNestedSetTest < ActiveSupport::TestCase
end
def test_move_a_child_to_another_issue
parent1 = create_issue!
parent2 = create_issue!
child = create_issue!(:parent_issue_id => parent1.id)
parent1 = Issue.generate!
parent2 = Issue.generate!
child = Issue.generate!(:parent_issue_id => parent1.id)
child.parent_issue_id = parent2.id
child.save!
@ -112,10 +112,10 @@ class IssueNestedSetTest < ActiveSupport::TestCase
end
def test_move_a_child_with_descendants_to_another_issue
parent1 = create_issue!
parent2 = create_issue!
child = create_issue!(:parent_issue_id => parent1.id)
grandchild = create_issue!(:parent_issue_id => child.id)
parent1 = Issue.generate!
parent2 = Issue.generate!
child = Issue.generate!(:parent_issue_id => parent1.id)
grandchild = Issue.generate!(:parent_issue_id => child.id)
parent1.reload
parent2.reload
@ -141,9 +141,9 @@ class IssueNestedSetTest < ActiveSupport::TestCase
end
def test_move_a_child_with_descendants_to_another_project
parent1 = create_issue!
child = create_issue!(:parent_issue_id => parent1.id)
grandchild = create_issue!(:parent_issue_id => child.id)
parent1 = Issue.generate!
child = Issue.generate!(:parent_issue_id => parent1.id)
grandchild = Issue.generate!(:parent_issue_id => child.id)
child.reload
child.project = Project.find(2)
@ -158,10 +158,10 @@ class IssueNestedSetTest < ActiveSupport::TestCase
end
def test_moving_an_issue_to_a_descendant_should_not_validate
parent1 = create_issue!
parent2 = create_issue!
child = create_issue!(:parent_issue_id => parent1.id)
grandchild = create_issue!(:parent_issue_id => child.id)
parent1 = Issue.generate!
parent2 = Issue.generate!
child = Issue.generate!(:parent_issue_id => parent1.id)
grandchild = Issue.generate!(:parent_issue_id => child.id)
child.reload
child.parent_issue_id = grandchild.id
@ -170,10 +170,10 @@ class IssueNestedSetTest < ActiveSupport::TestCase
end
def test_moving_an_issue_should_keep_valid_relations_only
issue1 = create_issue!
issue2 = create_issue!
issue3 = create_issue!(:parent_issue_id => issue2.id)
issue4 = create_issue!
issue1 = Issue.generate!
issue2 = Issue.generate!
issue3 = Issue.generate!(:parent_issue_id => issue2.id)
issue4 = Issue.generate!
r1 = IssueRelation.create!(:issue_from => issue1, :issue_to => issue2, :relation_type => IssueRelation::TYPE_PRECEDES)
r2 = IssueRelation.create!(:issue_from => issue1, :issue_to => issue3, :relation_type => IssueRelation::TYPE_PRECEDES)
r3 = IssueRelation.create!(:issue_from => issue2, :issue_to => issue4, :relation_type => IssueRelation::TYPE_PRECEDES)
@ -186,10 +186,10 @@ class IssueNestedSetTest < ActiveSupport::TestCase
end
def test_destroy_should_destroy_children
issue1 = create_issue!
issue2 = create_issue!
issue3 = create_issue!(:parent_issue_id => issue2.id)
issue4 = create_issue!(:parent_issue_id => issue1.id)
issue1 = Issue.generate!
issue2 = Issue.generate!
issue3 = Issue.generate!(:parent_issue_id => issue2.id)
issue4 = Issue.generate!(:parent_issue_id => issue1.id)
issue3.init_journal(User.find(2))
issue3.subject = 'child with journal'
@ -212,9 +212,9 @@ class IssueNestedSetTest < ActiveSupport::TestCase
end
def test_destroy_child_should_update_parent
issue = create_issue!
child1 = create_issue!(:parent_issue_id => issue.id)
child2 = create_issue!(:parent_issue_id => issue.id)
issue = Issue.generate!
child1 = Issue.generate!(:parent_issue_id => issue.id)
child2 = Issue.generate!(:parent_issue_id => issue.id)
issue.reload
assert_equal [issue.id, 1, 6], [issue.root_id, issue.lft, issue.rgt]
@ -226,9 +226,9 @@ class IssueNestedSetTest < ActiveSupport::TestCase
end
def test_destroy_parent_issue_updated_during_children_destroy
parent = create_issue!
create_issue!(:start_date => Date.today, :parent_issue_id => parent.id)
create_issue!(:start_date => 2.days.from_now, :parent_issue_id => parent.id)
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)
assert_difference 'Issue.count', -3 do
Issue.find(parent.id).destroy
@ -256,11 +256,11 @@ class IssueNestedSetTest < ActiveSupport::TestCase
end
def test_destroy_issue_with_grand_child
parent = create_issue!
issue = create_issue!(:parent_issue_id => parent.id)
child = create_issue!(:parent_issue_id => issue.id)
grandchild1 = create_issue!(:parent_issue_id => child.id)
grandchild2 = create_issue!(:parent_issue_id => child.id)
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)
assert_difference 'Issue.count', -4 do
Issue.find(issue.id).destroy
@ -270,14 +270,14 @@ class IssueNestedSetTest < ActiveSupport::TestCase
end
def test_parent_priority_should_be_the_highest_child_priority
parent = create_issue!(:priority => IssuePriority.find_by_name('Normal'))
parent = Issue.generate!(:priority => IssuePriority.find_by_name('Normal'))
# Create children
child1 = create_issue!(:priority => IssuePriority.find_by_name('High'), :parent_issue_id => parent.id)
child1 = Issue.generate!(:priority => IssuePriority.find_by_name('High'), :parent_issue_id => parent.id)
assert_equal 'High', parent.reload.priority.name
child2 = create_issue!(:priority => IssuePriority.find_by_name('Immediate'), :parent_issue_id => child1.id)
child2 = Issue.generate!(:priority => IssuePriority.find_by_name('Immediate'), :parent_issue_id => child1.id)
assert_equal 'Immediate', child1.reload.priority.name
assert_equal 'Immediate', parent.reload.priority.name
child3 = create_issue!(:priority => IssuePriority.find_by_name('Low'), :parent_issue_id => parent.id)
child3 = Issue.generate!(:priority => IssuePriority.find_by_name('Low'), :parent_issue_id => parent.id)
assert_equal 'Immediate', parent.reload.priority.name
# Destroy a child
child1.destroy
@ -289,52 +289,52 @@ class IssueNestedSetTest < ActiveSupport::TestCase
end
def test_parent_dates_should_be_lowest_start_and_highest_due_dates
parent = create_issue!
create_issue!(:start_date => '2010-01-25', :due_date => '2010-02-15', :parent_issue_id => parent.id)
create_issue!( :due_date => '2010-02-13', :parent_issue_id => parent.id)
create_issue!(:start_date => '2010-02-01', :due_date => '2010-02-22', :parent_issue_id => parent.id)
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.reload
assert_equal Date.parse('2010-01-25'), parent.start_date
assert_equal Date.parse('2010-02-22'), parent.due_date
end
def test_parent_done_ratio_should_be_average_done_ratio_of_leaves
parent = create_issue!
create_issue!(:done_ratio => 20, :parent_issue_id => parent.id)
parent = Issue.generate!
Issue.generate!(:done_ratio => 20, :parent_issue_id => parent.id)
assert_equal 20, parent.reload.done_ratio
create_issue!(:done_ratio => 70, :parent_issue_id => parent.id)
Issue.generate!(:done_ratio => 70, :parent_issue_id => parent.id)
assert_equal 45, parent.reload.done_ratio
child = create_issue!(:done_ratio => 0, :parent_issue_id => parent.id)
child = Issue.generate!(:done_ratio => 0, :parent_issue_id => parent.id)
assert_equal 30, parent.reload.done_ratio
create_issue!(:done_ratio => 30, :parent_issue_id => child.id)
Issue.generate!(:done_ratio => 30, :parent_issue_id => child.id)
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 = create_issue!
create_issue!(:estimated_hours => 10, :done_ratio => 20, :parent_issue_id => parent.id)
parent = Issue.generate!
Issue.generate!(:estimated_hours => 10, :done_ratio => 20, :parent_issue_id => parent.id)
assert_equal 20, parent.reload.done_ratio
create_issue!(:estimated_hours => 20, :done_ratio => 50, :parent_issue_id => parent.id)
Issue.generate!(:estimated_hours => 20, :done_ratio => 50, :parent_issue_id => parent.id)
assert_equal (50 * 20 + 20 * 10) / 30, parent.reload.done_ratio
end
def test_parent_estimate_should_be_sum_of_leaves
parent = create_issue!
create_issue!(:estimated_hours => nil, :parent_issue_id => parent.id)
parent = Issue.generate!
Issue.generate!(:estimated_hours => nil, :parent_issue_id => parent.id)
assert_equal nil, parent.reload.estimated_hours
create_issue!(:estimated_hours => 5, :parent_issue_id => parent.id)
Issue.generate!(:estimated_hours => 5, :parent_issue_id => parent.id)
assert_equal 5, parent.reload.estimated_hours
create_issue!(:estimated_hours => 7, :parent_issue_id => parent.id)
Issue.generate!(:estimated_hours => 7, :parent_issue_id => parent.id)
assert_equal 12, parent.reload.estimated_hours
end
def test_move_parent_updates_old_parent_attributes
first_parent = create_issue!
second_parent = create_issue!
child = create_issue!(:estimated_hours => 5, :parent_issue_id => first_parent.id)
first_parent = Issue.generate!
second_parent = Issue.generate!
child = Issue.generate!(:estimated_hours => 5, :parent_issue_id => first_parent.id)
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
@ -342,9 +342,9 @@ class IssueNestedSetTest < ActiveSupport::TestCase
end
def test_reschuling_a_parent_should_reschedule_subtasks
parent = create_issue!
c1 = create_issue!(:start_date => '2010-05-12', :due_date => '2010-05-18', :parent_issue_id => parent.id)
c2 = create_issue!(:start_date => '2010-06-03', :due_date => '2010-06-10', :parent_issue_id => parent.id)
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)
parent.reload
parent.reschedule_after(Date.parse('2010-06-02'))
c1.reload
@ -357,11 +357,11 @@ 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 = create_issue!(:project_id => p.id, :subject => 'i1')
i2 = create_issue!(:project_id => p.id, :subject => 'i2', :parent_issue_id => i1.id)
i3 = create_issue!(:project_id => p.id, :subject => 'i3', :parent_issue_id => i1.id)
i4 = create_issue!(:project_id => p.id, :subject => 'i4', :parent_issue_id => i2.id)
i5 = create_issue!(:project_id => p.id, :subject => 'i5')
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)
i5 = Issue.generate!(:project => p, :subject => 'i5')
c = Project.new(:name => 'Copy', :identifier => 'copy', :tracker_ids => [1, 2])
c.copy(p, :only => 'issues')
c.reload
@ -374,9 +374,4 @@ class IssueNestedSetTest < ActiveSupport::TestCase
assert_equal ic2, ic4.parent
assert ic5.root?
end
# Helper that creates an issue with default attributes
def create_issue!(attributes={})
Issue.create!({:project_id => 1, :tracker_id => 1, :author_id => 1, :subject => 'test'}.merge(attributes))
end
end

View File

@ -30,9 +30,9 @@ class IssueTransactionTest < ActiveSupport::TestCase
self.use_transactional_fixtures = false
def test_invalid_move_to_another_project
parent1 = create_issue!
child = create_issue!(:parent_issue_id => parent1.id)
grandchild = create_issue!(:parent_issue_id => child.id, :tracker_id => 2)
parent1 = Issue.generate!
child = Issue.generate!(:parent_issue_id => parent1.id)
grandchild = Issue.generate!(:parent_issue_id => child.id, :tracker_id => 2)
Project.find(2).tracker_ids = [1]
parent1.reload
@ -51,9 +51,4 @@ class IssueTransactionTest < ActiveSupport::TestCase
assert_equal [1, parent1.id, 2, 5], [child.project_id, child.root_id, child.lft, child.rgt]
assert_equal [1, parent1.id, 3, 4], [grandchild.project_id, grandchild.root_id, grandchild.lft, grandchild.rgt]
end
# Helper that creates an issue with default attributes
def create_issue!(attributes={})
Issue.create!({:project_id => 1, :tracker_id => 1, :author_id => 1, :subject => 'test'}.merge(attributes))
end
end