3 class ActionsControllerTest < ActionController::TestCase
6 post :report_issue, {format: 'js'}, session_for(:admin)
7 assert_response :success
10 ActionMailer::Base.deliveries.andand.each do |email|
11 if email.subject.include? "Issue reported by admin"
16 assert_equal true, found_email, 'Expected email after issue reported'
19 test "combine files into new collection" do
20 post(:combine_selected_files_into_collection, {
21 selection: ['zzzzz-4zz18-znfnqtbbv4spc3w/foo',
22 'zzzzz-4zz18-ehbhgtheo8909or/bar',
23 'zzzzz-4zz18-y9vne9npefyxh8g/baz',
24 '7a6ef4c162a5c6413070a8bd0bffc818+150'],
28 assert_response 302 # collection created and redirected to new collection page
30 assert response.headers['Location'].include? '/collections/'
31 new_collection_uuid = response.headers['Location'].split('/')[-1]
34 collection = Collection.select([:uuid, :manifest_text]).where(uuid: new_collection_uuid).first
35 manifest_text = collection['manifest_text']
36 assert manifest_text.include?('foo'), 'Not found foo in new collection manifest text'
37 assert manifest_text.include?('bar'), 'Not found bar in new collection manifest text'
38 assert manifest_text.include?('baz'), 'Not found baz in new collection manifest text'
39 assert manifest_text.include?('0:0:file1 0:0:file2 0:0:file3'),
40 'Not found 0:0:file1 0:0:file2 0:0:file3 in new collection manifest text'
41 assert manifest_text.include?('dir1/subdir'), 'Not found dir1/subdir in new collection manifest text'
42 assert manifest_text.include?('dir2'), 'Not found dir2 in new collection manifest text'
45 test "combine files with repeated names into new collection" do
46 post(:combine_selected_files_into_collection, {
47 selection: ['zzzzz-4zz18-znfnqtbbv4spc3w/foo',
48 'zzzzz-4zz18-00000nonamecoll/foo',
49 'zzzzz-4zz18-abcd6fx123409f7/foo',
50 'zzzzz-4zz18-ehbhgtheo8909or/bar',
51 'zzzzz-4zz18-y9vne9npefyxh8g/baz',
52 '7a6ef4c162a5c6413070a8bd0bffc818+150'],
56 assert_response 302 # collection created and redirected to new collection page
58 assert response.headers['Location'].include? '/collections/'
59 new_collection_uuid = response.headers['Location'].split('/')[-1]
62 collection = Collection.select([:uuid, :manifest_text]).where(uuid: new_collection_uuid).first
63 manifest_text = collection['manifest_text']
64 assert manifest_text.include?('foo'), 'Not found foo in new collection manifest text'
65 assert manifest_text.include?('foo(1)'), 'Not found foo(1) in new collection manifest text'
66 assert manifest_text.include?('foo(2)'), 'Not found foo(2) in new collection manifest text'
67 assert manifest_text.include?('bar'), 'Not found bar in new collection manifest text'
68 assert manifest_text.include?('baz'), 'Not found baz in new collection manifest text'
69 assert manifest_text.include?('0:0:file1 0:0:file2 0:0:file3'),
70 'Not found 0:0:file1 0:0:file2 0:0:file3 in new collection manifest text'
71 assert manifest_text.include?('dir1/subdir'), 'Not found dir1/subdir in new collection manifest text'
72 assert manifest_text.include?('dir2'), 'Not found dir2 in new collection manifest text'
75 test "combine collections with repeated filenames in almost similar directories and expect files with proper suffixes" do
76 post(:combine_selected_files_into_collection, {
77 selection: ['zzzzz-4zz18-duplicatenames1',
78 'zzzzz-4zz18-duplicatenames2',
79 'zzzzz-4zz18-znfnqtbbv4spc3w/foo',
80 'zzzzz-4zz18-00000nonamecoll/foo',],
84 assert_response 302 # collection created and redirected to new collection page
86 assert response.headers['Location'].include? '/collections/'
87 new_collection_uuid = response.headers['Location'].split('/')[-1]
90 collection = Collection.select([:uuid, :manifest_text]).where(uuid: new_collection_uuid).first
91 manifest_text = collection['manifest_text']
93 assert manifest_text.include?('foo'), 'Not found foo in new collection manifest text'
94 assert manifest_text.include?('foo(1)'), 'Not found foo(1) in new collection manifest text'
96 streams = manifest_text.split "\n"
97 streams.each do |stream|
98 if stream.start_with? './dir1'
100 assert stream.include?(':alice(1)'), "Not found: alice(1) in dir1 in manifest text #{manifest_text}"
101 assert stream.include?(':alice.txt'), "Not found: alice.txt in dir1 in manifest text #{manifest_text}"
102 assert stream.include?(':alice(1).txt'), "Not found: alice(1).txt in dir1 in manifest text #{manifest_text}"
103 assert stream.include?(':bob.txt'), "Not found: bob.txt in dir1 in manifest text #{manifest_text}"
104 assert stream.include?(':carol.txt'), "Not found: carol.txt in dir1 in manifest text #{manifest_text}"
105 elsif stream.start_with? './dir2'
107 assert stream.include?(':alice.txt'), "Not found: alice.txt in dir2 in manifest text #{manifest_text}"
108 assert stream.include?(':alice(1).txt'), "Not found: alice(1).txt in dir2 in manifest text #{manifest_text}"
109 elsif stream.start_with? '. '
111 assert stream.include?(':foo'), "Not found: foo in . in manifest text #{manifest_text}"
112 assert stream.include?(':foo(1)'), "Not found: foo(1) in . in manifest text #{manifest_text}"
117 test "combine collections with same filename in two different streams and expect no suffixes for filenames" do
118 post(:combine_selected_files_into_collection, {
119 selection: ['zzzzz-4zz18-znfnqtbbv4spc3w',
120 'zzzzz-4zz18-foonbarfilesdir'],
122 session_for(:active))
124 assert_response 302 # collection created and redirected to new collection page
126 assert response.headers['Location'].include? '/collections/'
127 new_collection_uuid = response.headers['Location'].split('/')[-1]
130 collection = Collection.select([:uuid, :manifest_text]).where(uuid: new_collection_uuid).first
131 manifest_text = collection['manifest_text']
133 streams = manifest_text.split "\n"
134 assert_equal 2, streams.length
135 streams.each do |stream|
136 if stream.start_with? './dir1'
137 assert stream.include?('foo'), 'Not found: foo in dir1'
138 elsif stream.start_with? '. '
139 assert stream.include?('foo'), 'Not found: foo in .'
142 assert !manifest_text.include?('foo(1)'), 'Found foo(1) in new collection manifest text'
145 test "combine foo files from two different collection streams and expect proper filename suffixes" do
146 post(:combine_selected_files_into_collection, {
147 selection: ['zzzzz-4zz18-znfnqtbbv4spc3w/foo',
148 'zzzzz-4zz18-foonbarfilesdir/dir1/foo'],
150 session_for(:active))
152 assert_response 302 # collection created and redirected to new collection page
154 assert response.headers['Location'].include? '/collections/'
155 new_collection_uuid = response.headers['Location'].split('/')[-1]
158 collection = Collection.select([:uuid, :manifest_text]).where(uuid: new_collection_uuid).first
159 manifest_text = collection['manifest_text']
161 streams = manifest_text.split "\n"
162 assert_equal 1, streams.length, "Incorrect number of streams in #{manifest_text}"
163 assert manifest_text.include?('foo'), "Not found foo in new collection manifest text #{manifest_text}"
164 assert manifest_text.include?('foo(1)'), "Not found foo(1) in new collection manifest text #{manifest_text}"