kt-paperclip 6.2.1 → 7.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.
Files changed (46) 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 +364 -357
  7. data/.rubocop.yml +2 -0
  8. data/.travis.yml +12 -14
  9. data/Appraisals +6 -0
  10. data/Gemfile +3 -3
  11. data/NEWS +28 -0
  12. data/README.md +41 -19
  13. data/features/step_definitions/attachment_steps.rb +11 -1
  14. data/gemfiles/4.2.gemfile +1 -1
  15. data/gemfiles/5.0.gemfile +1 -1
  16. data/gemfiles/5.1.gemfile +1 -1
  17. data/gemfiles/5.2.gemfile +1 -1
  18. data/gemfiles/6.0.gemfile +1 -1
  19. data/gemfiles/6.1.gemfile +21 -0
  20. data/lib/paperclip.rb +3 -3
  21. data/lib/paperclip/content_type_detector.rb +4 -4
  22. data/lib/paperclip/io_adapters/http_url_proxy_adapter.rb +2 -2
  23. data/lib/paperclip/io_adapters/uri_adapter.rb +13 -3
  24. data/lib/paperclip/schema.rb +2 -2
  25. data/lib/paperclip/storage/s3.rb +2 -2
  26. data/lib/paperclip/url_generator.rb +8 -1
  27. data/lib/paperclip/validators.rb +4 -4
  28. data/lib/paperclip/validators/attachment_content_type_validator.rb +9 -2
  29. data/lib/paperclip/validators/attachment_file_name_validator.rb +9 -2
  30. data/lib/paperclip/validators/attachment_presence_validator.rb +1 -1
  31. data/lib/paperclip/validators/attachment_size_validator.rb +18 -2
  32. data/lib/paperclip/version.rb +1 -1
  33. data/paperclip.gemspec +4 -4
  34. data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +1 -1
  35. data/spec/paperclip/io_adapters/file_adapter_spec.rb +1 -1
  36. data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +20 -15
  37. data/spec/paperclip/io_adapters/uri_adapter_spec.rb +13 -3
  38. data/spec/paperclip/storage/s3_spec.rb +54 -3
  39. data/spec/paperclip/url_generator_spec.rb +10 -0
  40. data/spec/paperclip/validators/attachment_content_type_validator_spec.rb +88 -0
  41. data/spec/paperclip/validators/attachment_file_name_validator_spec.rb +90 -0
  42. data/spec/paperclip/validators/attachment_size_validator_spec.rb +90 -0
  43. data/spec/support/fixtures/aws_s3.yml +13 -0
  44. data/spec/support/model_reconstruction.rb +1 -1
  45. metadata +17 -12
  46. data/.github/issue_template.md +0 -3
@@ -67,6 +67,94 @@ describe Paperclip::Validators::AttachmentContentTypeValidator do
67
67
  end
68
68
  end
69
69
 
70
+ context "with add_validation_errors_to not set (implicitly :both)" do
71
+ it "adds error to both attribute and base" do
72
+ build_validator content_type: "image/png", allow_nil: false
73
+ allow(@dummy).to receive_messages(avatar_content_type: nil)
74
+ @validator.validate(@dummy)
75
+
76
+ assert @dummy.errors[:avatar_content_type].present?,
77
+ "Error not added to attribute"
78
+
79
+ assert @dummy.errors[:avatar].present?,
80
+ "Error not added to base attribute"
81
+ end
82
+ end
83
+
84
+ context "with add_validation_errors_to set to :attribute globally" do
85
+ before do
86
+ Paperclip.options[:add_validation_errors_to] = :attribute
87
+ end
88
+
89
+ after do
90
+ Paperclip.options[:add_validation_errors_to] = :both
91
+ end
92
+
93
+ it "only adds error to attribute not base" do
94
+ build_validator content_type: "image/png", allow_nil: false
95
+ allow(@dummy).to receive_messages(avatar_content_type: nil)
96
+ @validator.validate(@dummy)
97
+
98
+ assert @dummy.errors[:avatar_content_type].present?,
99
+ "Error not added to attribute"
100
+
101
+ assert @dummy.errors[:avatar].blank?,
102
+ "Error added to base attribute"
103
+ end
104
+ end
105
+
106
+ context "with add_validation_errors_to set to :base globally" do
107
+ before do
108
+ Paperclip.options[:add_validation_errors_to] = :base
109
+ end
110
+
111
+ after do
112
+ Paperclip.options[:add_validation_errors_to] = :both
113
+ end
114
+
115
+ it "only adds error to base not attribute" do
116
+ build_validator content_type: "image/png", allow_nil: false
117
+ allow(@dummy).to receive_messages(avatar_content_type: nil)
118
+ @validator.validate(@dummy)
119
+
120
+ assert @dummy.errors[:avatar].present?,
121
+ "Error not added to base attribute"
122
+
123
+ assert @dummy.errors[:avatar_content_type].blank?,
124
+ "Error added to attribute"
125
+ end
126
+ end
127
+
128
+ context "with add_validation_errors_to set to :attribute" do
129
+ it "only adds error to attribute not base" do
130
+ build_validator content_type: "image/png", allow_nil: false,
131
+ add_validation_errors_to: :attribute
132
+ allow(@dummy).to receive_messages(avatar_content_type: nil)
133
+ @validator.validate(@dummy)
134
+
135
+ assert @dummy.errors[:avatar_content_type].present?,
136
+ "Error not added to attribute"
137
+
138
+ assert @dummy.errors[:avatar].blank?,
139
+ "Error added to base attribute"
140
+ end
141
+ end
142
+
143
+ context "with add_validation_errors_to set to :base" do
144
+ it "only adds error to base not attribute" do
145
+ build_validator content_type: "image/png", allow_nil: false,
146
+ add_validation_errors_to: :base
147
+ allow(@dummy).to receive_messages(avatar_content_type: nil)
148
+ @validator.validate(@dummy)
149
+
150
+ assert @dummy.errors[:avatar].present?,
151
+ "Error not added to base attribute"
152
+
153
+ assert @dummy.errors[:avatar_content_type].blank?,
154
+ "Error added to attribute"
155
+ end
156
+ end
157
+
70
158
  context "with a successful validation" do
71
159
  before do
72
160
  build_validator content_type: "image/png", allow_nil: false
@@ -29,6 +29,96 @@ describe Paperclip::Validators::AttachmentFileNameValidator do
29
29
  end
30
30
  end
31
31
 
32
+ context "with add_validation_errors_to not set (implicitly :both)" do
33
+ it "adds error to both attribute and base" do
34
+ build_validator matches: /.*\.png$/, allow_nil: false
35
+ allow(@dummy).to receive_messages(avatar_file_name: "data.txt")
36
+ @validator.validate(@dummy)
37
+
38
+ assert @dummy.errors[:avatar_file_name].present?,
39
+ "Error not added to attribute"
40
+
41
+ assert @dummy.errors[:avatar].present?,
42
+ "Error not added to base attribute"
43
+ end
44
+ end
45
+
46
+ context "with add_validation_errors_to set to :attribute globally" do
47
+ before do
48
+ Paperclip.options[:add_validation_errors_to] = :attribute
49
+ end
50
+
51
+ after do
52
+ Paperclip.options[:add_validation_errors_to] = :both
53
+ end
54
+
55
+ it "only adds error to attribute not base" do
56
+ build_validator matches: /.*\.png$/, allow_nil: false
57
+ allow(@dummy).to receive_messages(avatar_file_name: "data.txt")
58
+ @validator.validate(@dummy)
59
+
60
+ assert @dummy.errors[:avatar_file_name].present?,
61
+ "Error not added to attribute"
62
+
63
+ assert @dummy.errors[:avatar].blank?,
64
+ "Error added to base attribute"
65
+ end
66
+ end
67
+
68
+ context "with add_validation_errors_to set to :base globally" do
69
+ before do
70
+ Paperclip.options[:add_validation_errors_to] = :base
71
+ end
72
+
73
+ after do
74
+ Paperclip.options[:add_validation_errors_to] = :both
75
+ end
76
+
77
+ it "only adds error to base not attribute" do
78
+ build_validator matches: /.*\.png$/, allow_nil: false
79
+ allow(@dummy).to receive_messages(avatar_file_name: "data.txt")
80
+ @validator.validate(@dummy)
81
+
82
+ assert @dummy.errors[:avatar].present?,
83
+ "Error not added to base attribute"
84
+
85
+ assert @dummy.errors[:avatar_file_name].blank?,
86
+ "Error added to attribute"
87
+ end
88
+ end
89
+
90
+ context "with add_validation_errors_to set to :attribute" do
91
+ it "only adds error to attribute not base" do
92
+ build_validator matches: /.*\.png$/, allow_nil: false,
93
+ add_validation_errors_to: :attribute
94
+
95
+ allow(@dummy).to receive_messages(avatar_file_name: "data.txt")
96
+ @validator.validate(@dummy)
97
+
98
+ assert @dummy.errors[:avatar_file_name].present?,
99
+ "Error not added to attribute"
100
+
101
+ assert @dummy.errors[:avatar].blank?,
102
+ "Error added to base attribute"
103
+ end
104
+ end
105
+
106
+ context "with add_validation_errors_to set to :base" do
107
+ it "only adds error to base not attribute" do
108
+ build_validator matches: /.*\.png$/, allow_nil: false,
109
+ add_validation_errors_to: :base
110
+
111
+ allow(@dummy).to receive_messages(avatar_file_name: "data.txt")
112
+ @validator.validate(@dummy)
113
+
114
+ assert @dummy.errors[:avatar].present?,
115
+ "Error not added to base attribute"
116
+
117
+ assert @dummy.errors[:avatar_file_name].blank?,
118
+ "Error added to attribute"
119
+ end
120
+ end
121
+
32
122
  it "does not add error to the base object with a successful validation" do
33
123
  build_validator matches: /.*\.png$/, allow_nil: false
34
124
  allow(@dummy).to receive_messages(avatar_file_name: "image.png")
@@ -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)
@@ -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'] %>
@@ -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.1
4
+ version: 7.0.0
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-30 00:00:00.000000000 Z
11
+ date: 2021-05-28 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,6 +393,7 @@ files:
390
393
  - gemfiles/5.1.gemfile
391
394
  - gemfiles/5.2.gemfile
392
395
  - gemfiles/6.0.gemfile
396
+ - gemfiles/6.1.gemfile
393
397
  - lib/generators/paperclip/USAGE
394
398
  - lib/generators/paperclip/paperclip_generator.rb
395
399
  - lib/generators/paperclip/templates/paperclip_migration.rb.erb
@@ -522,6 +526,7 @@ files:
522
526
  - spec/support/fixtures/animated
523
527
  - spec/support/fixtures/animated.gif
524
528
  - spec/support/fixtures/animated.unknown
529
+ - spec/support/fixtures/aws_s3.yml
525
530
  - spec/support/fixtures/bad.png
526
531
  - spec/support/fixtures/empty.html
527
532
  - spec/support/fixtures/empty.xlsx
@@ -543,7 +548,7 @@ files:
543
548
  - spec/support/reporting.rb
544
549
  - spec/support/test_data.rb
545
550
  - spec/support/version_helper.rb
546
- homepage: https://github.com/kreeti/paperclip
551
+ homepage: https://github.com/kreeti/kt-paperclip
547
552
  licenses:
548
553
  - MIT
549
554
  metadata: {}
@@ -572,7 +577,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
572
577
  requirements:
573
578
  - - ">="
574
579
  - !ruby/object:Gem::Version
575
- version: 2.1.0
580
+ version: 2.3.0
576
581
  required_rubygems_version: !ruby/object:Gem::Requirement
577
582
  requirements:
578
583
  - - ">="
@@ -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.