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

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10611 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2012-10-12 08:39:22 +00:00
parent d8f039f489
commit 8bde60dc56
6 changed files with 44 additions and 65 deletions

View File

@ -61,6 +61,8 @@ module ObjectHelpers
def Issue.generate!(attributes={}) def Issue.generate!(attributes={})
issue = Issue.new(attributes) issue = Issue.new(attributes)
issue.project ||= Project.find(1)
issue.tracker ||= issue.project.trackers.first
issue.subject = 'Generated' if issue.subject.blank? issue.subject = 'Generated' if issue.subject.blank?
issue.author ||= User.find(2) issue.author ||= User.find(2)
yield issue if block_given? yield issue if block_given?
@ -68,25 +70,12 @@ module ObjectHelpers
issue issue
end 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 # Generates an issue with some children and a grandchild
def Issue.generate_with_descendants!(project, attributes={}) def Issue.generate_with_descendants!(project, attributes={})
issue = Issue.generate_for_project!(project, attributes) issue = Issue.generate!(attributes.merge(:project => project))
child = Issue.generate_for_project!(project, :subject => 'Child1', :parent_issue_id => issue.id) child = Issue.generate!(:project => project, :subject => 'Child1', :parent_issue_id => issue.id)
Issue.generate_for_project!(project, :subject => 'Child2', :parent_issue_id => issue.id) Issue.generate!(:project => project, :subject => 'Child2', :parent_issue_id => issue.id)
Issue.generate_for_project!(project, :subject => 'Child11', :parent_issue_id => child.id) Issue.generate!(:project => project, :subject => 'Child11', :parent_issue_id => child.id)
issue.reload issue.reload
end end

View File

@ -115,14 +115,14 @@ class IssueTest < ActiveSupport::TestCase
def test_anonymous_should_not_see_private_issues_with_issues_visibility_set_to_default def test_anonymous_should_not_see_private_issues_with_issues_visibility_set_to_default
assert Role.anonymous.update_attribute(:issues_visibility, '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_nil Issue.where(:id => issue.id).visible(User.anonymous).first
assert !issue.visible?(User.anonymous) assert !issue.visible?(User.anonymous)
end end
def test_anonymous_should_not_see_private_issues_with_issues_visibility_set_to_own def test_anonymous_should_not_see_private_issues_with_issues_visibility_set_to_own
assert Role.anonymous.update_attribute(:issues_visibility, '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_nil Issue.where(:id => issue.id).visible(User.anonymous).first
assert !issue.visible?(User.anonymous) assert !issue.visible?(User.anonymous)
end end
@ -720,10 +720,9 @@ class IssueTest < ActiveSupport::TestCase
def test_should_close_duplicates def test_should_close_duplicates
# Create 3 issues # Create 3 issues
project = Project.find(1) issue1 = Issue.generate!
issue1 = Issue.generate_for_project!(project) issue2 = Issue.generate!
issue2 = Issue.generate_for_project!(project) issue3 = Issue.generate!
issue3 = Issue.generate_for_project!(project)
# 2 is a dupe of 1 # 2 is a dupe of 1
IssueRelation.create!(:issue_from => issue2, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES) IssueRelation.create!(:issue_from => issue2, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES)
@ -744,9 +743,8 @@ class IssueTest < ActiveSupport::TestCase
end end
def test_should_not_close_duplicated_issue def test_should_not_close_duplicated_issue
project = Project.find(1) issue1 = Issue.generate!
issue1 = Issue.generate_for_project!(project) issue2 = Issue.generate!
issue2 = Issue.generate_for_project!(project)
# 2 is a dupe of 1 # 2 is a dupe of 1
IssueRelation.create(:issue_from => issue2, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES) IssueRelation.create(:issue_from => issue2, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES)
@ -1211,17 +1209,15 @@ class IssueTest < ActiveSupport::TestCase
end end
should "include the issue author" do should "include the issue author" do
project = Project.find(1)
non_project_member = User.generate! 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) assert issue.assignable_users.include?(non_project_member)
end end
should "include the current assignee" do should "include the current assignee" do
project = Project.find(1)
user = User.generate! user = User.generate!
issue = Issue.generate_for_project!(project, :assigned_to => user) issue = Issue.generate!(:assigned_to => user)
user.lock! user.lock!
assert Issue.find(issue.id).assignable_users.include?(user) assert Issue.find(issue.id).assignable_users.include?(user)
@ -1580,7 +1576,7 @@ class IssueTest < ActiveSupport::TestCase
before = Issue.on_active_project.length before = Issue.on_active_project.length
# test inclusion to results # 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 assert_equal before + 1, Issue.on_active_project.length
# Move to an archived project # Move to an archived project
@ -1594,7 +1590,7 @@ class IssueTest < ActiveSupport::TestCase
@project = Project.find(1) @project = Project.find(1)
@author = User.generate! @author = User.generate!
@assignee = 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 end
should "include project recipients" do should "include project recipients" do

View File

@ -67,7 +67,7 @@ class Redmine::Helpers::GanttHelperTest < ActionView::TestCase
should "not exceed max_rows option" do should "not exceed max_rows option" do
p = Project.generate! p = Project.generate!
5.times do 5.times do
Issue.generate_for_project!(p) Issue.generate!(:project => p)
end end
create_gantt(p) create_gantt(p)
@gantt.render @gantt.render
@ -90,14 +90,14 @@ class Redmine::Helpers::GanttHelperTest < ActionView::TestCase
end end
should "count the number of issues without a version" do 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) assert_equal 2, @gantt.number_of_rows_on_project(@project)
end end
should "count the number of issues on versions, including cross-project" do should "count the number of issues on versions, including cross-project" do
version = Version.generate! version = Version.generate!
@project.versions << version @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) assert_equal 3, @gantt.number_of_rows_on_project(@project)
end end
end end

View File

@ -828,11 +828,9 @@ class ProjectTest < ActiveSupport::TestCase
User.current = User.find(1) User.current = User.find(1)
assigned_version = Version.generate!(:name => "Assigned Issues") assigned_version = Version.generate!(:name => "Assigned Issues")
@source_project.versions << assigned_version @source_project.versions << assigned_version
Issue.generate_for_project!(@source_project, Issue.generate!(:project => @source_project,
:fixed_version_id => assigned_version.id, :fixed_version_id => assigned_version.id,
:subject => "copy issues assigned to a locked version", :subject => "copy issues assigned to a locked version")
:tracker_id => 1,
:project_id => @source_project.id)
assigned_version.update_attribute :status, 'locked' assigned_version.update_attribute :status, 'locked'
assert @project.copy(@source_project) assert @project.copy(@source_project)
@ -850,11 +848,9 @@ class ProjectTest < ActiveSupport::TestCase
assigned_version = Version.generate!(:name => "Assigned Issues", :status => 'open') assigned_version = Version.generate!(:name => "Assigned Issues", :status => 'open')
@source_project.versions << assigned_version @source_project.versions << assigned_version
assert_equal 3, @source_project.versions.size assert_equal 3, @source_project.versions.size
Issue.generate_for_project!(@source_project, Issue.generate!(:project => @source_project,
:fixed_version_id => assigned_version.id, :fixed_version_id => assigned_version.id,
:subject => "change the new issues to use the copied version", :subject => "change the new issues to use the copied version")
:tracker_id => 1,
:project_id => @source_project.id)
assert @project.copy(@source_project) assert @project.copy(@source_project)
@project.reload @project.reload
@ -868,11 +864,9 @@ class ProjectTest < ActiveSupport::TestCase
should "keep target shared versions from other project" do should "keep target shared versions from other project" do
assigned_version = Version.generate!(:name => "Assigned Issues", :status => 'open', :project_id => 1, :sharing => 'system') assigned_version = Version.generate!(:name => "Assigned Issues", :status => 'open', :project_id => 1, :sharing => 'system')
issue = Issue.generate_for_project!(@source_project, issue = Issue.generate!(:project => @source_project,
:fixed_version => assigned_version, :fixed_version => assigned_version,
:subject => "keep target shared versions", :subject => "keep target shared versions")
:tracker_id => 1,
:project_id => @source_project.id)
assert @project.copy(@source_project) assert @project.copy(@source_project)
@project.reload @project.reload
@ -1090,8 +1084,8 @@ class ProjectTest < ActiveSupport::TestCase
should "be the earliest start date of it's issues" do should "be the earliest start date of it's issues" do
early = 7.days.ago.to_date early = 7.days.ago.to_date
Issue.generate_for_project!(@project, :start_date => Date.today) Issue.generate!(:project => @project, :start_date => Date.today)
Issue.generate_for_project!(@project, :start_date => early) Issue.generate!(:project => @project, :start_date => early)
assert_equal early, @project.start_date assert_equal early, @project.start_date
end end
@ -1113,8 +1107,8 @@ class ProjectTest < ActiveSupport::TestCase
should "be the latest due date of it's issues" do should "be the latest due date of it's issues" do
future = 7.days.from_now.to_date future = 7.days.from_now.to_date
Issue.generate_for_project!(@project, :due_date => future) Issue.generate!(:project => @project, :due_date => future)
Issue.generate_for_project!(@project, :due_date => Date.today) Issue.generate!(:project => @project, :due_date => Date.today)
assert_equal future, @project.due_date assert_equal future, @project.due_date
end end
@ -1132,7 +1126,7 @@ class ProjectTest < ActiveSupport::TestCase
should "pick the latest date from it's issues and versions" do should "pick the latest date from it's issues and versions" do
future = 7.days.from_now.to_date future = 7.days.from_now.to_date
far_future = 14.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) @project.versions << Version.generate!(:effective_date => future)
assert_equal far_future, @project.due_date 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 should "return 100 if the version has only closed issues" do
v1 = Version.generate!(:project => @project) 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) 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 assert_equal 100, @project.completed_percent
end end
should "return the averaged completed percent of the versions (not weighted)" do should "return the averaged completed percent of the versions (not weighted)" do
v1 = Version.generate!(:project => @project) 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) 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 assert_equal 50, @project.completed_percent
end end

View File

@ -1149,11 +1149,11 @@ class QueryTest < ActiveSupport::TestCase
User.add_to_project(@developer, @project, @developer_role) User.add_to_project(@developer, @project, @developer_role)
User.add_to_project(@boss, @project, [@manager_role, @developer_role]) User.add_to_project(@boss, @project, [@manager_role, @developer_role])
@issue1 = Issue.generate_for_project!(@project, :assigned_to_id => @manager.id) @issue1 = Issue.generate!(:project => @project, :assigned_to_id => @manager.id)
@issue2 = Issue.generate_for_project!(@project, :assigned_to_id => @developer.id) @issue2 = Issue.generate!(:project => @project, :assigned_to_id => @developer.id)
@issue3 = Issue.generate_for_project!(@project, :assigned_to_id => @boss.id) @issue3 = Issue.generate!(:project => @project, :assigned_to_id => @boss.id)
@issue4 = Issue.generate_for_project!(@project, :assigned_to_id => @guest.id) @issue4 = Issue.generate!(:project => @project, :assigned_to_id => @guest.id)
@issue5 = Issue.generate_for_project!(@project) @issue5 = Issue.generate!(:project => @project)
end end
should "search assigned to for users with the Role" do should "search assigned to for users with the Role" do

View File

@ -948,7 +948,7 @@ class UserTest < ActiveSupport::TestCase
@project = Project.find(1) @project = Project.find(1)
@author = User.generate! @author = User.generate!
@assignee = 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 end
should "be true for a user with :all" do should "be true for a user with :all" do