paperclip 4.3.7 → 6.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.codeclimate.yml +17 -0
- data/.github/issue_template.md +3 -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/MIGRATING-ES.md +317 -0
- data/MIGRATING.md +375 -0
- data/NEWS +126 -31
- data/README.md +264 -156
- 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 +14 -14
- 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 +14 -12
- data/lib/paperclip/attachment.rb +44 -20
- 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/filename_cleaner.rb +0 -1
- data/lib/paperclip/geometry_detector_factory.rb +3 -3
- 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 +7 -2
- data/lib/paperclip/io_adapters/abstract_adapter.rb +31 -4
- data/lib/paperclip/io_adapters/attachment_adapter.rb +17 -6
- 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 +8 -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 +22 -17
- data/lib/paperclip/logger.rb +1 -1
- data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +4 -4
- data/lib/paperclip/media_type_spoof_detector.rb +11 -7
- data/lib/paperclip/processor.rb +15 -6
- data/lib/paperclip/schema.rb +3 -9
- data/lib/paperclip/storage/filesystem.rb +13 -2
- data/lib/paperclip/storage/fog.rb +21 -14
- data/lib/paperclip/storage/s3.rb +81 -61
- data/lib/paperclip/style.rb +0 -1
- data/lib/paperclip/thumbnail.rb +22 -9
- 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/validators/media_type_spoof_detection_validator.rb +4 -0
- 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 -5
- data/spec/paperclip/attachment_registry_spec.rb +28 -0
- data/spec/paperclip/attachment_spec.rb +89 -20
- 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/filename_cleaner_spec.rb +0 -1
- data/spec/paperclip/has_attached_file_spec.rb +24 -8
- data/spec/paperclip/integration_spec.rb +42 -5
- data/spec/paperclip/interpolations_spec.rb +9 -0
- data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +104 -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 +47 -13
- 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 +104 -11
- data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +10 -0
- data/spec/paperclip/matchers/validate_attachment_size_matcher_spec.rb +1 -1
- data/spec/paperclip/media_type_spoof_detector_spec.rb +41 -0
- data/spec/paperclip/paperclip_spec.rb +15 -45
- data/spec/paperclip/processor_spec.rb +4 -4
- data/spec/paperclip/schema_spec.rb +46 -46
- 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 +359 -192
- data/spec/paperclip/style_spec.rb +0 -1
- data/spec/paperclip/tempfile_spec.rb +35 -0
- data/spec/paperclip/thumbnail_spec.rb +43 -38
- data/spec/paperclip/url_generator_spec.rb +54 -44
- data/spec/paperclip/validators/attachment_size_validator_spec.rb +26 -20
- data/spec/paperclip/validators_spec.rb +5 -5
- data/spec/spec_helper.rb +5 -2
- data/spec/support/assertions.rb +12 -1
- data/spec/support/mock_attachment.rb +2 -0
- data/spec/support/mock_url_generator_builder.rb +2 -2
- data/spec/support/model_reconstruction.rb +11 -3
- data/spec/support/reporting.rb +11 -0
- metadata +64 -61
- 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
@@ -41,7 +41,7 @@ describe Paperclip::ContentTypeDetector do
|
|
41
41
|
end
|
42
42
|
|
43
43
|
it 'returns a sensible default when the file command is missing' do
|
44
|
-
Paperclip.stubs(:run).raises(
|
44
|
+
Paperclip.stubs(:run).raises(Terrapin::CommandLineError.new)
|
45
45
|
@filename = "/path/to/something"
|
46
46
|
assert_equal "application/octet-stream", Paperclip::ContentTypeDetector.new(@filename).detect
|
47
47
|
end
|
@@ -12,7 +12,7 @@ describe Paperclip::FileCommandContentTypeDetector do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'returns a sensible default when the file command is missing' do
|
15
|
-
Paperclip.stubs(:run).raises(
|
15
|
+
Paperclip.stubs(:run).raises(Terrapin::CommandLineError.new)
|
16
16
|
@filename = "/path/to/something"
|
17
17
|
assert_equal "application/octet-stream",
|
18
18
|
Paperclip::FileCommandContentTypeDetector.new(@filename).detect
|
@@ -23,4 +23,18 @@ describe Paperclip::FileCommandContentTypeDetector do
|
|
23
23
|
assert_equal "application/octet-stream",
|
24
24
|
Paperclip::FileCommandContentTypeDetector.new("windows").detect
|
25
25
|
end
|
26
|
+
|
27
|
+
context "#type_from_file_command" do
|
28
|
+
let(:detector) { Paperclip::FileCommandContentTypeDetector.new("html") }
|
29
|
+
|
30
|
+
it "does work with the output of old versions of file" do
|
31
|
+
Paperclip.stubs(:run).returns("text/html charset=us-ascii")
|
32
|
+
expect(detector.detect).to eq("text/html")
|
33
|
+
end
|
34
|
+
|
35
|
+
it "does work with the output of new versions of file" do
|
36
|
+
Paperclip.stubs(:run).returns("text/html; charset=us-ascii")
|
37
|
+
expect(detector.detect).to eq("text/html")
|
38
|
+
end
|
39
|
+
end
|
26
40
|
end
|
@@ -38,6 +38,15 @@ describe Paperclip::HasAttachedFile do
|
|
38
38
|
assert_adding_attachment('avatar').defines_callback('after_commit')
|
39
39
|
end
|
40
40
|
|
41
|
+
context 'when the class does not allow after_commit callbacks' do
|
42
|
+
it 'defines an after_destroy callback' do
|
43
|
+
assert_adding_attachment(
|
44
|
+
'avatar',
|
45
|
+
unstub_methods: [:after_commit]
|
46
|
+
).defines_callback('after_destroy')
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
41
50
|
it 'defines the Paperclip-specific callbacks' do
|
42
51
|
assert_adding_attachment('avatar').defines_callback('define_paperclip_callbacks')
|
43
52
|
end
|
@@ -53,20 +62,26 @@ describe Paperclip::HasAttachedFile do
|
|
53
62
|
|
54
63
|
private
|
55
64
|
|
56
|
-
def assert_adding_attachment(attachment_name)
|
57
|
-
AttachmentAdder.new(attachment_name)
|
65
|
+
def assert_adding_attachment(attachment_name, options={})
|
66
|
+
AttachmentAdder.new(attachment_name, options)
|
58
67
|
end
|
59
68
|
|
60
69
|
class AttachmentAdder
|
61
70
|
include Mocha::API
|
62
71
|
include RSpec::Matchers
|
63
72
|
|
64
|
-
def initialize(attachment_name)
|
73
|
+
def initialize(attachment_name, options = {})
|
65
74
|
@attachment_name = attachment_name
|
75
|
+
@stubbed_class = stub_class
|
76
|
+
if options.present?
|
77
|
+
options[:unstub_methods].each do |method|
|
78
|
+
@stubbed_class.unstub(method)
|
79
|
+
end
|
80
|
+
end
|
66
81
|
end
|
67
82
|
|
68
83
|
def defines_method(method_name)
|
69
|
-
a_class =
|
84
|
+
a_class = @stubbed_class
|
70
85
|
|
71
86
|
Paperclip::HasAttachedFile.define_on(a_class, @attachment_name, {})
|
72
87
|
|
@@ -74,7 +89,7 @@ describe Paperclip::HasAttachedFile do
|
|
74
89
|
end
|
75
90
|
|
76
91
|
def defines_class_method(method_name)
|
77
|
-
a_class =
|
92
|
+
a_class = @stubbed_class
|
78
93
|
a_class.class.stubs(:define_method)
|
79
94
|
|
80
95
|
Paperclip::HasAttachedFile.define_on(a_class, @attachment_name, {})
|
@@ -83,7 +98,7 @@ describe Paperclip::HasAttachedFile do
|
|
83
98
|
end
|
84
99
|
|
85
100
|
def defines_validation
|
86
|
-
a_class =
|
101
|
+
a_class = @stubbed_class
|
87
102
|
|
88
103
|
Paperclip::HasAttachedFile.define_on(a_class, @attachment_name, {})
|
89
104
|
|
@@ -91,7 +106,7 @@ describe Paperclip::HasAttachedFile do
|
|
91
106
|
end
|
92
107
|
|
93
108
|
def registers_attachment
|
94
|
-
a_class =
|
109
|
+
a_class = @stubbed_class
|
95
110
|
Paperclip::AttachmentRegistry.stubs(:register)
|
96
111
|
|
97
112
|
Paperclip::HasAttachedFile.define_on(a_class, @attachment_name, {size: 1})
|
@@ -100,7 +115,7 @@ describe Paperclip::HasAttachedFile do
|
|
100
115
|
end
|
101
116
|
|
102
117
|
def defines_callback(callback_name)
|
103
|
-
a_class =
|
118
|
+
a_class = @stubbed_class
|
104
119
|
|
105
120
|
Paperclip::HasAttachedFile.define_on(a_class, @attachment_name, {})
|
106
121
|
|
@@ -132,6 +147,7 @@ describe Paperclip::HasAttachedFile do
|
|
132
147
|
after_save: nil,
|
133
148
|
before_destroy: nil,
|
134
149
|
after_commit: nil,
|
150
|
+
after_destroy: nil,
|
135
151
|
define_paperclip_callbacks: nil,
|
136
152
|
extend: nil,
|
137
153
|
name: 'Billy',
|
@@ -1,15 +1,33 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
require 'spec_helper'
|
3
2
|
require 'open-uri'
|
4
3
|
|
5
4
|
describe 'Paperclip' do
|
5
|
+
around do |example|
|
6
|
+
files_before = ObjectSpace.each_object(Tempfile).select do |file|
|
7
|
+
file.path && File.file?(file.path)
|
8
|
+
end
|
9
|
+
|
10
|
+
example.run
|
11
|
+
|
12
|
+
files_after = ObjectSpace.each_object(Tempfile).select do |file|
|
13
|
+
file.path && File.file?(file.path)
|
14
|
+
end
|
15
|
+
|
16
|
+
diff = files_after - files_before
|
17
|
+
expect(diff).to eq([]), "Leaked tempfiles: #{diff.inspect}"
|
18
|
+
end
|
19
|
+
|
6
20
|
context "Many models at once" do
|
7
21
|
before do
|
8
22
|
rebuild_model
|
9
23
|
@file = File.new(fixture_file("5k.png"), 'rb')
|
10
|
-
|
11
|
-
|
12
|
-
|
24
|
+
# Deals with `Too many open files` error
|
25
|
+
dummies = Array.new(300) { Dummy.new avatar: @file }
|
26
|
+
Dummy.import dummies
|
27
|
+
# save attachment instances to run after hooks including tempfile cleanup
|
28
|
+
# since activerecord-import does not use our usually hooked-in hooks
|
29
|
+
# (such as after_save)
|
30
|
+
dummies.each { |dummy| dummy.avatar.save }
|
13
31
|
end
|
14
32
|
|
15
33
|
after { @file.close }
|
@@ -134,6 +152,14 @@ describe 'Paperclip' do
|
|
134
152
|
end
|
135
153
|
|
136
154
|
it "allows us to selectively create each thumbnail" do
|
155
|
+
skip <<-EXPLANATION
|
156
|
+
#reprocess! calls #assign which calls Paperclip.io_adapters.for
|
157
|
+
which creates the tempfile. #assign then calls #post_process_file which
|
158
|
+
calls MediaTypeSpoofDetectionValidator#validate_each which calls
|
159
|
+
Paperclip.io_adapters.for, which creates another tempfile. That first
|
160
|
+
tempfile is the one that leaks.
|
161
|
+
EXPLANATION
|
162
|
+
|
137
163
|
assert_file_not_exists(@thumb_small_path)
|
138
164
|
assert_file_not_exists(@thumb_large_path)
|
139
165
|
|
@@ -158,7 +184,11 @@ describe 'Paperclip' do
|
|
158
184
|
assert_not_equal File.size(@file.path), @dummy.avatar.size
|
159
185
|
end
|
160
186
|
|
161
|
-
after
|
187
|
+
after do
|
188
|
+
@file.close
|
189
|
+
# save attachment instance to run after hooks (including tempfile cleanup)
|
190
|
+
@dummy.avatar.save
|
191
|
+
end
|
162
192
|
end
|
163
193
|
|
164
194
|
context "A model with attachments scoped under an id" do
|
@@ -346,6 +376,8 @@ describe 'Paperclip' do
|
|
346
376
|
it "is not ok with bad files" do
|
347
377
|
@dummy.avatar = @bad_file
|
348
378
|
assert ! @dummy.valid?
|
379
|
+
# save attachment instance to run after hooks (including tempfile cleanup)
|
380
|
+
@dummy.avatar.save
|
349
381
|
end
|
350
382
|
|
351
383
|
it "knows the difference between good files, bad files, and not files when validating" do
|
@@ -353,8 +385,13 @@ describe 'Paperclip' do
|
|
353
385
|
@d2 = Dummy.find(@dummy.id)
|
354
386
|
@d2.avatar = @file
|
355
387
|
assert @d2.valid?, @d2.errors.full_messages.inspect
|
388
|
+
# save attachment instance to run after hooks (including tempfile cleanup)
|
389
|
+
@d2.avatar.save
|
390
|
+
|
356
391
|
@d2.avatar = @bad_file
|
357
392
|
assert ! @d2.valid?
|
393
|
+
# save attachment instance to run after hooks (including tempfile cleanup)
|
394
|
+
@d2.avatar.save
|
358
395
|
end
|
359
396
|
|
360
397
|
it "is able to reload without saving and not have the file disappear" do
|
@@ -139,6 +139,15 @@ describe Paperclip::Interpolations do
|
|
139
139
|
assert_equal "000/000/023", Paperclip::Interpolations.id_partition(attachment, :style)
|
140
140
|
end
|
141
141
|
|
142
|
+
it "returns the partitioned id when the id is above 999_999_999" do
|
143
|
+
attachment = mock
|
144
|
+
attachment.expects(:id).
|
145
|
+
returns(Paperclip::Interpolations::ID_PARTITION_LIMIT)
|
146
|
+
attachment.expects(:instance).returns(attachment)
|
147
|
+
assert_equal "001/000/000/000",
|
148
|
+
Paperclip::Interpolations.id_partition(attachment, :style)
|
149
|
+
end
|
150
|
+
|
142
151
|
it "returns the partitioned id of the attachment when the id is a string" do
|
143
152
|
attachment = mock
|
144
153
|
attachment.expects(:id).returns("32fnj23oio2f")
|
@@ -9,70 +9,152 @@ 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
|
94
|
+
end
|
95
|
+
|
96
|
+
context "#copy_to_tempfile" do
|
97
|
+
around do |example|
|
98
|
+
FileUtils.module_eval do
|
99
|
+
class << self
|
100
|
+
alias paperclip_ln ln
|
101
|
+
|
102
|
+
def ln(*)
|
103
|
+
raise Errno::EXDEV
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
example.run
|
109
|
+
|
110
|
+
FileUtils.module_eval do
|
111
|
+
class << self
|
112
|
+
alias ln paperclip_ln
|
113
|
+
undef paperclip_ln
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should return a readable file even when linking fails" do
|
119
|
+
src = open(fixture_file("5k.png"), "rb")
|
120
|
+
expect(subject.send(:copy_to_tempfile, src).read).to eq src.read
|
121
|
+
end
|
70
122
|
end
|
71
123
|
|
72
124
|
context "#original_filename=" do
|
73
125
|
it "should not fail with a nil original filename" do
|
74
|
-
|
75
|
-
|
126
|
+
expect { subject.original_filename = nil }.not_to raise_error
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
context "#link_or_copy_file" do
|
131
|
+
class TestLinkOrCopyAdapter < Paperclip::AbstractAdapter
|
132
|
+
public :copy_to_tempfile, :destination
|
133
|
+
end
|
134
|
+
|
135
|
+
subject { TestLinkOrCopyAdapter.new(nil) }
|
136
|
+
let(:body) { "body" }
|
137
|
+
|
138
|
+
let(:file) do
|
139
|
+
t = Tempfile.new("destination")
|
140
|
+
t.print(body)
|
141
|
+
t.rewind
|
142
|
+
t
|
143
|
+
end
|
144
|
+
|
145
|
+
after do
|
146
|
+
file.close
|
147
|
+
file.unlink
|
148
|
+
end
|
149
|
+
|
150
|
+
it "should be able to read the file" do
|
151
|
+
expect(subject.copy_to_tempfile(file).read).to eq(body)
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should be able to reopen the file after symlink has failed" do
|
155
|
+
FileUtils.expects(:ln).raises(Errno::EXDEV)
|
156
|
+
|
157
|
+
expect(subject.copy_to_tempfile(file).read).to eq(body)
|
76
158
|
end
|
77
159
|
end
|
78
160
|
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
|