@@ -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 | 770 | assert_not_nil project.versions.detect {|v| !v.completed? && v.status == 'open'} |
|
771 | 771 | end |
|
772 | 772 | |
|
773 | context "Project#copy" do | |
|
774 | setup do | |
|
775 | ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests | |
|
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 | |
|
1033 | ||
|
1034 | def test_copy_should_copy_subtasks | |
|
1035 | source = Project.generate!(:tracker_ids => [1]) | |
|
1036 | issue = Issue.generate_with_descendants!(:project => source) | |
|
1037 | project = Project.new(:name => 'Copy', :identifier => 'copy', :tracker_ids => [1]) | |
|
1038 | ||
|
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? | |
|
773 | test "#start_date should be nil if there are no issues on the project" do | |
|
774 | project = Project.generate! | |
|
775 | assert_nil project.start_date | |
|
1049 | 776 | end |
|
1050 | 777 | |
|
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 | |
|
778 | test "#start_date should be nil when issues have no start date" do | |
|
779 | project = Project.generate! | |
|
780 | project.trackers << Tracker.generate! | |
|
781 | early = 7.days.ago.to_date | |
|
782 | Issue.generate!(:project => project, :start_date => nil) | |
|
1057 | 783 | |
|
1058 | should "be nil if there are no issues on the project" do | |
|
1059 | assert_nil @project.start_date | |
|
784 | assert_nil project.start_date | |
|
1060 | 785 |
|
|
1061 | 786 | |
|
1062 | should "be tested when issues have no start date" | |
|
1063 | ||
|
1064 | should "be the earliest start date of it's issues" do | |
|
787 | test "#start_date should be the earliest start date of it's issues" do | |
|
788 | project = Project.generate! | |
|
789 | project.trackers << Tracker.generate! | |
|
1065 | 790 |
|
|
1066 |
|
|
|
1067 |
|
|
|
791 | Issue.generate!(:project => project, :start_date => Date.today) | |
|
792 | Issue.generate!(:project => project, :start_date => early) | |
|
1068 | 793 | |
|
1069 |
|
|
|
794 | assert_equal early, project.start_date | |
|
1070 | 795 |
|
|
1071 | 796 | |
|
797 | test "#due_date should be nil if there are no issues on the project" do | |
|
798 | project = Project.generate! | |
|
799 | assert_nil project.due_date | |
|
1072 | 800 | end |
|
1073 | 801 | |
|
1074 | context "#due_date" do | |
|
1075 | setup do | |
|
1076 | ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests | |
|
1077 | @project = Project.generate!(:identifier => 'test0') | |
|
1078 | @project.trackers << Tracker.generate! | |
|
1079 | end | |
|
802 | test "#due_date should be nil if there are no issues with due dates" do | |
|
803 | project = Project.generate! | |
|
804 | project.trackers << Tracker.generate! | |
|
805 | Issue.generate!(:project => project, :due_date => nil) | |
|
1080 | 806 | |
|
1081 | should "be nil if there are no issues on the project" do | |
|
1082 | assert_nil @project.due_date | |
|
807 | assert_nil project.due_date | |
|
1083 | 808 |
|
|
1084 | 809 | |
|
1085 | should "be tested when issues have no due date" | |
|
1086 | ||
|
1087 | should "be the latest due date of it's issues" do | |
|
810 | test "#due_date should be the latest due date of it's issues" do | |
|
811 | project = Project.generate! | |
|
812 | project.trackers << Tracker.generate! | |
|
1088 | 813 |
|
|
1089 |
|
|
|
1090 |
|
|
|
814 | Issue.generate!(:project => project, :due_date => future) | |
|
815 | Issue.generate!(:project => project, :due_date => Date.today) | |
|
1091 | 816 | |
|
1092 |
|
|
|
817 | assert_equal future, project.due_date | |
|
1093 | 818 |
|
|
1094 | 819 | |
|
1095 |
|
|
|
820 | test "#due_date should be the latest due date of it's versions" do | |
|
821 | project = Project.generate! | |
|
1096 | 822 |
|
|
1097 |
|
|
|
1098 |
|
|
|
1099 | ||
|
1100 | ||
|
1101 | assert_equal future, @project.due_date | |
|
823 | project.versions << Version.generate!(:effective_date => future) | |
|
824 | project.versions << Version.generate!(:effective_date => Date.today) | |
|
1102 | 825 | |
|
826 | assert_equal future, project.due_date | |
|
1103 | 827 |
|
|
1104 | 828 | |
|
1105 |
|
|
|
829 | test "#due_date should pick the latest date from it's issues and versions" do | |
|
830 | project = Project.generate! | |
|
831 | project.trackers << Tracker.generate! | |
|
1106 | 832 |
|
|
1107 | 833 |
|
|
1108 |
|
|
|
1109 |
|
|
|
1110 | ||
|
1111 | assert_equal far_future, @project.due_date | |
|
1112 | end | |
|
834 | Issue.generate!(:project => project, :due_date => far_future) | |
|
835 | project.versions << Version.generate!(:effective_date => future) | |
|
1113 | 836 | |
|
837 | assert_equal far_future, project.due_date | |
|
1114 | 838 | end |
|
1115 | 839 | |
|
1116 | context "Project#completed_percent" do | |
|
1117 | setup do | |
|
1118 | ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests | |
|
1119 | @project = Project.generate!(:identifier => 'test0') | |
|
1120 | @project.trackers << Tracker.generate! | |
|
1121 | end | |
|
1122 | ||
|
1123 | context "no versions" do | |
|
1124 | should "be 100" do | |
|
1125 | assert_equal 100, @project.completed_percent | |
|
1126 | end | |
|
840 | test "#completed_percent with no versions should be 100" do | |
|
841 | project = Project.generate! | |
|
842 | assert_equal 100, project.completed_percent | |
|
1127 | 843 |
|
|
1128 | 844 | |
|
1129 | context "with versions" do | |
|
1130 | should "return 0 if the versions have no issues" do | |
|
1131 |
|
|
|
1132 |
|
|
|
845 | test "#completed_percent with versions should return 0 if the versions have no issues" do | |
|
846 | project = Project.generate! | |
|
847 | Version.generate!(:project => project) | |
|
848 | Version.generate!(:project => project) | |
|
1133 | 849 | |
|
1134 |
|
|
|
850 | assert_equal 0, project.completed_percent | |
|
1135 | 851 |
|
|
1136 | 852 | |
|
1137 |
|
|
|
1138 | v1 = Version.generate!(:project => @project) | |
|
1139 | Issue.generate!(:project => @project, :status => IssueStatus.find_by_name('Closed'), :fixed_version => v1) | |
|
1140 |
|
|
|
1141 |
|
|
|
853 | test "#completed_percent with versions should return 100 if the version has only closed issues" do | |
|
854 | project = Project.generate! | |
|
855 | project.trackers << Tracker.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) | |
|
1142 | 860 | |
|
1143 |
|
|
|
861 | assert_equal 100, project.completed_percent | |
|
1144 | 862 |
|
|
1145 | 863 | |
|
1146 |
|
|
|
1147 | v1 = Version.generate!(:project => @project) | |
|
1148 | Issue.generate!(:project => @project, :status => IssueStatus.find_by_name('New'), :estimated_hours => 10, :done_ratio => 50, :fixed_version => v1) | |
|
1149 |
|
|
|
1150 |
|
|
|
1151 | ||
|
1152 | assert_equal 50, @project.completed_percent | |
|
1153 | end | |
|
864 | test "#completed_percent with versions should return the averaged completed percent of the versions (not weighted)" do | |
|
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) | |
|
1154 | 871 | |
|
872 | assert_equal 50, project.completed_percent | |
|
1155 | 873 |
|
|
1156 | end | |
|
1157 | ||
|
1158 | context "#notified_users" do | |
|
1159 | setup do | |
|
1160 | @project = Project.generate! | |
|
1161 | @role = Role.generate! | |
|
1162 | 874 | |
|
1163 | @user_with_membership_notification = User.generate!(:mail_notification => 'selected') | |
|
1164 | Member.create!(:project => @project, :roles => [@role], :principal => @user_with_membership_notification, :mail_notification => true) | |
|
1165 | ||
|
1166 | @all_events_user = User.generate!(:mail_notification => 'all') | |
|
1167 | Member.create!(:project => @project, :roles => [@role], :principal => @all_events_user) | |
|
875 | test "#notified_users" do | |
|
876 | project = Project.generate! | |
|
877 | role = Role.generate! | |
|
1168 | 878 | |
|
1169 |
|
|
|
1170 |
|
|
|
879 | user_with_membership_notification = User.generate!(:mail_notification => 'selected') | |
|
880 | Member.create!(:project => project, :roles => [role], :principal => user_with_membership_notification, :mail_notification => true) | |
|
1171 | 881 | |
|
1172 |
|
|
|
1173 |
|
|
|
882 | all_events_user = User.generate!(:mail_notification => 'all') | |
|
883 | Member.create!(:project => project, :roles => [role], :principal => all_events_user) | |
|
1174 | 884 | |
|
1175 |
|
|
|
1176 |
|
|
|
885 | no_events_user = User.generate!(:mail_notification => 'none') | |
|
886 | Member.create!(:project => project, :roles => [role], :principal => no_events_user) | |
|
1177 | 887 | |
|
1178 |
|
|
|
1179 |
|
|
|
1180 | end | |
|
888 | only_my_events_user = User.generate!(:mail_notification => 'only_my_events') | |
|
889 | Member.create!(:project => project, :roles => [role], :principal => only_my_events_user) | |
|
1181 | 890 | |
|
1182 | should "include members with a mail notification" do | |
|
1183 | assert @project.notified_users.include?(@user_with_membership_notification) | |
|
1184 | end | |
|
891 | only_assigned_user = User.generate!(:mail_notification => 'only_assigned') | |
|
892 | Member.create!(:project => project, :roles => [role], :principal => only_assigned_user) | |
|
1185 | 893 | |
|
1186 | should "include users with the 'all' notification option" do | |
|
1187 | assert @project.notified_users.include?(@all_events_user) | |
|
1188 | end | |
|
1189 | ||
|
1190 | should "not include users with the 'none' notification option" do | |
|
1191 | assert !@project.notified_users.include?(@no_events_user) | |
|
1192 | end | |
|
894 | only_owned_user = User.generate!(:mail_notification => 'only_owner') | |
|
895 | Member.create!(:project => project, :roles => [role], :principal => only_owned_user) | |
|
1193 | 896 | |
|
1194 | should "not include users with the 'only_my_events' notification option" do | |
|
1195 |
|
|
|
897 | assert project.notified_users.include?(user_with_membership_notification), "should include members with a mail notification" | |
|
898 | assert project.notified_users.include?(all_events_user), "should include users with the 'all' notification option" | |
|
899 | assert !project.notified_users.include?(no_events_user), "should not include users with the 'none' notification option" | |
|
900 | assert !project.notified_users.include?(only_my_events_user), "should not include users with the 'only_my_events' notification option" | |
|
901 | assert !project.notified_users.include?(only_assigned_user), "should not include users with the 'only_assigned' notification option" | |
|
902 | assert !project.notified_users.include?(only_owned_user), "should not include users with the 'only_owner' notification option" | |
|
1196 | 903 |
|
|
1197 | ||
|
1198 | should "not include users with the 'only_assigned' notification option" do | |
|
1199 | assert !@project.notified_users.include?(@only_assigned_user) | |
|
1200 | end | |
|
1201 | ||
|
1202 | should "not include users with the 'only_owner' notification option" do | |
|
1203 | assert !@project.notified_users.include?(@only_owned_user) | |
|
1204 | end | |
|
1205 | end | |
|
1206 | ||
|
1207 | 904 | end |
General Comments 0
You need to be logged in to leave comments.
Login now