paperclip 5.0.0.beta2 → 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 +14 -15
- data/Appraisals +3 -23
- data/CONTRIBUTING.md +10 -4
- data/Gemfile +1 -0
- data/NEWS +78 -2
- data/README.md +175 -81
- data/Rakefile +1 -1
- data/UPGRADING +1 -1
- data/features/basic_integration.feature +2 -2
- data/features/step_definitions/attachment_steps.rb +6 -6
- data/features/step_definitions/rails_steps.rb +29 -22
- data/features/step_definitions/s3_steps.rb +1 -1
- 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.awsv2.0.gemfile → 4.2.gemfile} +1 -1
- data/gemfiles/{5.0.awsv2.1.gemfile → 5.0.gemfile} +2 -2
- 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 -10
- data/lib/paperclip/attachment.rb +16 -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/helpers.rb +15 -12
- 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 +41 -19
- 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/storage/filesystem.rb +13 -2
- data/lib/paperclip/storage/fog.rb +12 -7
- data/lib/paperclip/storage/s3.rb +46 -19
- 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/version.rb +3 -1
- data/lib/tasks/paperclip.rake +18 -4
- data/paperclip.gemspec +4 -5
- data/spec/paperclip/attachment_processing_spec.rb +2 -4
- data/spec/paperclip/attachment_spec.rb +40 -9
- 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/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 +26 -6
- 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 +77 -7
- data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +10 -0
- data/spec/paperclip/media_type_spoof_detector_spec.rb +27 -3
- data/spec/paperclip/paperclip_spec.rb +13 -13
- data/spec/paperclip/processor_spec.rb +4 -4
- data/spec/paperclip/storage/fog_spec.rb +28 -0
- data/spec/paperclip/storage/s3_live_spec.rb +12 -10
- data/spec/paperclip/storage/s3_spec.rb +150 -39
- 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_spec.rb +3 -2
- data/spec/spec_helper.rb +3 -1
- data/spec/support/assertions.rb +5 -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
- metadata +37 -36
- data/gemfiles/4.2.awsv2.1.gemfile +0 -17
- data/gemfiles/4.2.awsv2.gemfile +0 -20
- data/gemfiles/5.0.awsv2.0.gemfile +0 -17
- data/gemfiles/5.0.awsv2.gemfile +0 -25
data/lib/tasks/paperclip.rake
CHANGED
@@ -18,7 +18,7 @@ module Paperclip
|
|
18
18
|
raise "Class #{klass.name} has no attachments specified"
|
19
19
|
end
|
20
20
|
|
21
|
-
if
|
21
|
+
if name.present? && attachment_names.map(&:to_s).include?(name.to_s)
|
22
22
|
[ name ]
|
23
23
|
else
|
24
24
|
attachment_names
|
@@ -46,7 +46,7 @@ namespace :paperclip do
|
|
46
46
|
attachment = instance.send(name)
|
47
47
|
begin
|
48
48
|
attachment.reprocess!(*styles)
|
49
|
-
rescue
|
49
|
+
rescue StandardError => e
|
50
50
|
Paperclip::Task.log_error("exception while processing #{klass} ID #{instance.id}:")
|
51
51
|
Paperclip::Task.log_error(" " + e.message + "\n")
|
52
52
|
end
|
@@ -64,7 +64,8 @@ namespace :paperclip do
|
|
64
64
|
names = Paperclip::Task.obtain_attachments(klass)
|
65
65
|
names.each do |name|
|
66
66
|
Paperclip.each_instance_with_attachment(klass, name) do |instance|
|
67
|
-
|
67
|
+
attachment = instance.send(name)
|
68
|
+
if file = Paperclip.io_adapters.for(attachment, attachment.options[:adapter_options])
|
68
69
|
instance.send("#{name}_file_name=", instance.send("#{name}_file_name").strip)
|
69
70
|
instance.send("#{name}_content_type=", file.content_type.to_s.strip)
|
70
71
|
instance.send("#{name}_file_size=", file.size) if instance.respond_to?("#{name}_file_size")
|
@@ -90,6 +91,19 @@ namespace :paperclip do
|
|
90
91
|
end
|
91
92
|
Paperclip.save_current_attachments_styles!
|
92
93
|
end
|
94
|
+
|
95
|
+
desc "Regenerates fingerprints for a given CLASS (and optional ATTACHMENT). Useful when changing digest."
|
96
|
+
task :fingerprints => :environment do
|
97
|
+
klass = Paperclip::Task.obtain_class
|
98
|
+
names = Paperclip::Task.obtain_attachments(klass)
|
99
|
+
names.each do |name|
|
100
|
+
Paperclip.each_instance_with_attachment(klass, name) do |instance|
|
101
|
+
attachment = instance.send(name)
|
102
|
+
attachment.assign(attachment)
|
103
|
+
instance.save(:validate => false)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
93
107
|
end
|
94
108
|
|
95
109
|
desc "Cleans out invalid attachments. Useful after you've added new validations."
|
@@ -109,7 +123,7 @@ namespace :paperclip do
|
|
109
123
|
end
|
110
124
|
end
|
111
125
|
|
112
|
-
|
126
|
+
desc "find missing attachments. Useful to know which attachments are broken"
|
113
127
|
task :find_broken_attachments => :environment do
|
114
128
|
klass = Paperclip::Task.obtain_class
|
115
129
|
names = Paperclip::Task.obtain_attachments(klass)
|
data/paperclip.gemspec
CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
|
|
26
26
|
|
27
27
|
s.add_dependency('activemodel', '>= 4.2.0')
|
28
28
|
s.add_dependency('activesupport', '>= 4.2.0')
|
29
|
-
s.add_dependency('
|
29
|
+
s.add_dependency('terrapin', '~> 0.6.0')
|
30
30
|
s.add_dependency('mime-types')
|
31
31
|
s.add_dependency('mimemagic', '~> 0.3.0')
|
32
32
|
|
@@ -35,12 +35,12 @@ Gem::Specification.new do |s|
|
|
35
35
|
s.add_development_dependency('rspec', '~> 3.0')
|
36
36
|
s.add_development_dependency('appraisal')
|
37
37
|
s.add_development_dependency('mocha')
|
38
|
-
s.add_development_dependency('aws-sdk', '>= 2.0
|
38
|
+
s.add_development_dependency('aws-sdk', '>= 2.3.0', '< 3.0')
|
39
39
|
s.add_development_dependency('bourne')
|
40
|
-
s.add_development_dependency('cucumber'
|
40
|
+
s.add_development_dependency('cucumber-rails')
|
41
|
+
s.add_development_dependency('cucumber-expressions', '4.0.3') # TODO: investigate failures on 4.0.4
|
41
42
|
s.add_development_dependency('aruba', '~> 0.9.0')
|
42
43
|
s.add_development_dependency('nokogiri')
|
43
|
-
# Ruby version < 1.9.3 can't install capybara > 2.0.3.
|
44
44
|
s.add_development_dependency('capybara')
|
45
45
|
s.add_development_dependency('bundler')
|
46
46
|
s.add_development_dependency('fog-aws')
|
@@ -49,7 +49,6 @@ Gem::Specification.new do |s|
|
|
49
49
|
s.add_development_dependency('rake')
|
50
50
|
s.add_development_dependency('fakeweb')
|
51
51
|
s.add_development_dependency('railties')
|
52
|
-
s.add_development_dependency('actionmailer', '>= 4.2.0')
|
53
52
|
s.add_development_dependency('generator_spec')
|
54
53
|
s.add_development_dependency('timecop')
|
55
54
|
end
|
@@ -2,11 +2,9 @@
|
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
4
|
describe 'Attachment Processing' do
|
5
|
-
|
6
|
-
before do
|
7
|
-
rebuild_class
|
8
|
-
end
|
5
|
+
before { rebuild_class }
|
9
6
|
|
7
|
+
context 'using validates_attachment_content_type' do
|
10
8
|
it 'processes attachments given a valid assignment' do
|
11
9
|
file = File.new(fixture_file("5k.png"))
|
12
10
|
Dummy.validates_attachment_content_type :avatar, content_type: "image/png"
|
@@ -500,6 +500,7 @@ describe Paperclip::Attachment do
|
|
500
500
|
@attachment.expects(:post_process).with(:thumb)
|
501
501
|
@attachment.expects(:post_process).with(:large).never
|
502
502
|
@attachment.assign(@file)
|
503
|
+
@attachment.save
|
503
504
|
end
|
504
505
|
end
|
505
506
|
|
@@ -1121,7 +1122,7 @@ describe Paperclip::Attachment do
|
|
1121
1122
|
context "with a file assigned but not saved yet" do
|
1122
1123
|
it "clears out any attached files" do
|
1123
1124
|
@attachment.assign(@file)
|
1124
|
-
assert
|
1125
|
+
assert @attachment.queued_for_write.present?
|
1125
1126
|
@attachment.clear
|
1126
1127
|
assert @attachment.queued_for_write.blank?
|
1127
1128
|
end
|
@@ -1433,16 +1434,46 @@ describe Paperclip::Attachment do
|
|
1433
1434
|
assert_nothing_raised { @dummy.avatar = @file }
|
1434
1435
|
end
|
1435
1436
|
|
1436
|
-
|
1437
|
-
|
1438
|
-
|
1437
|
+
context "with explicitly set digest" do
|
1438
|
+
before do
|
1439
|
+
rebuild_class adapter_options: { hash_digest: Digest::SHA256 }
|
1440
|
+
@dummy = Dummy.new
|
1441
|
+
end
|
1442
|
+
|
1443
|
+
it "returns the right value when sent #avatar_fingerprint" do
|
1444
|
+
@dummy.avatar = @file
|
1445
|
+
assert_equal "734016d801a497f5579cdd4ef2ae1d020088c1db754dc434482d76dd5486520a",
|
1446
|
+
@dummy.avatar_fingerprint
|
1447
|
+
end
|
1448
|
+
|
1449
|
+
it "returns the right value when saved, reloaded, and sent #avatar_fingerprint" do
|
1450
|
+
@dummy.avatar = @file
|
1451
|
+
@dummy.save
|
1452
|
+
@dummy = Dummy.find(@dummy.id)
|
1453
|
+
assert_equal "734016d801a497f5579cdd4ef2ae1d020088c1db754dc434482d76dd5486520a",
|
1454
|
+
@dummy.avatar_fingerprint
|
1455
|
+
end
|
1439
1456
|
end
|
1440
1457
|
|
1441
|
-
|
1442
|
-
|
1443
|
-
|
1444
|
-
|
1445
|
-
|
1458
|
+
context "with the default digest" do
|
1459
|
+
before do
|
1460
|
+
rebuild_class # MD5 is the default
|
1461
|
+
@dummy = Dummy.new
|
1462
|
+
end
|
1463
|
+
|
1464
|
+
it "returns the right value when sent #avatar_fingerprint" do
|
1465
|
+
@dummy.avatar = @file
|
1466
|
+
assert_equal "aec488126c3b33c08a10c3fa303acf27",
|
1467
|
+
@dummy.avatar_fingerprint
|
1468
|
+
end
|
1469
|
+
|
1470
|
+
it "returns the right value when saved, reloaded, and sent #avatar_fingerprint" do
|
1471
|
+
@dummy.avatar = @file
|
1472
|
+
@dummy.save
|
1473
|
+
@dummy = Dummy.find(@dummy.id)
|
1474
|
+
assert_equal "aec488126c3b33c08a10c3fa303acf27",
|
1475
|
+
@dummy.avatar_fingerprint
|
1476
|
+
end
|
1446
1477
|
end
|
1447
1478
|
end
|
1448
1479
|
end
|
@@ -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
|
@@ -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
|
@@ -1,13 +1,23 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Paperclip::HttpUrlProxyAdapter do
|
4
|
+
before do
|
5
|
+
@open_return = StringIO.new("xxx")
|
6
|
+
@open_return.stubs(:content_type).returns("image/png")
|
7
|
+
@open_return.stubs(:meta).returns({})
|
8
|
+
Paperclip::HttpUrlProxyAdapter.any_instance.
|
9
|
+
stubs(:download_content).returns(@open_return)
|
10
|
+
Paperclip::HttpUrlProxyAdapter.register
|
11
|
+
end
|
12
|
+
|
13
|
+
after do
|
14
|
+
Paperclip.io_adapters.unregister(described_class)
|
15
|
+
end
|
16
|
+
|
4
17
|
context "a new instance" do
|
5
18
|
before do
|
6
|
-
@open_return = StringIO.new("xxx")
|
7
|
-
@open_return.stubs(:content_type).returns("image/png")
|
8
|
-
Paperclip::HttpUrlProxyAdapter.any_instance.stubs(:download_content).returns(@open_return)
|
9
19
|
@url = "http://thoughtbot.com/images/thoughtbot-logo.png"
|
10
|
-
@subject = Paperclip.io_adapters.for(@url)
|
20
|
+
@subject = Paperclip.io_adapters.for(@url, hash_digest: Digest::MD5)
|
11
21
|
end
|
12
22
|
|
13
23
|
after do
|
@@ -60,7 +70,6 @@ describe Paperclip::HttpUrlProxyAdapter do
|
|
60
70
|
|
61
71
|
context "a url with query params" do
|
62
72
|
before do
|
63
|
-
Paperclip::HttpUrlProxyAdapter.any_instance.stubs(:download_content).returns(StringIO.new("x"))
|
64
73
|
@url = "https://github.com/thoughtbot/paperclip?file=test"
|
65
74
|
@subject = Paperclip.io_adapters.for(@url)
|
66
75
|
end
|
@@ -76,7 +85,6 @@ describe Paperclip::HttpUrlProxyAdapter do
|
|
76
85
|
|
77
86
|
context "a url with restricted characters in the filename" do
|
78
87
|
before do
|
79
|
-
Paperclip::HttpUrlProxyAdapter.any_instance.stubs(:download_content).returns(StringIO.new("x"))
|
80
88
|
@url = "https://github.com/thoughtbot/paper:clip.jpg"
|
81
89
|
@subject = Paperclip.io_adapters.for(@url)
|
82
90
|
end
|
@@ -98,4 +106,16 @@ describe Paperclip::HttpUrlProxyAdapter do
|
|
98
106
|
end
|
99
107
|
end
|
100
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
|
101
121
|
end
|