paperclip 4.3.7 → 5.0.0.beta1

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.

Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +13 -9
  3. data/Appraisals +22 -6
  4. data/CONTRIBUTING.md +6 -1
  5. data/Gemfile +2 -8
  6. data/LICENSE +1 -1
  7. data/NEWS +28 -37
  8. data/README.md +81 -63
  9. data/UPGRADING +9 -9
  10. data/features/basic_integration.feature +1 -0
  11. data/features/step_definitions/s3_steps.rb +6 -2
  12. data/gemfiles/{4.1.gemfile → 4.2.awsv2.0.gemfile} +4 -6
  13. data/gemfiles/4.2.awsv2.1.gemfile +17 -0
  14. data/gemfiles/{4.2.gemfile → 4.2.awsv2.gemfile} +1 -0
  15. data/gemfiles/5.0.awsv2.0.gemfile +17 -0
  16. data/gemfiles/5.0.awsv2.1.gemfile +17 -0
  17. data/gemfiles/{3.2.gemfile → 5.0.awsv2.gemfile} +7 -1
  18. data/lib/paperclip.rb +0 -2
  19. data/lib/paperclip/attachment.rb +9 -8
  20. data/lib/paperclip/attachment_registry.rb +2 -1
  21. data/lib/paperclip/callbacks.rb +8 -6
  22. data/lib/paperclip/glue.rb +1 -1
  23. data/lib/paperclip/has_attached_file.rb +7 -1
  24. data/lib/paperclip/io_adapters/uri_adapter.rb +11 -30
  25. data/lib/paperclip/schema.rb +1 -2
  26. data/lib/paperclip/storage/s3.rb +59 -35
  27. data/lib/paperclip/version.rb +1 -1
  28. data/paperclip.gemspec +11 -7
  29. data/spec/paperclip/attachment_registry_spec.rb +28 -0
  30. data/spec/paperclip/attachment_spec.rb +32 -6
  31. data/spec/paperclip/has_attached_file_spec.rb +24 -8
  32. data/spec/paperclip/integration_spec.rb +4 -3
  33. data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +5 -8
  34. data/spec/paperclip/io_adapters/uri_adapter_spec.rb +6 -31
  35. data/spec/paperclip/media_type_spoof_detector_spec.rb +3 -12
  36. data/spec/paperclip/paperclip_spec.rb +0 -32
  37. data/spec/paperclip/storage/s3_live_spec.rb +8 -4
  38. data/spec/paperclip/storage/s3_spec.rb +345 -165
  39. data/spec/paperclip/validators_spec.rb +2 -3
  40. data/spec/spec_helper.rb +3 -1
  41. data/spec/support/assertions.rb +7 -0
  42. data/spec/support/model_reconstruction.rb +9 -1
  43. data/spec/support/reporting.rb +11 -0
  44. metadata +45 -40
  45. data/lib/paperclip/deprecations.rb +0 -42
  46. data/lib/paperclip/locales/de.yml +0 -18
  47. data/lib/paperclip/locales/es.yml +0 -18
  48. data/lib/paperclip/locales/ja.yml +0 -18
  49. data/lib/paperclip/locales/pt-BR.yml +0 -18
  50. data/lib/paperclip/locales/zh-CN.yml +0 -18
  51. data/lib/paperclip/locales/zh-HK.yml +0 -18
  52. data/lib/paperclip/locales/zh-TW.yml +0 -18
  53. data/spec/paperclip/deprecations_spec.rb +0 -65
  54. data/spec/support/deprecations.rb +0 -9
  55. data/spec/support/rails_helpers.rb +0 -7
@@ -3,17 +3,24 @@ require 'aws-sdk'
3
3
 
4
4
  describe Paperclip::Storage::S3 do
5
5
  before do
6
- AWS.stub!
6
+ if defined?(::Aws)
7
+ Aws.config[:stub_responses] = true
8
+ else
9
+ AWS.stub!
10
+ end
11
+ end
12
+
13
+ def aws2_add_region
14
+ defined?(::Aws) ? { s3_region: 'us-east-1' } : {}
7
15
  end
8
16
 
9
17
  context "Parsing S3 credentials" do
10
18
  before do
11
19
  @proxy_settings = {host: "127.0.0.1", port: 8888, user: "foo", password: "bar"}
12
- rebuild_model storage: :s3,
20
+ rebuild_model (aws2_add_region).merge storage: :s3,
13
21
  bucket: "testing",
14
22
  http_proxy: @proxy_settings,
15
23
  s3_credentials: {not: :important}
16
-
17
24
  @dummy = Dummy.new
18
25
  @avatar = @dummy.avatar
19
26
  end
@@ -55,7 +62,8 @@ describe Paperclip::Storage::S3 do
55
62
  context ":bucket option via :s3_credentials" do
56
63
 
57
64
  before do
58
- rebuild_model storage: :s3, s3_credentials: {bucket: 'testing'}
65
+ rebuild_model (aws2_add_region).merge storage: :s3,
66
+ s3_credentials: {bucket: 'testing'}
59
67
  @dummy = Dummy.new
60
68
  end
61
69
 
@@ -68,7 +76,8 @@ describe Paperclip::Storage::S3 do
68
76
  context ":bucket option" do
69
77
 
70
78
  before do
71
- rebuild_model storage: :s3, bucket: "testing", s3_credentials: {}
79
+ rebuild_model (aws2_add_region).merge storage: :s3,
80
+ bucket: "testing", s3_credentials: {}
72
81
  @dummy = Dummy.new
73
82
  end
74
83
 
@@ -81,7 +90,7 @@ describe Paperclip::Storage::S3 do
81
90
  context "missing :bucket option" do
82
91
 
83
92
  before do
84
- rebuild_model storage: :s3,
93
+ rebuild_model (aws2_add_region).merge storage: :s3,
85
94
  http_proxy: @proxy_settings,
86
95
  s3_credentials: {not: :important}
87
96
 
@@ -98,7 +107,7 @@ describe Paperclip::Storage::S3 do
98
107
 
99
108
  context "" do
100
109
  before do
101
- rebuild_model storage: :s3,
110
+ rebuild_model (aws2_add_region).merge storage: :s3,
102
111
  s3_credentials: {},
103
112
  bucket: "bucket",
104
113
  path: ":attachment/:basename:dotextension",
@@ -125,8 +134,8 @@ describe Paperclip::Storage::S3 do
125
134
  ["http", :http, ""].each do |protocol|
126
135
  context "as #{protocol.inspect}" do
127
136
  before do
128
- rebuild_model storage: :s3, s3_protocol: protocol
129
-
137
+ rebuild_model (aws2_add_region).merge storage: :s3,
138
+ s3_protocol: protocol
130
139
  @dummy = Dummy.new
131
140
  end
132
141
 
@@ -139,7 +148,7 @@ describe Paperclip::Storage::S3 do
139
148
 
140
149
  context "s3_protocol: 'https'" do
141
150
  before do
142
- rebuild_model storage: :s3,
151
+ rebuild_model (aws2_add_region).merge storage: :s3,
143
152
  s3_credentials: {},
144
153
  s3_protocol: 'https',
145
154
  bucket: "bucket",
@@ -156,7 +165,7 @@ describe Paperclip::Storage::S3 do
156
165
 
157
166
  context "s3_protocol: ''" do
158
167
  before do
159
- rebuild_model storage: :s3,
168
+ rebuild_model (aws2_add_region).merge storage: :s3,
160
169
  s3_credentials: {},
161
170
  s3_protocol: '',
162
171
  bucket: "bucket",
@@ -173,7 +182,7 @@ describe Paperclip::Storage::S3 do
173
182
 
174
183
  context "s3_protocol: :https" do
175
184
  before do
176
- rebuild_model storage: :s3,
185
+ rebuild_model (aws2_add_region).merge storage: :s3,
177
186
  s3_credentials: {},
178
187
  s3_protocol: :https,
179
188
  bucket: "bucket",
@@ -190,7 +199,7 @@ describe Paperclip::Storage::S3 do
190
199
 
191
200
  context "s3_protocol: ''" do
192
201
  before do
193
- rebuild_model storage: :s3,
202
+ rebuild_model (aws2_add_region).merge storage: :s3,
194
203
  s3_credentials: {},
195
204
  s3_protocol: '',
196
205
  bucket: "bucket",
@@ -207,7 +216,7 @@ describe Paperclip::Storage::S3 do
207
216
 
208
217
  context "An attachment that uses S3 for storage and has the style in the path" do
209
218
  before do
210
- rebuild_model storage: :s3,
219
+ rebuild_model (aws2_add_region).merge storage: :s3,
211
220
  bucket: "testing",
212
221
  path: ":attachment/:style/:basename:dotextension",
213
222
  styles: {
@@ -232,13 +241,23 @@ describe Paperclip::Storage::S3 do
232
241
  end
233
242
  end
234
243
 
244
+ # if using aws-sdk-v2, the s3_host_name will be defined by the s3_region
235
245
  context "s3_host_name" do
236
246
  before do
237
- rebuild_model storage: :s3,
238
- s3_credentials: {},
239
- bucket: "bucket",
240
- path: ":attachment/:basename:dotextension",
241
- s3_host_name: "s3-ap-northeast-1.amazonaws.com"
247
+ if defined?(::Aws)
248
+ rebuild_model storage: :s3,
249
+ s3_credentials: {},
250
+ bucket: "bucket",
251
+ path: ":attachment/:basename:dotextension",
252
+ s3_host_name: "s3-ap-northeast-1.amazonaws.com",
253
+ s3_region: "ap-northeast-1"
254
+ else
255
+ rebuild_model storage: :s3,
256
+ s3_credentials: {},
257
+ bucket: "bucket",
258
+ path: ":attachment/:basename:dotextension",
259
+ s3_host_name: "s3-ap-northeast-1.amazonaws.com"
260
+ end
242
261
  @dummy = Dummy.new
243
262
  @dummy.avatar = stringy_file
244
263
  @dummy.stubs(:new_record?).returns(false)
@@ -249,13 +268,16 @@ describe Paperclip::Storage::S3 do
249
268
  end
250
269
 
251
270
  it "uses the S3 bucket with the correct host name" do
252
- assert_equal "s3-ap-northeast-1.amazonaws.com", @dummy.avatar.s3_bucket.config.s3_endpoint
271
+ assert_equal "s3-ap-northeast-1.amazonaws.com",
272
+ (defined?(::Aws) ?
273
+ @dummy.avatar.s3_bucket.client.config.endpoint.host :
274
+ @dummy.avatar.s3_bucket.config.s3_endpoint)
253
275
  end
254
276
  end
255
277
 
256
278
  context "dynamic s3_host_name" do
257
279
  before do
258
- rebuild_model storage: :s3,
280
+ rebuild_model (aws2_add_region).merge storage: :s3,
259
281
  s3_credentials: {},
260
282
  bucket: "bucket",
261
283
  path: ":attachment/:basename:dotextension",
@@ -276,8 +298,8 @@ describe Paperclip::Storage::S3 do
276
298
 
277
299
  context "An attachment that uses S3 for storage and has styles that return different file types" do
278
300
  before do
279
- rebuild_model styles: { large: ['500x500#', :jpg] },
280
- storage: :s3,
301
+ rebuild_model (aws2_add_region).merge storage: :s3,
302
+ styles: { large: ['500x500#', :jpg] },
281
303
  bucket: "bucket",
282
304
  path: ":attachment/:basename:dotextension",
283
305
  s3_credentials: {
@@ -311,8 +333,10 @@ describe Paperclip::Storage::S3 do
311
333
 
312
334
  context "An attachment that uses S3 for storage and has a proc for styles" do
313
335
  before do
314
- rebuild_model styles: lambda { |attachment| attachment.instance.counter; {thumbnail: { geometry: "50x50#", s3_headers: {'Cache-Control' => 'max-age=31557600'}} }},
315
- storage: :s3,
336
+ rebuild_model (aws2_add_region).merge storage: :s3,
337
+ styles: lambda { |attachment| attachment.instance.counter
338
+ {thumbnail: { geometry: "50x50#",
339
+ s3_headers: {'Cache-Control' => 'max-age=31557600'}} }},
316
340
  bucket: "bucket",
317
341
  path: ":attachment/:style/:basename:dotextension",
318
342
  s3_credentials: {
@@ -336,8 +360,15 @@ describe Paperclip::Storage::S3 do
336
360
  object = stub
337
361
  @dummy.avatar.stubs(:s3_object).with(:original).returns(object)
338
362
  @dummy.avatar.stubs(:s3_object).with(:thumbnail).returns(object)
339
- object.expects(:write).with(anything, content_type: 'image/png', acl: :public_read)
340
- object.expects(:write).with(anything, content_type: 'image/png', acl: :public_read, cache_control: 'max-age=31557600')
363
+
364
+ object.expects((defined?(::Aws) ? :upload_file : :write))
365
+ .with(anything, content_type: 'image/png',
366
+ acl: Paperclip::Storage::S3::DEFAULT_PERMISSION)
367
+
368
+ object.expects((defined?(::Aws) ? :upload_file : :write))
369
+ .with(anything, content_type: 'image/png',
370
+ acl: Paperclip::Storage::S3::DEFAULT_PERMISSION,
371
+ cache_control: 'max-age=31557600')
341
372
  @dummy.save
342
373
  end
343
374
 
@@ -351,8 +382,8 @@ describe Paperclip::Storage::S3 do
351
382
  context "An attachment that uses S3 for storage and has spaces in file name" do
352
383
  before do
353
384
  rebuild_model(
385
+ (aws2_add_region).merge storage: :s3,
354
386
  styles: { large: ["500x500#", :jpg] },
355
- storage: :s3,
356
387
  bucket: "bucket",
357
388
  s3_credentials: { "access_key_id" => "12345",
358
389
  "secret_access_key" => "54321" }
@@ -376,8 +407,8 @@ describe Paperclip::Storage::S3 do
376
407
 
377
408
  context "An attachment that uses S3 for storage and has a question mark in file name" do
378
409
  before do
379
- rebuild_model styles: { large: ['500x500#', :jpg] },
380
- storage: :s3,
410
+ rebuild_model (aws2_add_region).merge storage: :s3,
411
+ styles: { large: ['500x500#', :jpg] },
381
412
  bucket: "bucket",
382
413
  s3_credentials: {
383
414
  'access_key_id' => "12345",
@@ -408,7 +439,7 @@ describe Paperclip::Storage::S3 do
408
439
 
409
440
  context "" do
410
441
  before do
411
- rebuild_model storage: :s3,
442
+ rebuild_model (aws2_add_region).merge storage: :s3,
412
443
  s3_credentials: {},
413
444
  bucket: "bucket",
414
445
  path: ":attachment/:basename:dotextension",
@@ -426,7 +457,7 @@ describe Paperclip::Storage::S3 do
426
457
  context "" do
427
458
  before do
428
459
  rebuild_model(
429
- storage: :s3,
460
+ (aws2_add_region).merge storage: :s3,
430
461
  s3_credentials: {
431
462
  production: { bucket: "prod_bucket" },
432
463
  development: { bucket: "dev_bucket" }
@@ -448,7 +479,7 @@ describe Paperclip::Storage::S3 do
448
479
 
449
480
  context "generating a url with a proc as the host alias" do
450
481
  before do
451
- rebuild_model storage: :s3,
482
+ rebuild_model (aws2_add_region).merge storage: :s3,
452
483
  s3_credentials: { bucket: "prod_bucket" },
453
484
  s3_host_alias: Proc.new{|atch| "cdn#{atch.instance.counter % 4}.example.com"},
454
485
  path: ":attachment/:basename:dotextension",
@@ -478,7 +509,7 @@ describe Paperclip::Storage::S3 do
478
509
 
479
510
  context "" do
480
511
  before do
481
- rebuild_model storage: :s3,
512
+ rebuild_model (aws2_add_region).merge storage: :s3,
482
513
  s3_credentials: {},
483
514
  bucket: "bucket",
484
515
  path: ":attachment/:basename:dotextension",
@@ -509,7 +540,7 @@ describe Paperclip::Storage::S3 do
509
540
  url: ":s3_alias_url"
510
541
  }
511
542
 
512
- rebuild_model base_options.merge(options)
543
+ rebuild_model (aws2_add_region).merge base_options.merge(options)
513
544
  }
514
545
  end
515
546
 
@@ -522,8 +553,12 @@ describe Paperclip::Storage::S3 do
522
553
 
523
554
  object = stub
524
555
  @dummy.avatar.stubs(:s3_object).returns(object)
525
- object.expects(:url_for).with(:read, expires: 3600, secure: true)
526
556
 
557
+ if defined?(::Aws)
558
+ object.expects(:presigned_url).with(:get, expires_in: 3600)
559
+ else
560
+ object.expects(:url_for).with(:read, expires: 3600, secure: true)
561
+ end
527
562
  @dummy.avatar.expiring_url
528
563
  end
529
564
  end
@@ -537,8 +572,15 @@ describe Paperclip::Storage::S3 do
537
572
 
538
573
  object = stub
539
574
  @dummy.avatar.stubs(:s3_object).returns(object)
540
- object.expects(:url_for).with(:read, expires: 3600, secure: true, response_content_disposition: "inline")
541
-
575
+ if defined?(::Aws)
576
+ object.expects(:presigned_url)
577
+ .with(:get, expires_in: 3600,
578
+ response_content_disposition: "inline")
579
+ else
580
+ object.expects(:url_for)
581
+ .with(:read, expires: 3600, secure: true,
582
+ response_content_disposition: "inline")
583
+ end
542
584
  @dummy.avatar.expiring_url
543
585
  end
544
586
  end
@@ -559,8 +601,14 @@ describe Paperclip::Storage::S3 do
559
601
 
560
602
  object = stub
561
603
  @dummy.avatar.stubs(:s3_object).returns(object)
562
- object.expects(:url_for).with(:read, expires: 3600, secure: true, response_content_type: "image/png")
563
-
604
+ if defined?(::Aws)
605
+ object.expects(:presigned_url)
606
+ .with(:get, expires_in: 3600, response_content_type: "image/png")
607
+ else
608
+ object.expects(:url_for)
609
+ .with(:read, expires: 3600, secure: true,
610
+ response_content_type: "image/png")
611
+ end
564
612
  @dummy.avatar.expiring_url
565
613
  end
566
614
  end
@@ -588,15 +636,15 @@ describe Paperclip::Storage::S3 do
588
636
 
589
637
  context "Generating a url with an expiration for each style" do
590
638
  before do
591
- rebuild_model storage: :s3,
639
+ rebuild_model (aws2_add_region).merge storage: :s3,
592
640
  s3_credentials: {
593
- production: { bucket: "prod_bucket" },
594
- development: { bucket: "dev_bucket" }
595
- },
596
- s3_permissions: :private,
597
- s3_host_alias: "something.something.com",
598
- path: ":attachment/:style/:basename:dotextension",
599
- url: ":s3_alias_url"
641
+ production: { bucket: "prod_bucket" },
642
+ development: { bucket: "dev_bucket" }
643
+ },
644
+ s3_permissions: :private,
645
+ s3_host_alias: "something.something.com",
646
+ path: ":attachment/:style/:basename:dotextension",
647
+ url: ":s3_alias_url"
600
648
 
601
649
  rails_env("production") do
602
650
  @dummy = Dummy.new
@@ -607,26 +655,34 @@ describe Paperclip::Storage::S3 do
607
655
  it "generates a url for the thumb" do
608
656
  object = stub
609
657
  @dummy.avatar.stubs(:s3_object).with(:thumb).returns(object)
610
- object.expects(:url_for).with(:read, expires: 1800, secure: true)
658
+ if defined?(::Aws)
659
+ object.expects(:presigned_url).with(:get, expires_in: 1800)
660
+ else
661
+ object.expects(:url_for).with(:read, expires: 1800, secure: true)
662
+ end
611
663
  @dummy.avatar.expiring_url(1800, :thumb)
612
664
  end
613
665
 
614
666
  it "generates a url for the default style" do
615
667
  object = stub
616
668
  @dummy.avatar.stubs(:s3_object).with(:original).returns(object)
617
- object.expects(:url_for).with(:read, expires: 1800, secure: true)
669
+ if defined?(::Aws)
670
+ object.expects(:presigned_url).with(:get, expires_in: 1800)
671
+ else
672
+ object.expects(:url_for).with(:read, expires: 1800, secure: true)
673
+ end
618
674
  @dummy.avatar.expiring_url(1800)
619
675
  end
620
676
  end
621
677
 
622
678
  context "Parsing S3 credentials with a bucket in them" do
623
679
  before do
624
- rebuild_model storage: :s3,
680
+ rebuild_model (aws2_add_region).merge storage: :s3,
625
681
  s3_credentials: {
626
- production: { bucket: "prod_bucket" },
627
- development: { bucket: "dev_bucket" }
628
- }
629
- @dummy = Dummy.new
682
+ production: { bucket: "prod_bucket" },
683
+ development: { bucket: "dev_bucket" }
684
+ }
685
+ @dummy = Dummy.new
630
686
  end
631
687
 
632
688
  it "gets the right bucket in production" do
@@ -644,47 +700,81 @@ describe Paperclip::Storage::S3 do
644
700
  end
645
701
  end
646
702
 
703
+ # for aws-sdk-v2 the bucket.name is determined by the :s3_region
647
704
  context "Parsing S3 credentials with a s3_host_name in them" do
648
705
  before do
649
- rebuild_model storage: :s3,
650
- bucket: 'testing',
651
- s3_credentials: {
652
- production: { s3_host_name: "s3-world-end.amazonaws.com" },
653
- development: { s3_host_name: "s3-ap-northeast-1.amazonaws.com" }
654
- }
655
- @dummy = Dummy.new
706
+ if defined?(::Aws)
707
+ rebuild_model storage: :s3,
708
+ bucket: 'testing',
709
+ s3_credentials: {
710
+ production: {
711
+ s3_region: "world-end",
712
+ s3_host_name: "s3-world-end.amazonaws.com" },
713
+ development: {
714
+ s3_region: "ap-northeast-1",
715
+ s3_host_name: "s3-ap-northeast-1.amazonaws.com" }
716
+ }
717
+ else
718
+ rebuild_model storage: :s3,
719
+ bucket: 'testing',
720
+ s3_credentials: {
721
+ production: { s3_host_name: "s3-world-end.amazonaws.com" },
722
+ development: { s3_host_name: "s3-ap-northeast-1.amazonaws.com" }
723
+ }
724
+ end
725
+ @dummy = Dummy.new
656
726
  end
657
727
 
658
728
  it "gets the right s3_host_name in production" do
659
729
  rails_env("production") do
660
730
  assert_match %r{^s3-world-end.amazonaws.com}, @dummy.avatar.s3_host_name
661
- assert_match %r{^s3-world-end.amazonaws.com}, @dummy.avatar.s3_bucket.config.s3_endpoint
731
+ if defined?(::Aws)
732
+ assert_match %r{^s3.world-end.amazonaws.com},
733
+ @dummy.avatar.s3_bucket.client.config.endpoint.host
734
+ else
735
+ assert_match %r{^s3-world-end.amazonaws.com},
736
+ @dummy.avatar.s3_bucket.config.s3_endpoint
737
+ end
662
738
  end
663
739
  end
664
740
 
665
741
  it "gets the right s3_host_name in development" do
666
742
  rails_env("development") do
667
743
  assert_match %r{^s3-ap-northeast-1.amazonaws.com}, @dummy.avatar.s3_host_name
668
- assert_match %r{^s3-ap-northeast-1.amazonaws.com}, @dummy.avatar.s3_bucket.config.s3_endpoint
744
+ if defined?(::Aws)
745
+ assert_match %r{^s3-ap-northeast-1.amazonaws.com},
746
+ @dummy.avatar.s3_bucket.client.config.endpoint.host
747
+ else
748
+ assert_match %r{^s3-ap-northeast-1.amazonaws.com},
749
+ @dummy.avatar.s3_bucket.config.s3_endpoint
750
+ end
669
751
  end
670
752
  end
671
753
 
672
754
  it "gets the right s3_host_name if the key does not exist" do
673
755
  rails_env("test") do
674
756
  assert_match %r{^s3.amazonaws.com}, @dummy.avatar.s3_host_name
675
- assert_match %r{^s3.amazonaws.com}, @dummy.avatar.s3_bucket.config.s3_endpoint
757
+ if defined?(::Aws)
758
+ # :s3_region is *required* for aws-sdk-v2
759
+ assert_raises(Aws::Errors::MissingRegionError) do
760
+ @dummy.avatar.s3_bucket.client.config.endpoint.host
761
+ end
762
+ else
763
+ assert_match %r{^s3.amazonaws.com},
764
+ @dummy.avatar.s3_bucket.config.s3_endpoint
765
+ end
676
766
  end
677
767
  end
678
768
  end
679
769
 
680
770
  context "An attachment with S3 storage" do
681
771
  before do
682
- rebuild_model storage: :s3,
772
+ rebuild_model (aws2_add_region).merge storage: :s3,
683
773
  bucket: "testing",
684
774
  path: ":attachment/:style/:basename:dotextension",
685
775
  s3_credentials: {
686
- aws_access_key_id: "12345",
687
- aws_secret_access_key: "54321"
776
+ access_key_id: "12345",
777
+ secret_access_key: "54321"
688
778
  }
689
779
  end
690
780
 
@@ -714,15 +804,22 @@ describe Paperclip::Storage::S3 do
714
804
 
715
805
  it "is rewound after flush_writes" do
716
806
  @dummy.avatar.instance_eval "def after_flush_writes; end"
717
- @dummy.avatar.stubs(:s3_object).returns(stub(write: true))
718
-
807
+ if defined?(::Aws)
808
+ @dummy.avatar.stubs(:s3_object).returns(stub(upload_file: true))
809
+ else
810
+ @dummy.avatar.stubs(:s3_object).returns(stub(write: true))
811
+ end
719
812
  files = @dummy.avatar.queued_for_write.values.each(&:read)
720
813
  @dummy.save
721
814
  assert files.none?(&:eof?), "Expect all the files to be rewound."
722
815
  end
723
816
 
724
817
  it "is removed after after_flush_writes" do
725
- @dummy.avatar.stubs(:s3_object).returns(stub(write: true))
818
+ if defined?(::Aws)
819
+ @dummy.avatar.stubs(:s3_object).returns(stub(upload_file: true))
820
+ else
821
+ @dummy.avatar.stubs(:s3_object).returns(stub(write: true))
822
+ end
726
823
  paths = @dummy.avatar.queued_for_write.values.map(&:path)
727
824
  @dummy.save
728
825
  assert paths.none?{ |path| File.exist?(path) },
@@ -731,10 +828,17 @@ describe Paperclip::Storage::S3 do
731
828
 
732
829
  it "will retry to save again but back off on SlowDown" do
733
830
  @dummy.avatar.stubs(:sleep)
734
- AWS::S3::S3Object.any_instance.stubs(:write).
735
- raises(AWS::S3::Errors::SlowDown.new(stub, stub(status: 503, body: "")))
736
-
737
- expect {@dummy.save}.to raise_error(AWS::S3::Errors::SlowDown)
831
+ if defined?(::Aws)
832
+ Aws::S3::Object.any_instance.stubs(:upload_file).
833
+ raises(Aws::S3::Errors::SlowDown.new(stub,
834
+ stub(status: 503, body: "")))
835
+ expect {@dummy.save}.to raise_error(Aws::S3::Errors::SlowDown)
836
+ else
837
+ AWS::S3::S3Object.any_instance.stubs(:write).
838
+ raises(AWS::S3::Errors::SlowDown.new(stub,
839
+ stub(status: 503, body: "")))
840
+ expect {@dummy.save}.to raise_error(AWS::S3::Errors::SlowDown)
841
+ end
738
842
  expect(@dummy.avatar).to have_received(:sleep).with(1)
739
843
  expect(@dummy.avatar).to have_received(:sleep).with(2)
740
844
  expect(@dummy.avatar).to have_received(:sleep).with(4)
@@ -746,9 +850,9 @@ describe Paperclip::Storage::S3 do
746
850
  before do
747
851
  object = stub
748
852
  @dummy.avatar.stubs(:s3_object).returns(object)
749
- object.expects(:write).with(anything,
750
- content_type: "image/png",
751
- acl: :public_read)
853
+ object.expects((defined?(::Aws) ? :upload_file : :write))
854
+ .with(anything, content_type: 'image/png',
855
+ acl: Paperclip::Storage::S3::DEFAULT_PERMISSION)
752
856
  @dummy.save
753
857
  end
754
858
 
@@ -759,12 +863,21 @@ describe Paperclip::Storage::S3 do
759
863
 
760
864
  context "and saved without a bucket" do
761
865
  before do
762
- AWS::S3::BucketCollection.any_instance.expects(:create).with("testing")
763
- AWS::S3::S3Object.any_instance.stubs(:write).
764
- raises(AWS::S3::Errors::NoSuchBucket.new(stub,
765
- stub(status: 404,
766
- body: "<foo/>"))).
767
- then.returns(nil)
866
+ if defined?(::Aws)
867
+ Aws::S3::Bucket.any_instance.expects(:create)
868
+ Aws::S3::Object.any_instance.stubs(:upload_file).
869
+ raises(Aws::S3::Errors::NoSuchBucket
870
+ .new(stub,
871
+ stub(status: 404, body: "<foo/>"))).then.returns(nil)
872
+ else
873
+ AWS::S3::BucketCollection.any_instance.expects(:create)
874
+ .with("testing")
875
+ AWS::S3::S3Object.any_instance.stubs(:write).
876
+ raises(AWS::S3::Errors::NoSuchBucket.new(stub,
877
+ stub(status: 404,
878
+ body: "<foo/>"))).
879
+ then.returns(nil)
880
+ end
768
881
  @dummy.save
769
882
  end
770
883
 
@@ -775,8 +888,13 @@ describe Paperclip::Storage::S3 do
775
888
 
776
889
  context "and remove" do
777
890
  before do
778
- AWS::S3::S3Object.any_instance.stubs(:exists?).returns(true)
779
- AWS::S3::S3Object.any_instance.stubs(:delete)
891
+ if defined?(::Aws)
892
+ Aws::S3::Object.any_instance.stubs(:exists?).returns(true)
893
+ Aws::S3::Object.any_instance.stubs(:delete)
894
+ else
895
+ AWS::S3::S3Object.any_instance.stubs(:exists?).returns(true)
896
+ AWS::S3::S3Object.any_instance.stubs(:delete)
897
+ end
780
898
  @dummy.destroy
781
899
  end
782
900
 
@@ -787,7 +905,14 @@ describe Paperclip::Storage::S3 do
787
905
 
788
906
  context 'that the file were missing' do
789
907
  before do
790
- AWS::S3::S3Object.any_instance.stubs(:exists?).raises(AWS::Errors::Base)
908
+ if defined?(::Aws)
909
+ Aws::S3::Object.any_instance.stubs(:exists?)
910
+ .raises(Aws::S3::Errors::ServiceError.new("rspec stub raises",
911
+ "object exists?"))
912
+ else
913
+ AWS::S3::S3Object.any_instance.stubs(:exists?)
914
+ .raises(AWS::Errors::Base)
915
+ end
791
916
  end
792
917
 
793
918
  it 'returns false on exists?' do
@@ -799,7 +924,7 @@ describe Paperclip::Storage::S3 do
799
924
 
800
925
  context "An attachment with S3 storage and bucket defined as a Proc" do
801
926
  before do
802
- rebuild_model storage: :s3,
927
+ rebuild_model (aws2_add_region).merge storage: :s3,
803
928
  bucket: lambda { |attachment| "bucket_#{attachment.instance.other}" },
804
929
  s3_credentials: {not: :important}
805
930
  end
@@ -814,7 +939,7 @@ describe Paperclip::Storage::S3 do
814
939
 
815
940
  context "An attachment with S3 storage and S3 credentials defined as a Proc" do
816
941
  before do
817
- rebuild_model storage: :s3,
942
+ rebuild_model (aws2_add_region).merge storage: :s3,
818
943
  bucket: {not: :important},
819
944
  s3_credentials: lambda { |attachment|
820
945
  Hash['access_key_id' => "access#{attachment.instance.other}", 'secret_access_key' => "secret#{attachment.instance.other}"]
@@ -831,22 +956,35 @@ describe Paperclip::Storage::S3 do
831
956
  before do
832
957
  class DummyCredentialProvider; end
833
958
 
834
- rebuild_model storage: :s3,
835
- bucket: "testing",
836
- s3_credentials: {
837
- credential_provider: DummyCredentialProvider.new
838
- }
839
- @dummy = Dummy.new
959
+ if defined?(::Aws)
960
+ rebuild_model (aws2_add_region).merge storage: :s3,
961
+ bucket: "testing",
962
+ s3_credentials: {
963
+ credentials: DummyCredentialProvider.new
964
+ }
965
+ else
966
+ rebuild_model storage: :s3,
967
+ bucket: "testing",
968
+ s3_credentials: {
969
+ credential_provider: DummyCredentialProvider.new
970
+ }
971
+ end
972
+ @dummy = Dummy.new
840
973
  end
841
974
 
842
975
  it "sets the credential-provider" do
843
- expect(@dummy.avatar.s3_bucket.config.credential_provider).to be_a DummyCredentialProvider
976
+ if defined?(::Aws)
977
+ expect(@dummy.avatar.s3_bucket.client.config.credentials).to be_a DummyCredentialProvider
978
+ else
979
+ expect(@dummy.avatar.s3_bucket.config.credential_provider).to be_a DummyCredentialProvider
980
+ end
844
981
  end
845
982
  end
846
983
 
847
984
  context "An attachment with S3 storage and S3 credentials in an unsupported manor" do
848
985
  before do
849
- rebuild_model storage: :s3, bucket: "testing", s3_credentials: ["unsupported"]
986
+ rebuild_model (aws2_add_region).merge storage: :s3,
987
+ bucket: "testing", s3_credentials: ["unsupported"]
850
988
  @dummy = Dummy.new
851
989
  end
852
990
 
@@ -859,7 +997,7 @@ describe Paperclip::Storage::S3 do
859
997
 
860
998
  context "An attachment with S3 storage and S3 credentials not supplied" do
861
999
  before do
862
- rebuild_model storage: :s3, bucket: "testing"
1000
+ rebuild_model (aws2_add_region).merge storage: :s3, bucket: "testing"
863
1001
  @dummy = Dummy.new
864
1002
  end
865
1003
 
@@ -870,7 +1008,7 @@ describe Paperclip::Storage::S3 do
870
1008
 
871
1009
  context "An attachment with S3 storage and specific s3 headers set" do
872
1010
  before do
873
- rebuild_model storage: :s3,
1011
+ rebuild_model (aws2_add_region).merge storage: :s3,
874
1012
  bucket: "testing",
875
1013
  path: ":attachment/:style/:basename:dotextension",
876
1014
  s3_credentials: {
@@ -893,10 +1031,12 @@ describe Paperclip::Storage::S3 do
893
1031
  before do
894
1032
  object = stub
895
1033
  @dummy.avatar.stubs(:s3_object).returns(object)
896
- object.expects(:write).with(anything,
897
- content_type: "image/png",
898
- acl: :public_read,
899
- cache_control: 'max-age=31557600')
1034
+
1035
+ object.expects((defined?(::Aws) ? :upload_file : :write))
1036
+ .with(anything,
1037
+ content_type: 'image/png',
1038
+ acl: Paperclip::Storage::S3::DEFAULT_PERMISSION,
1039
+ cache_control: 'max-age=31557600')
900
1040
  @dummy.save
901
1041
  end
902
1042
 
@@ -909,7 +1049,7 @@ describe Paperclip::Storage::S3 do
909
1049
 
910
1050
  context "An attachment with S3 storage and metadata set using header names" do
911
1051
  before do
912
- rebuild_model storage: :s3,
1052
+ rebuild_model (aws2_add_region).merge storage: :s3,
913
1053
  bucket: "testing",
914
1054
  path: ":attachment/:style/:basename:dotextension",
915
1055
  s3_credentials: {
@@ -932,10 +1072,12 @@ describe Paperclip::Storage::S3 do
932
1072
  before do
933
1073
  object = stub
934
1074
  @dummy.avatar.stubs(:s3_object).returns(object)
935
- object.expects(:write).with(anything,
936
- content_type: "image/png",
937
- acl: :public_read,
938
- metadata: { "color" => "red" })
1075
+
1076
+ object.expects((defined?(::Aws) ? :upload_file : :write))
1077
+ .with(anything,
1078
+ content_type: 'image/png',
1079
+ acl: Paperclip::Storage::S3::DEFAULT_PERMISSION,
1080
+ metadata: { "color" => "red" })
939
1081
  @dummy.save
940
1082
  end
941
1083
 
@@ -948,7 +1090,7 @@ describe Paperclip::Storage::S3 do
948
1090
 
949
1091
  context "An attachment with S3 storage and metadata set using the :s3_metadata option" do
950
1092
  before do
951
- rebuild_model storage: :s3,
1093
+ rebuild_model (aws2_add_region).merge storage: :s3,
952
1094
  bucket: "testing",
953
1095
  path: ":attachment/:style/:basename:dotextension",
954
1096
  s3_credentials: {
@@ -971,10 +1113,12 @@ describe Paperclip::Storage::S3 do
971
1113
  before do
972
1114
  object = stub
973
1115
  @dummy.avatar.stubs(:s3_object).returns(object)
974
- object.expects(:write).with(anything,
975
- content_type: "image/png",
976
- acl: :public_read,
977
- metadata: { "color" => "red" })
1116
+
1117
+ object.expects((defined?(::Aws) ? :upload_file : :write))
1118
+ .with(anything,
1119
+ content_type: 'image/png',
1120
+ acl: Paperclip::Storage::S3::DEFAULT_PERMISSION,
1121
+ metadata: { "color" => "red" })
978
1122
  @dummy.save
979
1123
  end
980
1124
 
@@ -988,7 +1132,7 @@ describe Paperclip::Storage::S3 do
988
1132
  context "An attachment with S3 storage and storage class set" do
989
1133
  context "using the header name" do
990
1134
  before do
991
- rebuild_model storage: :s3,
1135
+ rebuild_model (aws2_add_region).merge storage: :s3,
992
1136
  bucket: "testing",
993
1137
  path: ":attachment/:style/:basename:dotextension",
994
1138
  s3_credentials: {
@@ -1011,10 +1155,12 @@ describe Paperclip::Storage::S3 do
1011
1155
  before do
1012
1156
  object = stub
1013
1157
  @dummy.avatar.stubs(:s3_object).returns(object)
1014
- object.expects(:write).with(anything,
1015
- content_type: "image/png",
1016
- acl: :public_read,
1017
- storage_class: "reduced_redundancy")
1158
+
1159
+ object.expects((defined?(::Aws) ? :upload_file : :write))
1160
+ .with(anything,
1161
+ content_type: 'image/png',
1162
+ acl: Paperclip::Storage::S3::DEFAULT_PERMISSION,
1163
+ storage_class: "reduced_redundancy")
1018
1164
  @dummy.save
1019
1165
  end
1020
1166
 
@@ -1027,7 +1173,7 @@ describe Paperclip::Storage::S3 do
1027
1173
 
1028
1174
  context "using per style hash" do
1029
1175
  before do
1030
- rebuild_model :storage => :s3,
1176
+ rebuild_model (aws2_add_region).merge :storage => :s3,
1031
1177
  :bucket => "testing",
1032
1178
  :path => ":attachment/:style/:basename.:extension",
1033
1179
  :styles => {
@@ -1056,9 +1202,15 @@ describe Paperclip::Storage::S3 do
1056
1202
  object = stub
1057
1203
  [:thumb, :original].each do |style|
1058
1204
  @dummy.avatar.stubs(:s3_object).with(style).returns(object)
1059
- expected_options = {:content_type => "image/png", :acl => :public_read}
1205
+
1206
+ expected_options = {
1207
+ :content_type => "image/png",
1208
+ :acl => Paperclip::Storage::S3::DEFAULT_PERMISSION
1209
+ }
1060
1210
  expected_options.merge!(:storage_class => :reduced_redundancy) if style == :thumb
1061
- object.expects(:write).with(anything, expected_options)
1211
+
1212
+ object.expects((defined?(::Aws) ? :upload_file : :write))
1213
+ .with(anything, expected_options)
1062
1214
  end
1063
1215
  @dummy.save
1064
1216
  end
@@ -1072,7 +1224,7 @@ describe Paperclip::Storage::S3 do
1072
1224
 
1073
1225
  context "using global hash option" do
1074
1226
  before do
1075
- rebuild_model :storage => :s3,
1227
+ rebuild_model (aws2_add_region).merge :storage => :s3,
1076
1228
  :bucket => "testing",
1077
1229
  :path => ":attachment/:style/:basename.:extension",
1078
1230
  :styles => {
@@ -1099,9 +1251,11 @@ describe Paperclip::Storage::S3 do
1099
1251
  object = stub
1100
1252
  [:thumb, :original].each do |style|
1101
1253
  @dummy.avatar.stubs(:s3_object).with(style).returns(object)
1102
- object.expects(:write).with(anything, :content_type => "image/png",
1103
- :acl => :public_read,
1104
- :storage_class => :reduced_redundancy)
1254
+
1255
+ object.expects((defined?(::Aws) ? :upload_file : :write))
1256
+ .with(anything, :content_type => "image/png",
1257
+ :acl => Paperclip::Storage::S3::DEFAULT_PERMISSION,
1258
+ :storage_class => :reduced_redundancy)
1105
1259
  end
1106
1260
  @dummy.save
1107
1261
  end
@@ -1118,7 +1272,7 @@ describe Paperclip::Storage::S3 do
1118
1272
  [nil, false, ''].each do |tech|
1119
1273
  before do
1120
1274
  rebuild_model(
1121
- storage: :s3,
1275
+ (aws2_add_region).merge storage: :s3,
1122
1276
  bucket: "testing",
1123
1277
  path: ":attachment/:style/:basename:dotextension",
1124
1278
  s3_credentials: {
@@ -1140,9 +1294,10 @@ describe Paperclip::Storage::S3 do
1140
1294
  before do
1141
1295
  object = stub
1142
1296
  @dummy.avatar.stubs(:s3_object).returns(object)
1143
- object.expects(:write).with(anything,
1144
- content_type: "image/png",
1145
- acl: :public_read)
1297
+
1298
+ object.expects((defined?(::Aws) ? :upload_file : :write))
1299
+ .with(anything, :content_type => "image/png",
1300
+ :acl => Paperclip::Storage::S3::DEFAULT_PERMISSION)
1146
1301
  @dummy.save
1147
1302
  end
1148
1303
 
@@ -1156,7 +1311,7 @@ describe Paperclip::Storage::S3 do
1156
1311
 
1157
1312
  context "An attachment with S3 storage and using AES256 encryption" do
1158
1313
  before do
1159
- rebuild_model storage: :s3,
1314
+ rebuild_model (aws2_add_region).merge storage: :s3,
1160
1315
  bucket: "testing",
1161
1316
  path: ":attachment/:style/:basename:dotextension",
1162
1317
  s3_credentials: {
@@ -1179,10 +1334,11 @@ describe Paperclip::Storage::S3 do
1179
1334
  before do
1180
1335
  object = stub
1181
1336
  @dummy.avatar.stubs(:s3_object).returns(object)
1182
- object.expects(:write).with(anything,
1183
- content_type: "image/png",
1184
- acl: :public_read,
1185
- server_side_encryption: :aes256)
1337
+
1338
+ object.expects((defined?(::Aws) ? :upload_file : :write))
1339
+ .with(anything, content_type: "image/png",
1340
+ acl: Paperclip::Storage::S3::DEFAULT_PERMISSION,
1341
+ server_side_encryption: :aes256)
1186
1342
  @dummy.save
1187
1343
  end
1188
1344
 
@@ -1195,7 +1351,7 @@ describe Paperclip::Storage::S3 do
1195
1351
 
1196
1352
  context "An attachment with S3 storage and storage class set using the :storage_class option" do
1197
1353
  before do
1198
- rebuild_model storage: :s3,
1354
+ rebuild_model (aws2_add_region).merge storage: :s3,
1199
1355
  bucket: "testing",
1200
1356
  path: ":attachment/:style/:basename:dotextension",
1201
1357
  s3_credentials: {
@@ -1218,10 +1374,12 @@ describe Paperclip::Storage::S3 do
1218
1374
  before do
1219
1375
  object = stub
1220
1376
  @dummy.avatar.stubs(:s3_object).returns(object)
1221
- object.expects(:write).with(anything,
1222
- content_type: "image/png",
1223
- acl: :public_read,
1224
- storage_class: :reduced_redundancy)
1377
+
1378
+ object.expects((defined?(::Aws) ? :upload_file : :write))
1379
+ .with(anything,
1380
+ content_type: "image/png",
1381
+ acl: Paperclip::Storage::S3::DEFAULT_PERMISSION,
1382
+ storage_class: :reduced_redundancy)
1225
1383
  @dummy.save
1226
1384
  end
1227
1385
 
@@ -1239,7 +1397,7 @@ describe Paperclip::Storage::S3 do
1239
1397
  ENV['S3_SECRET'] = 'pathname_secret'
1240
1398
 
1241
1399
  rails_env('test') do
1242
- rebuild_model storage: :s3,
1400
+ rebuild_model (aws2_add_region).merge storage: :s3,
1243
1401
  s3_credentials: Pathname.new(fixture_file('s3.yml'))
1244
1402
 
1245
1403
  Dummy.delete_all
@@ -1249,8 +1407,16 @@ describe Paperclip::Storage::S3 do
1249
1407
 
1250
1408
  it "parses the credentials" do
1251
1409
  assert_equal 'pathname_bucket', @dummy.avatar.bucket_name
1252
- assert_equal 'pathname_key', @dummy.avatar.s3_bucket.config.access_key_id
1253
- assert_equal 'pathname_secret', @dummy.avatar.s3_bucket.config.secret_access_key
1410
+
1411
+ assert_equal 'pathname_key',
1412
+ (defined?(::Aws) ?
1413
+ @dummy.avatar.s3_bucket.client.config.access_key_id :
1414
+ @dummy.avatar.s3_bucket.config.access_key_id)
1415
+
1416
+ assert_equal 'pathname_secret',
1417
+ (defined?(::Aws) ?
1418
+ @dummy.avatar.s3_bucket.client.config.secret_access_key :
1419
+ @dummy.avatar.s3_bucket.config.secret_access_key)
1254
1420
  end
1255
1421
  end
1256
1422
 
@@ -1261,7 +1427,7 @@ describe Paperclip::Storage::S3 do
1261
1427
  ENV['S3_SECRET'] = 'env_secret'
1262
1428
 
1263
1429
  rails_env('test') do
1264
- rebuild_model storage: :s3,
1430
+ rebuild_model (aws2_add_region).merge storage: :s3,
1265
1431
  s3_credentials: File.new(fixture_file('s3.yml'))
1266
1432
 
1267
1433
  Dummy.delete_all
@@ -1272,15 +1438,23 @@ describe Paperclip::Storage::S3 do
1272
1438
 
1273
1439
  it "runs the file through ERB" do
1274
1440
  assert_equal 'env_bucket', @dummy.avatar.bucket_name
1275
- assert_equal 'env_key', @dummy.avatar.s3_bucket.config.access_key_id
1276
- assert_equal 'env_secret', @dummy.avatar.s3_bucket.config.secret_access_key
1441
+
1442
+ assert_equal 'env_key',
1443
+ (defined?(::Aws) ?
1444
+ @dummy.avatar.s3_bucket.client.config.access_key_id :
1445
+ @dummy.avatar.s3_bucket.config.access_key_id)
1446
+
1447
+ assert_equal 'env_secret',
1448
+ (defined?(::Aws) ?
1449
+ @dummy.avatar.s3_bucket.client.config.secret_access_key :
1450
+ @dummy.avatar.s3_bucket.config.secret_access_key)
1277
1451
  end
1278
1452
  end
1279
1453
 
1280
1454
  context "S3 Permissions" do
1281
1455
  context "defaults to :public_read" do
1282
1456
  before do
1283
- rebuild_model storage: :s3,
1457
+ rebuild_model (aws2_add_region).merge storage: :s3,
1284
1458
  bucket: "testing",
1285
1459
  path: ":attachment/:style/:basename:dotextension",
1286
1460
  s3_credentials: {
@@ -1302,9 +1476,11 @@ describe Paperclip::Storage::S3 do
1302
1476
  before do
1303
1477
  object = stub
1304
1478
  @dummy.avatar.stubs(:s3_object).returns(object)
1305
- object.expects(:write).with(anything,
1306
- content_type: "image/png",
1307
- acl: :public_read)
1479
+
1480
+ object.expects((defined?(::Aws) ? :upload_file : :write))
1481
+ .with(anything,
1482
+ content_type: "image/png",
1483
+ acl: Paperclip::Storage::S3::DEFAULT_PERMISSION)
1308
1484
  @dummy.save
1309
1485
  end
1310
1486
 
@@ -1317,7 +1493,7 @@ describe Paperclip::Storage::S3 do
1317
1493
 
1318
1494
  context "string permissions set" do
1319
1495
  before do
1320
- rebuild_model storage: :s3,
1496
+ rebuild_model (aws2_add_region).merge storage: :s3,
1321
1497
  bucket: "testing",
1322
1498
  path: ":attachment/:style/:basename:dotextension",
1323
1499
  s3_credentials: {
@@ -1340,9 +1516,9 @@ describe Paperclip::Storage::S3 do
1340
1516
  before do
1341
1517
  object = stub
1342
1518
  @dummy.avatar.stubs(:s3_object).returns(object)
1343
- object.expects(:write).with(anything,
1344
- content_type: "image/png",
1345
- acl: :private)
1519
+
1520
+ object.expects((defined?(::Aws) ? :upload_file : :write))
1521
+ .with(anything, content_type: "image/png", acl: :private)
1346
1522
  @dummy.save
1347
1523
  end
1348
1524
 
@@ -1355,7 +1531,7 @@ describe Paperclip::Storage::S3 do
1355
1531
 
1356
1532
  context "hash permissions set" do
1357
1533
  before do
1358
- rebuild_model storage: :s3,
1534
+ rebuild_model (aws2_add_region).merge storage: :s3,
1359
1535
  bucket: "testing",
1360
1536
  path: ":attachment/:style/:basename:dotextension",
1361
1537
  styles: {
@@ -1385,9 +1561,11 @@ describe Paperclip::Storage::S3 do
1385
1561
  [:thumb, :original].each do |style|
1386
1562
  object = stub
1387
1563
  @dummy.avatar.stubs(:s3_object).with(style).returns(object)
1388
- object.expects(:write).with(anything,
1389
- content_type: "image/png",
1390
- acl: style == :thumb ? :public_read : :private)
1564
+
1565
+ object.expects((defined?(::Aws) ? :upload_file : :write))
1566
+ .with(anything,
1567
+ content_type: "image/png",
1568
+ acl: style == :thumb ? :public_read : :private)
1391
1569
  end
1392
1570
  @dummy.save
1393
1571
  end
@@ -1402,7 +1580,7 @@ describe Paperclip::Storage::S3 do
1402
1580
  context "proc permission set" do
1403
1581
  before do
1404
1582
  rebuild_model(
1405
- storage: :s3,
1583
+ (aws2_add_region).merge storage: :s3,
1406
1584
  bucket: "testing",
1407
1585
  path: ":attachment/:style/:basename:dotextension",
1408
1586
  styles: {
@@ -1413,7 +1591,7 @@ describe Paperclip::Storage::S3 do
1413
1591
  'secret_access_key' => "54321"
1414
1592
  },
1415
1593
  s3_permissions: lambda {|attachment, style|
1416
- attachment.instance.private_attachment? && style.to_sym != :thumb ? :private : :public_read
1594
+ attachment.instance.private_attachment? && style.to_sym != :thumb ? :private : Paperclip::Storage::S3::DEFAULT_PERMISSION
1417
1595
  }
1418
1596
  )
1419
1597
  end
@@ -1446,7 +1624,7 @@ describe Paperclip::Storage::S3 do
1446
1624
  context "An attachment with S3 storage and metadata set using a proc as headers" do
1447
1625
  before do
1448
1626
  rebuild_model(
1449
- storage: :s3,
1627
+ (aws2_add_region).merge storage: :s3,
1450
1628
  bucket: "testing",
1451
1629
  path: ":attachment/:style/:basename:dotextension",
1452
1630
  styles: {
@@ -1477,10 +1655,12 @@ describe Paperclip::Storage::S3 do
1477
1655
  [:thumb, :original].each do |style|
1478
1656
  object = stub
1479
1657
  @dummy.avatar.stubs(:s3_object).with(style).returns(object)
1480
- object.expects(:write).with(anything,
1481
- content_type: "image/png",
1482
- acl: :public_read,
1483
- content_disposition: 'attachment; filename="Custom Avatar Name.png"')
1658
+
1659
+ object.expects((defined?(::Aws) ? :upload_file : :write))
1660
+ .with(anything,
1661
+ content_type: "image/png",
1662
+ acl: Paperclip::Storage::S3::DEFAULT_PERMISSION,
1663
+ content_disposition: 'attachment; filename="Custom Avatar Name.png"')
1484
1664
  end
1485
1665
  @dummy.save
1486
1666
  end
@@ -1494,7 +1674,7 @@ describe Paperclip::Storage::S3 do
1494
1674
 
1495
1675
  context "path is a proc" do
1496
1676
  before do
1497
- rebuild_model storage: :s3,
1677
+ rebuild_model (aws2_add_region).merge storage: :s3,
1498
1678
  path: ->(attachment) { attachment.instance.attachment_path }
1499
1679
 
1500
1680
  @dummy = Dummy.new