3 class CollectionTest < ActiveSupport::TestCase
4 def create_collection name, enc=nil
5 txt = ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:#{name}.txt\n"
6 txt.force_encoding(enc) if enc
7 return Collection.create(manifest_text: txt)
10 test 'accept ASCII manifest_text' do
12 c = create_collection 'foo', Encoding::US_ASCII
17 test 'accept UTF-8 manifest_text' do
19 c = create_collection "f\xc3\x98\xc3\x98", Encoding::UTF_8
24 test 'refuse manifest_text with invalid UTF-8 byte sequence' do
26 c = create_collection "f\xc8o", Encoding::UTF_8
28 assert_equal [:manifest_text], c.errors.messages.keys
29 assert_match /UTF-8/, c.errors.messages[:manifest_text].first
33 test 'refuse manifest_text with non-UTF-8 encoding' do
35 c = create_collection "f\xc8o", Encoding::ASCII_8BIT
37 assert_equal [:manifest_text], c.errors.messages.keys
38 assert_match /UTF-8/, c.errors.messages[:manifest_text].first
42 test 'create and update collection and verify file_names' do
44 c = create_collection 'foo', Encoding::US_ASCII
46 created_file_names = c.file_names
47 assert created_file_names
48 assert_match /foo.txt/, c.file_names
50 c.update_attribute 'manifest_text', ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo2.txt\n"
51 assert_not_equal created_file_names, c.file_names
52 assert_match /foo2.txt/, c.file_names
59 ].each do |manifest_size, gets_truncated|
60 test "create collection with manifest size #{manifest_size} which gets truncated #{gets_truncated},
61 and not expect exceptions even on very large manifest texts" do
62 # file_names has a max size, hence there will be no errors even on large manifests
64 manifest_text = './blurfl d41d8cd98f00b204e9800998ecf8427e+0'
66 while manifest_text.length < manifest_size
67 manifest_text += ' ' + "0:0:veryverylongfilename000000000000#{index}.txt\n./subdir1"
71 c = Collection.create(manifest_text: manifest_text)
75 assert_match /veryverylongfilename0000000000001.txt/, c.file_names
76 assert_match /veryverylongfilename0000000000002.txt/, c.file_names
78 assert_match /blurfl/, c.file_names
79 assert_match /subdir1/, c.file_names