paperclip 4.2.2 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. data/.hound.yml +1066 -0
  3. data/.rubocop.yml +1 -0
  4. data/.travis.yml +18 -15
  5. data/Appraisals +20 -12
  6. data/CONTRIBUTING.md +19 -8
  7. data/Gemfile +4 -9
  8. data/LICENSE +1 -1
  9. data/NEWS +101 -31
  10. data/README.md +243 -159
  11. data/RELEASING.md +17 -0
  12. data/Rakefile +1 -1
  13. data/UPGRADING +12 -9
  14. data/features/basic_integration.feature +8 -4
  15. data/features/migration.feature +0 -24
  16. data/features/step_definitions/attachment_steps.rb +27 -21
  17. data/features/step_definitions/html_steps.rb +2 -2
  18. data/features/step_definitions/rails_steps.rb +11 -17
  19. data/features/step_definitions/s3_steps.rb +2 -2
  20. data/features/step_definitions/web_steps.rb +1 -103
  21. data/features/support/file_helpers.rb +2 -2
  22. data/gemfiles/4.2.awsv2.0.gemfile +17 -0
  23. data/gemfiles/4.2.awsv2.1.gemfile +17 -0
  24. data/gemfiles/{4.1.gemfile → 4.2.awsv2.gemfile} +4 -3
  25. data/gemfiles/5.0.awsv2.0.gemfile +17 -0
  26. data/gemfiles/5.0.awsv2.1.gemfile +17 -0
  27. data/gemfiles/{4.2.gemfile → 5.0.awsv2.gemfile} +4 -3
  28. data/lib/paperclip/attachment.rb +19 -16
  29. data/lib/paperclip/attachment_registry.rb +3 -2
  30. data/lib/paperclip/callbacks.rb +8 -6
  31. data/lib/paperclip/content_type_detector.rb +27 -11
  32. data/lib/paperclip/errors.rb +3 -1
  33. data/lib/paperclip/file_command_content_type_detector.rb +6 -8
  34. data/lib/paperclip/geometry_parser_factory.rb +1 -1
  35. data/lib/paperclip/glue.rb +1 -1
  36. data/lib/paperclip/has_attached_file.rb +9 -2
  37. data/lib/paperclip/helpers.rb +14 -10
  38. data/lib/paperclip/interpolations/plural_cache.rb +6 -5
  39. data/lib/paperclip/interpolations.rb +18 -13
  40. data/lib/paperclip/io_adapters/abstract_adapter.rb +1 -0
  41. data/lib/paperclip/io_adapters/http_url_proxy_adapter.rb +1 -1
  42. data/lib/paperclip/io_adapters/uri_adapter.rb +3 -1
  43. data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +4 -4
  44. data/lib/paperclip/media_type_spoof_detector.rb +2 -2
  45. data/lib/paperclip/rails_environment.rb +25 -0
  46. data/lib/paperclip/schema.rb +3 -9
  47. data/lib/paperclip/storage/fog.rb +21 -12
  48. data/lib/paperclip/storage/s3.rb +51 -50
  49. data/lib/paperclip/thumbnail.rb +2 -3
  50. data/lib/paperclip/validators/attachment_size_validator.rb +1 -7
  51. data/lib/paperclip/version.rb +3 -1
  52. data/lib/paperclip.rb +15 -4
  53. data/lib/tasks/paperclip.rake +17 -1
  54. data/paperclip.gemspec +18 -15
  55. data/spec/paperclip/attachment_definitions_spec.rb +1 -1
  56. data/spec/paperclip/attachment_processing_spec.rb +2 -4
  57. data/spec/paperclip/attachment_registry_spec.rb +84 -13
  58. data/spec/paperclip/attachment_spec.rb +91 -31
  59. data/spec/paperclip/content_type_detector_spec.rb +8 -1
  60. data/spec/paperclip/file_command_content_type_detector_spec.rb +0 -1
  61. data/spec/paperclip/geometry_spec.rb +1 -1
  62. data/spec/paperclip/glue_spec.rb +44 -0
  63. data/spec/paperclip/has_attached_file_spec.rb +24 -8
  64. data/spec/paperclip/integration_spec.rb +4 -3
  65. data/spec/paperclip/interpolations_spec.rb +16 -13
  66. data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +2 -1
  67. data/spec/paperclip/io_adapters/file_adapter_spec.rb +4 -1
  68. data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +12 -0
  69. data/spec/paperclip/io_adapters/stringio_adapter_spec.rb +4 -0
  70. data/spec/paperclip/io_adapters/uri_adapter_spec.rb +27 -0
  71. data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +10 -0
  72. data/spec/paperclip/media_type_spoof_detector_spec.rb +34 -11
  73. data/spec/paperclip/paperclip_spec.rb +4 -29
  74. data/spec/paperclip/plural_cache_spec.rb +17 -16
  75. data/spec/paperclip/rails_environment_spec.rb +33 -0
  76. data/spec/paperclip/storage/fog_spec.rb +42 -3
  77. data/spec/paperclip/storage/s3_live_spec.rb +8 -4
  78. data/spec/paperclip/storage/s3_spec.rb +255 -180
  79. data/spec/paperclip/tempfile_factory_spec.rb +4 -0
  80. data/spec/paperclip/thumbnail_spec.rb +16 -0
  81. data/spec/paperclip/url_generator_spec.rb +1 -1
  82. data/spec/paperclip/validators/attachment_size_validator_spec.rb +26 -20
  83. data/spec/paperclip/validators_spec.rb +3 -3
  84. data/spec/spec_helper.rb +6 -1
  85. data/spec/support/assertions.rb +7 -0
  86. data/spec/support/fake_model.rb +4 -0
  87. data/spec/support/fixtures/empty.xlsx +0 -0
  88. data/spec/support/matchers/have_column.rb +11 -2
  89. data/spec/support/model_reconstruction.rb +9 -1
  90. data/spec/support/reporting.rb +11 -0
  91. metadata +105 -54
  92. data/RUNNING_TESTS.md +0 -4
  93. data/cucumber/paperclip_steps.rb +0 -6
  94. data/gemfiles/3.2.gemfile +0 -19
  95. data/gemfiles/4.0.gemfile +0 -19
  96. data/lib/paperclip/locales/de.yml +0 -18
  97. data/lib/paperclip/locales/es.yml +0 -18
  98. data/lib/paperclip/locales/ja.yml +0 -18
  99. data/lib/paperclip/locales/pt-BR.yml +0 -18
  100. data/lib/paperclip/locales/zh-CN.yml +0 -18
  101. data/lib/paperclip/locales/zh-HK.yml +0 -18
  102. data/lib/paperclip/locales/zh-TW.yml +0 -18
  103. data/spec/support/mock_model.rb +0 -2
  104. 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
- AWS.stub!
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, s3_credentials: {bucket: 'testing'}
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, bucket: "testing", s3_credentials: {}
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,13 +103,14 @@ 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",
105
110
  url: ":s3_path_url"
106
111
  @dummy = Dummy.new
107
112
  @dummy.avatar = stringy_file
113
+ @dummy.stubs(:new_record?).returns(false)
108
114
  end
109
115
 
110
116
  it "returns a url based on an S3 path" do
@@ -124,8 +130,8 @@ describe Paperclip::Storage::S3 do
124
130
  ["http", :http, ""].each do |protocol|
125
131
  context "as #{protocol.inspect}" do
126
132
  before do
127
- rebuild_model storage: :s3, s3_protocol: protocol
128
-
133
+ rebuild_model (aws2_add_region).merge storage: :s3,
134
+ s3_protocol: protocol
129
135
  @dummy = Dummy.new
130
136
  end
131
137
 
@@ -138,13 +144,14 @@ describe Paperclip::Storage::S3 do
138
144
 
139
145
  context "s3_protocol: 'https'" do
140
146
  before do
141
- rebuild_model storage: :s3,
147
+ rebuild_model (aws2_add_region).merge storage: :s3,
142
148
  s3_credentials: {},
143
149
  s3_protocol: 'https',
144
150
  bucket: "bucket",
145
151
  path: ":attachment/:basename:dotextension"
146
152
  @dummy = Dummy.new
147
153
  @dummy.avatar = stringy_file
154
+ @dummy.stubs(:new_record?).returns(false)
148
155
  end
149
156
 
150
157
  it "returns a url based on an S3 path" do
@@ -154,13 +161,14 @@ describe Paperclip::Storage::S3 do
154
161
 
155
162
  context "s3_protocol: ''" do
156
163
  before do
157
- rebuild_model storage: :s3,
164
+ rebuild_model (aws2_add_region).merge storage: :s3,
158
165
  s3_credentials: {},
159
166
  s3_protocol: '',
160
167
  bucket: "bucket",
161
168
  path: ":attachment/:basename:dotextension"
162
169
  @dummy = Dummy.new
163
170
  @dummy.avatar = stringy_file
171
+ @dummy.stubs(:new_record?).returns(false)
164
172
  end
165
173
 
166
174
  it "returns a protocol-relative URL" do
@@ -170,13 +178,14 @@ describe Paperclip::Storage::S3 do
170
178
 
171
179
  context "s3_protocol: :https" do
172
180
  before do
173
- rebuild_model storage: :s3,
181
+ rebuild_model (aws2_add_region).merge storage: :s3,
174
182
  s3_credentials: {},
175
183
  s3_protocol: :https,
176
184
  bucket: "bucket",
177
185
  path: ":attachment/:basename:dotextension"
178
186
  @dummy = Dummy.new
179
187
  @dummy.avatar = stringy_file
188
+ @dummy.stubs(:new_record?).returns(false)
180
189
  end
181
190
 
182
191
  it "returns a url based on an S3 path" do
@@ -186,13 +195,14 @@ describe Paperclip::Storage::S3 do
186
195
 
187
196
  context "s3_protocol: ''" do
188
197
  before do
189
- rebuild_model storage: :s3,
198
+ rebuild_model (aws2_add_region).merge storage: :s3,
190
199
  s3_credentials: {},
191
200
  s3_protocol: '',
192
201
  bucket: "bucket",
193
202
  path: ":attachment/:basename:dotextension"
194
203
  @dummy = Dummy.new
195
204
  @dummy.avatar = stringy_file
205
+ @dummy.stubs(:new_record?).returns(false)
196
206
  end
197
207
 
198
208
  it "returns a url based on an S3 path" do
@@ -202,7 +212,7 @@ describe Paperclip::Storage::S3 do
202
212
 
203
213
  context "An attachment that uses S3 for storage and has the style in the path" do
204
214
  before do
205
- rebuild_model storage: :s3,
215
+ rebuild_model (aws2_add_region).merge storage: :s3,
206
216
  bucket: "testing",
207
217
  path: ":attachment/:style/:basename:dotextension",
208
218
  styles: {
@@ -227,15 +237,18 @@ describe Paperclip::Storage::S3 do
227
237
  end
228
238
  end
229
239
 
240
+ # if using aws-sdk-v2, the s3_host_name will be defined by the s3_region
230
241
  context "s3_host_name" do
231
242
  before do
232
243
  rebuild_model storage: :s3,
233
244
  s3_credentials: {},
234
245
  bucket: "bucket",
235
246
  path: ":attachment/:basename:dotextension",
236
- 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"
237
249
  @dummy = Dummy.new
238
250
  @dummy.avatar = stringy_file
251
+ @dummy.stubs(:new_record?).returns(false)
239
252
  end
240
253
 
241
254
  it "returns a url based on an :s3_host_name path" do
@@ -243,13 +256,14 @@ describe Paperclip::Storage::S3 do
243
256
  end
244
257
 
245
258
  it "uses the S3 bucket with the correct host name" do
246
- assert_equal "s3-ap-northeast-1.amazonaws.com", @dummy.avatar.s3_bucket.config.s3_endpoint
259
+ assert_equal "s3-ap-northeast-1.amazonaws.com",
260
+ @dummy.avatar.s3_bucket.client.config.endpoint.host
247
261
  end
248
262
  end
249
263
 
250
264
  context "dynamic s3_host_name" do
251
265
  before do
252
- rebuild_model storage: :s3,
266
+ rebuild_model (aws2_add_region).merge storage: :s3,
253
267
  s3_credentials: {},
254
268
  bucket: "bucket",
255
269
  path: ":attachment/:basename:dotextension",
@@ -259,6 +273,7 @@ describe Paperclip::Storage::S3 do
259
273
  attr_accessor :value
260
274
  end
261
275
  @dummy.avatar = stringy_file
276
+ @dummy.stubs(:new_record?).returns(false)
262
277
  end
263
278
 
264
279
  it "uses s3_host_name as a proc if available" do
@@ -269,8 +284,8 @@ describe Paperclip::Storage::S3 do
269
284
 
270
285
  context "An attachment that uses S3 for storage and has styles that return different file types" do
271
286
  before do
272
- rebuild_model styles: { large: ['500x500#', :jpg] },
273
- storage: :s3,
287
+ rebuild_model (aws2_add_region).merge storage: :s3,
288
+ styles: { large: ['500x500#', :jpg] },
274
289
  bucket: "bucket",
275
290
  path: ":attachment/:basename:dotextension",
276
291
  s3_credentials: {
@@ -281,6 +296,7 @@ describe Paperclip::Storage::S3 do
281
296
  File.open(fixture_file('5k.png'), 'rb') do |file|
282
297
  @dummy = Dummy.new
283
298
  @dummy.avatar = file
299
+ @dummy.stubs(:new_record?).returns(false)
284
300
  end
285
301
  end
286
302
 
@@ -303,8 +319,10 @@ describe Paperclip::Storage::S3 do
303
319
 
304
320
  context "An attachment that uses S3 for storage and has a proc for styles" do
305
321
  before do
306
- rebuild_model styles: lambda { |attachment| attachment.instance.counter; {thumbnail: { geometry: "50x50#", s3_headers: {'Cache-Control' => 'max-age=31557600'}} }},
307
- storage: :s3,
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'}} }},
308
326
  bucket: "bucket",
309
327
  path: ":attachment/:style/:basename:dotextension",
310
328
  s3_credentials: {
@@ -328,8 +346,14 @@ describe Paperclip::Storage::S3 do
328
346
  object = stub
329
347
  @dummy.avatar.stubs(:s3_object).with(:original).returns(object)
330
348
  @dummy.avatar.stubs(:s3_object).with(:thumbnail).returns(object)
331
- object.expects(:write).with(anything, content_type: 'image/png', acl: :public_read)
332
- object.expects(:write).with(anything, content_type: 'image/png', acl: :public_read, cache_control: 'max-age=31557600')
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')
333
357
  @dummy.save
334
358
  end
335
359
 
@@ -342,18 +366,19 @@ describe Paperclip::Storage::S3 do
342
366
 
343
367
  context "An attachment that uses S3 for storage and has spaces in file name" do
344
368
  before do
345
- rebuild_model styles: { large: ['500x500#', :jpg] },
346
- storage: :s3,
369
+ rebuild_model(
370
+ (aws2_add_region).merge storage: :s3,
371
+ styles: { large: ["500x500#", :jpg] },
347
372
  bucket: "bucket",
348
- s3_credentials: {
349
- 'access_key_id' => "12345",
350
- 'secret_access_key' => "54321"
351
- }
373
+ s3_credentials: { "access_key_id" => "12345",
374
+ "secret_access_key" => "54321" }
375
+ )
352
376
 
353
- File.open(fixture_file('spaced file.png'), 'rb') do |file|
354
- @dummy = Dummy.new
355
- @dummy.avatar = file
356
- end
377
+ File.open(fixture_file("spaced file.png"), "rb") do |file|
378
+ @dummy = Dummy.new
379
+ @dummy.avatar = file
380
+ @dummy.stubs(:new_record?).returns(false)
381
+ end
357
382
  end
358
383
 
359
384
  it "returns a replaced version for path" do
@@ -367,24 +392,25 @@ describe Paperclip::Storage::S3 do
367
392
 
368
393
  context "An attachment that uses S3 for storage and has a question mark in file name" do
369
394
  before do
370
- rebuild_model styles: { large: ['500x500#', :jpg] },
371
- storage: :s3,
395
+ rebuild_model (aws2_add_region).merge storage: :s3,
396
+ styles: { large: ['500x500#', :jpg] },
372
397
  bucket: "bucket",
373
398
  s3_credentials: {
374
399
  'access_key_id' => "12345",
375
400
  'secret_access_key' => "54321"
376
401
  }
377
402
 
378
- stringio = stringy_file
379
- class << stringio
380
- def original_filename
381
- "question?mark.png"
382
- end
403
+ stringio = stringy_file
404
+ class << stringio
405
+ def original_filename
406
+ "question?mark.png"
383
407
  end
384
- file = Paperclip.io_adapters.for(stringio)
385
- @dummy = Dummy.new
386
- @dummy.avatar = file
387
- @dummy.save
408
+ end
409
+ file = Paperclip.io_adapters.for(stringio)
410
+ @dummy = Dummy.new
411
+ @dummy.avatar = file
412
+ @dummy.save
413
+ @dummy.stubs(:new_record?).returns(false)
388
414
  end
389
415
 
390
416
  it "returns a replaced version for path" do
@@ -398,13 +424,14 @@ describe Paperclip::Storage::S3 do
398
424
 
399
425
  context "" do
400
426
  before do
401
- rebuild_model storage: :s3,
427
+ rebuild_model (aws2_add_region).merge storage: :s3,
402
428
  s3_credentials: {},
403
429
  bucket: "bucket",
404
430
  path: ":attachment/:basename:dotextension",
405
431
  url: ":s3_domain_url"
406
432
  @dummy = Dummy.new
407
433
  @dummy.avatar = stringy_file
434
+ @dummy.stubs(:new_record?).returns(false)
408
435
  end
409
436
 
410
437
  it "returns a url based on an S3 subdomain" do
@@ -414,16 +441,20 @@ describe Paperclip::Storage::S3 do
414
441
 
415
442
  context "" do
416
443
  before do
417
- rebuild_model storage: :s3,
444
+ rebuild_model(
445
+ (aws2_add_region).merge storage: :s3,
418
446
  s3_credentials: {
419
- production: { bucket: "prod_bucket" },
420
- development: { bucket: "dev_bucket" }
421
- },
422
- s3_host_alias: "something.something.com",
423
- path: ":attachment/:basename:dotextension",
424
- url: ":s3_alias_url"
447
+ production: { bucket: "prod_bucket" },
448
+ development: { bucket: "dev_bucket" }
449
+ },
450
+ bucket: "bucket",
451
+ s3_host_alias: "something.something.com",
452
+ path: ":attachment/:basename:dotextension",
453
+ url: ":s3_alias_url"
454
+ )
425
455
  @dummy = Dummy.new
426
456
  @dummy.avatar = stringy_file
457
+ @dummy.stubs(:new_record?).returns(false)
427
458
  end
428
459
 
429
460
  it "returns a url based on the host_alias" do
@@ -433,7 +464,7 @@ describe Paperclip::Storage::S3 do
433
464
 
434
465
  context "generating a url with a proc as the host alias" do
435
466
  before do
436
- rebuild_model storage: :s3,
467
+ rebuild_model (aws2_add_region).merge storage: :s3,
437
468
  s3_credentials: { bucket: "prod_bucket" },
438
469
  s3_host_alias: Proc.new{|atch| "cdn#{atch.instance.counter % 4}.example.com"},
439
470
  path: ":attachment/:basename:dotextension",
@@ -447,6 +478,7 @@ describe Paperclip::Storage::S3 do
447
478
  end
448
479
  @dummy = Dummy.new
449
480
  @dummy.avatar = stringy_file
481
+ @dummy.stubs(:new_record?).returns(false)
450
482
  end
451
483
 
452
484
  it "returns a url based on the host_alias" do
@@ -462,13 +494,14 @@ describe Paperclip::Storage::S3 do
462
494
 
463
495
  context "" do
464
496
  before do
465
- rebuild_model storage: :s3,
497
+ rebuild_model (aws2_add_region).merge storage: :s3,
466
498
  s3_credentials: {},
467
499
  bucket: "bucket",
468
500
  path: ":attachment/:basename:dotextension",
469
501
  url: ":asset_host"
470
502
  @dummy = Dummy.new
471
503
  @dummy.avatar = stringy_file
504
+ @dummy.stubs(:new_record?).returns(false)
472
505
  end
473
506
 
474
507
  it "returns a relative URL for Rails to calculate assets host" do
@@ -492,7 +525,7 @@ describe Paperclip::Storage::S3 do
492
525
  url: ":s3_alias_url"
493
526
  }
494
527
 
495
- rebuild_model base_options.merge(options)
528
+ rebuild_model (aws2_add_region).merge base_options.merge(options)
496
529
  }
497
530
  end
498
531
 
@@ -505,8 +538,8 @@ describe Paperclip::Storage::S3 do
505
538
 
506
539
  object = stub
507
540
  @dummy.avatar.stubs(:s3_object).returns(object)
508
- object.expects(:url_for).with(:read, expires: 3600, secure: true)
509
541
 
542
+ object.expects(:presigned_url).with(:get, expires_in: 3600)
510
543
  @dummy.avatar.expiring_url
511
544
  end
512
545
  end
@@ -520,8 +553,9 @@ describe Paperclip::Storage::S3 do
520
553
 
521
554
  object = stub
522
555
  @dummy.avatar.stubs(:s3_object).returns(object)
523
- object.expects(:url_for).with(:read, expires: 3600, secure: true, response_content_disposition: "inline")
524
-
556
+ object.expects(:presigned_url)
557
+ .with(:get, expires_in: 3600,
558
+ response_content_disposition: "inline")
525
559
  @dummy.avatar.expiring_url
526
560
  end
527
561
  end
@@ -542,8 +576,8 @@ describe Paperclip::Storage::S3 do
542
576
 
543
577
  object = stub
544
578
  @dummy.avatar.stubs(:s3_object).returns(object)
545
- object.expects(:url_for).with(:read, expires: 3600, secure: true, response_content_type: "image/png")
546
-
579
+ object.expects(:presigned_url)
580
+ .with(:get, expires_in: 3600, response_content_type: "image/png")
547
581
  @dummy.avatar.expiring_url
548
582
  end
549
583
  end
@@ -571,15 +605,15 @@ describe Paperclip::Storage::S3 do
571
605
 
572
606
  context "Generating a url with an expiration for each style" do
573
607
  before do
574
- rebuild_model storage: :s3,
608
+ rebuild_model (aws2_add_region).merge storage: :s3,
575
609
  s3_credentials: {
576
- production: { bucket: "prod_bucket" },
577
- development: { bucket: "dev_bucket" }
578
- },
579
- s3_permissions: :private,
580
- s3_host_alias: "something.something.com",
581
- path: ":attachment/:style/:basename:dotextension",
582
- url: ":s3_alias_url"
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"
583
617
 
584
618
  rails_env("production") do
585
619
  @dummy = Dummy.new
@@ -590,26 +624,26 @@ describe Paperclip::Storage::S3 do
590
624
  it "generates a url for the thumb" do
591
625
  object = stub
592
626
  @dummy.avatar.stubs(:s3_object).with(:thumb).returns(object)
593
- object.expects(:url_for).with(:read, expires: 1800, secure: true)
627
+ object.expects(:presigned_url).with(:get, expires_in: 1800)
594
628
  @dummy.avatar.expiring_url(1800, :thumb)
595
629
  end
596
630
 
597
631
  it "generates a url for the default style" do
598
632
  object = stub
599
633
  @dummy.avatar.stubs(:s3_object).with(:original).returns(object)
600
- object.expects(:url_for).with(:read, expires: 1800, secure: true)
634
+ object.expects(:presigned_url).with(:get, expires_in: 1800)
601
635
  @dummy.avatar.expiring_url(1800)
602
636
  end
603
637
  end
604
638
 
605
639
  context "Parsing S3 credentials with a bucket in them" do
606
640
  before do
607
- rebuild_model storage: :s3,
641
+ rebuild_model (aws2_add_region).merge storage: :s3,
608
642
  s3_credentials: {
609
- production: { bucket: "prod_bucket" },
610
- development: { bucket: "dev_bucket" }
611
- }
612
- @dummy = Dummy.new
643
+ production: { bucket: "prod_bucket" },
644
+ development: { bucket: "dev_bucket" }
645
+ }
646
+ @dummy = Dummy.new
613
647
  end
614
648
 
615
649
  it "gets the right bucket in production" do
@@ -627,47 +661,58 @@ describe Paperclip::Storage::S3 do
627
661
  end
628
662
  end
629
663
 
664
+ # for aws-sdk-v2 the bucket.name is determined by the :s3_region
630
665
  context "Parsing S3 credentials with a s3_host_name in them" do
631
666
  before do
632
667
  rebuild_model storage: :s3,
633
668
  bucket: 'testing',
634
669
  s3_credentials: {
635
- production: { s3_host_name: "s3-world-end.amazonaws.com" },
636
- development: { s3_host_name: "s3-ap-northeast-1.amazonaws.com" }
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: "" }
637
678
  }
638
- @dummy = Dummy.new
679
+ @dummy = Dummy.new
639
680
  end
640
681
 
641
682
  it "gets the right s3_host_name in production" do
642
683
  rails_env("production") do
643
684
  assert_match %r{^s3-world-end.amazonaws.com}, @dummy.avatar.s3_host_name
644
- assert_match %r{^s3-world-end.amazonaws.com}, @dummy.avatar.s3_bucket.config.s3_endpoint
685
+ assert_match %r{^s3.world-end.amazonaws.com},
686
+ @dummy.avatar.s3_bucket.client.config.endpoint.host
645
687
  end
646
688
  end
647
689
 
648
690
  it "gets the right s3_host_name in development" do
649
691
  rails_env("development") do
650
692
  assert_match %r{^s3-ap-northeast-1.amazonaws.com}, @dummy.avatar.s3_host_name
651
- assert_match %r{^s3-ap-northeast-1.amazonaws.com}, @dummy.avatar.s3_bucket.config.s3_endpoint
693
+ assert_match %r{^s3-ap-northeast-1.amazonaws.com},
694
+ @dummy.avatar.s3_bucket.client.config.endpoint.host
652
695
  end
653
696
  end
654
697
 
655
698
  it "gets the right s3_host_name if the key does not exist" do
656
699
  rails_env("test") do
657
700
  assert_match %r{^s3.amazonaws.com}, @dummy.avatar.s3_host_name
658
- assert_match %r{^s3.amazonaws.com}, @dummy.avatar.s3_bucket.config.s3_endpoint
701
+ assert_raises(Aws::Errors::MissingRegionError) do
702
+ @dummy.avatar.s3_bucket.client.config.endpoint.host
703
+ end
659
704
  end
660
705
  end
661
706
  end
662
707
 
663
708
  context "An attachment with S3 storage" do
664
709
  before do
665
- rebuild_model storage: :s3,
710
+ rebuild_model (aws2_add_region).merge storage: :s3,
666
711
  bucket: "testing",
667
712
  path: ":attachment/:style/:basename:dotextension",
668
713
  s3_credentials: {
669
- aws_access_key_id: "12345",
670
- aws_secret_access_key: "54321"
714
+ access_key_id: "12345",
715
+ secret_access_key: "54321"
671
716
  }
672
717
  end
673
718
 
@@ -684,6 +729,7 @@ describe Paperclip::Storage::S3 do
684
729
  @file = File.new(fixture_file('5k.png'), 'rb')
685
730
  @dummy = Dummy.new
686
731
  @dummy.avatar = @file
732
+ @dummy.stubs(:new_record?).returns(false)
687
733
  end
688
734
 
689
735
  after { @file.close }
@@ -696,15 +742,14 @@ describe Paperclip::Storage::S3 do
696
742
 
697
743
  it "is rewound after flush_writes" do
698
744
  @dummy.avatar.instance_eval "def after_flush_writes; end"
699
- @dummy.avatar.stubs(:s3_object).returns(stub(write: true))
700
-
745
+ @dummy.avatar.stubs(:s3_object).returns(stub(upload_file: true))
701
746
  files = @dummy.avatar.queued_for_write.values.each(&:read)
702
747
  @dummy.save
703
748
  assert files.none?(&:eof?), "Expect all the files to be rewound."
704
749
  end
705
750
 
706
751
  it "is removed after after_flush_writes" do
707
- @dummy.avatar.stubs(:s3_object).returns(stub(write: true))
752
+ @dummy.avatar.stubs(:s3_object).returns(stub(upload_file: true))
708
753
  paths = @dummy.avatar.queued_for_write.values.map(&:path)
709
754
  @dummy.save
710
755
  assert paths.none?{ |path| File.exist?(path) },
@@ -713,10 +758,10 @@ describe Paperclip::Storage::S3 do
713
758
 
714
759
  it "will retry to save again but back off on SlowDown" do
715
760
  @dummy.avatar.stubs(:sleep)
716
- AWS::S3::S3Object.any_instance.stubs(:write).
717
- raises(AWS::S3::Errors::SlowDown.new(stub, stub(status: 503, body: "")))
718
-
719
- expect {@dummy.save}.to raise_error(AWS::S3::Errors::SlowDown)
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)
720
765
  expect(@dummy.avatar).to have_received(:sleep).with(1)
721
766
  expect(@dummy.avatar).to have_received(:sleep).with(2)
722
767
  expect(@dummy.avatar).to have_received(:sleep).with(4)
@@ -728,9 +773,8 @@ describe Paperclip::Storage::S3 do
728
773
  before do
729
774
  object = stub
730
775
  @dummy.avatar.stubs(:s3_object).returns(object)
731
- object.expects(:write).with(anything,
732
- content_type: "image/png",
733
- acl: :public_read)
776
+ object.expects(:upload_file)
777
+ .with(anything, content_type: 'image/png', acl: :"public-read")
734
778
  @dummy.save
735
779
  end
736
780
 
@@ -741,12 +785,11 @@ describe Paperclip::Storage::S3 do
741
785
 
742
786
  context "and saved without a bucket" do
743
787
  before do
744
- AWS::S3::BucketCollection.any_instance.expects(:create).with("testing")
745
- AWS::S3::S3Object.any_instance.stubs(:write).
746
- raises(AWS::S3::Errors::NoSuchBucket.new(stub,
747
- stub(status: 404,
748
- body: "<foo/>"))).
749
- 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)
750
793
  @dummy.save
751
794
  end
752
795
 
@@ -757,8 +800,8 @@ describe Paperclip::Storage::S3 do
757
800
 
758
801
  context "and remove" do
759
802
  before do
760
- AWS::S3::S3Object.any_instance.stubs(:exists?).returns(true)
761
- AWS::S3::S3Object.any_instance.stubs(:delete)
803
+ Aws::S3::Object.any_instance.stubs(:exists?).returns(true)
804
+ Aws::S3::Object.any_instance.stubs(:delete)
762
805
  @dummy.destroy
763
806
  end
764
807
 
@@ -769,7 +812,9 @@ describe Paperclip::Storage::S3 do
769
812
 
770
813
  context 'that the file were missing' do
771
814
  before do
772
- AWS::S3::S3Object.any_instance.stubs(:exists?).raises(AWS::Errors::Base)
815
+ Aws::S3::Object.any_instance.stubs(:exists?)
816
+ .raises(Aws::S3::Errors::ServiceError.new("rspec stub raises",
817
+ "object exists?"))
773
818
  end
774
819
 
775
820
  it 'returns false on exists?' do
@@ -781,7 +826,7 @@ describe Paperclip::Storage::S3 do
781
826
 
782
827
  context "An attachment with S3 storage and bucket defined as a Proc" do
783
828
  before do
784
- rebuild_model storage: :s3,
829
+ rebuild_model (aws2_add_region).merge storage: :s3,
785
830
  bucket: lambda { |attachment| "bucket_#{attachment.instance.other}" },
786
831
  s3_credentials: {not: :important}
787
832
  end
@@ -796,7 +841,7 @@ describe Paperclip::Storage::S3 do
796
841
 
797
842
  context "An attachment with S3 storage and S3 credentials defined as a Proc" do
798
843
  before do
799
- rebuild_model storage: :s3,
844
+ rebuild_model (aws2_add_region).merge storage: :s3,
800
845
  bucket: {not: :important},
801
846
  s3_credentials: lambda { |attachment|
802
847
  Hash['access_key_id' => "access#{attachment.instance.other}", 'secret_access_key' => "secret#{attachment.instance.other}"]
@@ -813,22 +858,23 @@ describe Paperclip::Storage::S3 do
813
858
  before do
814
859
  class DummyCredentialProvider; end
815
860
 
816
- rebuild_model storage: :s3,
861
+ rebuild_model (aws2_add_region).merge storage: :s3,
817
862
  bucket: "testing",
818
863
  s3_credentials: {
819
- credential_provider: DummyCredentialProvider.new
864
+ credentials: DummyCredentialProvider.new
820
865
  }
821
- @dummy = Dummy.new
866
+ @dummy = Dummy.new
822
867
  end
823
868
 
824
869
  it "sets the credential-provider" do
825
- expect(@dummy.avatar.s3_bucket.config.credential_provider).to be_a DummyCredentialProvider
870
+ expect(@dummy.avatar.s3_bucket.client.config.credentials).to be_a DummyCredentialProvider
826
871
  end
827
872
  end
828
873
 
829
874
  context "An attachment with S3 storage and S3 credentials in an unsupported manor" do
830
875
  before do
831
- rebuild_model storage: :s3, bucket: "testing", s3_credentials: ["unsupported"]
876
+ rebuild_model (aws2_add_region).merge storage: :s3,
877
+ bucket: "testing", s3_credentials: ["unsupported"]
832
878
  @dummy = Dummy.new
833
879
  end
834
880
 
@@ -841,7 +887,7 @@ describe Paperclip::Storage::S3 do
841
887
 
842
888
  context "An attachment with S3 storage and S3 credentials not supplied" do
843
889
  before do
844
- rebuild_model storage: :s3, bucket: "testing"
890
+ rebuild_model (aws2_add_region).merge storage: :s3, bucket: "testing"
845
891
  @dummy = Dummy.new
846
892
  end
847
893
 
@@ -852,7 +898,7 @@ describe Paperclip::Storage::S3 do
852
898
 
853
899
  context "An attachment with S3 storage and specific s3 headers set" do
854
900
  before do
855
- rebuild_model storage: :s3,
901
+ rebuild_model (aws2_add_region).merge storage: :s3,
856
902
  bucket: "testing",
857
903
  path: ":attachment/:style/:basename:dotextension",
858
904
  s3_credentials: {
@@ -875,10 +921,12 @@ describe Paperclip::Storage::S3 do
875
921
  before do
876
922
  object = stub
877
923
  @dummy.avatar.stubs(:s3_object).returns(object)
878
- object.expects(:write).with(anything,
879
- content_type: "image/png",
880
- acl: :public_read,
881
- cache_control: 'max-age=31557600')
924
+
925
+ object.expects(:upload_file)
926
+ .with(anything,
927
+ content_type: 'image/png',
928
+ acl: :"public-read",
929
+ cache_control: 'max-age=31557600')
882
930
  @dummy.save
883
931
  end
884
932
 
@@ -891,7 +939,7 @@ describe Paperclip::Storage::S3 do
891
939
 
892
940
  context "An attachment with S3 storage and metadata set using header names" do
893
941
  before do
894
- rebuild_model storage: :s3,
942
+ rebuild_model (aws2_add_region).merge storage: :s3,
895
943
  bucket: "testing",
896
944
  path: ":attachment/:style/:basename:dotextension",
897
945
  s3_credentials: {
@@ -914,10 +962,12 @@ describe Paperclip::Storage::S3 do
914
962
  before do
915
963
  object = stub
916
964
  @dummy.avatar.stubs(:s3_object).returns(object)
917
- object.expects(:write).with(anything,
918
- content_type: "image/png",
919
- acl: :public_read,
920
- metadata: { "color" => "red" })
965
+
966
+ object.expects(:upload_file)
967
+ .with(anything,
968
+ content_type: 'image/png',
969
+ acl: :"public-read",
970
+ metadata: { "color" => "red" })
921
971
  @dummy.save
922
972
  end
923
973
 
@@ -930,7 +980,7 @@ describe Paperclip::Storage::S3 do
930
980
 
931
981
  context "An attachment with S3 storage and metadata set using the :s3_metadata option" do
932
982
  before do
933
- rebuild_model storage: :s3,
983
+ rebuild_model (aws2_add_region).merge storage: :s3,
934
984
  bucket: "testing",
935
985
  path: ":attachment/:style/:basename:dotextension",
936
986
  s3_credentials: {
@@ -953,10 +1003,12 @@ describe Paperclip::Storage::S3 do
953
1003
  before do
954
1004
  object = stub
955
1005
  @dummy.avatar.stubs(:s3_object).returns(object)
956
- object.expects(:write).with(anything,
957
- content_type: "image/png",
958
- acl: :public_read,
959
- metadata: { "color" => "red" })
1006
+
1007
+ object.expects(:upload_file)
1008
+ .with(anything,
1009
+ content_type: 'image/png',
1010
+ acl: :"public-read",
1011
+ metadata: { "color" => "red" })
960
1012
  @dummy.save
961
1013
  end
962
1014
 
@@ -970,7 +1022,7 @@ describe Paperclip::Storage::S3 do
970
1022
  context "An attachment with S3 storage and storage class set" do
971
1023
  context "using the header name" do
972
1024
  before do
973
- rebuild_model storage: :s3,
1025
+ rebuild_model (aws2_add_region).merge storage: :s3,
974
1026
  bucket: "testing",
975
1027
  path: ":attachment/:style/:basename:dotextension",
976
1028
  s3_credentials: {
@@ -993,10 +1045,12 @@ describe Paperclip::Storage::S3 do
993
1045
  before do
994
1046
  object = stub
995
1047
  @dummy.avatar.stubs(:s3_object).returns(object)
996
- object.expects(:write).with(anything,
997
- content_type: "image/png",
998
- acl: :public_read,
999
- storage_class: "reduced_redundancy")
1048
+
1049
+ object.expects(:upload_file)
1050
+ .with(anything,
1051
+ content_type: 'image/png',
1052
+ acl: :"public-read",
1053
+ storage_class: "reduced_redundancy")
1000
1054
  @dummy.save
1001
1055
  end
1002
1056
 
@@ -1009,7 +1063,7 @@ describe Paperclip::Storage::S3 do
1009
1063
 
1010
1064
  context "using per style hash" do
1011
1065
  before do
1012
- rebuild_model :storage => :s3,
1066
+ rebuild_model (aws2_add_region).merge :storage => :s3,
1013
1067
  :bucket => "testing",
1014
1068
  :path => ":attachment/:style/:basename.:extension",
1015
1069
  :styles => {
@@ -1038,9 +1092,15 @@ describe Paperclip::Storage::S3 do
1038
1092
  object = stub
1039
1093
  [:thumb, :original].each do |style|
1040
1094
  @dummy.avatar.stubs(:s3_object).with(style).returns(object)
1041
- expected_options = {:content_type => "image/png", :acl => :public_read}
1095
+
1096
+ expected_options = {
1097
+ :content_type => "image/png",
1098
+ acl: :"public-read"
1099
+ }
1042
1100
  expected_options.merge!(:storage_class => :reduced_redundancy) if style == :thumb
1043
- object.expects(:write).with(anything, expected_options)
1101
+
1102
+ object.expects(:upload_file)
1103
+ .with(anything, expected_options)
1044
1104
  end
1045
1105
  @dummy.save
1046
1106
  end
@@ -1054,7 +1114,7 @@ describe Paperclip::Storage::S3 do
1054
1114
 
1055
1115
  context "using global hash option" do
1056
1116
  before do
1057
- rebuild_model :storage => :s3,
1117
+ rebuild_model (aws2_add_region).merge :storage => :s3,
1058
1118
  :bucket => "testing",
1059
1119
  :path => ":attachment/:style/:basename.:extension",
1060
1120
  :styles => {
@@ -1081,9 +1141,11 @@ describe Paperclip::Storage::S3 do
1081
1141
  object = stub
1082
1142
  [:thumb, :original].each do |style|
1083
1143
  @dummy.avatar.stubs(:s3_object).with(style).returns(object)
1084
- object.expects(:write).with(anything, :content_type => "image/png",
1085
- :acl => :public_read,
1086
- :storage_class => :reduced_redundancy)
1144
+
1145
+ object.expects(:upload_file)
1146
+ .with(anything, :content_type => "image/png",
1147
+ acl: :"public-read",
1148
+ :storage_class => :reduced_redundancy)
1087
1149
  end
1088
1150
  @dummy.save
1089
1151
  end
@@ -1100,7 +1162,7 @@ describe Paperclip::Storage::S3 do
1100
1162
  [nil, false, ''].each do |tech|
1101
1163
  before do
1102
1164
  rebuild_model(
1103
- storage: :s3,
1165
+ (aws2_add_region).merge storage: :s3,
1104
1166
  bucket: "testing",
1105
1167
  path: ":attachment/:style/:basename:dotextension",
1106
1168
  s3_credentials: {
@@ -1122,9 +1184,9 @@ describe Paperclip::Storage::S3 do
1122
1184
  before do
1123
1185
  object = stub
1124
1186
  @dummy.avatar.stubs(:s3_object).returns(object)
1125
- object.expects(:write).with(anything,
1126
- content_type: "image/png",
1127
- acl: :public_read)
1187
+
1188
+ object.expects(:upload_file)
1189
+ .with(anything, :content_type => "image/png", acl: :"public-read")
1128
1190
  @dummy.save
1129
1191
  end
1130
1192
 
@@ -1138,7 +1200,7 @@ describe Paperclip::Storage::S3 do
1138
1200
 
1139
1201
  context "An attachment with S3 storage and using AES256 encryption" do
1140
1202
  before do
1141
- rebuild_model storage: :s3,
1203
+ rebuild_model (aws2_add_region).merge storage: :s3,
1142
1204
  bucket: "testing",
1143
1205
  path: ":attachment/:style/:basename:dotextension",
1144
1206
  s3_credentials: {
@@ -1161,10 +1223,11 @@ describe Paperclip::Storage::S3 do
1161
1223
  before do
1162
1224
  object = stub
1163
1225
  @dummy.avatar.stubs(:s3_object).returns(object)
1164
- object.expects(:write).with(anything,
1165
- content_type: "image/png",
1166
- acl: :public_read,
1167
- server_side_encryption: :aes256)
1226
+
1227
+ object.expects(:upload_file)
1228
+ .with(anything, content_type: "image/png",
1229
+ acl: :"public-read",
1230
+ server_side_encryption: :aes256)
1168
1231
  @dummy.save
1169
1232
  end
1170
1233
 
@@ -1177,7 +1240,7 @@ describe Paperclip::Storage::S3 do
1177
1240
 
1178
1241
  context "An attachment with S3 storage and storage class set using the :storage_class option" do
1179
1242
  before do
1180
- rebuild_model storage: :s3,
1243
+ rebuild_model (aws2_add_region).merge storage: :s3,
1181
1244
  bucket: "testing",
1182
1245
  path: ":attachment/:style/:basename:dotextension",
1183
1246
  s3_credentials: {
@@ -1200,10 +1263,12 @@ describe Paperclip::Storage::S3 do
1200
1263
  before do
1201
1264
  object = stub
1202
1265
  @dummy.avatar.stubs(:s3_object).returns(object)
1203
- object.expects(:write).with(anything,
1204
- content_type: "image/png",
1205
- acl: :public_read,
1206
- storage_class: :reduced_redundancy)
1266
+
1267
+ object.expects(:upload_file)
1268
+ .with(anything,
1269
+ content_type: "image/png",
1270
+ acl: :"public-read",
1271
+ storage_class: :reduced_redundancy)
1207
1272
  @dummy.save
1208
1273
  end
1209
1274
 
@@ -1221,7 +1286,7 @@ describe Paperclip::Storage::S3 do
1221
1286
  ENV['S3_SECRET'] = 'pathname_secret'
1222
1287
 
1223
1288
  rails_env('test') do
1224
- rebuild_model storage: :s3,
1289
+ rebuild_model (aws2_add_region).merge storage: :s3,
1225
1290
  s3_credentials: Pathname.new(fixture_file('s3.yml'))
1226
1291
 
1227
1292
  Dummy.delete_all
@@ -1231,8 +1296,12 @@ describe Paperclip::Storage::S3 do
1231
1296
 
1232
1297
  it "parses the credentials" do
1233
1298
  assert_equal 'pathname_bucket', @dummy.avatar.bucket_name
1234
- assert_equal 'pathname_key', @dummy.avatar.s3_bucket.config.access_key_id
1235
- assert_equal 'pathname_secret', @dummy.avatar.s3_bucket.config.secret_access_key
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
1236
1305
  end
1237
1306
  end
1238
1307
 
@@ -1243,7 +1312,7 @@ describe Paperclip::Storage::S3 do
1243
1312
  ENV['S3_SECRET'] = 'env_secret'
1244
1313
 
1245
1314
  rails_env('test') do
1246
- rebuild_model storage: :s3,
1315
+ rebuild_model (aws2_add_region).merge storage: :s3,
1247
1316
  s3_credentials: File.new(fixture_file('s3.yml'))
1248
1317
 
1249
1318
  Dummy.delete_all
@@ -1254,15 +1323,19 @@ describe Paperclip::Storage::S3 do
1254
1323
 
1255
1324
  it "runs the file through ERB" do
1256
1325
  assert_equal 'env_bucket', @dummy.avatar.bucket_name
1257
- assert_equal 'env_key', @dummy.avatar.s3_bucket.config.access_key_id
1258
- assert_equal 'env_secret', @dummy.avatar.s3_bucket.config.secret_access_key
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
1259
1332
  end
1260
1333
  end
1261
1334
 
1262
1335
  context "S3 Permissions" do
1263
1336
  context "defaults to :public_read" do
1264
1337
  before do
1265
- rebuild_model storage: :s3,
1338
+ rebuild_model (aws2_add_region).merge storage: :s3,
1266
1339
  bucket: "testing",
1267
1340
  path: ":attachment/:style/:basename:dotextension",
1268
1341
  s3_credentials: {
@@ -1284,9 +1357,9 @@ describe Paperclip::Storage::S3 do
1284
1357
  before do
1285
1358
  object = stub
1286
1359
  @dummy.avatar.stubs(:s3_object).returns(object)
1287
- object.expects(:write).with(anything,
1288
- content_type: "image/png",
1289
- acl: :public_read)
1360
+
1361
+ object.expects(:upload_file)
1362
+ .with(anything, content_type: "image/png", acl: :"public-read")
1290
1363
  @dummy.save
1291
1364
  end
1292
1365
 
@@ -1299,7 +1372,7 @@ describe Paperclip::Storage::S3 do
1299
1372
 
1300
1373
  context "string permissions set" do
1301
1374
  before do
1302
- rebuild_model storage: :s3,
1375
+ rebuild_model (aws2_add_region).merge storage: :s3,
1303
1376
  bucket: "testing",
1304
1377
  path: ":attachment/:style/:basename:dotextension",
1305
1378
  s3_credentials: {
@@ -1322,9 +1395,9 @@ describe Paperclip::Storage::S3 do
1322
1395
  before do
1323
1396
  object = stub
1324
1397
  @dummy.avatar.stubs(:s3_object).returns(object)
1325
- object.expects(:write).with(anything,
1326
- content_type: "image/png",
1327
- acl: :private)
1398
+
1399
+ object.expects(:upload_file)
1400
+ .with(anything, content_type: "image/png", acl: :private)
1328
1401
  @dummy.save
1329
1402
  end
1330
1403
 
@@ -1337,7 +1410,7 @@ describe Paperclip::Storage::S3 do
1337
1410
 
1338
1411
  context "hash permissions set" do
1339
1412
  before do
1340
- rebuild_model storage: :s3,
1413
+ rebuild_model (aws2_add_region).merge storage: :s3,
1341
1414
  bucket: "testing",
1342
1415
  path: ":attachment/:style/:basename:dotextension",
1343
1416
  styles: {
@@ -1367,9 +1440,11 @@ describe Paperclip::Storage::S3 do
1367
1440
  [:thumb, :original].each do |style|
1368
1441
  object = stub
1369
1442
  @dummy.avatar.stubs(:s3_object).with(style).returns(object)
1370
- object.expects(:write).with(anything,
1371
- content_type: "image/png",
1372
- acl: style == :thumb ? :public_read : :private)
1443
+
1444
+ object.expects(:upload_file)
1445
+ .with(anything,
1446
+ content_type: "image/png",
1447
+ acl: style == :thumb ? :public_read : :private)
1373
1448
  end
1374
1449
  @dummy.save
1375
1450
  end
@@ -1384,7 +1459,7 @@ describe Paperclip::Storage::S3 do
1384
1459
  context "proc permission set" do
1385
1460
  before do
1386
1461
  rebuild_model(
1387
- storage: :s3,
1462
+ (aws2_add_region).merge storage: :s3,
1388
1463
  bucket: "testing",
1389
1464
  path: ":attachment/:style/:basename:dotextension",
1390
1465
  styles: {
@@ -1395,7 +1470,7 @@ describe Paperclip::Storage::S3 do
1395
1470
  'secret_access_key' => "54321"
1396
1471
  },
1397
1472
  s3_permissions: lambda {|attachment, style|
1398
- attachment.instance.private_attachment? && style.to_sym != :thumb ? :private : :public_read
1473
+ attachment.instance.private_attachment? && style.to_sym != :thumb ? :private : :"public-read"
1399
1474
  }
1400
1475
  )
1401
1476
  end
@@ -1428,7 +1503,7 @@ describe Paperclip::Storage::S3 do
1428
1503
  context "An attachment with S3 storage and metadata set using a proc as headers" do
1429
1504
  before do
1430
1505
  rebuild_model(
1431
- storage: :s3,
1506
+ (aws2_add_region).merge storage: :s3,
1432
1507
  bucket: "testing",
1433
1508
  path: ":attachment/:style/:basename:dotextension",
1434
1509
  styles: {
@@ -1459,10 +1534,12 @@ describe Paperclip::Storage::S3 do
1459
1534
  [:thumb, :original].each do |style|
1460
1535
  object = stub
1461
1536
  @dummy.avatar.stubs(:s3_object).with(style).returns(object)
1462
- object.expects(:write).with(anything,
1463
- content_type: "image/png",
1464
- acl: :public_read,
1465
- content_disposition: 'attachment; filename="Custom Avatar Name.png"')
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"')
1466
1543
  end
1467
1544
  @dummy.save
1468
1545
  end
@@ -1476,7 +1553,7 @@ describe Paperclip::Storage::S3 do
1476
1553
 
1477
1554
  context "path is a proc" do
1478
1555
  before do
1479
- rebuild_model storage: :s3,
1556
+ rebuild_model (aws2_add_region).merge storage: :s3,
1480
1557
  path: ->(attachment) { attachment.instance.attachment_path }
1481
1558
 
1482
1559
  @dummy = Dummy.new
@@ -1493,7 +1570,6 @@ describe Paperclip::Storage::S3 do
1493
1570
  end
1494
1571
  end
1495
1572
 
1496
-
1497
1573
  private
1498
1574
 
1499
1575
  def rails_env(env)
@@ -1504,5 +1580,4 @@ describe Paperclip::Storage::S3 do
1504
1580
  Rails.env = stored_env
1505
1581
  end
1506
1582
  end
1507
-
1508
1583
  end