paperclip 3.5.4 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of paperclip might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/LICENSE +1 -3
- data/NEWS +25 -21
- data/README.md +35 -1
- data/features/step_definitions/attachment_steps.rb +2 -0
- data/features/step_definitions/rails_steps.rb +1 -0
- data/lib/paperclip.rb +1 -0
- data/lib/paperclip/attachment.rb +25 -1
- data/lib/paperclip/callbacks.rb +1 -1
- data/lib/paperclip/content_type_detector.rb +1 -13
- data/lib/paperclip/errors.rb +5 -0
- data/lib/paperclip/has_attached_file.rb +5 -0
- data/lib/paperclip/io_adapters/abstract_adapter.rb +1 -1
- data/lib/paperclip/io_adapters/attachment_adapter.rb +4 -4
- data/lib/paperclip/io_adapters/data_uri_adapter.rb +4 -9
- data/lib/paperclip/io_adapters/stringio_adapter.rb +10 -8
- data/lib/paperclip/media_type_spoof_detector.rb +36 -0
- data/lib/paperclip/tempfile_factory.rb +5 -1
- data/lib/paperclip/validators.rb +6 -1
- data/lib/paperclip/validators/attachment_content_type_validator.rb +4 -0
- data/lib/paperclip/validators/attachment_file_name_validator.rb +80 -0
- data/lib/paperclip/validators/attachment_file_type_ignorance_validator.rb +29 -0
- data/lib/paperclip/validators/attachment_presence_validator.rb +4 -0
- data/lib/paperclip/validators/attachment_size_validator.rb +4 -0
- data/lib/paperclip/validators/media_type_spoof_detection_validator.rb +27 -0
- data/lib/paperclip/version.rb +1 -1
- data/test/attachment_definitions_test.rb +1 -0
- data/test/attachment_test.rb +40 -43
- data/test/content_type_detector_test.rb +0 -10
- data/test/fixtures/empty.html +1 -0
- data/test/has_attached_file_test.rb +3 -1
- data/test/helper.rb +11 -4
- data/test/io_adapters/abstract_adapter_test.rb +1 -0
- data/test/io_adapters/attachment_adapter_test.rb +1 -1
- data/test/io_adapters/data_uri_adapter_test.rb +2 -2
- data/test/io_adapters/file_adapter_test.rb +0 -11
- data/test/io_adapters/http_url_proxy_adapter_test.rb +2 -3
- data/test/io_adapters/stringio_adapter_test.rb +1 -1
- data/test/matchers/have_attached_file_matcher_test.rb +3 -2
- data/test/matchers/validate_attachment_content_type_matcher_test.rb +13 -12
- data/test/matchers/validate_attachment_presence_matcher_test.rb +8 -7
- data/test/matchers/validate_attachment_size_matcher_test.rb +12 -11
- data/test/media_type_spoof_detector_test.rb +28 -0
- data/test/meta_class_test.rb +2 -2
- data/test/schema_test.rb +6 -0
- data/test/storage/fog_test.rb +4 -4
- data/test/storage/s3_test.rb +32 -31
- data/test/tempfile_factory_test.rb +13 -1
- data/test/validators/attachment_file_name_validator_test.rb +162 -0
- data/test/validators/attachment_presence_validator_test.rb +1 -1
- data/test/validators/media_type_spoof_detection_validator_test.rb +12 -0
- data/test/validators_test.rb +43 -3
- metadata +14 -2
@@ -75,7 +75,7 @@ class AttachmentAdapterTest < Test::Unit::TestCase
|
|
75
75
|
end
|
76
76
|
|
77
77
|
should "not generate paths that include restricted characters" do
|
78
|
-
assert_no_match
|
78
|
+
assert_no_match(/:/, @subject.path)
|
79
79
|
end
|
80
80
|
|
81
81
|
should "not generate filenames that include restricted characters" do
|
@@ -14,8 +14,8 @@ class DataUriAdapterTest < Test::Unit::TestCase
|
|
14
14
|
@subject = Paperclip.io_adapters.for(@contents)
|
15
15
|
end
|
16
16
|
|
17
|
-
should "
|
18
|
-
assert_equal "
|
17
|
+
should "returns a file name based on the content type" do
|
18
|
+
assert_equal "data.png", @subject.original_filename
|
19
19
|
end
|
20
20
|
|
21
21
|
should "return a content type" do
|
@@ -69,17 +69,6 @@ class FileAdapterTest < Test::Unit::TestCase
|
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
|
-
context "file with multiple possible x-types but no official type" do
|
73
|
-
setup do
|
74
|
-
MIME::Types.stubs(:type_for).returns([MIME::Type.new('image/x-mp4'), MIME::Type.new('image/x-video')])
|
75
|
-
@subject = Paperclip.io_adapters.for(@file)
|
76
|
-
end
|
77
|
-
|
78
|
-
should "return the first" do
|
79
|
-
assert_equal "image/x-mp4", @subject.content_type
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
72
|
context "file with content type derived from file command on *nix" do
|
84
73
|
setup do
|
85
74
|
MIME::Types.stubs(:type_for).returns([])
|
@@ -84,8 +84,7 @@ class HttpUrlProxyAdapterTest < Test::Unit::TestCase
|
|
84
84
|
teardown do
|
85
85
|
begin
|
86
86
|
@subject.close
|
87
|
-
rescue Exception
|
88
|
-
binding.pry
|
87
|
+
rescue Exception
|
89
88
|
true
|
90
89
|
end
|
91
90
|
end
|
@@ -95,7 +94,7 @@ class HttpUrlProxyAdapterTest < Test::Unit::TestCase
|
|
95
94
|
end
|
96
95
|
|
97
96
|
should "not generate paths that include restricted characters" do
|
98
|
-
assert_no_match
|
97
|
+
assert_no_match(/:/, @subject.path)
|
99
98
|
end
|
100
99
|
end
|
101
100
|
|
@@ -3,7 +3,7 @@ require './test/helper'
|
|
3
3
|
class HaveAttachedFileMatcherTest < Test::Unit::TestCase
|
4
4
|
context "have_attached_file" do
|
5
5
|
setup do
|
6
|
-
|
6
|
+
reset_class "Dummy"
|
7
7
|
reset_table "dummies"
|
8
8
|
@matcher = self.class.have_attached_file(:avatar)
|
9
9
|
end
|
@@ -15,7 +15,8 @@ class HaveAttachedFileMatcherTest < Test::Unit::TestCase
|
|
15
15
|
context "given a class with an attachment" do
|
16
16
|
setup do
|
17
17
|
modify_table("dummies"){|d| d.string :avatar_file_name }
|
18
|
-
|
18
|
+
Dummy.has_attached_file :avatar
|
19
|
+
Dummy.do_not_validate_attachment_file_type :avatar
|
19
20
|
end
|
20
21
|
|
21
22
|
should_accept_dummy_class
|
@@ -8,8 +8,9 @@ class ValidateAttachmentContentTypeMatcherTest < Test::Unit::TestCase
|
|
8
8
|
d.string :avatar_file_name
|
9
9
|
d.string :avatar_content_type
|
10
10
|
end
|
11
|
-
|
12
|
-
|
11
|
+
reset_class "Dummy"
|
12
|
+
Dummy.do_not_validate_attachment_file_type :avatar
|
13
|
+
Dummy.has_attached_file :avatar
|
13
14
|
@matcher = self.class.validate_attachment_content_type(:avatar).
|
14
15
|
allowing(%w(image/png image/jpeg)).
|
15
16
|
rejecting(%w(audio/mp3 application/octet-stream))
|
@@ -21,7 +22,7 @@ class ValidateAttachmentContentTypeMatcherTest < Test::Unit::TestCase
|
|
21
22
|
|
22
23
|
context "given a class with a validation that doesn't match" do
|
23
24
|
setup do
|
24
|
-
|
25
|
+
Dummy.validates_attachment_content_type :avatar, :content_type => %r{audio/.*}
|
25
26
|
end
|
26
27
|
|
27
28
|
should_reject_dummy_class
|
@@ -29,7 +30,7 @@ class ValidateAttachmentContentTypeMatcherTest < Test::Unit::TestCase
|
|
29
30
|
|
30
31
|
context "given a class with a matching validation" do
|
31
32
|
setup do
|
32
|
-
|
33
|
+
Dummy.validates_attachment_content_type :avatar, :content_type => %r{image/.*}
|
33
34
|
end
|
34
35
|
|
35
36
|
should_accept_dummy_class
|
@@ -37,8 +38,8 @@ class ValidateAttachmentContentTypeMatcherTest < Test::Unit::TestCase
|
|
37
38
|
|
38
39
|
context "given a class with other validations but matching types" do
|
39
40
|
setup do
|
40
|
-
|
41
|
-
|
41
|
+
Dummy.validates_presence_of :title
|
42
|
+
Dummy.validates_attachment_content_type :avatar, :content_type => %r{image/.*}
|
42
43
|
end
|
43
44
|
|
44
45
|
should_accept_dummy_class
|
@@ -46,7 +47,7 @@ class ValidateAttachmentContentTypeMatcherTest < Test::Unit::TestCase
|
|
46
47
|
|
47
48
|
context "given a class that matches and a matcher that only specifies 'allowing'" do
|
48
49
|
setup do
|
49
|
-
|
50
|
+
Dummy.validates_attachment_content_type :avatar, :content_type => %r{image/.*}
|
50
51
|
@matcher = self.class.validate_attachment_content_type(:avatar).
|
51
52
|
allowing(%w(image/png image/jpeg))
|
52
53
|
end
|
@@ -56,7 +57,7 @@ class ValidateAttachmentContentTypeMatcherTest < Test::Unit::TestCase
|
|
56
57
|
|
57
58
|
context "given a class that does not match and a matcher that only specifies 'allowing'" do
|
58
59
|
setup do
|
59
|
-
|
60
|
+
Dummy.validates_attachment_content_type :avatar, :content_type => %r{audio/.*}
|
60
61
|
@matcher = self.class.validate_attachment_content_type(:avatar).
|
61
62
|
allowing(%w(image/png image/jpeg))
|
62
63
|
end
|
@@ -66,7 +67,7 @@ class ValidateAttachmentContentTypeMatcherTest < Test::Unit::TestCase
|
|
66
67
|
|
67
68
|
context "given a class that matches and a matcher that only specifies 'rejecting'" do
|
68
69
|
setup do
|
69
|
-
|
70
|
+
Dummy.validates_attachment_content_type :avatar, :content_type => %r{image/.*}
|
70
71
|
@matcher = self.class.validate_attachment_content_type(:avatar).
|
71
72
|
rejecting(%w(audio/mp3 application/octet-stream))
|
72
73
|
end
|
@@ -76,7 +77,7 @@ class ValidateAttachmentContentTypeMatcherTest < Test::Unit::TestCase
|
|
76
77
|
|
77
78
|
context "given a class that does not match and a matcher that only specifies 'rejecting'" do
|
78
79
|
setup do
|
79
|
-
|
80
|
+
Dummy.validates_attachment_content_type :avatar, :content_type => %r{audio/.*}
|
80
81
|
@matcher = self.class.validate_attachment_content_type(:avatar).
|
81
82
|
rejecting(%w(audio/mp3 application/octet-stream))
|
82
83
|
end
|
@@ -86,14 +87,14 @@ class ValidateAttachmentContentTypeMatcherTest < Test::Unit::TestCase
|
|
86
87
|
|
87
88
|
context "using an :if to control the validation" do
|
88
89
|
setup do
|
89
|
-
|
90
|
+
Dummy.class_eval do
|
90
91
|
validates_attachment_content_type :avatar, :content_type => %r{image/*} , :if => :go
|
91
92
|
attr_accessor :go
|
92
93
|
end
|
93
94
|
@matcher = self.class.validate_attachment_content_type(:avatar).
|
94
95
|
allowing(%w(image/png image/jpeg)).
|
95
96
|
rejecting(%w(audio/mp3 application/octet-stream))
|
96
|
-
@dummy =
|
97
|
+
@dummy = Dummy.new
|
97
98
|
end
|
98
99
|
|
99
100
|
should "run the validation if the control is true" do
|
@@ -6,8 +6,9 @@ class ValidateAttachmentPresenceMatcherTest < Test::Unit::TestCase
|
|
6
6
|
reset_table("dummies") do |d|
|
7
7
|
d.string :avatar_file_name
|
8
8
|
end
|
9
|
-
|
10
|
-
|
9
|
+
reset_class "Dummy"
|
10
|
+
Dummy.has_attached_file :avatar
|
11
|
+
Dummy.do_not_validate_attachment_file_type :avatar
|
11
12
|
@matcher = self.class.validate_attachment_presence(:avatar)
|
12
13
|
end
|
13
14
|
|
@@ -17,7 +18,7 @@ class ValidateAttachmentPresenceMatcherTest < Test::Unit::TestCase
|
|
17
18
|
|
18
19
|
context "given a class with a matching validation" do
|
19
20
|
setup do
|
20
|
-
|
21
|
+
Dummy.validates_attachment_presence :avatar
|
21
22
|
end
|
22
23
|
|
23
24
|
should_accept_dummy_class
|
@@ -30,12 +31,12 @@ class ValidateAttachmentPresenceMatcherTest < Test::Unit::TestCase
|
|
30
31
|
d.string :avatar_content_type
|
31
32
|
end
|
32
33
|
|
33
|
-
|
34
|
+
Dummy.class_eval do
|
34
35
|
validates_attachment_presence :avatar
|
35
36
|
validates_attachment_content_type :avatar, :content_type => 'image/gif'
|
36
37
|
end
|
37
38
|
|
38
|
-
@dummy =
|
39
|
+
@dummy = Dummy.new
|
39
40
|
@matcher = self.class.validate_attachment_presence(:avatar)
|
40
41
|
end
|
41
42
|
|
@@ -47,11 +48,11 @@ class ValidateAttachmentPresenceMatcherTest < Test::Unit::TestCase
|
|
47
48
|
|
48
49
|
context "using an :if to control the validation" do
|
49
50
|
setup do
|
50
|
-
|
51
|
+
Dummy.class_eval do
|
51
52
|
validates_attachment_presence :avatar, :if => :go
|
52
53
|
attr_accessor :go
|
53
54
|
end
|
54
|
-
@dummy =
|
55
|
+
@dummy = Dummy.new
|
55
56
|
@dummy.avatar = nil
|
56
57
|
end
|
57
58
|
|
@@ -7,8 +7,9 @@ class ValidateAttachmentSizeMatcherTest < Test::Unit::TestCase
|
|
7
7
|
d.string :avatar_file_name
|
8
8
|
d.integer :avatar_file_size
|
9
9
|
end
|
10
|
-
|
11
|
-
|
10
|
+
reset_class "Dummy"
|
11
|
+
Dummy.do_not_validate_attachment_file_type :avatar
|
12
|
+
Dummy.has_attached_file :avatar
|
12
13
|
end
|
13
14
|
|
14
15
|
context "of limited size" do
|
@@ -19,17 +20,17 @@ class ValidateAttachmentSizeMatcherTest < Test::Unit::TestCase
|
|
19
20
|
end
|
20
21
|
|
21
22
|
context "given a class with a validation that's too high" do
|
22
|
-
setup {
|
23
|
+
setup { Dummy.validates_attachment_size :avatar, :in => 256..2048 }
|
23
24
|
should_reject_dummy_class
|
24
25
|
end
|
25
26
|
|
26
27
|
context "given a class with a validation that's too low" do
|
27
|
-
setup {
|
28
|
+
setup { Dummy.validates_attachment_size :avatar, :in => 0..1024 }
|
28
29
|
should_reject_dummy_class
|
29
30
|
end
|
30
31
|
|
31
32
|
context "given a class with a validation that matches" do
|
32
|
-
setup {
|
33
|
+
setup { Dummy.validates_attachment_size :avatar, :in => 256..1024 }
|
33
34
|
should_accept_dummy_class
|
34
35
|
end
|
35
36
|
end
|
@@ -38,23 +39,23 @@ class ValidateAttachmentSizeMatcherTest < Test::Unit::TestCase
|
|
38
39
|
setup{ @matcher = self.class.validate_attachment_size(:avatar) }
|
39
40
|
|
40
41
|
context "given a class with an upper limit" do
|
41
|
-
setup {
|
42
|
+
setup { Dummy.validates_attachment_size :avatar, :less_than => 1 }
|
42
43
|
should_accept_dummy_class
|
43
44
|
end
|
44
45
|
|
45
46
|
context "given a class with a lower limit" do
|
46
|
-
setup {
|
47
|
+
setup { Dummy.validates_attachment_size :avatar, :greater_than => 1 }
|
47
48
|
should_accept_dummy_class
|
48
49
|
end
|
49
50
|
end
|
50
51
|
|
51
52
|
context "using an :if to control the validation" do
|
52
53
|
setup do
|
53
|
-
|
54
|
+
Dummy.class_eval do
|
54
55
|
validates_attachment_size :avatar, :greater_than => 1024, :if => :go
|
55
56
|
attr_accessor :go
|
56
57
|
end
|
57
|
-
@dummy =
|
58
|
+
@dummy = Dummy.new
|
58
59
|
@matcher = self.class.validate_attachment_size(:avatar).greater_than(1024)
|
59
60
|
end
|
60
61
|
|
@@ -71,9 +72,9 @@ class ValidateAttachmentSizeMatcherTest < Test::Unit::TestCase
|
|
71
72
|
|
72
73
|
context "post processing" do
|
73
74
|
setup do
|
74
|
-
|
75
|
+
Dummy.validates_attachment_size :avatar, :greater_than => 1024
|
75
76
|
|
76
|
-
@dummy =
|
77
|
+
@dummy = Dummy.new
|
77
78
|
@matcher = self.class.validate_attachment_size(:avatar).greater_than(1024)
|
78
79
|
end
|
79
80
|
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require './test/helper'
|
2
|
+
|
3
|
+
class MediaTypeSpoofDetectorTest < Test::Unit::TestCase
|
4
|
+
should 'reject a file that is named .html and identifies as PNG' do
|
5
|
+
file = File.open(fixture_file("5k.png"))
|
6
|
+
assert Paperclip::MediaTypeSpoofDetector.using(file, "5k.html").spoofed?
|
7
|
+
end
|
8
|
+
|
9
|
+
should 'not reject a file that is named .jpg and identifies as PNG' do
|
10
|
+
file = File.open(fixture_file("5k.png"))
|
11
|
+
assert ! Paperclip::MediaTypeSpoofDetector.using(file, "5k.jpg").spoofed?
|
12
|
+
end
|
13
|
+
|
14
|
+
should 'not reject a file that is named .html and identifies as HTML' do
|
15
|
+
file = File.open(fixture_file("empty.html"))
|
16
|
+
assert ! Paperclip::MediaTypeSpoofDetector.using(file, "empty.html").spoofed?
|
17
|
+
end
|
18
|
+
|
19
|
+
should 'not reject a file that does not have a name' do
|
20
|
+
file = File.open(fixture_file("empty.html"))
|
21
|
+
assert ! Paperclip::MediaTypeSpoofDetector.using(file, "").spoofed?
|
22
|
+
end
|
23
|
+
|
24
|
+
should 'not reject when the supplied file is an IOAdapter' do
|
25
|
+
adapter = Paperclip.io_adapters.for(File.new(fixture_file("5k.png")))
|
26
|
+
assert ! Paperclip::MediaTypeSpoofDetector.using(adapter, adapter.original_filename).spoofed?
|
27
|
+
end
|
28
|
+
end
|
data/test/meta_class_test.rb
CHANGED
@@ -16,7 +16,7 @@ class MetaClassTest < Test::Unit::TestCase
|
|
16
16
|
assert_nothing_raised do
|
17
17
|
rebuild_meta_class_of(@dummy)
|
18
18
|
end
|
19
|
-
end
|
19
|
+
end
|
20
20
|
|
21
21
|
should "work like any other instance" do
|
22
22
|
reset_class("Dummy")
|
@@ -29,4 +29,4 @@ class MetaClassTest < Test::Unit::TestCase
|
|
29
29
|
assert @dummy.save
|
30
30
|
end
|
31
31
|
end
|
32
|
-
end
|
32
|
+
end
|
data/test/schema_test.rb
CHANGED
@@ -15,6 +15,9 @@ class SchemaTest < Test::Unit::TestCase
|
|
15
15
|
|
16
16
|
context "within table definition" do
|
17
17
|
context "using #has_attached_file" do
|
18
|
+
setup do
|
19
|
+
ActiveSupport::Deprecation.silenced = false
|
20
|
+
end
|
18
21
|
should "create attachment columns" do
|
19
22
|
Dummy.connection.create_table :dummies, :force => true do |t|
|
20
23
|
ActiveSupport::Deprecation.silence do
|
@@ -122,6 +125,9 @@ class SchemaTest < Test::Unit::TestCase
|
|
122
125
|
end
|
123
126
|
|
124
127
|
context "using #drop_attached_file" do
|
128
|
+
setup do
|
129
|
+
ActiveSupport::Deprecation.silenced = false
|
130
|
+
end
|
125
131
|
should "remove the attachment columns" do
|
126
132
|
ActiveSupport::Deprecation.silence do
|
127
133
|
Dummy.connection.drop_attached_file :dummies, :avatar
|
data/test/storage/fog_test.rb
CHANGED
@@ -222,12 +222,12 @@ class FogTest < Test::Unit::TestCase
|
|
222
222
|
setup do
|
223
223
|
rebuild_model(@options.merge(:fog_host => 'http://example.com'))
|
224
224
|
@dummy = Dummy.new
|
225
|
-
@dummy.avatar = StringIO.new(
|
225
|
+
@dummy.avatar = StringIO.new(".\n")
|
226
226
|
@dummy.save
|
227
227
|
end
|
228
228
|
|
229
229
|
should "provide a public url" do
|
230
|
-
assert @dummy.avatar.url =~ /^http:\/\/example\.com\/avatars\/
|
230
|
+
assert @dummy.avatar.url =~ /^http:\/\/example\.com\/avatars\/data\.txt\?\d*$/
|
231
231
|
end
|
232
232
|
end
|
233
233
|
|
@@ -241,12 +241,12 @@ class FogTest < Test::Unit::TestCase
|
|
241
241
|
:storage => :fog
|
242
242
|
)
|
243
243
|
@dummy = Dummy.new
|
244
|
-
@dummy.avatar = StringIO.new(
|
244
|
+
@dummy.avatar = StringIO.new(".\n")
|
245
245
|
@dummy.save
|
246
246
|
end
|
247
247
|
|
248
248
|
should "provide a public url" do
|
249
|
-
assert @dummy.avatar.url =~ /^http:\/\/img[0123]\.example\.com\/avatars\/
|
249
|
+
assert @dummy.avatar.url =~ /^http:\/\/img[0123]\.example\.com\/avatars\/data\.txt\?\d*$/
|
250
250
|
end
|
251
251
|
end
|
252
252
|
|
data/test/storage/s3_test.rb
CHANGED
@@ -92,7 +92,7 @@ class S3Test < Test::Unit::TestCase
|
|
92
92
|
:s3_credentials => {:not => :important}
|
93
93
|
|
94
94
|
@dummy = Dummy.new
|
95
|
-
@dummy.avatar =
|
95
|
+
@dummy.avatar = stringy_file
|
96
96
|
|
97
97
|
end
|
98
98
|
|
@@ -111,11 +111,11 @@ class S3Test < Test::Unit::TestCase
|
|
111
111
|
:path => ":attachment/:basename.:extension",
|
112
112
|
:url => ":s3_path_url"
|
113
113
|
@dummy = Dummy.new
|
114
|
-
@dummy.avatar =
|
114
|
+
@dummy.avatar = stringy_file
|
115
115
|
end
|
116
116
|
|
117
117
|
should "return a url based on an S3 path" do
|
118
|
-
assert_match %r{^http://s3.amazonaws.com/bucket/avatars/
|
118
|
+
assert_match %r{^http://s3.amazonaws.com/bucket/avatars/data.txt}, @dummy.avatar.url
|
119
119
|
end
|
120
120
|
|
121
121
|
should "use the correct bucket" do
|
@@ -123,7 +123,7 @@ class S3Test < Test::Unit::TestCase
|
|
123
123
|
end
|
124
124
|
|
125
125
|
should "use the correct key" do
|
126
|
-
assert_equal "avatars/
|
126
|
+
assert_equal "avatars/data.txt", @dummy.avatar.s3_object.key
|
127
127
|
end
|
128
128
|
end
|
129
129
|
|
@@ -151,11 +151,11 @@ class S3Test < Test::Unit::TestCase
|
|
151
151
|
:bucket => "bucket",
|
152
152
|
:path => ":attachment/:basename.:extension"
|
153
153
|
@dummy = Dummy.new
|
154
|
-
@dummy.avatar =
|
154
|
+
@dummy.avatar = stringy_file
|
155
155
|
end
|
156
156
|
|
157
157
|
should "return a url based on an S3 path" do
|
158
|
-
assert_match %r{^https://s3.amazonaws.com/bucket/avatars/
|
158
|
+
assert_match %r{^https://s3.amazonaws.com/bucket/avatars/data.txt}, @dummy.avatar.url
|
159
159
|
end
|
160
160
|
end
|
161
161
|
|
@@ -167,11 +167,11 @@ class S3Test < Test::Unit::TestCase
|
|
167
167
|
:bucket => "bucket",
|
168
168
|
:path => ":attachment/:basename.:extension"
|
169
169
|
@dummy = Dummy.new
|
170
|
-
@dummy.avatar =
|
170
|
+
@dummy.avatar = stringy_file
|
171
171
|
end
|
172
172
|
|
173
173
|
should "return a url based on an S3 path" do
|
174
|
-
assert_match %r{^https://s3.amazonaws.com/bucket/avatars/
|
174
|
+
assert_match %r{^https://s3.amazonaws.com/bucket/avatars/data.txt}, @dummy.avatar.url
|
175
175
|
end
|
176
176
|
end
|
177
177
|
|
@@ -183,11 +183,11 @@ class S3Test < Test::Unit::TestCase
|
|
183
183
|
:bucket => "bucket",
|
184
184
|
:path => ":attachment/:basename.:extension"
|
185
185
|
@dummy = Dummy.new
|
186
|
-
@dummy.avatar =
|
186
|
+
@dummy.avatar = stringy_file
|
187
187
|
end
|
188
188
|
|
189
189
|
should "return a url based on an S3 path" do
|
190
|
-
assert_match %r{^//s3.amazonaws.com/bucket/avatars/
|
190
|
+
assert_match %r{^//s3.amazonaws.com/bucket/avatars/data.txt}, @dummy.avatar.url
|
191
191
|
end
|
192
192
|
end
|
193
193
|
|
@@ -205,16 +205,16 @@ class S3Test < Test::Unit::TestCase
|
|
205
205
|
}
|
206
206
|
|
207
207
|
@dummy = Dummy.new
|
208
|
-
@dummy.avatar =
|
208
|
+
@dummy.avatar = stringy_file
|
209
209
|
@avatar = @dummy.avatar
|
210
210
|
end
|
211
211
|
|
212
212
|
should "use an S3 object based on the correct path for the default style" do
|
213
|
-
assert_equal("avatars/original/
|
213
|
+
assert_equal("avatars/original/data.txt", @dummy.avatar.s3_object.key)
|
214
214
|
end
|
215
215
|
|
216
216
|
should "use an S3 object based on the correct path for the custom style" do
|
217
|
-
assert_equal("avatars/thumb/
|
217
|
+
assert_equal("avatars/thumb/data.txt", @dummy.avatar.s3_object(:thumb).key)
|
218
218
|
end
|
219
219
|
end
|
220
220
|
|
@@ -226,11 +226,11 @@ class S3Test < Test::Unit::TestCase
|
|
226
226
|
:path => ":attachment/:basename.:extension",
|
227
227
|
:s3_host_name => "s3-ap-northeast-1.amazonaws.com"
|
228
228
|
@dummy = Dummy.new
|
229
|
-
@dummy.avatar =
|
229
|
+
@dummy.avatar = stringy_file
|
230
230
|
end
|
231
231
|
|
232
232
|
should "return a url based on an :s3_host_name path" do
|
233
|
-
assert_match %r{^http://s3-ap-northeast-1.amazonaws.com/bucket/avatars/
|
233
|
+
assert_match %r{^http://s3-ap-northeast-1.amazonaws.com/bucket/avatars/data.txt}, @dummy.avatar.url
|
234
234
|
end
|
235
235
|
|
236
236
|
should "use the S3 bucket with the correct host name" do
|
@@ -249,12 +249,12 @@ class S3Test < Test::Unit::TestCase
|
|
249
249
|
class << @dummy
|
250
250
|
attr_accessor :value
|
251
251
|
end
|
252
|
-
@dummy.avatar =
|
252
|
+
@dummy.avatar = stringy_file
|
253
253
|
end
|
254
254
|
|
255
255
|
should "use s3_host_name as a proc if available" do
|
256
256
|
@dummy.value = "s3.something.com"
|
257
|
-
assert_equal "http://s3.something.com/bucket/avatars/
|
257
|
+
assert_equal "http://s3.something.com/bucket/avatars/data.txt", @dummy.avatar.url(:original, :timestamp => false)
|
258
258
|
end
|
259
259
|
end
|
260
260
|
|
@@ -366,7 +366,7 @@ class S3Test < Test::Unit::TestCase
|
|
366
366
|
'secret_access_key' => "54321"
|
367
367
|
}
|
368
368
|
|
369
|
-
stringio =
|
369
|
+
stringio = stringy_file
|
370
370
|
class << stringio
|
371
371
|
def original_filename
|
372
372
|
"question?mark.png"
|
@@ -395,11 +395,11 @@ class S3Test < Test::Unit::TestCase
|
|
395
395
|
:path => ":attachment/:basename.:extension",
|
396
396
|
:url => ":s3_domain_url"
|
397
397
|
@dummy = Dummy.new
|
398
|
-
@dummy.avatar =
|
398
|
+
@dummy.avatar = stringy_file
|
399
399
|
end
|
400
400
|
|
401
401
|
should "return a url based on an S3 subdomain" do
|
402
|
-
assert_match %r{^http://bucket.s3.amazonaws.com/avatars/
|
402
|
+
assert_match %r{^http://bucket.s3.amazonaws.com/avatars/data.txt}, @dummy.avatar.url
|
403
403
|
end
|
404
404
|
end
|
405
405
|
|
@@ -414,11 +414,11 @@ class S3Test < Test::Unit::TestCase
|
|
414
414
|
:path => ":attachment/:basename.:extension",
|
415
415
|
:url => ":s3_alias_url"
|
416
416
|
@dummy = Dummy.new
|
417
|
-
@dummy.avatar =
|
417
|
+
@dummy.avatar = stringy_file
|
418
418
|
end
|
419
419
|
|
420
420
|
should "return a url based on the host_alias" do
|
421
|
-
assert_match %r{^http://something.something.com/avatars/
|
421
|
+
assert_match %r{^http://something.something.com/avatars/data.txt}, @dummy.avatar.url
|
422
422
|
end
|
423
423
|
end
|
424
424
|
|
@@ -437,12 +437,12 @@ class S3Test < Test::Unit::TestCase
|
|
437
437
|
end
|
438
438
|
end
|
439
439
|
@dummy = Dummy.new
|
440
|
-
@dummy.avatar =
|
440
|
+
@dummy.avatar = stringy_file
|
441
441
|
end
|
442
442
|
|
443
443
|
should "return a url based on the host_alias" do
|
444
|
-
assert_match %r{^http://cdn1.example.com/avatars/
|
445
|
-
assert_match %r{^http://cdn2.example.com/avatars/
|
444
|
+
assert_match %r{^http://cdn1.example.com/avatars/data.txt}, @dummy.avatar.url
|
445
|
+
assert_match %r{^http://cdn2.example.com/avatars/data.txt}, @dummy.avatar.url
|
446
446
|
end
|
447
447
|
|
448
448
|
should "still return the bucket name" do
|
@@ -459,11 +459,11 @@ class S3Test < Test::Unit::TestCase
|
|
459
459
|
:path => ":attachment/:basename.:extension",
|
460
460
|
:url => ":asset_host"
|
461
461
|
@dummy = Dummy.new
|
462
|
-
@dummy.avatar =
|
462
|
+
@dummy.avatar = stringy_file
|
463
463
|
end
|
464
464
|
|
465
465
|
should "return a relative URL for Rails to calculate assets host" do
|
466
|
-
assert_match %r{^avatars/
|
466
|
+
assert_match %r{^avatars/data\.txt}, @dummy.avatar.url
|
467
467
|
end
|
468
468
|
|
469
469
|
end
|
@@ -493,7 +493,7 @@ class S3Test < Test::Unit::TestCase
|
|
493
493
|
rails_env("production")
|
494
494
|
|
495
495
|
@dummy = Dummy.new
|
496
|
-
@dummy.avatar =
|
496
|
+
@dummy.avatar = stringy_file
|
497
497
|
|
498
498
|
object = stub
|
499
499
|
@dummy.avatar.stubs(:s3_object).returns(object)
|
@@ -508,7 +508,7 @@ class S3Test < Test::Unit::TestCase
|
|
508
508
|
rails_env("production")
|
509
509
|
|
510
510
|
@dummy = Dummy.new
|
511
|
-
@dummy.avatar =
|
511
|
+
@dummy.avatar = stringy_file
|
512
512
|
|
513
513
|
object = stub
|
514
514
|
@dummy.avatar.stubs(:s3_object).returns(object)
|
@@ -524,8 +524,9 @@ class S3Test < Test::Unit::TestCase
|
|
524
524
|
|
525
525
|
@dummy = Dummy.new
|
526
526
|
|
527
|
-
@file =
|
527
|
+
@file = stringy_file
|
528
528
|
@file.stubs(:original_filename).returns("5k.png\n\n")
|
529
|
+
Paperclip.stubs(:run).returns('image/png')
|
529
530
|
@file.stubs(:content_type).returns("image/png\n\n")
|
530
531
|
@file.stubs(:to_tempfile).returns(@file)
|
531
532
|
|
@@ -574,7 +575,7 @@ class S3Test < Test::Unit::TestCase
|
|
574
575
|
rails_env("production")
|
575
576
|
|
576
577
|
@dummy = Dummy.new
|
577
|
-
@dummy.avatar =
|
578
|
+
@dummy.avatar = stringy_file
|
578
579
|
end
|
579
580
|
|
580
581
|
should "should generate a url for the thumb" do
|