paperclip 4.3.0 → 5.0.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.

Potentially problematic release.


This version of paperclip might be problematic. Click here for more details.

Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +14 -13
  3. data/Appraisals +22 -9
  4. data/CONTRIBUTING.md +16 -5
  5. data/Gemfile +2 -8
  6. data/LICENSE +1 -1
  7. data/NEWS +49 -2
  8. data/README.md +126 -102
  9. data/UPGRADING +12 -9
  10. data/features/basic_integration.feature +1 -0
  11. data/features/migration.feature +0 -24
  12. data/features/step_definitions/attachment_steps.rb +20 -20
  13. data/features/step_definitions/html_steps.rb +2 -2
  14. data/features/step_definitions/rails_steps.rb +11 -17
  15. data/features/step_definitions/s3_steps.rb +2 -2
  16. data/features/step_definitions/web_steps.rb +1 -103
  17. data/features/support/file_helpers.rb +2 -2
  18. data/gemfiles/4.2.awsv2.0.gemfile +17 -0
  19. data/gemfiles/4.2.awsv2.1.gemfile +17 -0
  20. data/gemfiles/{4.2.gemfile → 4.2.awsv2.gemfile} +1 -1
  21. data/gemfiles/5.0.awsv2.0.gemfile +17 -0
  22. data/gemfiles/5.0.awsv2.1.gemfile +17 -0
  23. data/gemfiles/{4.1.gemfile → 5.0.awsv2.gemfile} +2 -2
  24. data/lib/paperclip/attachment.rb +18 -17
  25. data/lib/paperclip/attachment_registry.rb +2 -1
  26. data/lib/paperclip/callbacks.rb +8 -6
  27. data/lib/paperclip/content_type_detector.rb +3 -2
  28. data/lib/paperclip/errors.rb +3 -1
  29. data/lib/paperclip/geometry_parser_factory.rb +1 -1
  30. data/lib/paperclip/glue.rb +1 -1
  31. data/lib/paperclip/has_attached_file.rb +7 -1
  32. data/lib/paperclip/helpers.rb +14 -10
  33. data/lib/paperclip/interpolations/plural_cache.rb +6 -5
  34. data/lib/paperclip/interpolations.rb +18 -13
  35. data/lib/paperclip/io_adapters/http_url_proxy_adapter.rb +1 -1
  36. data/lib/paperclip/io_adapters/uri_adapter.rb +3 -1
  37. data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +4 -4
  38. data/lib/paperclip/media_type_spoof_detector.rb +1 -1
  39. data/lib/paperclip/rails_environment.rb +1 -1
  40. data/lib/paperclip/schema.rb +3 -9
  41. data/lib/paperclip/storage/fog.rb +17 -8
  42. data/lib/paperclip/storage/s3.rb +51 -49
  43. data/lib/paperclip/validators/attachment_size_validator.rb +1 -7
  44. data/lib/paperclip/version.rb +3 -1
  45. data/lib/paperclip.rb +2 -1
  46. data/lib/tasks/paperclip.rake +1 -1
  47. data/paperclip.gemspec +15 -11
  48. data/spec/paperclip/attachment_processing_spec.rb +2 -4
  49. data/spec/paperclip/attachment_registry_spec.rb +28 -0
  50. data/spec/paperclip/attachment_spec.rb +36 -14
  51. data/spec/paperclip/geometry_spec.rb +1 -1
  52. data/spec/paperclip/glue_spec.rb +44 -0
  53. data/spec/paperclip/has_attached_file_spec.rb +24 -8
  54. data/spec/paperclip/integration_spec.rb +4 -3
  55. data/spec/paperclip/interpolations_spec.rb +14 -4
  56. data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +12 -0
  57. data/spec/paperclip/io_adapters/uri_adapter_spec.rb +27 -0
  58. data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +10 -0
  59. data/spec/paperclip/media_type_spoof_detector_spec.rb +12 -3
  60. data/spec/paperclip/paperclip_spec.rb +3 -28
  61. data/spec/paperclip/plural_cache_spec.rb +17 -16
  62. data/spec/paperclip/storage/fog_spec.rb +31 -1
  63. data/spec/paperclip/storage/s3_live_spec.rb +8 -4
  64. data/spec/paperclip/storage/s3_spec.rb +213 -156
  65. data/spec/paperclip/validators/attachment_size_validator_spec.rb +26 -20
  66. data/spec/paperclip/validators_spec.rb +3 -3
  67. data/spec/spec_helper.rb +6 -1
  68. data/spec/support/assertions.rb +7 -0
  69. data/spec/support/model_reconstruction.rb +9 -1
  70. data/spec/support/reporting.rb +11 -0
  71. metadata +74 -47
  72. data/cucumber/paperclip_steps.rb +0 -6
  73. data/gemfiles/3.2.gemfile +0 -20
  74. data/lib/paperclip/locales/de.yml +0 -18
  75. data/lib/paperclip/locales/es.yml +0 -18
  76. data/lib/paperclip/locales/ja.yml +0 -18
  77. data/lib/paperclip/locales/pt-BR.yml +0 -18
  78. data/lib/paperclip/locales/zh-CN.yml +0 -18
  79. data/lib/paperclip/locales/zh-HK.yml +0 -18
  80. data/lib/paperclip/locales/zh-TW.yml +0 -18
  81. data/spec/support/rails_helpers.rb +0 -7
@@ -3,34 +3,35 @@ require 'spec_helper'
3
3
  describe 'Plural cache' do
4
4
  it 'caches pluralizations' do
5
5
  cache = Paperclip::Interpolations::PluralCache.new
6
- word = "box"
6
+ symbol = :box
7
7
 
8
- word.expects(:pluralize).returns("boxes").once
9
-
10
- cache.pluralize(word)
11
- cache.pluralize(word)
8
+ first = cache.pluralize_symbol(symbol)
9
+ second = cache.pluralize_symbol(symbol)
10
+ expect(first).to equal(second)
12
11
  end
13
12
 
14
13
  it 'caches pluralizations and underscores' do
14
+ class BigBox ; end
15
15
  cache = Paperclip::Interpolations::PluralCache.new
16
- word = "BigBox"
17
-
18
- word.expects(:pluralize).returns(word).once
19
- word.expects(:underscore).returns(word).once
16
+ klass = BigBox
20
17
 
21
- cache.underscore_and_pluralize(word)
22
- cache.underscore_and_pluralize(word)
18
+ first = cache.underscore_and_pluralize_class(klass)
19
+ second = cache.underscore_and_pluralize_class(klass)
20
+ expect(first).to equal(second)
23
21
  end
24
22
 
25
23
  it 'pluralizes words' do
26
24
  cache = Paperclip::Interpolations::PluralCache.new
27
- word = "box"
28
- assert_equal "boxes", cache.pluralize(word)
25
+ symbol = :box
26
+
27
+ expect(cache.pluralize_symbol(symbol)).to eq("boxes")
29
28
  end
30
29
 
31
- it 'pluralizes and underscore words' do
30
+ it 'pluralizes and underscore class names' do
31
+ class BigBox ; end
32
32
  cache = Paperclip::Interpolations::PluralCache.new
33
- word = "BigBox"
34
- assert_equal "big_boxes", cache.underscore_and_pluralize(word)
33
+ klass = BigBox
34
+
35
+ expect(cache.underscore_and_pluralize_class(klass)).to eq("big_boxes")
35
36
  end
36
37
  end
@@ -1,5 +1,6 @@
1
1
  require 'spec_helper'
2
- require 'fog'
2
+ require 'fog/aws'
3
+ require 'fog/local'
3
4
  require 'timecop'
4
5
 
5
6
  describe Paperclip::Storage::Fog do
@@ -182,6 +183,13 @@ describe Paperclip::Storage::Fog do
182
183
  tempfile.close
183
184
  end
184
185
 
186
+ it 'is able to be handled when missing while copying to a local file' do
187
+ tempfile = Tempfile.new("known_location")
188
+ tempfile.binmode
189
+ assert_equal false, @dummy.avatar.copy_to_local_file(:original, tempfile.path)
190
+ tempfile.close
191
+ end
192
+
185
193
  it "passes the content type to the Fog::Storage::AWS::Files instance" do
186
194
  Fog::Storage::AWS::Files.any_instance.expects(:create).with do |hash|
187
195
  hash[:content_type]
@@ -417,6 +425,9 @@ describe Paperclip::Storage::Fog do
417
425
  assert @connection.directories.get(@dynamic_fog_directory).inspect
418
426
  end
419
427
 
428
+ it "provides an url using dynamic bucket name" do
429
+ assert_match(/^https:\/\/dynamicpaperclip.s3.amazonaws.com\/avatars\/5k.png\?\d*$/, @dummy.avatar.url)
430
+ end
420
431
  end
421
432
 
422
433
  context "with a proc for the fog_host evaluating a model method" do
@@ -483,6 +494,25 @@ describe Paperclip::Storage::Fog do
483
494
  assert_equal @dummy.avatar.fog_credentials, @dynamic_fog_credentials
484
495
  end
485
496
  end
497
+
498
+ context "with custom fog_options" do
499
+ before do
500
+ rebuild_model(
501
+ @options.merge(fog_options: { multipart_chunk_size: 104857600 }),
502
+ )
503
+ @dummy = Dummy.new
504
+ @dummy.avatar = @file
505
+ end
506
+
507
+ it "applies the options to the fog #create call" do
508
+ files = stub
509
+ @dummy.avatar.stubs(:directory).returns stub(files: files)
510
+ files.expects(:create).with(
511
+ has_entries(multipart_chunk_size: 104857600),
512
+ )
513
+ @dummy.save
514
+ end
515
+ end
486
516
  end
487
517
 
488
518
  end
@@ -8,6 +8,7 @@ unless ENV["S3_BUCKET"].blank?
8
8
  storage: :s3,
9
9
  bucket: ENV["S3_BUCKET"],
10
10
  path: ":class/:attachment/:id/:style.:extension",
11
+ s3_region: ENV["S3_REGION"],
11
12
  s3_credentials: {
12
13
  aws_access_key_id: ENV['AWS_ACCESS_KEY_ID'],
13
14
  aws_secre_access_key: ENV['AWS_SECRET_ACCESS_KEY']
@@ -45,6 +46,7 @@ unless ENV["S3_BUCKET"].blank?
45
46
  storage: :s3,
46
47
  bucket: ENV["S3_BUCKET"],
47
48
  path: ":class/:attachment/:id/:style.:extension",
49
+ s3_region: ENV["S3_REGION"],
48
50
  s3_credentials: {
49
51
  aws_access_key_id: ENV['AWS_ACCESS_KEY_ID'],
50
52
  aws_secre_access_key: ENV['AWS_SECRET_ACCESS_KEY']
@@ -64,6 +66,7 @@ unless ENV["S3_BUCKET"].blank?
64
66
  storage: :s3,
65
67
  bucket: ENV["S3_BUCKET"],
66
68
  path: ":class/:attachment/:id/:style.:extension",
69
+ s3_region: ENV["S3_REGION"],
67
70
  s3_credentials: {
68
71
  aws_access_key_id: ENV['AWS_ACCESS_KEY_ID'],
69
72
  aws_secre_access_key: ENV['AWS_SECRET_ACCESS_KEY']
@@ -105,6 +108,7 @@ unless ENV["S3_BUCKET"].blank?
105
108
  rebuild_model styles: { thumb: "100x100", square: "32x32#" },
106
109
  storage: :s3,
107
110
  bucket: ENV["S3_BUCKET"],
111
+ s3_region: ENV["S3_REGION"],
108
112
  s3_credentials: {
109
113
  aws_access_key_id: ENV['AWS_ACCESS_KEY_ID'],
110
114
  aws_secre_access_key: ENV['AWS_SECRET_ACCESS_KEY']
@@ -136,7 +140,7 @@ unless ENV["S3_BUCKET"].blank?
136
140
  it "is destroyable" do
137
141
  url = @dummy.avatar.url
138
142
  @dummy.destroy
139
- assert_not_found_response url
143
+ assert_forbidden_response url
140
144
  end
141
145
  end
142
146
 
@@ -146,12 +150,12 @@ unless ENV["S3_BUCKET"].blank?
146
150
  storage: :s3,
147
151
  bucket: ENV["S3_BUCKET"],
148
152
  path: ":class/:attachment/:id/:style.:extension",
153
+ s3_region: ENV["S3_REGION"],
149
154
  s3_credentials: {
150
155
  aws_access_key_id: ENV['AWS_ACCESS_KEY_ID'],
151
156
  aws_secre_access_key: ENV['AWS_SECRET_ACCESS_KEY']
152
157
  },
153
- s3_server_side_encryption: :aes256
154
-
158
+ s3_server_side_encryption: "AES256"
155
159
  Dummy.delete_all
156
160
  @dummy = Dummy.new
157
161
  end
@@ -173,7 +177,7 @@ unless ENV["S3_BUCKET"].blank?
173
177
  end
174
178
 
175
179
  it "is encrypted on S3" do
176
- assert @dummy.avatar.s3_object.server_side_encryption == :aes256
180
+ assert @dummy.avatar.s3_object.server_side_encryption == "AES256"
177
181
  end
178
182
  end
179
183
  end