kt-paperclip 7.0.0 → 7.2.2
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 +3 -1057
- data/.rubocop.yml +1059 -1
- data/CONTRIBUTING.md +4 -5
- data/Gemfile +2 -1
- data/NEWS +11 -0
- data/README.md +3 -3
- data/gemfiles/7.0.gemfile +21 -0
- data/lib/paperclip/attachment.rb +1 -1
- data/lib/paperclip/content_type_detector.rb +8 -3
- data/lib/paperclip/geometry_detector_factory.rb +1 -1
- data/lib/paperclip/glue.rb +3 -2
- data/lib/paperclip/interpolations.rb +6 -2
- data/lib/paperclip/locales/gd.yml +20 -0
- data/lib/paperclip/media_type_spoof_detector.rb +4 -1
- data/lib/paperclip/schema.rb +2 -2
- data/lib/paperclip/storage/filesystem.rb +1 -1
- data/lib/paperclip/storage/fog.rb +1 -1
- data/lib/paperclip/storage/s3.rb +18 -4
- data/lib/paperclip/validators/attachment_file_name_validator.rb +1 -1
- data/lib/paperclip/validators/attachment_size_validator.rb +2 -1
- data/lib/paperclip/version.rb +1 -1
- data/paperclip.gemspec +1 -1
- data/spec/paperclip/attachment_spec.rb +6 -6
- data/spec/paperclip/content_type_detector_spec.rb +7 -0
- data/spec/paperclip/geometry_detector_spec.rb +9 -0
- data/spec/paperclip/geometry_spec.rb +16 -4
- data/spec/paperclip/glue_spec.rb +21 -0
- data/spec/paperclip/io_adapters/uri_adapter_spec.rb +1 -1
- data/spec/paperclip/media_type_spoof_detector_spec.rb +10 -4
- data/spec/paperclip/paperclip_missing_attachment_styles_spec.rb +1 -1
- data/spec/paperclip/paperclip_spec.rb +1 -1
- data/spec/paperclip/schema_spec.rb +18 -18
- data/spec/paperclip/storage/filesystem_spec.rb +23 -0
- data/spec/paperclip/storage/fog_spec.rb +46 -0
- data/spec/paperclip/storage/s3_spec.rb +179 -47
- data/spec/paperclip/validators_spec.rb +21 -6
- data/spec/spec_helper.rb +1 -0
- data/spec/support/fixtures/sample.xlsm +0 -0
- data/spec/support/model_reconstruction.rb +3 -3
- metadata +123 -8
data/CONTRIBUTING.md
CHANGED
@@ -10,8 +10,7 @@ Here's a quick guide for contributing:
|
|
10
10
|
|
11
11
|
1. Fork the repo.
|
12
12
|
|
13
|
-
1. Make sure you have ImageMagick and Ghostscript installed. See [this section]
|
14
|
-
(./README.md#image-processor) of the README.
|
13
|
+
1. Make sure you have ImageMagick and Ghostscript installed. See [this section](./README.md#image-processor) of the README.
|
15
14
|
|
16
15
|
1. Run the tests. We only take pull requests with passing tests, and it's great
|
17
16
|
to know that you have a clean slate: `bundle && bundle exec rake`
|
@@ -78,9 +77,9 @@ Syntax
|
|
78
77
|
|
79
78
|
* Two spaces, no tabs.
|
80
79
|
* No trailing whitespace. Blank lines should not have any space.
|
81
|
-
* Prefer
|
82
|
-
* MyClass.my_method(my_arg)
|
83
|
-
* a = b
|
80
|
+
* Prefer `&&` instead of `and` ; prefer `||` instead of `or`.
|
81
|
+
* Use `MyClass.my_method(my_arg)` instead of `MyClass.my_method( my_arg )` or `MyClass.my_method my_arg`.
|
82
|
+
* `a = b` rather than `a=b` .
|
84
83
|
* Follow the conventions you see used in the source already.
|
85
84
|
|
86
85
|
And in case we didn't emphasize it enough: we love tests!
|
data/Gemfile
CHANGED
@@ -12,7 +12,8 @@ group :development, :test do
|
|
12
12
|
gem "builder"
|
13
13
|
gem "listen", "~> 3.0.8"
|
14
14
|
gem "rspec"
|
15
|
-
|
15
|
+
# Hound only supports certain versions of Rubocop -- 1.22.1 is currently the most recent one supported.
|
16
|
+
gem "rubocop", "1.22.1", require: false
|
16
17
|
gem "rubocop-rails"
|
17
18
|
gem "sprockets", "3.7.2"
|
18
19
|
end
|
data/NEWS
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
[UNRELEASED]
|
2
|
+
|
3
|
+
7.2.1 (2023-09-09)
|
4
|
+
* Improvement: Support file extension names both as symbols and strings for :content_type_mappings
|
5
|
+
|
6
|
+
7.2.0 (2023-05-30)
|
7
|
+
* Paperclip schema statements are consistent with ActiveRecord::Migration::Compatibility versioning. Old migrations containing Paperclip schema statements perform the same schema changes both before and after an ActiveRecord version upgrade.
|
8
|
+
|
9
|
+
7.0.1 (2021-10-06)
|
10
|
+
* Issue file delete only once per unique style when nullifying attachment or destroying an object. Avoids triggering a rate limit error on Google Cloud Storage.
|
11
|
+
|
1
12
|
7.0.0 (2021-05-28)
|
2
13
|
* Replace `mimemagic` gem with `marcel` due to licensing issues. See https://github.com/kreeti/kt-paperclip/pull/54 for details and limitations
|
3
14
|
|
data/README.md
CHANGED
@@ -592,9 +592,9 @@ Storage
|
|
592
592
|
|
593
593
|
Paperclip ships with 3 storage adapters:
|
594
594
|
|
595
|
-
* File Storage
|
596
|
-
* S3 Storage (via `aws-sdk-s3`)
|
597
|
-
* Fog Storage
|
595
|
+
* File Storage (`storage: :filesystem`)
|
596
|
+
* S3 Storage (via `aws-sdk-s3`) (`storage: :s3`)
|
597
|
+
* Fog Storage (`storage: :fog`)
|
598
598
|
|
599
599
|
If you would like to use Paperclip with another storage, you can install these
|
600
600
|
gems along side with Paperclip:
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "pry"
|
6
|
+
gem "sqlite3", "~> 1.4", platforms: :ruby
|
7
|
+
gem "aruba", "~> 1.0", ">= 1.0.4"
|
8
|
+
gem "rails", "~> 7.0.0"
|
9
|
+
|
10
|
+
group :development, :test do
|
11
|
+
gem "activerecord-import"
|
12
|
+
gem "bootsnap", require: false
|
13
|
+
gem "builder"
|
14
|
+
gem "listen", "~> 3.0.8"
|
15
|
+
gem "rspec"
|
16
|
+
gem "rubocop", require: false
|
17
|
+
gem "rubocop-rails"
|
18
|
+
gem "sprockets", "3.7.2"
|
19
|
+
end
|
20
|
+
|
21
|
+
gemspec path: "../"
|
data/lib/paperclip/attachment.rb
CHANGED
@@ -38,7 +38,7 @@ module Paperclip
|
|
38
38
|
end
|
39
39
|
|
40
40
|
attr_reader :name, :instance, :default_style, :convert_options, :queued_for_write, :whiny,
|
41
|
-
:options, :interpolator, :source_file_options
|
41
|
+
:options, :interpolator, :source_file_options, :queued_for_delete
|
42
42
|
attr_accessor :post_processing
|
43
43
|
|
44
44
|
# Creates an Attachment object. +name+ is the name of the attachment,
|
@@ -67,9 +67,14 @@ module Paperclip
|
|
67
67
|
end
|
68
68
|
|
69
69
|
def type_from_marcel
|
70
|
-
@type_from_marcel
|
71
|
-
|
72
|
-
|
70
|
+
return @type_from_marcel if defined? @type_from_marcel
|
71
|
+
|
72
|
+
@type_from_marcel = Marcel::MimeType.for Pathname.new(@filepath),
|
73
|
+
name: @filepath
|
74
|
+
# Marcel::MineType returns 'application/octet-stream' if it can't find
|
75
|
+
# a valid type.
|
76
|
+
@type_from_marcel = nil if @type_from_marcel == SENSIBLE_DEFAULT
|
77
|
+
@type_from_marcel
|
73
78
|
end
|
74
79
|
|
75
80
|
def type_from_file_command
|
@@ -7,7 +7,7 @@ module Paperclip
|
|
7
7
|
|
8
8
|
def make
|
9
9
|
geometry = GeometryParser.new(geometry_string.strip).make
|
10
|
-
geometry || raise(Errors::NotIdentifiedByImageMagickError.new)
|
10
|
+
geometry || raise(Errors::NotIdentifiedByImageMagickError.new("Could not identify image size"))
|
11
11
|
end
|
12
12
|
|
13
13
|
private
|
data/lib/paperclip/glue.rb
CHANGED
@@ -4,14 +4,15 @@ require "paperclip/schema"
|
|
4
4
|
|
5
5
|
module Paperclip
|
6
6
|
module Glue
|
7
|
+
LOCALE_PATHS = Dir.glob("#{File.dirname(__FILE__)}/locales/*.{rb,yml}")
|
8
|
+
|
7
9
|
def self.included(base)
|
8
10
|
base.extend ClassMethods
|
9
11
|
base.send :include, Callbacks
|
10
12
|
base.send :include, Validators
|
11
13
|
base.send :include, Schema if defined? ActiveRecord::Base
|
12
14
|
|
13
|
-
|
14
|
-
I18n.load_path += locale_path unless I18n.load_path.include?(locale_path)
|
15
|
+
I18n.load_path += LOCALE_PATHS unless (LOCALE_PATHS - I18n.load_path).empty?
|
15
16
|
end
|
16
17
|
end
|
17
18
|
end
|
@@ -54,10 +54,14 @@ module Paperclip
|
|
54
54
|
# Returns the interpolated URL. Will raise an error if the url itself
|
55
55
|
# contains ":url" to prevent infinite recursion. This interpolation
|
56
56
|
# is used in the default :path to ease default specifications.
|
57
|
-
RIGHT_HERE = "#{__FILE__.gsub(%r{\A\./}, '')}:#{__LINE__ + 3}"
|
58
57
|
def url(attachment, style_name)
|
59
|
-
|
58
|
+
if Thread.current.thread_variable_get(:kt_paperclip_no_recursion)
|
59
|
+
raise Errors::InfiniteInterpolationError
|
60
|
+
end
|
61
|
+
Thread.current.thread_variable_set(:kt_paperclip_no_recursion, true)
|
60
62
|
attachment.url(style_name, timestamp: false, escape: false)
|
63
|
+
ensure
|
64
|
+
Thread.current.thread_variable_set(:kt_paperclip_no_recursion, false)
|
61
65
|
end
|
62
66
|
|
63
67
|
# Returns the timestamp as defined by the <attachment>_updated_at field
|
@@ -0,0 +1,20 @@
|
|
1
|
+
gd:
|
2
|
+
errors:
|
3
|
+
messages:
|
4
|
+
in_between: "– feumaidh seo a bhith eadar %{min} ’s %{max}"
|
5
|
+
spoofed_media_type: "– tha susbaint ann nach eil a-rèir na chaidh aithris"
|
6
|
+
|
7
|
+
number:
|
8
|
+
human:
|
9
|
+
storage_units:
|
10
|
+
format: "%n %u"
|
11
|
+
units:
|
12
|
+
byte:
|
13
|
+
one: "bhaidht"
|
14
|
+
two: "bhaidht"
|
15
|
+
few: "baidhtean"
|
16
|
+
other: "baidht"
|
17
|
+
kb: "KB"
|
18
|
+
mb: "MB"
|
19
|
+
gb: "GB"
|
20
|
+
tb: "TB"
|
@@ -76,11 +76,14 @@ module Paperclip
|
|
76
76
|
Paperclip.run("file", "-b --mime :file", file: @file.path).
|
77
77
|
split(/[:;\s]+/).first
|
78
78
|
rescue Terrapin::CommandLineError
|
79
|
+
Paperclip.log("Problem getting type from `file` command. Possible that `file` doesn't exist on this system. Content Type validations don't work without this.")
|
80
|
+
|
79
81
|
""
|
80
82
|
end
|
81
83
|
|
82
84
|
def mapped_content_type
|
83
|
-
Paperclip.options[:content_type_mappings]
|
85
|
+
content_type_mappings = Paperclip.options[:content_type_mappings]
|
86
|
+
content_type_mappings[filename_extension] || content_type_mappings[filename_extension.to_s]
|
84
87
|
end
|
85
88
|
|
86
89
|
def filename_extension
|
data/lib/paperclip/schema.rb
CHANGED
@@ -6,12 +6,12 @@ module Paperclip
|
|
6
6
|
COLUMNS = { file_name: :string,
|
7
7
|
content_type: :string,
|
8
8
|
file_size: :bigint,
|
9
|
-
updated_at: :datetime }
|
9
|
+
updated_at: :datetime }
|
10
10
|
|
11
11
|
def self.included(_base)
|
12
12
|
ActiveRecord::ConnectionAdapters::Table.include TableDefinition
|
13
13
|
ActiveRecord::ConnectionAdapters::TableDefinition.include TableDefinition
|
14
|
-
ActiveRecord::
|
14
|
+
ActiveRecord::Migration.include Statements
|
15
15
|
ActiveRecord::Migration::CommandRecorder.include CommandRecorder
|
16
16
|
end
|
17
17
|
|
data/lib/paperclip/storage/s3.rb
CHANGED
@@ -137,6 +137,9 @@ module Paperclip
|
|
137
137
|
@s3_headers = {}
|
138
138
|
merge_s3_headers(@options[:s3_headers], @s3_headers, @s3_metadata)
|
139
139
|
|
140
|
+
@s3_acl_enabled = @options[:s3_acl_enabled]
|
141
|
+
@s3_acl_enabled = true if @s3_acl_enabled.nil?
|
142
|
+
|
140
143
|
@s3_storage_class = set_storage_class(@options[:s3_storage_class])
|
141
144
|
|
142
145
|
@s3_server_side_encryption = "AES256"
|
@@ -359,9 +362,12 @@ module Paperclip
|
|
359
362
|
log("saving #{path(style)}")
|
360
363
|
write_options = {
|
361
364
|
content_type: file.content_type,
|
362
|
-
acl: s3_permissions(style)
|
363
365
|
}
|
364
366
|
|
367
|
+
if @s3_acl_enabled
|
368
|
+
write_options[:acl] = s3_permissions(style)
|
369
|
+
end
|
370
|
+
|
365
371
|
# add storage class for this style if defined
|
366
372
|
storage_class = s3_storage_class(style)
|
367
373
|
write_options.merge!(storage_class: storage_class) if storage_class
|
@@ -403,7 +409,7 @@ module Paperclip
|
|
403
409
|
end
|
404
410
|
|
405
411
|
def flush_deletes #:nodoc:
|
406
|
-
@queued_for_delete.each do |path|
|
412
|
+
@queued_for_delete.uniq.each do |path|
|
407
413
|
begin
|
408
414
|
log("deleting #{path}")
|
409
415
|
s3_bucket.object(path.sub(%r{\A/}, "")).delete
|
@@ -427,9 +433,9 @@ module Paperclip
|
|
427
433
|
def find_credentials(creds)
|
428
434
|
case creds
|
429
435
|
when File
|
430
|
-
|
436
|
+
load_credentials_from_file(creds.path)
|
431
437
|
when String, Pathname
|
432
|
-
|
438
|
+
load_credentials_from_file(creds)
|
433
439
|
when Hash
|
434
440
|
creds
|
435
441
|
when NilClass
|
@@ -439,6 +445,14 @@ module Paperclip
|
|
439
445
|
end
|
440
446
|
end
|
441
447
|
|
448
|
+
def load_credentials_from_file(path)
|
449
|
+
if Gem::Version.new(Psych::VERSION) >= Gem::Version.new("3.1.0")
|
450
|
+
YAML::safe_load(ERB.new(File.read(path)).result, aliases: true)
|
451
|
+
else
|
452
|
+
YAML::safe_load(ERB.new(File.read(path)).result, [], [], true)
|
453
|
+
end
|
454
|
+
end
|
455
|
+
|
442
456
|
def use_secure_protocol?(style_name)
|
443
457
|
s3_protocol(style_name) == "https"
|
444
458
|
end
|
@@ -27,7 +27,7 @@ module Paperclip
|
|
27
27
|
[:both, :base].include?(options[:add_validation_errors_to])
|
28
28
|
|
29
29
|
record.errors[attribute].each do |error|
|
30
|
-
record.errors.add
|
30
|
+
record.errors.add(base_attribute, error)
|
31
31
|
end
|
32
32
|
|
33
33
|
record.errors.delete(attribute) if options[:add_validation_errors_to] == :base
|
@@ -35,8 +35,9 @@ module Paperclip
|
|
35
35
|
options.slice(*AVAILABLE_CHECKS).each do |option, option_value|
|
36
36
|
option_value = option_value.call(record) if option_value.is_a?(Proc)
|
37
37
|
option_value = extract_option_value(option, option_value)
|
38
|
+
operator = ActiveModel::VERSION::MAJOR >= 7 ? COMPARE_CHECKS[option] : CHECKS[option]
|
38
39
|
|
39
|
-
unless value.send(
|
40
|
+
unless value.send(operator, option_value)
|
40
41
|
error_message_key = options[:in] ? :in_between : option
|
41
42
|
error_attrs.each do |error_attr_name|
|
42
43
|
record.errors.add(error_attr_name, error_message_key, **filtered_options(value).merge(
|
data/lib/paperclip/version.rb
CHANGED
data/paperclip.gemspec
CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
|
|
26
26
|
s.add_dependency("activesupport", ">= 4.2.0")
|
27
27
|
s.add_dependency("mime-types")
|
28
28
|
s.add_dependency("marcel", "~> 1.0.1")
|
29
|
-
s.add_dependency("terrapin", "
|
29
|
+
s.add_dependency("terrapin", ">= 0.6.0", "< 2.0")
|
30
30
|
|
31
31
|
s.add_development_dependency("activerecord", ">= 4.2.0")
|
32
32
|
s.add_development_dependency("appraisal")
|
@@ -1333,7 +1333,7 @@ describe Paperclip::Attachment do
|
|
1333
1333
|
|
1334
1334
|
context "An attachment with only a avatar_file_name column" do
|
1335
1335
|
before do
|
1336
|
-
ActiveRecord::
|
1336
|
+
ActiveRecord::Migration.create_table :dummies, force: true do |table|
|
1337
1337
|
table.column :avatar_file_name, :string
|
1338
1338
|
end
|
1339
1339
|
rebuild_class
|
@@ -1359,7 +1359,7 @@ describe Paperclip::Attachment do
|
|
1359
1359
|
|
1360
1360
|
context "and avatar_created_at column" do
|
1361
1361
|
before do
|
1362
|
-
ActiveRecord::
|
1362
|
+
ActiveRecord::Migration.add_column :dummies, :avatar_created_at, :timestamp
|
1363
1363
|
rebuild_class
|
1364
1364
|
@dummy = Dummy.new
|
1365
1365
|
end
|
@@ -1396,7 +1396,7 @@ describe Paperclip::Attachment do
|
|
1396
1396
|
|
1397
1397
|
context "and avatar_updated_at column" do
|
1398
1398
|
before do
|
1399
|
-
ActiveRecord::
|
1399
|
+
ActiveRecord::Migration.add_column :dummies, :avatar_updated_at, :timestamp
|
1400
1400
|
rebuild_class
|
1401
1401
|
@dummy = Dummy.new
|
1402
1402
|
end
|
@@ -1426,7 +1426,7 @@ describe Paperclip::Attachment do
|
|
1426
1426
|
|
1427
1427
|
context "and avatar_content_type column" do
|
1428
1428
|
before do
|
1429
|
-
ActiveRecord::
|
1429
|
+
ActiveRecord::Migration.add_column :dummies, :avatar_content_type, :string
|
1430
1430
|
rebuild_class
|
1431
1431
|
@dummy = Dummy.new
|
1432
1432
|
end
|
@@ -1443,7 +1443,7 @@ describe Paperclip::Attachment do
|
|
1443
1443
|
|
1444
1444
|
context "and avatar_file_size column" do
|
1445
1445
|
before do
|
1446
|
-
ActiveRecord::
|
1446
|
+
ActiveRecord::Migration.add_column :dummies, :avatar_file_size, :bigint
|
1447
1447
|
rebuild_class
|
1448
1448
|
@dummy = Dummy.new
|
1449
1449
|
end
|
@@ -1467,7 +1467,7 @@ describe Paperclip::Attachment do
|
|
1467
1467
|
|
1468
1468
|
context "and avatar_fingerprint column" do
|
1469
1469
|
before do
|
1470
|
-
ActiveRecord::
|
1470
|
+
ActiveRecord::Migration.add_column :dummies, :avatar_fingerprint, :string
|
1471
1471
|
rebuild_class
|
1472
1472
|
@dummy = Dummy.new
|
1473
1473
|
end
|
@@ -7,6 +7,13 @@ describe Paperclip::ContentTypeDetector do
|
|
7
7
|
Paperclip::ContentTypeDetector.new(file.path).detect
|
8
8
|
end
|
9
9
|
|
10
|
+
it 'returns a more specific content type based on the filename if it matches
|
11
|
+
multiple content types' do
|
12
|
+
file = File.new(fixture_file('sample.xlsm'))
|
13
|
+
assert_equal 'application/vnd.ms-excel.sheet.macroenabled.12',
|
14
|
+
Paperclip::ContentTypeDetector.new(file.path).detect
|
15
|
+
end
|
16
|
+
|
10
17
|
it "gives a sensible default when the name is empty" do
|
11
18
|
assert_equal "application/octet-stream", Paperclip::ContentTypeDetector.new("").detect
|
12
19
|
end
|
@@ -35,4 +35,13 @@ describe Paperclip::GeometryDetector do
|
|
35
35
|
Paperclip.options[:use_exif_orientation] = true
|
36
36
|
end
|
37
37
|
end
|
38
|
+
|
39
|
+
it "raises an exception with a message when the file is not an image" do
|
40
|
+
file = fixture_file("text.txt")
|
41
|
+
factory = Paperclip::GeometryDetector.new(file)
|
42
|
+
|
43
|
+
expect do
|
44
|
+
factory.make
|
45
|
+
end.to raise_error(Paperclip::Errors::NotIdentifiedByImageMagickError, "Could not identify image size")
|
46
|
+
end
|
38
47
|
end
|
@@ -147,23 +147,35 @@ describe Paperclip::Geometry do
|
|
147
147
|
|
148
148
|
it "does not generate from a bad file" do
|
149
149
|
file = "/home/This File Does Not Exist.omg"
|
150
|
-
expect
|
150
|
+
expect do
|
151
|
+
@geo = Paperclip::Geometry.from_file(file)
|
152
|
+
end.to raise_error(Paperclip::Errors::NotIdentifiedByImageMagickError,
|
153
|
+
"Could not identify image size")
|
151
154
|
end
|
152
155
|
|
153
156
|
it "does not generate from a blank filename" do
|
154
157
|
file = ""
|
155
|
-
expect
|
158
|
+
expect do
|
159
|
+
@geo = Paperclip::Geometry.from_file(file)
|
160
|
+
end.to raise_error(Paperclip::Errors::NotIdentifiedByImageMagickError,
|
161
|
+
"Cannot find the geometry of a file with a blank name")
|
156
162
|
end
|
157
163
|
|
158
164
|
it "does not generate from a nil file" do
|
159
165
|
file = nil
|
160
|
-
expect
|
166
|
+
expect do
|
167
|
+
@geo = Paperclip::Geometry.from_file(file)
|
168
|
+
end.to raise_error(Paperclip::Errors::NotIdentifiedByImageMagickError,
|
169
|
+
"Cannot find the geometry of a file with a blank name")
|
161
170
|
end
|
162
171
|
|
163
172
|
it "does not generate from a file with no path" do
|
164
173
|
file = double("file", path: "")
|
165
174
|
allow(file).to receive(:respond_to?).with(:path).and_return(true)
|
166
|
-
expect
|
175
|
+
expect do
|
176
|
+
@geo = Paperclip::Geometry.from_file(file)
|
177
|
+
end.to raise_error(Paperclip::Errors::NotIdentifiedByImageMagickError,
|
178
|
+
"Cannot find the geometry of a file with a blank name")
|
167
179
|
end
|
168
180
|
|
169
181
|
it "lets us know when a command isn't found versus a processing error" do
|
data/spec/paperclip/glue_spec.rb
CHANGED
@@ -39,4 +39,25 @@ describe Paperclip::Glue do
|
|
39
39
|
Object.send :remove_const, "NonActiveRecordModel"
|
40
40
|
end
|
41
41
|
end
|
42
|
+
|
43
|
+
describe "when included" do
|
44
|
+
it "does not mutate I18n.load_path more than once" do
|
45
|
+
before_load_path = I18n.load_path
|
46
|
+
I18n.load_path = []
|
47
|
+
|
48
|
+
# expect twice because the load_path is reset after creating the classes
|
49
|
+
expect(I18n.config).to receive(:load_path=).and_call_original.twice
|
50
|
+
|
51
|
+
FirstModel = Class.new
|
52
|
+
FirstModel.include Paperclip::Glue
|
53
|
+
|
54
|
+
SecondModel = Class.new
|
55
|
+
SecondModel.include Paperclip::Glue
|
56
|
+
|
57
|
+
ThirdModel = Class.new
|
58
|
+
ThirdModel.include Paperclip::Glue
|
59
|
+
|
60
|
+
I18n.load_path = before_load_path
|
61
|
+
end
|
62
|
+
end
|
42
63
|
end
|
@@ -224,7 +224,7 @@ describe Paperclip::UriAdapter do
|
|
224
224
|
|
225
225
|
it "calls open with read_timeout option" do
|
226
226
|
expect(@uri_opener)
|
227
|
-
.to receive(:open).with(@uri, read_timeout: 120).at_least(1).times
|
227
|
+
.to receive(:open).with(@uri, { read_timeout: 120 }).at_least(1).times
|
228
228
|
end
|
229
229
|
end
|
230
230
|
end
|
@@ -32,12 +32,18 @@ describe Paperclip::MediaTypeSpoofDetector do
|
|
32
32
|
end
|
33
33
|
|
34
34
|
it "does not reject when the extension => content_type is in :content_type_mappings" do
|
35
|
+
file = Tempfile.open(["test", ".PEM"])
|
36
|
+
file.puts "Certificate!"
|
37
|
+
file.close
|
38
|
+
|
39
|
+
adapter = Paperclip.io_adapters.for(File.new(file.path))
|
40
|
+
|
35
41
|
begin
|
36
42
|
Paperclip.options[:content_type_mappings] = { pem: "text/plain" }
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
43
|
+
assert !Paperclip::MediaTypeSpoofDetector.using(adapter, adapter.original_filename, adapter.content_type).spoofed?
|
44
|
+
|
45
|
+
# As a string.
|
46
|
+
Paperclip.options[:content_type_mappings] = { "pem" => "text/plain" }
|
41
47
|
assert !Paperclip::MediaTypeSpoofDetector.using(adapter, adapter.original_filename, adapter.content_type).spoofed?
|
42
48
|
ensure
|
43
49
|
Paperclip.options[:content_type_mappings] = {}
|
@@ -49,7 +49,7 @@ describe "Missing Attachment Styles" do
|
|
49
49
|
expected_hash = { Dummy: { avatar: [:export, :thumb] } }
|
50
50
|
assert_equal expected_hash, Paperclip.missing_attachments_styles
|
51
51
|
|
52
|
-
ActiveRecord::
|
52
|
+
ActiveRecord::Migration.create_table :books, force: true
|
53
53
|
class ::Book < ActiveRecord::Base
|
54
54
|
has_attached_file :cover, styles: { small: "x100", large: "1000x1000>" }
|
55
55
|
has_attached_file :sample, styles: { thumb: "x100" }
|
@@ -63,7 +63,7 @@ describe Paperclip do
|
|
63
63
|
context "Calling Paperclip.run with a logger" do
|
64
64
|
it "passes the defined logger if :log_command is set" do
|
65
65
|
Paperclip.options[:log_command] = true
|
66
|
-
expect(Terrapin::CommandLine).to receive(:new).with("convert", "stuff", logger: Paperclip.logger).and_return(double(run: nil))
|
66
|
+
expect(Terrapin::CommandLine).to receive(:new).with("convert", "stuff", { logger: Paperclip.logger }).and_return(double(run: nil))
|
67
67
|
Paperclip.run("convert", "stuff")
|
68
68
|
end
|
69
69
|
end
|