@@ -1,953 +1,954 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2014 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2014 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 :projects, :trackers, :issue_statuses, :issues, |
|
21 | fixtures :projects, :trackers, :issue_statuses, :issues, | |
22 | :journals, :journal_details, |
|
22 | :journals, :journal_details, | |
23 | :enumerations, :users, :issue_categories, |
|
23 | :enumerations, :users, :issue_categories, | |
24 | :projects_trackers, |
|
24 | :projects_trackers, | |
25 | :custom_fields, |
|
25 | :custom_fields, | |
26 | :custom_fields_projects, |
|
26 | :custom_fields_projects, | |
27 | :custom_fields_trackers, |
|
27 | :custom_fields_trackers, | |
28 | :custom_values, |
|
28 | :custom_values, | |
29 | :roles, |
|
29 | :roles, | |
30 | :member_roles, |
|
30 | :member_roles, | |
31 | :members, |
|
31 | :members, | |
32 | :enabled_modules, |
|
32 | :enabled_modules, | |
33 | :versions, |
|
33 | :versions, | |
34 | :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions, |
|
34 | :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions, | |
35 | :groups_users, |
|
35 | :groups_users, | |
36 | :boards, :messages, |
|
36 | :boards, :messages, | |
37 | :repositories, |
|
37 | :repositories, | |
38 | :news, :comments, |
|
38 | :news, :comments, | |
39 | :documents |
|
39 | :documents, | |
|
40 | :workflows | |||
40 |
|
41 | |||
41 | def setup |
|
42 | def setup | |
42 | @ecookbook = Project.find(1) |
|
43 | @ecookbook = Project.find(1) | |
43 | @ecookbook_sub1 = Project.find(3) |
|
44 | @ecookbook_sub1 = Project.find(3) | |
44 | set_tmp_attachments_directory |
|
45 | set_tmp_attachments_directory | |
45 | User.current = nil |
|
46 | User.current = nil | |
46 | end |
|
47 | end | |
47 |
|
48 | |||
48 | def test_truth |
|
49 | def test_truth | |
49 | assert_kind_of Project, @ecookbook |
|
50 | assert_kind_of Project, @ecookbook | |
50 | assert_equal "eCookbook", @ecookbook.name |
|
51 | assert_equal "eCookbook", @ecookbook.name | |
51 | end |
|
52 | end | |
52 |
|
53 | |||
53 | def test_default_attributes |
|
54 | def test_default_attributes | |
54 | with_settings :default_projects_public => '1' do |
|
55 | with_settings :default_projects_public => '1' do | |
55 | assert_equal true, Project.new.is_public |
|
56 | assert_equal true, Project.new.is_public | |
56 | assert_equal false, Project.new(:is_public => false).is_public |
|
57 | assert_equal false, Project.new(:is_public => false).is_public | |
57 | end |
|
58 | end | |
58 |
|
59 | |||
59 | with_settings :default_projects_public => '0' do |
|
60 | with_settings :default_projects_public => '0' do | |
60 | assert_equal false, Project.new.is_public |
|
61 | assert_equal false, Project.new.is_public | |
61 | assert_equal true, Project.new(:is_public => true).is_public |
|
62 | assert_equal true, Project.new(:is_public => true).is_public | |
62 | end |
|
63 | end | |
63 |
|
64 | |||
64 | with_settings :sequential_project_identifiers => '1' do |
|
65 | with_settings :sequential_project_identifiers => '1' do | |
65 | assert !Project.new.identifier.blank? |
|
66 | assert !Project.new.identifier.blank? | |
66 | assert Project.new(:identifier => '').identifier.blank? |
|
67 | assert Project.new(:identifier => '').identifier.blank? | |
67 | end |
|
68 | end | |
68 |
|
69 | |||
69 | with_settings :sequential_project_identifiers => '0' do |
|
70 | with_settings :sequential_project_identifiers => '0' do | |
70 | assert Project.new.identifier.blank? |
|
71 | assert Project.new.identifier.blank? | |
71 | assert !Project.new(:identifier => 'test').blank? |
|
72 | assert !Project.new(:identifier => 'test').blank? | |
72 | end |
|
73 | end | |
73 |
|
74 | |||
74 | with_settings :default_projects_modules => ['issue_tracking', 'repository'] do |
|
75 | with_settings :default_projects_modules => ['issue_tracking', 'repository'] do | |
75 | assert_equal ['issue_tracking', 'repository'], Project.new.enabled_module_names |
|
76 | assert_equal ['issue_tracking', 'repository'], Project.new.enabled_module_names | |
76 | end |
|
77 | end | |
77 | end |
|
78 | end | |
78 |
|
79 | |||
79 | def test_default_trackers_should_match_default_tracker_ids_setting |
|
80 | def test_default_trackers_should_match_default_tracker_ids_setting | |
80 | with_settings :default_projects_tracker_ids => ['1', '3'] do |
|
81 | with_settings :default_projects_tracker_ids => ['1', '3'] do | |
81 | assert_equal Tracker.find(1, 3).sort, Project.new.trackers.sort |
|
82 | assert_equal Tracker.find(1, 3).sort, Project.new.trackers.sort | |
82 | end |
|
83 | end | |
83 | end |
|
84 | end | |
84 |
|
85 | |||
85 | def test_default_trackers_should_be_all_trackers_with_blank_setting |
|
86 | def test_default_trackers_should_be_all_trackers_with_blank_setting | |
86 | with_settings :default_projects_tracker_ids => nil do |
|
87 | with_settings :default_projects_tracker_ids => nil do | |
87 | assert_equal Tracker.all.sort, Project.new.trackers.sort |
|
88 | assert_equal Tracker.all.sort, Project.new.trackers.sort | |
88 | end |
|
89 | end | |
89 | end |
|
90 | end | |
90 |
|
91 | |||
91 | def test_default_trackers_should_be_empty_with_empty_setting |
|
92 | def test_default_trackers_should_be_empty_with_empty_setting | |
92 | with_settings :default_projects_tracker_ids => [] do |
|
93 | with_settings :default_projects_tracker_ids => [] do | |
93 | assert_equal [], Project.new.trackers |
|
94 | assert_equal [], Project.new.trackers | |
94 | end |
|
95 | end | |
95 | end |
|
96 | end | |
96 |
|
97 | |||
97 | def test_default_trackers_should_not_replace_initialized_trackers |
|
98 | def test_default_trackers_should_not_replace_initialized_trackers | |
98 | with_settings :default_projects_tracker_ids => ['1', '3'] do |
|
99 | with_settings :default_projects_tracker_ids => ['1', '3'] do | |
99 | assert_equal Tracker.find(1, 2).sort, Project.new(:tracker_ids => [1, 2]).trackers.sort |
|
100 | assert_equal Tracker.find(1, 2).sort, Project.new(:tracker_ids => [1, 2]).trackers.sort | |
100 | end |
|
101 | end | |
101 | end |
|
102 | end | |
102 |
|
103 | |||
103 | def test_update |
|
104 | def test_update | |
104 | assert_equal "eCookbook", @ecookbook.name |
|
105 | assert_equal "eCookbook", @ecookbook.name | |
105 | @ecookbook.name = "eCook" |
|
106 | @ecookbook.name = "eCook" | |
106 | assert @ecookbook.save, @ecookbook.errors.full_messages.join("; ") |
|
107 | assert @ecookbook.save, @ecookbook.errors.full_messages.join("; ") | |
107 | @ecookbook.reload |
|
108 | @ecookbook.reload | |
108 | assert_equal "eCook", @ecookbook.name |
|
109 | assert_equal "eCook", @ecookbook.name | |
109 | end |
|
110 | end | |
110 |
|
111 | |||
111 | def test_validate_identifier |
|
112 | def test_validate_identifier | |
112 | to_test = {"abc" => true, |
|
113 | to_test = {"abc" => true, | |
113 | "ab12" => true, |
|
114 | "ab12" => true, | |
114 | "ab-12" => true, |
|
115 | "ab-12" => true, | |
115 | "ab_12" => true, |
|
116 | "ab_12" => true, | |
116 | "12" => false, |
|
117 | "12" => false, | |
117 | "new" => false} |
|
118 | "new" => false} | |
118 |
|
119 | |||
119 | to_test.each do |identifier, valid| |
|
120 | to_test.each do |identifier, valid| | |
120 | p = Project.new |
|
121 | p = Project.new | |
121 | p.identifier = identifier |
|
122 | p.identifier = identifier | |
122 | p.valid? |
|
123 | p.valid? | |
123 | if valid |
|
124 | if valid | |
124 | assert p.errors['identifier'].blank?, "identifier #{identifier} was not valid" |
|
125 | assert p.errors['identifier'].blank?, "identifier #{identifier} was not valid" | |
125 | else |
|
126 | else | |
126 | assert p.errors['identifier'].present?, "identifier #{identifier} was valid" |
|
127 | assert p.errors['identifier'].present?, "identifier #{identifier} was valid" | |
127 | end |
|
128 | end | |
128 | end |
|
129 | end | |
129 | end |
|
130 | end | |
130 |
|
131 | |||
131 | def test_identifier_should_not_be_frozen_for_a_new_project |
|
132 | def test_identifier_should_not_be_frozen_for_a_new_project | |
132 | assert_equal false, Project.new.identifier_frozen? |
|
133 | assert_equal false, Project.new.identifier_frozen? | |
133 | end |
|
134 | end | |
134 |
|
135 | |||
135 | def test_identifier_should_not_be_frozen_for_a_saved_project_with_blank_identifier |
|
136 | def test_identifier_should_not_be_frozen_for_a_saved_project_with_blank_identifier | |
136 | Project.where(:id => 1).update_all(["identifier = ''"]) |
|
137 | Project.where(:id => 1).update_all(["identifier = ''"]) | |
137 | assert_equal false, Project.find(1).identifier_frozen? |
|
138 | assert_equal false, Project.find(1).identifier_frozen? | |
138 | end |
|
139 | end | |
139 |
|
140 | |||
140 | def test_identifier_should_be_frozen_for_a_saved_project_with_valid_identifier |
|
141 | def test_identifier_should_be_frozen_for_a_saved_project_with_valid_identifier | |
141 | assert_equal true, Project.find(1).identifier_frozen? |
|
142 | assert_equal true, Project.find(1).identifier_frozen? | |
142 | end |
|
143 | end | |
143 |
|
144 | |||
144 | def test_members_should_be_active_users |
|
145 | def test_members_should_be_active_users | |
145 | Project.all.each do |project| |
|
146 | Project.all.each do |project| | |
146 | assert_nil project.members.detect {|m| !(m.user.is_a?(User) && m.user.active?) } |
|
147 | assert_nil project.members.detect {|m| !(m.user.is_a?(User) && m.user.active?) } | |
147 | end |
|
148 | end | |
148 | end |
|
149 | end | |
149 |
|
150 | |||
150 | def test_users_should_be_active_users |
|
151 | def test_users_should_be_active_users | |
151 | Project.all.each do |project| |
|
152 | Project.all.each do |project| | |
152 | assert_nil project.users.detect {|u| !(u.is_a?(User) && u.active?) } |
|
153 | assert_nil project.users.detect {|u| !(u.is_a?(User) && u.active?) } | |
153 | end |
|
154 | end | |
154 | end |
|
155 | end | |
155 |
|
156 | |||
156 | def test_open_scope_on_issues_association |
|
157 | def test_open_scope_on_issues_association | |
157 | assert_kind_of Issue, Project.find(1).issues.open.first |
|
158 | assert_kind_of Issue, Project.find(1).issues.open.first | |
158 | end |
|
159 | end | |
159 |
|
160 | |||
160 | def test_archive |
|
161 | def test_archive | |
161 | user = @ecookbook.members.first.user |
|
162 | user = @ecookbook.members.first.user | |
162 | @ecookbook.archive |
|
163 | @ecookbook.archive | |
163 | @ecookbook.reload |
|
164 | @ecookbook.reload | |
164 |
|
165 | |||
165 | assert !@ecookbook.active? |
|
166 | assert !@ecookbook.active? | |
166 | assert @ecookbook.archived? |
|
167 | assert @ecookbook.archived? | |
167 | assert !user.projects.include?(@ecookbook) |
|
168 | assert !user.projects.include?(@ecookbook) | |
168 | # Subproject are also archived |
|
169 | # Subproject are also archived | |
169 | assert !@ecookbook.children.empty? |
|
170 | assert !@ecookbook.children.empty? | |
170 | assert @ecookbook.descendants.active.empty? |
|
171 | assert @ecookbook.descendants.active.empty? | |
171 | end |
|
172 | end | |
172 |
|
173 | |||
173 | def test_archive_should_fail_if_versions_are_used_by_non_descendant_projects |
|
174 | def test_archive_should_fail_if_versions_are_used_by_non_descendant_projects | |
174 | # Assign an issue of a project to a version of a child project |
|
175 | # Assign an issue of a project to a version of a child project | |
175 | Issue.find(4).update_attribute :fixed_version_id, 4 |
|
176 | Issue.find(4).update_attribute :fixed_version_id, 4 | |
176 |
|
177 | |||
177 | assert_no_difference "Project.where(:status => Project::STATUS_ARCHIVED).count" do |
|
178 | assert_no_difference "Project.where(:status => Project::STATUS_ARCHIVED).count" do | |
178 | assert_equal false, @ecookbook.archive |
|
179 | assert_equal false, @ecookbook.archive | |
179 | end |
|
180 | end | |
180 | @ecookbook.reload |
|
181 | @ecookbook.reload | |
181 | assert @ecookbook.active? |
|
182 | assert @ecookbook.active? | |
182 | end |
|
183 | end | |
183 |
|
184 | |||
184 | def test_unarchive |
|
185 | def test_unarchive | |
185 | user = @ecookbook.members.first.user |
|
186 | user = @ecookbook.members.first.user | |
186 | @ecookbook.archive |
|
187 | @ecookbook.archive | |
187 | # A subproject of an archived project can not be unarchived |
|
188 | # A subproject of an archived project can not be unarchived | |
188 | assert !@ecookbook_sub1.unarchive |
|
189 | assert !@ecookbook_sub1.unarchive | |
189 |
|
190 | |||
190 | # Unarchive project |
|
191 | # Unarchive project | |
191 | assert @ecookbook.unarchive |
|
192 | assert @ecookbook.unarchive | |
192 | @ecookbook.reload |
|
193 | @ecookbook.reload | |
193 | assert @ecookbook.active? |
|
194 | assert @ecookbook.active? | |
194 | assert !@ecookbook.archived? |
|
195 | assert !@ecookbook.archived? | |
195 | assert user.projects.include?(@ecookbook) |
|
196 | assert user.projects.include?(@ecookbook) | |
196 | # Subproject can now be unarchived |
|
197 | # Subproject can now be unarchived | |
197 | @ecookbook_sub1.reload |
|
198 | @ecookbook_sub1.reload | |
198 | assert @ecookbook_sub1.unarchive |
|
199 | assert @ecookbook_sub1.unarchive | |
199 | end |
|
200 | end | |
200 |
|
201 | |||
201 | def test_destroy |
|
202 | def test_destroy | |
202 | # 2 active members |
|
203 | # 2 active members | |
203 | assert_equal 2, @ecookbook.members.size |
|
204 | assert_equal 2, @ecookbook.members.size | |
204 | # and 1 is locked |
|
205 | # and 1 is locked | |
205 | assert_equal 3, Member.where(:project_id => @ecookbook.id).count |
|
206 | assert_equal 3, Member.where(:project_id => @ecookbook.id).count | |
206 | # some boards |
|
207 | # some boards | |
207 | assert @ecookbook.boards.any? |
|
208 | assert @ecookbook.boards.any? | |
208 |
|
209 | |||
209 | @ecookbook.destroy |
|
210 | @ecookbook.destroy | |
210 | # make sure that the project non longer exists |
|
211 | # make sure that the project non longer exists | |
211 | assert_raise(ActiveRecord::RecordNotFound) { Project.find(@ecookbook.id) } |
|
212 | assert_raise(ActiveRecord::RecordNotFound) { Project.find(@ecookbook.id) } | |
212 | # make sure related data was removed |
|
213 | # make sure related data was removed | |
213 | assert_nil Member.where(:project_id => @ecookbook.id).first |
|
214 | assert_nil Member.where(:project_id => @ecookbook.id).first | |
214 | assert_nil Board.where(:project_id => @ecookbook.id).first |
|
215 | assert_nil Board.where(:project_id => @ecookbook.id).first | |
215 | assert_nil Issue.where(:project_id => @ecookbook.id).first |
|
216 | assert_nil Issue.where(:project_id => @ecookbook.id).first | |
216 | end |
|
217 | end | |
217 |
|
218 | |||
218 | def test_destroy_should_destroy_subtasks |
|
219 | def test_destroy_should_destroy_subtasks | |
219 | issues = (0..2).to_a.map {Issue.create!(:project_id => 1, :tracker_id => 1, :author_id => 1, :subject => 'test')} |
|
220 | issues = (0..2).to_a.map {Issue.create!(:project_id => 1, :tracker_id => 1, :author_id => 1, :subject => 'test')} | |
220 | issues[0].update_attribute :parent_issue_id, issues[1].id |
|
221 | issues[0].update_attribute :parent_issue_id, issues[1].id | |
221 | issues[2].update_attribute :parent_issue_id, issues[1].id |
|
222 | issues[2].update_attribute :parent_issue_id, issues[1].id | |
222 | assert_equal 2, issues[1].children.count |
|
223 | assert_equal 2, issues[1].children.count | |
223 |
|
224 | |||
224 | assert_nothing_raised do |
|
225 | assert_nothing_raised do | |
225 | Project.find(1).destroy |
|
226 | Project.find(1).destroy | |
226 | end |
|
227 | end | |
227 | assert_equal 0, Issue.where(:id => issues.map(&:id)).count |
|
228 | assert_equal 0, Issue.where(:id => issues.map(&:id)).count | |
228 | end |
|
229 | end | |
229 |
|
230 | |||
230 | def test_destroying_root_projects_should_clear_data |
|
231 | def test_destroying_root_projects_should_clear_data | |
231 | Project.roots.each do |root| |
|
232 | Project.roots.each do |root| | |
232 | root.destroy |
|
233 | root.destroy | |
233 | end |
|
234 | end | |
234 |
|
235 | |||
235 | assert_equal 0, Project.count, "Projects were not deleted: #{Project.all.inspect}" |
|
236 | assert_equal 0, Project.count, "Projects were not deleted: #{Project.all.inspect}" | |
236 | assert_equal 0, Member.count, "Members were not deleted: #{Member.all.inspect}" |
|
237 | assert_equal 0, Member.count, "Members were not deleted: #{Member.all.inspect}" | |
237 | assert_equal 0, MemberRole.count |
|
238 | assert_equal 0, MemberRole.count | |
238 | assert_equal 0, Issue.count |
|
239 | assert_equal 0, Issue.count | |
239 | assert_equal 0, Journal.count |
|
240 | assert_equal 0, Journal.count | |
240 | assert_equal 0, JournalDetail.count |
|
241 | assert_equal 0, JournalDetail.count | |
241 | assert_equal 0, Attachment.count, "Attachments were not deleted: #{Attachment.all.inspect}" |
|
242 | assert_equal 0, Attachment.count, "Attachments were not deleted: #{Attachment.all.inspect}" | |
242 | assert_equal 0, EnabledModule.count |
|
243 | assert_equal 0, EnabledModule.count | |
243 | assert_equal 0, IssueCategory.count |
|
244 | assert_equal 0, IssueCategory.count | |
244 | assert_equal 0, IssueRelation.count |
|
245 | assert_equal 0, IssueRelation.count | |
245 | assert_equal 0, Board.count |
|
246 | assert_equal 0, Board.count | |
246 | assert_equal 0, Message.count |
|
247 | assert_equal 0, Message.count | |
247 | assert_equal 0, News.count |
|
248 | assert_equal 0, News.count | |
248 | assert_equal 0, Query.where("project_id IS NOT NULL").count |
|
249 | assert_equal 0, Query.where("project_id IS NOT NULL").count | |
249 | assert_equal 0, Repository.count |
|
250 | assert_equal 0, Repository.count | |
250 | assert_equal 0, Changeset.count |
|
251 | assert_equal 0, Changeset.count | |
251 | assert_equal 0, Change.count |
|
252 | assert_equal 0, Change.count | |
252 | assert_equal 0, Comment.count |
|
253 | assert_equal 0, Comment.count | |
253 | assert_equal 0, TimeEntry.count |
|
254 | assert_equal 0, TimeEntry.count | |
254 | assert_equal 0, Version.count |
|
255 | assert_equal 0, Version.count | |
255 | assert_equal 0, Watcher.count |
|
256 | assert_equal 0, Watcher.count | |
256 | assert_equal 0, Wiki.count |
|
257 | assert_equal 0, Wiki.count | |
257 | assert_equal 0, WikiPage.count |
|
258 | assert_equal 0, WikiPage.count | |
258 | assert_equal 0, WikiContent.count |
|
259 | assert_equal 0, WikiContent.count | |
259 | assert_equal 0, WikiContent::Version.count |
|
260 | assert_equal 0, WikiContent::Version.count | |
260 | assert_equal 0, Project.connection.select_all("SELECT * FROM projects_trackers").count |
|
261 | assert_equal 0, Project.connection.select_all("SELECT * FROM projects_trackers").count | |
261 | assert_equal 0, Project.connection.select_all("SELECT * FROM custom_fields_projects").count |
|
262 | assert_equal 0, Project.connection.select_all("SELECT * FROM custom_fields_projects").count | |
262 | assert_equal 0, CustomValue.where(:customized_type => ['Project', 'Issue', 'TimeEntry', 'Version']).count |
|
263 | assert_equal 0, CustomValue.where(:customized_type => ['Project', 'Issue', 'TimeEntry', 'Version']).count | |
263 | end |
|
264 | end | |
264 |
|
265 | |||
265 | def test_destroy_should_delete_time_entries_custom_values |
|
266 | def test_destroy_should_delete_time_entries_custom_values | |
266 | project = Project.generate! |
|
267 | project = Project.generate! | |
267 | time_entry = TimeEntry.generate!(:project => project, :custom_field_values => {10 => '1'}) |
|
268 | time_entry = TimeEntry.generate!(:project => project, :custom_field_values => {10 => '1'}) | |
268 |
|
269 | |||
269 | assert_difference 'CustomValue.where(:customized_type => "TimeEntry").count', -1 do |
|
270 | assert_difference 'CustomValue.where(:customized_type => "TimeEntry").count', -1 do | |
270 | assert project.destroy |
|
271 | assert project.destroy | |
271 | end |
|
272 | end | |
272 | end |
|
273 | end | |
273 |
|
274 | |||
274 | def test_move_an_orphan_project_to_a_root_project |
|
275 | def test_move_an_orphan_project_to_a_root_project | |
275 | sub = Project.find(2) |
|
276 | sub = Project.find(2) | |
276 | sub.set_parent! @ecookbook |
|
277 | sub.set_parent! @ecookbook | |
277 | assert_equal @ecookbook.id, sub.parent.id |
|
278 | assert_equal @ecookbook.id, sub.parent.id | |
278 | @ecookbook.reload |
|
279 | @ecookbook.reload | |
279 | assert_equal 4, @ecookbook.children.size |
|
280 | assert_equal 4, @ecookbook.children.size | |
280 | end |
|
281 | end | |
281 |
|
282 | |||
282 | def test_move_an_orphan_project_to_a_subproject |
|
283 | def test_move_an_orphan_project_to_a_subproject | |
283 | sub = Project.find(2) |
|
284 | sub = Project.find(2) | |
284 | assert sub.set_parent!(@ecookbook_sub1) |
|
285 | assert sub.set_parent!(@ecookbook_sub1) | |
285 | end |
|
286 | end | |
286 |
|
287 | |||
287 | def test_move_a_root_project_to_a_project |
|
288 | def test_move_a_root_project_to_a_project | |
288 | sub = @ecookbook |
|
289 | sub = @ecookbook | |
289 | assert sub.set_parent!(Project.find(2)) |
|
290 | assert sub.set_parent!(Project.find(2)) | |
290 | end |
|
291 | end | |
291 |
|
292 | |||
292 | def test_should_not_move_a_project_to_its_children |
|
293 | def test_should_not_move_a_project_to_its_children | |
293 | sub = @ecookbook |
|
294 | sub = @ecookbook | |
294 | assert !(sub.set_parent!(Project.find(3))) |
|
295 | assert !(sub.set_parent!(Project.find(3))) | |
295 | end |
|
296 | end | |
296 |
|
297 | |||
297 | def test_set_parent_should_add_roots_in_alphabetical_order |
|
298 | def test_set_parent_should_add_roots_in_alphabetical_order | |
298 | ProjectCustomField.delete_all |
|
299 | ProjectCustomField.delete_all | |
299 | Project.delete_all |
|
300 | Project.delete_all | |
300 | Project.create!(:name => 'Project C', :identifier => 'project-c').set_parent!(nil) |
|
301 | Project.create!(:name => 'Project C', :identifier => 'project-c').set_parent!(nil) | |
301 | Project.create!(:name => 'Project B', :identifier => 'project-b').set_parent!(nil) |
|
302 | Project.create!(:name => 'Project B', :identifier => 'project-b').set_parent!(nil) | |
302 | Project.create!(:name => 'Project D', :identifier => 'project-d').set_parent!(nil) |
|
303 | Project.create!(:name => 'Project D', :identifier => 'project-d').set_parent!(nil) | |
303 | Project.create!(:name => 'Project A', :identifier => 'project-a').set_parent!(nil) |
|
304 | Project.create!(:name => 'Project A', :identifier => 'project-a').set_parent!(nil) | |
304 |
|
305 | |||
305 | assert_equal 4, Project.count |
|
306 | assert_equal 4, Project.count | |
306 | assert_equal Project.all.sort_by(&:name), Project.all.sort_by(&:lft) |
|
307 | assert_equal Project.all.sort_by(&:name), Project.all.sort_by(&:lft) | |
307 | end |
|
308 | end | |
308 |
|
309 | |||
309 | def test_set_parent_should_add_children_in_alphabetical_order |
|
310 | def test_set_parent_should_add_children_in_alphabetical_order | |
310 | ProjectCustomField.delete_all |
|
311 | ProjectCustomField.delete_all | |
311 | parent = Project.create!(:name => 'Parent', :identifier => 'parent') |
|
312 | parent = Project.create!(:name => 'Parent', :identifier => 'parent') | |
312 | Project.create!(:name => 'Project C', :identifier => 'project-c').set_parent!(parent) |
|
313 | Project.create!(:name => 'Project C', :identifier => 'project-c').set_parent!(parent) | |
313 | Project.create!(:name => 'Project B', :identifier => 'project-b').set_parent!(parent) |
|
314 | Project.create!(:name => 'Project B', :identifier => 'project-b').set_parent!(parent) | |
314 | Project.create!(:name => 'Project D', :identifier => 'project-d').set_parent!(parent) |
|
315 | Project.create!(:name => 'Project D', :identifier => 'project-d').set_parent!(parent) | |
315 | Project.create!(:name => 'Project A', :identifier => 'project-a').set_parent!(parent) |
|
316 | Project.create!(:name => 'Project A', :identifier => 'project-a').set_parent!(parent) | |
316 |
|
317 | |||
317 | parent.reload |
|
318 | parent.reload | |
318 | assert_equal 4, parent.children.size |
|
319 | assert_equal 4, parent.children.size | |
319 | assert_equal parent.children.sort_by(&:name), parent.children.to_a |
|
320 | assert_equal parent.children.sort_by(&:name), parent.children.to_a | |
320 | end |
|
321 | end | |
321 |
|
322 | |||
322 | def test_set_parent_should_update_issue_fixed_version_associations_when_a_fixed_version_is_moved_out_of_the_hierarchy |
|
323 | def test_set_parent_should_update_issue_fixed_version_associations_when_a_fixed_version_is_moved_out_of_the_hierarchy | |
323 | # Parent issue with a hierarchy project's fixed version |
|
324 | # Parent issue with a hierarchy project's fixed version | |
324 | parent_issue = Issue.find(1) |
|
325 | parent_issue = Issue.find(1) | |
325 | parent_issue.update_attribute(:fixed_version_id, 4) |
|
326 | parent_issue.update_attribute(:fixed_version_id, 4) | |
326 | parent_issue.reload |
|
327 | parent_issue.reload | |
327 | assert_equal 4, parent_issue.fixed_version_id |
|
328 | assert_equal 4, parent_issue.fixed_version_id | |
328 |
|
329 | |||
329 | # Should keep fixed versions for the issues |
|
330 | # Should keep fixed versions for the issues | |
330 | issue_with_local_fixed_version = Issue.find(5) |
|
331 | issue_with_local_fixed_version = Issue.find(5) | |
331 | issue_with_local_fixed_version.update_attribute(:fixed_version_id, 4) |
|
332 | issue_with_local_fixed_version.update_attribute(:fixed_version_id, 4) | |
332 | issue_with_local_fixed_version.reload |
|
333 | issue_with_local_fixed_version.reload | |
333 | assert_equal 4, issue_with_local_fixed_version.fixed_version_id |
|
334 | assert_equal 4, issue_with_local_fixed_version.fixed_version_id | |
334 |
|
335 | |||
335 | # Local issue with hierarchy fixed_version |
|
336 | # Local issue with hierarchy fixed_version | |
336 | issue_with_hierarchy_fixed_version = Issue.find(13) |
|
337 | issue_with_hierarchy_fixed_version = Issue.find(13) | |
337 | issue_with_hierarchy_fixed_version.update_attribute(:fixed_version_id, 6) |
|
338 | issue_with_hierarchy_fixed_version.update_attribute(:fixed_version_id, 6) | |
338 | issue_with_hierarchy_fixed_version.reload |
|
339 | issue_with_hierarchy_fixed_version.reload | |
339 | assert_equal 6, issue_with_hierarchy_fixed_version.fixed_version_id |
|
340 | assert_equal 6, issue_with_hierarchy_fixed_version.fixed_version_id | |
340 |
|
341 | |||
341 | # Move project out of the issue's hierarchy |
|
342 | # Move project out of the issue's hierarchy | |
342 | moved_project = Project.find(3) |
|
343 | moved_project = Project.find(3) | |
343 | moved_project.set_parent!(Project.find(2)) |
|
344 | moved_project.set_parent!(Project.find(2)) | |
344 | parent_issue.reload |
|
345 | parent_issue.reload | |
345 | issue_with_local_fixed_version.reload |
|
346 | issue_with_local_fixed_version.reload | |
346 | issue_with_hierarchy_fixed_version.reload |
|
347 | issue_with_hierarchy_fixed_version.reload | |
347 |
|
348 | |||
348 | assert_equal 4, issue_with_local_fixed_version.fixed_version_id, "Fixed version was not keep on an issue local to the moved project" |
|
349 | assert_equal 4, issue_with_local_fixed_version.fixed_version_id, "Fixed version was not keep on an issue local to the moved project" | |
349 | 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" |
|
350 | 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" | |
350 | assert_equal nil, parent_issue.fixed_version_id, "Fixed version is still set after moving the Version out of the hierarchy for the issue." |
|
351 | assert_equal nil, parent_issue.fixed_version_id, "Fixed version is still set after moving the Version out of the hierarchy for the issue." | |
351 | end |
|
352 | end | |
352 |
|
353 | |||
353 | def test_parent |
|
354 | def test_parent | |
354 | p = Project.find(6).parent |
|
355 | p = Project.find(6).parent | |
355 | assert p.is_a?(Project) |
|
356 | assert p.is_a?(Project) | |
356 | assert_equal 5, p.id |
|
357 | assert_equal 5, p.id | |
357 | end |
|
358 | end | |
358 |
|
359 | |||
359 | def test_ancestors |
|
360 | def test_ancestors | |
360 | a = Project.find(6).ancestors |
|
361 | a = Project.find(6).ancestors | |
361 | assert a.first.is_a?(Project) |
|
362 | assert a.first.is_a?(Project) | |
362 | assert_equal [1, 5], a.collect(&:id) |
|
363 | assert_equal [1, 5], a.collect(&:id) | |
363 | end |
|
364 | end | |
364 |
|
365 | |||
365 | def test_root |
|
366 | def test_root | |
366 | r = Project.find(6).root |
|
367 | r = Project.find(6).root | |
367 | assert r.is_a?(Project) |
|
368 | assert r.is_a?(Project) | |
368 | assert_equal 1, r.id |
|
369 | assert_equal 1, r.id | |
369 | end |
|
370 | end | |
370 |
|
371 | |||
371 | def test_children |
|
372 | def test_children | |
372 | c = Project.find(1).children |
|
373 | c = Project.find(1).children | |
373 | assert c.first.is_a?(Project) |
|
374 | assert c.first.is_a?(Project) | |
374 | assert_equal [5, 3, 4], c.collect(&:id) |
|
375 | assert_equal [5, 3, 4], c.collect(&:id) | |
375 | end |
|
376 | end | |
376 |
|
377 | |||
377 | def test_descendants |
|
378 | def test_descendants | |
378 | d = Project.find(1).descendants |
|
379 | d = Project.find(1).descendants | |
379 | assert d.first.is_a?(Project) |
|
380 | assert d.first.is_a?(Project) | |
380 | assert_equal [5, 6, 3, 4], d.collect(&:id) |
|
381 | assert_equal [5, 6, 3, 4], d.collect(&:id) | |
381 | end |
|
382 | end | |
382 |
|
383 | |||
383 | def test_allowed_parents_should_be_empty_for_non_member_user |
|
384 | def test_allowed_parents_should_be_empty_for_non_member_user | |
384 | Role.non_member.add_permission!(:add_project) |
|
385 | Role.non_member.add_permission!(:add_project) | |
385 | user = User.find(9) |
|
386 | user = User.find(9) | |
386 | assert user.memberships.empty? |
|
387 | assert user.memberships.empty? | |
387 | User.current = user |
|
388 | User.current = user | |
388 | assert Project.new.allowed_parents.compact.empty? |
|
389 | assert Project.new.allowed_parents.compact.empty? | |
389 | end |
|
390 | end | |
390 |
|
391 | |||
391 | def test_allowed_parents_with_add_subprojects_permission |
|
392 | def test_allowed_parents_with_add_subprojects_permission | |
392 | Role.find(1).remove_permission!(:add_project) |
|
393 | Role.find(1).remove_permission!(:add_project) | |
393 | Role.find(1).add_permission!(:add_subprojects) |
|
394 | Role.find(1).add_permission!(:add_subprojects) | |
394 | User.current = User.find(2) |
|
395 | User.current = User.find(2) | |
395 | # new project |
|
396 | # new project | |
396 | assert !Project.new.allowed_parents.include?(nil) |
|
397 | assert !Project.new.allowed_parents.include?(nil) | |
397 | assert Project.new.allowed_parents.include?(Project.find(1)) |
|
398 | assert Project.new.allowed_parents.include?(Project.find(1)) | |
398 | # existing root project |
|
399 | # existing root project | |
399 | assert Project.find(1).allowed_parents.include?(nil) |
|
400 | assert Project.find(1).allowed_parents.include?(nil) | |
400 | # existing child |
|
401 | # existing child | |
401 | assert Project.find(3).allowed_parents.include?(Project.find(1)) |
|
402 | assert Project.find(3).allowed_parents.include?(Project.find(1)) | |
402 | assert !Project.find(3).allowed_parents.include?(nil) |
|
403 | assert !Project.find(3).allowed_parents.include?(nil) | |
403 | end |
|
404 | end | |
404 |
|
405 | |||
405 | def test_allowed_parents_with_add_project_permission |
|
406 | def test_allowed_parents_with_add_project_permission | |
406 | Role.find(1).add_permission!(:add_project) |
|
407 | Role.find(1).add_permission!(:add_project) | |
407 | Role.find(1).remove_permission!(:add_subprojects) |
|
408 | Role.find(1).remove_permission!(:add_subprojects) | |
408 | User.current = User.find(2) |
|
409 | User.current = User.find(2) | |
409 | # new project |
|
410 | # new project | |
410 | assert Project.new.allowed_parents.include?(nil) |
|
411 | assert Project.new.allowed_parents.include?(nil) | |
411 | assert !Project.new.allowed_parents.include?(Project.find(1)) |
|
412 | assert !Project.new.allowed_parents.include?(Project.find(1)) | |
412 | # existing root project |
|
413 | # existing root project | |
413 | assert Project.find(1).allowed_parents.include?(nil) |
|
414 | assert Project.find(1).allowed_parents.include?(nil) | |
414 | # existing child |
|
415 | # existing child | |
415 | assert Project.find(3).allowed_parents.include?(Project.find(1)) |
|
416 | assert Project.find(3).allowed_parents.include?(Project.find(1)) | |
416 | assert Project.find(3).allowed_parents.include?(nil) |
|
417 | assert Project.find(3).allowed_parents.include?(nil) | |
417 | end |
|
418 | end | |
418 |
|
419 | |||
419 | def test_allowed_parents_with_add_project_and_subprojects_permission |
|
420 | def test_allowed_parents_with_add_project_and_subprojects_permission | |
420 | Role.find(1).add_permission!(:add_project) |
|
421 | Role.find(1).add_permission!(:add_project) | |
421 | Role.find(1).add_permission!(:add_subprojects) |
|
422 | Role.find(1).add_permission!(:add_subprojects) | |
422 | User.current = User.find(2) |
|
423 | User.current = User.find(2) | |
423 | # new project |
|
424 | # new project | |
424 | assert Project.new.allowed_parents.include?(nil) |
|
425 | assert Project.new.allowed_parents.include?(nil) | |
425 | assert Project.new.allowed_parents.include?(Project.find(1)) |
|
426 | assert Project.new.allowed_parents.include?(Project.find(1)) | |
426 | # existing root project |
|
427 | # existing root project | |
427 | assert Project.find(1).allowed_parents.include?(nil) |
|
428 | assert Project.find(1).allowed_parents.include?(nil) | |
428 | # existing child |
|
429 | # existing child | |
429 | assert Project.find(3).allowed_parents.include?(Project.find(1)) |
|
430 | assert Project.find(3).allowed_parents.include?(Project.find(1)) | |
430 | assert Project.find(3).allowed_parents.include?(nil) |
|
431 | assert Project.find(3).allowed_parents.include?(nil) | |
431 | end |
|
432 | end | |
432 |
|
433 | |||
433 | def test_users_by_role |
|
434 | def test_users_by_role | |
434 | users_by_role = Project.find(1).users_by_role |
|
435 | users_by_role = Project.find(1).users_by_role | |
435 | assert_kind_of Hash, users_by_role |
|
436 | assert_kind_of Hash, users_by_role | |
436 | role = Role.find(1) |
|
437 | role = Role.find(1) | |
437 | assert_kind_of Array, users_by_role[role] |
|
438 | assert_kind_of Array, users_by_role[role] | |
438 | assert users_by_role[role].include?(User.find(2)) |
|
439 | assert users_by_role[role].include?(User.find(2)) | |
439 | end |
|
440 | end | |
440 |
|
441 | |||
441 | def test_rolled_up_trackers |
|
442 | def test_rolled_up_trackers | |
442 | parent = Project.find(1) |
|
443 | parent = Project.find(1) | |
443 | parent.trackers = Tracker.find([1,2]) |
|
444 | parent.trackers = Tracker.find([1,2]) | |
444 | child = parent.children.find(3) |
|
445 | child = parent.children.find(3) | |
445 |
|
446 | |||
446 | assert_equal [1, 2], parent.tracker_ids |
|
447 | assert_equal [1, 2], parent.tracker_ids | |
447 | assert_equal [2, 3], child.trackers.collect(&:id) |
|
448 | assert_equal [2, 3], child.trackers.collect(&:id) | |
448 |
|
449 | |||
449 | assert_kind_of Tracker, parent.rolled_up_trackers.first |
|
450 | assert_kind_of Tracker, parent.rolled_up_trackers.first | |
450 | assert_equal Tracker.find(1), parent.rolled_up_trackers.first |
|
451 | assert_equal Tracker.find(1), parent.rolled_up_trackers.first | |
451 |
|
452 | |||
452 | assert_equal [1, 2, 3], parent.rolled_up_trackers.collect(&:id) |
|
453 | assert_equal [1, 2, 3], parent.rolled_up_trackers.collect(&:id) | |
453 | assert_equal [2, 3], child.rolled_up_trackers.collect(&:id) |
|
454 | assert_equal [2, 3], child.rolled_up_trackers.collect(&:id) | |
454 | end |
|
455 | end | |
455 |
|
456 | |||
456 | def test_rolled_up_trackers_should_ignore_archived_subprojects |
|
457 | def test_rolled_up_trackers_should_ignore_archived_subprojects | |
457 | parent = Project.find(1) |
|
458 | parent = Project.find(1) | |
458 | parent.trackers = Tracker.find([1,2]) |
|
459 | parent.trackers = Tracker.find([1,2]) | |
459 | child = parent.children.find(3) |
|
460 | child = parent.children.find(3) | |
460 | child.trackers = Tracker.find([1,3]) |
|
461 | child.trackers = Tracker.find([1,3]) | |
461 | parent.children.each(&:archive) |
|
462 | parent.children.each(&:archive) | |
462 |
|
463 | |||
463 | assert_equal [1,2], parent.rolled_up_trackers.collect(&:id) |
|
464 | assert_equal [1,2], parent.rolled_up_trackers.collect(&:id) | |
464 | end |
|
465 | end | |
465 |
|
466 | |||
466 | test "#rolled_up_trackers should ignore projects with issue_tracking module disabled" do |
|
467 | test "#rolled_up_trackers should ignore projects with issue_tracking module disabled" do | |
467 | parent = Project.generate! |
|
468 | parent = Project.generate! | |
468 | parent.trackers = Tracker.find([1, 2]) |
|
469 | parent.trackers = Tracker.find([1, 2]) | |
469 | child = Project.generate_with_parent!(parent) |
|
470 | child = Project.generate_with_parent!(parent) | |
470 | child.trackers = Tracker.find([2, 3]) |
|
471 | child.trackers = Tracker.find([2, 3]) | |
471 |
|
472 | |||
472 | assert_equal [1, 2, 3], parent.rolled_up_trackers.collect(&:id).sort |
|
473 | assert_equal [1, 2, 3], parent.rolled_up_trackers.collect(&:id).sort | |
473 |
|
474 | |||
474 | assert child.disable_module!(:issue_tracking) |
|
475 | assert child.disable_module!(:issue_tracking) | |
475 | parent.reload |
|
476 | parent.reload | |
476 | assert_equal [1, 2], parent.rolled_up_trackers.collect(&:id).sort |
|
477 | assert_equal [1, 2], parent.rolled_up_trackers.collect(&:id).sort | |
477 | end |
|
478 | end | |
478 |
|
479 | |||
479 | test "#rolled_up_versions should include the versions for the current project" do |
|
480 | test "#rolled_up_versions should include the versions for the current project" do | |
480 | project = Project.generate! |
|
481 | project = Project.generate! | |
481 | parent_version_1 = Version.generate!(:project => project) |
|
482 | parent_version_1 = Version.generate!(:project => project) | |
482 | parent_version_2 = Version.generate!(:project => project) |
|
483 | parent_version_2 = Version.generate!(:project => project) | |
483 | assert_same_elements [parent_version_1, parent_version_2], project.rolled_up_versions |
|
484 | assert_same_elements [parent_version_1, parent_version_2], project.rolled_up_versions | |
484 | end |
|
485 | end | |
485 |
|
486 | |||
486 | test "#rolled_up_versions should include versions for a subproject" do |
|
487 | test "#rolled_up_versions should include versions for a subproject" do | |
487 | project = Project.generate! |
|
488 | project = Project.generate! | |
488 | parent_version_1 = Version.generate!(:project => project) |
|
489 | parent_version_1 = Version.generate!(:project => project) | |
489 | parent_version_2 = Version.generate!(:project => project) |
|
490 | parent_version_2 = Version.generate!(:project => project) | |
490 | subproject = Project.generate_with_parent!(project) |
|
491 | subproject = Project.generate_with_parent!(project) | |
491 | subproject_version = Version.generate!(:project => subproject) |
|
492 | subproject_version = Version.generate!(:project => subproject) | |
492 |
|
493 | |||
493 | assert_same_elements [ |
|
494 | assert_same_elements [ | |
494 | parent_version_1, |
|
495 | parent_version_1, | |
495 | parent_version_2, |
|
496 | parent_version_2, | |
496 | subproject_version |
|
497 | subproject_version | |
497 | ], project.rolled_up_versions |
|
498 | ], project.rolled_up_versions | |
498 | end |
|
499 | end | |
499 |
|
500 | |||
500 | test "#rolled_up_versions should include versions for a sub-subproject" do |
|
501 | test "#rolled_up_versions should include versions for a sub-subproject" do | |
501 | project = Project.generate! |
|
502 | project = Project.generate! | |
502 | parent_version_1 = Version.generate!(:project => project) |
|
503 | parent_version_1 = Version.generate!(:project => project) | |
503 | parent_version_2 = Version.generate!(:project => project) |
|
504 | parent_version_2 = Version.generate!(:project => project) | |
504 | subproject = Project.generate_with_parent!(project) |
|
505 | subproject = Project.generate_with_parent!(project) | |
505 | sub_subproject = Project.generate_with_parent!(subproject) |
|
506 | sub_subproject = Project.generate_with_parent!(subproject) | |
506 | sub_subproject_version = Version.generate!(:project => sub_subproject) |
|
507 | sub_subproject_version = Version.generate!(:project => sub_subproject) | |
507 | project.reload |
|
508 | project.reload | |
508 |
|
509 | |||
509 | assert_same_elements [ |
|
510 | assert_same_elements [ | |
510 | parent_version_1, |
|
511 | parent_version_1, | |
511 | parent_version_2, |
|
512 | parent_version_2, | |
512 | sub_subproject_version |
|
513 | sub_subproject_version | |
513 | ], project.rolled_up_versions |
|
514 | ], project.rolled_up_versions | |
514 | end |
|
515 | end | |
515 |
|
516 | |||
516 | test "#rolled_up_versions should only check active projects" do |
|
517 | test "#rolled_up_versions should only check active projects" do | |
517 | project = Project.generate! |
|
518 | project = Project.generate! | |
518 | parent_version_1 = Version.generate!(:project => project) |
|
519 | parent_version_1 = Version.generate!(:project => project) | |
519 | parent_version_2 = Version.generate!(:project => project) |
|
520 | parent_version_2 = Version.generate!(:project => project) | |
520 | subproject = Project.generate_with_parent!(project) |
|
521 | subproject = Project.generate_with_parent!(project) | |
521 | subproject_version = Version.generate!(:project => subproject) |
|
522 | subproject_version = Version.generate!(:project => subproject) | |
522 | assert subproject.archive |
|
523 | assert subproject.archive | |
523 | project.reload |
|
524 | project.reload | |
524 |
|
525 | |||
525 | assert !subproject.active? |
|
526 | assert !subproject.active? | |
526 | assert_same_elements [parent_version_1, parent_version_2], project.rolled_up_versions |
|
527 | assert_same_elements [parent_version_1, parent_version_2], project.rolled_up_versions | |
527 | end |
|
528 | end | |
528 |
|
529 | |||
529 | def test_shared_versions_none_sharing |
|
530 | def test_shared_versions_none_sharing | |
530 | p = Project.find(5) |
|
531 | p = Project.find(5) | |
531 | v = Version.create!(:name => 'none_sharing', :project => p, :sharing => 'none') |
|
532 | v = Version.create!(:name => 'none_sharing', :project => p, :sharing => 'none') | |
532 | assert p.shared_versions.include?(v) |
|
533 | assert p.shared_versions.include?(v) | |
533 | assert !p.children.first.shared_versions.include?(v) |
|
534 | assert !p.children.first.shared_versions.include?(v) | |
534 | assert !p.root.shared_versions.include?(v) |
|
535 | assert !p.root.shared_versions.include?(v) | |
535 | assert !p.siblings.first.shared_versions.include?(v) |
|
536 | assert !p.siblings.first.shared_versions.include?(v) | |
536 | assert !p.root.siblings.first.shared_versions.include?(v) |
|
537 | assert !p.root.siblings.first.shared_versions.include?(v) | |
537 | end |
|
538 | end | |
538 |
|
539 | |||
539 | def test_shared_versions_descendants_sharing |
|
540 | def test_shared_versions_descendants_sharing | |
540 | p = Project.find(5) |
|
541 | p = Project.find(5) | |
541 | v = Version.create!(:name => 'descendants_sharing', :project => p, :sharing => 'descendants') |
|
542 | v = Version.create!(:name => 'descendants_sharing', :project => p, :sharing => 'descendants') | |
542 | assert p.shared_versions.include?(v) |
|
543 | assert p.shared_versions.include?(v) | |
543 | assert p.children.first.shared_versions.include?(v) |
|
544 | assert p.children.first.shared_versions.include?(v) | |
544 | assert !p.root.shared_versions.include?(v) |
|
545 | assert !p.root.shared_versions.include?(v) | |
545 | assert !p.siblings.first.shared_versions.include?(v) |
|
546 | assert !p.siblings.first.shared_versions.include?(v) | |
546 | assert !p.root.siblings.first.shared_versions.include?(v) |
|
547 | assert !p.root.siblings.first.shared_versions.include?(v) | |
547 | end |
|
548 | end | |
548 |
|
549 | |||
549 | def test_shared_versions_hierarchy_sharing |
|
550 | def test_shared_versions_hierarchy_sharing | |
550 | p = Project.find(5) |
|
551 | p = Project.find(5) | |
551 | v = Version.create!(:name => 'hierarchy_sharing', :project => p, :sharing => 'hierarchy') |
|
552 | v = Version.create!(:name => 'hierarchy_sharing', :project => p, :sharing => 'hierarchy') | |
552 | assert p.shared_versions.include?(v) |
|
553 | assert p.shared_versions.include?(v) | |
553 | assert p.children.first.shared_versions.include?(v) |
|
554 | assert p.children.first.shared_versions.include?(v) | |
554 | assert p.root.shared_versions.include?(v) |
|
555 | assert p.root.shared_versions.include?(v) | |
555 | assert !p.siblings.first.shared_versions.include?(v) |
|
556 | assert !p.siblings.first.shared_versions.include?(v) | |
556 | assert !p.root.siblings.first.shared_versions.include?(v) |
|
557 | assert !p.root.siblings.first.shared_versions.include?(v) | |
557 | end |
|
558 | end | |
558 |
|
559 | |||
559 | def test_shared_versions_tree_sharing |
|
560 | def test_shared_versions_tree_sharing | |
560 | p = Project.find(5) |
|
561 | p = Project.find(5) | |
561 | v = Version.create!(:name => 'tree_sharing', :project => p, :sharing => 'tree') |
|
562 | v = Version.create!(:name => 'tree_sharing', :project => p, :sharing => 'tree') | |
562 | assert p.shared_versions.include?(v) |
|
563 | assert p.shared_versions.include?(v) | |
563 | assert p.children.first.shared_versions.include?(v) |
|
564 | assert p.children.first.shared_versions.include?(v) | |
564 | assert p.root.shared_versions.include?(v) |
|
565 | assert p.root.shared_versions.include?(v) | |
565 | assert p.siblings.first.shared_versions.include?(v) |
|
566 | assert p.siblings.first.shared_versions.include?(v) | |
566 | assert !p.root.siblings.first.shared_versions.include?(v) |
|
567 | assert !p.root.siblings.first.shared_versions.include?(v) | |
567 | end |
|
568 | end | |
568 |
|
569 | |||
569 | def test_shared_versions_system_sharing |
|
570 | def test_shared_versions_system_sharing | |
570 | p = Project.find(5) |
|
571 | p = Project.find(5) | |
571 | v = Version.create!(:name => 'system_sharing', :project => p, :sharing => 'system') |
|
572 | v = Version.create!(:name => 'system_sharing', :project => p, :sharing => 'system') | |
572 | assert p.shared_versions.include?(v) |
|
573 | assert p.shared_versions.include?(v) | |
573 | assert p.children.first.shared_versions.include?(v) |
|
574 | assert p.children.first.shared_versions.include?(v) | |
574 | assert p.root.shared_versions.include?(v) |
|
575 | assert p.root.shared_versions.include?(v) | |
575 | assert p.siblings.first.shared_versions.include?(v) |
|
576 | assert p.siblings.first.shared_versions.include?(v) | |
576 | assert p.root.siblings.first.shared_versions.include?(v) |
|
577 | assert p.root.siblings.first.shared_versions.include?(v) | |
577 | end |
|
578 | end | |
578 |
|
579 | |||
579 | def test_shared_versions |
|
580 | def test_shared_versions | |
580 | parent = Project.find(1) |
|
581 | parent = Project.find(1) | |
581 | child = parent.children.find(3) |
|
582 | child = parent.children.find(3) | |
582 | private_child = parent.children.find(5) |
|
583 | private_child = parent.children.find(5) | |
583 |
|
584 | |||
584 | assert_equal [1,2,3], parent.version_ids.sort |
|
585 | assert_equal [1,2,3], parent.version_ids.sort | |
585 | assert_equal [4], child.version_ids |
|
586 | assert_equal [4], child.version_ids | |
586 | assert_equal [6], private_child.version_ids |
|
587 | assert_equal [6], private_child.version_ids | |
587 | assert_equal [7], Version.where(:sharing => 'system').collect(&:id) |
|
588 | assert_equal [7], Version.where(:sharing => 'system').collect(&:id) | |
588 |
|
589 | |||
589 | assert_equal 6, parent.shared_versions.size |
|
590 | assert_equal 6, parent.shared_versions.size | |
590 | parent.shared_versions.each do |version| |
|
591 | parent.shared_versions.each do |version| | |
591 | assert_kind_of Version, version |
|
592 | assert_kind_of Version, version | |
592 | end |
|
593 | end | |
593 |
|
594 | |||
594 | assert_equal [1,2,3,4,6,7], parent.shared_versions.collect(&:id).sort |
|
595 | assert_equal [1,2,3,4,6,7], parent.shared_versions.collect(&:id).sort | |
595 | end |
|
596 | end | |
596 |
|
597 | |||
597 | def test_shared_versions_should_ignore_archived_subprojects |
|
598 | def test_shared_versions_should_ignore_archived_subprojects | |
598 | parent = Project.find(1) |
|
599 | parent = Project.find(1) | |
599 | child = parent.children.find(3) |
|
600 | child = parent.children.find(3) | |
600 | child.archive |
|
601 | child.archive | |
601 | parent.reload |
|
602 | parent.reload | |
602 |
|
603 | |||
603 | assert_equal [1,2,3], parent.version_ids.sort |
|
604 | assert_equal [1,2,3], parent.version_ids.sort | |
604 | assert_equal [4], child.version_ids |
|
605 | assert_equal [4], child.version_ids | |
605 | assert !parent.shared_versions.collect(&:id).include?(4) |
|
606 | assert !parent.shared_versions.collect(&:id).include?(4) | |
606 | end |
|
607 | end | |
607 |
|
608 | |||
608 | def test_shared_versions_visible_to_user |
|
609 | def test_shared_versions_visible_to_user | |
609 | user = User.find(3) |
|
610 | user = User.find(3) | |
610 | parent = Project.find(1) |
|
611 | parent = Project.find(1) | |
611 | child = parent.children.find(5) |
|
612 | child = parent.children.find(5) | |
612 |
|
613 | |||
613 | assert_equal [1,2,3], parent.version_ids.sort |
|
614 | assert_equal [1,2,3], parent.version_ids.sort | |
614 | assert_equal [6], child.version_ids |
|
615 | assert_equal [6], child.version_ids | |
615 |
|
616 | |||
616 | versions = parent.shared_versions.visible(user) |
|
617 | versions = parent.shared_versions.visible(user) | |
617 |
|
618 | |||
618 | assert_equal 4, versions.size |
|
619 | assert_equal 4, versions.size | |
619 | versions.each do |version| |
|
620 | versions.each do |version| | |
620 | assert_kind_of Version, version |
|
621 | assert_kind_of Version, version | |
621 | end |
|
622 | end | |
622 |
|
623 | |||
623 | assert !versions.collect(&:id).include?(6) |
|
624 | assert !versions.collect(&:id).include?(6) | |
624 | end |
|
625 | end | |
625 |
|
626 | |||
626 | def test_shared_versions_for_new_project_should_include_system_shared_versions |
|
627 | def test_shared_versions_for_new_project_should_include_system_shared_versions | |
627 | p = Project.find(5) |
|
628 | p = Project.find(5) | |
628 | v = Version.create!(:name => 'system_sharing', :project => p, :sharing => 'system') |
|
629 | v = Version.create!(:name => 'system_sharing', :project => p, :sharing => 'system') | |
629 |
|
630 | |||
630 | assert_include v, Project.new.shared_versions |
|
631 | assert_include v, Project.new.shared_versions | |
631 | end |
|
632 | end | |
632 |
|
633 | |||
633 | def test_next_identifier |
|
634 | def test_next_identifier | |
634 | ProjectCustomField.delete_all |
|
635 | ProjectCustomField.delete_all | |
635 | Project.create!(:name => 'last', :identifier => 'p2008040') |
|
636 | Project.create!(:name => 'last', :identifier => 'p2008040') | |
636 | assert_equal 'p2008041', Project.next_identifier |
|
637 | assert_equal 'p2008041', Project.next_identifier | |
637 | end |
|
638 | end | |
638 |
|
639 | |||
639 | def test_next_identifier_first_project |
|
640 | def test_next_identifier_first_project | |
640 | Project.delete_all |
|
641 | Project.delete_all | |
641 | assert_nil Project.next_identifier |
|
642 | assert_nil Project.next_identifier | |
642 | end |
|
643 | end | |
643 |
|
644 | |||
644 | def test_enabled_module_names |
|
645 | def test_enabled_module_names | |
645 | with_settings :default_projects_modules => ['issue_tracking', 'repository'] do |
|
646 | with_settings :default_projects_modules => ['issue_tracking', 'repository'] do | |
646 | project = Project.new |
|
647 | project = Project.new | |
647 |
|
648 | |||
648 | project.enabled_module_names = %w(issue_tracking news) |
|
649 | project.enabled_module_names = %w(issue_tracking news) | |
649 | assert_equal %w(issue_tracking news), project.enabled_module_names.sort |
|
650 | assert_equal %w(issue_tracking news), project.enabled_module_names.sort | |
650 | end |
|
651 | end | |
651 | end |
|
652 | end | |
652 |
|
653 | |||
653 | test "enabled_modules should define module by names and preserve ids" do |
|
654 | test "enabled_modules should define module by names and preserve ids" do | |
654 | @project = Project.find(1) |
|
655 | @project = Project.find(1) | |
655 | # Remove one module |
|
656 | # Remove one module | |
656 | modules = @project.enabled_modules.slice(0..-2) |
|
657 | modules = @project.enabled_modules.slice(0..-2) | |
657 | assert modules.any? |
|
658 | assert modules.any? | |
658 | assert_difference 'EnabledModule.count', -1 do |
|
659 | assert_difference 'EnabledModule.count', -1 do | |
659 | @project.enabled_module_names = modules.collect(&:name) |
|
660 | @project.enabled_module_names = modules.collect(&:name) | |
660 | end |
|
661 | end | |
661 | @project.reload |
|
662 | @project.reload | |
662 | # Ids should be preserved |
|
663 | # Ids should be preserved | |
663 | assert_equal @project.enabled_module_ids.sort, modules.collect(&:id).sort |
|
664 | assert_equal @project.enabled_module_ids.sort, modules.collect(&:id).sort | |
664 | end |
|
665 | end | |
665 |
|
666 | |||
666 | test "enabled_modules should enable a module" do |
|
667 | test "enabled_modules should enable a module" do | |
667 | @project = Project.find(1) |
|
668 | @project = Project.find(1) | |
668 | @project.enabled_module_names = [] |
|
669 | @project.enabled_module_names = [] | |
669 | @project.reload |
|
670 | @project.reload | |
670 | assert_equal [], @project.enabled_module_names |
|
671 | assert_equal [], @project.enabled_module_names | |
671 | #with string |
|
672 | #with string | |
672 | @project.enable_module!("issue_tracking") |
|
673 | @project.enable_module!("issue_tracking") | |
673 | assert_equal ["issue_tracking"], @project.enabled_module_names |
|
674 | assert_equal ["issue_tracking"], @project.enabled_module_names | |
674 | #with symbol |
|
675 | #with symbol | |
675 | @project.enable_module!(:gantt) |
|
676 | @project.enable_module!(:gantt) | |
676 | assert_equal ["issue_tracking", "gantt"], @project.enabled_module_names |
|
677 | assert_equal ["issue_tracking", "gantt"], @project.enabled_module_names | |
677 | #don't add a module twice |
|
678 | #don't add a module twice | |
678 | @project.enable_module!("issue_tracking") |
|
679 | @project.enable_module!("issue_tracking") | |
679 | assert_equal ["issue_tracking", "gantt"], @project.enabled_module_names |
|
680 | assert_equal ["issue_tracking", "gantt"], @project.enabled_module_names | |
680 | end |
|
681 | end | |
681 |
|
682 | |||
682 | test "enabled_modules should disable a module" do |
|
683 | test "enabled_modules should disable a module" do | |
683 | @project = Project.find(1) |
|
684 | @project = Project.find(1) | |
684 | #with string |
|
685 | #with string | |
685 | assert @project.enabled_module_names.include?("issue_tracking") |
|
686 | assert @project.enabled_module_names.include?("issue_tracking") | |
686 | @project.disable_module!("issue_tracking") |
|
687 | @project.disable_module!("issue_tracking") | |
687 | assert ! @project.reload.enabled_module_names.include?("issue_tracking") |
|
688 | assert ! @project.reload.enabled_module_names.include?("issue_tracking") | |
688 | #with symbol |
|
689 | #with symbol | |
689 | assert @project.enabled_module_names.include?("gantt") |
|
690 | assert @project.enabled_module_names.include?("gantt") | |
690 | @project.disable_module!(:gantt) |
|
691 | @project.disable_module!(:gantt) | |
691 | assert ! @project.reload.enabled_module_names.include?("gantt") |
|
692 | assert ! @project.reload.enabled_module_names.include?("gantt") | |
692 | #with EnabledModule object |
|
693 | #with EnabledModule object | |
693 | first_module = @project.enabled_modules.first |
|
694 | first_module = @project.enabled_modules.first | |
694 | @project.disable_module!(first_module) |
|
695 | @project.disable_module!(first_module) | |
695 | assert ! @project.reload.enabled_module_names.include?(first_module.name) |
|
696 | assert ! @project.reload.enabled_module_names.include?(first_module.name) | |
696 | end |
|
697 | end | |
697 |
|
698 | |||
698 | def test_enabled_module_names_should_not_recreate_enabled_modules |
|
699 | def test_enabled_module_names_should_not_recreate_enabled_modules | |
699 | project = Project.find(1) |
|
700 | project = Project.find(1) | |
700 | # Remove one module |
|
701 | # Remove one module | |
701 | modules = project.enabled_modules.slice(0..-2) |
|
702 | modules = project.enabled_modules.slice(0..-2) | |
702 | assert modules.any? |
|
703 | assert modules.any? | |
703 | assert_difference 'EnabledModule.count', -1 do |
|
704 | assert_difference 'EnabledModule.count', -1 do | |
704 | project.enabled_module_names = modules.collect(&:name) |
|
705 | project.enabled_module_names = modules.collect(&:name) | |
705 | end |
|
706 | end | |
706 | project.reload |
|
707 | project.reload | |
707 | # Ids should be preserved |
|
708 | # Ids should be preserved | |
708 | assert_equal project.enabled_module_ids.sort, modules.collect(&:id).sort |
|
709 | assert_equal project.enabled_module_ids.sort, modules.collect(&:id).sort | |
709 | end |
|
710 | end | |
710 |
|
711 | |||
711 | def test_copy_from_existing_project |
|
712 | def test_copy_from_existing_project | |
712 | source_project = Project.find(1) |
|
713 | source_project = Project.find(1) | |
713 | copied_project = Project.copy_from(1) |
|
714 | copied_project = Project.copy_from(1) | |
714 |
|
715 | |||
715 | assert copied_project |
|
716 | assert copied_project | |
716 | # Cleared attributes |
|
717 | # Cleared attributes | |
717 | assert copied_project.id.blank? |
|
718 | assert copied_project.id.blank? | |
718 | assert copied_project.name.blank? |
|
719 | assert copied_project.name.blank? | |
719 | assert copied_project.identifier.blank? |
|
720 | assert copied_project.identifier.blank? | |
720 |
|
721 | |||
721 | # Duplicated attributes |
|
722 | # Duplicated attributes | |
722 | assert_equal source_project.description, copied_project.description |
|
723 | assert_equal source_project.description, copied_project.description | |
723 | assert_equal source_project.enabled_modules, copied_project.enabled_modules |
|
724 | assert_equal source_project.enabled_modules, copied_project.enabled_modules | |
724 | assert_equal source_project.trackers, copied_project.trackers |
|
725 | assert_equal source_project.trackers, copied_project.trackers | |
725 |
|
726 | |||
726 | # Default attributes |
|
727 | # Default attributes | |
727 | assert_equal 1, copied_project.status |
|
728 | assert_equal 1, copied_project.status | |
728 | end |
|
729 | end | |
729 |
|
730 | |||
730 | def test_activities_should_use_the_system_activities |
|
731 | def test_activities_should_use_the_system_activities | |
731 | project = Project.find(1) |
|
732 | project = Project.find(1) | |
732 | assert_equal project.activities.to_a, TimeEntryActivity.where(:active => true).to_a |
|
733 | assert_equal project.activities.to_a, TimeEntryActivity.where(:active => true).to_a | |
733 | assert_kind_of ActiveRecord::Relation, project.activities |
|
734 | assert_kind_of ActiveRecord::Relation, project.activities | |
734 | end |
|
735 | end | |
735 |
|
736 | |||
736 |
|
737 | |||
737 | def test_activities_should_use_the_project_specific_activities |
|
738 | def test_activities_should_use_the_project_specific_activities | |
738 | project = Project.find(1) |
|
739 | project = Project.find(1) | |
739 | overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project}) |
|
740 | overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project}) | |
740 | assert overridden_activity.save! |
|
741 | assert overridden_activity.save! | |
741 |
|
742 | |||
742 | assert project.activities.include?(overridden_activity), "Project specific Activity not found" |
|
743 | assert project.activities.include?(overridden_activity), "Project specific Activity not found" | |
743 | assert_kind_of ActiveRecord::Relation, project.activities |
|
744 | assert_kind_of ActiveRecord::Relation, project.activities | |
744 | end |
|
745 | end | |
745 |
|
746 | |||
746 | def test_activities_should_not_include_the_inactive_project_specific_activities |
|
747 | def test_activities_should_not_include_the_inactive_project_specific_activities | |
747 | project = Project.find(1) |
|
748 | project = Project.find(1) | |
748 | overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project, :parent => TimeEntryActivity.first, :active => false}) |
|
749 | overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project, :parent => TimeEntryActivity.first, :active => false}) | |
749 | assert overridden_activity.save! |
|
750 | assert overridden_activity.save! | |
750 |
|
751 | |||
751 | assert !project.activities.include?(overridden_activity), "Inactive Project specific Activity found" |
|
752 | assert !project.activities.include?(overridden_activity), "Inactive Project specific Activity found" | |
752 | end |
|
753 | end | |
753 |
|
754 | |||
754 | def test_activities_should_not_include_project_specific_activities_from_other_projects |
|
755 | def test_activities_should_not_include_project_specific_activities_from_other_projects | |
755 | project = Project.find(1) |
|
756 | project = Project.find(1) | |
756 | overridden_activity = TimeEntryActivity.new({:name => "Project", :project => Project.find(2)}) |
|
757 | overridden_activity = TimeEntryActivity.new({:name => "Project", :project => Project.find(2)}) | |
757 | assert overridden_activity.save! |
|
758 | assert overridden_activity.save! | |
758 |
|
759 | |||
759 | assert !project.activities.include?(overridden_activity), "Project specific Activity found on a different project" |
|
760 | assert !project.activities.include?(overridden_activity), "Project specific Activity found on a different project" | |
760 | end |
|
761 | end | |
761 |
|
762 | |||
762 | def test_activities_should_handle_nils |
|
763 | def test_activities_should_handle_nils | |
763 | overridden_activity = TimeEntryActivity.new({:name => "Project", :project => Project.find(1), :parent => TimeEntryActivity.first}) |
|
764 | overridden_activity = TimeEntryActivity.new({:name => "Project", :project => Project.find(1), :parent => TimeEntryActivity.first}) | |
764 | TimeEntryActivity.delete_all |
|
765 | TimeEntryActivity.delete_all | |
765 |
|
766 | |||
766 | # No activities |
|
767 | # No activities | |
767 | project = Project.find(1) |
|
768 | project = Project.find(1) | |
768 | assert project.activities.empty? |
|
769 | assert project.activities.empty? | |
769 |
|
770 | |||
770 | # No system, one overridden |
|
771 | # No system, one overridden | |
771 | assert overridden_activity.save! |
|
772 | assert overridden_activity.save! | |
772 | project.reload |
|
773 | project.reload | |
773 | assert_equal [overridden_activity], project.activities |
|
774 | assert_equal [overridden_activity], project.activities | |
774 | end |
|
775 | end | |
775 |
|
776 | |||
776 | def test_activities_should_override_system_activities_with_project_activities |
|
777 | def test_activities_should_override_system_activities_with_project_activities | |
777 | project = Project.find(1) |
|
778 | project = Project.find(1) | |
778 | parent_activity = TimeEntryActivity.first |
|
779 | parent_activity = TimeEntryActivity.first | |
779 | overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project, :parent => parent_activity}) |
|
780 | overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project, :parent => parent_activity}) | |
780 | assert overridden_activity.save! |
|
781 | assert overridden_activity.save! | |
781 |
|
782 | |||
782 | assert project.activities.include?(overridden_activity), "Project specific Activity not found" |
|
783 | assert project.activities.include?(overridden_activity), "Project specific Activity not found" | |
783 | assert !project.activities.include?(parent_activity), "System Activity found when it should have been overridden" |
|
784 | assert !project.activities.include?(parent_activity), "System Activity found when it should have been overridden" | |
784 | end |
|
785 | end | |
785 |
|
786 | |||
786 | def test_activities_should_include_inactive_activities_if_specified |
|
787 | def test_activities_should_include_inactive_activities_if_specified | |
787 | project = Project.find(1) |
|
788 | project = Project.find(1) | |
788 | overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project, :parent => TimeEntryActivity.first, :active => false}) |
|
789 | overridden_activity = TimeEntryActivity.new({:name => "Project", :project => project, :parent => TimeEntryActivity.first, :active => false}) | |
789 | assert overridden_activity.save! |
|
790 | assert overridden_activity.save! | |
790 |
|
791 | |||
791 | assert project.activities(true).include?(overridden_activity), "Inactive Project specific Activity not found" |
|
792 | assert project.activities(true).include?(overridden_activity), "Inactive Project specific Activity not found" | |
792 | end |
|
793 | end | |
793 |
|
794 | |||
794 | test 'activities should not include active System activities if the project has an override that is inactive' do |
|
795 | test 'activities should not include active System activities if the project has an override that is inactive' do | |
795 | project = Project.find(1) |
|
796 | project = Project.find(1) | |
796 | system_activity = TimeEntryActivity.find_by_name('Design') |
|
797 | system_activity = TimeEntryActivity.find_by_name('Design') | |
797 | assert system_activity.active? |
|
798 | assert system_activity.active? | |
798 | overridden_activity = TimeEntryActivity.create!(:name => "Project", :project => project, :parent => system_activity, :active => false) |
|
799 | overridden_activity = TimeEntryActivity.create!(:name => "Project", :project => project, :parent => system_activity, :active => false) | |
799 | assert overridden_activity.save! |
|
800 | assert overridden_activity.save! | |
800 |
|
801 | |||
801 | assert !project.activities.include?(overridden_activity), "Inactive Project specific Activity not found" |
|
802 | assert !project.activities.include?(overridden_activity), "Inactive Project specific Activity not found" | |
802 | assert !project.activities.include?(system_activity), "System activity found when the project has an inactive override" |
|
803 | assert !project.activities.include?(system_activity), "System activity found when the project has an inactive override" | |
803 | end |
|
804 | end | |
804 |
|
805 | |||
805 | def test_close_completed_versions |
|
806 | def test_close_completed_versions | |
806 | Version.update_all("status = 'open'") |
|
807 | Version.update_all("status = 'open'") | |
807 | project = Project.find(1) |
|
808 | project = Project.find(1) | |
808 | assert_not_nil project.versions.detect {|v| v.completed? && v.status == 'open'} |
|
809 | assert_not_nil project.versions.detect {|v| v.completed? && v.status == 'open'} | |
809 | assert_not_nil project.versions.detect {|v| !v.completed? && v.status == 'open'} |
|
810 | assert_not_nil project.versions.detect {|v| !v.completed? && v.status == 'open'} | |
810 | project.close_completed_versions |
|
811 | project.close_completed_versions | |
811 | project.reload |
|
812 | project.reload | |
812 | assert_nil project.versions.detect {|v| v.completed? && v.status != 'closed'} |
|
813 | assert_nil project.versions.detect {|v| v.completed? && v.status != 'closed'} | |
813 | assert_not_nil project.versions.detect {|v| !v.completed? && v.status == 'open'} |
|
814 | assert_not_nil project.versions.detect {|v| !v.completed? && v.status == 'open'} | |
814 | end |
|
815 | end | |
815 |
|
816 | |||
816 | test "#start_date should be nil if there are no issues on the project" do |
|
817 | test "#start_date should be nil if there are no issues on the project" do | |
817 | project = Project.generate! |
|
818 | project = Project.generate! | |
818 | assert_nil project.start_date |
|
819 | assert_nil project.start_date | |
819 | end |
|
820 | end | |
820 |
|
821 | |||
821 | test "#start_date should be nil when issues have no start date" do |
|
822 | test "#start_date should be nil when issues have no start date" do | |
822 | project = Project.generate! |
|
823 | project = Project.generate! | |
823 | project.trackers << Tracker.generate! |
|
824 | project.trackers << Tracker.generate! | |
824 | early = 7.days.ago.to_date |
|
825 | early = 7.days.ago.to_date | |
825 | Issue.generate!(:project => project, :start_date => nil) |
|
826 | Issue.generate!(:project => project, :start_date => nil) | |
826 |
|
827 | |||
827 | assert_nil project.start_date |
|
828 | assert_nil project.start_date | |
828 | end |
|
829 | end | |
829 |
|
830 | |||
830 | test "#start_date should be the earliest start date of it's issues" do |
|
831 | test "#start_date should be the earliest start date of it's issues" do | |
831 | project = Project.generate! |
|
832 | project = Project.generate! | |
832 | project.trackers << Tracker.generate! |
|
833 | project.trackers << Tracker.generate! | |
833 | early = 7.days.ago.to_date |
|
834 | early = 7.days.ago.to_date | |
834 | Issue.generate!(:project => project, :start_date => Date.today) |
|
835 | Issue.generate!(:project => project, :start_date => Date.today) | |
835 | Issue.generate!(:project => project, :start_date => early) |
|
836 | Issue.generate!(:project => project, :start_date => early) | |
836 |
|
837 | |||
837 | assert_equal early, project.start_date |
|
838 | assert_equal early, project.start_date | |
838 | end |
|
839 | end | |
839 |
|
840 | |||
840 | test "#due_date should be nil if there are no issues on the project" do |
|
841 | test "#due_date should be nil if there are no issues on the project" do | |
841 | project = Project.generate! |
|
842 | project = Project.generate! | |
842 | assert_nil project.due_date |
|
843 | assert_nil project.due_date | |
843 | end |
|
844 | end | |
844 |
|
845 | |||
845 | test "#due_date should be nil if there are no issues with due dates" do |
|
846 | test "#due_date should be nil if there are no issues with due dates" do | |
846 | project = Project.generate! |
|
847 | project = Project.generate! | |
847 | project.trackers << Tracker.generate! |
|
848 | project.trackers << Tracker.generate! | |
848 | Issue.generate!(:project => project, :due_date => nil) |
|
849 | Issue.generate!(:project => project, :due_date => nil) | |
849 |
|
850 | |||
850 | assert_nil project.due_date |
|
851 | assert_nil project.due_date | |
851 | end |
|
852 | end | |
852 |
|
853 | |||
853 | test "#due_date should be the latest due date of it's issues" do |
|
854 | test "#due_date should be the latest due date of it's issues" do | |
854 | project = Project.generate! |
|
855 | project = Project.generate! | |
855 | project.trackers << Tracker.generate! |
|
856 | project.trackers << Tracker.generate! | |
856 | future = 7.days.from_now.to_date |
|
857 | future = 7.days.from_now.to_date | |
857 | Issue.generate!(:project => project, :due_date => future) |
|
858 | Issue.generate!(:project => project, :due_date => future) | |
858 | Issue.generate!(:project => project, :due_date => Date.today) |
|
859 | Issue.generate!(:project => project, :due_date => Date.today) | |
859 |
|
860 | |||
860 | assert_equal future, project.due_date |
|
861 | assert_equal future, project.due_date | |
861 | end |
|
862 | end | |
862 |
|
863 | |||
863 | test "#due_date should be the latest due date of it's versions" do |
|
864 | test "#due_date should be the latest due date of it's versions" do | |
864 | project = Project.generate! |
|
865 | project = Project.generate! | |
865 | future = 7.days.from_now.to_date |
|
866 | future = 7.days.from_now.to_date | |
866 | project.versions << Version.generate!(:effective_date => future) |
|
867 | project.versions << Version.generate!(:effective_date => future) | |
867 | project.versions << Version.generate!(:effective_date => Date.today) |
|
868 | project.versions << Version.generate!(:effective_date => Date.today) | |
868 |
|
869 | |||
869 | assert_equal future, project.due_date |
|
870 | assert_equal future, project.due_date | |
870 | end |
|
871 | end | |
871 |
|
872 | |||
872 | test "#due_date should pick the latest date from it's issues and versions" do |
|
873 | test "#due_date should pick the latest date from it's issues and versions" do | |
873 | project = Project.generate! |
|
874 | project = Project.generate! | |
874 | project.trackers << Tracker.generate! |
|
875 | project.trackers << Tracker.generate! | |
875 | future = 7.days.from_now.to_date |
|
876 | future = 7.days.from_now.to_date | |
876 | far_future = 14.days.from_now.to_date |
|
877 | far_future = 14.days.from_now.to_date | |
877 | Issue.generate!(:project => project, :due_date => far_future) |
|
878 | Issue.generate!(:project => project, :due_date => far_future) | |
878 | project.versions << Version.generate!(:effective_date => future) |
|
879 | project.versions << Version.generate!(:effective_date => future) | |
879 |
|
880 | |||
880 | assert_equal far_future, project.due_date |
|
881 | assert_equal far_future, project.due_date | |
881 | end |
|
882 | end | |
882 |
|
883 | |||
883 | test "#completed_percent with no versions should be 100" do |
|
884 | test "#completed_percent with no versions should be 100" do | |
884 | project = Project.generate! |
|
885 | project = Project.generate! | |
885 | assert_equal 100, project.completed_percent |
|
886 | assert_equal 100, project.completed_percent | |
886 | end |
|
887 | end | |
887 |
|
888 | |||
888 | test "#completed_percent with versions should return 0 if the versions have no issues" do |
|
889 | test "#completed_percent with versions should return 0 if the versions have no issues" do | |
889 | project = Project.generate! |
|
890 | project = Project.generate! | |
890 | Version.generate!(:project => project) |
|
891 | Version.generate!(:project => project) | |
891 | Version.generate!(:project => project) |
|
892 | Version.generate!(:project => project) | |
892 |
|
893 | |||
893 | assert_equal 0, project.completed_percent |
|
894 | assert_equal 0, project.completed_percent | |
894 | end |
|
895 | end | |
895 |
|
896 | |||
896 | test "#completed_percent with versions should return 100 if the version has only closed issues" do |
|
897 | test "#completed_percent with versions should return 100 if the version has only closed issues" do | |
897 | project = Project.generate! |
|
898 | project = Project.generate! | |
898 | project.trackers << Tracker.generate! |
|
899 | project.trackers << Tracker.generate! | |
899 | v1 = Version.generate!(:project => project) |
|
900 | v1 = Version.generate!(:project => project) | |
900 | Issue.generate!(:project => project, :status => IssueStatus.find_by_name('Closed'), :fixed_version => v1) |
|
901 | Issue.generate!(:project => project, :status => IssueStatus.find_by_name('Closed'), :fixed_version => v1) | |
901 | v2 = Version.generate!(:project => project) |
|
902 | v2 = Version.generate!(:project => project) | |
902 | Issue.generate!(:project => project, :status => IssueStatus.find_by_name('Closed'), :fixed_version => v2) |
|
903 | Issue.generate!(:project => project, :status => IssueStatus.find_by_name('Closed'), :fixed_version => v2) | |
903 |
|
904 | |||
904 | assert_equal 100, project.completed_percent |
|
905 | assert_equal 100, project.completed_percent | |
905 | end |
|
906 | end | |
906 |
|
907 | |||
907 | test "#completed_percent with versions should return the averaged completed percent of the versions (not weighted)" do |
|
908 | test "#completed_percent with versions should return the averaged completed percent of the versions (not weighted)" do | |
908 | project = Project.generate! |
|
909 | project = Project.generate! | |
909 | project.trackers << Tracker.generate! |
|
910 | project.trackers << Tracker.generate! | |
910 | v1 = Version.generate!(:project => project) |
|
911 | v1 = Version.generate!(:project => project) | |
911 | Issue.generate!(:project => project, :status => IssueStatus.find_by_name('New'), :estimated_hours => 10, :done_ratio => 50, :fixed_version => v1) |
|
912 | Issue.generate!(:project => project, :status => IssueStatus.find_by_name('New'), :estimated_hours => 10, :done_ratio => 50, :fixed_version => v1) | |
912 | v2 = Version.generate!(:project => project) |
|
913 | v2 = Version.generate!(:project => project) | |
913 | Issue.generate!(:project => project, :status => IssueStatus.find_by_name('New'), :estimated_hours => 10, :done_ratio => 50, :fixed_version => v2) |
|
914 | Issue.generate!(:project => project, :status => IssueStatus.find_by_name('New'), :estimated_hours => 10, :done_ratio => 50, :fixed_version => v2) | |
914 |
|
915 | |||
915 | assert_equal 50, project.completed_percent |
|
916 | assert_equal 50, project.completed_percent | |
916 | end |
|
917 | end | |
917 |
|
918 | |||
918 | test "#notified_users" do |
|
919 | test "#notified_users" do | |
919 | project = Project.generate! |
|
920 | project = Project.generate! | |
920 | role = Role.generate! |
|
921 | role = Role.generate! | |
921 |
|
922 | |||
922 | user_with_membership_notification = User.generate!(:mail_notification => 'selected') |
|
923 | user_with_membership_notification = User.generate!(:mail_notification => 'selected') | |
923 | Member.create!(:project => project, :roles => [role], :principal => user_with_membership_notification, :mail_notification => true) |
|
924 | Member.create!(:project => project, :roles => [role], :principal => user_with_membership_notification, :mail_notification => true) | |
924 |
|
925 | |||
925 | all_events_user = User.generate!(:mail_notification => 'all') |
|
926 | all_events_user = User.generate!(:mail_notification => 'all') | |
926 | Member.create!(:project => project, :roles => [role], :principal => all_events_user) |
|
927 | Member.create!(:project => project, :roles => [role], :principal => all_events_user) | |
927 |
|
928 | |||
928 | no_events_user = User.generate!(:mail_notification => 'none') |
|
929 | no_events_user = User.generate!(:mail_notification => 'none') | |
929 | Member.create!(:project => project, :roles => [role], :principal => no_events_user) |
|
930 | Member.create!(:project => project, :roles => [role], :principal => no_events_user) | |
930 |
|
931 | |||
931 | only_my_events_user = User.generate!(:mail_notification => 'only_my_events') |
|
932 | only_my_events_user = User.generate!(:mail_notification => 'only_my_events') | |
932 | Member.create!(:project => project, :roles => [role], :principal => only_my_events_user) |
|
933 | Member.create!(:project => project, :roles => [role], :principal => only_my_events_user) | |
933 |
|
934 | |||
934 | only_assigned_user = User.generate!(:mail_notification => 'only_assigned') |
|
935 | only_assigned_user = User.generate!(:mail_notification => 'only_assigned') | |
935 | Member.create!(:project => project, :roles => [role], :principal => only_assigned_user) |
|
936 | Member.create!(:project => project, :roles => [role], :principal => only_assigned_user) | |
936 |
|
937 | |||
937 | only_owned_user = User.generate!(:mail_notification => 'only_owner') |
|
938 | only_owned_user = User.generate!(:mail_notification => 'only_owner') | |
938 | Member.create!(:project => project, :roles => [role], :principal => only_owned_user) |
|
939 | Member.create!(:project => project, :roles => [role], :principal => only_owned_user) | |
939 |
|
940 | |||
940 | assert project.notified_users.include?(user_with_membership_notification), "should include members with a mail notification" |
|
941 | assert project.notified_users.include?(user_with_membership_notification), "should include members with a mail notification" | |
941 | assert project.notified_users.include?(all_events_user), "should include users with the 'all' notification option" |
|
942 | assert project.notified_users.include?(all_events_user), "should include users with the 'all' notification option" | |
942 | assert !project.notified_users.include?(no_events_user), "should not include users with the 'none' notification option" |
|
943 | assert !project.notified_users.include?(no_events_user), "should not include users with the 'none' notification option" | |
943 | assert !project.notified_users.include?(only_my_events_user), "should not include users with the 'only_my_events' notification option" |
|
944 | assert !project.notified_users.include?(only_my_events_user), "should not include users with the 'only_my_events' notification option" | |
944 | assert !project.notified_users.include?(only_assigned_user), "should not include users with the 'only_assigned' notification option" |
|
945 | assert !project.notified_users.include?(only_assigned_user), "should not include users with the 'only_assigned' notification option" | |
945 | assert !project.notified_users.include?(only_owned_user), "should not include users with the 'only_owner' notification option" |
|
946 | assert !project.notified_users.include?(only_owned_user), "should not include users with the 'only_owner' notification option" | |
946 | end |
|
947 | end | |
947 |
|
948 | |||
948 | def test_override_roles_without_builtin_group_memberships |
|
949 | def test_override_roles_without_builtin_group_memberships | |
949 | project = Project.generate! |
|
950 | project = Project.generate! | |
950 | assert_equal [Role.anonymous], project.override_roles(Role.anonymous) |
|
951 | assert_equal [Role.anonymous], project.override_roles(Role.anonymous) | |
951 | assert_equal [Role.non_member], project.override_roles(Role.non_member) |
|
952 | assert_equal [Role.non_member], project.override_roles(Role.non_member) | |
952 | end |
|
953 | end | |
953 | end |
|
954 | end |
General Comments 0
You need to be logged in to leave comments.
Login now