paperclip 4.2.1 → 4.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.hound.yml +1066 -0
- data/.rubocop.yml +1 -0
- data/.travis.yml +5 -3
- data/Appraisals +2 -7
- data/CONTRIBUTING.md +3 -3
- data/Gemfile +2 -1
- data/LICENSE +1 -1
- data/NEWS +57 -30
- data/README.md +137 -77
- data/RELEASING.md +17 -0
- data/Rakefile +1 -1
- data/features/basic_integration.feature +7 -4
- data/features/step_definitions/attachment_steps.rb +7 -1
- data/gemfiles/3.2.gemfile +2 -1
- data/gemfiles/4.1.gemfile +2 -1
- data/gemfiles/4.2.gemfile +3 -2
- data/lib/paperclip/attachment.rb +3 -1
- data/lib/paperclip/attachment_registry.rb +1 -1
- data/lib/paperclip/content_type_detector.rb +26 -11
- data/lib/paperclip/file_command_content_type_detector.rb +6 -8
- data/lib/paperclip/glue.rb +1 -1
- data/lib/paperclip/has_attached_file.rb +2 -1
- data/lib/paperclip/interpolations.rb +1 -1
- data/lib/paperclip/io_adapters/abstract_adapter.rb +1 -0
- data/lib/paperclip/locales/en.yml +1 -1
- data/lib/paperclip/media_type_spoof_detector.rb +38 -18
- data/lib/paperclip/rails_environment.rb +25 -0
- data/lib/paperclip/storage/fog.rb +4 -4
- data/lib/paperclip/storage/s3.rb +2 -3
- data/lib/paperclip/thumbnail.rb +2 -3
- data/lib/paperclip/validators/media_type_spoof_detection_validator.rb +1 -1
- data/lib/paperclip/version.rb +1 -1
- data/lib/paperclip.rb +13 -3
- data/lib/tasks/paperclip.rake +16 -0
- data/paperclip.gemspec +9 -10
- data/spec/paperclip/attachment_definitions_spec.rb +1 -1
- data/spec/paperclip/attachment_registry_spec.rb +56 -13
- data/spec/paperclip/attachment_spec.rb +57 -19
- data/spec/paperclip/content_type_detector_spec.rb +8 -1
- data/spec/paperclip/file_command_content_type_detector_spec.rb +0 -1
- data/spec/paperclip/interpolations_spec.rb +2 -9
- data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +2 -1
- data/spec/paperclip/io_adapters/file_adapter_spec.rb +4 -1
- data/spec/paperclip/io_adapters/stringio_adapter_spec.rb +4 -0
- data/spec/paperclip/media_type_spoof_detector_spec.rb +31 -7
- data/spec/paperclip/paperclip_spec.rb +1 -1
- data/spec/paperclip/rails_environment_spec.rb +33 -0
- data/spec/paperclip/storage/fog_spec.rb +11 -2
- data/spec/paperclip/storage/s3_spec.rb +43 -25
- data/spec/paperclip/tempfile_factory_spec.rb +4 -0
- data/spec/paperclip/thumbnail_spec.rb +16 -0
- data/spec/paperclip/url_generator_spec.rb +1 -1
- data/spec/paperclip/validators/media_type_spoof_detection_validator_spec.rb +1 -1
- data/spec/support/fake_model.rb +4 -0
- data/spec/support/fixtures/empty.xlsx +0 -0
- data/spec/support/matchers/have_column.rb +11 -2
- metadata +49 -24
- data/RUNNING_TESTS.md +0 -4
- data/gemfiles/4.0.gemfile +0 -19
- data/spec/support/mock_model.rb +0 -2
|
@@ -13,7 +13,7 @@ describe Paperclip::Attachment do
|
|
|
13
13
|
it "is present when the file is set" do
|
|
14
14
|
rebuild_class
|
|
15
15
|
dummy = Dummy.new
|
|
16
|
-
dummy.avatar = File.new(fixture_file("50x50.png"), "rb")
|
|
16
|
+
dummy.avatar = File.new(fixture_file("50x50.png"), "rb")
|
|
17
17
|
expect(dummy.avatar).to_not be_blank
|
|
18
18
|
expect(dummy.avatar).to be_present
|
|
19
19
|
end
|
|
@@ -34,9 +34,9 @@ describe Paperclip::Attachment do
|
|
|
34
34
|
it "does not delete styles that don't get reprocessed" do
|
|
35
35
|
file = File.new(fixture_file("50x50.png"), 'rb')
|
|
36
36
|
rebuild_class styles: {
|
|
37
|
-
small:
|
|
38
|
-
large:
|
|
39
|
-
original:
|
|
37
|
+
small: "100x>",
|
|
38
|
+
large: "500x>",
|
|
39
|
+
original: "42x42#"
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
dummy = Dummy.new
|
|
@@ -75,7 +75,11 @@ describe Paperclip::Attachment do
|
|
|
75
75
|
|
|
76
76
|
it "handles a boolean second argument to #url" do
|
|
77
77
|
mock_url_generator_builder = MockUrlGeneratorBuilder.new
|
|
78
|
-
attachment = Paperclip::Attachment.new(
|
|
78
|
+
attachment = Paperclip::Attachment.new(
|
|
79
|
+
:name,
|
|
80
|
+
FakeModel.new,
|
|
81
|
+
url_generator: mock_url_generator_builder
|
|
82
|
+
)
|
|
79
83
|
|
|
80
84
|
attachment.url(:style_name, true)
|
|
81
85
|
expect(mock_url_generator_builder.has_generated_url_with_options?(timestamp: true, escape: true)).to eq true
|
|
@@ -86,7 +90,11 @@ describe Paperclip::Attachment do
|
|
|
86
90
|
|
|
87
91
|
it "passes the style and options through to the URL generator on #url" do
|
|
88
92
|
mock_url_generator_builder = MockUrlGeneratorBuilder.new
|
|
89
|
-
attachment = Paperclip::Attachment.new(
|
|
93
|
+
attachment = Paperclip::Attachment.new(
|
|
94
|
+
:name,
|
|
95
|
+
FakeModel.new,
|
|
96
|
+
url_generator: mock_url_generator_builder
|
|
97
|
+
)
|
|
90
98
|
|
|
91
99
|
attachment.url(:style_name, options: :values)
|
|
92
100
|
expect(mock_url_generator_builder.has_generated_url_with_options?(options: :values)).to eq true
|
|
@@ -95,7 +103,7 @@ describe Paperclip::Attachment do
|
|
|
95
103
|
it "passes default options through when #url is given one argument" do
|
|
96
104
|
mock_url_generator_builder = MockUrlGeneratorBuilder.new
|
|
97
105
|
attachment = Paperclip::Attachment.new(:name,
|
|
98
|
-
|
|
106
|
+
FakeModel.new,
|
|
99
107
|
url_generator: mock_url_generator_builder,
|
|
100
108
|
use_timestamp: true)
|
|
101
109
|
|
|
@@ -106,7 +114,7 @@ describe Paperclip::Attachment do
|
|
|
106
114
|
it "passes default style and options through when #url is given no arguments" do
|
|
107
115
|
mock_url_generator_builder = MockUrlGeneratorBuilder.new
|
|
108
116
|
attachment = Paperclip::Attachment.new(:name,
|
|
109
|
-
|
|
117
|
+
FakeModel.new,
|
|
110
118
|
default_style: 'default style',
|
|
111
119
|
url_generator: mock_url_generator_builder,
|
|
112
120
|
use_timestamp: true)
|
|
@@ -119,7 +127,7 @@ describe Paperclip::Attachment do
|
|
|
119
127
|
it "passes the option timestamp: true if :use_timestamp is true and :timestamp is not passed" do
|
|
120
128
|
mock_url_generator_builder = MockUrlGeneratorBuilder.new
|
|
121
129
|
attachment = Paperclip::Attachment.new(:name,
|
|
122
|
-
|
|
130
|
+
FakeModel.new,
|
|
123
131
|
url_generator: mock_url_generator_builder,
|
|
124
132
|
use_timestamp: true)
|
|
125
133
|
|
|
@@ -130,7 +138,7 @@ describe Paperclip::Attachment do
|
|
|
130
138
|
it "passes the option timestamp: false if :use_timestamp is false and :timestamp is not passed" do
|
|
131
139
|
mock_url_generator_builder = MockUrlGeneratorBuilder.new
|
|
132
140
|
attachment = Paperclip::Attachment.new(:name,
|
|
133
|
-
|
|
141
|
+
FakeModel.new,
|
|
134
142
|
url_generator: mock_url_generator_builder,
|
|
135
143
|
use_timestamp: false)
|
|
136
144
|
|
|
@@ -141,7 +149,7 @@ describe Paperclip::Attachment do
|
|
|
141
149
|
it "does not change the :timestamp if :timestamp is passed" do
|
|
142
150
|
mock_url_generator_builder = MockUrlGeneratorBuilder.new
|
|
143
151
|
attachment = Paperclip::Attachment.new(:name,
|
|
144
|
-
|
|
152
|
+
FakeModel.new,
|
|
145
153
|
url_generator: mock_url_generator_builder,
|
|
146
154
|
use_timestamp: false)
|
|
147
155
|
|
|
@@ -152,7 +160,7 @@ describe Paperclip::Attachment do
|
|
|
152
160
|
it "renders JSON as default style" do
|
|
153
161
|
mock_url_generator_builder = MockUrlGeneratorBuilder.new
|
|
154
162
|
attachment = Paperclip::Attachment.new(:name,
|
|
155
|
-
|
|
163
|
+
FakeModel.new,
|
|
156
164
|
default_style: 'default style',
|
|
157
165
|
url_generator: mock_url_generator_builder)
|
|
158
166
|
|
|
@@ -163,7 +171,7 @@ describe Paperclip::Attachment do
|
|
|
163
171
|
it "passes the option escape: true if :escape_url is true and :escape is not passed" do
|
|
164
172
|
mock_url_generator_builder = MockUrlGeneratorBuilder.new
|
|
165
173
|
attachment = Paperclip::Attachment.new(:name,
|
|
166
|
-
|
|
174
|
+
FakeModel.new,
|
|
167
175
|
url_generator: mock_url_generator_builder,
|
|
168
176
|
escape_url: true)
|
|
169
177
|
|
|
@@ -174,7 +182,7 @@ describe Paperclip::Attachment do
|
|
|
174
182
|
it "passes the option escape: false if :escape_url is false and :escape is not passed" do
|
|
175
183
|
mock_url_generator_builder = MockUrlGeneratorBuilder.new
|
|
176
184
|
attachment = Paperclip::Attachment.new(:name,
|
|
177
|
-
|
|
185
|
+
FakeModel.new,
|
|
178
186
|
url_generator: mock_url_generator_builder,
|
|
179
187
|
escape_url: false)
|
|
180
188
|
|
|
@@ -212,6 +220,7 @@ describe Paperclip::Attachment do
|
|
|
212
220
|
dummy = Dummy.new
|
|
213
221
|
dummy.id = 1234
|
|
214
222
|
dummy.avatar_file_name = "fake.jpg"
|
|
223
|
+
dummy.stubs(:new_record?).returns(false)
|
|
215
224
|
expected_string = '{"avatar":"/system/dummies/avatars/000/001/234/original/fake.jpg"}'
|
|
216
225
|
if ActiveRecord::Base.include_root_in_json # This is true by default in Rails 3, and false in 4
|
|
217
226
|
expected_string = %({"dummy":#{expected_string}})
|
|
@@ -251,6 +260,10 @@ describe Paperclip::Attachment do
|
|
|
251
260
|
it "returns false when asked exists?" do
|
|
252
261
|
assert !@dummy.avatar.exists?
|
|
253
262
|
end
|
|
263
|
+
|
|
264
|
+
it "#url returns nil" do
|
|
265
|
+
assert_nil @dummy.avatar.url
|
|
266
|
+
end
|
|
254
267
|
end
|
|
255
268
|
|
|
256
269
|
context "on an Attachment" do
|
|
@@ -635,15 +648,40 @@ describe Paperclip::Attachment do
|
|
|
635
648
|
before do
|
|
636
649
|
rebuild_model processor: [:thumbnail], styles: { small: '' }, whiny_thumbnails: true
|
|
637
650
|
@dummy = Dummy.new
|
|
638
|
-
Paperclip::Thumbnail.expects(:make).raises(Paperclip::Error, "cannot be processed.")
|
|
639
651
|
@file = StringIO.new("...")
|
|
640
652
|
@file.stubs(:to_tempfile).returns(@file)
|
|
641
|
-
@dummy.avatar = @file
|
|
642
653
|
end
|
|
643
654
|
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
655
|
+
context "when error is meaningful for the end user" do
|
|
656
|
+
before do
|
|
657
|
+
Paperclip::Thumbnail.expects(:make).raises(
|
|
658
|
+
Paperclip::Errors::NotIdentifiedByImageMagickError,
|
|
659
|
+
"cannot be processed."
|
|
660
|
+
)
|
|
661
|
+
end
|
|
662
|
+
|
|
663
|
+
it "correctly forwards processing error message to the instance" do
|
|
664
|
+
@dummy.avatar = @file
|
|
665
|
+
@dummy.valid?
|
|
666
|
+
assert_contains(
|
|
667
|
+
@dummy.errors.full_messages,
|
|
668
|
+
"Avatar cannot be processed."
|
|
669
|
+
)
|
|
670
|
+
end
|
|
671
|
+
end
|
|
672
|
+
|
|
673
|
+
context "when error is intended for the developer" do
|
|
674
|
+
before do
|
|
675
|
+
Paperclip::Thumbnail.expects(:make).raises(
|
|
676
|
+
Paperclip::Errors::CommandNotFoundError
|
|
677
|
+
)
|
|
678
|
+
end
|
|
679
|
+
|
|
680
|
+
it "propagates the error" do
|
|
681
|
+
assert_raises(Paperclip::Errors::CommandNotFoundError) do
|
|
682
|
+
@dummy.avatar = @file
|
|
683
|
+
end
|
|
684
|
+
end
|
|
647
685
|
end
|
|
648
686
|
end
|
|
649
687
|
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe Paperclip::ContentTypeDetector do
|
|
4
|
+
it 'returns a meaningful content type for open xml spreadsheets' do
|
|
5
|
+
file = File.new(fixture_file("empty.xlsx"))
|
|
6
|
+
assert_equal "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
7
|
+
Paperclip::ContentTypeDetector.new(file.path).detect
|
|
8
|
+
end
|
|
9
|
+
|
|
4
10
|
it 'gives a sensible default when the name is empty' do
|
|
5
11
|
assert_equal "application/octet-stream", Paperclip::ContentTypeDetector.new("").detect
|
|
6
12
|
end
|
|
@@ -13,7 +19,8 @@ describe Paperclip::ContentTypeDetector do
|
|
|
13
19
|
|
|
14
20
|
it 'returns content type of file if it is an acceptable type' do
|
|
15
21
|
MIME::Types.stubs(:type_for).returns([MIME::Type.new('application/mp4'), MIME::Type.new('video/mp4'), MIME::Type.new('audio/mp4')])
|
|
16
|
-
Paperclip.
|
|
22
|
+
Paperclip::ContentTypeDetector.any_instance
|
|
23
|
+
.stubs(:type_from_file_contents).returns("video/mp4")
|
|
17
24
|
@filename = "my_file.mp4"
|
|
18
25
|
assert_equal "video/mp4", Paperclip::ContentTypeDetector.new(@filename).detect
|
|
19
26
|
end
|
|
@@ -138,14 +138,7 @@ describe Paperclip::Interpolations do
|
|
|
138
138
|
assert_equal "000/000/023", Paperclip::Interpolations.id_partition(attachment, :style)
|
|
139
139
|
end
|
|
140
140
|
|
|
141
|
-
it "returns the partitioned id of the attachment when the id is a
|
|
142
|
-
attachment = mock
|
|
143
|
-
attachment.expects(:id).returns("fnj23")
|
|
144
|
-
attachment.expects(:instance).returns(attachment)
|
|
145
|
-
assert_equal "000/0fn/j23", Paperclip::Interpolations.id_partition(attachment, :style)
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
it "returns the partitioned id of the attachment when the id is a long string" do
|
|
141
|
+
it "returns the partitioned id of the attachment when the id is a string" do
|
|
149
142
|
attachment = mock
|
|
150
143
|
attachment.expects(:id).returns("32fnj23oio2f")
|
|
151
144
|
attachment.expects(:instance).returns(attachment)
|
|
@@ -211,7 +204,7 @@ describe Paperclip::Interpolations do
|
|
|
211
204
|
attachment.stubs(:original_filename).returns("one")
|
|
212
205
|
assert_equal "one", Paperclip::Interpolations.filename(attachment, :style)
|
|
213
206
|
end
|
|
214
|
-
|
|
207
|
+
|
|
215
208
|
it "returns the basename when the extension contains regexp special characters" do
|
|
216
209
|
attachment = mock
|
|
217
210
|
attachment.stubs(:styles).returns({})
|
|
@@ -9,11 +9,12 @@ describe Paperclip::AbstractAdapter do
|
|
|
9
9
|
end
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
context "content type from file
|
|
12
|
+
context "content type from file contents" do
|
|
13
13
|
before do
|
|
14
14
|
@adapter = TestAdapter.new
|
|
15
15
|
@adapter.stubs(:path).returns("image.png")
|
|
16
16
|
Paperclip.stubs(:run).returns("image/png\n")
|
|
17
|
+
Paperclip::ContentTypeDetector.any_instance.stubs(:type_from_mime_magic).returns("image/png")
|
|
17
18
|
end
|
|
18
19
|
|
|
19
20
|
it "returns the content type without newline" do
|
|
@@ -73,10 +73,13 @@ describe Paperclip::FileAdapter do
|
|
|
73
73
|
end
|
|
74
74
|
end
|
|
75
75
|
|
|
76
|
-
context "file with content type derived from file
|
|
76
|
+
context "file with content type derived from file contents on *nix" do
|
|
77
77
|
before do
|
|
78
78
|
MIME::Types.stubs(:type_for).returns([])
|
|
79
79
|
Paperclip.stubs(:run).returns("application/vnd.ms-office\n")
|
|
80
|
+
Paperclip::ContentTypeDetector.any_instance
|
|
81
|
+
.stubs(:type_from_mime_magic).returns("application/vnd.ms-office")
|
|
82
|
+
|
|
80
83
|
@subject = Paperclip.io_adapters.for(@file)
|
|
81
84
|
end
|
|
82
85
|
|
|
@@ -20,6 +20,10 @@ describe Paperclip::StringioAdapter do
|
|
|
20
20
|
assert_equal 6, @subject.size
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
+
it "returns the length of the data" do
|
|
24
|
+
assert_equal 6, @subject.length
|
|
25
|
+
end
|
|
26
|
+
|
|
23
27
|
it "generates an MD5 hash of the contents" do
|
|
24
28
|
assert_equal Digest::MD5.hexdigest(@contents), @subject.fingerprint
|
|
25
29
|
end
|
|
@@ -3,32 +3,32 @@ require 'spec_helper'
|
|
|
3
3
|
describe Paperclip::MediaTypeSpoofDetector do
|
|
4
4
|
it 'rejects a file that is named .html and identifies as PNG' do
|
|
5
5
|
file = File.open(fixture_file("5k.png"))
|
|
6
|
-
assert Paperclip::MediaTypeSpoofDetector.using(file, "5k.html").spoofed?
|
|
6
|
+
assert Paperclip::MediaTypeSpoofDetector.using(file, "5k.html", "image/png").spoofed?
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
it 'does not reject a file that is named .jpg and identifies as PNG' do
|
|
10
10
|
file = File.open(fixture_file("5k.png"))
|
|
11
|
-
assert ! Paperclip::MediaTypeSpoofDetector.using(file, "5k.jpg").spoofed?
|
|
11
|
+
assert ! Paperclip::MediaTypeSpoofDetector.using(file, "5k.jpg", "image/png").spoofed?
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
it 'does not reject a file that is named .html and identifies as HTML' do
|
|
15
15
|
file = File.open(fixture_file("empty.html"))
|
|
16
|
-
assert ! Paperclip::MediaTypeSpoofDetector.using(file, "empty.html").spoofed?
|
|
16
|
+
assert ! Paperclip::MediaTypeSpoofDetector.using(file, "empty.html", "text/html").spoofed?
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
it 'does not reject a file that does not have a name' do
|
|
20
20
|
file = File.open(fixture_file("empty.html"))
|
|
21
|
-
assert ! Paperclip::MediaTypeSpoofDetector.using(file, "").spoofed?
|
|
21
|
+
assert ! Paperclip::MediaTypeSpoofDetector.using(file, "", "text/html").spoofed?
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
it 'does not reject a file that does have an extension' do
|
|
25
25
|
file = File.open(fixture_file("empty.html"))
|
|
26
|
-
assert ! Paperclip::MediaTypeSpoofDetector.using(file, "data").spoofed?
|
|
26
|
+
assert ! Paperclip::MediaTypeSpoofDetector.using(file, "data", "text/html").spoofed?
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
it 'does not reject when the supplied file is an IOAdapter' do
|
|
30
30
|
adapter = Paperclip.io_adapters.for(File.new(fixture_file("5k.png")))
|
|
31
|
-
assert ! Paperclip::MediaTypeSpoofDetector.using(adapter, adapter.original_filename).spoofed?
|
|
31
|
+
assert ! Paperclip::MediaTypeSpoofDetector.using(adapter, adapter.original_filename, adapter.content_type).spoofed?
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
it 'does not reject when the extension => content_type is in :content_type_mappings' do
|
|
@@ -38,7 +38,31 @@ describe Paperclip::MediaTypeSpoofDetector do
|
|
|
38
38
|
file.puts "Certificate!"
|
|
39
39
|
file.close
|
|
40
40
|
adapter = Paperclip.io_adapters.for(File.new(file.path));
|
|
41
|
-
assert ! Paperclip::MediaTypeSpoofDetector.using(adapter, adapter.original_filename).spoofed?
|
|
41
|
+
assert ! Paperclip::MediaTypeSpoofDetector.using(adapter, adapter.original_filename, adapter.content_type).spoofed?
|
|
42
|
+
ensure
|
|
43
|
+
Paperclip.options[:content_type_mappings] = {}
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "rejects a file if named .html and is as HTML, but we're told JPG" do
|
|
48
|
+
file = File.open(fixture_file("empty.html"))
|
|
49
|
+
assert Paperclip::MediaTypeSpoofDetector.using(file, "empty.html", "image/jpg").spoofed?
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it "does not reject if content_type is empty but otherwise checks out" do
|
|
53
|
+
file = File.open(fixture_file("empty.html"))
|
|
54
|
+
assert ! Paperclip::MediaTypeSpoofDetector.using(file, "empty.html", "").spoofed?
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it 'does allow array as :content_type_mappings' do
|
|
58
|
+
begin
|
|
59
|
+
Paperclip.options[:content_type_mappings] = {
|
|
60
|
+
html: ['binary', 'text/html']
|
|
61
|
+
}
|
|
62
|
+
file = File.open(fixture_file('empty.html'))
|
|
63
|
+
spoofed = Paperclip::MediaTypeSpoofDetector
|
|
64
|
+
.using(file, "empty.html", "text/html").spoofed?
|
|
65
|
+
assert !spoofed
|
|
42
66
|
ensure
|
|
43
67
|
Paperclip.options[:content_type_mappings] = {}
|
|
44
68
|
end
|
|
@@ -20,7 +20,7 @@ describe Paperclip do
|
|
|
20
20
|
it "saves Cocaine::CommandLine.path that set before" do
|
|
21
21
|
Cocaine::CommandLine.path = "/opt/my_app/bin"
|
|
22
22
|
Paperclip.run("convert", "stuff")
|
|
23
|
-
|
|
23
|
+
expect(Cocaine::CommandLine.path).to match("/opt/my_app/bin")
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
it "does not duplicate Cocaine::CommandLine.path on multiple runs" do
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Paperclip::RailsEnvironment do
|
|
4
|
+
|
|
5
|
+
it "returns nil when Rails isn't defined" do
|
|
6
|
+
resetting_rails_to(nil) do
|
|
7
|
+
expect(Paperclip::RailsEnvironment.get).to be_nil
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "returns nil when Rails.env isn't defined" do
|
|
12
|
+
resetting_rails_to({}) do
|
|
13
|
+
expect(Paperclip::RailsEnvironment.get).to be_nil
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "returns the value of Rails.env if it is set" do
|
|
18
|
+
resetting_rails_to(OpenStruct.new(env: "foo")) do
|
|
19
|
+
expect(Paperclip::RailsEnvironment.get).to eq "foo"
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def resetting_rails_to(new_value)
|
|
24
|
+
begin
|
|
25
|
+
previous_rails = Object.send(:remove_const, "Rails")
|
|
26
|
+
Object.const_set("Rails", new_value) unless new_value.nil?
|
|
27
|
+
yield
|
|
28
|
+
ensure
|
|
29
|
+
Object.send(:remove_const, "Rails") if Object.const_defined?("Rails")
|
|
30
|
+
Object.const_set("Rails", previous_rails)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -320,6 +320,9 @@ describe Paperclip::Storage::Fog do
|
|
|
320
320
|
it "honors the scheme in public url" do
|
|
321
321
|
assert_match(/^http:\/\//, @dummy.avatar.url)
|
|
322
322
|
end
|
|
323
|
+
it "honors the scheme in expiring url" do
|
|
324
|
+
assert_match(/^http:\/\//, @dummy.avatar.expiring_url)
|
|
325
|
+
end
|
|
323
326
|
end
|
|
324
327
|
|
|
325
328
|
context "with scheme not set" do
|
|
@@ -334,15 +337,20 @@ describe Paperclip::Storage::Fog do
|
|
|
334
337
|
it "provides HTTPS public url" do
|
|
335
338
|
assert_match(/^https:\/\//, @dummy.avatar.url)
|
|
336
339
|
end
|
|
340
|
+
it "provides HTTPS expiring url" do
|
|
341
|
+
assert_match(/^https:\/\//, @dummy.avatar.expiring_url)
|
|
342
|
+
end
|
|
337
343
|
end
|
|
338
344
|
|
|
339
345
|
context "with a valid bucket name for a subdomain" do
|
|
346
|
+
before { @dummy.stubs(:new_record?).returns(false) }
|
|
347
|
+
|
|
340
348
|
it "provides an url in subdomain style" do
|
|
341
349
|
assert_match(/^https:\/\/papercliptests.s3.amazonaws.com\/avatars\/5k.png/, @dummy.avatar.url)
|
|
342
350
|
end
|
|
343
351
|
|
|
344
352
|
it "provides an url that expires in subdomain style" do
|
|
345
|
-
assert_match(/^
|
|
353
|
+
assert_match(/^https:\/\/papercliptests.s3.amazonaws.com\/avatars\/5k.png.+Expires=.+$/, @dummy.avatar.expiring_url)
|
|
346
354
|
end
|
|
347
355
|
end
|
|
348
356
|
|
|
@@ -390,7 +398,7 @@ describe Paperclip::Storage::Fog do
|
|
|
390
398
|
end
|
|
391
399
|
|
|
392
400
|
it "provides a url that expires in folder style" do
|
|
393
|
-
assert_match(/^
|
|
401
|
+
assert_match(/^https:\/\/s3.amazonaws.com\/this_is_invalid\/avatars\/5k.png.+Expires=.+$/, @dummy.avatar.expiring_url)
|
|
394
402
|
end
|
|
395
403
|
|
|
396
404
|
end
|
|
@@ -492,6 +500,7 @@ describe Paperclip::Storage::Fog do
|
|
|
492
500
|
@file = File.new(fixture_file('5k.png'), 'rb')
|
|
493
501
|
@dummy = Dummy.new
|
|
494
502
|
@dummy.avatar = @file
|
|
503
|
+
@dummy.stubs(:new_record?).returns(false)
|
|
495
504
|
end
|
|
496
505
|
|
|
497
506
|
after do
|
|
@@ -105,6 +105,7 @@ describe Paperclip::Storage::S3 do
|
|
|
105
105
|
url: ":s3_path_url"
|
|
106
106
|
@dummy = Dummy.new
|
|
107
107
|
@dummy.avatar = stringy_file
|
|
108
|
+
@dummy.stubs(:new_record?).returns(false)
|
|
108
109
|
end
|
|
109
110
|
|
|
110
111
|
it "returns a url based on an S3 path" do
|
|
@@ -145,6 +146,7 @@ describe Paperclip::Storage::S3 do
|
|
|
145
146
|
path: ":attachment/:basename:dotextension"
|
|
146
147
|
@dummy = Dummy.new
|
|
147
148
|
@dummy.avatar = stringy_file
|
|
149
|
+
@dummy.stubs(:new_record?).returns(false)
|
|
148
150
|
end
|
|
149
151
|
|
|
150
152
|
it "returns a url based on an S3 path" do
|
|
@@ -161,6 +163,7 @@ describe Paperclip::Storage::S3 do
|
|
|
161
163
|
path: ":attachment/:basename:dotextension"
|
|
162
164
|
@dummy = Dummy.new
|
|
163
165
|
@dummy.avatar = stringy_file
|
|
166
|
+
@dummy.stubs(:new_record?).returns(false)
|
|
164
167
|
end
|
|
165
168
|
|
|
166
169
|
it "returns a protocol-relative URL" do
|
|
@@ -177,6 +180,7 @@ describe Paperclip::Storage::S3 do
|
|
|
177
180
|
path: ":attachment/:basename:dotextension"
|
|
178
181
|
@dummy = Dummy.new
|
|
179
182
|
@dummy.avatar = stringy_file
|
|
183
|
+
@dummy.stubs(:new_record?).returns(false)
|
|
180
184
|
end
|
|
181
185
|
|
|
182
186
|
it "returns a url based on an S3 path" do
|
|
@@ -193,6 +197,7 @@ describe Paperclip::Storage::S3 do
|
|
|
193
197
|
path: ":attachment/:basename:dotextension"
|
|
194
198
|
@dummy = Dummy.new
|
|
195
199
|
@dummy.avatar = stringy_file
|
|
200
|
+
@dummy.stubs(:new_record?).returns(false)
|
|
196
201
|
end
|
|
197
202
|
|
|
198
203
|
it "returns a url based on an S3 path" do
|
|
@@ -236,6 +241,7 @@ describe Paperclip::Storage::S3 do
|
|
|
236
241
|
s3_host_name: "s3-ap-northeast-1.amazonaws.com"
|
|
237
242
|
@dummy = Dummy.new
|
|
238
243
|
@dummy.avatar = stringy_file
|
|
244
|
+
@dummy.stubs(:new_record?).returns(false)
|
|
239
245
|
end
|
|
240
246
|
|
|
241
247
|
it "returns a url based on an :s3_host_name path" do
|
|
@@ -259,6 +265,7 @@ describe Paperclip::Storage::S3 do
|
|
|
259
265
|
attr_accessor :value
|
|
260
266
|
end
|
|
261
267
|
@dummy.avatar = stringy_file
|
|
268
|
+
@dummy.stubs(:new_record?).returns(false)
|
|
262
269
|
end
|
|
263
270
|
|
|
264
271
|
it "uses s3_host_name as a proc if available" do
|
|
@@ -281,6 +288,7 @@ describe Paperclip::Storage::S3 do
|
|
|
281
288
|
File.open(fixture_file('5k.png'), 'rb') do |file|
|
|
282
289
|
@dummy = Dummy.new
|
|
283
290
|
@dummy.avatar = file
|
|
291
|
+
@dummy.stubs(:new_record?).returns(false)
|
|
284
292
|
end
|
|
285
293
|
end
|
|
286
294
|
|
|
@@ -342,18 +350,19 @@ describe Paperclip::Storage::S3 do
|
|
|
342
350
|
|
|
343
351
|
context "An attachment that uses S3 for storage and has spaces in file name" do
|
|
344
352
|
before do
|
|
345
|
-
rebuild_model
|
|
353
|
+
rebuild_model(
|
|
354
|
+
styles: { large: ["500x500#", :jpg] },
|
|
346
355
|
storage: :s3,
|
|
347
356
|
bucket: "bucket",
|
|
348
|
-
s3_credentials: {
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
}
|
|
357
|
+
s3_credentials: { "access_key_id" => "12345",
|
|
358
|
+
"secret_access_key" => "54321" }
|
|
359
|
+
)
|
|
352
360
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
361
|
+
File.open(fixture_file("spaced file.png"), "rb") do |file|
|
|
362
|
+
@dummy = Dummy.new
|
|
363
|
+
@dummy.avatar = file
|
|
364
|
+
@dummy.stubs(:new_record?).returns(false)
|
|
365
|
+
end
|
|
357
366
|
end
|
|
358
367
|
|
|
359
368
|
it "returns a replaced version for path" do
|
|
@@ -375,16 +384,17 @@ describe Paperclip::Storage::S3 do
|
|
|
375
384
|
'secret_access_key' => "54321"
|
|
376
385
|
}
|
|
377
386
|
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
end
|
|
387
|
+
stringio = stringy_file
|
|
388
|
+
class << stringio
|
|
389
|
+
def original_filename
|
|
390
|
+
"question?mark.png"
|
|
383
391
|
end
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
392
|
+
end
|
|
393
|
+
file = Paperclip.io_adapters.for(stringio)
|
|
394
|
+
@dummy = Dummy.new
|
|
395
|
+
@dummy.avatar = file
|
|
396
|
+
@dummy.save
|
|
397
|
+
@dummy.stubs(:new_record?).returns(false)
|
|
388
398
|
end
|
|
389
399
|
|
|
390
400
|
it "returns a replaced version for path" do
|
|
@@ -405,6 +415,7 @@ describe Paperclip::Storage::S3 do
|
|
|
405
415
|
url: ":s3_domain_url"
|
|
406
416
|
@dummy = Dummy.new
|
|
407
417
|
@dummy.avatar = stringy_file
|
|
418
|
+
@dummy.stubs(:new_record?).returns(false)
|
|
408
419
|
end
|
|
409
420
|
|
|
410
421
|
it "returns a url based on an S3 subdomain" do
|
|
@@ -414,16 +425,20 @@ describe Paperclip::Storage::S3 do
|
|
|
414
425
|
|
|
415
426
|
context "" do
|
|
416
427
|
before do
|
|
417
|
-
rebuild_model
|
|
428
|
+
rebuild_model(
|
|
429
|
+
storage: :s3,
|
|
418
430
|
s3_credentials: {
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
431
|
+
production: { bucket: "prod_bucket" },
|
|
432
|
+
development: { bucket: "dev_bucket" }
|
|
433
|
+
},
|
|
434
|
+
bucket: "bucket",
|
|
435
|
+
s3_host_alias: "something.something.com",
|
|
436
|
+
path: ":attachment/:basename:dotextension",
|
|
437
|
+
url: ":s3_alias_url"
|
|
438
|
+
)
|
|
425
439
|
@dummy = Dummy.new
|
|
426
440
|
@dummy.avatar = stringy_file
|
|
441
|
+
@dummy.stubs(:new_record?).returns(false)
|
|
427
442
|
end
|
|
428
443
|
|
|
429
444
|
it "returns a url based on the host_alias" do
|
|
@@ -447,6 +462,7 @@ describe Paperclip::Storage::S3 do
|
|
|
447
462
|
end
|
|
448
463
|
@dummy = Dummy.new
|
|
449
464
|
@dummy.avatar = stringy_file
|
|
465
|
+
@dummy.stubs(:new_record?).returns(false)
|
|
450
466
|
end
|
|
451
467
|
|
|
452
468
|
it "returns a url based on the host_alias" do
|
|
@@ -469,6 +485,7 @@ describe Paperclip::Storage::S3 do
|
|
|
469
485
|
url: ":asset_host"
|
|
470
486
|
@dummy = Dummy.new
|
|
471
487
|
@dummy.avatar = stringy_file
|
|
488
|
+
@dummy.stubs(:new_record?).returns(false)
|
|
472
489
|
end
|
|
473
490
|
|
|
474
491
|
it "returns a relative URL for Rails to calculate assets host" do
|
|
@@ -684,6 +701,7 @@ describe Paperclip::Storage::S3 do
|
|
|
684
701
|
@file = File.new(fixture_file('5k.png'), 'rb')
|
|
685
702
|
@dummy = Dummy.new
|
|
686
703
|
@dummy.avatar = @file
|
|
704
|
+
@dummy.stubs(:new_record?).returns(false)
|
|
687
705
|
end
|
|
688
706
|
|
|
689
707
|
after { @file.close }
|
|
@@ -481,4 +481,20 @@ describe Paperclip::Thumbnail do
|
|
|
481
481
|
end
|
|
482
482
|
end
|
|
483
483
|
end
|
|
484
|
+
|
|
485
|
+
context "with a really long file name" do
|
|
486
|
+
before do
|
|
487
|
+
tempfile = Tempfile.new("f")
|
|
488
|
+
tempfile_additional_chars = tempfile.path.split("/")[-1].length + 15
|
|
489
|
+
image_file = File.new(fixture_file("5k.png"), "rb")
|
|
490
|
+
@file = Tempfile.new("f" * (255 - tempfile_additional_chars))
|
|
491
|
+
@file.write(image_file.read)
|
|
492
|
+
@file.rewind
|
|
493
|
+
end
|
|
494
|
+
|
|
495
|
+
it "does not throw Errno::ENAMETOOLONG" do
|
|
496
|
+
thumb = Paperclip::Thumbnail.new(@file, geometry: "50x50", format: :gif)
|
|
497
|
+
expect { thumb.make }.to_not raise_error
|
|
498
|
+
end
|
|
499
|
+
end
|
|
484
500
|
end
|
|
@@ -43,7 +43,7 @@ describe Paperclip::UrlGenerator do
|
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
it "executes the method named by the symbol as the default URL when no file is assigned" do
|
|
46
|
-
mock_model =
|
|
46
|
+
mock_model = FakeModel.new
|
|
47
47
|
mock_attachment = MockAttachment.new(model: mock_model)
|
|
48
48
|
mock_interpolator = MockInterpolator.new
|
|
49
49
|
default_url = :to_s
|
|
@@ -30,7 +30,7 @@ describe Paperclip::Validators::MediaTypeSpoofDetectionValidator do
|
|
|
30
30
|
Paperclip::MediaTypeSpoofDetector.stubs(:using).returns(detector)
|
|
31
31
|
@validator.validate(@dummy)
|
|
32
32
|
|
|
33
|
-
assert_equal "
|
|
33
|
+
assert_equal I18n.t("errors.messages.spoofed_media_type"), @dummy.errors[:avatar].first
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
it "runs when attachment is dirty" do
|