paperclip 4.3.7 → 5.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +17 -0
- data/.hound.yml +5 -16
- data/.travis.yml +15 -12
- data/Appraisals +4 -8
- data/CONTRIBUTING.md +16 -5
- data/Gemfile +3 -8
- data/LICENSE +1 -1
- data/NEWS +105 -31
- data/README.md +239 -153
- data/Rakefile +1 -1
- data/UPGRADING +12 -9
- data/features/basic_integration.feature +3 -2
- data/features/migration.feature +0 -24
- data/features/step_definitions/attachment_steps.rb +6 -6
- data/features/step_definitions/rails_steps.rb +29 -28
- data/features/step_definitions/s3_steps.rb +2 -2
- data/features/support/env.rb +1 -0
- data/features/support/paths.rb +1 -1
- data/features/support/rails.rb +0 -24
- data/gemfiles/4.2.gemfile +3 -5
- data/gemfiles/{3.2.gemfile → 5.0.gemfile} +4 -6
- data/lib/generators/paperclip/paperclip_generator.rb +9 -1
- data/lib/generators/paperclip/templates/paperclip_migration.rb.erb +1 -1
- data/lib/paperclip.rb +13 -12
- data/lib/paperclip/attachment.rb +25 -14
- data/lib/paperclip/attachment_registry.rb +2 -1
- data/lib/paperclip/callbacks.rb +8 -6
- data/lib/paperclip/content_type_detector.rb +3 -2
- data/lib/paperclip/errors.rb +3 -1
- data/lib/paperclip/file_command_content_type_detector.rb +1 -1
- data/lib/paperclip/geometry_detector_factory.rb +2 -2
- data/lib/paperclip/glue.rb +1 -1
- data/lib/paperclip/has_attached_file.rb +7 -1
- data/lib/paperclip/helpers.rb +15 -11
- data/lib/paperclip/interpolations.rb +1 -1
- data/lib/paperclip/io_adapters/abstract_adapter.rb +29 -3
- data/lib/paperclip/io_adapters/attachment_adapter.rb +10 -5
- data/lib/paperclip/io_adapters/data_uri_adapter.rb +8 -8
- data/lib/paperclip/io_adapters/empty_string_adapter.rb +5 -4
- data/lib/paperclip/io_adapters/file_adapter.rb +12 -6
- data/lib/paperclip/io_adapters/http_url_proxy_adapter.rb +7 -7
- data/lib/paperclip/io_adapters/identity_adapter.rb +12 -6
- data/lib/paperclip/io_adapters/nil_adapter.rb +8 -5
- data/lib/paperclip/io_adapters/registry.rb +6 -2
- data/lib/paperclip/io_adapters/stringio_adapter.rb +9 -6
- data/lib/paperclip/io_adapters/uploaded_file_adapter.rb +10 -6
- data/lib/paperclip/io_adapters/uri_adapter.rb +17 -14
- data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +4 -4
- data/lib/paperclip/media_type_spoof_detector.rb +3 -2
- data/lib/paperclip/processor.rb +5 -4
- data/lib/paperclip/schema.rb +2 -8
- data/lib/paperclip/storage/filesystem.rb +13 -2
- data/lib/paperclip/storage/fog.rb +20 -13
- data/lib/paperclip/storage/s3.rb +87 -58
- data/lib/paperclip/thumbnail.rb +18 -8
- data/lib/paperclip/url_generator.rb +17 -13
- data/lib/paperclip/validators.rb +1 -1
- data/lib/paperclip/validators/attachment_size_validator.rb +1 -7
- data/lib/paperclip/version.rb +3 -1
- data/lib/tasks/paperclip.rake +18 -4
- data/paperclip.gemspec +13 -10
- data/spec/paperclip/attachment_processing_spec.rb +2 -4
- data/spec/paperclip/attachment_registry_spec.rb +28 -0
- data/spec/paperclip/attachment_spec.rb +72 -18
- data/spec/paperclip/content_type_detector_spec.rb +1 -1
- data/spec/paperclip/file_command_content_type_detector_spec.rb +15 -1
- data/spec/paperclip/has_attached_file_spec.rb +24 -8
- data/spec/paperclip/integration_spec.rb +4 -3
- data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +76 -22
- data/spec/paperclip/io_adapters/attachment_adapter_spec.rb +6 -3
- data/spec/paperclip/io_adapters/data_uri_adapter_spec.rb +7 -1
- data/spec/paperclip/io_adapters/file_adapter_spec.rb +2 -2
- data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +18 -1
- data/spec/paperclip/io_adapters/identity_adapter_spec.rb +1 -1
- data/spec/paperclip/io_adapters/registry_spec.rb +2 -2
- data/spec/paperclip/io_adapters/stringio_adapter_spec.rb +1 -1
- data/spec/paperclip/io_adapters/uploaded_file_adapter_spec.rb +5 -5
- data/spec/paperclip/io_adapters/uri_adapter_spec.rb +48 -3
- data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +10 -0
- data/spec/paperclip/media_type_spoof_detector_spec.rb +15 -0
- data/spec/paperclip/paperclip_spec.rb +15 -45
- data/spec/paperclip/processor_spec.rb +4 -4
- data/spec/paperclip/storage/fog_spec.rb +31 -0
- data/spec/paperclip/storage/s3_live_spec.rb +20 -14
- data/spec/paperclip/storage/s3_spec.rb +357 -190
- data/spec/paperclip/tempfile_spec.rb +35 -0
- data/spec/paperclip/thumbnail_spec.rb +38 -35
- data/spec/paperclip/url_generator_spec.rb +54 -43
- data/spec/paperclip/validators/attachment_size_validator_spec.rb +26 -20
- data/spec/paperclip/validators_spec.rb +5 -5
- data/spec/spec_helper.rb +6 -2
- data/spec/support/assertions.rb +12 -1
- data/spec/support/conditional_filter_helper.rb +5 -0
- data/spec/support/mock_attachment.rb +2 -0
- data/spec/support/mock_url_generator_builder.rb +2 -2
- data/spec/support/model_reconstruction.rb +9 -1
- data/spec/support/reporting.rb +11 -0
- metadata +66 -58
- data/cucumber/paperclip_steps.rb +0 -6
- data/gemfiles/4.1.gemfile +0 -19
- data/lib/paperclip/deprecations.rb +0 -42
- data/lib/paperclip/locales/de.yml +0 -18
- data/lib/paperclip/locales/es.yml +0 -18
- data/lib/paperclip/locales/ja.yml +0 -18
- data/lib/paperclip/locales/pt-BR.yml +0 -18
- data/lib/paperclip/locales/zh-CN.yml +0 -18
- data/lib/paperclip/locales/zh-HK.yml +0 -18
- data/lib/paperclip/locales/zh-TW.yml +0 -18
- data/spec/paperclip/deprecations_spec.rb +0 -65
- data/spec/support/deprecations.rb +0 -9
- data/spec/support/rails_helpers.rb +0 -7
@@ -7,9 +7,10 @@ describe 'Paperclip' do
|
|
7
7
|
before do
|
8
8
|
rebuild_model
|
9
9
|
@file = File.new(fixture_file("5k.png"), 'rb')
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
# Deals with `Too many open files` error
|
11
|
+
Dummy.import 100.times.map { Dummy.new avatar: @file }
|
12
|
+
Dummy.import 100.times.map { Dummy.new avatar: @file }
|
13
|
+
Dummy.import 100.times.map { Dummy.new avatar: @file }
|
13
14
|
end
|
14
15
|
|
15
16
|
after { @file.close }
|
@@ -9,70 +9,124 @@ describe Paperclip::AbstractAdapter do
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
+
subject { TestAdapter.new(nil) }
|
13
|
+
|
12
14
|
context "content type from file contents" do
|
13
15
|
before do
|
14
|
-
|
15
|
-
@adapter.stubs(:path).returns("image.png")
|
16
|
+
subject.stubs(:path).returns("image.png")
|
16
17
|
Paperclip.stubs(:run).returns("image/png\n")
|
17
18
|
Paperclip::ContentTypeDetector.any_instance.stubs(:type_from_mime_magic).returns("image/png")
|
18
19
|
end
|
19
20
|
|
20
21
|
it "returns the content type without newline" do
|
21
|
-
assert_equal "image/png",
|
22
|
+
assert_equal "image/png", subject.content_type
|
22
23
|
end
|
23
24
|
end
|
24
25
|
|
25
26
|
context "nil?" do
|
26
27
|
it "returns false" do
|
27
|
-
assert !
|
28
|
+
assert !subject.nil?
|
28
29
|
end
|
29
30
|
end
|
30
31
|
|
31
32
|
context "delegation" do
|
32
33
|
before do
|
33
|
-
|
34
|
-
@adapter.tempfile = stub("Tempfile")
|
34
|
+
subject.tempfile = stub("Tempfile")
|
35
35
|
end
|
36
36
|
|
37
|
-
[:binmode, :binmode?, :close, :close!, :closed?, :eof?, :path, :rewind, :unlink].each do |method|
|
37
|
+
[:binmode, :binmode?, :close, :close!, :closed?, :eof?, :path, :readbyte, :rewind, :unlink].each do |method|
|
38
38
|
it "delegates #{method} to @tempfile" do
|
39
|
-
|
40
|
-
|
41
|
-
assert_received
|
39
|
+
subject.tempfile.stubs(method)
|
40
|
+
subject.public_send(method)
|
41
|
+
assert_received subject.tempfile, method
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'gets rid of slashes and colons in filenames' do
|
47
|
-
|
48
|
-
@adapter.original_filename = "awesome/file:name.png"
|
47
|
+
subject.original_filename = "awesome/file:name.png"
|
49
48
|
|
50
|
-
assert_equal "awesome_file_name.png",
|
49
|
+
assert_equal "awesome_file_name.png", subject.original_filename
|
51
50
|
end
|
52
51
|
|
53
52
|
it 'is an assignment' do
|
54
|
-
assert
|
53
|
+
assert subject.assignment?
|
55
54
|
end
|
56
55
|
|
57
56
|
it 'is not nil' do
|
58
|
-
assert !
|
57
|
+
assert !subject.nil?
|
59
58
|
end
|
60
59
|
|
61
60
|
it "generates a destination filename with no original filename" do
|
62
|
-
|
63
|
-
expect(@adapter.send(:destination).path).to_not be_nil
|
61
|
+
expect(subject.send(:destination).path).to_not be_nil
|
64
62
|
end
|
65
63
|
|
66
64
|
it 'uses the original filename to generate the tempfile' do
|
67
|
-
|
68
|
-
|
69
|
-
|
65
|
+
subject.original_filename = "file.png"
|
66
|
+
expect(subject.send(:destination).path).to end_with(".png")
|
67
|
+
end
|
68
|
+
|
69
|
+
context "generates a fingerprint" do
|
70
|
+
subject { TestAdapter.new(nil, options) }
|
71
|
+
|
72
|
+
before do
|
73
|
+
subject.stubs(:path).returns(fixture_file("50x50.png"))
|
74
|
+
end
|
75
|
+
|
76
|
+
context "MD5" do
|
77
|
+
let(:options) { { hash_digest: Digest::MD5 } }
|
78
|
+
|
79
|
+
it "returns a fingerprint" do
|
80
|
+
expect(subject.fingerprint).to be_a String
|
81
|
+
expect(subject.fingerprint).to eq "a790b00c9b5d58a8fd17a1ec5a187129"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context "SHA256" do
|
86
|
+
let(:options) { { hash_digest: Digest::SHA256 } }
|
87
|
+
|
88
|
+
it "returns a fingerprint" do
|
89
|
+
expect(subject.fingerprint).to be_a String
|
90
|
+
expect(subject.fingerprint).
|
91
|
+
to eq "243d7ce1099719df25f600f1c369c629fb979f88d5a01dbe7d0d48c8e6715bb1"
|
92
|
+
end
|
93
|
+
end
|
70
94
|
end
|
71
95
|
|
72
96
|
context "#original_filename=" do
|
73
97
|
it "should not fail with a nil original filename" do
|
74
|
-
|
75
|
-
|
98
|
+
expect { subject.original_filename = nil }.not_to raise_error
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context "#link_or_copy_file" do
|
103
|
+
class TestLinkOrCopyAdapter < Paperclip::AbstractAdapter
|
104
|
+
public :copy_to_tempfile, :destination
|
105
|
+
end
|
106
|
+
|
107
|
+
subject { TestLinkOrCopyAdapter.new(nil) }
|
108
|
+
let(:body) { "body" }
|
109
|
+
|
110
|
+
let(:file) do
|
111
|
+
t = Tempfile.new("destination")
|
112
|
+
t.print(body)
|
113
|
+
t.rewind
|
114
|
+
t
|
115
|
+
end
|
116
|
+
|
117
|
+
after do
|
118
|
+
file.close
|
119
|
+
file.unlink
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should be able to read the file" do
|
123
|
+
expect(subject.copy_to_tempfile(file).read).to eq(body)
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should be able to reopen the file after symlink has failed" do
|
127
|
+
FileUtils.expects(:ln).raises(Errno::EXDEV)
|
128
|
+
|
129
|
+
expect(subject.copy_to_tempfile(file).read).to eq(body)
|
76
130
|
end
|
77
131
|
end
|
78
132
|
end
|
@@ -13,7 +13,8 @@ describe Paperclip::AttachmentAdapter do
|
|
13
13
|
|
14
14
|
@attachment.assign(@file)
|
15
15
|
@attachment.save
|
16
|
-
@subject = Paperclip.io_adapters.for(@attachment
|
16
|
+
@subject = Paperclip.io_adapters.for(@attachment,
|
17
|
+
hash_digest: Digest::MD5)
|
17
18
|
end
|
18
19
|
|
19
20
|
after do
|
@@ -65,7 +66,8 @@ describe Paperclip::AttachmentAdapter do
|
|
65
66
|
|
66
67
|
@attachment.assign(@file)
|
67
68
|
@attachment.save
|
68
|
-
@subject = Paperclip.io_adapters.for(@attachment
|
69
|
+
@subject = Paperclip.io_adapters.for(@attachment,
|
70
|
+
hash_digest: Digest::MD5)
|
69
71
|
end
|
70
72
|
|
71
73
|
after do
|
@@ -92,7 +94,8 @@ describe Paperclip::AttachmentAdapter do
|
|
92
94
|
FileUtils.cp @attachment.queued_for_write[:thumb].path, @thumb.path
|
93
95
|
|
94
96
|
@attachment.save
|
95
|
-
@subject = Paperclip.io_adapters.for(@attachment.styles[:thumb]
|
97
|
+
@subject = Paperclip.io_adapters.for(@attachment.styles[:thumb],
|
98
|
+
hash_digest: Digest::MD5)
|
96
99
|
end
|
97
100
|
|
98
101
|
after do
|
@@ -1,7 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Paperclip::DataUriAdapter do
|
4
|
+
before do
|
5
|
+
Paperclip::DataUriAdapter.register
|
6
|
+
end
|
7
|
+
|
4
8
|
after do
|
9
|
+
Paperclip.io_adapters.unregister(described_class)
|
10
|
+
|
5
11
|
if @subject
|
6
12
|
@subject.close
|
7
13
|
end
|
@@ -20,7 +26,7 @@ describe Paperclip::DataUriAdapter do
|
|
20
26
|
context "a new instance" do
|
21
27
|
before do
|
22
28
|
@contents = "data:image/png;base64,#{original_base64_content}"
|
23
|
-
@subject = Paperclip.io_adapters.for(@contents)
|
29
|
+
@subject = Paperclip.io_adapters.for(@contents, hash_digest: Digest::MD5)
|
24
30
|
end
|
25
31
|
|
26
32
|
it "returns a nondescript file name" do
|
@@ -15,7 +15,7 @@ describe Paperclip::FileAdapter do
|
|
15
15
|
|
16
16
|
context 'doing normal things' do
|
17
17
|
before do
|
18
|
-
@subject = Paperclip.io_adapters.for(@file)
|
18
|
+
@subject = Paperclip.io_adapters.for(@file, hash_digest: Digest::MD5)
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'uses the original filename to generate the tempfile' do
|
@@ -61,7 +61,7 @@ describe Paperclip::FileAdapter do
|
|
61
61
|
context "file with multiple possible content type" do
|
62
62
|
before do
|
63
63
|
MIME::Types.stubs(:type_for).returns([MIME::Type.new('image/x-png'), MIME::Type.new('image/png')])
|
64
|
-
@subject = Paperclip.io_adapters.for(@file)
|
64
|
+
@subject = Paperclip.io_adapters.for(@file, hash_digest: Digest::MD5)
|
65
65
|
end
|
66
66
|
|
67
67
|
it "prefers officially registered mime type" do
|
@@ -7,12 +7,17 @@ describe Paperclip::HttpUrlProxyAdapter do
|
|
7
7
|
@open_return.stubs(:meta).returns({})
|
8
8
|
Paperclip::HttpUrlProxyAdapter.any_instance.
|
9
9
|
stubs(:download_content).returns(@open_return)
|
10
|
+
Paperclip::HttpUrlProxyAdapter.register
|
11
|
+
end
|
12
|
+
|
13
|
+
after do
|
14
|
+
Paperclip.io_adapters.unregister(described_class)
|
10
15
|
end
|
11
16
|
|
12
17
|
context "a new instance" do
|
13
18
|
before do
|
14
19
|
@url = "http://thoughtbot.com/images/thoughtbot-logo.png"
|
15
|
-
@subject = Paperclip.io_adapters.for(@url)
|
20
|
+
@subject = Paperclip.io_adapters.for(@url, hash_digest: Digest::MD5)
|
16
21
|
end
|
17
22
|
|
18
23
|
after do
|
@@ -101,4 +106,16 @@ describe Paperclip::HttpUrlProxyAdapter do
|
|
101
106
|
end
|
102
107
|
end
|
103
108
|
|
109
|
+
context "a url with special characters in the filename" do
|
110
|
+
it "returns a encoded filename" do
|
111
|
+
Paperclip::HttpUrlProxyAdapter.any_instance.stubs(:download_content).
|
112
|
+
returns(@open_return)
|
113
|
+
url = "https://github.com/thoughtbot/paperclip-öäü字´½♥زÈ.png"
|
114
|
+
subject = Paperclip.io_adapters.for(url)
|
115
|
+
filename = "paperclip-%C3%B6%C3%A4%C3%BC%E5%AD%97%C2%B4%C2%BD%E2%99%A5"\
|
116
|
+
"%C3%98%C2%B2%C3%88.png"
|
117
|
+
|
118
|
+
assert_equal filename, subject.original_filename
|
119
|
+
end
|
120
|
+
end
|
104
121
|
end
|
@@ -4,7 +4,7 @@ describe Paperclip::AttachmentRegistry do
|
|
4
4
|
context "for" do
|
5
5
|
before do
|
6
6
|
class AdapterTest
|
7
|
-
def initialize(
|
7
|
+
def initialize(_target, _ = {}); end
|
8
8
|
end
|
9
9
|
@subject = Paperclip::AdapterRegistry.new
|
10
10
|
@subject.register(AdapterTest){|t| Symbol === t }
|
@@ -18,7 +18,7 @@ describe Paperclip::AttachmentRegistry do
|
|
18
18
|
context "registered?" do
|
19
19
|
before do
|
20
20
|
class AdapterTest
|
21
|
-
def initialize(
|
21
|
+
def initialize(_target, _ = {}); end
|
22
22
|
end
|
23
23
|
@subject = Paperclip::AdapterRegistry.new
|
24
24
|
@subject.register(AdapterTest){|t| Symbol === t }
|
@@ -5,7 +5,7 @@ describe Paperclip::StringioAdapter do
|
|
5
5
|
before do
|
6
6
|
@contents = "abc123"
|
7
7
|
@stringio = StringIO.new(@contents)
|
8
|
-
@subject = Paperclip.io_adapters.for(@stringio)
|
8
|
+
@subject = Paperclip.io_adapters.for(@stringio, hash_digest: Digest::MD5)
|
9
9
|
end
|
10
10
|
|
11
11
|
it "returns a file name" do
|
@@ -17,7 +17,7 @@ describe Paperclip::UploadedFileAdapter do
|
|
17
17
|
tempfile: tempfile,
|
18
18
|
path: tempfile.path
|
19
19
|
)
|
20
|
-
@subject = Paperclip.io_adapters.for(@file)
|
20
|
+
@subject = Paperclip.io_adapters.for(@file, hash_digest: Digest::MD5)
|
21
21
|
end
|
22
22
|
|
23
23
|
it "gets the right filename" do
|
@@ -29,7 +29,7 @@ describe Paperclip::UploadedFileAdapter do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
it "gets the content type" do
|
32
|
-
assert_equal "image/
|
32
|
+
assert_equal "image/png", @subject.content_type
|
33
33
|
end
|
34
34
|
|
35
35
|
it "gets the file's size" do
|
@@ -63,7 +63,7 @@ describe Paperclip::UploadedFileAdapter do
|
|
63
63
|
head: "",
|
64
64
|
path: fixture_file("5k.png")
|
65
65
|
)
|
66
|
-
@subject = Paperclip.io_adapters.for(@file)
|
66
|
+
@subject = Paperclip.io_adapters.for(@file, hash_digest: Digest::MD5)
|
67
67
|
end
|
68
68
|
|
69
69
|
it "does not generate paths that include restricted characters" do
|
@@ -86,7 +86,7 @@ describe Paperclip::UploadedFileAdapter do
|
|
86
86
|
head: "",
|
87
87
|
path: fixture_file("5k.png")
|
88
88
|
)
|
89
|
-
@subject = Paperclip.io_adapters.for(@file)
|
89
|
+
@subject = Paperclip.io_adapters.for(@file, hash_digest: Digest::MD5)
|
90
90
|
end
|
91
91
|
|
92
92
|
it "gets the right filename" do
|
@@ -98,7 +98,7 @@ describe Paperclip::UploadedFileAdapter do
|
|
98
98
|
end
|
99
99
|
|
100
100
|
it "gets the content type" do
|
101
|
-
assert_equal "image/
|
101
|
+
assert_equal "image/png", @subject.content_type
|
102
102
|
end
|
103
103
|
|
104
104
|
it "gets the file's size" do
|
@@ -8,14 +8,20 @@ describe Paperclip::UriAdapter do
|
|
8
8
|
@open_return = StringIO.new("xxx")
|
9
9
|
@open_return.stubs(:content_type).returns(content_type)
|
10
10
|
@open_return.stubs(:meta).returns(meta)
|
11
|
-
Paperclip::UriAdapter.
|
12
|
-
|
11
|
+
Paperclip::UriAdapter.register
|
12
|
+
end
|
13
|
+
|
14
|
+
after do
|
15
|
+
Paperclip.io_adapters.unregister(described_class)
|
13
16
|
end
|
14
17
|
|
15
18
|
context "a new instance" do
|
16
19
|
before do
|
20
|
+
Paperclip::UriAdapter.any_instance.
|
21
|
+
stubs(:download_content).returns(@open_return)
|
22
|
+
|
17
23
|
@uri = URI.parse("http://thoughtbot.com/images/thoughtbot-logo.png")
|
18
|
-
@subject = Paperclip.io_adapters.for(@uri)
|
24
|
+
@subject = Paperclip.io_adapters.for(@uri, hash_digest: Digest::MD5)
|
19
25
|
end
|
20
26
|
|
21
27
|
it "returns a file name" do
|
@@ -67,6 +73,9 @@ describe Paperclip::UriAdapter do
|
|
67
73
|
let(:content_type) { "text/html" }
|
68
74
|
|
69
75
|
before do
|
76
|
+
Paperclip::UriAdapter.any_instance.
|
77
|
+
stubs(:download_content).returns(@open_return)
|
78
|
+
|
70
79
|
@uri = URI.parse("http://thoughtbot.com")
|
71
80
|
@subject = Paperclip.io_adapters.for(@uri)
|
72
81
|
end
|
@@ -82,6 +91,9 @@ describe Paperclip::UriAdapter do
|
|
82
91
|
|
83
92
|
context "a url with query params" do
|
84
93
|
before do
|
94
|
+
Paperclip::UriAdapter.any_instance.
|
95
|
+
stubs(:download_content).returns(@open_return)
|
96
|
+
|
85
97
|
@uri = URI.parse("https://github.com/thoughtbot/paperclip?file=test")
|
86
98
|
@subject = Paperclip.io_adapters.for(@uri)
|
87
99
|
end
|
@@ -100,6 +112,9 @@ describe Paperclip::UriAdapter do
|
|
100
112
|
end
|
101
113
|
|
102
114
|
before do
|
115
|
+
Paperclip::UriAdapter.any_instance.
|
116
|
+
stubs(:download_content).returns(@open_return)
|
117
|
+
|
103
118
|
@uri = URI.parse("https://github.com/thoughtbot/paperclip?file=test")
|
104
119
|
@subject = Paperclip.io_adapters.for(@uri)
|
105
120
|
end
|
@@ -111,6 +126,9 @@ describe Paperclip::UriAdapter do
|
|
111
126
|
|
112
127
|
context "a url with restricted characters in the filename" do
|
113
128
|
before do
|
129
|
+
Paperclip::UriAdapter.any_instance.
|
130
|
+
stubs(:download_content).returns(@open_return)
|
131
|
+
|
114
132
|
@uri = URI.parse("https://github.com/thoughtbot/paper:clip.jpg")
|
115
133
|
@subject = Paperclip.io_adapters.for(@uri)
|
116
134
|
end
|
@@ -124,4 +142,31 @@ describe Paperclip::UriAdapter do
|
|
124
142
|
end
|
125
143
|
end
|
126
144
|
|
145
|
+
describe "#download_content" do
|
146
|
+
before do
|
147
|
+
Paperclip::UriAdapter.any_instance.stubs(:open).returns(@open_return)
|
148
|
+
@uri = URI.parse("https://github.com/thoughtbot/paper:clip.jpg")
|
149
|
+
@subject = Paperclip.io_adapters.for(@uri)
|
150
|
+
end
|
151
|
+
|
152
|
+
after do
|
153
|
+
@subject.send(:download_content)
|
154
|
+
end
|
155
|
+
|
156
|
+
context "with default read_timeout" do
|
157
|
+
it "calls open without options" do
|
158
|
+
@subject.expects(:open).with(@uri, {}).at_least_once
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
context "with custom read_timeout" do
|
163
|
+
before do
|
164
|
+
Paperclip.options[:read_timeout] = 120
|
165
|
+
end
|
166
|
+
|
167
|
+
it "calls open with read_timeout option" do
|
168
|
+
@subject.expects(:open).with(@uri, read_timeout: 120).at_least_once
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
127
172
|
end
|
@@ -17,22 +17,26 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do
|
|
17
17
|
|
18
18
|
it "rejects a class with no validation" do
|
19
19
|
expect(matcher).to_not accept(Dummy)
|
20
|
+
expect { matcher.failure_message }.to_not raise_error
|
20
21
|
end
|
21
22
|
|
22
23
|
it 'rejects a class when the validation fails' do
|
23
24
|
Dummy.validates_attachment_content_type :avatar, content_type: %r{audio/.*}
|
24
25
|
expect(matcher).to_not accept(Dummy)
|
26
|
+
expect { matcher.failure_message }.to_not raise_error
|
25
27
|
end
|
26
28
|
|
27
29
|
it "accepts a class with a matching validation" do
|
28
30
|
Dummy.validates_attachment_content_type :avatar, content_type: %r{image/.*}
|
29
31
|
expect(matcher).to accept(Dummy)
|
32
|
+
expect { matcher.failure_message }.to_not raise_error
|
30
33
|
end
|
31
34
|
|
32
35
|
it "accepts a class with other validations but matching types" do
|
33
36
|
Dummy.validates_presence_of :title
|
34
37
|
Dummy.validates_attachment_content_type :avatar, content_type: %r{image/.*}
|
35
38
|
expect(matcher).to accept(Dummy)
|
39
|
+
expect { matcher.failure_message }.to_not raise_error
|
36
40
|
end
|
37
41
|
|
38
42
|
it "accepts a class that matches and a matcher that only specifies 'allowing'" do
|
@@ -40,6 +44,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do
|
|
40
44
|
matcher = plain_matcher.allowing(%w(image/png image/jpeg))
|
41
45
|
|
42
46
|
expect(matcher).to accept(Dummy)
|
47
|
+
expect { matcher.failure_message }.to_not raise_error
|
43
48
|
end
|
44
49
|
|
45
50
|
it "rejects a class that does not match and a matcher that only specifies 'allowing'" do
|
@@ -47,6 +52,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do
|
|
47
52
|
matcher = plain_matcher.allowing(%w(image/png image/jpeg))
|
48
53
|
|
49
54
|
expect(matcher).to_not accept(Dummy)
|
55
|
+
expect { matcher.failure_message }.to_not raise_error
|
50
56
|
end
|
51
57
|
|
52
58
|
it "accepts a class that matches and a matcher that only specifies 'rejecting'" do
|
@@ -54,6 +60,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do
|
|
54
60
|
matcher = plain_matcher.rejecting(%w(audio/mp3 application/octet-stream))
|
55
61
|
|
56
62
|
expect(matcher).to accept(Dummy)
|
63
|
+
expect { matcher.failure_message }.to_not raise_error
|
57
64
|
end
|
58
65
|
|
59
66
|
it "rejects a class that does not match and a matcher that only specifies 'rejecting'" do
|
@@ -61,6 +68,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do
|
|
61
68
|
matcher = plain_matcher.rejecting(%w(audio/mp3 application/octet-stream))
|
62
69
|
|
63
70
|
expect(matcher).to_not accept(Dummy)
|
71
|
+
expect { matcher.failure_message }.to_not raise_error
|
64
72
|
end
|
65
73
|
|
66
74
|
context "using an :if to control the validation" do
|
@@ -75,12 +83,14 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do
|
|
75
83
|
dummy = Dummy.new
|
76
84
|
dummy.go = true
|
77
85
|
expect(matcher).to accept(dummy)
|
86
|
+
expect { matcher.failure_message }.to_not raise_error
|
78
87
|
end
|
79
88
|
|
80
89
|
it "does not run the validation if the control is false" do
|
81
90
|
dummy = Dummy.new
|
82
91
|
dummy.go = false
|
83
92
|
expect(matcher).to_not accept(dummy)
|
93
|
+
expect { matcher.failure_message }.to_not raise_error
|
84
94
|
end
|
85
95
|
end
|
86
96
|
|