kt-paperclip 6.2.0 → 7.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +3 -0
  3. data/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
  4. data/.github/ISSUE_TEMPLATE/custom.md +10 -0
  5. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  6. data/.hound.yml +3 -1050
  7. data/.rubocop.yml +1061 -1
  8. data/.travis.yml +12 -14
  9. data/Appraisals +6 -0
  10. data/CONTRIBUTING.md +4 -5
  11. data/Gemfile +5 -4
  12. data/NEWS +31 -0
  13. data/README.md +41 -19
  14. data/features/step_definitions/attachment_steps.rb +11 -1
  15. data/gemfiles/4.2.gemfile +1 -1
  16. data/gemfiles/5.0.gemfile +1 -1
  17. data/gemfiles/5.1.gemfile +1 -1
  18. data/gemfiles/5.2.gemfile +1 -1
  19. data/gemfiles/6.0.gemfile +1 -1
  20. data/gemfiles/6.1.gemfile +21 -0
  21. data/gemfiles/7.0.gemfile +21 -0
  22. data/lib/kt-paperclip.rb +1 -0
  23. data/lib/paperclip/attachment.rb +1 -1
  24. data/lib/paperclip/content_type_detector.rb +10 -5
  25. data/lib/paperclip/io_adapters/http_url_proxy_adapter.rb +2 -2
  26. data/lib/paperclip/io_adapters/uri_adapter.rb +13 -3
  27. data/lib/paperclip/schema.rb +2 -2
  28. data/lib/paperclip/storage/filesystem.rb +1 -1
  29. data/lib/paperclip/storage/fog.rb +1 -1
  30. data/lib/paperclip/storage/s3.rb +3 -3
  31. data/lib/paperclip/url_generator.rb +8 -1
  32. data/lib/paperclip/validators/attachment_content_type_validator.rb +9 -2
  33. data/lib/paperclip/validators/attachment_file_name_validator.rb +10 -3
  34. data/lib/paperclip/validators/attachment_presence_validator.rb +1 -1
  35. data/lib/paperclip/validators/attachment_size_validator.rb +21 -4
  36. data/lib/paperclip/validators.rb +4 -4
  37. data/lib/paperclip/version.rb +1 -1
  38. data/lib/paperclip.rb +3 -3
  39. data/paperclip.gemspec +4 -4
  40. data/spec/paperclip/content_type_detector_spec.rb +7 -0
  41. data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +1 -1
  42. data/spec/paperclip/io_adapters/file_adapter_spec.rb +1 -1
  43. data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +20 -15
  44. data/spec/paperclip/io_adapters/uri_adapter_spec.rb +13 -3
  45. data/spec/paperclip/storage/filesystem_spec.rb +23 -0
  46. data/spec/paperclip/storage/fog_spec.rb +46 -0
  47. data/spec/paperclip/storage/s3_spec.rb +67 -3
  48. data/spec/paperclip/url_generator_spec.rb +10 -0
  49. data/spec/paperclip/validators/attachment_content_type_validator_spec.rb +88 -0
  50. data/spec/paperclip/validators/attachment_file_name_validator_spec.rb +90 -0
  51. data/spec/paperclip/validators/attachment_size_validator_spec.rb +90 -0
  52. data/spec/paperclip/validators_spec.rb +21 -6
  53. data/spec/support/fixtures/aws_s3.yml +13 -0
  54. data/spec/support/fixtures/sample.xlsm +0 -0
  55. data/spec/support/model_reconstruction.rb +1 -1
  56. metadata +20 -12
  57. data/.github/issue_template.md +0 -3
@@ -205,6 +205,96 @@ describe Paperclip::Validators::AttachmentSizeValidator do
205
205
  end
206
206
  end
207
207
 
208
+ context "with add_validation_errors_to not set (implicitly :both)" do
209
+ it "adds error to both attribute and base" do
210
+ build_validator in: (5.kilobytes..10.kilobytes)
211
+ allow(@dummy).to receive(:avatar_file_size).and_return(11.kilobytes)
212
+ @validator.validate(@dummy)
213
+
214
+ assert @dummy.errors[:avatar_file_size].present?,
215
+ "Error not added to attribute"
216
+
217
+ assert @dummy.errors[:avatar].present?,
218
+ "Error not added to base attribute"
219
+ end
220
+ end
221
+
222
+ context "with add_validation_errors_to set to :attribute globally" do
223
+ before do
224
+ Paperclip.options[:add_validation_errors_to] = :attribute
225
+ end
226
+
227
+ after do
228
+ Paperclip.options[:add_validation_errors_to] = :both
229
+ end
230
+
231
+ it "only adds error to attribute not base" do
232
+ build_validator in: (5.kilobytes..10.kilobytes)
233
+ allow(@dummy).to receive(:avatar_file_size).and_return(11.kilobytes)
234
+ @validator.validate(@dummy)
235
+
236
+ assert @dummy.errors[:avatar_file_size].present?,
237
+ "Error not added to attribute"
238
+
239
+ assert @dummy.errors[:avatar].blank?,
240
+ "Error added to base attribute"
241
+ end
242
+ end
243
+
244
+ context "with add_validation_errors_to set to :base globally" do
245
+ before do
246
+ Paperclip.options[:add_validation_errors_to] = :base
247
+ end
248
+
249
+ after do
250
+ Paperclip.options[:add_validation_errors_to] = :both
251
+ end
252
+
253
+ it "only adds error to base not attribute" do
254
+ build_validator in: (5.kilobytes..10.kilobytes)
255
+ allow(@dummy).to receive(:avatar_file_size).and_return(11.kilobytes)
256
+ @validator.validate(@dummy)
257
+
258
+ assert @dummy.errors[:avatar].present?,
259
+ "Error not added to base attribute"
260
+
261
+ assert @dummy.errors[:avatar_file_size].blank?,
262
+ "Error added to attribute"
263
+ end
264
+ end
265
+
266
+ context "with add_validation_errors_to set to :attribute" do
267
+ it "only adds error to attribute not base" do
268
+ build_validator in: (5.kilobytes..10.kilobytes),
269
+ add_validation_errors_to: :attribute
270
+
271
+ allow(@dummy).to receive(:avatar_file_size).and_return(11.kilobytes)
272
+ @validator.validate(@dummy)
273
+
274
+ assert @dummy.errors[:avatar_file_size].present?,
275
+ "Error not added to attribute"
276
+
277
+ assert @dummy.errors[:avatar].blank?,
278
+ "Error added to base attribute"
279
+ end
280
+ end
281
+
282
+ context "with add_validation_errors_to set to :base" do
283
+ it "only adds error to base not attribute" do
284
+ build_validator in: (5.kilobytes..10.kilobytes),
285
+ add_validation_errors_to: :base
286
+
287
+ allow(@dummy).to receive(:avatar_file_size).and_return(11.kilobytes)
288
+ @validator.validate(@dummy)
289
+
290
+ assert @dummy.errors[:avatar].present?,
291
+ "Error not added to base attribute"
292
+
293
+ assert @dummy.errors[:avatar_file_size].blank?,
294
+ "Error added to attribute"
295
+ end
296
+ end
297
+
208
298
  context "using the helper" do
209
299
  before do
210
300
  Dummy.validates_attachment_size :avatar, in: (5.kilobytes..10.kilobytes)
@@ -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
 
@@ -0,0 +1,13 @@
1
+ default: &default
2
+ acl: public-read
3
+ development:
4
+ <<: *default
5
+ key: 54321
6
+ production:
7
+ <<: *default
8
+ key: 12345
9
+ test:
10
+ <<: *default
11
+ bucket: <%= ENV['S3_BUCKET'] %>
12
+ access_key_id: <%= ENV['S3_KEY'] %>
13
+ secret_access_key: <%= ENV['S3_SECRET'] %>
Binary file
@@ -28,7 +28,7 @@ module ModelReconstruction
28
28
 
29
29
  def reset_table(_table_name, &block)
30
30
  block ||= lambda { |_table| true }
31
- ActiveRecord::Base.connection.create_table :dummies, { force: true }, &block
31
+ ActiveRecord::Base.connection.create_table :dummies, **{ force: true }, &block
32
32
  end
33
33
 
34
34
  def modify_table(&block)
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.2.0
4
+ version: 7.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Surendra Singhi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-22 00:00:00.000000000 Z
11
+ date: 2022-02-09 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
@@ -168,16 +168,16 @@ dependencies:
168
168
  name: cucumber-expressions
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
- - - '='
171
+ - - ">="
172
172
  - !ruby/object:Gem::Version
173
- version: 4.0.3
173
+ version: '0'
174
174
  type: :development
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
- - - '='
178
+ - - ">="
179
179
  - !ruby/object:Gem::Version
180
- version: 4.0.3
180
+ version: '0'
181
181
  - !ruby/object:Gem::Dependency
182
182
  name: cucumber-rails
183
183
  requirement: !ruby/object:Gem::Requirement
@@ -354,7 +354,10 @@ extensions: []
354
354
  extra_rdoc_files: []
355
355
  files:
356
356
  - ".codeclimate.yml"
357
- - ".github/issue_template.md"
357
+ - ".github/FUNDING.yml"
358
+ - ".github/ISSUE_TEMPLATE/bug_report.md"
359
+ - ".github/ISSUE_TEMPLATE/custom.md"
360
+ - ".github/ISSUE_TEMPLATE/feature_request.md"
358
361
  - ".gitignore"
359
362
  - ".hound.yml"
360
363
  - ".rubocop.yml"
@@ -390,9 +393,12 @@ files:
390
393
  - gemfiles/5.1.gemfile
391
394
  - gemfiles/5.2.gemfile
392
395
  - gemfiles/6.0.gemfile
396
+ - gemfiles/6.1.gemfile
397
+ - gemfiles/7.0.gemfile
393
398
  - lib/generators/paperclip/USAGE
394
399
  - lib/generators/paperclip/paperclip_generator.rb
395
400
  - lib/generators/paperclip/templates/paperclip_migration.rb.erb
401
+ - lib/kt-paperclip.rb
396
402
  - lib/paperclip.rb
397
403
  - lib/paperclip/attachment.rb
398
404
  - lib/paperclip/attachment_registry.rb
@@ -521,12 +527,14 @@ files:
521
527
  - spec/support/fixtures/animated
522
528
  - spec/support/fixtures/animated.gif
523
529
  - spec/support/fixtures/animated.unknown
530
+ - spec/support/fixtures/aws_s3.yml
524
531
  - spec/support/fixtures/bad.png
525
532
  - spec/support/fixtures/empty.html
526
533
  - spec/support/fixtures/empty.xlsx
527
534
  - spec/support/fixtures/fog.yml
528
535
  - spec/support/fixtures/rotated.jpg
529
536
  - spec/support/fixtures/s3.yml
537
+ - spec/support/fixtures/sample.xlsm
530
538
  - spec/support/fixtures/spaced file.jpg
531
539
  - spec/support/fixtures/spaced file.png
532
540
  - spec/support/fixtures/text.txt
@@ -542,7 +550,7 @@ files:
542
550
  - spec/support/reporting.rb
543
551
  - spec/support/test_data.rb
544
552
  - spec/support/version_helper.rb
545
- homepage: https://github.com/kreeti/paperclip
553
+ homepage: https://github.com/kreeti/kt-paperclip
546
554
  licenses:
547
555
  - MIT
548
556
  metadata: {}
@@ -571,7 +579,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
571
579
  requirements:
572
580
  - - ">="
573
581
  - !ruby/object:Gem::Version
574
- version: 2.1.0
582
+ version: 2.3.0
575
583
  required_rubygems_version: !ruby/object:Gem::Requirement
576
584
  requirements:
577
585
  - - ">="
@@ -1,3 +0,0 @@
1
- ## Deprecation notice
2
-
3
- Paperclip is currently undergoing [deprecation in favor of ActiveStorage](https://github.com/thoughtbot/paperclip/blob/master/MIGRATING.md). Maintainers of this repository will no longer be tending to new issues. We're leaving the issues page open so Paperclip users can still see & search through old issues, and continue existing discussions if they wish.