-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload_test.rb
102 lines (64 loc) · 2.38 KB
/
upload_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
test 'Upload'
f = File.new('./test/fugroup_avatar.jpg')
is f.size, :gt => 0
is Pushfile.mode, 'development'
is Pushfile.provider, 'amazon'
base = File.basename(f.path)
tmp = "/tmp/upload-#{base}"
# Move test file into /tmp
`cp #{f.path} #{tmp}` unless File.file?(tmp)
test '* config'
options = {:filename => File.basename(f.path), :tempfile => tmp, :mimetype => 'image/jpeg'}
u = Pushfile::Upload.new(options.merge(:config => :campaign))
is u.width, 610
u = Pushfile::Upload.new(options.merge(:config => :asdf))
is u.width, nil
u = Pushfile::Upload.new(options.merge(:config => :default))
is u.width, 590
u = Pushfile::Upload.new(options)
is u.width, 590
u = Pushfile::Upload.new
is u.width, 590
test '* url upload, amazon'
options = {:url => 'http://fugroup.net/images/fugroup_logo1.png'}
u = Pushfile::Upload.new(options)
is u.provider, 'amazon'
is u.container, '7ino'
is u.width, 590
is u.status, nil
u.create
is u.status, :a? => Hash
is u.status[:mimetype], 'image/png'
test '* ajax upload, amazon'
options = {:filename => File.basename(f.path), :tempfile => tmp, :mimetype => 'image/jpeg'}
u = Pushfile::Upload.new(options)
is u.provider, 'amazon'
is u.container, '7ino'
is u.width, 590
is u.status, nil
u.create
is u.status, :a? => Hash
is u.status[:url], :a? => String
is u.status[:mimetype], 'image/jpeg'
test '* ajax upload, rackspace'
Pushfile.provider = 'rackspace'
u = Pushfile::Upload.new(options)
is u.provider, 'rackspace'
is u.container, 'crowdfundhq'
is u.status, nil
u.create
is u.status, :a? => Hash
is u.status[:url], :a? => String
is u.status[:mimetype], 'image/jpeg'
test '* max size'
Pushfile.provider = 'amazon'
options = {:max => 1, :filename => File.basename(f.path), :tempfile => tmp, :mimetype => 'image/jpeg'}
u = Pushfile::Upload.new(options)
is u.max, 1
u.create
is u.status, :a? => Hash
is u.status[:error], 'upload_file_size_is_too_big'
# Ajax upload
# {"filename"=>"morning-tur-nyttnorge.jpg", "mimetype"=>"image/jpeg", "size"=>"61606", "preventCache"=>"8P6qZe2G9ij6VmSzKsDR47ArMczrjZ", "config"=>"files"}
# Froala upload
# {"config"=>"campaign", "file"=>{:filename=>"fugroup_avatar.jpeg", :type=>"image/jpeg", :name=>"file", :tempfile=>#<Tempfile:/var/folders/t4/b0c2hjbx55z074nqmg74s_ch0000gn/T/RackMultipart20170110-87813-909yn0.jpeg>, :head=>"Content-Disposition: form-data; name=\"file\"; filename=\"fugroup_avatar.jpeg\"\r\nContent-Type: image/jpeg\r\n"}}