kt-paperclip 6.4.2 → 7.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +1 -1
  3. data/.hound.yml +3 -1057
  4. data/.rubocop.yml +1059 -1
  5. data/.travis.yml +5 -5
  6. data/Appraisals +6 -0
  7. data/CONTRIBUTING.md +4 -5
  8. data/Gemfile +2 -2
  9. data/NEWS +31 -0
  10. data/README.md +8 -7
  11. data/features/step_definitions/attachment_steps.rb +11 -1
  12. data/gemfiles/4.2.gemfile +1 -1
  13. data/gemfiles/5.0.gemfile +1 -1
  14. data/gemfiles/5.1.gemfile +1 -1
  15. data/gemfiles/5.2.gemfile +1 -1
  16. data/gemfiles/6.0.gemfile +1 -1
  17. data/gemfiles/6.1.gemfile +21 -0
  18. data/gemfiles/7.0.gemfile +21 -0
  19. data/lib/paperclip/attachment.rb +1 -1
  20. data/lib/paperclip/content_type_detector.rb +10 -5
  21. data/lib/paperclip/interpolations.rb +6 -2
  22. data/lib/paperclip/media_type_spoof_detector.rb +2 -0
  23. data/lib/paperclip/schema.rb +1 -1
  24. data/lib/paperclip/storage/filesystem.rb +1 -1
  25. data/lib/paperclip/storage/fog.rb +1 -1
  26. data/lib/paperclip/storage/s3.rb +18 -4
  27. data/lib/paperclip/validators/attachment_file_name_validator.rb +1 -1
  28. data/lib/paperclip/validators/attachment_size_validator.rb +3 -2
  29. data/lib/paperclip/version.rb +1 -1
  30. data/lib/paperclip.rb +1 -2
  31. data/paperclip.gemspec +2 -2
  32. data/spec/paperclip/content_type_detector_spec.rb +7 -0
  33. data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +1 -1
  34. data/spec/paperclip/io_adapters/file_adapter_spec.rb +1 -1
  35. data/spec/paperclip/storage/filesystem_spec.rb +23 -0
  36. data/spec/paperclip/storage/fog_spec.rb +46 -0
  37. data/spec/paperclip/storage/s3_spec.rb +69 -0
  38. data/spec/paperclip/validators_spec.rb +21 -6
  39. data/spec/support/fixtures/sample.xlsm +0 -0
  40. metadata +118 -9
@@ -411,6 +411,62 @@ describe Paperclip::Storage::S3 do
411
411
  end
412
412
  end
413
413
 
414
+ context "An attachment that uses S3 for storage with acl disabled" do
415
+ before do
416
+ rebuild_model(
417
+ aws2_add_region.merge(
418
+ storage: :s3,
419
+ styles: { thumb: ["90x90#", :jpg] },
420
+ bucket: "bucket",
421
+ s3_acl_enabled: false,
422
+ s3_credentials: {
423
+ "access_key_id" => "12345",
424
+ "secret_access_key" => "54321"
425
+ }
426
+ )
427
+ )
428
+
429
+ @file = File.new(fixture_file("5k.png"), "rb")
430
+ @dummy = Dummy.new
431
+ @dummy.avatar = @file
432
+ @dummy.save
433
+ end
434
+
435
+ context "reprocess" do
436
+ before do
437
+ @object = double
438
+ allow(@dummy.avatar).to receive(:s3_object).with(:original).and_return(@object)
439
+ allow(@dummy.avatar).to receive(:s3_object).with(:thumb).and_return(@object)
440
+ allow(@object).to receive(:get).and_yield(@file.read)
441
+ allow(@object).to receive(:exists?).and_return(true)
442
+ allow(@object).to receive(:download_file).with(anything)
443
+ end
444
+
445
+ it "uploads original" do
446
+ expect(@object).to receive(:upload_file).with(
447
+ anything,
448
+ content_type: "image/png",
449
+ ).and_return(true)
450
+ @dummy.avatar.reprocess!
451
+ expect(@object).to receive(:upload_file).with(
452
+ anything,
453
+ content_type: "image/png",
454
+ ).and_return(true)
455
+ @dummy.avatar.reprocess!
456
+ end
457
+
458
+ it "doesn't upload original" do
459
+ expect(@object).to receive(:upload_file).with(
460
+ anything,
461
+ content_type: "image/png",
462
+ ).and_return(true)
463
+ @dummy.avatar.reprocess!
464
+ end
465
+ end
466
+
467
+ after { @file.close }
468
+ end
469
+
414
470
  context "An attachment that uses S3 for storage and has styles" do
415
471
  before do
416
472
  rebuild_model(
@@ -940,6 +996,19 @@ describe Paperclip::Storage::S3 do
940
996
  end
941
997
  end
942
998
 
999
+ context "and remove, calling S3 Object destroy once per unique style" do
1000
+ before do
1001
+ allow_any_instance_of(Aws::S3::Object).to receive(:exists?).and_return(true)
1002
+ expect_any_instance_of(Aws::S3::Object).to receive(:delete).once
1003
+ @dummy.avatar.clear(:original)
1004
+ @dummy.destroy
1005
+ end
1006
+
1007
+ it "succeeds" do
1008
+ assert true
1009
+ end
1010
+ end
1011
+
943
1012
  context "that the file were missing" do
944
1013
  before do
945
1014
  allow_any_instance_of(Aws::S3::Object).to receive(:exists?).
@@ -1,6 +1,11 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Paperclip::Validators do
4
+ # required to support a range of rubies
5
+ def error_attribute_names(error)
6
+ error.try(:attribute_names) || error.keys
7
+ end
8
+
4
9
  context "using the helper" do
5
10
  before do
6
11
  rebuild_class
@@ -22,7 +27,9 @@ describe Paperclip::Validators do
22
27
  it "prevents you from attaching a file that violates that validation" do
23
28
  Dummy.class_eval { validate(:name) { raise "DO NOT RUN THIS" } }
24
29
  dummy = Dummy.new(avatar: File.new(fixture_file("12k.png")))
25
- expect(dummy.errors.keys).to match_array [:avatar_content_type, :avatar, :avatar_file_size]
30
+ expect(error_attribute_names(dummy.errors)).to match_array(
31
+ %i[avatar_content_type avatar avatar_file_size]
32
+ )
26
33
  assert_raises(RuntimeError) { dummy.valid? }
27
34
  end
28
35
  end
@@ -47,21 +54,27 @@ describe Paperclip::Validators do
47
54
  it "prevents you from attaching a file that violates all of these validations" do
48
55
  Dummy.class_eval { validate(:name) { raise "DO NOT RUN THIS" } }
49
56
  dummy = Dummy.new(avatar: File.new(fixture_file("spaced file.png")))
50
- expect(dummy.errors.keys).to match_array [:avatar, :avatar_file_name]
57
+ expect(error_attribute_names(dummy.errors)).to match_array(
58
+ %i[avatar avatar_file_name]
59
+ )
51
60
  assert_raises(RuntimeError) { dummy.valid? }
52
61
  end
53
62
 
54
63
  it "prevents you from attaching a file that violates only first of these validations" do
55
64
  Dummy.class_eval { validate(:name) { raise "DO NOT RUN THIS" } }
56
65
  dummy = Dummy.new(avatar: File.new(fixture_file("5k.png")))
57
- expect(dummy.errors.keys).to match_array [:avatar, :avatar_file_name]
66
+ expect(error_attribute_names(dummy.errors)).to match_array(
67
+ %i[avatar avatar_file_name]
68
+ )
58
69
  assert_raises(RuntimeError) { dummy.valid? }
59
70
  end
60
71
 
61
72
  it "prevents you from attaching a file that violates only second of these validations" do
62
73
  Dummy.class_eval { validate(:name) { raise "DO NOT RUN THIS" } }
63
74
  dummy = Dummy.new(avatar: File.new(fixture_file("spaced file.jpg")))
64
- expect(dummy.errors.keys).to match_array [:avatar, :avatar_file_name]
75
+ expect(error_attribute_names(dummy.errors)).to match_array(
76
+ %i[avatar avatar_file_name]
77
+ )
65
78
  assert_raises(RuntimeError) { dummy.valid? }
66
79
  end
67
80
 
@@ -88,7 +101,9 @@ describe Paperclip::Validators do
88
101
  end
89
102
  end
90
103
  dummy = Dummy.new(avatar: File.new(fixture_file("12k.png")))
91
- expect(dummy.errors.keys).to match_array [:avatar_content_type, :avatar, :avatar_file_size]
104
+ expect(error_attribute_names(dummy.errors)).to match_array(
105
+ %i[avatar_content_type avatar avatar_file_size]
106
+ )
92
107
  end
93
108
 
94
109
  it "does not validate attachment if title is not present" do
@@ -98,7 +113,7 @@ describe Paperclip::Validators do
98
113
  end
99
114
  end
100
115
  dummy = Dummy.new(avatar: File.new(fixture_file("12k.png")))
101
- assert_equal [], dummy.errors.keys
116
+ assert_equal [], error_attribute_names(dummy.errors)
102
117
  end
103
118
  end
104
119
 
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kt-paperclip
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.4.2
4
+ version: 7.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Surendra Singhi
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-13 00:00:00.000000000 Z
11
+ date: 2023-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -53,19 +53,19 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: mimemagic
56
+ name: marcel
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.3.0
61
+ version: 1.0.1
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.3.0
68
+ version: 1.0.1
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: terrapin
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -393,6 +393,8 @@ files:
393
393
  - gemfiles/5.1.gemfile
394
394
  - gemfiles/5.2.gemfile
395
395
  - gemfiles/6.0.gemfile
396
+ - gemfiles/6.1.gemfile
397
+ - gemfiles/7.0.gemfile
396
398
  - lib/generators/paperclip/USAGE
397
399
  - lib/generators/paperclip/paperclip_generator.rb
398
400
  - lib/generators/paperclip/templates/paperclip_migration.rb.erb
@@ -532,6 +534,7 @@ files:
532
534
  - spec/support/fixtures/fog.yml
533
535
  - spec/support/fixtures/rotated.jpg
534
536
  - spec/support/fixtures/s3.yml
537
+ - spec/support/fixtures/sample.xlsm
535
538
  - spec/support/fixtures/spaced file.jpg
536
539
  - spec/support/fixtures/spaced file.png
537
540
  - spec/support/fixtures/text.txt
@@ -576,7 +579,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
576
579
  requirements:
577
580
  - - ">="
578
581
  - !ruby/object:Gem::Version
579
- version: 2.2.0
582
+ version: 2.3.0
580
583
  required_rubygems_version: !ruby/object:Gem::Requirement
581
584
  requirements:
582
585
  - - ">="
@@ -585,7 +588,113 @@ required_rubygems_version: !ruby/object:Gem::Requirement
585
588
  requirements:
586
589
  - ImageMagick
587
590
  rubygems_version: 3.1.6
588
- signing_key:
591
+ signing_key:
589
592
  specification_version: 4
590
593
  summary: File attachments as attributes for ActiveRecord
591
- test_files: []
594
+ test_files:
595
+ - features/basic_integration.feature
596
+ - features/migration.feature
597
+ - features/rake_tasks.feature
598
+ - features/step_definitions/attachment_steps.rb
599
+ - features/step_definitions/html_steps.rb
600
+ - features/step_definitions/rails_steps.rb
601
+ - features/step_definitions/s3_steps.rb
602
+ - features/step_definitions/web_steps.rb
603
+ - features/support/env.rb
604
+ - features/support/fakeweb.rb
605
+ - features/support/file_helpers.rb
606
+ - features/support/fixtures/boot_config.txt
607
+ - features/support/fixtures/gemfile.txt
608
+ - features/support/fixtures/preinitializer.txt
609
+ - features/support/paths.rb
610
+ - features/support/rails.rb
611
+ - features/support/selectors.rb
612
+ - spec/database.yml
613
+ - spec/paperclip/attachment_definitions_spec.rb
614
+ - spec/paperclip/attachment_processing_spec.rb
615
+ - spec/paperclip/attachment_registry_spec.rb
616
+ - spec/paperclip/attachment_spec.rb
617
+ - spec/paperclip/content_type_detector_spec.rb
618
+ - spec/paperclip/file_command_content_type_detector_spec.rb
619
+ - spec/paperclip/filename_cleaner_spec.rb
620
+ - spec/paperclip/geometry_detector_spec.rb
621
+ - spec/paperclip/geometry_parser_spec.rb
622
+ - spec/paperclip/geometry_spec.rb
623
+ - spec/paperclip/glue_spec.rb
624
+ - spec/paperclip/has_attached_file_spec.rb
625
+ - spec/paperclip/integration_spec.rb
626
+ - spec/paperclip/interpolations_spec.rb
627
+ - spec/paperclip/io_adapters/abstract_adapter_spec.rb
628
+ - spec/paperclip/io_adapters/attachment_adapter_spec.rb
629
+ - spec/paperclip/io_adapters/data_uri_adapter_spec.rb
630
+ - spec/paperclip/io_adapters/empty_string_adapter_spec.rb
631
+ - spec/paperclip/io_adapters/file_adapter_spec.rb
632
+ - spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb
633
+ - spec/paperclip/io_adapters/identity_adapter_spec.rb
634
+ - spec/paperclip/io_adapters/nil_adapter_spec.rb
635
+ - spec/paperclip/io_adapters/registry_spec.rb
636
+ - spec/paperclip/io_adapters/stringio_adapter_spec.rb
637
+ - spec/paperclip/io_adapters/uploaded_file_adapter_spec.rb
638
+ - spec/paperclip/io_adapters/uri_adapter_spec.rb
639
+ - spec/paperclip/matchers/have_attached_file_matcher_spec.rb
640
+ - spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb
641
+ - spec/paperclip/matchers/validate_attachment_presence_matcher_spec.rb
642
+ - spec/paperclip/matchers/validate_attachment_size_matcher_spec.rb
643
+ - spec/paperclip/media_type_spoof_detector_spec.rb
644
+ - spec/paperclip/meta_class_spec.rb
645
+ - spec/paperclip/paperclip_missing_attachment_styles_spec.rb
646
+ - spec/paperclip/paperclip_spec.rb
647
+ - spec/paperclip/plural_cache_spec.rb
648
+ - spec/paperclip/processor_helpers_spec.rb
649
+ - spec/paperclip/processor_spec.rb
650
+ - spec/paperclip/rails_environment_spec.rb
651
+ - spec/paperclip/rake_spec.rb
652
+ - spec/paperclip/schema_spec.rb
653
+ - spec/paperclip/storage/filesystem_spec.rb
654
+ - spec/paperclip/storage/fog_spec.rb
655
+ - spec/paperclip/storage/s3_live_spec.rb
656
+ - spec/paperclip/storage/s3_spec.rb
657
+ - spec/paperclip/style_spec.rb
658
+ - spec/paperclip/tempfile_factory_spec.rb
659
+ - spec/paperclip/tempfile_spec.rb
660
+ - spec/paperclip/thumbnail_spec.rb
661
+ - spec/paperclip/url_generator_spec.rb
662
+ - spec/paperclip/validators/attachment_content_type_validator_spec.rb
663
+ - spec/paperclip/validators/attachment_file_name_validator_spec.rb
664
+ - spec/paperclip/validators/attachment_presence_validator_spec.rb
665
+ - spec/paperclip/validators/attachment_size_validator_spec.rb
666
+ - spec/paperclip/validators/media_type_spoof_detection_validator_spec.rb
667
+ - spec/paperclip/validators_spec.rb
668
+ - spec/spec_helper.rb
669
+ - spec/support/assertions.rb
670
+ - spec/support/fake_model.rb
671
+ - spec/support/fake_rails.rb
672
+ - spec/support/fixtures/12k.png
673
+ - spec/support/fixtures/50x50.png
674
+ - spec/support/fixtures/5k.png
675
+ - spec/support/fixtures/animated
676
+ - spec/support/fixtures/animated.gif
677
+ - spec/support/fixtures/animated.unknown
678
+ - spec/support/fixtures/aws_s3.yml
679
+ - spec/support/fixtures/bad.png
680
+ - spec/support/fixtures/empty.html
681
+ - spec/support/fixtures/empty.xlsx
682
+ - spec/support/fixtures/fog.yml
683
+ - spec/support/fixtures/rotated.jpg
684
+ - spec/support/fixtures/s3.yml
685
+ - spec/support/fixtures/sample.xlsm
686
+ - spec/support/fixtures/spaced file.jpg
687
+ - spec/support/fixtures/spaced file.png
688
+ - spec/support/fixtures/text.txt
689
+ - spec/support/fixtures/twopage.pdf
690
+ - spec/support/fixtures/uppercase.PNG
691
+ - spec/support/matchers/accept.rb
692
+ - spec/support/matchers/exist.rb
693
+ - spec/support/matchers/have_column.rb
694
+ - spec/support/mock_attachment.rb
695
+ - spec/support/mock_interpolator.rb
696
+ - spec/support/mock_url_generator_builder.rb
697
+ - spec/support/model_reconstruction.rb
698
+ - spec/support/reporting.rb
699
+ - spec/support/test_data.rb
700
+ - spec/support/version_helper.rb