paperclip 4.3.0 → 5.0.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.
- checksums.yaml +4 -4
- data/.travis.yml +14 -13
- data/Appraisals +22 -9
- data/CONTRIBUTING.md +16 -5
- data/Gemfile +2 -8
- data/LICENSE +1 -1
- data/NEWS +49 -2
- data/README.md +126 -102
- data/UPGRADING +12 -9
- data/features/basic_integration.feature +1 -0
- data/features/migration.feature +0 -24
- data/features/step_definitions/attachment_steps.rb +20 -20
- data/features/step_definitions/html_steps.rb +2 -2
- data/features/step_definitions/rails_steps.rb +11 -17
- data/features/step_definitions/s3_steps.rb +2 -2
- data/features/step_definitions/web_steps.rb +1 -103
- data/features/support/file_helpers.rb +2 -2
- data/gemfiles/4.2.awsv2.0.gemfile +17 -0
- data/gemfiles/4.2.awsv2.1.gemfile +17 -0
- data/gemfiles/{4.2.gemfile → 4.2.awsv2.gemfile} +1 -1
- data/gemfiles/5.0.awsv2.0.gemfile +17 -0
- data/gemfiles/5.0.awsv2.1.gemfile +17 -0
- data/gemfiles/{4.1.gemfile → 5.0.awsv2.gemfile} +2 -2
- data/lib/paperclip/attachment.rb +18 -17
- data/lib/paperclip/attachment_registry.rb +2 -1
- data/lib/paperclip/callbacks.rb +8 -6
- data/lib/paperclip/content_type_detector.rb +3 -2
- data/lib/paperclip/errors.rb +3 -1
- data/lib/paperclip/geometry_parser_factory.rb +1 -1
- data/lib/paperclip/glue.rb +1 -1
- data/lib/paperclip/has_attached_file.rb +7 -1
- data/lib/paperclip/helpers.rb +14 -10
- data/lib/paperclip/interpolations/plural_cache.rb +6 -5
- data/lib/paperclip/interpolations.rb +18 -13
- data/lib/paperclip/io_adapters/http_url_proxy_adapter.rb +1 -1
- data/lib/paperclip/io_adapters/uri_adapter.rb +3 -1
- data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +4 -4
- data/lib/paperclip/media_type_spoof_detector.rb +1 -1
- data/lib/paperclip/rails_environment.rb +1 -1
- data/lib/paperclip/schema.rb +3 -9
- data/lib/paperclip/storage/fog.rb +17 -8
- data/lib/paperclip/storage/s3.rb +51 -49
- data/lib/paperclip/validators/attachment_size_validator.rb +1 -7
- data/lib/paperclip/version.rb +3 -1
- data/lib/paperclip.rb +2 -1
- data/lib/tasks/paperclip.rake +1 -1
- data/paperclip.gemspec +15 -11
- data/spec/paperclip/attachment_processing_spec.rb +2 -4
- data/spec/paperclip/attachment_registry_spec.rb +28 -0
- data/spec/paperclip/attachment_spec.rb +36 -14
- data/spec/paperclip/geometry_spec.rb +1 -1
- data/spec/paperclip/glue_spec.rb +44 -0
- data/spec/paperclip/has_attached_file_spec.rb +24 -8
- data/spec/paperclip/integration_spec.rb +4 -3
- data/spec/paperclip/interpolations_spec.rb +14 -4
- data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +12 -0
- data/spec/paperclip/io_adapters/uri_adapter_spec.rb +27 -0
- data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +10 -0
- data/spec/paperclip/media_type_spoof_detector_spec.rb +12 -3
- data/spec/paperclip/paperclip_spec.rb +3 -28
- data/spec/paperclip/plural_cache_spec.rb +17 -16
- data/spec/paperclip/storage/fog_spec.rb +31 -1
- data/spec/paperclip/storage/s3_live_spec.rb +8 -4
- data/spec/paperclip/storage/s3_spec.rb +213 -156
- data/spec/paperclip/validators/attachment_size_validator_spec.rb +26 -20
- data/spec/paperclip/validators_spec.rb +3 -3
- data/spec/spec_helper.rb +6 -1
- data/spec/support/assertions.rb +7 -0
- data/spec/support/model_reconstruction.rb +9 -1
- data/spec/support/reporting.rb +11 -0
- metadata +74 -47
- data/cucumber/paperclip_steps.rb +0 -6
- data/gemfiles/3.2.gemfile +0 -20
- data/lib/paperclip/locales/de.yml +0 -18
- data/lib/paperclip/locales/es.yml +0 -18
- data/lib/paperclip/locales/ja.yml +0 -18
- data/lib/paperclip/locales/pt-BR.yml +0 -18
- data/lib/paperclip/locales/zh-CN.yml +0 -18
- data/lib/paperclip/locales/zh-HK.yml +0 -18
- data/lib/paperclip/locales/zh-TW.yml +0 -18
- data/spec/support/rails_helpers.rb +0 -7
@@ -3,17 +3,20 @@ require 'aws-sdk'
|
|
3
3
|
|
4
4
|
describe Paperclip::Storage::S3 do
|
5
5
|
before do
|
6
|
-
|
6
|
+
Aws.config[:stub_responses] = true
|
7
|
+
end
|
8
|
+
|
9
|
+
def aws2_add_region
|
10
|
+
{ s3_region: 'us-east-1' }
|
7
11
|
end
|
8
12
|
|
9
13
|
context "Parsing S3 credentials" do
|
10
14
|
before do
|
11
15
|
@proxy_settings = {host: "127.0.0.1", port: 8888, user: "foo", password: "bar"}
|
12
|
-
rebuild_model storage: :s3,
|
16
|
+
rebuild_model (aws2_add_region).merge storage: :s3,
|
13
17
|
bucket: "testing",
|
14
18
|
http_proxy: @proxy_settings,
|
15
19
|
s3_credentials: {not: :important}
|
16
|
-
|
17
20
|
@dummy = Dummy.new
|
18
21
|
@avatar = @dummy.avatar
|
19
22
|
end
|
@@ -55,7 +58,8 @@ describe Paperclip::Storage::S3 do
|
|
55
58
|
context ":bucket option via :s3_credentials" do
|
56
59
|
|
57
60
|
before do
|
58
|
-
rebuild_model storage: :s3,
|
61
|
+
rebuild_model (aws2_add_region).merge storage: :s3,
|
62
|
+
s3_credentials: {bucket: 'testing'}
|
59
63
|
@dummy = Dummy.new
|
60
64
|
end
|
61
65
|
|
@@ -68,7 +72,8 @@ describe Paperclip::Storage::S3 do
|
|
68
72
|
context ":bucket option" do
|
69
73
|
|
70
74
|
before do
|
71
|
-
rebuild_model storage: :s3,
|
75
|
+
rebuild_model (aws2_add_region).merge storage: :s3,
|
76
|
+
bucket: "testing", s3_credentials: {}
|
72
77
|
@dummy = Dummy.new
|
73
78
|
end
|
74
79
|
|
@@ -81,7 +86,7 @@ describe Paperclip::Storage::S3 do
|
|
81
86
|
context "missing :bucket option" do
|
82
87
|
|
83
88
|
before do
|
84
|
-
rebuild_model storage: :s3,
|
89
|
+
rebuild_model (aws2_add_region).merge storage: :s3,
|
85
90
|
http_proxy: @proxy_settings,
|
86
91
|
s3_credentials: {not: :important}
|
87
92
|
|
@@ -98,7 +103,7 @@ describe Paperclip::Storage::S3 do
|
|
98
103
|
|
99
104
|
context "" do
|
100
105
|
before do
|
101
|
-
rebuild_model storage: :s3,
|
106
|
+
rebuild_model (aws2_add_region).merge storage: :s3,
|
102
107
|
s3_credentials: {},
|
103
108
|
bucket: "bucket",
|
104
109
|
path: ":attachment/:basename:dotextension",
|
@@ -125,8 +130,8 @@ describe Paperclip::Storage::S3 do
|
|
125
130
|
["http", :http, ""].each do |protocol|
|
126
131
|
context "as #{protocol.inspect}" do
|
127
132
|
before do
|
128
|
-
rebuild_model storage: :s3,
|
129
|
-
|
133
|
+
rebuild_model (aws2_add_region).merge storage: :s3,
|
134
|
+
s3_protocol: protocol
|
130
135
|
@dummy = Dummy.new
|
131
136
|
end
|
132
137
|
|
@@ -139,7 +144,7 @@ describe Paperclip::Storage::S3 do
|
|
139
144
|
|
140
145
|
context "s3_protocol: 'https'" do
|
141
146
|
before do
|
142
|
-
rebuild_model storage: :s3,
|
147
|
+
rebuild_model (aws2_add_region).merge storage: :s3,
|
143
148
|
s3_credentials: {},
|
144
149
|
s3_protocol: 'https',
|
145
150
|
bucket: "bucket",
|
@@ -156,7 +161,7 @@ describe Paperclip::Storage::S3 do
|
|
156
161
|
|
157
162
|
context "s3_protocol: ''" do
|
158
163
|
before do
|
159
|
-
rebuild_model storage: :s3,
|
164
|
+
rebuild_model (aws2_add_region).merge storage: :s3,
|
160
165
|
s3_credentials: {},
|
161
166
|
s3_protocol: '',
|
162
167
|
bucket: "bucket",
|
@@ -173,7 +178,7 @@ describe Paperclip::Storage::S3 do
|
|
173
178
|
|
174
179
|
context "s3_protocol: :https" do
|
175
180
|
before do
|
176
|
-
rebuild_model storage: :s3,
|
181
|
+
rebuild_model (aws2_add_region).merge storage: :s3,
|
177
182
|
s3_credentials: {},
|
178
183
|
s3_protocol: :https,
|
179
184
|
bucket: "bucket",
|
@@ -190,7 +195,7 @@ describe Paperclip::Storage::S3 do
|
|
190
195
|
|
191
196
|
context "s3_protocol: ''" do
|
192
197
|
before do
|
193
|
-
rebuild_model storage: :s3,
|
198
|
+
rebuild_model (aws2_add_region).merge storage: :s3,
|
194
199
|
s3_credentials: {},
|
195
200
|
s3_protocol: '',
|
196
201
|
bucket: "bucket",
|
@@ -207,7 +212,7 @@ describe Paperclip::Storage::S3 do
|
|
207
212
|
|
208
213
|
context "An attachment that uses S3 for storage and has the style in the path" do
|
209
214
|
before do
|
210
|
-
rebuild_model storage: :s3,
|
215
|
+
rebuild_model (aws2_add_region).merge storage: :s3,
|
211
216
|
bucket: "testing",
|
212
217
|
path: ":attachment/:style/:basename:dotextension",
|
213
218
|
styles: {
|
@@ -232,13 +237,15 @@ describe Paperclip::Storage::S3 do
|
|
232
237
|
end
|
233
238
|
end
|
234
239
|
|
240
|
+
# if using aws-sdk-v2, the s3_host_name will be defined by the s3_region
|
235
241
|
context "s3_host_name" do
|
236
242
|
before do
|
237
243
|
rebuild_model storage: :s3,
|
238
244
|
s3_credentials: {},
|
239
245
|
bucket: "bucket",
|
240
246
|
path: ":attachment/:basename:dotextension",
|
241
|
-
s3_host_name: "s3-ap-northeast-1.amazonaws.com"
|
247
|
+
s3_host_name: "s3-ap-northeast-1.amazonaws.com",
|
248
|
+
s3_region: "ap-northeast-1"
|
242
249
|
@dummy = Dummy.new
|
243
250
|
@dummy.avatar = stringy_file
|
244
251
|
@dummy.stubs(:new_record?).returns(false)
|
@@ -249,13 +256,14 @@ describe Paperclip::Storage::S3 do
|
|
249
256
|
end
|
250
257
|
|
251
258
|
it "uses the S3 bucket with the correct host name" do
|
252
|
-
assert_equal "s3-ap-northeast-1.amazonaws.com",
|
259
|
+
assert_equal "s3-ap-northeast-1.amazonaws.com",
|
260
|
+
@dummy.avatar.s3_bucket.client.config.endpoint.host
|
253
261
|
end
|
254
262
|
end
|
255
263
|
|
256
264
|
context "dynamic s3_host_name" do
|
257
265
|
before do
|
258
|
-
rebuild_model storage: :s3,
|
266
|
+
rebuild_model (aws2_add_region).merge storage: :s3,
|
259
267
|
s3_credentials: {},
|
260
268
|
bucket: "bucket",
|
261
269
|
path: ":attachment/:basename:dotextension",
|
@@ -276,8 +284,8 @@ describe Paperclip::Storage::S3 do
|
|
276
284
|
|
277
285
|
context "An attachment that uses S3 for storage and has styles that return different file types" do
|
278
286
|
before do
|
279
|
-
rebuild_model
|
280
|
-
|
287
|
+
rebuild_model (aws2_add_region).merge storage: :s3,
|
288
|
+
styles: { large: ['500x500#', :jpg] },
|
281
289
|
bucket: "bucket",
|
282
290
|
path: ":attachment/:basename:dotextension",
|
283
291
|
s3_credentials: {
|
@@ -311,8 +319,10 @@ describe Paperclip::Storage::S3 do
|
|
311
319
|
|
312
320
|
context "An attachment that uses S3 for storage and has a proc for styles" do
|
313
321
|
before do
|
314
|
-
rebuild_model
|
315
|
-
|
322
|
+
rebuild_model (aws2_add_region).merge storage: :s3,
|
323
|
+
styles: lambda { |attachment| attachment.instance.counter
|
324
|
+
{thumbnail: { geometry: "50x50#",
|
325
|
+
s3_headers: {'Cache-Control' => 'max-age=31557600'}} }},
|
316
326
|
bucket: "bucket",
|
317
327
|
path: ":attachment/:style/:basename:dotextension",
|
318
328
|
s3_credentials: {
|
@@ -336,8 +346,14 @@ describe Paperclip::Storage::S3 do
|
|
336
346
|
object = stub
|
337
347
|
@dummy.avatar.stubs(:s3_object).with(:original).returns(object)
|
338
348
|
@dummy.avatar.stubs(:s3_object).with(:thumbnail).returns(object)
|
339
|
-
|
340
|
-
object.expects(:
|
349
|
+
|
350
|
+
object.expects(:upload_file)
|
351
|
+
.with(anything, content_type: 'image/png',
|
352
|
+
acl: :"public-read")
|
353
|
+
object.expects(:upload_file)
|
354
|
+
.with(anything, content_type: 'image/png',
|
355
|
+
acl: :"public-read",
|
356
|
+
cache_control: 'max-age=31557600')
|
341
357
|
@dummy.save
|
342
358
|
end
|
343
359
|
|
@@ -351,8 +367,8 @@ describe Paperclip::Storage::S3 do
|
|
351
367
|
context "An attachment that uses S3 for storage and has spaces in file name" do
|
352
368
|
before do
|
353
369
|
rebuild_model(
|
370
|
+
(aws2_add_region).merge storage: :s3,
|
354
371
|
styles: { large: ["500x500#", :jpg] },
|
355
|
-
storage: :s3,
|
356
372
|
bucket: "bucket",
|
357
373
|
s3_credentials: { "access_key_id" => "12345",
|
358
374
|
"secret_access_key" => "54321" }
|
@@ -376,8 +392,8 @@ describe Paperclip::Storage::S3 do
|
|
376
392
|
|
377
393
|
context "An attachment that uses S3 for storage and has a question mark in file name" do
|
378
394
|
before do
|
379
|
-
rebuild_model
|
380
|
-
|
395
|
+
rebuild_model (aws2_add_region).merge storage: :s3,
|
396
|
+
styles: { large: ['500x500#', :jpg] },
|
381
397
|
bucket: "bucket",
|
382
398
|
s3_credentials: {
|
383
399
|
'access_key_id' => "12345",
|
@@ -408,7 +424,7 @@ describe Paperclip::Storage::S3 do
|
|
408
424
|
|
409
425
|
context "" do
|
410
426
|
before do
|
411
|
-
rebuild_model storage: :s3,
|
427
|
+
rebuild_model (aws2_add_region).merge storage: :s3,
|
412
428
|
s3_credentials: {},
|
413
429
|
bucket: "bucket",
|
414
430
|
path: ":attachment/:basename:dotextension",
|
@@ -426,7 +442,7 @@ describe Paperclip::Storage::S3 do
|
|
426
442
|
context "" do
|
427
443
|
before do
|
428
444
|
rebuild_model(
|
429
|
-
storage: :s3,
|
445
|
+
(aws2_add_region).merge storage: :s3,
|
430
446
|
s3_credentials: {
|
431
447
|
production: { bucket: "prod_bucket" },
|
432
448
|
development: { bucket: "dev_bucket" }
|
@@ -448,7 +464,7 @@ describe Paperclip::Storage::S3 do
|
|
448
464
|
|
449
465
|
context "generating a url with a proc as the host alias" do
|
450
466
|
before do
|
451
|
-
rebuild_model storage: :s3,
|
467
|
+
rebuild_model (aws2_add_region).merge storage: :s3,
|
452
468
|
s3_credentials: { bucket: "prod_bucket" },
|
453
469
|
s3_host_alias: Proc.new{|atch| "cdn#{atch.instance.counter % 4}.example.com"},
|
454
470
|
path: ":attachment/:basename:dotextension",
|
@@ -478,7 +494,7 @@ describe Paperclip::Storage::S3 do
|
|
478
494
|
|
479
495
|
context "" do
|
480
496
|
before do
|
481
|
-
rebuild_model storage: :s3,
|
497
|
+
rebuild_model (aws2_add_region).merge storage: :s3,
|
482
498
|
s3_credentials: {},
|
483
499
|
bucket: "bucket",
|
484
500
|
path: ":attachment/:basename:dotextension",
|
@@ -509,7 +525,7 @@ describe Paperclip::Storage::S3 do
|
|
509
525
|
url: ":s3_alias_url"
|
510
526
|
}
|
511
527
|
|
512
|
-
rebuild_model base_options.merge(options)
|
528
|
+
rebuild_model (aws2_add_region).merge base_options.merge(options)
|
513
529
|
}
|
514
530
|
end
|
515
531
|
|
@@ -522,8 +538,8 @@ describe Paperclip::Storage::S3 do
|
|
522
538
|
|
523
539
|
object = stub
|
524
540
|
@dummy.avatar.stubs(:s3_object).returns(object)
|
525
|
-
object.expects(:url_for).with(:read, expires: 3600, secure: true)
|
526
541
|
|
542
|
+
object.expects(:presigned_url).with(:get, expires_in: 3600)
|
527
543
|
@dummy.avatar.expiring_url
|
528
544
|
end
|
529
545
|
end
|
@@ -537,8 +553,9 @@ describe Paperclip::Storage::S3 do
|
|
537
553
|
|
538
554
|
object = stub
|
539
555
|
@dummy.avatar.stubs(:s3_object).returns(object)
|
540
|
-
object.expects(:
|
541
|
-
|
556
|
+
object.expects(:presigned_url)
|
557
|
+
.with(:get, expires_in: 3600,
|
558
|
+
response_content_disposition: "inline")
|
542
559
|
@dummy.avatar.expiring_url
|
543
560
|
end
|
544
561
|
end
|
@@ -559,8 +576,8 @@ describe Paperclip::Storage::S3 do
|
|
559
576
|
|
560
577
|
object = stub
|
561
578
|
@dummy.avatar.stubs(:s3_object).returns(object)
|
562
|
-
object.expects(:
|
563
|
-
|
579
|
+
object.expects(:presigned_url)
|
580
|
+
.with(:get, expires_in: 3600, response_content_type: "image/png")
|
564
581
|
@dummy.avatar.expiring_url
|
565
582
|
end
|
566
583
|
end
|
@@ -588,15 +605,15 @@ describe Paperclip::Storage::S3 do
|
|
588
605
|
|
589
606
|
context "Generating a url with an expiration for each style" do
|
590
607
|
before do
|
591
|
-
rebuild_model storage: :s3,
|
608
|
+
rebuild_model (aws2_add_region).merge storage: :s3,
|
592
609
|
s3_credentials: {
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
610
|
+
production: { bucket: "prod_bucket" },
|
611
|
+
development: { bucket: "dev_bucket" }
|
612
|
+
},
|
613
|
+
s3_permissions: :private,
|
614
|
+
s3_host_alias: "something.something.com",
|
615
|
+
path: ":attachment/:style/:basename:dotextension",
|
616
|
+
url: ":s3_alias_url"
|
600
617
|
|
601
618
|
rails_env("production") do
|
602
619
|
@dummy = Dummy.new
|
@@ -607,26 +624,26 @@ describe Paperclip::Storage::S3 do
|
|
607
624
|
it "generates a url for the thumb" do
|
608
625
|
object = stub
|
609
626
|
@dummy.avatar.stubs(:s3_object).with(:thumb).returns(object)
|
610
|
-
object.expects(:
|
627
|
+
object.expects(:presigned_url).with(:get, expires_in: 1800)
|
611
628
|
@dummy.avatar.expiring_url(1800, :thumb)
|
612
629
|
end
|
613
630
|
|
614
631
|
it "generates a url for the default style" do
|
615
632
|
object = stub
|
616
633
|
@dummy.avatar.stubs(:s3_object).with(:original).returns(object)
|
617
|
-
object.expects(:
|
634
|
+
object.expects(:presigned_url).with(:get, expires_in: 1800)
|
618
635
|
@dummy.avatar.expiring_url(1800)
|
619
636
|
end
|
620
637
|
end
|
621
638
|
|
622
639
|
context "Parsing S3 credentials with a bucket in them" do
|
623
640
|
before do
|
624
|
-
rebuild_model storage: :s3,
|
641
|
+
rebuild_model (aws2_add_region).merge storage: :s3,
|
625
642
|
s3_credentials: {
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
643
|
+
production: { bucket: "prod_bucket" },
|
644
|
+
development: { bucket: "dev_bucket" }
|
645
|
+
}
|
646
|
+
@dummy = Dummy.new
|
630
647
|
end
|
631
648
|
|
632
649
|
it "gets the right bucket in production" do
|
@@ -644,47 +661,58 @@ describe Paperclip::Storage::S3 do
|
|
644
661
|
end
|
645
662
|
end
|
646
663
|
|
664
|
+
# for aws-sdk-v2 the bucket.name is determined by the :s3_region
|
647
665
|
context "Parsing S3 credentials with a s3_host_name in them" do
|
648
666
|
before do
|
649
667
|
rebuild_model storage: :s3,
|
650
668
|
bucket: 'testing',
|
651
669
|
s3_credentials: {
|
652
|
-
|
653
|
-
|
670
|
+
production: {
|
671
|
+
s3_region: "world-end",
|
672
|
+
s3_host_name: "s3-world-end.amazonaws.com" },
|
673
|
+
development: {
|
674
|
+
s3_region: "ap-northeast-1",
|
675
|
+
s3_host_name: "s3-ap-northeast-1.amazonaws.com" },
|
676
|
+
test: {
|
677
|
+
s3_region: "" }
|
654
678
|
}
|
655
|
-
|
679
|
+
@dummy = Dummy.new
|
656
680
|
end
|
657
681
|
|
658
682
|
it "gets the right s3_host_name in production" do
|
659
683
|
rails_env("production") do
|
660
684
|
assert_match %r{^s3-world-end.amazonaws.com}, @dummy.avatar.s3_host_name
|
661
|
-
assert_match %r{^s3
|
685
|
+
assert_match %r{^s3.world-end.amazonaws.com},
|
686
|
+
@dummy.avatar.s3_bucket.client.config.endpoint.host
|
662
687
|
end
|
663
688
|
end
|
664
689
|
|
665
690
|
it "gets the right s3_host_name in development" do
|
666
691
|
rails_env("development") do
|
667
692
|
assert_match %r{^s3-ap-northeast-1.amazonaws.com}, @dummy.avatar.s3_host_name
|
668
|
-
assert_match %r{^s3-ap-northeast-1.amazonaws.com},
|
693
|
+
assert_match %r{^s3-ap-northeast-1.amazonaws.com},
|
694
|
+
@dummy.avatar.s3_bucket.client.config.endpoint.host
|
669
695
|
end
|
670
696
|
end
|
671
697
|
|
672
698
|
it "gets the right s3_host_name if the key does not exist" do
|
673
699
|
rails_env("test") do
|
674
700
|
assert_match %r{^s3.amazonaws.com}, @dummy.avatar.s3_host_name
|
675
|
-
|
701
|
+
assert_raises(Aws::Errors::MissingRegionError) do
|
702
|
+
@dummy.avatar.s3_bucket.client.config.endpoint.host
|
703
|
+
end
|
676
704
|
end
|
677
705
|
end
|
678
706
|
end
|
679
707
|
|
680
708
|
context "An attachment with S3 storage" do
|
681
709
|
before do
|
682
|
-
rebuild_model storage: :s3,
|
710
|
+
rebuild_model (aws2_add_region).merge storage: :s3,
|
683
711
|
bucket: "testing",
|
684
712
|
path: ":attachment/:style/:basename:dotextension",
|
685
713
|
s3_credentials: {
|
686
|
-
|
687
|
-
|
714
|
+
access_key_id: "12345",
|
715
|
+
secret_access_key: "54321"
|
688
716
|
}
|
689
717
|
end
|
690
718
|
|
@@ -714,15 +742,14 @@ describe Paperclip::Storage::S3 do
|
|
714
742
|
|
715
743
|
it "is rewound after flush_writes" do
|
716
744
|
@dummy.avatar.instance_eval "def after_flush_writes; end"
|
717
|
-
@dummy.avatar.stubs(:s3_object).returns(stub(
|
718
|
-
|
745
|
+
@dummy.avatar.stubs(:s3_object).returns(stub(upload_file: true))
|
719
746
|
files = @dummy.avatar.queued_for_write.values.each(&:read)
|
720
747
|
@dummy.save
|
721
748
|
assert files.none?(&:eof?), "Expect all the files to be rewound."
|
722
749
|
end
|
723
750
|
|
724
751
|
it "is removed after after_flush_writes" do
|
725
|
-
@dummy.avatar.stubs(:s3_object).returns(stub(
|
752
|
+
@dummy.avatar.stubs(:s3_object).returns(stub(upload_file: true))
|
726
753
|
paths = @dummy.avatar.queued_for_write.values.map(&:path)
|
727
754
|
@dummy.save
|
728
755
|
assert paths.none?{ |path| File.exist?(path) },
|
@@ -731,10 +758,10 @@ describe Paperclip::Storage::S3 do
|
|
731
758
|
|
732
759
|
it "will retry to save again but back off on SlowDown" do
|
733
760
|
@dummy.avatar.stubs(:sleep)
|
734
|
-
|
735
|
-
raises(
|
736
|
-
|
737
|
-
expect {@dummy.save}.to raise_error(
|
761
|
+
Aws::S3::Object.any_instance.stubs(:upload_file).
|
762
|
+
raises(Aws::S3::Errors::SlowDown.new(stub,
|
763
|
+
stub(status: 503, body: "")))
|
764
|
+
expect {@dummy.save}.to raise_error(Aws::S3::Errors::SlowDown)
|
738
765
|
expect(@dummy.avatar).to have_received(:sleep).with(1)
|
739
766
|
expect(@dummy.avatar).to have_received(:sleep).with(2)
|
740
767
|
expect(@dummy.avatar).to have_received(:sleep).with(4)
|
@@ -746,9 +773,8 @@ describe Paperclip::Storage::S3 do
|
|
746
773
|
before do
|
747
774
|
object = stub
|
748
775
|
@dummy.avatar.stubs(:s3_object).returns(object)
|
749
|
-
object.expects(:
|
750
|
-
|
751
|
-
acl: :public_read)
|
776
|
+
object.expects(:upload_file)
|
777
|
+
.with(anything, content_type: 'image/png', acl: :"public-read")
|
752
778
|
@dummy.save
|
753
779
|
end
|
754
780
|
|
@@ -759,12 +785,11 @@ describe Paperclip::Storage::S3 do
|
|
759
785
|
|
760
786
|
context "and saved without a bucket" do
|
761
787
|
before do
|
762
|
-
|
763
|
-
|
764
|
-
raises(
|
765
|
-
|
766
|
-
|
767
|
-
then.returns(nil)
|
788
|
+
Aws::S3::Bucket.any_instance.expects(:create)
|
789
|
+
Aws::S3::Object.any_instance.stubs(:upload_file).
|
790
|
+
raises(Aws::S3::Errors::NoSuchBucket
|
791
|
+
.new(stub,
|
792
|
+
stub(status: 404, body: "<foo/>"))).then.returns(nil)
|
768
793
|
@dummy.save
|
769
794
|
end
|
770
795
|
|
@@ -775,8 +800,8 @@ describe Paperclip::Storage::S3 do
|
|
775
800
|
|
776
801
|
context "and remove" do
|
777
802
|
before do
|
778
|
-
|
779
|
-
|
803
|
+
Aws::S3::Object.any_instance.stubs(:exists?).returns(true)
|
804
|
+
Aws::S3::Object.any_instance.stubs(:delete)
|
780
805
|
@dummy.destroy
|
781
806
|
end
|
782
807
|
|
@@ -787,7 +812,9 @@ describe Paperclip::Storage::S3 do
|
|
787
812
|
|
788
813
|
context 'that the file were missing' do
|
789
814
|
before do
|
790
|
-
|
815
|
+
Aws::S3::Object.any_instance.stubs(:exists?)
|
816
|
+
.raises(Aws::S3::Errors::ServiceError.new("rspec stub raises",
|
817
|
+
"object exists?"))
|
791
818
|
end
|
792
819
|
|
793
820
|
it 'returns false on exists?' do
|
@@ -799,7 +826,7 @@ describe Paperclip::Storage::S3 do
|
|
799
826
|
|
800
827
|
context "An attachment with S3 storage and bucket defined as a Proc" do
|
801
828
|
before do
|
802
|
-
rebuild_model storage: :s3,
|
829
|
+
rebuild_model (aws2_add_region).merge storage: :s3,
|
803
830
|
bucket: lambda { |attachment| "bucket_#{attachment.instance.other}" },
|
804
831
|
s3_credentials: {not: :important}
|
805
832
|
end
|
@@ -814,7 +841,7 @@ describe Paperclip::Storage::S3 do
|
|
814
841
|
|
815
842
|
context "An attachment with S3 storage and S3 credentials defined as a Proc" do
|
816
843
|
before do
|
817
|
-
rebuild_model storage: :s3,
|
844
|
+
rebuild_model (aws2_add_region).merge storage: :s3,
|
818
845
|
bucket: {not: :important},
|
819
846
|
s3_credentials: lambda { |attachment|
|
820
847
|
Hash['access_key_id' => "access#{attachment.instance.other}", 'secret_access_key' => "secret#{attachment.instance.other}"]
|
@@ -831,22 +858,23 @@ describe Paperclip::Storage::S3 do
|
|
831
858
|
before do
|
832
859
|
class DummyCredentialProvider; end
|
833
860
|
|
834
|
-
rebuild_model storage: :s3,
|
861
|
+
rebuild_model (aws2_add_region).merge storage: :s3,
|
835
862
|
bucket: "testing",
|
836
863
|
s3_credentials: {
|
837
|
-
|
864
|
+
credentials: DummyCredentialProvider.new
|
838
865
|
}
|
839
|
-
|
866
|
+
@dummy = Dummy.new
|
840
867
|
end
|
841
868
|
|
842
869
|
it "sets the credential-provider" do
|
843
|
-
expect(@dummy.avatar.s3_bucket.config.
|
870
|
+
expect(@dummy.avatar.s3_bucket.client.config.credentials).to be_a DummyCredentialProvider
|
844
871
|
end
|
845
872
|
end
|
846
873
|
|
847
874
|
context "An attachment with S3 storage and S3 credentials in an unsupported manor" do
|
848
875
|
before do
|
849
|
-
rebuild_model storage: :s3,
|
876
|
+
rebuild_model (aws2_add_region).merge storage: :s3,
|
877
|
+
bucket: "testing", s3_credentials: ["unsupported"]
|
850
878
|
@dummy = Dummy.new
|
851
879
|
end
|
852
880
|
|
@@ -859,7 +887,7 @@ describe Paperclip::Storage::S3 do
|
|
859
887
|
|
860
888
|
context "An attachment with S3 storage and S3 credentials not supplied" do
|
861
889
|
before do
|
862
|
-
rebuild_model storage: :s3, bucket: "testing"
|
890
|
+
rebuild_model (aws2_add_region).merge storage: :s3, bucket: "testing"
|
863
891
|
@dummy = Dummy.new
|
864
892
|
end
|
865
893
|
|
@@ -870,7 +898,7 @@ describe Paperclip::Storage::S3 do
|
|
870
898
|
|
871
899
|
context "An attachment with S3 storage and specific s3 headers set" do
|
872
900
|
before do
|
873
|
-
rebuild_model storage: :s3,
|
901
|
+
rebuild_model (aws2_add_region).merge storage: :s3,
|
874
902
|
bucket: "testing",
|
875
903
|
path: ":attachment/:style/:basename:dotextension",
|
876
904
|
s3_credentials: {
|
@@ -893,10 +921,12 @@ describe Paperclip::Storage::S3 do
|
|
893
921
|
before do
|
894
922
|
object = stub
|
895
923
|
@dummy.avatar.stubs(:s3_object).returns(object)
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
|
924
|
+
|
925
|
+
object.expects(:upload_file)
|
926
|
+
.with(anything,
|
927
|
+
content_type: 'image/png',
|
928
|
+
acl: :"public-read",
|
929
|
+
cache_control: 'max-age=31557600')
|
900
930
|
@dummy.save
|
901
931
|
end
|
902
932
|
|
@@ -909,7 +939,7 @@ describe Paperclip::Storage::S3 do
|
|
909
939
|
|
910
940
|
context "An attachment with S3 storage and metadata set using header names" do
|
911
941
|
before do
|
912
|
-
rebuild_model storage: :s3,
|
942
|
+
rebuild_model (aws2_add_region).merge storage: :s3,
|
913
943
|
bucket: "testing",
|
914
944
|
path: ":attachment/:style/:basename:dotextension",
|
915
945
|
s3_credentials: {
|
@@ -932,10 +962,12 @@ describe Paperclip::Storage::S3 do
|
|
932
962
|
before do
|
933
963
|
object = stub
|
934
964
|
@dummy.avatar.stubs(:s3_object).returns(object)
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
965
|
+
|
966
|
+
object.expects(:upload_file)
|
967
|
+
.with(anything,
|
968
|
+
content_type: 'image/png',
|
969
|
+
acl: :"public-read",
|
970
|
+
metadata: { "color" => "red" })
|
939
971
|
@dummy.save
|
940
972
|
end
|
941
973
|
|
@@ -948,7 +980,7 @@ describe Paperclip::Storage::S3 do
|
|
948
980
|
|
949
981
|
context "An attachment with S3 storage and metadata set using the :s3_metadata option" do
|
950
982
|
before do
|
951
|
-
rebuild_model storage: :s3,
|
983
|
+
rebuild_model (aws2_add_region).merge storage: :s3,
|
952
984
|
bucket: "testing",
|
953
985
|
path: ":attachment/:style/:basename:dotextension",
|
954
986
|
s3_credentials: {
|
@@ -971,10 +1003,12 @@ describe Paperclip::Storage::S3 do
|
|
971
1003
|
before do
|
972
1004
|
object = stub
|
973
1005
|
@dummy.avatar.stubs(:s3_object).returns(object)
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
|
1006
|
+
|
1007
|
+
object.expects(:upload_file)
|
1008
|
+
.with(anything,
|
1009
|
+
content_type: 'image/png',
|
1010
|
+
acl: :"public-read",
|
1011
|
+
metadata: { "color" => "red" })
|
978
1012
|
@dummy.save
|
979
1013
|
end
|
980
1014
|
|
@@ -988,7 +1022,7 @@ describe Paperclip::Storage::S3 do
|
|
988
1022
|
context "An attachment with S3 storage and storage class set" do
|
989
1023
|
context "using the header name" do
|
990
1024
|
before do
|
991
|
-
rebuild_model storage: :s3,
|
1025
|
+
rebuild_model (aws2_add_region).merge storage: :s3,
|
992
1026
|
bucket: "testing",
|
993
1027
|
path: ":attachment/:style/:basename:dotextension",
|
994
1028
|
s3_credentials: {
|
@@ -1011,10 +1045,12 @@ describe Paperclip::Storage::S3 do
|
|
1011
1045
|
before do
|
1012
1046
|
object = stub
|
1013
1047
|
@dummy.avatar.stubs(:s3_object).returns(object)
|
1014
|
-
|
1015
|
-
|
1016
|
-
|
1017
|
-
|
1048
|
+
|
1049
|
+
object.expects(:upload_file)
|
1050
|
+
.with(anything,
|
1051
|
+
content_type: 'image/png',
|
1052
|
+
acl: :"public-read",
|
1053
|
+
storage_class: "reduced_redundancy")
|
1018
1054
|
@dummy.save
|
1019
1055
|
end
|
1020
1056
|
|
@@ -1027,7 +1063,7 @@ describe Paperclip::Storage::S3 do
|
|
1027
1063
|
|
1028
1064
|
context "using per style hash" do
|
1029
1065
|
before do
|
1030
|
-
rebuild_model :storage => :s3,
|
1066
|
+
rebuild_model (aws2_add_region).merge :storage => :s3,
|
1031
1067
|
:bucket => "testing",
|
1032
1068
|
:path => ":attachment/:style/:basename.:extension",
|
1033
1069
|
:styles => {
|
@@ -1056,9 +1092,15 @@ describe Paperclip::Storage::S3 do
|
|
1056
1092
|
object = stub
|
1057
1093
|
[:thumb, :original].each do |style|
|
1058
1094
|
@dummy.avatar.stubs(:s3_object).with(style).returns(object)
|
1059
|
-
|
1095
|
+
|
1096
|
+
expected_options = {
|
1097
|
+
:content_type => "image/png",
|
1098
|
+
acl: :"public-read"
|
1099
|
+
}
|
1060
1100
|
expected_options.merge!(:storage_class => :reduced_redundancy) if style == :thumb
|
1061
|
-
|
1101
|
+
|
1102
|
+
object.expects(:upload_file)
|
1103
|
+
.with(anything, expected_options)
|
1062
1104
|
end
|
1063
1105
|
@dummy.save
|
1064
1106
|
end
|
@@ -1072,7 +1114,7 @@ describe Paperclip::Storage::S3 do
|
|
1072
1114
|
|
1073
1115
|
context "using global hash option" do
|
1074
1116
|
before do
|
1075
|
-
rebuild_model :storage => :s3,
|
1117
|
+
rebuild_model (aws2_add_region).merge :storage => :s3,
|
1076
1118
|
:bucket => "testing",
|
1077
1119
|
:path => ":attachment/:style/:basename.:extension",
|
1078
1120
|
:styles => {
|
@@ -1099,9 +1141,11 @@ describe Paperclip::Storage::S3 do
|
|
1099
1141
|
object = stub
|
1100
1142
|
[:thumb, :original].each do |style|
|
1101
1143
|
@dummy.avatar.stubs(:s3_object).with(style).returns(object)
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1144
|
+
|
1145
|
+
object.expects(:upload_file)
|
1146
|
+
.with(anything, :content_type => "image/png",
|
1147
|
+
acl: :"public-read",
|
1148
|
+
:storage_class => :reduced_redundancy)
|
1105
1149
|
end
|
1106
1150
|
@dummy.save
|
1107
1151
|
end
|
@@ -1118,7 +1162,7 @@ describe Paperclip::Storage::S3 do
|
|
1118
1162
|
[nil, false, ''].each do |tech|
|
1119
1163
|
before do
|
1120
1164
|
rebuild_model(
|
1121
|
-
storage: :s3,
|
1165
|
+
(aws2_add_region).merge storage: :s3,
|
1122
1166
|
bucket: "testing",
|
1123
1167
|
path: ":attachment/:style/:basename:dotextension",
|
1124
1168
|
s3_credentials: {
|
@@ -1140,9 +1184,9 @@ describe Paperclip::Storage::S3 do
|
|
1140
1184
|
before do
|
1141
1185
|
object = stub
|
1142
1186
|
@dummy.avatar.stubs(:s3_object).returns(object)
|
1143
|
-
|
1144
|
-
|
1145
|
-
|
1187
|
+
|
1188
|
+
object.expects(:upload_file)
|
1189
|
+
.with(anything, :content_type => "image/png", acl: :"public-read")
|
1146
1190
|
@dummy.save
|
1147
1191
|
end
|
1148
1192
|
|
@@ -1156,7 +1200,7 @@ describe Paperclip::Storage::S3 do
|
|
1156
1200
|
|
1157
1201
|
context "An attachment with S3 storage and using AES256 encryption" do
|
1158
1202
|
before do
|
1159
|
-
rebuild_model storage: :s3,
|
1203
|
+
rebuild_model (aws2_add_region).merge storage: :s3,
|
1160
1204
|
bucket: "testing",
|
1161
1205
|
path: ":attachment/:style/:basename:dotextension",
|
1162
1206
|
s3_credentials: {
|
@@ -1179,10 +1223,11 @@ describe Paperclip::Storage::S3 do
|
|
1179
1223
|
before do
|
1180
1224
|
object = stub
|
1181
1225
|
@dummy.avatar.stubs(:s3_object).returns(object)
|
1182
|
-
|
1183
|
-
|
1184
|
-
|
1185
|
-
|
1226
|
+
|
1227
|
+
object.expects(:upload_file)
|
1228
|
+
.with(anything, content_type: "image/png",
|
1229
|
+
acl: :"public-read",
|
1230
|
+
server_side_encryption: :aes256)
|
1186
1231
|
@dummy.save
|
1187
1232
|
end
|
1188
1233
|
|
@@ -1195,7 +1240,7 @@ describe Paperclip::Storage::S3 do
|
|
1195
1240
|
|
1196
1241
|
context "An attachment with S3 storage and storage class set using the :storage_class option" do
|
1197
1242
|
before do
|
1198
|
-
rebuild_model storage: :s3,
|
1243
|
+
rebuild_model (aws2_add_region).merge storage: :s3,
|
1199
1244
|
bucket: "testing",
|
1200
1245
|
path: ":attachment/:style/:basename:dotextension",
|
1201
1246
|
s3_credentials: {
|
@@ -1218,10 +1263,12 @@ describe Paperclip::Storage::S3 do
|
|
1218
1263
|
before do
|
1219
1264
|
object = stub
|
1220
1265
|
@dummy.avatar.stubs(:s3_object).returns(object)
|
1221
|
-
|
1222
|
-
|
1223
|
-
|
1224
|
-
|
1266
|
+
|
1267
|
+
object.expects(:upload_file)
|
1268
|
+
.with(anything,
|
1269
|
+
content_type: "image/png",
|
1270
|
+
acl: :"public-read",
|
1271
|
+
storage_class: :reduced_redundancy)
|
1225
1272
|
@dummy.save
|
1226
1273
|
end
|
1227
1274
|
|
@@ -1239,7 +1286,7 @@ describe Paperclip::Storage::S3 do
|
|
1239
1286
|
ENV['S3_SECRET'] = 'pathname_secret'
|
1240
1287
|
|
1241
1288
|
rails_env('test') do
|
1242
|
-
rebuild_model storage: :s3,
|
1289
|
+
rebuild_model (aws2_add_region).merge storage: :s3,
|
1243
1290
|
s3_credentials: Pathname.new(fixture_file('s3.yml'))
|
1244
1291
|
|
1245
1292
|
Dummy.delete_all
|
@@ -1249,8 +1296,12 @@ describe Paperclip::Storage::S3 do
|
|
1249
1296
|
|
1250
1297
|
it "parses the credentials" do
|
1251
1298
|
assert_equal 'pathname_bucket', @dummy.avatar.bucket_name
|
1252
|
-
|
1253
|
-
assert_equal '
|
1299
|
+
|
1300
|
+
assert_equal 'pathname_key',
|
1301
|
+
@dummy.avatar.s3_bucket.client.config.access_key_id
|
1302
|
+
|
1303
|
+
assert_equal 'pathname_secret',
|
1304
|
+
@dummy.avatar.s3_bucket.client.config.secret_access_key
|
1254
1305
|
end
|
1255
1306
|
end
|
1256
1307
|
|
@@ -1261,7 +1312,7 @@ describe Paperclip::Storage::S3 do
|
|
1261
1312
|
ENV['S3_SECRET'] = 'env_secret'
|
1262
1313
|
|
1263
1314
|
rails_env('test') do
|
1264
|
-
rebuild_model storage: :s3,
|
1315
|
+
rebuild_model (aws2_add_region).merge storage: :s3,
|
1265
1316
|
s3_credentials: File.new(fixture_file('s3.yml'))
|
1266
1317
|
|
1267
1318
|
Dummy.delete_all
|
@@ -1272,15 +1323,19 @@ describe Paperclip::Storage::S3 do
|
|
1272
1323
|
|
1273
1324
|
it "runs the file through ERB" do
|
1274
1325
|
assert_equal 'env_bucket', @dummy.avatar.bucket_name
|
1275
|
-
|
1276
|
-
assert_equal '
|
1326
|
+
|
1327
|
+
assert_equal 'env_key',
|
1328
|
+
@dummy.avatar.s3_bucket.client.config.access_key_id
|
1329
|
+
|
1330
|
+
assert_equal 'env_secret',
|
1331
|
+
@dummy.avatar.s3_bucket.client.config.secret_access_key
|
1277
1332
|
end
|
1278
1333
|
end
|
1279
1334
|
|
1280
1335
|
context "S3 Permissions" do
|
1281
1336
|
context "defaults to :public_read" do
|
1282
1337
|
before do
|
1283
|
-
rebuild_model storage: :s3,
|
1338
|
+
rebuild_model (aws2_add_region).merge storage: :s3,
|
1284
1339
|
bucket: "testing",
|
1285
1340
|
path: ":attachment/:style/:basename:dotextension",
|
1286
1341
|
s3_credentials: {
|
@@ -1302,9 +1357,9 @@ describe Paperclip::Storage::S3 do
|
|
1302
1357
|
before do
|
1303
1358
|
object = stub
|
1304
1359
|
@dummy.avatar.stubs(:s3_object).returns(object)
|
1305
|
-
|
1306
|
-
|
1307
|
-
|
1360
|
+
|
1361
|
+
object.expects(:upload_file)
|
1362
|
+
.with(anything, content_type: "image/png", acl: :"public-read")
|
1308
1363
|
@dummy.save
|
1309
1364
|
end
|
1310
1365
|
|
@@ -1317,7 +1372,7 @@ describe Paperclip::Storage::S3 do
|
|
1317
1372
|
|
1318
1373
|
context "string permissions set" do
|
1319
1374
|
before do
|
1320
|
-
rebuild_model storage: :s3,
|
1375
|
+
rebuild_model (aws2_add_region).merge storage: :s3,
|
1321
1376
|
bucket: "testing",
|
1322
1377
|
path: ":attachment/:style/:basename:dotextension",
|
1323
1378
|
s3_credentials: {
|
@@ -1340,9 +1395,9 @@ describe Paperclip::Storage::S3 do
|
|
1340
1395
|
before do
|
1341
1396
|
object = stub
|
1342
1397
|
@dummy.avatar.stubs(:s3_object).returns(object)
|
1343
|
-
|
1344
|
-
|
1345
|
-
|
1398
|
+
|
1399
|
+
object.expects(:upload_file)
|
1400
|
+
.with(anything, content_type: "image/png", acl: :private)
|
1346
1401
|
@dummy.save
|
1347
1402
|
end
|
1348
1403
|
|
@@ -1355,7 +1410,7 @@ describe Paperclip::Storage::S3 do
|
|
1355
1410
|
|
1356
1411
|
context "hash permissions set" do
|
1357
1412
|
before do
|
1358
|
-
rebuild_model storage: :s3,
|
1413
|
+
rebuild_model (aws2_add_region).merge storage: :s3,
|
1359
1414
|
bucket: "testing",
|
1360
1415
|
path: ":attachment/:style/:basename:dotextension",
|
1361
1416
|
styles: {
|
@@ -1385,9 +1440,11 @@ describe Paperclip::Storage::S3 do
|
|
1385
1440
|
[:thumb, :original].each do |style|
|
1386
1441
|
object = stub
|
1387
1442
|
@dummy.avatar.stubs(:s3_object).with(style).returns(object)
|
1388
|
-
|
1389
|
-
|
1390
|
-
|
1443
|
+
|
1444
|
+
object.expects(:upload_file)
|
1445
|
+
.with(anything,
|
1446
|
+
content_type: "image/png",
|
1447
|
+
acl: style == :thumb ? :public_read : :private)
|
1391
1448
|
end
|
1392
1449
|
@dummy.save
|
1393
1450
|
end
|
@@ -1402,7 +1459,7 @@ describe Paperclip::Storage::S3 do
|
|
1402
1459
|
context "proc permission set" do
|
1403
1460
|
before do
|
1404
1461
|
rebuild_model(
|
1405
|
-
storage: :s3,
|
1462
|
+
(aws2_add_region).merge storage: :s3,
|
1406
1463
|
bucket: "testing",
|
1407
1464
|
path: ":attachment/:style/:basename:dotextension",
|
1408
1465
|
styles: {
|
@@ -1413,7 +1470,7 @@ describe Paperclip::Storage::S3 do
|
|
1413
1470
|
'secret_access_key' => "54321"
|
1414
1471
|
},
|
1415
1472
|
s3_permissions: lambda {|attachment, style|
|
1416
|
-
attachment.instance.private_attachment? && style.to_sym != :thumb ? :private : :
|
1473
|
+
attachment.instance.private_attachment? && style.to_sym != :thumb ? :private : :"public-read"
|
1417
1474
|
}
|
1418
1475
|
)
|
1419
1476
|
end
|
@@ -1446,7 +1503,7 @@ describe Paperclip::Storage::S3 do
|
|
1446
1503
|
context "An attachment with S3 storage and metadata set using a proc as headers" do
|
1447
1504
|
before do
|
1448
1505
|
rebuild_model(
|
1449
|
-
storage: :s3,
|
1506
|
+
(aws2_add_region).merge storage: :s3,
|
1450
1507
|
bucket: "testing",
|
1451
1508
|
path: ":attachment/:style/:basename:dotextension",
|
1452
1509
|
styles: {
|
@@ -1477,10 +1534,12 @@ describe Paperclip::Storage::S3 do
|
|
1477
1534
|
[:thumb, :original].each do |style|
|
1478
1535
|
object = stub
|
1479
1536
|
@dummy.avatar.stubs(:s3_object).with(style).returns(object)
|
1480
|
-
|
1481
|
-
|
1482
|
-
|
1483
|
-
|
1537
|
+
|
1538
|
+
object.expects(:upload_file)
|
1539
|
+
.with(anything,
|
1540
|
+
content_type: "image/png",
|
1541
|
+
acl: :"public-read",
|
1542
|
+
content_disposition: 'attachment; filename="Custom Avatar Name.png"')
|
1484
1543
|
end
|
1485
1544
|
@dummy.save
|
1486
1545
|
end
|
@@ -1494,7 +1553,7 @@ describe Paperclip::Storage::S3 do
|
|
1494
1553
|
|
1495
1554
|
context "path is a proc" do
|
1496
1555
|
before do
|
1497
|
-
rebuild_model storage: :s3,
|
1556
|
+
rebuild_model (aws2_add_region).merge storage: :s3,
|
1498
1557
|
path: ->(attachment) { attachment.instance.attachment_path }
|
1499
1558
|
|
1500
1559
|
@dummy = Dummy.new
|
@@ -1511,7 +1570,6 @@ describe Paperclip::Storage::S3 do
|
|
1511
1570
|
end
|
1512
1571
|
end
|
1513
1572
|
|
1514
|
-
|
1515
1573
|
private
|
1516
1574
|
|
1517
1575
|
def rails_env(env)
|
@@ -1522,5 +1580,4 @@ describe Paperclip::Storage::S3 do
|
|
1522
1580
|
Rails.env = stored_env
|
1523
1581
|
end
|
1524
1582
|
end
|
1525
|
-
|
1526
1583
|
end
|