kt-paperclip 4.4.0 → 5.4.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/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 +4 -10
- data/lib/paperclip/storage/filesystem.rb +13 -2
- data/lib/paperclip/storage/fog.rb +19 -13
- data/lib/paperclip/storage/s3.rb +87 -58
- data/lib/paperclip/thumbnail.rb +18 -8
- data/lib/paperclip/url_generator.rb +18 -14
- data/lib/paperclip/validators/attachment_size_validator.rb +1 -7
- data/lib/paperclip/validators.rb +1 -1
- data/lib/paperclip/version.rb +3 -1
- data/lib/paperclip.rb +13 -12
- data/lib/tasks/paperclip.rake +18 -4
- data/paperclip.gemspec +13 -11
- 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 +26 -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 +53 -42
- 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 +10 -2
- data/spec/support/reporting.rb +11 -0
- metadata +69 -75
- 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,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
|
|
@@ -76,4 +76,19 @@ describe Paperclip::MediaTypeSpoofDetector do
|
|
76
76
|
Paperclip.options[:content_type_mappings] = {}
|
77
77
|
end
|
78
78
|
end
|
79
|
+
|
80
|
+
context "#type_from_file_command" do
|
81
|
+
let(:file) { File.new(fixture_file("empty.html")) }
|
82
|
+
let(:detector) { Paperclip::MediaTypeSpoofDetector.new(file, "html", "") }
|
83
|
+
|
84
|
+
it "does work with the output of old versions of file" do
|
85
|
+
Paperclip.stubs(:run).returns("text/html charset=us-ascii")
|
86
|
+
expect(detector.send(:type_from_file_command)).to eq("text/html")
|
87
|
+
end
|
88
|
+
|
89
|
+
it "does work with the output of new versions of file" do
|
90
|
+
Paperclip.stubs(:run).returns("text/html; charset=us-ascii")
|
91
|
+
expect(detector.send(:type_from_file_command)).to eq("text/html")
|
92
|
+
end
|
93
|
+
end
|
79
94
|
end
|
@@ -4,38 +4,40 @@ describe Paperclip do
|
|
4
4
|
context ".run" do
|
5
5
|
before do
|
6
6
|
Paperclip.options[:log_command] = false
|
7
|
-
|
8
|
-
@original_command_line_path =
|
7
|
+
Terrapin::CommandLine.expects(:new).with("convert", "stuff", {}).returns(stub(:run))
|
8
|
+
@original_command_line_path = Terrapin::CommandLine.path
|
9
9
|
end
|
10
10
|
|
11
11
|
after do
|
12
12
|
Paperclip.options[:log_command] = true
|
13
|
-
|
13
|
+
Terrapin::CommandLine.path = @original_command_line_path
|
14
14
|
end
|
15
15
|
|
16
|
-
it "runs the command with
|
16
|
+
it "runs the command with Terrapin" do
|
17
17
|
Paperclip.run("convert", "stuff")
|
18
18
|
end
|
19
19
|
|
20
|
-
it "saves
|
21
|
-
|
20
|
+
it "saves Terrapin::CommandLine.path that set before" do
|
21
|
+
Terrapin::CommandLine.path = "/opt/my_app/bin"
|
22
22
|
Paperclip.run("convert", "stuff")
|
23
|
-
expect(
|
23
|
+
expect(Terrapin::CommandLine.path).to match("/opt/my_app/bin")
|
24
24
|
end
|
25
25
|
|
26
|
-
it "does not duplicate
|
27
|
-
|
28
|
-
|
26
|
+
it "does not duplicate Terrapin::CommandLine.path on multiple runs" do
|
27
|
+
Terrapin::CommandLine.expects(:new).with("convert", "more_stuff", {}).returns(stub(:run))
|
28
|
+
Terrapin::CommandLine.path = nil
|
29
29
|
Paperclip.options[:command_path] = "/opt/my_app/bin"
|
30
30
|
Paperclip.run("convert", "stuff")
|
31
31
|
Paperclip.run("convert", "more_stuff")
|
32
|
-
|
32
|
+
|
33
|
+
cmd_path = Paperclip.options[:command_path]
|
34
|
+
assert_equal 1, Terrapin::CommandLine.path.scan(cmd_path).count
|
33
35
|
end
|
34
36
|
end
|
35
37
|
|
36
38
|
it 'does not raise errors when doing a lot of running' do
|
37
39
|
Paperclip.options[:command_path] = ["/usr/local/bin"] * 1024
|
38
|
-
|
40
|
+
Terrapin::CommandLine.path = "/something/else"
|
39
41
|
100.times do |x|
|
40
42
|
Paperclip.run("echo", x.to_s)
|
41
43
|
end
|
@@ -61,7 +63,7 @@ describe Paperclip do
|
|
61
63
|
context "Calling Paperclip.run with a logger" do
|
62
64
|
it "passes the defined logger if :log_command is set" do
|
63
65
|
Paperclip.options[:log_command] = true
|
64
|
-
|
66
|
+
Terrapin::CommandLine.expects(:new).with("convert", "stuff", logger: Paperclip.logger).returns(stub(:run))
|
65
67
|
Paperclip.run("convert", "stuff")
|
66
68
|
end
|
67
69
|
end
|
@@ -109,7 +111,6 @@ describe Paperclip do
|
|
109
111
|
|
110
112
|
context "An ActiveRecord model with an 'avatar' attachment" do
|
111
113
|
before do
|
112
|
-
Paperclip::Deprecations.stubs(:check)
|
113
114
|
rebuild_model path: "tmp/:class/omg/:style.:extension"
|
114
115
|
@file = File.new(fixture_file("5k.png"), 'rb')
|
115
116
|
end
|
@@ -124,37 +125,6 @@ describe Paperclip do
|
|
124
125
|
end
|
125
126
|
end
|
126
127
|
|
127
|
-
if using_protected_attributes?
|
128
|
-
context "that is attr_protected" do
|
129
|
-
before do
|
130
|
-
Dummy.class_eval do
|
131
|
-
attr_protected :avatar
|
132
|
-
end
|
133
|
-
@dummy = Dummy.new
|
134
|
-
end
|
135
|
-
|
136
|
-
it "does not assign the avatar on mass-set" do
|
137
|
-
@dummy.attributes = { other: "I'm set!",
|
138
|
-
avatar: @file }
|
139
|
-
|
140
|
-
assert_equal "I'm set!", @dummy.other
|
141
|
-
assert ! @dummy.avatar?
|
142
|
-
end
|
143
|
-
|
144
|
-
it "allows assigment on normal set" do
|
145
|
-
@dummy.other = "I'm set!"
|
146
|
-
@dummy.avatar = @file
|
147
|
-
|
148
|
-
assert_equal "I'm set!", @dummy.other
|
149
|
-
assert @dummy.avatar?
|
150
|
-
end
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
it "calls Paperclip::Deprecations.check" do
|
155
|
-
expect(Paperclip::Deprecations).to have_received(:check)
|
156
|
-
end
|
157
|
-
|
158
128
|
context "with a subclass" do
|
159
129
|
before do
|
160
130
|
class ::SubDummy < Dummy; end
|
@@ -9,17 +9,17 @@ describe Paperclip::Processor do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
context "Calling #convert" do
|
12
|
-
it "runs the convert command with
|
12
|
+
it "runs the convert command with Terrapin" do
|
13
13
|
Paperclip.options[:log_command] = false
|
14
|
-
|
14
|
+
Terrapin::CommandLine.expects(:new).with("convert", "stuff", {}).returns(stub(:run))
|
15
15
|
Paperclip::Processor.new('filename').convert("stuff")
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
context "Calling #identify" do
|
20
|
-
it "runs the identify command with
|
20
|
+
it "runs the identify command with Terrapin" do
|
21
21
|
Paperclip.options[:log_command] = false
|
22
|
-
|
22
|
+
Terrapin::CommandLine.expects(:new).with("identify", "stuff", {}).returns(stub(:run))
|
23
23
|
Paperclip::Processor.new('filename').identify("stuff")
|
24
24
|
end
|
25
25
|
end
|
@@ -183,6 +183,13 @@ describe Paperclip::Storage::Fog do
|
|
183
183
|
tempfile.close
|
184
184
|
end
|
185
185
|
|
186
|
+
it 'is able to be handled when missing while copying to a local file' do
|
187
|
+
tempfile = Tempfile.new("known_location")
|
188
|
+
tempfile.binmode
|
189
|
+
assert_equal false, @dummy.avatar.copy_to_local_file(:original, tempfile.path)
|
190
|
+
tempfile.close
|
191
|
+
end
|
192
|
+
|
186
193
|
it "passes the content type to the Fog::Storage::AWS::Files instance" do
|
187
194
|
Fog::Storage::AWS::Files.any_instance.expects(:create).with do |hash|
|
188
195
|
hash[:content_type]
|
@@ -271,6 +278,22 @@ describe Paperclip::Storage::Fog do
|
|
271
278
|
end
|
272
279
|
end
|
273
280
|
|
281
|
+
context "with fog_public as a proc" do
|
282
|
+
let(:proc) { ->(attachment) { !attachment } }
|
283
|
+
|
284
|
+
before do
|
285
|
+
rebuild_model(@options.merge(fog_public: proc))
|
286
|
+
@dummy = Dummy.new
|
287
|
+
@dummy.avatar = StringIO.new(".")
|
288
|
+
@dummy.save
|
289
|
+
end
|
290
|
+
|
291
|
+
it "sets the @fog_public instance variable to false" do
|
292
|
+
assert_equal proc, @dummy.avatar.instance_variable_get("@options")[:fog_public]
|
293
|
+
assert_equal false, @dummy.avatar.fog_public
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
274
297
|
context "with styles set and fog_public set to false" do
|
275
298
|
before do
|
276
299
|
rebuild_model(@options.merge(fog_public: false, styles: { medium: "300x300>", thumb: "100x100>" }))
|
@@ -423,6 +446,9 @@ describe Paperclip::Storage::Fog do
|
|
423
446
|
assert @connection.directories.get(@dynamic_fog_directory).inspect
|
424
447
|
end
|
425
448
|
|
449
|
+
it "provides an url using dynamic bucket name" do
|
450
|
+
assert_match(/^https:\/\/dynamicpaperclip.s3.amazonaws.com\/avatars\/5k.png\?\d*$/, @dummy.avatar.url)
|
451
|
+
end
|
426
452
|
end
|
427
453
|
|
428
454
|
context "with a proc for the fog_host evaluating a model method" do
|
@@ -8,9 +8,10 @@ unless ENV["S3_BUCKET"].blank?
|
|
8
8
|
storage: :s3,
|
9
9
|
bucket: ENV["S3_BUCKET"],
|
10
10
|
path: ":class/:attachment/:id/:style.:extension",
|
11
|
+
s3_region: ENV["S3_REGION"],
|
11
12
|
s3_credentials: {
|
12
|
-
|
13
|
-
|
13
|
+
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
|
14
|
+
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY']
|
14
15
|
}
|
15
16
|
|
16
17
|
@file = File.new(fixture_file("5k.png"))
|
@@ -45,9 +46,10 @@ unless ENV["S3_BUCKET"].blank?
|
|
45
46
|
storage: :s3,
|
46
47
|
bucket: ENV["S3_BUCKET"],
|
47
48
|
path: ":class/:attachment/:id/:style.:extension",
|
49
|
+
s3_region: ENV["S3_REGION"],
|
48
50
|
s3_credentials: {
|
49
|
-
|
50
|
-
|
51
|
+
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
|
52
|
+
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY']
|
51
53
|
}
|
52
54
|
|
53
55
|
@dummy = Dummy.new
|
@@ -64,9 +66,10 @@ unless ENV["S3_BUCKET"].blank?
|
|
64
66
|
storage: :s3,
|
65
67
|
bucket: ENV["S3_BUCKET"],
|
66
68
|
path: ":class/:attachment/:id/:style.:extension",
|
69
|
+
s3_region: ENV["S3_REGION"],
|
67
70
|
s3_credentials: {
|
68
|
-
|
69
|
-
|
71
|
+
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
|
72
|
+
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY']
|
70
73
|
}
|
71
74
|
|
72
75
|
Dummy.delete_all
|
@@ -105,9 +108,12 @@ unless ENV["S3_BUCKET"].blank?
|
|
105
108
|
rebuild_model styles: { thumb: "100x100", square: "32x32#" },
|
106
109
|
storage: :s3,
|
107
110
|
bucket: ENV["S3_BUCKET"],
|
111
|
+
s3_region: ENV["S3_REGION"],
|
112
|
+
url: ":s3_domain_url",
|
113
|
+
path: "/:class/:attachment/:id_partition/:style/:filename",
|
108
114
|
s3_credentials: {
|
109
|
-
|
110
|
-
|
115
|
+
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
|
116
|
+
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY']
|
111
117
|
}
|
112
118
|
|
113
119
|
Dummy.delete_all
|
@@ -136,7 +142,7 @@ unless ENV["S3_BUCKET"].blank?
|
|
136
142
|
it "is destroyable" do
|
137
143
|
url = @dummy.avatar.url
|
138
144
|
@dummy.destroy
|
139
|
-
|
145
|
+
assert_forbidden_response url
|
140
146
|
end
|
141
147
|
end
|
142
148
|
|
@@ -146,12 +152,12 @@ unless ENV["S3_BUCKET"].blank?
|
|
146
152
|
storage: :s3,
|
147
153
|
bucket: ENV["S3_BUCKET"],
|
148
154
|
path: ":class/:attachment/:id/:style.:extension",
|
155
|
+
s3_region: ENV["S3_REGION"],
|
149
156
|
s3_credentials: {
|
150
|
-
|
151
|
-
|
157
|
+
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
|
158
|
+
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY']
|
152
159
|
},
|
153
|
-
s3_server_side_encryption:
|
154
|
-
|
160
|
+
s3_server_side_encryption: "AES256"
|
155
161
|
Dummy.delete_all
|
156
162
|
@dummy = Dummy.new
|
157
163
|
end
|
@@ -173,7 +179,7 @@ unless ENV["S3_BUCKET"].blank?
|
|
173
179
|
end
|
174
180
|
|
175
181
|
it "is encrypted on S3" do
|
176
|
-
assert @dummy.avatar.s3_object.server_side_encryption ==
|
182
|
+
assert @dummy.avatar.s3_object.server_side_encryption == "AES256"
|
177
183
|
end
|
178
184
|
end
|
179
185
|
end
|