Commit ad52b48a authored by jplang's avatar jplang

Remove Issue.generate_for_project! test helper and use Issue.generate! instead.

git-svn-id: https://svn.redmine.org/redmine/trunk@10611 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent edbf802d
......@@ -61,6 +61,8 @@ module ObjectHelpers
def Issue.generate!(attributes={})
issue = Issue.new(attributes)
issue.project ||= Project.find(1)
issue.tracker ||= issue.project.trackers.first
issue.subject = 'Generated' if issue.subject.blank?
issue.author ||= User.find(2)
yield issue if block_given?
......@@ -68,25 +70,12 @@ module ObjectHelpers
issue
end
# Generate an issue for a project, using its trackers
def Issue.generate_for_project!(project, attributes={})
issue = Issue.new(attributes) do |issue|
issue.project = project
issue.tracker = project.trackers.first unless project.trackers.empty?
issue.subject = 'Generated' if issue.subject.blank?
issue.author ||= User.find(2)
yield issue if block_given?
end
issue.save!
issue
end
# Generates an issue with some children and a grandchild
def Issue.generate_with_descendants!(project, attributes={})
issue = Issue.generate_for_project!(project, attributes)
child = Issue.generate_for_project!(project, :subject => 'Child1', :parent_issue_id => issue.id)
Issue.generate_for_project!(project, :subject => 'Child2', :parent_issue_id => issue.id)
Issue.generate_for_project!(project, :subject => 'Child11', :parent_issue_id => child.id)
issue = Issue.generate!(attributes.merge(:project => project))
child = Issue.generate!(:project => project, :subject => 'Child1', :parent_issue_id => issue.id)
Issue.generate!(:project => project, :subject => 'Child2', :parent_issue_id => issue.id)
Issue.generate!(:project => project, :subject => 'Child11', :parent_issue_id => child.id)
issue.reload
end
......
......@@ -115,14 +115,14 @@ class IssueTest < ActiveSupport::TestCase
def test_anonymous_should_not_see_private_issues_with_issues_visibility_set_to_default
assert Role.anonymous.update_attribute(:issues_visibility, 'default')
issue = Issue.generate_for_project!(Project.find(1), :author => User.anonymous, :assigned_to => User.anonymous, :is_private => true)
issue = Issue.generate!(:author => User.anonymous, :assigned_to => User.anonymous, :is_private => true)
assert_nil Issue.where(:id => issue.id).visible(User.anonymous).first
assert !issue.visible?(User.anonymous)
end
def test_anonymous_should_not_see_private_issues_with_issues_visibility_set_to_own
assert Role.anonymous.update_attribute(:issues_visibility, 'own')
issue = Issue.generate_for_project!(Project.find(1), :author => User.anonymous, :assigned_to => User.anonymous, :is_private => true)
issue = Issue.generate!(:author => User.anonymous, :assigned_to => User.anonymous, :is_private => true)
assert_nil Issue.where(:id => issue.id).visible(User.anonymous).first
assert !issue.visible?(User.anonymous)
end
......@@ -720,10 +720,9 @@ class IssueTest < ActiveSupport::TestCase
def test_should_close_duplicates
# Create 3 issues
project = Project.find(1)
issue1 = Issue.generate_for_project!(project)
issue2 = Issue.generate_for_project!(project)
issue3 = Issue.generate_for_project!(project)
issue1 = Issue.generate!
issue2 = Issue.generate!
issue3 = Issue.generate!
# 2 is a dupe of 1
IssueRelation.create!(:issue_from => issue2, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES)
......@@ -744,9 +743,8 @@ class IssueTest < ActiveSupport::TestCase
end
def test_should_not_close_duplicated_issue
project = Project.find(1)
issue1 = Issue.generate_for_project!(project)
issue2 = Issue.generate_for_project!(project)
issue1 = Issue.generate!
issue2 = Issue.generate!
# 2 is a dupe of 1
IssueRelation.create(:issue_from => issue2, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES)
......@@ -1211,17 +1209,15 @@ class IssueTest < ActiveSupport::TestCase
end
should "include the issue author" do
project = Project.find(1)
non_project_member = User.generate!
issue = Issue.generate_for_project!(project, :author => non_project_member)
issue = Issue.generate!(:author => non_project_member)
assert issue.assignable_users.include?(non_project_member)
end
should "include the current assignee" do
project = Project.find(1)
user = User.generate!
issue = Issue.generate_for_project!(project, :assigned_to => user)
issue = Issue.generate!(:assigned_to => user)
user.lock!
assert Issue.find(issue.id).assignable_users.include?(user)
......@@ -1580,7 +1576,7 @@ class IssueTest < ActiveSupport::TestCase
before = Issue.on_active_project.length
# test inclusion to results
issue = Issue.generate_for_project!(Project.find(1), :tracker => Project.find(2).trackers.first)
issue = Issue.generate!(:tracker => Project.find(2).trackers.first)
assert_equal before + 1, Issue.on_active_project.length
# Move to an archived project
......@@ -1594,7 +1590,7 @@ class IssueTest < ActiveSupport::TestCase
@project = Project.find(1)
@author = User.generate!
@assignee = User.generate!
@issue = Issue.generate_for_project!(@project, :assigned_to => @assignee, :author => @author)
@issue = Issue.generate!(:project => @project, :assigned_to => @assignee, :author => @author)
end
should "include project recipients" do
......
......@@ -67,7 +67,7 @@ class Redmine::Helpers::GanttHelperTest < ActionView::TestCase
should "not exceed max_rows option" do
p = Project.generate!
5.times do
Issue.generate_for_project!(p)
Issue.generate!(:project => p)
end
create_gantt(p)
@gantt.render
......@@ -90,14 +90,14 @@ class Redmine::Helpers::GanttHelperTest < ActionView::TestCase
end
should "count the number of issues without a version" do
@project.issues << Issue.generate_for_project!(@project, :fixed_version => nil)
@project.issues << Issue.generate!(:project => @project, :fixed_version => nil)
assert_equal 2, @gantt.number_of_rows_on_project(@project)
end
should "count the number of issues on versions, including cross-project" do
version = Version.generate!
@project.versions << version
@project.issues << Issue.generate_for_project!(@project, :fixed_version => version)
@project.issues << Issue.generate!(:project => @project, :fixed_version => version)
assert_equal 3, @gantt.number_of_rows_on_project(@project)
end
end
......
......@@ -828,11 +828,9 @@ class ProjectTest < ActiveSupport::TestCase
User.current = User.find(1)
assigned_version = Version.generate!(:name => "Assigned Issues")
@source_project.versions << assigned_version
Issue.generate_for_project!(@source_project,
:fixed_version_id => assigned_version.id,
:subject => "copy issues assigned to a locked version",
:tracker_id => 1,
:project_id => @source_project.id)
Issue.generate!(:project => @source_project,
:fixed_version_id => assigned_version.id,
:subject => "copy issues assigned to a locked version")
assigned_version.update_attribute :status, 'locked'
assert @project.copy(@source_project)
......@@ -850,11 +848,9 @@ class ProjectTest < ActiveSupport::TestCase
assigned_version = Version.generate!(:name => "Assigned Issues", :status => 'open')
@source_project.versions << assigned_version
assert_equal 3, @source_project.versions.size
Issue.generate_for_project!(@source_project,
:fixed_version_id => assigned_version.id,
:subject => "change the new issues to use the copied version",
:tracker_id => 1,
:project_id => @source_project.id)
Issue.generate!(:project => @source_project,
:fixed_version_id => assigned_version.id,
:subject => "change the new issues to use the copied version")
assert @project.copy(@source_project)
@project.reload
......@@ -868,11 +864,9 @@ class ProjectTest < ActiveSupport::TestCase
should "keep target shared versions from other project" do
assigned_version = Version.generate!(:name => "Assigned Issues", :status => 'open', :project_id => 1, :sharing => 'system')
issue = Issue.generate_for_project!(@source_project,
:fixed_version => assigned_version,
:subject => "keep target shared versions",
:tracker_id => 1,
:project_id => @source_project.id)
issue = Issue.generate!(:project => @source_project,
:fixed_version => assigned_version,
:subject => "keep target shared versions")
assert @project.copy(@source_project)
@project.reload
......@@ -1090,8 +1084,8 @@ class ProjectTest < ActiveSupport::TestCase
should "be the earliest start date of it's issues" do
early = 7.days.ago.to_date
Issue.generate_for_project!(@project, :start_date => Date.today)
Issue.generate_for_project!(@project, :start_date => early)
Issue.generate!(:project => @project, :start_date => Date.today)
Issue.generate!(:project => @project, :start_date => early)
assert_equal early, @project.start_date
end
......@@ -1113,8 +1107,8 @@ class ProjectTest < ActiveSupport::TestCase
should "be the latest due date of it's issues" do
future = 7.days.from_now.to_date
Issue.generate_for_project!(@project, :due_date => future)
Issue.generate_for_project!(@project, :due_date => Date.today)
Issue.generate!(:project => @project, :due_date => future)
Issue.generate!(:project => @project, :due_date => Date.today)
assert_equal future, @project.due_date
end
......@@ -1132,7 +1126,7 @@ class ProjectTest < ActiveSupport::TestCase
should "pick the latest date from it's issues and versions" do
future = 7.days.from_now.to_date
far_future = 14.days.from_now.to_date
Issue.generate_for_project!(@project, :due_date => far_future)
Issue.generate!(:project => @project, :due_date => far_future)
@project.versions << Version.generate!(:effective_date => future)
assert_equal far_future, @project.due_date
......@@ -1163,18 +1157,18 @@ class ProjectTest < ActiveSupport::TestCase
should "return 100 if the version has only closed issues" do
v1 = Version.generate!(:project => @project)
Issue.generate_for_project!(@project, :status => IssueStatus.find_by_name('Closed'), :fixed_version => v1)
Issue.generate!(:project => @project, :status => IssueStatus.find_by_name('Closed'), :fixed_version => v1)
v2 = Version.generate!(:project => @project)
Issue.generate_for_project!(@project, :status => IssueStatus.find_by_name('Closed'), :fixed_version => v2)
Issue.generate!(:project => @project, :status => IssueStatus.find_by_name('Closed'), :fixed_version => v2)
assert_equal 100, @project.completed_percent
end
should "return the averaged completed percent of the versions (not weighted)" do
v1 = Version.generate!(:project => @project)
Issue.generate_for_project!(@project, :status => IssueStatus.find_by_name('New'), :estimated_hours => 10, :done_ratio => 50, :fixed_version => v1)
Issue.generate!(:project => @project, :status => IssueStatus.find_by_name('New'), :estimated_hours => 10, :done_ratio => 50, :fixed_version => v1)
v2 = Version.generate!(:project => @project)
Issue.generate_for_project!(@project, :status => IssueStatus.find_by_name('New'), :estimated_hours => 10, :done_ratio => 50, :fixed_version => v2)
Issue.generate!(:project => @project, :status => IssueStatus.find_by_name('New'), :estimated_hours => 10, :done_ratio => 50, :fixed_version => v2)
assert_equal 50, @project.completed_percent
end
......
......@@ -1149,11 +1149,11 @@ class QueryTest < ActiveSupport::TestCase
User.add_to_project(@developer, @project, @developer_role)
User.add_to_project(@boss, @project, [@manager_role, @developer_role])
@issue1 = Issue.generate_for_project!(@project, :assigned_to_id => @manager.id)
@issue2 = Issue.generate_for_project!(@project, :assigned_to_id => @developer.id)
@issue3 = Issue.generate_for_project!(@project, :assigned_to_id => @boss.id)
@issue4 = Issue.generate_for_project!(@project, :assigned_to_id => @guest.id)
@issue5 = Issue.generate_for_project!(@project)
@issue1 = Issue.generate!(:project => @project, :assigned_to_id => @manager.id)
@issue2 = Issue.generate!(:project => @project, :assigned_to_id => @developer.id)
@issue3 = Issue.generate!(:project => @project, :assigned_to_id => @boss.id)
@issue4 = Issue.generate!(:project => @project, :assigned_to_id => @guest.id)
@issue5 = Issue.generate!(:project => @project)
end
should "search assigned to for users with the Role" do
......
......@@ -948,7 +948,7 @@ class UserTest < ActiveSupport::TestCase
@project = Project.find(1)
@author = User.generate!
@assignee = User.generate!
@issue = Issue.generate_for_project!(@project, :assigned_to => @assignee, :author => @author)
@issue = Issue.generate!(:project => @project, :assigned_to => @assignee, :author => @author)
end
should "be true for a user with :all" do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment