@@ -1,1136 +1,1147 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | require File.expand_path('../../test_helper', __FILE__) |
|
18 | require File.expand_path('../../test_helper', __FILE__) | |
19 |
|
19 | |||
20 | class ProjectTest < ActiveSupport::TestCase |
|
20 | class ProjectTest < ActiveSupport::TestCase | |
21 | fixtures :all |
|
21 | fixtures :projects, :trackers, :issue_statuses, :issues, | |
|
22 | :enumerations, :users, :issue_categories, | |||
|
23 | :projects_trackers, | |||
|
24 | :roles, | |||
|
25 | :member_roles, | |||
|
26 | :members, | |||
|
27 | :enabled_modules, | |||
|
28 | :workflows, | |||
|
29 | :versions, | |||
|
30 | :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions, | |||
|
31 | :groups_users, | |||
|
32 | :boards | |||
22 |
|
33 | |||
23 | def setup |
|
34 | def setup | |
24 | @ecookbook = Project.find(1) |
|
35 | @ecookbook = Project.find(1) | |
25 | @ecookbook_sub1 = Project.find(3) |
|
36 | @ecookbook_sub1 = Project.find(3) | |
26 | User.current = nil |
|
37 | User.current = nil | |
27 | end |
|
38 | end | |
28 |
|
39 | |||
29 | should_validate_presence_of :name |
|
40 | should_validate_presence_of :name | |
30 | should_validate_presence_of :identifier |
|
41 | should_validate_presence_of :identifier | |
31 |
|
42 | |||
32 | should_validate_uniqueness_of :identifier |
|
43 | should_validate_uniqueness_of :identifier | |
33 |
|
44 | |||
34 | context "associations" do |
|
45 | context "associations" do | |
35 | should_have_many :members |
|
46 | should_have_many :members | |
36 | should_have_many :users, :through => :members |
|
47 | should_have_many :users, :through => :members | |
37 | should_have_many :member_principals |
|
48 | should_have_many :member_principals | |
38 | should_have_many :principals, :through => :member_principals |
|
49 | should_have_many :principals, :through => :member_principals | |
39 | should_have_many :enabled_modules |
|
50 | should_have_many :enabled_modules | |
40 | should_have_many :issues |
|
51 | should_have_many :issues | |
41 | should_have_many :issue_changes, :through => :issues |
|
52 | should_have_many :issue_changes, :through => :issues | |
42 | should_have_many :versions |
|
53 | should_have_many :versions | |
43 | should_have_many :time_entries |
|
54 | should_have_many :time_entries | |
44 | should_have_many :queries |
|
55 | should_have_many :queries | |
45 | should_have_many :documents |
|
56 | should_have_many :documents | |
46 | should_have_many :news |
|
57 | should_have_many :news | |
47 | should_have_many :issue_categories |
|
58 | should_have_many :issue_categories | |
48 | should_have_many :boards |
|
59 | should_have_many :boards | |
49 | should_have_many :changesets, :through => :repository |
|
60 | should_have_many :changesets, :through => :repository | |
50 |
|
61 | |||
51 | should_have_one :repository |
|
62 | should_have_one :repository | |
52 | should_have_one :wiki |
|
63 | should_have_one :wiki | |
53 |
|
64 | |||
54 | should_have_and_belong_to_many :trackers |
|
65 | should_have_and_belong_to_many :trackers | |
55 | should_have_and_belong_to_many :issue_custom_fields |
|
66 | should_have_and_belong_to_many :issue_custom_fields | |
56 | end |
|
67 | end | |
57 |
|
68 | |||
58 | def test_truth |
|
69 | def test_truth | |
59 | assert_kind_of Project, @ecookbook |
|
70 | assert_kind_of Project, @ecookbook | |
60 | assert_equal "eCookbook", @ecookbook.name |
|
71 | assert_equal "eCookbook", @ecookbook.name | |
61 | end |
|
72 | end | |
62 |
|
73 | |||
63 | def test_default_attributes |
|
74 | def test_default_attributes | |
64 | with_settings :default_projects_public => '1' do |
|
75 | with_settings :default_projects_public => '1' do | |
65 | assert_equal true, Project.new.is_public |
|
76 | assert_equal true, Project.new.is_public | |
66 | assert_equal false, Project.new(:is_public => false).is_public |
|
77 | assert_equal false, Project.new(:is_public => false).is_public | |
67 | end |
|
78 | end | |
68 |
|
79 | |||
69 | with_settings :default_projects_public => '0' do |
|
80 | with_settings :default_projects_public => '0' do | |
70 | assert_equal false, Project.new.is_public |
|
81 | assert_equal false, Project.new.is_public | |
71 | assert_equal true, Project.new(:is_public => true).is_public |
|
82 | assert_equal true, Project.new(:is_public => true).is_public | |
72 | end |
|
83 | end | |
73 |
|
84 | |||
74 | with_settings :sequential_project_identifiers => '1' do |
|
85 | with_settings :sequential_project_identifiers => '1' do | |
75 | assert !Project.new.identifier.blank? |
|
86 | assert !Project.new.identifier.blank? | |
76 | assert Project.new(:identifier => '').identifier.blank? |
|
87 | assert Project.new(:identifier => '').identifier.blank? | |
77 | end |
|
88 | end | |
78 |
|
89 | |||
79 | with_settings :sequential_project_identifiers => '0' do |
|
90 | with_settings :sequential_project_identifiers => '0' do | |
80 | assert Project.new.identifier.blank? |
|
91 | assert Project.new.identifier.blank? | |
81 | assert !Project.new(:identifier => 'test').blank? |
|
92 | assert !Project.new(:identifier => 'test').blank? | |
82 | end |
|
93 | end | |
83 |
|
94 | |||
84 | with_settings :default_projects_modules => ['issue_tracking', 'repository'] do |
|
95 | with_settings :default_projects_modules => ['issue_tracking', 'repository'] do | |
85 | assert_equal ['issue_tracking', 'repository'], Project.new.enabled_module_names |
|
96 | assert_equal ['issue_tracking', 'repository'], Project.new.enabled_module_names | |
86 | end |
|
97 | end | |
87 |
|
98 | |||
88 | assert_equal Tracker.all, Project.new.trackers |
|
99 | assert_equal Tracker.all, Project.new.trackers | |
89 | assert_equal Tracker.find(1, 3), Project.new(:tracker_ids => [1, 3]).trackers |
|
100 | assert_equal Tracker.find(1, 3), Project.new(:tracker_ids => [1, 3]).trackers | |
90 | end |
|
101 | end | |
91 |
|
102 | |||
92 | def test_update |
|
103 | def test_update | |
93 | assert_equal "eCookbook", @ecookbook.name |
|
104 | assert_equal "eCookbook", @ecookbook.name | |
94 | @ecookbook.name = "eCook" |
|
105 | @ecookbook.name = "eCook" | |
95 | assert @ecookbook.save, @ecookbook.errors.full_messages.join("; ") |
|
106 | assert @ecookbook.save, @ecookbook.errors.full_messages.join("; ") | |
96 | @ecookbook.reload |
|
107 | @ecookbook.reload | |
97 | assert_equal "eCook", @ecookbook.name |
|
108 | assert_equal "eCook", @ecookbook.name | |
98 | end |
|
109 | end | |
99 |
|
110 | |||
100 | def test_validate_identifier |
|
111 | def test_validate_identifier | |
101 | to_test = {"abc" => true, |
|
112 | to_test = {"abc" => true, | |
102 | "ab12" => true, |
|
113 | "ab12" => true, | |
103 | "ab-12" => true, |
|
114 | "ab-12" => true, | |
104 | "12" => false, |
|
115 | "12" => false, | |
105 | "new" => false} |
|
116 | "new" => false} | |
106 |
|
117 | |||
107 | to_test.each do |identifier, valid| |
|
118 | to_test.each do |identifier, valid| | |
108 | p = Project.new |
|
119 | p = Project.new | |
109 | p.identifier = identifier |
|
120 | p.identifier = identifier | |
110 | p.valid? |
|
121 | p.valid? | |
111 | assert_equal valid, p.errors.on('identifier').nil? |
|
122 | assert_equal valid, p.errors.on('identifier').nil? | |
112 | end |
|
123 | end | |
113 | end |
|
124 | end | |
114 |
|
125 | |||
115 | def test_members_should_be_active_users |
|
126 | def test_members_should_be_active_users | |
116 | Project.all.each do |project| |
|
127 | Project.all.each do |project| | |
117 | assert_nil project.members.detect {|m| !(m.user.is_a?(User) && m.user.active?) } |
|
128 | assert_nil project.members.detect {|m| !(m.user.is_a?(User) && m.user.active?) } | |
118 | end |
|
129 | end | |
119 | end |
|
130 | end | |
120 |
|
131 | |||
121 | def test_users_should_be_active_users |
|
132 | def test_users_should_be_active_users | |
122 | Project.all.each do |project| |
|
133 | Project.all.each do |project| | |
123 | assert_nil project.users.detect {|u| !(u.is_a?(User) && u.active?) } |
|
134 | assert_nil project.users.detect {|u| !(u.is_a?(User) && u.active?) } | |
124 | end |
|
135 | end | |
125 | end |
|
136 | end | |
126 |
|
137 | |||
127 | def test_archive |
|
138 | def test_archive | |
128 | user = @ecookbook.members.first.user |
|
139 | user = @ecookbook.members.first.user | |
129 | @ecookbook.archive |
|
140 | @ecookbook.archive | |
130 | @ecookbook.reload |
|
141 | @ecookbook.reload | |
131 |
|
142 | |||
132 | assert !@ecookbook.active? |
|
143 | assert !@ecookbook.active? | |
133 | assert @ecookbook.archived? |
|
144 | assert @ecookbook.archived? | |
134 | assert !user.projects.include?(@ecookbook) |
|
145 | assert !user.projects.include?(@ecookbook) | |
135 | # Subproject are also archived |
|
146 | # Subproject are also archived | |
136 | assert !@ecookbook.children.empty? |
|
147 | assert !@ecookbook.children.empty? | |
137 | assert @ecookbook.descendants.active.empty? |
|
148 | assert @ecookbook.descendants.active.empty? | |
138 | end |
|
149 | end | |
139 |
|
150 | |||
140 | def test_archive_should_fail_if_versions_are_used_by_non_descendant_projects |
|
151 | def test_archive_should_fail_if_versions_are_used_by_non_descendant_projects | |
141 | # Assign an issue of a project to a version of a child project |
|
152 | # Assign an issue of a project to a version of a child project | |
142 | Issue.find(4).update_attribute :fixed_version_id, 4 |
|
153 | Issue.find(4).update_attribute :fixed_version_id, 4 | |
143 |
|
154 | |||
144 | assert_no_difference "Project.count(:all, :conditions => 'status = #{Project::STATUS_ARCHIVED}')" do |
|
155 | assert_no_difference "Project.count(:all, :conditions => 'status = #{Project::STATUS_ARCHIVED}')" do | |
145 | assert_equal false, @ecookbook.archive |
|
156 | assert_equal false, @ecookbook.archive | |
146 | end |
|
157 | end | |
147 | @ecookbook.reload |
|
158 | @ecookbook.reload | |
148 | assert @ecookbook.active? |
|
159 | assert @ecookbook.active? | |
149 | end |
|
160 | end | |
150 |
|
161 | |||
151 | def test_unarchive |
|
162 | def test_unarchive | |
152 | user = @ecookbook.members.first.user |
|
163 | user = @ecookbook.members.first.user | |
153 | @ecookbook.archive |
|
164 | @ecookbook.archive | |
154 | # A subproject of an archived project can not be unarchived |
|
165 | # A subproject of an archived project can not be unarchived | |
155 | assert !@ecookbook_sub1.unarchive |
|
166 | assert !@ecookbook_sub1.unarchive | |
156 |
|
167 | |||
157 | # Unarchive project |
|
168 | # Unarchive project | |
158 | assert @ecookbook.unarchive |
|
169 | assert @ecookbook.unarchive | |
159 | @ecookbook.reload |
|
170 | @ecookbook.reload | |
160 | assert @ecookbook.active? |
|
171 | assert @ecookbook.active? | |
161 | assert !@ecookbook.archived? |
|
172 | assert !@ecookbook.archived? | |
162 | assert user.projects.include?(@ecookbook) |
|
173 | assert user.projects.include?(@ecookbook) | |
163 | # Subproject can now be unarchived |
|
174 | # Subproject can now be unarchived | |
164 | @ecookbook_sub1.reload |
|
175 | @ecookbook_sub1.reload | |
165 | assert @ecookbook_sub1.unarchive |
|
176 | assert @ecookbook_sub1.unarchive | |
166 | end |
|
177 | end | |
167 |
|
178 | |||
168 | def test_destroy |
|
179 | def test_destroy | |
169 | # 2 active members |
|
180 | # 2 active members | |
170 | assert_equal 2, @ecookbook.members.size |
|
181 | assert_equal 2, @ecookbook.members.size | |
171 | # and 1 is locked |
|
182 | # and 1 is locked | |
172 | assert_equal 3, Member.find(:all, :conditions => ['project_id = ?', @ecookbook.id]).size |
|
183 | assert_equal 3, Member.find(:all, :conditions => ['project_id = ?', @ecookbook.id]).size | |
173 | # some boards |
|
184 | # some boards | |
174 | assert @ecookbook.boards.any? |
|
185 | assert @ecookbook.boards.any? | |
175 |
|
186 | |||
176 | @ecookbook.destroy |
|
187 | @ecookbook.destroy | |
177 | # make sure that the project non longer exists |
|
188 | # make sure that the project non longer exists | |
178 | assert_raise(ActiveRecord::RecordNotFound) { Project.find(@ecookbook.id) } |
|
189 | assert_raise(ActiveRecord::RecordNotFound) { Project.find(@ecookbook.id) } | |
179 | # make sure related data was removed |
|
190 | # make sure related data was removed | |
180 | assert_nil Member.first(:conditions => {:project_id => @ecookbook.id}) |
|
191 | assert_nil Member.first(:conditions => {:project_id => @ecookbook.id}) | |
181 | assert_nil Board.first(:conditions => {:project_id => @ecookbook.id}) |
|
192 | assert_nil Board.first(:conditions => {:project_id => @ecookbook.id}) | |
182 | assert_nil Issue.first(:conditions => {:project_id => @ecookbook.id}) |
|
193 | assert_nil Issue.first(:conditions => {:project_id => @ecookbook.id}) | |
183 | end |
|
194 | end | |
184 |
|
195 | |||
185 | def test_destroying_root_projects_should_clear_data |
|
196 | def test_destroying_root_projects_should_clear_data | |
186 | Project.roots.each do |root| |
|
197 | Project.roots.each do |root| | |
187 | root.destroy |
|
198 | root.destroy | |
188 | end |
|
199 | end | |
189 |
|
200 | |||
190 | assert_equal 0, Project.count, "Projects were not deleted: #{Project.all.inspect}" |
|
201 | assert_equal 0, Project.count, "Projects were not deleted: #{Project.all.inspect}" | |
191 | assert_equal 0, Member.count, "Members were not deleted: #{Member.all.inspect}" |
|
202 | assert_equal 0, Member.count, "Members were not deleted: #{Member.all.inspect}" | |
192 | assert_equal 0, MemberRole.count |
|
203 | assert_equal 0, MemberRole.count | |
193 | assert_equal 0, Issue.count |
|
204 | assert_equal 0, Issue.count | |
194 | assert_equal 0, Journal.count |
|
205 | assert_equal 0, Journal.count | |
195 | assert_equal 0, JournalDetail.count |
|
206 | assert_equal 0, JournalDetail.count | |
196 | assert_equal 0, Attachment.count |
|
207 | assert_equal 0, Attachment.count | |
197 | assert_equal 0, EnabledModule.count |
|
208 | assert_equal 0, EnabledModule.count | |
198 | assert_equal 0, IssueCategory.count |
|
209 | assert_equal 0, IssueCategory.count | |
199 | assert_equal 0, IssueRelation.count |
|
210 | assert_equal 0, IssueRelation.count | |
200 | assert_equal 0, Board.count |
|
211 | assert_equal 0, Board.count | |
201 | assert_equal 0, Message.count |
|
212 | assert_equal 0, Message.count | |
202 | assert_equal 0, News.count |
|
213 | assert_equal 0, News.count | |
203 | assert_equal 0, Query.count(:conditions => "project_id IS NOT NULL") |
|
214 | assert_equal 0, Query.count(:conditions => "project_id IS NOT NULL") | |
204 | assert_equal 0, Repository.count |
|
215 | assert_equal 0, Repository.count | |
205 | assert_equal 0, Changeset.count |
|
216 | assert_equal 0, Changeset.count | |
206 | assert_equal 0, Change.count |
|
217 | assert_equal 0, Change.count | |
207 | assert_equal 0, Comment.count |
|
218 | assert_equal 0, Comment.count | |
208 | assert_equal 0, TimeEntry.count |
|
219 | assert_equal 0, TimeEntry.count | |
209 | assert_equal 0, Version.count |
|
220 | assert_equal 0, Version.count | |
210 | assert_equal 0, Watcher.count |
|
221 | assert_equal 0, Watcher.count | |
211 | assert_equal 0, Wiki.count |
|
222 | assert_equal 0, Wiki.count | |
212 | assert_equal 0, WikiPage.count |
|
223 | assert_equal 0, WikiPage.count | |
213 | assert_equal 0, WikiContent.count |
|
224 | assert_equal 0, WikiContent.count | |
214 | assert_equal 0, WikiContent::Version.count |
|
225 | assert_equal 0, WikiContent::Version.count | |
215 | assert_equal 0, Project.connection.select_all("SELECT * FROM projects_trackers").size |
|
226 | assert_equal 0, Project.connection.select_all("SELECT * FROM projects_trackers").size | |
216 | assert_equal 0, Project.connection.select_all("SELECT * FROM custom_fields_projects").size |
|
227 | assert_equal 0, Project.connection.select_all("SELECT * FROM custom_fields_projects").size | |
217 | assert_equal 0, CustomValue.count(:conditions => {:customized_type => ['Project', 'Issue', 'TimeEntry', 'Version']}) |
|
228 | assert_equal 0, CustomValue.count(:conditions => {:customized_type => ['Project', 'Issue', 'TimeEntry', 'Version']}) | |
218 | end |
|
229 | end | |
219 |
|
230 | |||
220 | def test_move_an_orphan_project_to_a_root_project |
|
231 | def test_move_an_orphan_project_to_a_root_project | |
221 | sub = Project.find(2) |
|
232 | sub = Project.find(2) | |
222 | sub.set_parent! @ecookbook |
|
233 | sub.set_parent! @ecookbook | |
223 | assert_equal @ecookbook.id, sub.parent.id |
|
234 | assert_equal @ecookbook.id, sub.parent.id | |
224 | @ecookbook.reload |
|
235 | @ecookbook.reload | |
225 | assert_equal 4, @ecookbook.children.size |
|
236 | assert_equal 4, @ecookbook.children.size | |
226 | end |
|
237 | end | |
227 |
|
238 | |||
228 | def test_move_an_orphan_project_to_a_subproject |
|
239 | def test_move_an_orphan_project_to_a_subproject | |
229 | sub = Project.find(2) |
|
240 | sub = Project.find(2) | |
230 | assert sub.set_parent!(@ecookbook_sub1) |
|
241 | assert sub.set_parent!(@ecookbook_sub1) | |
231 | end |
|
242 | end | |
232 |
|
243 | |||
233 | def test_move_a_root_project_to_a_project |
|
244 | def test_move_a_root_project_to_a_project | |
234 | sub = @ecookbook |
|
245 | sub = @ecookbook | |
235 | assert sub.set_parent!(Project.find(2)) |
|
246 | assert sub.set_parent!(Project.find(2)) | |
236 | end |
|
247 | end | |
237 |
|
248 | |||
238 | def test_should_not_move_a_project_to_its_children |
|
249 | def test_should_not_move_a_project_to_its_children | |
239 | sub = @ecookbook |
|
250 | sub = @ecookbook | |
240 | assert !(sub.set_parent!(Project.find(3))) |
|
251 | assert !(sub.set_parent!(Project.find(3))) | |
241 | end |
|
252 | end | |
242 |
|
253 | |||
243 | def test_set_parent_should_add_roots_in_alphabetical_order |
|
254 | def test_set_parent_should_add_roots_in_alphabetical_order | |
244 | ProjectCustomField.delete_all |
|
255 | ProjectCustomField.delete_all | |
245 | Project.delete_all |
|
256 | Project.delete_all | |
246 | Project.create!(:name => 'Project C', :identifier => 'project-c').set_parent!(nil) |
|
257 | Project.create!(:name => 'Project C', :identifier => 'project-c').set_parent!(nil) | |
247 | Project.create!(:name => 'Project B', :identifier => 'project-b').set_parent!(nil) |
|
258 | Project.create!(:name => 'Project B', :identifier => 'project-b').set_parent!(nil) | |
248 | Project.create!(:name => 'Project D', :identifier => 'project-d').set_parent!(nil) |
|
259 | Project.create!(:name => 'Project D', :identifier => 'project-d').set_parent!(nil) | |
249 | Project.create!(:name => 'Project A', :identifier => 'project-a').set_parent!(nil) |
|
260 | Project.create!(:name => 'Project A', :identifier => 'project-a').set_parent!(nil) | |
250 |
|
261 | |||
251 | assert_equal 4, Project.count |
|
262 | assert_equal 4, Project.count | |
252 | assert_equal Project.all.sort_by(&:name), Project.all.sort_by(&:lft) |
|
263 | assert_equal Project.all.sort_by(&:name), Project.all.sort_by(&:lft) | |
253 | end |
|
264 | end | |
254 |
|
265 | |||
255 | def test_set_parent_should_add_children_in_alphabetical_order |
|
266 | def test_set_parent_should_add_children_in_alphabetical_order | |
256 | ProjectCustomField.delete_all |
|
267 | ProjectCustomField.delete_all | |
257 | parent = Project.create!(:name => 'Parent', :identifier => 'parent') |
|
268 | parent = Project.create!(:name => 'Parent', :identifier => 'parent') | |
258 | Project.create!(:name => 'Project C', :identifier => 'project-c').set_parent!(parent) |
|
269 | Project.create!(:name => 'Project C', :identifier => 'project-c').set_parent!(parent) | |
259 | Project.create!(:name => 'Project B', :identifier => 'project-b').set_parent!(parent) |
|
270 | Project.create!(:name => 'Project B', :identifier => 'project-b').set_parent!(parent) | |
260 | Project.create!(:name => 'Project D', :identifier => 'project-d').set_parent!(parent) |
|
271 | Project.create!(:name => 'Project D', :identifier => 'project-d').set_parent!(parent) | |
261 | Project.create!(:name => 'Project A', :identifier => 'project-a').set_parent!(parent) |
|
272 | Project.create!(:name => 'Project A', :identifier => 'project-a').set_parent!(parent) | |
262 |
|
273 | |||
263 | parent.reload |
|
274 | parent.reload | |
264 | assert_equal 4, parent.children.size |
|
275 | assert_equal 4, parent.children.size | |
265 | assert_equal parent.children.sort_by(&:name), parent.children |
|
276 | assert_equal parent.children.sort_by(&:name), parent.children | |
266 | end |
|
277 | end | |
267 |
|
278 | |||
268 | def test_rebuild_should_sort_children_alphabetically |
|
279 | def test_rebuild_should_sort_children_alphabetically | |
269 | ProjectCustomField.delete_all |
|
280 | ProjectCustomField.delete_all | |
270 | parent = Project.create!(:name => 'Parent', :identifier => 'parent') |
|
281 | parent = Project.create!(:name => 'Parent', :identifier => 'parent') | |
271 | Project.create!(:name => 'Project C', :identifier => 'project-c').move_to_child_of(parent) |
|
282 | Project.create!(:name => 'Project C', :identifier => 'project-c').move_to_child_of(parent) | |
272 | Project.create!(:name => 'Project B', :identifier => 'project-b').move_to_child_of(parent) |
|
283 | Project.create!(:name => 'Project B', :identifier => 'project-b').move_to_child_of(parent) | |
273 | Project.create!(:name => 'Project D', :identifier => 'project-d').move_to_child_of(parent) |
|
284 | Project.create!(:name => 'Project D', :identifier => 'project-d').move_to_child_of(parent) | |
274 | Project.create!(:name => 'Project A', :identifier => 'project-a').move_to_child_of(parent) |
|
285 | Project.create!(:name => 'Project A', :identifier => 'project-a').move_to_child_of(parent) | |
275 |
|
286 | |||
276 | Project.update_all("lft = NULL, rgt = NULL") |
|
287 | Project.update_all("lft = NULL, rgt = NULL") | |
277 | Project.rebuild! |
|
288 | Project.rebuild! | |
278 |
|
289 | |||
279 | parent.reload |
|
290 | parent.reload | |
280 | assert_equal 4, parent.children.size |
|
291 | assert_equal 4, parent.children.size | |
281 | assert_equal parent.children.sort_by(&:name), parent.children |
|
292 | assert_equal parent.children.sort_by(&:name), parent.children | |
282 | end |
|
293 | end | |
283 |
|
294 | |||
284 |
|
295 | |||
285 | def test_set_parent_should_update_issue_fixed_version_associations_when_a_fixed_version_is_moved_out_of_the_hierarchy |
|
296 | def test_set_parent_should_update_issue_fixed_version_associations_when_a_fixed_version_is_moved_out_of_the_hierarchy | |
286 | # Parent issue with a hierarchy project's fixed version |
|
297 | # Parent issue with a hierarchy project's fixed version | |
287 | parent_issue = Issue.find(1) |
|
298 | parent_issue = Issue.find(1) | |
288 | parent_issue.update_attribute(:fixed_version_id, 4) |
|
299 | parent_issue.update_attribute(:fixed_version_id, 4) | |
289 | parent_issue.reload |
|
300 | parent_issue.reload | |
290 | assert_equal 4, parent_issue.fixed_version_id |
|
301 | assert_equal 4, parent_issue.fixed_version_id | |
291 |
|
302 | |||
292 | # Should keep fixed versions for the issues |
|
303 | # Should keep fixed versions for the issues | |
293 | issue_with_local_fixed_version = Issue.find(5) |
|
304 | issue_with_local_fixed_version = Issue.find(5) | |
294 | issue_with_local_fixed_version.update_attribute(:fixed_version_id, 4) |
|
305 | issue_with_local_fixed_version.update_attribute(:fixed_version_id, 4) | |
295 | issue_with_local_fixed_version.reload |
|
306 | issue_with_local_fixed_version.reload | |
296 | assert_equal 4, issue_with_local_fixed_version.fixed_version_id |
|
307 | assert_equal 4, issue_with_local_fixed_version.fixed_version_id | |
297 |
|
308 | |||
298 | # Local issue with hierarchy fixed_version |
|
309 | # Local issue with hierarchy fixed_version | |
299 | issue_with_hierarchy_fixed_version = Issue.find(13) |
|
310 | issue_with_hierarchy_fixed_version = Issue.find(13) | |
300 | issue_with_hierarchy_fixed_version.update_attribute(:fixed_version_id, 6) |
|
311 | issue_with_hierarchy_fixed_version.update_attribute(:fixed_version_id, 6) | |
301 | issue_with_hierarchy_fixed_version.reload |
|
312 | issue_with_hierarchy_fixed_version.reload | |
302 | assert_equal 6, issue_with_hierarchy_fixed_version.fixed_version_id |
|
313 | assert_equal 6, issue_with_hierarchy_fixed_version.fixed_version_id | |
303 |
|
314 | |||
304 | # Move project out of the issue's hierarchy |
|
315 | # Move project out of the issue's hierarchy | |
305 | moved_project = Project.find(3) |
|
316 | moved_project = Project.find(3) | |
306 | moved_project.set_parent!(Project.find(2)) |
|
317 | moved_project.set_parent!(Project.find(2)) | |
307 | parent_issue.reload |
|
318 | parent_issue.reload | |
308 | issue_with_local_fixed_version.reload |
|
319 | issue_with_local_fixed_version.reload | |
309 | issue_with_hierarchy_fixed_version.reload |
|
320 | issue_with_hierarchy_fixed_version.reload | |
310 |
|
321 | |||
311 | assert_equal 4, issue_with_local_fixed_version.fixed_version_id, "Fixed version was not keep on an issue local to the moved project" |
|
322 | assert_equal 4, issue_with_local_fixed_version.fixed_version_id, "Fixed version was not keep on an issue local to the moved project" | |
312 | assert_equal nil, issue_with_hierarchy_fixed_version.fixed_version_id, "Fixed version is still set after moving the Project out of the hierarchy where the version is defined in" |
|
323 | assert_equal nil, issue_with_hierarchy_fixed_version.fixed_version_id, "Fixed version is still set after moving the Project out of the hierarchy where the version is defined in" | |
313 | assert_equal nil, parent_issue.fixed_version_id, "Fixed version is still set after moving the Version out of the hierarchy for the issue." |
|
324 | assert_equal nil, parent_issue.fixed_version_id, "Fixed version is still set after moving the Version out of the hierarchy for the issue." | |
314 | end |
|
325 | end | |
315 |
|
326 | |||
316 | def test_parent |
|
327 | def test_parent | |
317 | p = Project.find(6).parent |
|
328 | p = Project.find(6).parent | |
318 | assert p.is_a?(Project) |
|
329 | assert p.is_a?(Project) | |
319 | assert_equal 5, p.id |
|
330 | assert_equal 5, p.id | |
320 | end |
|
331 | end | |
321 |
|
332 | |||
322 | def test_ancestors |
|
333 | def test_ancestors | |
323 | a = Project.find(6).ancestors |
|
334 | a = Project.find(6).ancestors | |
324 | assert a.first.is_a?(Project) |
|
335 | assert a.first.is_a?(Project) | |
325 | assert_equal [1, 5], a.collect(&:id) |
|
336 | assert_equal [1, 5], a.collect(&:id) | |
326 | end |
|
337 | end | |
327 |
|
338 | |||
328 | def test_root |
|
339 | def test_root | |
329 | r = Project.find(6).root |
|
340 | r = Project.find(6).root | |
330 | assert r.is_a?(Project) |
|
341 | assert r.is_a?(Project) | |
331 | assert_equal 1, r.id |
|
342 | assert_equal 1, r.id | |
332 | end |
|
343 | end | |
333 |
|
344 | |||
334 | def test_children |
|
345 | def test_children | |
335 | c = Project.find(1).children |
|
346 | c = Project.find(1).children | |
336 | assert c.first.is_a?(Project) |
|
347 | assert c.first.is_a?(Project) | |
337 | assert_equal [5, 3, 4], c.collect(&:id) |
|
348 | assert_equal [5, 3, 4], c.collect(&:id) | |
338 | end |
|
349 | end | |
339 |
|
350 | |||
340 | def test_descendants |
|
351 | def test_descendants | |
341 | d = Project.find(1).descendants |
|
352 | d = Project.find(1).descendants | |
342 | assert d.first.is_a?(Project) |
|
353 | assert d.first.is_a?(Project) | |
343 | assert_equal [5, 6, 3, 4], d.collect(&:id) |
|
354 | assert_equal [5, 6, 3, 4], d.collect(&:id) | |
344 | end |
|
355 | end | |
345 |
|
356 | |||
346 | def test_allowed_parents_should_be_empty_for_non_member_user |
|
357 | def test_allowed_parents_should_be_empty_for_non_member_user | |
347 | Role.non_member.add_permission!(:add_project) |
|
358 | Role.non_member.add_permission!(:add_project) | |
348 | user = User.find(9) |
|
359 | user = User.find(9) | |
349 | assert user.memberships.empty? |
|
360 | assert user.memberships.empty? | |
350 | User.current = user |
|
361 | User.current = user | |
351 | assert Project.new.allowed_parents.compact.empty? |
|
362 | assert Project.new.allowed_parents.compact.empty? | |
352 | end |
|
363 | end | |
353 |
|
364 | |||
354 | def test_allowed_parents_with_add_subprojects_permission |
|
365 | def test_allowed_parents_with_add_subprojects_permission | |
355 | Role.find(1).remove_permission!(:add_project) |
|
366 | Role.find(1).remove_permission!(:add_project) | |
356 | Role.find(1).add_permission!(:add_subprojects) |
|
367 | Role.find(1).add_permission!(:add_subprojects) | |
357 | User.current = User.find(2) |
|
368 | User.current = User.find(2) | |
358 | # new project |
|
369 | # new project | |
359 | assert !Project.new.allowed_parents.include?(nil) |
|
370 | assert !Project.new.allowed_parents.include?(nil) | |
360 | assert Project.new.allowed_parents.include?(Project.find(1)) |
|
371 | assert Project.new.allowed_parents.include?(Project.find(1)) | |
361 | # existing root project |
|
372 | # existing root project | |
362 | assert Project.find(1).allowed_parents.include?(nil) |
|
373 | assert Project.find(1).allowed_parents.include?(nil) | |
363 | # existing child |
|
374 | # existing child | |
364 | assert Project.find(3).allowed_parents.include?(Project.find(1)) |
|
375 | assert Project.find(3).allowed_parents.include?(Project.find(1)) | |
365 | assert !Project.find(3).allowed_parents.include?(nil) |
|
376 | assert !Project.find(3).allowed_parents.include?(nil) | |
366 | end |
|
377 | end | |
367 |
|
378 | |||
368 | def test_allowed_parents_with_add_project_permission |
|
379 | def test_allowed_parents_with_add_project_permission | |
369 | Role.find(1).add_permission!(:add_project) |
|
380 | Role.find(1).add_permission!(:add_project) | |
370 | Role.find(1).remove_permission!(:add_subprojects) |
|
381 | Role.find(1).remove_permission!(:add_subprojects) | |
371 | User.current = User.find(2) |
|
382 | User.current = User.find(2) | |
372 | # new project |
|
383 | # new project | |
373 | assert Project.new.allowed_parents.include?(nil) |
|
384 | assert Project.new.allowed_parents.include?(nil) | |
374 | assert !Project.new.allowed_parents.include?(Project.find(1)) |
|
385 | assert !Project.new.allowed_parents.include?(Project.find(1)) | |
375 | # existing root project |
|
386 | # existing root project | |
376 | assert Project.find(1).allowed_parents.include?(nil) |
|
387 | assert Project.find(1).allowed_parents.include?(nil) | |
377 | # existing child |
|
388 | # existing child | |
378 | assert Project.find(3).allowed_parents.include?(Project.find(1)) |
|
389 | assert Project.find(3).allowed_parents.include?(Project.find(1)) | |
379 | assert Project.find(3).allowed_parents.include?(nil) |
|
390 | assert Project.find(3).allowed_parents.include?(nil) | |
380 | end |
|
391 | end | |
381 |
|
392 | |||
382 | def test_allowed_parents_with_add_project_and_subprojects_permission |
|
393 | def test_allowed_parents_with_add_project_and_subprojects_permission | |
383 | Role.find(1).add_permission!(:add_project) |
|
394 | Role.find(1).add_permission!(:add_project) | |
384 | Role.find(1).add_permission!(:add_subprojects) |
|
395 | Role.find(1).add_permission!(:add_subprojects) | |
385 | User.current = User.find(2) |
|
396 | User.current = User.find(2) | |
386 | # new project |
|
397 | # new project | |
387 | assert Project.new.allowed_parents.include?(nil) |
|
398 | assert Project.new.allowed_parents.include?(nil) | |
388 | assert Project.new.allowed_parents.include?(Project.find(1)) |
|
399 | assert Project.new.allowed_parents.include?(Project.find(1)) | |
389 | # existing root project |
|
400 | # existing root project | |
390 | assert Project.find(1).allowed_parents.include?(nil) |
|
401 | assert Project.find(1).allowed_parents.include?(nil) | |
391 | # existing child |
|
402 | # existing child | |
392 | assert Project.find(3).allowed_parents.include?(Project.find(1)) |
|
403 | assert Project.find(3).allowed_parents.include?(Project.find(1)) | |
393 | assert Project.find(3).allowed_parents.include?(nil) |
|
404 | assert Project.find(3).allowed_parents.include?(nil) | |
394 | end |
|
405 | end | |
395 |
|
406 | |||
396 | def test_users_by_role |
|
407 | def test_users_by_role | |
397 | users_by_role = Project.find(1).users_by_role |
|
408 | users_by_role = Project.find(1).users_by_role | |
398 | assert_kind_of Hash, users_by_role |
|
409 | assert_kind_of Hash, users_by_role | |
399 | role = Role.find(1) |
|
410 | role = Role.find(1) | |
400 | assert_kind_of Array, users_by_role[role] |
|
411 | assert_kind_of Array, users_by_role[role] | |
401 | assert users_by_role[role].include?(User.find(2)) |
|
412 | assert users_by_role[role].include?(User.find(2)) | |
402 | end |
|
413 | end | |
403 |
|
414 | |||
404 | def test_rolled_up_trackers |
|
415 | def test_rolled_up_trackers | |
405 | parent = Project.find(1) |
|
416 | parent = Project.find(1) | |
406 | parent.trackers = Tracker.find([1,2]) |
|
417 | parent.trackers = Tracker.find([1,2]) | |
407 | child = parent.children.find(3) |
|
418 | child = parent.children.find(3) | |
408 |
|
419 | |||
409 | assert_equal [1, 2], parent.tracker_ids |
|
420 | assert_equal [1, 2], parent.tracker_ids | |
410 | assert_equal [2, 3], child.trackers.collect(&:id) |
|
421 | assert_equal [2, 3], child.trackers.collect(&:id) | |
411 |
|
422 | |||
412 | assert_kind_of Tracker, parent.rolled_up_trackers.first |
|
423 | assert_kind_of Tracker, parent.rolled_up_trackers.first | |
413 | assert_equal Tracker.find(1), parent.rolled_up_trackers.first |
|
424 | assert_equal Tracker.find(1), parent.rolled_up_trackers.first | |
414 |
|
425 | |||
415 | assert_equal [1, 2, 3], parent.rolled_up_trackers.collect(&:id) |
|
426 | assert_equal [1, 2, 3], parent.rolled_up_trackers.collect(&:id) | |
416 | assert_equal [2, 3], child.rolled_up_trackers.collect(&:id) |
|
427 | assert_equal [2, 3], child.rolled_up_trackers.collect(&:id) | |
417 | end |
|
428 | end | |
418 |
|
429 | |||
419 | def test_rolled_up_trackers_should_ignore_archived_subprojects |
|
430 | def test_rolled_up_trackers_should_ignore_archived_subprojects | |
420 | parent = Project.find(1) |
|
431 | parent = Project.find(1) | |
421 | parent.trackers = Tracker.find([1,2]) |
|
432 | parent.trackers = Tracker.find([1,2]) | |
422 | child = parent.children.find(3) |
|
433 | child = parent.children.find(3) | |
423 | child.trackers = Tracker.find([1,3]) |
|
434 | child.trackers = Tracker.find([1,3]) | |
424 | parent.children.each(&:archive) |
|
435 | parent.children.each(&:archive) | |
425 |
|
436 | |||
426 | assert_equal [1,2], parent.rolled_up_trackers.collect(&:id) |
|
437 | assert_equal [1,2], parent.rolled_up_trackers.collect(&:id) | |
427 | end |
|
438 | end | |
428 |
|
439 | |||
429 | context "#rolled_up_versions" do |
|
440 | context "#rolled_up_versions" do | |
430 | setup do |
|
441 | setup do | |
431 | @project = Project.generate! |
|
442 | @project = Project.generate! | |
432 | @parent_version_1 = Version.generate!(:project => @project) |
|
443 | @parent_version_1 = Version.generate!(:project => @project) | |
433 | @parent_version_2 = Version.generate!(:project => @project) |
|
444 | @parent_version_2 = Version.generate!(:project => @project) | |
434 | end |
|
445 | end | |
435 |
|
446 | |||
436 | should "include the versions for the current project" do |
|
447 | should "include the versions for the current project" do | |
437 | assert_same_elements [@parent_version_1, @parent_version_2], @project.rolled_up_versions |
|
448 | assert_same_elements [@parent_version_1, @parent_version_2], @project.rolled_up_versions | |
438 | end |
|
449 | end | |
439 |
|
450 | |||
440 | should "include versions for a subproject" do |
|
451 | should "include versions for a subproject" do | |
441 | @subproject = Project.generate! |
|
452 | @subproject = Project.generate! | |
442 | @subproject.set_parent!(@project) |
|
453 | @subproject.set_parent!(@project) | |
443 | @subproject_version = Version.generate!(:project => @subproject) |
|
454 | @subproject_version = Version.generate!(:project => @subproject) | |
444 |
|
455 | |||
445 | assert_same_elements [ |
|
456 | assert_same_elements [ | |
446 | @parent_version_1, |
|
457 | @parent_version_1, | |
447 | @parent_version_2, |
|
458 | @parent_version_2, | |
448 | @subproject_version |
|
459 | @subproject_version | |
449 | ], @project.rolled_up_versions |
|
460 | ], @project.rolled_up_versions | |
450 | end |
|
461 | end | |
451 |
|
462 | |||
452 | should "include versions for a sub-subproject" do |
|
463 | should "include versions for a sub-subproject" do | |
453 | @subproject = Project.generate! |
|
464 | @subproject = Project.generate! | |
454 | @subproject.set_parent!(@project) |
|
465 | @subproject.set_parent!(@project) | |
455 | @sub_subproject = Project.generate! |
|
466 | @sub_subproject = Project.generate! | |
456 | @sub_subproject.set_parent!(@subproject) |
|
467 | @sub_subproject.set_parent!(@subproject) | |
457 | @sub_subproject_version = Version.generate!(:project => @sub_subproject) |
|
468 | @sub_subproject_version = Version.generate!(:project => @sub_subproject) | |
458 |
|
469 | |||
459 | @project.reload |
|
470 | @project.reload | |
460 |
|
471 | |||
461 | assert_same_elements [ |
|
472 | assert_same_elements [ | |
462 | @parent_version_1, |
|
473 | @parent_version_1, | |
463 | @parent_version_2, |
|
474 | @parent_version_2, | |
464 | @sub_subproject_version |
|
475 | @sub_subproject_version | |
465 | ], @project.rolled_up_versions |
|
476 | ], @project.rolled_up_versions | |
466 | end |
|
477 | end | |
467 |
|
478 | |||
468 | should "only check active projects" do |
|
479 | should "only check active projects" do | |
469 | @subproject = Project.generate! |
|
480 | @subproject = Project.generate! | |
470 | @subproject.set_parent!(@project) |
|
481 | @subproject.set_parent!(@project) | |
471 | @subproject_version = Version.generate!(:project => @subproject) |
|
482 | @subproject_version = Version.generate!(:project => @subproject) | |
472 | assert @subproject.archive |
|
483 | assert @subproject.archive | |
473 |
|
484 | |||
474 | @project.reload |
|
485 | @project.reload | |
475 |
|
486 | |||
476 | assert !@subproject.active? |
|
487 | assert !@subproject.active? | |
477 | assert_same_elements [@parent_version_1, @parent_version_2], @project.rolled_up_versions |
|
488 | assert_same_elements [@parent_version_1, @parent_version_2], @project.rolled_up_versions | |
478 | end |
|
489 | end | |
479 | end |
|
490 | end | |
480 |
|
491 | |||
481 | def test_shared_versions_none_sharing |
|
492 | def test_shared_versions_none_sharing | |
482 | p = Project.find(5) |
|
493 | p = Project.find(5) | |
483 | v = Version.create!(:name => 'none_sharing', :project => p, :sharing => 'none') |
|
494 | v = Version.create!(:name => 'none_sharing', :project => p, :sharing => 'none') | |
484 | assert p.shared_versions.include?(v) |
|
495 | assert p.shared_versions.include?(v) | |
485 | assert !p.children.first.shared_versions.include?(v) |
|
496 | assert !p.children.first.shared_versions.include?(v) | |
486 | assert !p.root.shared_versions.include?(v) |
|
497 | assert !p.root.shared_versions.include?(v) | |
487 | assert !p.siblings.first.shared_versions.include?(v) |
|
498 | assert !p.siblings.first.shared_versions.include?(v) | |
488 | assert !p.root.siblings.first.shared_versions.include?(v) |
|
499 | assert !p.root.siblings.first.shared_versions.include?(v) | |
489 | end |
|
500 | end | |
490 |
|
501 | |||
491 | def test_shared_versions_descendants_sharing |
|
502 | def test_shared_versions_descendants_sharing | |
492 | p = Project.find(5) |
|
503 | p = Project.find(5) | |
493 | v = Version.create!(:name => 'descendants_sharing', :project => p, :sharing => 'descendants') |
|
504 | v = Version.create!(:name => 'descendants_sharing', :project => p, :sharing => 'descendants') | |
494 | assert p.shared_versions.include?(v) |
|
505 | assert p.shared_versions.include?(v) | |
495 | assert p.children.first.shared_versions.include?(v) |
|
506 | assert p.children.first.shared_versions.include?(v) | |
496 | assert !p.root.shared_versions.include?(v) |
|
507 | assert !p.root.shared_versions.include?(v) | |
497 | assert !p.siblings.first.shared_versions.include?(v) |
|
508 | assert !p.siblings.first.shared_versions.include?(v) | |
498 | assert !p.root.siblings.first.shared_versions.include?(v) |
|
509 | assert !p.root.siblings.first.shared_versions.include?(v) | |
499 | end |
|
510 | end | |
500 |
|
511 | |||
501 | def test_shared_versions_hierarchy_sharing |
|
512 | def test_shared_versions_hierarchy_sharing | |
502 | p = Project.find(5) |
|
513 | p = Project.find(5) | |
503 | v = Version.create!(:name => 'hierarchy_sharing', :project => p, :sharing => 'hierarchy') |
|
514 | v = Version.create!(:name => 'hierarchy_sharing', :project => p, :sharing => 'hierarchy') | |
504 | assert p.shared_versions.include?(v) |
|
515 | assert p.shared_versions.include?(v) | |
505 | assert p.children.first.shared_versions.include?(v) |
|
516 | assert p.children.first.shared_versions.include?(v) | |
506 | assert p.root.shared_versions.include?(v) |
|
517 | assert p.root.shared_versions.include?(v) | |
507 | assert !p.siblings.first.shared_versions.include?(v) |
|
518 | assert !p.siblings.first.shared_versions.include?(v) | |
508 | assert !p.root.siblings.first.shared_versions.include?(v) |
|
519 | assert !p.root.siblings.first.shared_versions.include?(v) | |
509 | end |
|
520 | end | |
510 |
|
521 | |||
511 | def test_shared_versions_tree_sharing |
|
522 | def test_shared_versions_tree_sharing | |
512 | p = Project.find(5) |
|
523 | p = Project.find(5) | |
513 | v = Version.create!(:name => 'tree_sharing', :project => p, :sharing => 'tree') |
|
524 | v = Version.create!(:name => 'tree_sharing', :project => p, :sharing => 'tree') | |
514 | assert p.shared_versions.include?(v) |
|
525 | assert p.shared_versions.include?(v) | |
515 | assert p.children.first.shared_versions.include?(v) |
|
526 | assert p.children.first.shared_versions.include?(v) | |
516 | assert p.root.shared_versions.include?(v) |
|
527 | assert p.root.shared_versions.include?(v) | |
517 | assert p.siblings.first.shared_versions.include?(v) |
|
528 | assert p.siblings.first.shared_versions.include?(v) | |
518 | assert !p.root.siblings.first.shared_versions.include?(v) |
|
529 | assert !p.root.siblings.first.shared_versions.include?(v) | |
519 | end |
|
530 | end | |
520 |
|
531 | |||
521 | def test_shared_versions_system_sharing |
|
532 | def test_shared_versions_system_sharing | |
522 | p = Project.find(5) |
|
533 | p = Project.find(5) | |
523 | v = Version.create!(:name => 'system_sharing', :project => p, :sharing => 'system') |
|
534 | v = Version.create!(:name => 'system_sharing', :project => p, :sharing => 'system') | |
524 | assert p.shared_versions.include?(v) |
|
535 | assert p.shared_versions.include?(v) | |
525 | assert p.children.first.shared_versions.include?(v) |
|
536 | assert p.children.first.shared_versions.include?(v) | |
526 | assert p.root.shared_versions.include?(v) |
|
537 | assert p.root.shared_versions.include?(v) | |
527 | assert p.siblings.first.shared_versions.include?(v) |
|
538 | assert p.siblings.first.shared_versions.include?(v) | |
528 | assert p.root.siblings.first.shared_versions.include?(v) |
|
539 | assert p.root.siblings.first.shared_versions.include?(v) | |
529 | end |
|
540 | end | |
530 |
|
541 | |||
531 | def test_shared_versions |
|
542 | def test_shared_versions | |
532 | parent = Project.find(1) |
|
543 | parent = Project.find(1) | |
533 | child = parent.children.find(3) |
|
544 | child = parent.children.find(3) | |
534 | private_child = parent.children.find(5) |
|
545 | private_child = parent.children.find(5) | |
535 |
|
546 | |||
536 | assert_equal [1,2,3], parent.version_ids.sort |
|
547 | assert_equal [1,2,3], parent.version_ids.sort | |
537 | assert_equal [4], child.version_ids |
|
548 | assert_equal [4], child.version_ids | |
538 | assert_equal [6], private_child.version_ids |
|
549 | assert_equal [6], private_child.version_ids | |
539 | assert_equal [7], Version.find_all_by_sharing('system').collect(&:id) |
|
550 | assert_equal [7], Version.find_all_by_sharing('system').collect(&:id) | |
540 |
|
551 | |||
541 | assert_equal 6, parent.shared_versions.size |
|
552 | assert_equal 6, parent.shared_versions.size | |
542 | parent.shared_versions.each do |version| |
|
553 | parent.shared_versions.each do |version| | |
543 | assert_kind_of Version, version |
|
554 | assert_kind_of Version, version | |
544 | end |
|
555 | end | |
545 |
|
556 | |||
546 | assert_equal [1,2,3,4,6,7], parent.shared_versions.collect(&:id).sort |
|
557 | assert_equal [1,2,3,4,6,7], parent.shared_versions.collect(&:id).sort | |
547 | end |
|
558 | end | |
548 |
|
559 | |||
549 | def test_shared_versions_should_ignore_archived_subprojects |
|
560 | def test_shared_versions_should_ignore_archived_subprojects | |
550 | parent = Project.find(1) |
|
561 | parent = Project.find(1) | |
551 | child = parent.children.find(3) |
|
562 | child = parent.children.find(3) | |
552 | child.archive |
|
563 | child.archive | |
553 | parent.reload |
|
564 | parent.reload | |
554 |
|
565 | |||
555 | assert_equal [1,2,3], parent.version_ids.sort |
|
566 | assert_equal [1,2,3], parent.version_ids.sort | |
556 | assert_equal [4], child.version_ids |
|
567 | assert_equal [4], child.version_ids | |
557 | assert !parent.shared_versions.collect(&:id).include?(4) |
|
568 | assert !parent.shared_versions.collect(&:id).include?(4) | |
558 | end |
|
569 | end | |
559 |
|
570 | |||
560 | def test_shared_versions_visible_to_user |
|
571 | def test_shared_versions_visible_to_user | |
561 | user = User.find(3) |
|
572 | user = User.find(3) | |
562 | parent = Project.find(1) |
|
573 | parent = Project.find(1) | |
563 | child = parent.children.find(5) |
|
574 | child = parent.children.find(5) | |
564 |
|
575 | |||
565 | assert_equal [1,2,3], parent.version_ids.sort |
|
576 | assert_equal [1,2,3], parent.version_ids.sort | |
566 | assert_equal [6], child.version_ids |
|
577 | assert_equal [6], child.version_ids | |
567 |
|
578 | |||
568 | versions = parent.shared_versions.visible(user) |
|
579 | versions = parent.shared_versions.visible(user) | |
569 |
|
580 | |||
570 | assert_equal 4, versions.size |
|
581 | assert_equal 4, versions.size | |
571 | versions.each do |version| |
|
582 | versions.each do |version| | |
572 | assert_kind_of Version, version |
|
583 | assert_kind_of Version, version | |
573 | end |
|
584 | end | |
574 |
|
585 | |||
575 | assert !versions.collect(&:id).include?(6) |
|
586 | assert !versions.collect(&:id).include?(6) | |
576 | end |
|
587 | end | |
577 |
|
588 | |||
578 | def test_next_identifier |
|
589 | def test_next_identifier | |
579 | ProjectCustomField.delete_all |
|
590 | ProjectCustomField.delete_all | |
580 | Project.create!(:name => 'last', :identifier => 'p2008040') |
|
591 | Project.create!(:name => 'last', :identifier => 'p2008040') | |
581 | assert_equal 'p2008041', Project.next_identifier |
|
592 | assert_equal 'p2008041', Project.next_identifier | |
582 | end |
|
593 | end | |
583 |
|
594 | |||
584 | def test_next_identifier_first_project |
|
595 | def test_next_identifier_first_project | |
585 | Project.delete_all |
|
596 | Project.delete_all | |
586 | assert_nil Project.next_identifier |
|
597 | assert_nil Project.next_identifier | |
587 | end |
|
598 | end | |
588 |
|
599 | |||
589 | def test_enabled_module_names |
|
600 | def test_enabled_module_names | |
590 | with_settings :default_projects_modules => ['issue_tracking', 'repository'] do |
|
601 | with_settings :default_projects_modules => ['issue_tracking', 'repository'] do | |
591 | project = Project.new |
|
602 | project = Project.new | |
592 |
|
603 | |||
593 | project.enabled_module_names = %w(issue_tracking news) |
|
604 | project.enabled_module_names = %w(issue_tracking news) | |
594 | assert_equal %w(issue_tracking news), project.enabled_module_names.sort |
|
605 | assert_equal %w(issue_tracking news), project.enabled_module_names.sort | |
595 | end |
|
606 | end | |
596 | end |
|
607 | end | |
597 |
|
608 | |||
598 | context "enabled_modules" do |
|
609 | context "enabled_modules" do | |
599 | setup do |
|
610 | setup do | |
600 | @project = Project.find(1) |
|
611 | @project = Project.find(1) | |
601 | end |
|
612 | end | |
602 |
|
613 | |||
603 | should "define module by names and preserve ids" do |
|
614 | should "define module by names and preserve ids" do | |
604 | # Remove one module |
|
615 | # Remove one module | |
605 | modules = @project.enabled_modules.slice(0..-2) |
|
616 | modules = @project.enabled_modules.slice(0..-2) | |
606 | assert modules.any? |
|
617 | assert modules.any? | |
607 | assert_difference 'EnabledModule.count', -1 do |
|
618 | assert_difference 'EnabledModule.count', -1 do | |
608 | @project.enabled_module_names = modules.collect(&:name) |
|
619 | @project.enabled_module_names = modules.collect(&:name) | |
609 | end |
|
620 | end | |
610 | @project.reload |
|
621 | @project.reload | |
611 | # Ids should be preserved |
|
622 | # Ids should be preserved | |
612 | assert_equal @project.enabled_module_ids.sort, modules.collect(&:id).sort |
|
623 | assert_equal @project.enabled_module_ids.sort, modules.collect(&:id).sort | |
613 | end |
|
624 | end | |
614 |
|
625 | |||
615 | should "enable a module" do |
|
626 | should "enable a module" do | |
616 | @project.enabled_module_names = [] |
|
627 | @project.enabled_module_names = [] | |
617 | @project.reload |
|
628 | @project.reload | |
618 | assert_equal [], @project.enabled_module_names |
|
629 | assert_equal [], @project.enabled_module_names | |
619 | #with string |
|
630 | #with string | |
620 | @project.enable_module!("issue_tracking") |
|
631 | @project.enable_module!("issue_tracking") | |
621 | assert_equal ["issue_tracking"], @project.enabled_module_names |
|
632 | assert_equal ["issue_tracking"], @project.enabled_module_names | |
622 | #with symbol |
|
633 | #with symbol | |
623 | @project.enable_module!(:gantt) |
|
634 | @project.enable_module!(:gantt) | |
624 | assert_equal ["issue_tracking", "gantt"], @project.enabled_module_names |
|
635 | assert_equal ["issue_tracking", "gantt"], @project.enabled_module_names | |
625 | #don't add a module twice |
|
636 | #don't add a module twice | |
626 | @project.enable_module!("issue_tracking") |
|
637 | @project.enable_module!("issue_tracking") | |
627 | assert_equal ["issue_tracking", "gantt"], @project.enabled_module_names |
|
638 | assert_equal ["issue_tracking", "gantt"], @project.enabled_module_names | |
628 | end |
|
639 | end | |
629 |
|
640 | |||
630 | should "disable a module" do |
|
641 | should "disable a module" do | |
631 | #with string |
|
642 | #with string | |
632 | assert @project.enabled_module_names.include?("issue_tracking") |
|
643 | assert @project.enabled_module_names.include?("issue_tracking") | |
633 | @project.disable_module!("issue_tracking") |
|
644 | @project.disable_module!("issue_tracking") | |
634 | assert ! @project.reload.enabled_module_names.include?("issue_tracking") |
|
645 | assert ! @project.reload.enabled_module_names.include?("issue_tracking") | |
635 | #with symbol |
|
646 | #with symbol | |
636 | assert @project.enabled_module_names.include?("gantt") |
|
647 | assert @project.enabled_module_names.include?("gantt") | |
637 | @project.disable_module!(:gantt) |
|
648 | @project.disable_module!(:gantt) | |
638 | assert ! @project.reload.enabled_module_names.include?("gantt") |
|
649 | assert ! @project.reload.enabled_module_names.include?("gantt") | |
639 | #with EnabledModule object |
|
650 | #with EnabledModule object | |
640 | first_module = @project.enabled_modules.first |
|
651 | first_module = @project.enabled_modules.first | |
641 | @project.disable_module!(first_module) |
|
652 | @project.disable_module!(first_module) | |
642 | assert ! @project.reload.enabled_module_names.include?(first_module.name) |
|
653 | assert ! @project.reload.enabled_module_names.include?(first_module.name) | |
643 | end |
|
654 | end | |
644 | end |
|
655 | end | |
645 |
|
656 | |||
646 | def test_enabled_module_names_should_not_recreate_enabled_modules |
|
657 | def test_enabled_module_names_should_not_recreate_enabled_modules | |
647 | project = Project.find(1) |
|
658 | project = Project.find(1) | |
648 | # Remove one module |
|
659 | # Remove one module | |
649 | modules = project.enabled_modules.slice(0..-2) |
|
660 | modules = project.enabled_modules.slice(0..-2) | |
650 | assert modules.any? |
|
661 | assert modules.any? | |
651 | assert_difference 'EnabledModule.count', -1 do |
|
662 | assert_difference 'EnabledModule.count', -1 do | |
652 | project.enabled_module_names = modules.collect(&:name) |
|
663 | project.enabled_module_names = modules.collect(&:name) | |
653 | end |
|
664 | end | |
654 | project.reload |
|
665 | project.reload | |
655 | # Ids should be preserved |
|
666 | # Ids should be preserved | |
656 | assert_equal project.enabled_module_ids.sort, modules.collect(&:id).sort |
|
667 | assert_equal project.enabled_module_ids.sort, modules.collect(&:id).sort | |
657 | end |
|
668 | end | |
658 |
|
669 | |||
659 | def test_copy_from_existing_project |
|
670 | def test_copy_from_existing_project | |
660 | source_project = Project.find(1) |
|
671 | source_project = Project.find(1) | |
661 | copied_project = Project.copy_from(1) |
|
672 | copied_project = Project.copy_from(1) | |
662 |
|
673 | |||
663 | assert copied_project |
|
674 | assert copied_project | |
664 | # Cleared attributes |
|
675 | # Cleared attributes | |
665 | assert copied_project.id.blank? |
|
676 | assert copied_project.id.blank? | |
666 | assert copied_project.name.blank? |
|
677 | assert copied_project.name.blank? | |
667 | assert copied_project.identifier.blank? |
|
678 | assert copied_project.identifier.blank? | |
668 |
|
679 | |||
669 | # Duplicated attributes |
|
680 | # Duplicated attributes | |
670 | assert_equal source_project.description, copied_project.description |
|
681 | assert_equal source_project.description, copied_project.description | |
671 | assert_equal source_project.enabled_modules, copied_project.enabled_modules |
|
682 | assert_equal source_project.enabled_modules, copied_project.enabled_modules | |
672 | assert_equal source_project.trackers, copied_project.trackers |
|
683 | assert_equal source_project.trackers, copied_project.trackers | |
673 |
|
684 | |||
674 | # Default attributes |
|
685 | # Default attributes | |
675 | assert_equal 1, copied_project.status |
|
686 | assert_equal 1, copied_project.status | |
676 | end |
|
687 | end | |
677 |
|
688 | |||
678 | def test_activities_should_use_the_system_activities |
|
689 | def test_activities_should_use_the_system_activities | |
679 | project = Project.find(1) |
|
690 | project = Project.find(1) | |
680 | assert_equal project.activities, TimeEntryActivity.find(:all, :conditions => {:active => true} ) |
|
691 | assert_equal project.activities, TimeEntryActivity.find(:all, :conditions => {:active => true} ) | |
681 | end |
|
692 | end | |
682 |
|
693 | |||
683 |
|
694 | |||
684 | def test_activities_should_use_the_project_specific_activities |
|
695 | def test_activities_should_use_the_project_specific_activities | |
685 | project = Project.find(1) |
|
696 | project = Project.find(1) | |
686 | overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project}) |
|
697 | overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project}) | |
687 | assert overridden_activity.save! |
|
698 | assert overridden_activity.save! | |
688 |
|
699 | |||
689 | assert project.activities.include?(overridden_activity), "Project specific Activity not found" |
|
700 | assert project.activities.include?(overridden_activity), "Project specific Activity not found" | |
690 | end |
|
701 | end | |
691 |
|
702 | |||
692 | def test_activities_should_not_include_the_inactive_project_specific_activities |
|
703 | def test_activities_should_not_include_the_inactive_project_specific_activities | |
693 | project = Project.find(1) |
|
704 | project = Project.find(1) | |
694 | overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project, :parent => TimeEntryActivity.find(:first), :active => false}) |
|
705 | overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project, :parent => TimeEntryActivity.find(:first), :active => false}) | |
695 | assert overridden_activity.save! |
|
706 | assert overridden_activity.save! | |
696 |
|
707 | |||
697 | assert !project.activities.include?(overridden_activity), "Inactive Project specific Activity found" |
|
708 | assert !project.activities.include?(overridden_activity), "Inactive Project specific Activity found" | |
698 | end |
|
709 | end | |
699 |
|
710 | |||
700 | def test_activities_should_not_include_project_specific_activities_from_other_projects |
|
711 | def test_activities_should_not_include_project_specific_activities_from_other_projects | |
701 | project = Project.find(1) |
|
712 | project = Project.find(1) | |
702 | overridden_activity = TimeEntryActivity.new({:name => "Project", :project => Project.find(2)}) |
|
713 | overridden_activity = TimeEntryActivity.new({:name => "Project", :project => Project.find(2)}) | |
703 | assert overridden_activity.save! |
|
714 | assert overridden_activity.save! | |
704 |
|
715 | |||
705 | assert !project.activities.include?(overridden_activity), "Project specific Activity found on a different project" |
|
716 | assert !project.activities.include?(overridden_activity), "Project specific Activity found on a different project" | |
706 | end |
|
717 | end | |
707 |
|
718 | |||
708 | def test_activities_should_handle_nils |
|
719 | def test_activities_should_handle_nils | |
709 | overridden_activity = TimeEntryActivity.new({:name => "Project", :project => Project.find(1), :parent => TimeEntryActivity.find(:first)}) |
|
720 | overridden_activity = TimeEntryActivity.new({:name => "Project", :project => Project.find(1), :parent => TimeEntryActivity.find(:first)}) | |
710 | TimeEntryActivity.delete_all |
|
721 | TimeEntryActivity.delete_all | |
711 |
|
722 | |||
712 | # No activities |
|
723 | # No activities | |
713 | project = Project.find(1) |
|
724 | project = Project.find(1) | |
714 | assert project.activities.empty? |
|
725 | assert project.activities.empty? | |
715 |
|
726 | |||
716 | # No system, one overridden |
|
727 | # No system, one overridden | |
717 | assert overridden_activity.save! |
|
728 | assert overridden_activity.save! | |
718 | project.reload |
|
729 | project.reload | |
719 | assert_equal [overridden_activity], project.activities |
|
730 | assert_equal [overridden_activity], project.activities | |
720 | end |
|
731 | end | |
721 |
|
732 | |||
722 | def test_activities_should_override_system_activities_with_project_activities |
|
733 | def test_activities_should_override_system_activities_with_project_activities | |
723 | project = Project.find(1) |
|
734 | project = Project.find(1) | |
724 | parent_activity = TimeEntryActivity.find(:first) |
|
735 | parent_activity = TimeEntryActivity.find(:first) | |
725 | overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project, :parent => parent_activity}) |
|
736 | overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project, :parent => parent_activity}) | |
726 | assert overridden_activity.save! |
|
737 | assert overridden_activity.save! | |
727 |
|
738 | |||
728 | assert project.activities.include?(overridden_activity), "Project specific Activity not found" |
|
739 | assert project.activities.include?(overridden_activity), "Project specific Activity not found" | |
729 | assert !project.activities.include?(parent_activity), "System Activity found when it should have been overridden" |
|
740 | assert !project.activities.include?(parent_activity), "System Activity found when it should have been overridden" | |
730 | end |
|
741 | end | |
731 |
|
742 | |||
732 | def test_activities_should_include_inactive_activities_if_specified |
|
743 | def test_activities_should_include_inactive_activities_if_specified | |
733 | project = Project.find(1) |
|
744 | project = Project.find(1) | |
734 | overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project, :parent => TimeEntryActivity.find(:first), :active => false}) |
|
745 | overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project, :parent => TimeEntryActivity.find(:first), :active => false}) | |
735 | assert overridden_activity.save! |
|
746 | assert overridden_activity.save! | |
736 |
|
747 | |||
737 | assert project.activities(true).include?(overridden_activity), "Inactive Project specific Activity not found" |
|
748 | assert project.activities(true).include?(overridden_activity), "Inactive Project specific Activity not found" | |
738 | end |
|
749 | end | |
739 |
|
750 | |||
740 | test 'activities should not include active System activities if the project has an override that is inactive' do |
|
751 | test 'activities should not include active System activities if the project has an override that is inactive' do | |
741 | project = Project.find(1) |
|
752 | project = Project.find(1) | |
742 | system_activity = TimeEntryActivity.find_by_name('Design') |
|
753 | system_activity = TimeEntryActivity.find_by_name('Design') | |
743 | assert system_activity.active? |
|
754 | assert system_activity.active? | |
744 | overridden_activity = TimeEntryActivity.generate!(:project => project, :parent => system_activity, :active => false) |
|
755 | overridden_activity = TimeEntryActivity.generate!(:project => project, :parent => system_activity, :active => false) | |
745 | assert overridden_activity.save! |
|
756 | assert overridden_activity.save! | |
746 |
|
757 | |||
747 | assert !project.activities.include?(overridden_activity), "Inactive Project specific Activity not found" |
|
758 | assert !project.activities.include?(overridden_activity), "Inactive Project specific Activity not found" | |
748 | assert !project.activities.include?(system_activity), "System activity found when the project has an inactive override" |
|
759 | assert !project.activities.include?(system_activity), "System activity found when the project has an inactive override" | |
749 | end |
|
760 | end | |
750 |
|
761 | |||
751 | def test_close_completed_versions |
|
762 | def test_close_completed_versions | |
752 | Version.update_all("status = 'open'") |
|
763 | Version.update_all("status = 'open'") | |
753 | project = Project.find(1) |
|
764 | project = Project.find(1) | |
754 | assert_not_nil project.versions.detect {|v| v.completed? && v.status == 'open'} |
|
765 | assert_not_nil project.versions.detect {|v| v.completed? && v.status == 'open'} | |
755 | assert_not_nil project.versions.detect {|v| !v.completed? && v.status == 'open'} |
|
766 | assert_not_nil project.versions.detect {|v| !v.completed? && v.status == 'open'} | |
756 | project.close_completed_versions |
|
767 | project.close_completed_versions | |
757 | project.reload |
|
768 | project.reload | |
758 | assert_nil project.versions.detect {|v| v.completed? && v.status != 'closed'} |
|
769 | assert_nil project.versions.detect {|v| v.completed? && v.status != 'closed'} | |
759 | assert_not_nil project.versions.detect {|v| !v.completed? && v.status == 'open'} |
|
770 | assert_not_nil project.versions.detect {|v| !v.completed? && v.status == 'open'} | |
760 | end |
|
771 | end | |
761 |
|
772 | |||
762 | context "Project#copy" do |
|
773 | context "Project#copy" do | |
763 | setup do |
|
774 | setup do | |
764 | ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests |
|
775 | ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests | |
765 | Project.destroy_all :identifier => "copy-test" |
|
776 | Project.destroy_all :identifier => "copy-test" | |
766 | @source_project = Project.find(2) |
|
777 | @source_project = Project.find(2) | |
767 | @project = Project.new(:name => 'Copy Test', :identifier => 'copy-test') |
|
778 | @project = Project.new(:name => 'Copy Test', :identifier => 'copy-test') | |
768 | @project.trackers = @source_project.trackers |
|
779 | @project.trackers = @source_project.trackers | |
769 | @project.enabled_module_names = @source_project.enabled_modules.collect(&:name) |
|
780 | @project.enabled_module_names = @source_project.enabled_modules.collect(&:name) | |
770 | end |
|
781 | end | |
771 |
|
782 | |||
772 | should "copy issues" do |
|
783 | should "copy issues" do | |
773 | @source_project.issues << Issue.generate!(:status => IssueStatus.find_by_name('Closed'), |
|
784 | @source_project.issues << Issue.generate!(:status => IssueStatus.find_by_name('Closed'), | |
774 | :subject => "copy issue status", |
|
785 | :subject => "copy issue status", | |
775 | :tracker_id => 1, |
|
786 | :tracker_id => 1, | |
776 | :assigned_to_id => 2, |
|
787 | :assigned_to_id => 2, | |
777 | :project_id => @source_project.id) |
|
788 | :project_id => @source_project.id) | |
778 | assert @project.valid? |
|
789 | assert @project.valid? | |
779 | assert @project.issues.empty? |
|
790 | assert @project.issues.empty? | |
780 | assert @project.copy(@source_project) |
|
791 | assert @project.copy(@source_project) | |
781 |
|
792 | |||
782 | assert_equal @source_project.issues.size, @project.issues.size |
|
793 | assert_equal @source_project.issues.size, @project.issues.size | |
783 | @project.issues.each do |issue| |
|
794 | @project.issues.each do |issue| | |
784 | assert issue.valid? |
|
795 | assert issue.valid? | |
785 | assert ! issue.assigned_to.blank? |
|
796 | assert ! issue.assigned_to.blank? | |
786 | assert_equal @project, issue.project |
|
797 | assert_equal @project, issue.project | |
787 | end |
|
798 | end | |
788 |
|
799 | |||
789 | copied_issue = @project.issues.first(:conditions => {:subject => "copy issue status"}) |
|
800 | copied_issue = @project.issues.first(:conditions => {:subject => "copy issue status"}) | |
790 | assert copied_issue |
|
801 | assert copied_issue | |
791 | assert copied_issue.status |
|
802 | assert copied_issue.status | |
792 | assert_equal "Closed", copied_issue.status.name |
|
803 | assert_equal "Closed", copied_issue.status.name | |
793 | end |
|
804 | end | |
794 |
|
805 | |||
795 | should "change the new issues to use the copied version" do |
|
806 | should "change the new issues to use the copied version" do | |
796 | User.current = User.find(1) |
|
807 | User.current = User.find(1) | |
797 | assigned_version = Version.generate!(:name => "Assigned Issues", :status => 'open') |
|
808 | assigned_version = Version.generate!(:name => "Assigned Issues", :status => 'open') | |
798 | @source_project.versions << assigned_version |
|
809 | @source_project.versions << assigned_version | |
799 | assert_equal 3, @source_project.versions.size |
|
810 | assert_equal 3, @source_project.versions.size | |
800 | Issue.generate_for_project!(@source_project, |
|
811 | Issue.generate_for_project!(@source_project, | |
801 | :fixed_version_id => assigned_version.id, |
|
812 | :fixed_version_id => assigned_version.id, | |
802 | :subject => "change the new issues to use the copied version", |
|
813 | :subject => "change the new issues to use the copied version", | |
803 | :tracker_id => 1, |
|
814 | :tracker_id => 1, | |
804 | :project_id => @source_project.id) |
|
815 | :project_id => @source_project.id) | |
805 |
|
816 | |||
806 | assert @project.copy(@source_project) |
|
817 | assert @project.copy(@source_project) | |
807 | @project.reload |
|
818 | @project.reload | |
808 | copied_issue = @project.issues.first(:conditions => {:subject => "change the new issues to use the copied version"}) |
|
819 | copied_issue = @project.issues.first(:conditions => {:subject => "change the new issues to use the copied version"}) | |
809 |
|
820 | |||
810 | assert copied_issue |
|
821 | assert copied_issue | |
811 | assert copied_issue.fixed_version |
|
822 | assert copied_issue.fixed_version | |
812 | assert_equal "Assigned Issues", copied_issue.fixed_version.name # Same name |
|
823 | assert_equal "Assigned Issues", copied_issue.fixed_version.name # Same name | |
813 | assert_not_equal assigned_version.id, copied_issue.fixed_version.id # Different record |
|
824 | assert_not_equal assigned_version.id, copied_issue.fixed_version.id # Different record | |
814 | end |
|
825 | end | |
815 |
|
826 | |||
816 | should "copy issue relations" do |
|
827 | should "copy issue relations" do | |
817 | Setting.cross_project_issue_relations = '1' |
|
828 | Setting.cross_project_issue_relations = '1' | |
818 |
|
829 | |||
819 | second_issue = Issue.generate!(:status_id => 5, |
|
830 | second_issue = Issue.generate!(:status_id => 5, | |
820 | :subject => "copy issue relation", |
|
831 | :subject => "copy issue relation", | |
821 | :tracker_id => 1, |
|
832 | :tracker_id => 1, | |
822 | :assigned_to_id => 2, |
|
833 | :assigned_to_id => 2, | |
823 | :project_id => @source_project.id) |
|
834 | :project_id => @source_project.id) | |
824 | source_relation = IssueRelation.generate!(:issue_from => Issue.find(4), |
|
835 | source_relation = IssueRelation.generate!(:issue_from => Issue.find(4), | |
825 | :issue_to => second_issue, |
|
836 | :issue_to => second_issue, | |
826 | :relation_type => "relates") |
|
837 | :relation_type => "relates") | |
827 | source_relation_cross_project = IssueRelation.generate!(:issue_from => Issue.find(1), |
|
838 | source_relation_cross_project = IssueRelation.generate!(:issue_from => Issue.find(1), | |
828 | :issue_to => second_issue, |
|
839 | :issue_to => second_issue, | |
829 | :relation_type => "duplicates") |
|
840 | :relation_type => "duplicates") | |
830 |
|
841 | |||
831 | assert @project.copy(@source_project) |
|
842 | assert @project.copy(@source_project) | |
832 | assert_equal @source_project.issues.count, @project.issues.count |
|
843 | assert_equal @source_project.issues.count, @project.issues.count | |
833 | copied_issue = @project.issues.find_by_subject("Issue on project 2") # Was #4 |
|
844 | copied_issue = @project.issues.find_by_subject("Issue on project 2") # Was #4 | |
834 | copied_second_issue = @project.issues.find_by_subject("copy issue relation") |
|
845 | copied_second_issue = @project.issues.find_by_subject("copy issue relation") | |
835 |
|
846 | |||
836 | # First issue with a relation on project |
|
847 | # First issue with a relation on project | |
837 | assert_equal 1, copied_issue.relations.size, "Relation not copied" |
|
848 | assert_equal 1, copied_issue.relations.size, "Relation not copied" | |
838 | copied_relation = copied_issue.relations.first |
|
849 | copied_relation = copied_issue.relations.first | |
839 | assert_equal "relates", copied_relation.relation_type |
|
850 | assert_equal "relates", copied_relation.relation_type | |
840 | assert_equal copied_second_issue.id, copied_relation.issue_to_id |
|
851 | assert_equal copied_second_issue.id, copied_relation.issue_to_id | |
841 | assert_not_equal source_relation.id, copied_relation.id |
|
852 | assert_not_equal source_relation.id, copied_relation.id | |
842 |
|
853 | |||
843 | # Second issue with a cross project relation |
|
854 | # Second issue with a cross project relation | |
844 | assert_equal 2, copied_second_issue.relations.size, "Relation not copied" |
|
855 | assert_equal 2, copied_second_issue.relations.size, "Relation not copied" | |
845 | copied_relation = copied_second_issue.relations.select {|r| r.relation_type == 'duplicates'}.first |
|
856 | copied_relation = copied_second_issue.relations.select {|r| r.relation_type == 'duplicates'}.first | |
846 | assert_equal "duplicates", copied_relation.relation_type |
|
857 | assert_equal "duplicates", copied_relation.relation_type | |
847 | assert_equal 1, copied_relation.issue_from_id, "Cross project relation not kept" |
|
858 | assert_equal 1, copied_relation.issue_from_id, "Cross project relation not kept" | |
848 | assert_not_equal source_relation_cross_project.id, copied_relation.id |
|
859 | assert_not_equal source_relation_cross_project.id, copied_relation.id | |
849 | end |
|
860 | end | |
850 |
|
861 | |||
851 | should "copy memberships" do |
|
862 | should "copy memberships" do | |
852 | assert @project.valid? |
|
863 | assert @project.valid? | |
853 | assert @project.members.empty? |
|
864 | assert @project.members.empty? | |
854 | assert @project.copy(@source_project) |
|
865 | assert @project.copy(@source_project) | |
855 |
|
866 | |||
856 | assert_equal @source_project.memberships.size, @project.memberships.size |
|
867 | assert_equal @source_project.memberships.size, @project.memberships.size | |
857 | @project.memberships.each do |membership| |
|
868 | @project.memberships.each do |membership| | |
858 | assert membership |
|
869 | assert membership | |
859 | assert_equal @project, membership.project |
|
870 | assert_equal @project, membership.project | |
860 | end |
|
871 | end | |
861 | end |
|
872 | end | |
862 |
|
873 | |||
863 | should "copy memberships with groups and additional roles" do |
|
874 | should "copy memberships with groups and additional roles" do | |
864 | group = Group.create!(:lastname => "Copy group") |
|
875 | group = Group.create!(:lastname => "Copy group") | |
865 | user = User.find(7) |
|
876 | user = User.find(7) | |
866 | group.users << user |
|
877 | group.users << user | |
867 | # group role |
|
878 | # group role | |
868 | Member.create!(:project_id => @source_project.id, :principal => group, :role_ids => [2]) |
|
879 | Member.create!(:project_id => @source_project.id, :principal => group, :role_ids => [2]) | |
869 | member = Member.find_by_user_id_and_project_id(user.id, @source_project.id) |
|
880 | member = Member.find_by_user_id_and_project_id(user.id, @source_project.id) | |
870 | # additional role |
|
881 | # additional role | |
871 | member.role_ids = [1] |
|
882 | member.role_ids = [1] | |
872 |
|
883 | |||
873 | assert @project.copy(@source_project) |
|
884 | assert @project.copy(@source_project) | |
874 | member = Member.find_by_user_id_and_project_id(user.id, @project.id) |
|
885 | member = Member.find_by_user_id_and_project_id(user.id, @project.id) | |
875 | assert_not_nil member |
|
886 | assert_not_nil member | |
876 | assert_equal [1, 2], member.role_ids.sort |
|
887 | assert_equal [1, 2], member.role_ids.sort | |
877 | end |
|
888 | end | |
878 |
|
889 | |||
879 | should "copy project specific queries" do |
|
890 | should "copy project specific queries" do | |
880 | assert @project.valid? |
|
891 | assert @project.valid? | |
881 | assert @project.queries.empty? |
|
892 | assert @project.queries.empty? | |
882 | assert @project.copy(@source_project) |
|
893 | assert @project.copy(@source_project) | |
883 |
|
894 | |||
884 | assert_equal @source_project.queries.size, @project.queries.size |
|
895 | assert_equal @source_project.queries.size, @project.queries.size | |
885 | @project.queries.each do |query| |
|
896 | @project.queries.each do |query| | |
886 | assert query |
|
897 | assert query | |
887 | assert_equal @project, query.project |
|
898 | assert_equal @project, query.project | |
888 | end |
|
899 | end | |
889 | end |
|
900 | end | |
890 |
|
901 | |||
891 | should "copy versions" do |
|
902 | should "copy versions" do | |
892 | @source_project.versions << Version.generate! |
|
903 | @source_project.versions << Version.generate! | |
893 | @source_project.versions << Version.generate! |
|
904 | @source_project.versions << Version.generate! | |
894 |
|
905 | |||
895 | assert @project.versions.empty? |
|
906 | assert @project.versions.empty? | |
896 | assert @project.copy(@source_project) |
|
907 | assert @project.copy(@source_project) | |
897 |
|
908 | |||
898 | assert_equal @source_project.versions.size, @project.versions.size |
|
909 | assert_equal @source_project.versions.size, @project.versions.size | |
899 | @project.versions.each do |version| |
|
910 | @project.versions.each do |version| | |
900 | assert version |
|
911 | assert version | |
901 | assert_equal @project, version.project |
|
912 | assert_equal @project, version.project | |
902 | end |
|
913 | end | |
903 | end |
|
914 | end | |
904 |
|
915 | |||
905 | should "copy wiki" do |
|
916 | should "copy wiki" do | |
906 | assert_difference 'Wiki.count' do |
|
917 | assert_difference 'Wiki.count' do | |
907 | assert @project.copy(@source_project) |
|
918 | assert @project.copy(@source_project) | |
908 | end |
|
919 | end | |
909 |
|
920 | |||
910 | assert @project.wiki |
|
921 | assert @project.wiki | |
911 | assert_not_equal @source_project.wiki, @project.wiki |
|
922 | assert_not_equal @source_project.wiki, @project.wiki | |
912 | assert_equal "Start page", @project.wiki.start_page |
|
923 | assert_equal "Start page", @project.wiki.start_page | |
913 | end |
|
924 | end | |
914 |
|
925 | |||
915 | should "copy wiki pages and content with hierarchy" do |
|
926 | should "copy wiki pages and content with hierarchy" do | |
916 | assert_difference 'WikiPage.count', @source_project.wiki.pages.size do |
|
927 | assert_difference 'WikiPage.count', @source_project.wiki.pages.size do | |
917 | assert @project.copy(@source_project) |
|
928 | assert @project.copy(@source_project) | |
918 | end |
|
929 | end | |
919 |
|
930 | |||
920 | assert @project.wiki |
|
931 | assert @project.wiki | |
921 | assert_equal @source_project.wiki.pages.size, @project.wiki.pages.size |
|
932 | assert_equal @source_project.wiki.pages.size, @project.wiki.pages.size | |
922 |
|
933 | |||
923 | @project.wiki.pages.each do |wiki_page| |
|
934 | @project.wiki.pages.each do |wiki_page| | |
924 | assert wiki_page.content |
|
935 | assert wiki_page.content | |
925 | assert !@source_project.wiki.pages.include?(wiki_page) |
|
936 | assert !@source_project.wiki.pages.include?(wiki_page) | |
926 | end |
|
937 | end | |
927 |
|
938 | |||
928 | parent = @project.wiki.find_page('Parent_page') |
|
939 | parent = @project.wiki.find_page('Parent_page') | |
929 | child1 = @project.wiki.find_page('Child_page_1') |
|
940 | child1 = @project.wiki.find_page('Child_page_1') | |
930 | child2 = @project.wiki.find_page('Child_page_2') |
|
941 | child2 = @project.wiki.find_page('Child_page_2') | |
931 | assert_equal parent, child1.parent |
|
942 | assert_equal parent, child1.parent | |
932 | assert_equal parent, child2.parent |
|
943 | assert_equal parent, child2.parent | |
933 | end |
|
944 | end | |
934 |
|
945 | |||
935 | should "copy issue categories" do |
|
946 | should "copy issue categories" do | |
936 | assert @project.copy(@source_project) |
|
947 | assert @project.copy(@source_project) | |
937 |
|
948 | |||
938 | assert_equal 2, @project.issue_categories.size |
|
949 | assert_equal 2, @project.issue_categories.size | |
939 | @project.issue_categories.each do |issue_category| |
|
950 | @project.issue_categories.each do |issue_category| | |
940 | assert !@source_project.issue_categories.include?(issue_category) |
|
951 | assert !@source_project.issue_categories.include?(issue_category) | |
941 | end |
|
952 | end | |
942 | end |
|
953 | end | |
943 |
|
954 | |||
944 | should "copy boards" do |
|
955 | should "copy boards" do | |
945 | assert @project.copy(@source_project) |
|
956 | assert @project.copy(@source_project) | |
946 |
|
957 | |||
947 | assert_equal 1, @project.boards.size |
|
958 | assert_equal 1, @project.boards.size | |
948 | @project.boards.each do |board| |
|
959 | @project.boards.each do |board| | |
949 | assert !@source_project.boards.include?(board) |
|
960 | assert !@source_project.boards.include?(board) | |
950 | end |
|
961 | end | |
951 | end |
|
962 | end | |
952 |
|
963 | |||
953 | should "change the new issues to use the copied issue categories" do |
|
964 | should "change the new issues to use the copied issue categories" do | |
954 | issue = Issue.find(4) |
|
965 | issue = Issue.find(4) | |
955 | issue.update_attribute(:category_id, 3) |
|
966 | issue.update_attribute(:category_id, 3) | |
956 |
|
967 | |||
957 | assert @project.copy(@source_project) |
|
968 | assert @project.copy(@source_project) | |
958 |
|
969 | |||
959 | @project.issues.each do |issue| |
|
970 | @project.issues.each do |issue| | |
960 | assert issue.category |
|
971 | assert issue.category | |
961 | assert_equal "Stock management", issue.category.name # Same name |
|
972 | assert_equal "Stock management", issue.category.name # Same name | |
962 | assert_not_equal IssueCategory.find(3), issue.category # Different record |
|
973 | assert_not_equal IssueCategory.find(3), issue.category # Different record | |
963 | end |
|
974 | end | |
964 | end |
|
975 | end | |
965 |
|
976 | |||
966 | should "limit copy with :only option" do |
|
977 | should "limit copy with :only option" do | |
967 | assert @project.members.empty? |
|
978 | assert @project.members.empty? | |
968 | assert @project.issue_categories.empty? |
|
979 | assert @project.issue_categories.empty? | |
969 | assert @source_project.issues.any? |
|
980 | assert @source_project.issues.any? | |
970 |
|
981 | |||
971 | assert @project.copy(@source_project, :only => ['members', 'issue_categories']) |
|
982 | assert @project.copy(@source_project, :only => ['members', 'issue_categories']) | |
972 |
|
983 | |||
973 | assert @project.members.any? |
|
984 | assert @project.members.any? | |
974 | assert @project.issue_categories.any? |
|
985 | assert @project.issue_categories.any? | |
975 | assert @project.issues.empty? |
|
986 | assert @project.issues.empty? | |
976 | end |
|
987 | end | |
977 |
|
988 | |||
978 | end |
|
989 | end | |
979 |
|
990 | |||
980 | context "#start_date" do |
|
991 | context "#start_date" do | |
981 | setup do |
|
992 | setup do | |
982 | ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests |
|
993 | ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests | |
983 | @project = Project.generate!(:identifier => 'test0') |
|
994 | @project = Project.generate!(:identifier => 'test0') | |
984 | @project.trackers << Tracker.generate! |
|
995 | @project.trackers << Tracker.generate! | |
985 | end |
|
996 | end | |
986 |
|
997 | |||
987 | should "be nil if there are no issues on the project" do |
|
998 | should "be nil if there are no issues on the project" do | |
988 | assert_nil @project.start_date |
|
999 | assert_nil @project.start_date | |
989 | end |
|
1000 | end | |
990 |
|
1001 | |||
991 | should "be tested when issues have no start date" |
|
1002 | should "be tested when issues have no start date" | |
992 |
|
1003 | |||
993 | should "be the earliest start date of it's issues" do |
|
1004 | should "be the earliest start date of it's issues" do | |
994 | early = 7.days.ago.to_date |
|
1005 | early = 7.days.ago.to_date | |
995 | Issue.generate_for_project!(@project, :start_date => Date.today) |
|
1006 | Issue.generate_for_project!(@project, :start_date => Date.today) | |
996 | Issue.generate_for_project!(@project, :start_date => early) |
|
1007 | Issue.generate_for_project!(@project, :start_date => early) | |
997 |
|
1008 | |||
998 | assert_equal early, @project.start_date |
|
1009 | assert_equal early, @project.start_date | |
999 | end |
|
1010 | end | |
1000 |
|
1011 | |||
1001 | end |
|
1012 | end | |
1002 |
|
1013 | |||
1003 | context "#due_date" do |
|
1014 | context "#due_date" do | |
1004 | setup do |
|
1015 | setup do | |
1005 | ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests |
|
1016 | ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests | |
1006 | @project = Project.generate!(:identifier => 'test0') |
|
1017 | @project = Project.generate!(:identifier => 'test0') | |
1007 | @project.trackers << Tracker.generate! |
|
1018 | @project.trackers << Tracker.generate! | |
1008 | end |
|
1019 | end | |
1009 |
|
1020 | |||
1010 | should "be nil if there are no issues on the project" do |
|
1021 | should "be nil if there are no issues on the project" do | |
1011 | assert_nil @project.due_date |
|
1022 | assert_nil @project.due_date | |
1012 | end |
|
1023 | end | |
1013 |
|
1024 | |||
1014 | should "be tested when issues have no due date" |
|
1025 | should "be tested when issues have no due date" | |
1015 |
|
1026 | |||
1016 | should "be the latest due date of it's issues" do |
|
1027 | should "be the latest due date of it's issues" do | |
1017 | future = 7.days.from_now.to_date |
|
1028 | future = 7.days.from_now.to_date | |
1018 | Issue.generate_for_project!(@project, :due_date => future) |
|
1029 | Issue.generate_for_project!(@project, :due_date => future) | |
1019 | Issue.generate_for_project!(@project, :due_date => Date.today) |
|
1030 | Issue.generate_for_project!(@project, :due_date => Date.today) | |
1020 |
|
1031 | |||
1021 | assert_equal future, @project.due_date |
|
1032 | assert_equal future, @project.due_date | |
1022 | end |
|
1033 | end | |
1023 |
|
1034 | |||
1024 | should "be the latest due date of it's versions" do |
|
1035 | should "be the latest due date of it's versions" do | |
1025 | future = 7.days.from_now.to_date |
|
1036 | future = 7.days.from_now.to_date | |
1026 | @project.versions << Version.generate!(:effective_date => future) |
|
1037 | @project.versions << Version.generate!(:effective_date => future) | |
1027 | @project.versions << Version.generate!(:effective_date => Date.today) |
|
1038 | @project.versions << Version.generate!(:effective_date => Date.today) | |
1028 |
|
1039 | |||
1029 |
|
1040 | |||
1030 | assert_equal future, @project.due_date |
|
1041 | assert_equal future, @project.due_date | |
1031 |
|
1042 | |||
1032 | end |
|
1043 | end | |
1033 |
|
1044 | |||
1034 | should "pick the latest date from it's issues and versions" do |
|
1045 | should "pick the latest date from it's issues and versions" do | |
1035 | future = 7.days.from_now.to_date |
|
1046 | future = 7.days.from_now.to_date | |
1036 | far_future = 14.days.from_now.to_date |
|
1047 | far_future = 14.days.from_now.to_date | |
1037 | Issue.generate_for_project!(@project, :due_date => far_future) |
|
1048 | Issue.generate_for_project!(@project, :due_date => far_future) | |
1038 | @project.versions << Version.generate!(:effective_date => future) |
|
1049 | @project.versions << Version.generate!(:effective_date => future) | |
1039 |
|
1050 | |||
1040 | assert_equal far_future, @project.due_date |
|
1051 | assert_equal far_future, @project.due_date | |
1041 | end |
|
1052 | end | |
1042 |
|
1053 | |||
1043 | end |
|
1054 | end | |
1044 |
|
1055 | |||
1045 | context "Project#completed_percent" do |
|
1056 | context "Project#completed_percent" do | |
1046 | setup do |
|
1057 | setup do | |
1047 | ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests |
|
1058 | ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests | |
1048 | @project = Project.generate!(:identifier => 'test0') |
|
1059 | @project = Project.generate!(:identifier => 'test0') | |
1049 | @project.trackers << Tracker.generate! |
|
1060 | @project.trackers << Tracker.generate! | |
1050 | end |
|
1061 | end | |
1051 |
|
1062 | |||
1052 | context "no versions" do |
|
1063 | context "no versions" do | |
1053 | should "be 100" do |
|
1064 | should "be 100" do | |
1054 | assert_equal 100, @project.completed_percent |
|
1065 | assert_equal 100, @project.completed_percent | |
1055 | end |
|
1066 | end | |
1056 | end |
|
1067 | end | |
1057 |
|
1068 | |||
1058 | context "with versions" do |
|
1069 | context "with versions" do | |
1059 | should "return 0 if the versions have no issues" do |
|
1070 | should "return 0 if the versions have no issues" do | |
1060 | Version.generate!(:project => @project) |
|
1071 | Version.generate!(:project => @project) | |
1061 | Version.generate!(:project => @project) |
|
1072 | Version.generate!(:project => @project) | |
1062 |
|
1073 | |||
1063 | assert_equal 0, @project.completed_percent |
|
1074 | assert_equal 0, @project.completed_percent | |
1064 | end |
|
1075 | end | |
1065 |
|
1076 | |||
1066 | should "return 100 if the version has only closed issues" do |
|
1077 | should "return 100 if the version has only closed issues" do | |
1067 | v1 = Version.generate!(:project => @project) |
|
1078 | v1 = Version.generate!(:project => @project) | |
1068 | Issue.generate_for_project!(@project, :status => IssueStatus.find_by_name('Closed'), :fixed_version => v1) |
|
1079 | Issue.generate_for_project!(@project, :status => IssueStatus.find_by_name('Closed'), :fixed_version => v1) | |
1069 | v2 = Version.generate!(:project => @project) |
|
1080 | v2 = Version.generate!(:project => @project) | |
1070 | Issue.generate_for_project!(@project, :status => IssueStatus.find_by_name('Closed'), :fixed_version => v2) |
|
1081 | Issue.generate_for_project!(@project, :status => IssueStatus.find_by_name('Closed'), :fixed_version => v2) | |
1071 |
|
1082 | |||
1072 | assert_equal 100, @project.completed_percent |
|
1083 | assert_equal 100, @project.completed_percent | |
1073 | end |
|
1084 | end | |
1074 |
|
1085 | |||
1075 | should "return the averaged completed percent of the versions (not weighted)" do |
|
1086 | should "return the averaged completed percent of the versions (not weighted)" do | |
1076 | v1 = Version.generate!(:project => @project) |
|
1087 | v1 = Version.generate!(:project => @project) | |
1077 | Issue.generate_for_project!(@project, :status => IssueStatus.find_by_name('New'), :estimated_hours => 10, :done_ratio => 50, :fixed_version => v1) |
|
1088 | Issue.generate_for_project!(@project, :status => IssueStatus.find_by_name('New'), :estimated_hours => 10, :done_ratio => 50, :fixed_version => v1) | |
1078 | v2 = Version.generate!(:project => @project) |
|
1089 | v2 = Version.generate!(:project => @project) | |
1079 | Issue.generate_for_project!(@project, :status => IssueStatus.find_by_name('New'), :estimated_hours => 10, :done_ratio => 50, :fixed_version => v2) |
|
1090 | Issue.generate_for_project!(@project, :status => IssueStatus.find_by_name('New'), :estimated_hours => 10, :done_ratio => 50, :fixed_version => v2) | |
1080 |
|
1091 | |||
1081 | assert_equal 50, @project.completed_percent |
|
1092 | assert_equal 50, @project.completed_percent | |
1082 | end |
|
1093 | end | |
1083 |
|
1094 | |||
1084 | end |
|
1095 | end | |
1085 | end |
|
1096 | end | |
1086 |
|
1097 | |||
1087 | context "#notified_users" do |
|
1098 | context "#notified_users" do | |
1088 | setup do |
|
1099 | setup do | |
1089 | @project = Project.generate! |
|
1100 | @project = Project.generate! | |
1090 | @role = Role.generate! |
|
1101 | @role = Role.generate! | |
1091 |
|
1102 | |||
1092 | @user_with_membership_notification = User.generate!(:mail_notification => 'selected') |
|
1103 | @user_with_membership_notification = User.generate!(:mail_notification => 'selected') | |
1093 | Member.generate!(:project => @project, :roles => [@role], :principal => @user_with_membership_notification, :mail_notification => true) |
|
1104 | Member.generate!(:project => @project, :roles => [@role], :principal => @user_with_membership_notification, :mail_notification => true) | |
1094 |
|
1105 | |||
1095 | @all_events_user = User.generate!(:mail_notification => 'all') |
|
1106 | @all_events_user = User.generate!(:mail_notification => 'all') | |
1096 | Member.generate!(:project => @project, :roles => [@role], :principal => @all_events_user) |
|
1107 | Member.generate!(:project => @project, :roles => [@role], :principal => @all_events_user) | |
1097 |
|
1108 | |||
1098 | @no_events_user = User.generate!(:mail_notification => 'none') |
|
1109 | @no_events_user = User.generate!(:mail_notification => 'none') | |
1099 | Member.generate!(:project => @project, :roles => [@role], :principal => @no_events_user) |
|
1110 | Member.generate!(:project => @project, :roles => [@role], :principal => @no_events_user) | |
1100 |
|
1111 | |||
1101 | @only_my_events_user = User.generate!(:mail_notification => 'only_my_events') |
|
1112 | @only_my_events_user = User.generate!(:mail_notification => 'only_my_events') | |
1102 | Member.generate!(:project => @project, :roles => [@role], :principal => @only_my_events_user) |
|
1113 | Member.generate!(:project => @project, :roles => [@role], :principal => @only_my_events_user) | |
1103 |
|
1114 | |||
1104 | @only_assigned_user = User.generate!(:mail_notification => 'only_assigned') |
|
1115 | @only_assigned_user = User.generate!(:mail_notification => 'only_assigned') | |
1105 | Member.generate!(:project => @project, :roles => [@role], :principal => @only_assigned_user) |
|
1116 | Member.generate!(:project => @project, :roles => [@role], :principal => @only_assigned_user) | |
1106 |
|
1117 | |||
1107 | @only_owned_user = User.generate!(:mail_notification => 'only_owner') |
|
1118 | @only_owned_user = User.generate!(:mail_notification => 'only_owner') | |
1108 | Member.generate!(:project => @project, :roles => [@role], :principal => @only_owned_user) |
|
1119 | Member.generate!(:project => @project, :roles => [@role], :principal => @only_owned_user) | |
1109 | end |
|
1120 | end | |
1110 |
|
1121 | |||
1111 | should "include members with a mail notification" do |
|
1122 | should "include members with a mail notification" do | |
1112 | assert @project.notified_users.include?(@user_with_membership_notification) |
|
1123 | assert @project.notified_users.include?(@user_with_membership_notification) | |
1113 | end |
|
1124 | end | |
1114 |
|
1125 | |||
1115 | should "include users with the 'all' notification option" do |
|
1126 | should "include users with the 'all' notification option" do | |
1116 | assert @project.notified_users.include?(@all_events_user) |
|
1127 | assert @project.notified_users.include?(@all_events_user) | |
1117 | end |
|
1128 | end | |
1118 |
|
1129 | |||
1119 | should "not include users with the 'none' notification option" do |
|
1130 | should "not include users with the 'none' notification option" do | |
1120 | assert !@project.notified_users.include?(@no_events_user) |
|
1131 | assert !@project.notified_users.include?(@no_events_user) | |
1121 | end |
|
1132 | end | |
1122 |
|
1133 | |||
1123 | should "not include users with the 'only_my_events' notification option" do |
|
1134 | should "not include users with the 'only_my_events' notification option" do | |
1124 | assert !@project.notified_users.include?(@only_my_events_user) |
|
1135 | assert !@project.notified_users.include?(@only_my_events_user) | |
1125 | end |
|
1136 | end | |
1126 |
|
1137 | |||
1127 | should "not include users with the 'only_assigned' notification option" do |
|
1138 | should "not include users with the 'only_assigned' notification option" do | |
1128 | assert !@project.notified_users.include?(@only_assigned_user) |
|
1139 | assert !@project.notified_users.include?(@only_assigned_user) | |
1129 | end |
|
1140 | end | |
1130 |
|
1141 | |||
1131 | should "not include users with the 'only_owner' notification option" do |
|
1142 | should "not include users with the 'only_owner' notification option" do | |
1132 | assert !@project.notified_users.include?(@only_owned_user) |
|
1143 | assert !@project.notified_users.include?(@only_owned_user) | |
1133 | end |
|
1144 | end | |
1134 | end |
|
1145 | end | |
1135 |
|
1146 | |||
1136 | end |
|
1147 | end |
General Comments 0
You need to be logged in to leave comments.
Login now