kt-paperclip 6.2.0 → 6.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) 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 +7 -9
  9. data/Gemfile +3 -2
  10. data/README.md +38 -17
  11. data/lib/kt-paperclip.rb +1 -0
  12. data/lib/paperclip/io_adapters/http_url_proxy_adapter.rb +2 -2
  13. data/lib/paperclip/io_adapters/uri_adapter.rb +13 -3
  14. data/lib/paperclip/schema.rb +2 -2
  15. data/lib/paperclip/storage/s3.rb +2 -2
  16. data/lib/paperclip/url_generator.rb +8 -1
  17. data/lib/paperclip/validators/attachment_content_type_validator.rb +9 -2
  18. data/lib/paperclip/validators/attachment_file_name_validator.rb +9 -2
  19. data/lib/paperclip/validators/attachment_presence_validator.rb +1 -1
  20. data/lib/paperclip/validators/attachment_size_validator.rb +18 -2
  21. data/lib/paperclip/validators.rb +4 -4
  22. data/lib/paperclip/version.rb +1 -1
  23. data/lib/paperclip.rb +2 -1
  24. data/paperclip.gemspec +3 -3
  25. data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +20 -15
  26. data/spec/paperclip/io_adapters/uri_adapter_spec.rb +13 -3
  27. data/spec/paperclip/storage/s3_spec.rb +54 -3
  28. data/spec/paperclip/url_generator_spec.rb +10 -0
  29. data/spec/paperclip/validators/attachment_content_type_validator_spec.rb +88 -0
  30. data/spec/paperclip/validators/attachment_file_name_validator_spec.rb +90 -0
  31. data/spec/paperclip/validators/attachment_size_validator_spec.rb +90 -0
  32. data/spec/support/fixtures/aws_s3.yml +13 -0
  33. data/spec/support/model_reconstruction.rb +1 -1
  34. metadata +15 -10
  35. data/.github/issue_template.md +0 -3
@@ -805,9 +805,7 @@ describe Paperclip::Storage::S3 do
805
805
  s3_region: "ap-northeast-1",
806
806
  s3_host_name: "s3-ap-northeast-1.amazonaws.com"
807
807
  },
808
- test: {
809
- s3_region: ""
810
- }
808
+ test: {}
811
809
  }
812
810
  @dummy = Dummy.new
813
811
  end
@@ -1439,6 +1437,32 @@ describe Paperclip::Storage::S3 do
1439
1437
  end
1440
1438
  end
1441
1439
 
1440
+ context "with S3 credentials supplied as Pathname and aliases being set" do
1441
+ before do
1442
+ ENV["S3_KEY"] = "pathname_key"
1443
+ ENV["S3_BUCKET"] = "pathname_bucket"
1444
+ ENV["S3_SECRET"] = "pathname_secret"
1445
+
1446
+ rails_env("test") do
1447
+ rebuild_model aws2_add_region.merge storage: :s3,
1448
+ s3_credentials: Pathname.new(fixture_file("aws_s3.yml"))
1449
+
1450
+ Dummy.delete_all
1451
+ @dummy = Dummy.new
1452
+ end
1453
+ end
1454
+
1455
+ it "parses the credentials" do
1456
+ assert_equal "pathname_bucket", @dummy.avatar.bucket_name
1457
+
1458
+ assert_equal "pathname_key",
1459
+ @dummy.avatar.s3_bucket.client.config.access_key_id
1460
+
1461
+ assert_equal "pathname_secret",
1462
+ @dummy.avatar.s3_bucket.client.config.secret_access_key
1463
+ end
1464
+ end
1465
+
1442
1466
  context "with S3 credentials in a YAML file" do
1443
1467
  before do
1444
1468
  ENV["S3_KEY"] = "env_key"
@@ -1466,6 +1490,33 @@ describe Paperclip::Storage::S3 do
1466
1490
  end
1467
1491
  end
1468
1492
 
1493
+ context "with S3 credentials in a YAML file and aliases being set" do
1494
+ before do
1495
+ ENV["S3_KEY"] = "env_key"
1496
+ ENV["S3_BUCKET"] = "env_bucket"
1497
+ ENV["S3_SECRET"] = "env_secret"
1498
+
1499
+ rails_env("test") do
1500
+ rebuild_model aws2_add_region.merge storage: :s3,
1501
+ s3_credentials: File.new(fixture_file("aws_s3.yml"))
1502
+
1503
+ Dummy.delete_all
1504
+
1505
+ @dummy = Dummy.new
1506
+ end
1507
+ end
1508
+
1509
+ it "runs the file through ERB" do
1510
+ assert_equal "env_bucket", @dummy.avatar.bucket_name
1511
+
1512
+ assert_equal "env_key",
1513
+ @dummy.avatar.s3_bucket.client.config.access_key_id
1514
+
1515
+ assert_equal "env_secret",
1516
+ @dummy.avatar.s3_bucket.client.config.secret_access_key
1517
+ end
1518
+ end
1519
+
1469
1520
  context "S3 Permissions" do
1470
1521
  context "defaults to :public_read" do
1471
1522
  before do
@@ -194,6 +194,16 @@ describe Paperclip::UrlGenerator do
194
194
  "expected the interpolator to be passed #{expected.inspect} but it wasn't"
195
195
  end
196
196
 
197
+ it "doesn't emit deprecation warnings" do
198
+ expected = "the expected result"
199
+ mock_interpolator = MockInterpolator.new(result: expected)
200
+ options = { interpolator: mock_interpolator }
201
+ mock_attachment = MockAttachment.new(options)
202
+ url_generator = Paperclip::UrlGenerator.new(mock_attachment)
203
+
204
+ expect { url_generator.for(:style_name, escape: true) }.to_not(output(/URI\.(un)?escape is obsolete/).to_stderr)
205
+ end
206
+
197
207
  describe "should be able to escape (, ), [, and ]." do
198
208
  def generate(expected, updated_at = nil)
199
209
  mock_interpolator = MockInterpolator.new(result: expected)
@@ -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.0
4
+ version: 6.4.2
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-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -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"
@@ -393,6 +396,7 @@ files:
393
396
  - lib/generators/paperclip/USAGE
394
397
  - lib/generators/paperclip/paperclip_generator.rb
395
398
  - lib/generators/paperclip/templates/paperclip_migration.rb.erb
399
+ - lib/kt-paperclip.rb
396
400
  - lib/paperclip.rb
397
401
  - lib/paperclip/attachment.rb
398
402
  - lib/paperclip/attachment_registry.rb
@@ -521,6 +525,7 @@ files:
521
525
  - spec/support/fixtures/animated
522
526
  - spec/support/fixtures/animated.gif
523
527
  - spec/support/fixtures/animated.unknown
528
+ - spec/support/fixtures/aws_s3.yml
524
529
  - spec/support/fixtures/bad.png
525
530
  - spec/support/fixtures/empty.html
526
531
  - spec/support/fixtures/empty.xlsx
@@ -542,7 +547,7 @@ files:
542
547
  - spec/support/reporting.rb
543
548
  - spec/support/test_data.rb
544
549
  - spec/support/version_helper.rb
545
- homepage: https://github.com/kreeti/paperclip
550
+ homepage: https://github.com/kreeti/kt-paperclip
546
551
  licenses:
547
552
  - MIT
548
553
  metadata: {}
@@ -571,7 +576,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
571
576
  requirements:
572
577
  - - ">="
573
578
  - !ruby/object:Gem::Version
574
- version: 2.1.0
579
+ version: 2.2.0
575
580
  required_rubygems_version: !ruby/object:Gem::Requirement
576
581
  requirements:
577
582
  - - ">="
@@ -579,7 +584,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
579
584
  version: '0'
580
585
  requirements:
581
586
  - ImageMagick
582
- rubygems_version: 3.0.1
587
+ rubygems_version: 3.1.6
583
588
  signing_key:
584
589
  specification_version: 4
585
590
  summary: File attachments as attributes for ActiveRecord
@@ -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.