@@ -0,0 +1,316 | |||||
|
1 | # Redmine - project management software | |||
|
2 | # Copyright (C) 2006-2013 Jean-Philippe Lang | |||
|
3 | # | |||
|
4 | # This program is free software; you can redistribute it and/or | |||
|
5 | # modify it under the terms of the GNU General Public License | |||
|
6 | # as published by the Free Software Foundation; either version 2 | |||
|
7 | # of the License, or (at your option) any later version. | |||
|
8 | # | |||
|
9 | # This program is distributed in the hope that it will be useful, | |||
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
12 | # GNU General Public License for more details. | |||
|
13 | # | |||
|
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 | |||
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
|
17 | ||||
|
18 | require File.expand_path('../../test_helper', __FILE__) | |||
|
19 | ||||
|
20 | class ProjectCopyTest < ActiveSupport::TestCase | |||
|
21 | fixtures :projects, :trackers, :issue_statuses, :issues, | |||
|
22 | :journals, :journal_details, | |||
|
23 | :enumerations, :users, :issue_categories, | |||
|
24 | :projects_trackers, | |||
|
25 | :custom_fields, | |||
|
26 | :custom_fields_projects, | |||
|
27 | :custom_fields_trackers, | |||
|
28 | :custom_values, | |||
|
29 | :roles, | |||
|
30 | :member_roles, | |||
|
31 | :members, | |||
|
32 | :enabled_modules, | |||
|
33 | :workflows, | |||
|
34 | :versions, | |||
|
35 | :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions, | |||
|
36 | :groups_users, | |||
|
37 | :boards, :messages, | |||
|
38 | :repositories, | |||
|
39 | :news, :comments, | |||
|
40 | :documents | |||
|
41 | ||||
|
42 | def setup | |||
|
43 | ProjectCustomField.destroy_all | |||
|
44 | @source_project = Project.find(2) | |||
|
45 | @project = Project.new(:name => 'Copy Test', :identifier => 'copy-test') | |||
|
46 | @project.trackers = @source_project.trackers | |||
|
47 | @project.enabled_module_names = @source_project.enabled_modules.collect(&:name) | |||
|
48 | end | |||
|
49 | ||||
|
50 | test "#copy should copy issues" do | |||
|
51 | @source_project.issues << Issue.generate!(:status => IssueStatus.find_by_name('Closed'), | |||
|
52 | :subject => "copy issue status", | |||
|
53 | :tracker_id => 1, | |||
|
54 | :assigned_to_id => 2, | |||
|
55 | :project_id => @source_project.id) | |||
|
56 | assert @project.valid? | |||
|
57 | assert @project.issues.empty? | |||
|
58 | assert @project.copy(@source_project) | |||
|
59 | ||||
|
60 | assert_equal @source_project.issues.size, @project.issues.size | |||
|
61 | @project.issues.each do |issue| | |||
|
62 | assert issue.valid? | |||
|
63 | assert ! issue.assigned_to.blank? | |||
|
64 | assert_equal @project, issue.project | |||
|
65 | end | |||
|
66 | ||||
|
67 | copied_issue = @project.issues.first(:conditions => {:subject => "copy issue status"}) | |||
|
68 | assert copied_issue | |||
|
69 | assert copied_issue.status | |||
|
70 | assert_equal "Closed", copied_issue.status.name | |||
|
71 | end | |||
|
72 | ||||
|
73 | test "#copy should copy issues assigned to a locked version" do | |||
|
74 | User.current = User.find(1) | |||
|
75 | assigned_version = Version.generate!(:name => "Assigned Issues") | |||
|
76 | @source_project.versions << assigned_version | |||
|
77 | Issue.generate!(:project => @source_project, | |||
|
78 | :fixed_version_id => assigned_version.id, | |||
|
79 | :subject => "copy issues assigned to a locked version") | |||
|
80 | assigned_version.update_attribute :status, 'locked' | |||
|
81 | ||||
|
82 | assert @project.copy(@source_project) | |||
|
83 | @project.reload | |||
|
84 | copied_issue = @project.issues.first(:conditions => {:subject => "copy issues assigned to a locked version"}) | |||
|
85 | ||||
|
86 | assert copied_issue | |||
|
87 | assert copied_issue.fixed_version | |||
|
88 | assert_equal "Assigned Issues", copied_issue.fixed_version.name # Same name | |||
|
89 | assert_equal 'locked', copied_issue.fixed_version.status | |||
|
90 | end | |||
|
91 | ||||
|
92 | test "#copy should change the new issues to use the copied version" do | |||
|
93 | User.current = User.find(1) | |||
|
94 | assigned_version = Version.generate!(:name => "Assigned Issues", :status => 'open') | |||
|
95 | @source_project.versions << assigned_version | |||
|
96 | assert_equal 3, @source_project.versions.size | |||
|
97 | Issue.generate!(:project => @source_project, | |||
|
98 | :fixed_version_id => assigned_version.id, | |||
|
99 | :subject => "change the new issues to use the copied version") | |||
|
100 | ||||
|
101 | assert @project.copy(@source_project) | |||
|
102 | @project.reload | |||
|
103 | copied_issue = @project.issues.first(:conditions => {:subject => "change the new issues to use the copied version"}) | |||
|
104 | ||||
|
105 | assert copied_issue | |||
|
106 | assert copied_issue.fixed_version | |||
|
107 | assert_equal "Assigned Issues", copied_issue.fixed_version.name # Same name | |||
|
108 | assert_not_equal assigned_version.id, copied_issue.fixed_version.id # Different record | |||
|
109 | end | |||
|
110 | ||||
|
111 | test "#copy should keep target shared versions from other project" do | |||
|
112 | assigned_version = Version.generate!(:name => "Assigned Issues", :status => 'open', :project_id => 1, :sharing => 'system') | |||
|
113 | issue = Issue.generate!(:project => @source_project, | |||
|
114 | :fixed_version => assigned_version, | |||
|
115 | :subject => "keep target shared versions") | |||
|
116 | ||||
|
117 | assert @project.copy(@source_project) | |||
|
118 | @project.reload | |||
|
119 | copied_issue = @project.issues.first(:conditions => {:subject => "keep target shared versions"}) | |||
|
120 | ||||
|
121 | assert copied_issue | |||
|
122 | assert_equal assigned_version, copied_issue.fixed_version | |||
|
123 | end | |||
|
124 | ||||
|
125 | test "#copy should copy issue relations" do | |||
|
126 | Setting.cross_project_issue_relations = '1' | |||
|
127 | ||||
|
128 | second_issue = Issue.generate!(:status_id => 5, | |||
|
129 | :subject => "copy issue relation", | |||
|
130 | :tracker_id => 1, | |||
|
131 | :assigned_to_id => 2, | |||
|
132 | :project_id => @source_project.id) | |||
|
133 | source_relation = IssueRelation.create!(:issue_from => Issue.find(4), | |||
|
134 | :issue_to => second_issue, | |||
|
135 | :relation_type => "relates") | |||
|
136 | source_relation_cross_project = IssueRelation.create!(:issue_from => Issue.find(1), | |||
|
137 | :issue_to => second_issue, | |||
|
138 | :relation_type => "duplicates") | |||
|
139 | ||||
|
140 | assert @project.copy(@source_project) | |||
|
141 | assert_equal @source_project.issues.count, @project.issues.count | |||
|
142 | copied_issue = @project.issues.find_by_subject("Issue on project 2") # Was #4 | |||
|
143 | copied_second_issue = @project.issues.find_by_subject("copy issue relation") | |||
|
144 | ||||
|
145 | # First issue with a relation on project | |||
|
146 | assert_equal 1, copied_issue.relations.size, "Relation not copied" | |||
|
147 | copied_relation = copied_issue.relations.first | |||
|
148 | assert_equal "relates", copied_relation.relation_type | |||
|
149 | assert_equal copied_second_issue.id, copied_relation.issue_to_id | |||
|
150 | assert_not_equal source_relation.id, copied_relation.id | |||
|
151 | ||||
|
152 | # Second issue with a cross project relation | |||
|
153 | assert_equal 2, copied_second_issue.relations.size, "Relation not copied" | |||
|
154 | copied_relation = copied_second_issue.relations.select {|r| r.relation_type == 'duplicates'}.first | |||
|
155 | assert_equal "duplicates", copied_relation.relation_type | |||
|
156 | assert_equal 1, copied_relation.issue_from_id, "Cross project relation not kept" | |||
|
157 | assert_not_equal source_relation_cross_project.id, copied_relation.id | |||
|
158 | end | |||
|
159 | ||||
|
160 | test "#copy should copy issue attachments" do | |||
|
161 | issue = Issue.generate!(:subject => "copy with attachment", :tracker_id => 1, :project_id => @source_project.id) | |||
|
162 | Attachment.create!(:container => issue, :file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 1) | |||
|
163 | @source_project.issues << issue | |||
|
164 | assert @project.copy(@source_project) | |||
|
165 | ||||
|
166 | copied_issue = @project.issues.first(:conditions => {:subject => "copy with attachment"}) | |||
|
167 | assert_not_nil copied_issue | |||
|
168 | assert_equal 1, copied_issue.attachments.count, "Attachment not copied" | |||
|
169 | assert_equal "testfile.txt", copied_issue.attachments.first.filename | |||
|
170 | end | |||
|
171 | ||||
|
172 | test "#copy should copy memberships" do | |||
|
173 | assert @project.valid? | |||
|
174 | assert @project.members.empty? | |||
|
175 | assert @project.copy(@source_project) | |||
|
176 | ||||
|
177 | assert_equal @source_project.memberships.size, @project.memberships.size | |||
|
178 | @project.memberships.each do |membership| | |||
|
179 | assert membership | |||
|
180 | assert_equal @project, membership.project | |||
|
181 | end | |||
|
182 | end | |||
|
183 | ||||
|
184 | test "#copy should copy memberships with groups and additional roles" do | |||
|
185 | group = Group.create!(:lastname => "Copy group") | |||
|
186 | user = User.find(7) | |||
|
187 | group.users << user | |||
|
188 | # group role | |||
|
189 | Member.create!(:project_id => @source_project.id, :principal => group, :role_ids => [2]) | |||
|
190 | member = Member.find_by_user_id_and_project_id(user.id, @source_project.id) | |||
|
191 | # additional role | |||
|
192 | member.role_ids = [1] | |||
|
193 | ||||
|
194 | assert @project.copy(@source_project) | |||
|
195 | member = Member.find_by_user_id_and_project_id(user.id, @project.id) | |||
|
196 | assert_not_nil member | |||
|
197 | assert_equal [1, 2], member.role_ids.sort | |||
|
198 | end | |||
|
199 | ||||
|
200 | test "#copy should copy project specific queries" do | |||
|
201 | assert @project.valid? | |||
|
202 | assert @project.queries.empty? | |||
|
203 | assert @project.copy(@source_project) | |||
|
204 | ||||
|
205 | assert_equal @source_project.queries.size, @project.queries.size | |||
|
206 | @project.queries.each do |query| | |||
|
207 | assert query | |||
|
208 | assert_equal @project, query.project | |||
|
209 | end | |||
|
210 | assert_equal @source_project.queries.map(&:user_id).sort, @project.queries.map(&:user_id).sort | |||
|
211 | end | |||
|
212 | ||||
|
213 | test "#copy should copy versions" do | |||
|
214 | @source_project.versions << Version.generate! | |||
|
215 | @source_project.versions << Version.generate! | |||
|
216 | ||||
|
217 | assert @project.versions.empty? | |||
|
218 | assert @project.copy(@source_project) | |||
|
219 | ||||
|
220 | assert_equal @source_project.versions.size, @project.versions.size | |||
|
221 | @project.versions.each do |version| | |||
|
222 | assert version | |||
|
223 | assert_equal @project, version.project | |||
|
224 | end | |||
|
225 | end | |||
|
226 | ||||
|
227 | test "#copy should copy wiki" do | |||
|
228 | assert_difference 'Wiki.count' do | |||
|
229 | assert @project.copy(@source_project) | |||
|
230 | end | |||
|
231 | ||||
|
232 | assert @project.wiki | |||
|
233 | assert_not_equal @source_project.wiki, @project.wiki | |||
|
234 | assert_equal "Start page", @project.wiki.start_page | |||
|
235 | end | |||
|
236 | ||||
|
237 | test "#copy should copy wiki pages and content with hierarchy" do | |||
|
238 | assert_difference 'WikiPage.count', @source_project.wiki.pages.size do | |||
|
239 | assert @project.copy(@source_project) | |||
|
240 | end | |||
|
241 | ||||
|
242 | assert @project.wiki | |||
|
243 | assert_equal @source_project.wiki.pages.size, @project.wiki.pages.size | |||
|
244 | ||||
|
245 | @project.wiki.pages.each do |wiki_page| | |||
|
246 | assert wiki_page.content | |||
|
247 | assert !@source_project.wiki.pages.include?(wiki_page) | |||
|
248 | end | |||
|
249 | ||||
|
250 | parent = @project.wiki.find_page('Parent_page') | |||
|
251 | child1 = @project.wiki.find_page('Child_page_1') | |||
|
252 | child2 = @project.wiki.find_page('Child_page_2') | |||
|
253 | assert_equal parent, child1.parent | |||
|
254 | assert_equal parent, child2.parent | |||
|
255 | end | |||
|
256 | ||||
|
257 | test "#copy should copy issue categories" do | |||
|
258 | assert @project.copy(@source_project) | |||
|
259 | ||||
|
260 | assert_equal 2, @project.issue_categories.size | |||
|
261 | @project.issue_categories.each do |issue_category| | |||
|
262 | assert !@source_project.issue_categories.include?(issue_category) | |||
|
263 | end | |||
|
264 | end | |||
|
265 | ||||
|
266 | test "#copy should copy boards" do | |||
|
267 | assert @project.copy(@source_project) | |||
|
268 | ||||
|
269 | assert_equal 1, @project.boards.size | |||
|
270 | @project.boards.each do |board| | |||
|
271 | assert !@source_project.boards.include?(board) | |||
|
272 | end | |||
|
273 | end | |||
|
274 | ||||
|
275 | test "#copy should change the new issues to use the copied issue categories" do | |||
|
276 | issue = Issue.find(4) | |||
|
277 | issue.update_attribute(:category_id, 3) | |||
|
278 | ||||
|
279 | assert @project.copy(@source_project) | |||
|
280 | ||||
|
281 | @project.issues.each do |issue| | |||
|
282 | assert issue.category | |||
|
283 | assert_equal "Stock management", issue.category.name # Same name | |||
|
284 | assert_not_equal IssueCategory.find(3), issue.category # Different record | |||
|
285 | end | |||
|
286 | end | |||
|
287 | ||||
|
288 | test "#copy should limit copy with :only option" do | |||
|
289 | assert @project.members.empty? | |||
|
290 | assert @project.issue_categories.empty? | |||
|
291 | assert @source_project.issues.any? | |||
|
292 | ||||
|
293 | assert @project.copy(@source_project, :only => ['members', 'issue_categories']) | |||
|
294 | ||||
|
295 | assert @project.members.any? | |||
|
296 | assert @project.issue_categories.any? | |||
|
297 | assert @project.issues.empty? | |||
|
298 | end | |||
|
299 | ||||
|
300 | test "#copy should copy subtasks" do | |||
|
301 | source = Project.generate!(:tracker_ids => [1]) | |||
|
302 | issue = Issue.generate_with_descendants!(:project => source) | |||
|
303 | project = Project.new(:name => 'Copy', :identifier => 'copy', :tracker_ids => [1]) | |||
|
304 | ||||
|
305 | assert_difference 'Project.count' do | |||
|
306 | assert_difference 'Issue.count', 1+issue.descendants.count do | |||
|
307 | assert project.copy(source.reload) | |||
|
308 | end | |||
|
309 | end | |||
|
310 | copy = Issue.where(:parent_id => nil).order("id DESC").first | |||
|
311 | assert_equal project, copy.project | |||
|
312 | assert_equal issue.descendants.count, copy.descendants.count | |||
|
313 | child_copy = copy.children.detect {|c| c.subject == 'Child1'} | |||
|
314 | assert child_copy.descendants.any? | |||
|
315 | end | |||
|
316 | end |
@@ -770,438 +770,135 class ProjectTest < ActiveSupport::TestCase | |||||
770 | 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'} | |
771 | end |
|
771 | end | |
772 |
|
772 | |||
773 | context "Project#copy" do |
|
773 | test "#start_date should be nil if there are no issues on the project" do | |
774 | setup do |
|
774 | project = Project.generate! | |
775 | ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests |
|
775 | assert_nil project.start_date | |
776 | Project.destroy_all :identifier => "copy-test" |
|
|||
777 | @source_project = Project.find(2) |
|
|||
778 | @project = Project.new(:name => 'Copy Test', :identifier => 'copy-test') |
|
|||
779 | @project.trackers = @source_project.trackers |
|
|||
780 | @project.enabled_module_names = @source_project.enabled_modules.collect(&:name) |
|
|||
781 | end |
|
|||
782 |
|
||||
783 | should "copy issues" do |
|
|||
784 | @source_project.issues << Issue.generate!(:status => IssueStatus.find_by_name('Closed'), |
|
|||
785 | :subject => "copy issue status", |
|
|||
786 | :tracker_id => 1, |
|
|||
787 | :assigned_to_id => 2, |
|
|||
788 | :project_id => @source_project.id) |
|
|||
789 | assert @project.valid? |
|
|||
790 | assert @project.issues.empty? |
|
|||
791 | assert @project.copy(@source_project) |
|
|||
792 |
|
||||
793 | assert_equal @source_project.issues.size, @project.issues.size |
|
|||
794 | @project.issues.each do |issue| |
|
|||
795 | assert issue.valid? |
|
|||
796 | assert ! issue.assigned_to.blank? |
|
|||
797 | assert_equal @project, issue.project |
|
|||
798 | end |
|
|||
799 |
|
||||
800 | copied_issue = @project.issues.first(:conditions => {:subject => "copy issue status"}) |
|
|||
801 | assert copied_issue |
|
|||
802 | assert copied_issue.status |
|
|||
803 | assert_equal "Closed", copied_issue.status.name |
|
|||
804 | end |
|
|||
805 |
|
||||
806 | should "copy issues assigned to a locked version" do |
|
|||
807 | User.current = User.find(1) |
|
|||
808 | assigned_version = Version.generate!(:name => "Assigned Issues") |
|
|||
809 | @source_project.versions << assigned_version |
|
|||
810 | Issue.generate!(:project => @source_project, |
|
|||
811 | :fixed_version_id => assigned_version.id, |
|
|||
812 | :subject => "copy issues assigned to a locked version") |
|
|||
813 | assigned_version.update_attribute :status, 'locked' |
|
|||
814 |
|
||||
815 | assert @project.copy(@source_project) |
|
|||
816 | @project.reload |
|
|||
817 | copied_issue = @project.issues.first(:conditions => {:subject => "copy issues assigned to a locked version"}) |
|
|||
818 |
|
||||
819 | assert copied_issue |
|
|||
820 | assert copied_issue.fixed_version |
|
|||
821 | assert_equal "Assigned Issues", copied_issue.fixed_version.name # Same name |
|
|||
822 | assert_equal 'locked', copied_issue.fixed_version.status |
|
|||
823 | end |
|
|||
824 |
|
||||
825 | should "change the new issues to use the copied version" do |
|
|||
826 | User.current = User.find(1) |
|
|||
827 | assigned_version = Version.generate!(:name => "Assigned Issues", :status => 'open') |
|
|||
828 | @source_project.versions << assigned_version |
|
|||
829 | assert_equal 3, @source_project.versions.size |
|
|||
830 | Issue.generate!(:project => @source_project, |
|
|||
831 | :fixed_version_id => assigned_version.id, |
|
|||
832 | :subject => "change the new issues to use the copied version") |
|
|||
833 |
|
||||
834 | assert @project.copy(@source_project) |
|
|||
835 | @project.reload |
|
|||
836 | copied_issue = @project.issues.first(:conditions => {:subject => "change the new issues to use the copied version"}) |
|
|||
837 |
|
||||
838 | assert copied_issue |
|
|||
839 | assert copied_issue.fixed_version |
|
|||
840 | assert_equal "Assigned Issues", copied_issue.fixed_version.name # Same name |
|
|||
841 | assert_not_equal assigned_version.id, copied_issue.fixed_version.id # Different record |
|
|||
842 | end |
|
|||
843 |
|
||||
844 | should "keep target shared versions from other project" do |
|
|||
845 | assigned_version = Version.generate!(:name => "Assigned Issues", :status => 'open', :project_id => 1, :sharing => 'system') |
|
|||
846 | issue = Issue.generate!(:project => @source_project, |
|
|||
847 | :fixed_version => assigned_version, |
|
|||
848 | :subject => "keep target shared versions") |
|
|||
849 |
|
||||
850 | assert @project.copy(@source_project) |
|
|||
851 | @project.reload |
|
|||
852 | copied_issue = @project.issues.first(:conditions => {:subject => "keep target shared versions"}) |
|
|||
853 |
|
||||
854 | assert copied_issue |
|
|||
855 | assert_equal assigned_version, copied_issue.fixed_version |
|
|||
856 | end |
|
|||
857 |
|
||||
858 | should "copy issue relations" do |
|
|||
859 | Setting.cross_project_issue_relations = '1' |
|
|||
860 |
|
||||
861 | second_issue = Issue.generate!(:status_id => 5, |
|
|||
862 | :subject => "copy issue relation", |
|
|||
863 | :tracker_id => 1, |
|
|||
864 | :assigned_to_id => 2, |
|
|||
865 | :project_id => @source_project.id) |
|
|||
866 | source_relation = IssueRelation.create!(:issue_from => Issue.find(4), |
|
|||
867 | :issue_to => second_issue, |
|
|||
868 | :relation_type => "relates") |
|
|||
869 | source_relation_cross_project = IssueRelation.create!(:issue_from => Issue.find(1), |
|
|||
870 | :issue_to => second_issue, |
|
|||
871 | :relation_type => "duplicates") |
|
|||
872 |
|
||||
873 | assert @project.copy(@source_project) |
|
|||
874 | assert_equal @source_project.issues.count, @project.issues.count |
|
|||
875 | copied_issue = @project.issues.find_by_subject("Issue on project 2") # Was #4 |
|
|||
876 | copied_second_issue = @project.issues.find_by_subject("copy issue relation") |
|
|||
877 |
|
||||
878 | # First issue with a relation on project |
|
|||
879 | assert_equal 1, copied_issue.relations.size, "Relation not copied" |
|
|||
880 | copied_relation = copied_issue.relations.first |
|
|||
881 | assert_equal "relates", copied_relation.relation_type |
|
|||
882 | assert_equal copied_second_issue.id, copied_relation.issue_to_id |
|
|||
883 | assert_not_equal source_relation.id, copied_relation.id |
|
|||
884 |
|
||||
885 | # Second issue with a cross project relation |
|
|||
886 | assert_equal 2, copied_second_issue.relations.size, "Relation not copied" |
|
|||
887 | copied_relation = copied_second_issue.relations.select {|r| r.relation_type == 'duplicates'}.first |
|
|||
888 | assert_equal "duplicates", copied_relation.relation_type |
|
|||
889 | assert_equal 1, copied_relation.issue_from_id, "Cross project relation not kept" |
|
|||
890 | assert_not_equal source_relation_cross_project.id, copied_relation.id |
|
|||
891 | end |
|
|||
892 |
|
||||
893 | should "copy issue attachments" do |
|
|||
894 | issue = Issue.generate!(:subject => "copy with attachment", :tracker_id => 1, :project_id => @source_project.id) |
|
|||
895 | Attachment.create!(:container => issue, :file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 1) |
|
|||
896 | @source_project.issues << issue |
|
|||
897 | assert @project.copy(@source_project) |
|
|||
898 |
|
||||
899 | copied_issue = @project.issues.first(:conditions => {:subject => "copy with attachment"}) |
|
|||
900 | assert_not_nil copied_issue |
|
|||
901 | assert_equal 1, copied_issue.attachments.count, "Attachment not copied" |
|
|||
902 | assert_equal "testfile.txt", copied_issue.attachments.first.filename |
|
|||
903 | end |
|
|||
904 |
|
||||
905 | should "copy memberships" do |
|
|||
906 | assert @project.valid? |
|
|||
907 | assert @project.members.empty? |
|
|||
908 | assert @project.copy(@source_project) |
|
|||
909 |
|
||||
910 | assert_equal @source_project.memberships.size, @project.memberships.size |
|
|||
911 | @project.memberships.each do |membership| |
|
|||
912 | assert membership |
|
|||
913 | assert_equal @project, membership.project |
|
|||
914 | end |
|
|||
915 | end |
|
|||
916 |
|
||||
917 | should "copy memberships with groups and additional roles" do |
|
|||
918 | group = Group.create!(:lastname => "Copy group") |
|
|||
919 | user = User.find(7) |
|
|||
920 | group.users << user |
|
|||
921 | # group role |
|
|||
922 | Member.create!(:project_id => @source_project.id, :principal => group, :role_ids => [2]) |
|
|||
923 | member = Member.find_by_user_id_and_project_id(user.id, @source_project.id) |
|
|||
924 | # additional role |
|
|||
925 | member.role_ids = [1] |
|
|||
926 |
|
||||
927 | assert @project.copy(@source_project) |
|
|||
928 | member = Member.find_by_user_id_and_project_id(user.id, @project.id) |
|
|||
929 | assert_not_nil member |
|
|||
930 | assert_equal [1, 2], member.role_ids.sort |
|
|||
931 | end |
|
|||
932 |
|
||||
933 | should "copy project specific queries" do |
|
|||
934 | assert @project.valid? |
|
|||
935 | assert @project.queries.empty? |
|
|||
936 | assert @project.copy(@source_project) |
|
|||
937 |
|
||||
938 | assert_equal @source_project.queries.size, @project.queries.size |
|
|||
939 | @project.queries.each do |query| |
|
|||
940 | assert query |
|
|||
941 | assert_equal @project, query.project |
|
|||
942 | end |
|
|||
943 | assert_equal @source_project.queries.map(&:user_id).sort, @project.queries.map(&:user_id).sort |
|
|||
944 | end |
|
|||
945 |
|
||||
946 | should "copy versions" do |
|
|||
947 | @source_project.versions << Version.generate! |
|
|||
948 | @source_project.versions << Version.generate! |
|
|||
949 |
|
||||
950 | assert @project.versions.empty? |
|
|||
951 | assert @project.copy(@source_project) |
|
|||
952 |
|
||||
953 | assert_equal @source_project.versions.size, @project.versions.size |
|
|||
954 | @project.versions.each do |version| |
|
|||
955 | assert version |
|
|||
956 | assert_equal @project, version.project |
|
|||
957 | end |
|
|||
958 | end |
|
|||
959 |
|
||||
960 | should "copy wiki" do |
|
|||
961 | assert_difference 'Wiki.count' do |
|
|||
962 | assert @project.copy(@source_project) |
|
|||
963 | end |
|
|||
964 |
|
||||
965 | assert @project.wiki |
|
|||
966 | assert_not_equal @source_project.wiki, @project.wiki |
|
|||
967 | assert_equal "Start page", @project.wiki.start_page |
|
|||
968 | end |
|
|||
969 |
|
||||
970 | should "copy wiki pages and content with hierarchy" do |
|
|||
971 | assert_difference 'WikiPage.count', @source_project.wiki.pages.size do |
|
|||
972 | assert @project.copy(@source_project) |
|
|||
973 | end |
|
|||
974 |
|
||||
975 | assert @project.wiki |
|
|||
976 | assert_equal @source_project.wiki.pages.size, @project.wiki.pages.size |
|
|||
977 |
|
||||
978 | @project.wiki.pages.each do |wiki_page| |
|
|||
979 | assert wiki_page.content |
|
|||
980 | assert !@source_project.wiki.pages.include?(wiki_page) |
|
|||
981 | end |
|
|||
982 |
|
||||
983 | parent = @project.wiki.find_page('Parent_page') |
|
|||
984 | child1 = @project.wiki.find_page('Child_page_1') |
|
|||
985 | child2 = @project.wiki.find_page('Child_page_2') |
|
|||
986 | assert_equal parent, child1.parent |
|
|||
987 | assert_equal parent, child2.parent |
|
|||
988 | end |
|
|||
989 |
|
||||
990 | should "copy issue categories" do |
|
|||
991 | assert @project.copy(@source_project) |
|
|||
992 |
|
||||
993 | assert_equal 2, @project.issue_categories.size |
|
|||
994 | @project.issue_categories.each do |issue_category| |
|
|||
995 | assert !@source_project.issue_categories.include?(issue_category) |
|
|||
996 | end |
|
|||
997 | end |
|
|||
998 |
|
||||
999 | should "copy boards" do |
|
|||
1000 | assert @project.copy(@source_project) |
|
|||
1001 |
|
||||
1002 | assert_equal 1, @project.boards.size |
|
|||
1003 | @project.boards.each do |board| |
|
|||
1004 | assert !@source_project.boards.include?(board) |
|
|||
1005 | end |
|
|||
1006 | end |
|
|||
1007 |
|
||||
1008 | should "change the new issues to use the copied issue categories" do |
|
|||
1009 | issue = Issue.find(4) |
|
|||
1010 | issue.update_attribute(:category_id, 3) |
|
|||
1011 |
|
||||
1012 | assert @project.copy(@source_project) |
|
|||
1013 |
|
||||
1014 | @project.issues.each do |issue| |
|
|||
1015 | assert issue.category |
|
|||
1016 | assert_equal "Stock management", issue.category.name # Same name |
|
|||
1017 | assert_not_equal IssueCategory.find(3), issue.category # Different record |
|
|||
1018 | end |
|
|||
1019 | end |
|
|||
1020 |
|
||||
1021 | should "limit copy with :only option" do |
|
|||
1022 | assert @project.members.empty? |
|
|||
1023 | assert @project.issue_categories.empty? |
|
|||
1024 | assert @source_project.issues.any? |
|
|||
1025 |
|
||||
1026 | assert @project.copy(@source_project, :only => ['members', 'issue_categories']) |
|
|||
1027 |
|
||||
1028 | assert @project.members.any? |
|
|||
1029 | assert @project.issue_categories.any? |
|
|||
1030 | assert @project.issues.empty? |
|
|||
1031 | end |
|
|||
1032 | end |
|
776 | end | |
1033 |
|
777 | |||
1034 | def test_copy_should_copy_subtasks |
|
778 | test "#start_date should be nil when issues have no start date" do | |
1035 |
|
|
779 | project = Project.generate! | |
1036 | issue = Issue.generate_with_descendants!(:project => source) |
|
780 | project.trackers << Tracker.generate! | |
1037 | project = Project.new(:name => 'Copy', :identifier => 'copy', :tracker_ids => [1]) |
|
781 | early = 7.days.ago.to_date | |
1038 |
|
782 | Issue.generate!(:project => project, :start_date => nil) | ||
1039 | assert_difference 'Project.count' do |
|
|||
1040 | assert_difference 'Issue.count', 1+issue.descendants.count do |
|
|||
1041 | assert project.copy(source.reload) |
|
|||
1042 | end |
|
|||
1043 | end |
|
|||
1044 | copy = Issue.where(:parent_id => nil).order("id DESC").first |
|
|||
1045 | assert_equal project, copy.project |
|
|||
1046 | assert_equal issue.descendants.count, copy.descendants.count |
|
|||
1047 | child_copy = copy.children.detect {|c| c.subject == 'Child1'} |
|
|||
1048 | assert child_copy.descendants.any? |
|
|||
1049 | end |
|
|||
1050 |
|
||||
1051 | context "#start_date" do |
|
|||
1052 | setup do |
|
|||
1053 | ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests |
|
|||
1054 | @project = Project.generate!(:identifier => 'test0') |
|
|||
1055 | @project.trackers << Tracker.generate! |
|
|||
1056 | end |
|
|||
1057 |
|
||||
1058 | should "be nil if there are no issues on the project" do |
|
|||
1059 | assert_nil @project.start_date |
|
|||
1060 | end |
|
|||
1061 |
|
||||
1062 | should "be tested when issues have no start date" |
|
|||
1063 |
|
||||
1064 | should "be the earliest start date of it's issues" do |
|
|||
1065 | early = 7.days.ago.to_date |
|
|||
1066 | Issue.generate!(:project => @project, :start_date => Date.today) |
|
|||
1067 | Issue.generate!(:project => @project, :start_date => early) |
|
|||
1068 |
|
||||
1069 | assert_equal early, @project.start_date |
|
|||
1070 | end |
|
|||
1071 |
|
783 | |||
|
784 | assert_nil project.start_date | |||
1072 | end |
|
785 | end | |
1073 |
|
786 | |||
1074 | context "#due_date" do |
|
787 | test "#start_date should be the earliest start date of it's issues" do | |
1075 | setup do |
|
788 | project = Project.generate! | |
1076 | ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests |
|
789 | project.trackers << Tracker.generate! | |
1077 | @project = Project.generate!(:identifier => 'test0') |
|
790 | early = 7.days.ago.to_date | |
1078 | @project.trackers << Tracker.generate! |
|
791 | Issue.generate!(:project => project, :start_date => Date.today) | |
1079 | end |
|
792 | Issue.generate!(:project => project, :start_date => early) | |
1080 |
|
||||
1081 | should "be nil if there are no issues on the project" do |
|
|||
1082 | assert_nil @project.due_date |
|
|||
1083 | end |
|
|||
1084 |
|
||||
1085 | should "be tested when issues have no due date" |
|
|||
1086 |
|
||||
1087 | should "be the latest due date of it's issues" do |
|
|||
1088 | future = 7.days.from_now.to_date |
|
|||
1089 | Issue.generate!(:project => @project, :due_date => future) |
|
|||
1090 | Issue.generate!(:project => @project, :due_date => Date.today) |
|
|||
1091 |
|
||||
1092 | assert_equal future, @project.due_date |
|
|||
1093 | end |
|
|||
1094 |
|
||||
1095 | should "be the latest due date of it's versions" do |
|
|||
1096 | future = 7.days.from_now.to_date |
|
|||
1097 | @project.versions << Version.generate!(:effective_date => future) |
|
|||
1098 | @project.versions << Version.generate!(:effective_date => Date.today) |
|
|||
1099 |
|
||||
1100 |
|
||||
1101 | assert_equal future, @project.due_date |
|
|||
1102 |
|
793 | |||
1103 | end |
|
794 | assert_equal early, project.start_date | |
|
795 | end | |||
1104 |
|
796 | |||
1105 | should "pick the latest date from it's issues and versions" do |
|
797 | test "#due_date should be nil if there are no issues on the project" do | |
1106 | future = 7.days.from_now.to_date |
|
798 | project = Project.generate! | |
1107 | far_future = 14.days.from_now.to_date |
|
799 | assert_nil project.due_date | |
1108 | Issue.generate!(:project => @project, :due_date => far_future) |
|
800 | end | |
1109 | @project.versions << Version.generate!(:effective_date => future) |
|
|||
1110 |
|
801 | |||
1111 | assert_equal far_future, @project.due_date |
|
802 | test "#due_date should be nil if there are no issues with due dates" do | |
1112 | end |
|
803 | project = Project.generate! | |
|
804 | project.trackers << Tracker.generate! | |||
|
805 | Issue.generate!(:project => project, :due_date => nil) | |||
1113 |
|
806 | |||
|
807 | assert_nil project.due_date | |||
1114 | end |
|
808 | end | |
1115 |
|
809 | |||
1116 | context "Project#completed_percent" do |
|
810 | test "#due_date should be the latest due date of it's issues" do | |
1117 | setup do |
|
811 | project = Project.generate! | |
1118 | ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests |
|
812 | project.trackers << Tracker.generate! | |
1119 | @project = Project.generate!(:identifier => 'test0') |
|
813 | future = 7.days.from_now.to_date | |
1120 | @project.trackers << Tracker.generate! |
|
814 | Issue.generate!(:project => project, :due_date => future) | |
1121 | end |
|
815 | Issue.generate!(:project => project, :due_date => Date.today) | |
1122 |
|
816 | |||
1123 | context "no versions" do |
|
817 | assert_equal future, project.due_date | |
1124 | should "be 100" do |
|
818 | end | |
1125 | assert_equal 100, @project.completed_percent |
|
|||
1126 | end |
|
|||
1127 | end |
|
|||
1128 |
|
819 | |||
1129 | context "with versions" do |
|
820 | test "#due_date should be the latest due date of it's versions" do | |
1130 | should "return 0 if the versions have no issues" do |
|
821 | project = Project.generate! | |
1131 | Version.generate!(:project => @project) |
|
822 | future = 7.days.from_now.to_date | |
1132 |
|
|
823 | project.versions << Version.generate!(:effective_date => future) | |
|
824 | project.versions << Version.generate!(:effective_date => Date.today) | |||
1133 |
|
825 | |||
1134 |
|
|
826 | assert_equal future, project.due_date | |
1135 |
|
|
827 | end | |
1136 |
|
828 | |||
1137 | should "return 100 if the version has only closed issues" do |
|
829 | test "#due_date should pick the latest date from it's issues and versions" do | |
1138 | v1 = Version.generate!(:project => @project) |
|
830 | project = Project.generate! | |
1139 | Issue.generate!(:project => @project, :status => IssueStatus.find_by_name('Closed'), :fixed_version => v1) |
|
831 | project.trackers << Tracker.generate! | |
1140 | v2 = Version.generate!(:project => @project) |
|
832 | future = 7.days.from_now.to_date | |
1141 | Issue.generate!(:project => @project, :status => IssueStatus.find_by_name('Closed'), :fixed_version => v2) |
|
833 | far_future = 14.days.from_now.to_date | |
|
834 | Issue.generate!(:project => project, :due_date => far_future) | |||
|
835 | project.versions << Version.generate!(:effective_date => future) | |||
1142 |
|
836 | |||
1143 |
|
|
837 | assert_equal far_future, project.due_date | |
1144 |
|
|
838 | end | |
1145 |
|
839 | |||
1146 | should "return the averaged completed percent of the versions (not weighted)" do |
|
840 | test "#completed_percent with no versions should be 100" do | |
1147 | v1 = Version.generate!(:project => @project) |
|
841 | project = Project.generate! | |
1148 | Issue.generate!(:project => @project, :status => IssueStatus.find_by_name('New'), :estimated_hours => 10, :done_ratio => 50, :fixed_version => v1) |
|
842 | assert_equal 100, project.completed_percent | |
1149 | v2 = Version.generate!(:project => @project) |
|
843 | end | |
1150 | Issue.generate!(:project => @project, :status => IssueStatus.find_by_name('New'), :estimated_hours => 10, :done_ratio => 50, :fixed_version => v2) |
|
|||
1151 |
|
844 | |||
1152 | assert_equal 50, @project.completed_percent |
|
845 | test "#completed_percent with versions should return 0 if the versions have no issues" do | |
1153 | end |
|
846 | project = Project.generate! | |
|
847 | Version.generate!(:project => project) | |||
|
848 | Version.generate!(:project => project) | |||
1154 |
|
849 | |||
1155 | end |
|
850 | assert_equal 0, project.completed_percent | |
1156 | end |
|
851 | end | |
1157 |
|
852 | |||
1158 | context "#notified_users" do |
|
853 | test "#completed_percent with versions should return 100 if the version has only closed issues" do | |
1159 | setup do |
|
854 | project = Project.generate! | |
1160 |
|
|
855 | project.trackers << Tracker.generate! | |
1161 | @role = Role.generate! |
|
856 | v1 = Version.generate!(:project => project) | |
|
857 | Issue.generate!(:project => project, :status => IssueStatus.find_by_name('Closed'), :fixed_version => v1) | |||
|
858 | v2 = Version.generate!(:project => project) | |||
|
859 | Issue.generate!(:project => project, :status => IssueStatus.find_by_name('Closed'), :fixed_version => v2) | |||
1162 |
|
860 | |||
1163 | @user_with_membership_notification = User.generate!(:mail_notification => 'selected') |
|
861 | assert_equal 100, project.completed_percent | |
1164 | Member.create!(:project => @project, :roles => [@role], :principal => @user_with_membership_notification, :mail_notification => true) |
|
862 | end | |
1165 |
|
863 | |||
1166 | @all_events_user = User.generate!(:mail_notification => 'all') |
|
864 | test "#completed_percent with versions should return the averaged completed percent of the versions (not weighted)" do | |
1167 | Member.create!(:project => @project, :roles => [@role], :principal => @all_events_user) |
|
865 | project = Project.generate! | |
|
866 | project.trackers << Tracker.generate! | |||
|
867 | v1 = Version.generate!(:project => project) | |||
|
868 | Issue.generate!(:project => project, :status => IssueStatus.find_by_name('New'), :estimated_hours => 10, :done_ratio => 50, :fixed_version => v1) | |||
|
869 | v2 = Version.generate!(:project => project) | |||
|
870 | Issue.generate!(:project => project, :status => IssueStatus.find_by_name('New'), :estimated_hours => 10, :done_ratio => 50, :fixed_version => v2) | |||
1168 |
|
871 | |||
1169 | @no_events_user = User.generate!(:mail_notification => 'none') |
|
872 | assert_equal 50, project.completed_percent | |
1170 | Member.create!(:project => @project, :roles => [@role], :principal => @no_events_user) |
|
873 | end | |
1171 |
|
874 | |||
1172 | @only_my_events_user = User.generate!(:mail_notification => 'only_my_events') |
|
875 | test "#notified_users" do | |
1173 | Member.create!(:project => @project, :roles => [@role], :principal => @only_my_events_user) |
|
876 | project = Project.generate! | |
|
877 | role = Role.generate! | |||
1174 |
|
878 | |||
1175 |
|
|
879 | user_with_membership_notification = User.generate!(:mail_notification => 'selected') | |
1176 |
|
|
880 | Member.create!(:project => project, :roles => [role], :principal => user_with_membership_notification, :mail_notification => true) | |
1177 |
|
881 | |||
1178 |
|
|
882 | all_events_user = User.generate!(:mail_notification => 'all') | |
1179 |
|
|
883 | Member.create!(:project => project, :roles => [role], :principal => all_events_user) | |
1180 | end |
|
|||
1181 |
|
884 | |||
1182 | should "include members with a mail notification" do |
|
885 | no_events_user = User.generate!(:mail_notification => 'none') | |
1183 | assert @project.notified_users.include?(@user_with_membership_notification) |
|
886 | Member.create!(:project => project, :roles => [role], :principal => no_events_user) | |
1184 | end |
|
|||
1185 |
|
887 | |||
1186 | should "include users with the 'all' notification option" do |
|
888 | only_my_events_user = User.generate!(:mail_notification => 'only_my_events') | |
1187 | assert @project.notified_users.include?(@all_events_user) |
|
889 | Member.create!(:project => project, :roles => [role], :principal => only_my_events_user) | |
1188 | end |
|
|||
1189 |
|
890 | |||
1190 | should "not include users with the 'none' notification option" do |
|
891 | only_assigned_user = User.generate!(:mail_notification => 'only_assigned') | |
1191 | assert !@project.notified_users.include?(@no_events_user) |
|
892 | Member.create!(:project => project, :roles => [role], :principal => only_assigned_user) | |
1192 | end |
|
|||
1193 |
|
893 | |||
1194 | should "not include users with the 'only_my_events' notification option" do |
|
894 | only_owned_user = User.generate!(:mail_notification => 'only_owner') | |
1195 | assert !@project.notified_users.include?(@only_my_events_user) |
|
895 | Member.create!(:project => project, :roles => [role], :principal => only_owned_user) | |
1196 | end |
|
|||
1197 |
|
896 | |||
1198 | should "not include users with the 'only_assigned' notification option" do |
|
897 | assert project.notified_users.include?(user_with_membership_notification), "should include members with a mail notification" | |
1199 | assert !@project.notified_users.include?(@only_assigned_user) |
|
898 | assert project.notified_users.include?(all_events_user), "should include users with the 'all' notification option" | |
1200 | end |
|
899 | assert !project.notified_users.include?(no_events_user), "should not include users with the 'none' notification option" | |
1201 |
|
900 | assert !project.notified_users.include?(only_my_events_user), "should not include users with the 'only_my_events' notification option" | ||
1202 |
|
|
901 | assert !project.notified_users.include?(only_assigned_user), "should not include users with the 'only_assigned' notification option" | |
1203 |
|
|
902 | assert !project.notified_users.include?(only_owned_user), "should not include users with the 'only_owner' notification option" | |
1204 | end |
|
|||
1205 | end |
|
903 | end | |
1206 |
|
||||
1207 | end |
|
904 | end |
General Comments 0
You need to be logged in to leave comments.
Login now