paperclip 4.2.4 → 4.3.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


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

Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.hound.yml +1066 -0
  3. data/.rubocop.yml +1 -0
  4. data/.travis.yml +5 -3
  5. data/Appraisals +1 -6
  6. data/CONTRIBUTING.md +3 -3
  7. data/Gemfile +1 -0
  8. data/LICENSE +1 -1
  9. data/NEWS +14 -1
  10. data/README.md +137 -77
  11. data/RELEASING.md +17 -0
  12. data/Rakefile +1 -1
  13. data/features/basic_integration.feature +7 -4
  14. data/features/step_definitions/attachment_steps.rb +7 -1
  15. data/gemfiles/3.2.gemfile +2 -1
  16. data/gemfiles/4.1.gemfile +1 -0
  17. data/gemfiles/4.2.gemfile +2 -1
  18. data/lib/paperclip.rb +13 -3
  19. data/lib/paperclip/attachment.rb +3 -1
  20. data/lib/paperclip/attachment_registry.rb +1 -1
  21. data/lib/paperclip/content_type_detector.rb +26 -11
  22. data/lib/paperclip/file_command_content_type_detector.rb +6 -8
  23. data/lib/paperclip/glue.rb +1 -1
  24. data/lib/paperclip/has_attached_file.rb +2 -1
  25. data/lib/paperclip/interpolations.rb +1 -1
  26. data/lib/paperclip/io_adapters/abstract_adapter.rb +1 -0
  27. data/lib/paperclip/media_type_spoof_detector.rb +1 -1
  28. data/lib/paperclip/rails_environment.rb +25 -0
  29. data/lib/paperclip/storage/fog.rb +4 -4
  30. data/lib/paperclip/storage/s3.rb +2 -3
  31. data/lib/paperclip/thumbnail.rb +2 -3
  32. data/lib/paperclip/version.rb +1 -1
  33. data/lib/tasks/paperclip.rake +16 -0
  34. data/paperclip.gemspec +3 -4
  35. data/spec/paperclip/attachment_definitions_spec.rb +1 -1
  36. data/spec/paperclip/attachment_registry_spec.rb +56 -13
  37. data/spec/paperclip/attachment_spec.rb +57 -19
  38. data/spec/paperclip/content_type_detector_spec.rb +8 -1
  39. data/spec/paperclip/file_command_content_type_detector_spec.rb +0 -1
  40. data/spec/paperclip/interpolations_spec.rb +2 -9
  41. data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +2 -1
  42. data/spec/paperclip/io_adapters/file_adapter_spec.rb +4 -1
  43. data/spec/paperclip/io_adapters/stringio_adapter_spec.rb +4 -0
  44. data/spec/paperclip/media_type_spoof_detector_spec.rb +16 -2
  45. data/spec/paperclip/rails_environment_spec.rb +33 -0
  46. data/spec/paperclip/storage/fog_spec.rb +11 -2
  47. data/spec/paperclip/storage/s3_spec.rb +43 -25
  48. data/spec/paperclip/tempfile_factory_spec.rb +4 -0
  49. data/spec/paperclip/thumbnail_spec.rb +16 -0
  50. data/spec/paperclip/url_generator_spec.rb +1 -1
  51. data/spec/support/fake_model.rb +4 -0
  52. data/spec/support/fixtures/empty.xlsx +0 -0
  53. data/spec/support/matchers/have_column.rb +11 -2
  54. metadata +30 -12
  55. data/RUNNING_TESTS.md +0 -4
  56. data/gemfiles/4.0.gemfile +0 -19
  57. data/spec/support/mock_model.rb +0 -2
@@ -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(/^http:\/\/papercliptests.s3.amazonaws.com\/avatars\/5k.png.+Expires=.+$/, @dummy.avatar.expiring_url)
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(/^http:\/\/s3.amazonaws.com\/this_is_invalid\/avatars\/5k.png.+Expires=.+$/, @dummy.avatar.expiring_url)
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 styles: { large: ['500x500#', :jpg] },
353
+ rebuild_model(
354
+ styles: { large: ["500x500#", :jpg] },
346
355
  storage: :s3,
347
356
  bucket: "bucket",
348
- s3_credentials: {
349
- 'access_key_id' => "12345",
350
- 'secret_access_key' => "54321"
351
- }
357
+ s3_credentials: { "access_key_id" => "12345",
358
+ "secret_access_key" => "54321" }
359
+ )
352
360
 
353
- File.open(fixture_file('spaced file.png'), 'rb') do |file|
354
- @dummy = Dummy.new
355
- @dummy.avatar = file
356
- end
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
- stringio = stringy_file
379
- class << stringio
380
- def original_filename
381
- "question?mark.png"
382
- end
387
+ stringio = stringy_file
388
+ class << stringio
389
+ def original_filename
390
+ "question?mark.png"
383
391
  end
384
- file = Paperclip.io_adapters.for(stringio)
385
- @dummy = Dummy.new
386
- @dummy.avatar = file
387
- @dummy.save
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 storage: :s3,
428
+ rebuild_model(
429
+ storage: :s3,
418
430
  s3_credentials: {
419
- production: { bucket: "prod_bucket" },
420
- development: { bucket: "dev_bucket" }
421
- },
422
- s3_host_alias: "something.something.com",
423
- path: ":attachment/:basename:dotextension",
424
- url: ":s3_alias_url"
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 }
@@ -26,4 +26,8 @@ describe Paperclip::TempfileFactory do
26
26
  file = subject.generate
27
27
  assert File.exist?(file.path)
28
28
  end
29
+
30
+ it "does not throw Errno::ENAMETOOLONG when it has a really long name" do
31
+ expect { subject.generate("o" * 255) }.to_not raise_error
32
+ end
29
33
  end
@@ -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 = MockModel.new
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
@@ -18,4 +18,8 @@ class FakeModel
18
18
  def valid?
19
19
  errors.empty?
20
20
  end
21
+
22
+ def new_record?
23
+ false
24
+ end
21
25
  end
@@ -8,7 +8,16 @@ RSpec::Matchers.define :have_column do |column_name|
8
8
  column && column.default.to_s == @default.to_s
9
9
  end
10
10
 
11
- failure_message_for_should do |columns|
12
- "expected to find '#{column_name}', default '#{@default}' in #{columns.map{|column| [column.name, column.default] }}"
11
+ failure_message_method =
12
+ if RSpec::Version::STRING.to_i >= 3
13
+ :failure_message
14
+ else
15
+ :failure_message_for_should
16
+ end
17
+
18
+ send(failure_message_method) do |columns|
19
+ "expected to find '#{column_name}', " +
20
+ "default '#{@default}' " +
21
+ "in #{columns.map { |column| [column.name, column.default] }}"
13
22
  end
14
23
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paperclip
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.4
4
+ version: 4.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Yurek
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mimemagic
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 0.3.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 0.3.0
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: activerecord
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -176,14 +190,14 @@ dependencies:
176
190
  requirements:
177
191
  - - "~>"
178
192
  - !ruby/object:Gem::Version
179
- version: 1.3.11
193
+ version: 1.3.18
180
194
  type: :development
181
195
  prerelease: false
182
196
  version_requirements: !ruby/object:Gem::Requirement
183
197
  requirements:
184
198
  - - "~>"
185
199
  - !ruby/object:Gem::Version
186
- version: 1.3.11
200
+ version: 1.3.18
187
201
  - !ruby/object:Gem::Dependency
188
202
  name: aruba
189
203
  requirement: !ruby/object:Gem::Requirement
@@ -216,16 +230,16 @@ dependencies:
216
230
  name: capybara
217
231
  requirement: !ruby/object:Gem::Requirement
218
232
  requirements:
219
- - - '='
233
+ - - ">="
220
234
  - !ruby/object:Gem::Version
221
- version: 2.0.3
235
+ version: '0'
222
236
  type: :development
223
237
  prerelease: false
224
238
  version_requirements: !ruby/object:Gem::Requirement
225
239
  requirements:
226
- - - '='
240
+ - - ">="
227
241
  - !ruby/object:Gem::Version
228
- version: 2.0.3
242
+ version: '0'
229
243
  - !ruby/object:Gem::Dependency
230
244
  name: bundler
231
245
  requirement: !ruby/object:Gem::Requirement
@@ -360,6 +374,8 @@ extensions: []
360
374
  extra_rdoc_files: []
361
375
  files:
362
376
  - ".gitignore"
377
+ - ".hound.yml"
378
+ - ".rubocop.yml"
363
379
  - ".travis.yml"
364
380
  - Appraisals
365
381
  - CONTRIBUTING.md
@@ -367,7 +383,7 @@ files:
367
383
  - LICENSE
368
384
  - NEWS
369
385
  - README.md
370
- - RUNNING_TESTS.md
386
+ - RELEASING.md
371
387
  - Rakefile
372
388
  - UPGRADING
373
389
  - cucumber/paperclip_steps.rb
@@ -389,7 +405,6 @@ files:
389
405
  - features/support/rails.rb
390
406
  - features/support/selectors.rb
391
407
  - gemfiles/3.2.gemfile
392
- - gemfiles/4.0.gemfile
393
408
  - gemfiles/4.1.gemfile
394
409
  - gemfiles/4.2.gemfile
395
410
  - lib/generators/paperclip/USAGE
@@ -441,6 +456,7 @@ files:
441
456
  - lib/paperclip/missing_attachment_styles.rb
442
457
  - lib/paperclip/processor.rb
443
458
  - lib/paperclip/processor_helpers.rb
459
+ - lib/paperclip/rails_environment.rb
444
460
  - lib/paperclip/railtie.rb
445
461
  - lib/paperclip/schema.rb
446
462
  - lib/paperclip/storage.rb
@@ -500,6 +516,7 @@ files:
500
516
  - spec/paperclip/plural_cache_spec.rb
501
517
  - spec/paperclip/processor_helpers_spec.rb
502
518
  - spec/paperclip/processor_spec.rb
519
+ - spec/paperclip/rails_environment_spec.rb
503
520
  - spec/paperclip/rake_spec.rb
504
521
  - spec/paperclip/schema_spec.rb
505
522
  - spec/paperclip/storage/filesystem_spec.rb
@@ -528,6 +545,7 @@ files:
528
545
  - spec/support/fixtures/animated.unknown
529
546
  - spec/support/fixtures/bad.png
530
547
  - spec/support/fixtures/empty.html
548
+ - spec/support/fixtures/empty.xlsx
531
549
  - spec/support/fixtures/fog.yml
532
550
  - spec/support/fixtures/rotated.jpg
533
551
  - spec/support/fixtures/s3.yml
@@ -541,7 +559,6 @@ files:
541
559
  - spec/support/matchers/have_column.rb
542
560
  - spec/support/mock_attachment.rb
543
561
  - spec/support/mock_interpolator.rb
544
- - spec/support/mock_model.rb
545
562
  - spec/support/mock_url_generator_builder.rb
546
563
  - spec/support/model_reconstruction.rb
547
564
  - spec/support/rails_helpers.rb
@@ -567,7 +584,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
567
584
  version: '0'
568
585
  requirements:
569
586
  - ImageMagick
570
- rubyforge_project: paperclip
587
+ rubyforge_project:
571
588
  rubygems_version: 2.4.5
572
589
  signing_key:
573
590
  specification_version: 4
@@ -627,6 +644,7 @@ test_files:
627
644
  - spec/paperclip/plural_cache_spec.rb
628
645
  - spec/paperclip/processor_helpers_spec.rb
629
646
  - spec/paperclip/processor_spec.rb
647
+ - spec/paperclip/rails_environment_spec.rb
630
648
  - spec/paperclip/rake_spec.rb
631
649
  - spec/paperclip/schema_spec.rb
632
650
  - spec/paperclip/storage/filesystem_spec.rb
@@ -655,6 +673,7 @@ test_files:
655
673
  - spec/support/fixtures/animated.unknown
656
674
  - spec/support/fixtures/bad.png
657
675
  - spec/support/fixtures/empty.html
676
+ - spec/support/fixtures/empty.xlsx
658
677
  - spec/support/fixtures/fog.yml
659
678
  - spec/support/fixtures/rotated.jpg
660
679
  - spec/support/fixtures/s3.yml
@@ -668,7 +687,6 @@ test_files:
668
687
  - spec/support/matchers/have_column.rb
669
688
  - spec/support/mock_attachment.rb
670
689
  - spec/support/mock_interpolator.rb
671
- - spec/support/mock_model.rb
672
690
  - spec/support/mock_url_generator_builder.rb
673
691
  - spec/support/model_reconstruction.rb
674
692
  - spec/support/rails_helpers.rb
@@ -1,4 +0,0 @@
1
- Running Tests
2
- =============
3
-
4
- Please see `CONTRIBUTING.md` in "Running Tests" section for more information.