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_includes(response.headers['Location'], '/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_includes(manifest_text, "foo")
37 assert_includes(manifest_text, "bar")
38 assert_includes(manifest_text, "baz")
39 assert_includes(manifest_text, "0:0:file1 0:0:file2 0:0:file3")
40 assert_includes(manifest_text, "dir1/subdir")
41 assert_includes(manifest_text, "dir2")
44 test "combine files with repeated names into new collection" do
45 post(:combine_selected_files_into_collection, {
46 selection: ['zzzzz-4zz18-znfnqtbbv4spc3w/foo',
47 'zzzzz-4zz18-00000nonamecoll/foo',
48 'zzzzz-4zz18-abcd6fx123409f7/foo',
49 'zzzzz-4zz18-ehbhgtheo8909or/bar',
50 'zzzzz-4zz18-y9vne9npefyxh8g/baz',
51 '7a6ef4c162a5c6413070a8bd0bffc818+150'],
55 assert_response 302 # collection created and redirected to new collection page
57 assert_includes(response.headers['Location'], '/collections/')
58 new_collection_uuid = response.headers['Location'].split('/')[-1]
61 collection = Collection.select([:uuid, :manifest_text]).where(uuid: new_collection_uuid).first
62 manifest_text = collection['manifest_text']
63 assert_includes(manifest_text, "foo(1)")
64 assert_includes(manifest_text, "foo(2)")
65 assert_includes(manifest_text, "bar")
66 assert_includes(manifest_text, "baz")
67 assert_includes(manifest_text, "0:0:file1 0:0:file2 0:0:file3")
68 assert_includes(manifest_text, "dir1/subdir")
69 assert_includes(manifest_text, "dir2")
72 test "combine collections with repeated filenames in almost similar directories and expect files with proper suffixes" do
73 post(:combine_selected_files_into_collection, {
74 selection: ['zzzzz-4zz18-duplicatenames1',
75 'zzzzz-4zz18-duplicatenames2',
76 'zzzzz-4zz18-znfnqtbbv4spc3w/foo',
77 'zzzzz-4zz18-00000nonamecoll/foo',],
81 assert_response 302 # collection created and redirected to new collection page
83 assert response.headers['Location'].include? '/collections/'
84 new_collection_uuid = response.headers['Location'].split('/')[-1]
87 collection = Collection.select([:uuid, :manifest_text]).where(uuid: new_collection_uuid).first
88 manifest_text = collection['manifest_text']
90 assert_includes(manifest_text, 'foo')
91 assert_includes(manifest_text, 'foo(1)')
93 streams = manifest_text.split "\n"
94 streams.each do |stream|
95 if stream.start_with? './dir1'
97 assert_includes(stream, ':alice(1)')
98 assert_includes(stream, ':alice.txt')
99 assert_includes(stream, ':alice(1).txt')
100 assert_includes(stream, ':bob.txt')
101 assert_includes(stream, ':carol.txt')
102 elsif stream.start_with? './dir2'
104 assert_includes(stream, ':alice.txt')
105 assert_includes(stream, ':alice(1).txt')
106 elsif stream.start_with? '. '
108 assert_includes(stream, ':foo')
109 assert_includes(stream, ':foo(1)')
114 test "combine collections with same filename in two different streams and expect no suffixes for filenames" do
115 post(:combine_selected_files_into_collection, {
116 selection: ['zzzzz-4zz18-znfnqtbbv4spc3w',
117 'zzzzz-4zz18-foonbarfilesdir'],
119 session_for(:active))
121 assert_response 302 # collection created and redirected to new collection page
123 assert_includes(response.headers['Location'], '/collections/')
124 new_collection_uuid = response.headers['Location'].split('/')[-1]
127 collection = Collection.select([:uuid, :manifest_text]).where(uuid: new_collection_uuid).first
128 manifest_text = collection['manifest_text']
130 streams = manifest_text.split "\n"
131 assert_equal 2, streams.length
132 streams.each do |stream|
133 if stream.start_with? './dir1'
134 assert_includes(stream, 'foo')
135 elsif stream.start_with? '. '
136 assert_includes(stream, 'foo')
139 refute_includes(manifest_text, 'foo(1)')
142 test "combine foo files from two different collection streams and expect proper filename suffixes" do
143 post(:combine_selected_files_into_collection, {
144 selection: ['zzzzz-4zz18-znfnqtbbv4spc3w/foo',
145 'zzzzz-4zz18-foonbarfilesdir/dir1/foo'],
147 session_for(:active))
149 assert_response 302 # collection created and redirected to new collection page
151 assert_includes(response.headers['Location'], '/collections/')
152 new_collection_uuid = response.headers['Location'].split('/')[-1]
155 collection = Collection.select([:uuid, :manifest_text]).where(uuid: new_collection_uuid).first
156 manifest_text = collection['manifest_text']
158 streams = manifest_text.split "\n"
159 assert_equal 1, streams.length, "Incorrect number of streams in #{manifest_text}"
160 assert_includes(manifest_text, 'foo')
161 assert_includes(manifest_text, 'foo(1)')