@@ -61,6 +61,8 module ObjectHelpers | |||||
61 |
|
61 | |||
62 | def Issue.generate!(attributes={}) |
|
62 | def Issue.generate!(attributes={}) | |
63 | issue = Issue.new(attributes) |
|
63 | issue = Issue.new(attributes) | |
|
64 | issue.project ||= Project.find(1) | |||
|
65 | issue.tracker ||= issue.project.trackers.first | |||
64 | issue.subject = 'Generated' if issue.subject.blank? |
|
66 | issue.subject = 'Generated' if issue.subject.blank? | |
65 | issue.author ||= User.find(2) |
|
67 | issue.author ||= User.find(2) | |
66 | yield issue if block_given? |
|
68 | yield issue if block_given? | |
@@ -68,25 +70,12 module ObjectHelpers | |||||
68 | issue |
|
70 | issue | |
69 | end |
|
71 | end | |
70 |
|
72 | |||
71 | # Generate an issue for a project, using its trackers |
|
|||
72 | def Issue.generate_for_project!(project, attributes={}) |
|
|||
73 | issue = Issue.new(attributes) do |issue| |
|
|||
74 | issue.project = project |
|
|||
75 | issue.tracker = project.trackers.first unless project.trackers.empty? |
|
|||
76 | issue.subject = 'Generated' if issue.subject.blank? |
|
|||
77 | issue.author ||= User.find(2) |
|
|||
78 | yield issue if block_given? |
|
|||
79 | end |
|
|||
80 | issue.save! |
|
|||
81 | issue |
|
|||
82 | end |
|
|||
83 |
|
||||
84 | # Generates an issue with some children and a grandchild |
|
73 | # Generates an issue with some children and a grandchild | |
85 | def Issue.generate_with_descendants!(project, attributes={}) |
|
74 | def Issue.generate_with_descendants!(project, attributes={}) | |
86 |
issue = Issue.generate |
|
75 | issue = Issue.generate!(attributes.merge(:project => project)) | |
87 |
child = Issue.generate |
|
76 | child = Issue.generate!(:project => project, :subject => 'Child1', :parent_issue_id => issue.id) | |
88 |
Issue.generate |
|
77 | Issue.generate!(:project => project, :subject => 'Child2', :parent_issue_id => issue.id) | |
89 |
Issue.generate |
|
78 | Issue.generate!(:project => project, :subject => 'Child11', :parent_issue_id => child.id) | |
90 | issue.reload |
|
79 | issue.reload | |
91 | end |
|
80 | end | |
92 |
|
81 |
@@ -115,14 +115,14 class IssueTest < ActiveSupport::TestCase | |||||
115 |
|
115 | |||
116 | def test_anonymous_should_not_see_private_issues_with_issues_visibility_set_to_default |
|
116 | def test_anonymous_should_not_see_private_issues_with_issues_visibility_set_to_default | |
117 | assert Role.anonymous.update_attribute(:issues_visibility, 'default') |
|
117 | assert Role.anonymous.update_attribute(:issues_visibility, 'default') | |
118 |
issue = Issue.generate |
|
118 | issue = Issue.generate!(:author => User.anonymous, :assigned_to => User.anonymous, :is_private => true) | |
119 | assert_nil Issue.where(:id => issue.id).visible(User.anonymous).first |
|
119 | assert_nil Issue.where(:id => issue.id).visible(User.anonymous).first | |
120 | assert !issue.visible?(User.anonymous) |
|
120 | assert !issue.visible?(User.anonymous) | |
121 | end |
|
121 | end | |
122 |
|
122 | |||
123 | def test_anonymous_should_not_see_private_issues_with_issues_visibility_set_to_own |
|
123 | def test_anonymous_should_not_see_private_issues_with_issues_visibility_set_to_own | |
124 | assert Role.anonymous.update_attribute(:issues_visibility, 'own') |
|
124 | assert Role.anonymous.update_attribute(:issues_visibility, 'own') | |
125 |
issue = Issue.generate |
|
125 | issue = Issue.generate!(:author => User.anonymous, :assigned_to => User.anonymous, :is_private => true) | |
126 | assert_nil Issue.where(:id => issue.id).visible(User.anonymous).first |
|
126 | assert_nil Issue.where(:id => issue.id).visible(User.anonymous).first | |
127 | assert !issue.visible?(User.anonymous) |
|
127 | assert !issue.visible?(User.anonymous) | |
128 | end |
|
128 | end | |
@@ -720,10 +720,9 class IssueTest < ActiveSupport::TestCase | |||||
720 |
|
720 | |||
721 | def test_should_close_duplicates |
|
721 | def test_should_close_duplicates | |
722 | # Create 3 issues |
|
722 | # Create 3 issues | |
723 | project = Project.find(1) |
|
723 | issue1 = Issue.generate! | |
724 |
issue |
|
724 | issue2 = Issue.generate! | |
725 |
issue |
|
725 | issue3 = Issue.generate! | |
726 | issue3 = Issue.generate_for_project!(project) |
|
|||
727 |
|
726 | |||
728 | # 2 is a dupe of 1 |
|
727 | # 2 is a dupe of 1 | |
729 | IssueRelation.create!(:issue_from => issue2, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES) |
|
728 | IssueRelation.create!(:issue_from => issue2, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES) | |
@@ -744,9 +743,8 class IssueTest < ActiveSupport::TestCase | |||||
744 | end |
|
743 | end | |
745 |
|
744 | |||
746 | def test_should_not_close_duplicated_issue |
|
745 | def test_should_not_close_duplicated_issue | |
747 | project = Project.find(1) |
|
746 | issue1 = Issue.generate! | |
748 |
issue |
|
747 | issue2 = Issue.generate! | |
749 | issue2 = Issue.generate_for_project!(project) |
|
|||
750 |
|
748 | |||
751 | # 2 is a dupe of 1 |
|
749 | # 2 is a dupe of 1 | |
752 | IssueRelation.create(:issue_from => issue2, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES) |
|
750 | IssueRelation.create(:issue_from => issue2, :issue_to => issue1, :relation_type => IssueRelation::TYPE_DUPLICATES) | |
@@ -1211,17 +1209,15 class IssueTest < ActiveSupport::TestCase | |||||
1211 | end |
|
1209 | end | |
1212 |
|
1210 | |||
1213 | should "include the issue author" do |
|
1211 | should "include the issue author" do | |
1214 | project = Project.find(1) |
|
|||
1215 | non_project_member = User.generate! |
|
1212 | non_project_member = User.generate! | |
1216 |
issue = Issue.generate |
|
1213 | issue = Issue.generate!(:author => non_project_member) | |
1217 |
|
1214 | |||
1218 | assert issue.assignable_users.include?(non_project_member) |
|
1215 | assert issue.assignable_users.include?(non_project_member) | |
1219 | end |
|
1216 | end | |
1220 |
|
1217 | |||
1221 | should "include the current assignee" do |
|
1218 | should "include the current assignee" do | |
1222 | project = Project.find(1) |
|
|||
1223 | user = User.generate! |
|
1219 | user = User.generate! | |
1224 |
issue = Issue.generate |
|
1220 | issue = Issue.generate!(:assigned_to => user) | |
1225 | user.lock! |
|
1221 | user.lock! | |
1226 |
|
1222 | |||
1227 | assert Issue.find(issue.id).assignable_users.include?(user) |
|
1223 | assert Issue.find(issue.id).assignable_users.include?(user) | |
@@ -1580,7 +1576,7 class IssueTest < ActiveSupport::TestCase | |||||
1580 |
|
1576 | |||
1581 | before = Issue.on_active_project.length |
|
1577 | before = Issue.on_active_project.length | |
1582 | # test inclusion to results |
|
1578 | # test inclusion to results | |
1583 |
issue = Issue.generate |
|
1579 | issue = Issue.generate!(:tracker => Project.find(2).trackers.first) | |
1584 | assert_equal before + 1, Issue.on_active_project.length |
|
1580 | assert_equal before + 1, Issue.on_active_project.length | |
1585 |
|
1581 | |||
1586 | # Move to an archived project |
|
1582 | # Move to an archived project | |
@@ -1594,7 +1590,7 class IssueTest < ActiveSupport::TestCase | |||||
1594 | @project = Project.find(1) |
|
1590 | @project = Project.find(1) | |
1595 | @author = User.generate! |
|
1591 | @author = User.generate! | |
1596 | @assignee = User.generate! |
|
1592 | @assignee = User.generate! | |
1597 |
@issue = Issue.generate |
|
1593 | @issue = Issue.generate!(:project => @project, :assigned_to => @assignee, :author => @author) | |
1598 | end |
|
1594 | end | |
1599 |
|
1595 | |||
1600 | should "include project recipients" do |
|
1596 | should "include project recipients" do |
@@ -67,7 +67,7 class Redmine::Helpers::GanttHelperTest < ActionView::TestCase | |||||
67 | should "not exceed max_rows option" do |
|
67 | should "not exceed max_rows option" do | |
68 | p = Project.generate! |
|
68 | p = Project.generate! | |
69 | 5.times do |
|
69 | 5.times do | |
70 |
Issue.generate |
|
70 | Issue.generate!(:project => p) | |
71 | end |
|
71 | end | |
72 | create_gantt(p) |
|
72 | create_gantt(p) | |
73 | @gantt.render |
|
73 | @gantt.render | |
@@ -90,14 +90,14 class Redmine::Helpers::GanttHelperTest < ActionView::TestCase | |||||
90 | end |
|
90 | end | |
91 |
|
91 | |||
92 | should "count the number of issues without a version" do |
|
92 | should "count the number of issues without a version" do | |
93 |
@project.issues << Issue.generate |
|
93 | @project.issues << Issue.generate!(:project => @project, :fixed_version => nil) | |
94 | assert_equal 2, @gantt.number_of_rows_on_project(@project) |
|
94 | assert_equal 2, @gantt.number_of_rows_on_project(@project) | |
95 | end |
|
95 | end | |
96 |
|
96 | |||
97 | should "count the number of issues on versions, including cross-project" do |
|
97 | should "count the number of issues on versions, including cross-project" do | |
98 | version = Version.generate! |
|
98 | version = Version.generate! | |
99 | @project.versions << version |
|
99 | @project.versions << version | |
100 |
@project.issues << Issue.generate |
|
100 | @project.issues << Issue.generate!(:project => @project, :fixed_version => version) | |
101 | assert_equal 3, @gantt.number_of_rows_on_project(@project) |
|
101 | assert_equal 3, @gantt.number_of_rows_on_project(@project) | |
102 | end |
|
102 | end | |
103 | end |
|
103 | end |
@@ -828,11 +828,9 class ProjectTest < ActiveSupport::TestCase | |||||
828 | User.current = User.find(1) |
|
828 | User.current = User.find(1) | |
829 | assigned_version = Version.generate!(:name => "Assigned Issues") |
|
829 | assigned_version = Version.generate!(:name => "Assigned Issues") | |
830 | @source_project.versions << assigned_version |
|
830 | @source_project.versions << assigned_version | |
831 |
Issue.generate |
|
831 | Issue.generate!(:project => @source_project, | |
832 |
|
|
832 | :fixed_version_id => assigned_version.id, | |
833 |
|
|
833 | :subject => "copy issues assigned to a locked version") | |
834 | :tracker_id => 1, |
|
|||
835 | :project_id => @source_project.id) |
|
|||
836 | assigned_version.update_attribute :status, 'locked' |
|
834 | assigned_version.update_attribute :status, 'locked' | |
837 |
|
835 | |||
838 | assert @project.copy(@source_project) |
|
836 | assert @project.copy(@source_project) | |
@@ -850,11 +848,9 class ProjectTest < ActiveSupport::TestCase | |||||
850 | assigned_version = Version.generate!(:name => "Assigned Issues", :status => 'open') |
|
848 | assigned_version = Version.generate!(:name => "Assigned Issues", :status => 'open') | |
851 | @source_project.versions << assigned_version |
|
849 | @source_project.versions << assigned_version | |
852 | assert_equal 3, @source_project.versions.size |
|
850 | assert_equal 3, @source_project.versions.size | |
853 |
Issue.generate |
|
851 | Issue.generate!(:project => @source_project, | |
854 |
|
|
852 | :fixed_version_id => assigned_version.id, | |
855 |
|
|
853 | :subject => "change the new issues to use the copied version") | |
856 | :tracker_id => 1, |
|
|||
857 | :project_id => @source_project.id) |
|
|||
858 |
|
854 | |||
859 | assert @project.copy(@source_project) |
|
855 | assert @project.copy(@source_project) | |
860 | @project.reload |
|
856 | @project.reload | |
@@ -868,11 +864,9 class ProjectTest < ActiveSupport::TestCase | |||||
868 |
|
864 | |||
869 | should "keep target shared versions from other project" do |
|
865 | should "keep target shared versions from other project" do | |
870 | assigned_version = Version.generate!(:name => "Assigned Issues", :status => 'open', :project_id => 1, :sharing => 'system') |
|
866 | assigned_version = Version.generate!(:name => "Assigned Issues", :status => 'open', :project_id => 1, :sharing => 'system') | |
871 |
issue = Issue.generate |
|
867 | issue = Issue.generate!(:project => @source_project, | |
872 |
|
|
868 | :fixed_version => assigned_version, | |
873 |
|
|
869 | :subject => "keep target shared versions") | |
874 | :tracker_id => 1, |
|
|||
875 | :project_id => @source_project.id) |
|
|||
876 |
|
870 | |||
877 | assert @project.copy(@source_project) |
|
871 | assert @project.copy(@source_project) | |
878 | @project.reload |
|
872 | @project.reload | |
@@ -1090,8 +1084,8 class ProjectTest < ActiveSupport::TestCase | |||||
1090 |
|
1084 | |||
1091 | should "be the earliest start date of it's issues" do |
|
1085 | should "be the earliest start date of it's issues" do | |
1092 | early = 7.days.ago.to_date |
|
1086 | early = 7.days.ago.to_date | |
1093 |
Issue.generate |
|
1087 | Issue.generate!(:project => @project, :start_date => Date.today) | |
1094 |
Issue.generate |
|
1088 | Issue.generate!(:project => @project, :start_date => early) | |
1095 |
|
1089 | |||
1096 | assert_equal early, @project.start_date |
|
1090 | assert_equal early, @project.start_date | |
1097 | end |
|
1091 | end | |
@@ -1113,8 +1107,8 class ProjectTest < ActiveSupport::TestCase | |||||
1113 |
|
1107 | |||
1114 | should "be the latest due date of it's issues" do |
|
1108 | should "be the latest due date of it's issues" do | |
1115 | future = 7.days.from_now.to_date |
|
1109 | future = 7.days.from_now.to_date | |
1116 |
Issue.generate |
|
1110 | Issue.generate!(:project => @project, :due_date => future) | |
1117 |
Issue.generate |
|
1111 | Issue.generate!(:project => @project, :due_date => Date.today) | |
1118 |
|
1112 | |||
1119 | assert_equal future, @project.due_date |
|
1113 | assert_equal future, @project.due_date | |
1120 | end |
|
1114 | end | |
@@ -1132,7 +1126,7 class ProjectTest < ActiveSupport::TestCase | |||||
1132 | should "pick the latest date from it's issues and versions" do |
|
1126 | should "pick the latest date from it's issues and versions" do | |
1133 | future = 7.days.from_now.to_date |
|
1127 | future = 7.days.from_now.to_date | |
1134 | far_future = 14.days.from_now.to_date |
|
1128 | far_future = 14.days.from_now.to_date | |
1135 |
Issue.generate |
|
1129 | Issue.generate!(:project => @project, :due_date => far_future) | |
1136 | @project.versions << Version.generate!(:effective_date => future) |
|
1130 | @project.versions << Version.generate!(:effective_date => future) | |
1137 |
|
1131 | |||
1138 | assert_equal far_future, @project.due_date |
|
1132 | assert_equal far_future, @project.due_date | |
@@ -1163,18 +1157,18 class ProjectTest < ActiveSupport::TestCase | |||||
1163 |
|
1157 | |||
1164 | should "return 100 if the version has only closed issues" do |
|
1158 | should "return 100 if the version has only closed issues" do | |
1165 | v1 = Version.generate!(:project => @project) |
|
1159 | v1 = Version.generate!(:project => @project) | |
1166 |
Issue.generate |
|
1160 | Issue.generate!(:project => @project, :status => IssueStatus.find_by_name('Closed'), :fixed_version => v1) | |
1167 | v2 = Version.generate!(:project => @project) |
|
1161 | v2 = Version.generate!(:project => @project) | |
1168 |
Issue.generate |
|
1162 | Issue.generate!(:project => @project, :status => IssueStatus.find_by_name('Closed'), :fixed_version => v2) | |
1169 |
|
1163 | |||
1170 | assert_equal 100, @project.completed_percent |
|
1164 | assert_equal 100, @project.completed_percent | |
1171 | end |
|
1165 | end | |
1172 |
|
1166 | |||
1173 | should "return the averaged completed percent of the versions (not weighted)" do |
|
1167 | should "return the averaged completed percent of the versions (not weighted)" do | |
1174 | v1 = Version.generate!(:project => @project) |
|
1168 | v1 = Version.generate!(:project => @project) | |
1175 |
Issue.generate |
|
1169 | Issue.generate!(:project => @project, :status => IssueStatus.find_by_name('New'), :estimated_hours => 10, :done_ratio => 50, :fixed_version => v1) | |
1176 | v2 = Version.generate!(:project => @project) |
|
1170 | v2 = Version.generate!(:project => @project) | |
1177 |
Issue.generate |
|
1171 | Issue.generate!(:project => @project, :status => IssueStatus.find_by_name('New'), :estimated_hours => 10, :done_ratio => 50, :fixed_version => v2) | |
1178 |
|
1172 | |||
1179 | assert_equal 50, @project.completed_percent |
|
1173 | assert_equal 50, @project.completed_percent | |
1180 | end |
|
1174 | end |
@@ -1149,11 +1149,11 class QueryTest < ActiveSupport::TestCase | |||||
1149 | User.add_to_project(@developer, @project, @developer_role) |
|
1149 | User.add_to_project(@developer, @project, @developer_role) | |
1150 | User.add_to_project(@boss, @project, [@manager_role, @developer_role]) |
|
1150 | User.add_to_project(@boss, @project, [@manager_role, @developer_role]) | |
1151 |
|
1151 | |||
1152 |
@issue1 = Issue.generate |
|
1152 | @issue1 = Issue.generate!(:project => @project, :assigned_to_id => @manager.id) | |
1153 |
@issue2 = Issue.generate |
|
1153 | @issue2 = Issue.generate!(:project => @project, :assigned_to_id => @developer.id) | |
1154 |
@issue3 = Issue.generate |
|
1154 | @issue3 = Issue.generate!(:project => @project, :assigned_to_id => @boss.id) | |
1155 |
@issue4 = Issue.generate |
|
1155 | @issue4 = Issue.generate!(:project => @project, :assigned_to_id => @guest.id) | |
1156 |
@issue5 = Issue.generate |
|
1156 | @issue5 = Issue.generate!(:project => @project) | |
1157 | end |
|
1157 | end | |
1158 |
|
1158 | |||
1159 | should "search assigned to for users with the Role" do |
|
1159 | should "search assigned to for users with the Role" do |
@@ -948,7 +948,7 class UserTest < ActiveSupport::TestCase | |||||
948 | @project = Project.find(1) |
|
948 | @project = Project.find(1) | |
949 | @author = User.generate! |
|
949 | @author = User.generate! | |
950 | @assignee = User.generate! |
|
950 | @assignee = User.generate! | |
951 |
@issue = Issue.generate |
|
951 | @issue = Issue.generate!(:project => @project, :assigned_to => @assignee, :author => @author) | |
952 | end |
|
952 | end | |
953 |
|
953 | |||
954 | should "be true for a user with :all" do |
|
954 | should "be true for a user with :all" do |
General Comments 0
You need to be logged in to leave comments.
Login now