resizing 1.2.2 → 1.4.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 (65) hide show
  1. checksums.yaml +4 -4
  2. data/.devcontainer/Dockerfile +73 -0
  3. data/.devcontainer/compose.yaml +61 -0
  4. data/.devcontainer/devcontainer-lock.json +9 -0
  5. data/.devcontainer/devcontainer.json +32 -0
  6. data/.devcontainer/post-create.sh +41 -0
  7. data/.github/copilot-instructions.md +1 -0
  8. data/.github/dependabot.yml +23 -0
  9. data/.github/labeler.yml +28 -0
  10. data/.github/release.yml +35 -0
  11. data/.github/tools/actionlint/Dockerfile +3 -0
  12. data/.github/tools/gitleaks/Dockerfile +2 -0
  13. data/.github/workflows/actionlint.yml +27 -0
  14. data/.github/workflows/actions.lock +54 -0
  15. data/.github/workflows/labeler.yml +22 -0
  16. data/.github/workflows/lint.yml +37 -0
  17. data/.github/workflows/secret-scan.yml +29 -0
  18. data/.github/workflows/test.yml +51 -13
  19. data/.github/workflows/verify-lockfile.yml +28 -0
  20. data/AGENTS.md +1 -0
  21. data/CHANGELOG.md +3 -0
  22. data/CLAUDE.md +68 -0
  23. data/Gemfile +12 -3
  24. data/README.ja.md +241 -0
  25. data/README.md +196 -2
  26. data/Rakefile +5 -7
  27. data/bin/setup +3 -0
  28. data/docker-compose.yml +7 -0
  29. data/git-hooks/pre-push +6 -0
  30. data/git-hooks/pre-push-ruby.sh +53 -0
  31. data/lib/resizing/carrier_wave/callback_file.rb +88 -0
  32. data/lib/resizing/carrier_wave/storage/file.rb +105 -38
  33. data/lib/resizing/carrier_wave/storage/remote.rb +25 -16
  34. data/lib/resizing/carrier_wave.rb +109 -6
  35. data/lib/resizing/client.rb +47 -4
  36. data/lib/resizing/configurable.rb +1 -1
  37. data/lib/resizing/configuration.rb +40 -10
  38. data/lib/resizing/mock_client.rb +48 -9
  39. data/lib/resizing/public_id.rb +3 -2
  40. data/lib/resizing/version.rb +1 -1
  41. data/lib/resizing.rb +4 -1
  42. data/resizing.gemspec +3 -3
  43. data/test/rails_app/app/views/users/new.html.erb +6 -0
  44. data/test/rails_app/rails_app.rb +86 -0
  45. data/test/resizing/carrier_wave/storage/file_test.rb +495 -9
  46. data/test/resizing/carrier_wave/storage/remote_test.rb +151 -12
  47. data/test/resizing/carrier_wave_cache_callbacks_test.rb +224 -0
  48. data/test/resizing/carrier_wave_callback_file_test.rb +77 -0
  49. data/test/resizing/carrier_wave_rails_integration_test.rb +94 -0
  50. data/test/resizing/carrier_wave_temporary_image_test.rb +280 -0
  51. data/test/resizing/carrier_wave_test.rb +214 -30
  52. data/test/resizing/carrier_wave_uploader_test.rb +225 -0
  53. data/test/resizing/client_test.rb +419 -30
  54. data/test/resizing/configuration_test.rb +235 -10
  55. data/test/resizing/http_clientable_test.rb +27 -0
  56. data/test/resizing/mock_client_test.rb +145 -1
  57. data/test/resizing/public_id_test.rb +96 -0
  58. data/test/resizing_module_test.rb +126 -0
  59. data/test/resizing_test.rb +8 -0
  60. data/test/test_helper.rb +318 -9
  61. data/test/vcr/carrier_wave_test/confirm.yml +23 -0
  62. data/test/vcr/carrier_wave_test/retrieve_from_cache.yml +23 -0
  63. data/test/vcr/carrier_wave_test/save.yml +1 -1
  64. data/test/vcr/carrier_wave_test/update_image.yml +42 -2
  65. metadata +47 -9
@@ -4,23 +4,14 @@ require 'test_helper'
4
4
 
5
5
  module Resizing
6
6
  class ClientTest < Minitest::Test
7
- def setup
8
- @configuration_template = {
9
- image_host: 'http://192.168.56.101:5000',
10
- video_host: 'http://192.168.56.101:5000',
11
- project_id: 'e06e710d-f026-4dcf-b2c0-eab0de8bb83f',
12
- secret_token: 'ewbym2r1pk49x1d2lxdbiiavnqp25j2kh00hsg3koy0ppm620x5mhlmgl3rq5ci8',
13
- open_timeout: 10,
14
- response_timeout: 20
15
- }
16
- end
7
+ include ResizingTestConfiguration
17
8
 
18
9
  def teardown
19
10
  # NOP
20
11
  end
21
12
 
22
13
  def test_is_initialized
23
- Resizing.configure = @configuration_template
14
+ Resizing.configure = configuration_template
24
15
 
25
16
  client = Resizing::Client.new
26
17
  assert(!client.config.nil?)
@@ -28,14 +19,14 @@ module Resizing
28
19
  end
29
20
 
30
21
  def test_is_initialized_with_configuration
31
- config = Resizing::Configuration.new(@configuration_template)
22
+ config = Resizing::Configuration.new(configuration_template)
32
23
  client = Resizing::Client.new(config)
33
24
  assert(!client.config.nil?)
34
25
  assert_equal(client.config, config)
35
26
  end
36
27
 
37
28
  def test_is_postable_with_filename
38
- Resizing.configure = @configuration_template
29
+ Resizing.configure = configuration_template
39
30
 
40
31
  client = Resizing::Client.new
41
32
  VCR.use_cassette 'client/post', record: :once do
@@ -53,7 +44,7 @@ module Resizing
53
44
  end
54
45
 
55
46
  def test_is_unpostable_with_filename
56
- Resizing.configure = @configuration_template
47
+ Resizing.configure = configuration_template
57
48
 
58
49
  client = Resizing::Client.new
59
50
  VCR.use_cassette 'client/post', record: :once do
@@ -64,7 +55,7 @@ module Resizing
64
55
  end
65
56
 
66
57
  def test_is_postable_with_file
67
- Resizing.configure = @configuration_template
58
+ Resizing.configure = configuration_template
68
59
 
69
60
  client = Resizing::Client.new
70
61
  VCR.use_cassette 'client/post', record: :once do
@@ -83,7 +74,7 @@ module Resizing
83
74
  end
84
75
 
85
76
  def test_is_timeout_with_post_method
86
- Resizing.configure = @configuration_template.merge(project_id: 'timeout_project_id')
77
+ Resizing.configure = configuration_template.merge(project_id: 'timeout_project_id')
87
78
 
88
79
  client = Resizing::Client.new
89
80
  f = File.open('test/data/images/sample1.jpg', 'r')
@@ -93,13 +84,14 @@ module Resizing
93
84
  end
94
85
 
95
86
  def test_is_putable_file
96
- Resizing.configure = @configuration_template
87
+ Resizing.configure = configuration_template
97
88
 
98
89
  client = Resizing::Client.new
99
90
  VCR.use_cassette 'client/put', record: :once do
100
91
  f = File.open('test/data/images/sample1.jpg', 'r')
101
92
  name = 'AWEaewfAreaweFAFASfwe'
102
- r = client.put(name, f, content_type: 'image/jpeg')
93
+ r = nil
94
+ capture_io { r = client.put(name, f, content_type: 'image/jpeg') }
103
95
  assert_equal(r['id'], name)
104
96
  assert_equal(r['project_id'], Resizing.configure.project_id)
105
97
  assert_equal(r['content_type'], 'image/jpeg')
@@ -115,19 +107,21 @@ module Resizing
115
107
  end
116
108
 
117
109
  def test_is_timeout_with_put_method
118
- Resizing.configure = @configuration_template.merge(project_id: 'timeout_project_id')
110
+ Resizing.configure = configuration_template.merge(project_id: 'timeout_project_id')
119
111
 
120
112
  client = Resizing::Client.new
121
113
  name = 'AWEaewfAreaweFAFASfwe'
122
114
  f = File.open('test/data/images/sample1.jpg', 'r')
123
115
 
124
- assert_raises Resizing::APIError do
125
- _r = client.put(name, f, content_type: 'image/jpeg')
116
+ capture_io do
117
+ assert_raises Resizing::APIError do
118
+ _r = client.put(name, f, content_type: 'image/jpeg')
119
+ end
126
120
  end
127
121
  end
128
122
 
129
123
  def test_raise_error
130
- Resizing.configure = @configuration_template
124
+ Resizing.configure = configuration_template
131
125
 
132
126
  client = Resizing::Client.new
133
127
  VCR.use_cassette 'client/error', record: :once do
@@ -139,7 +133,7 @@ module Resizing
139
133
  end
140
134
 
141
135
  def test_handleable_response_body_from_resizing
142
- Resizing.configure = @configuration_template
136
+ Resizing.configure = configuration_template
143
137
 
144
138
  client = Resizing::Client.new
145
139
  VCR.use_cassette 'client/error', record: :once do
@@ -159,7 +153,7 @@ module Resizing
159
153
  def test_get_the_metadata
160
154
  # TODO
161
155
 
162
- Resizing.configure = @configuration_template
156
+ Resizing.configure = configuration_template
163
157
 
164
158
  client = Resizing::Client.new
165
159
  VCR.use_cassette 'client/metadata', record: :once do
@@ -202,7 +196,7 @@ module Resizing
202
196
  end
203
197
 
204
198
  def test_get_raises_not_implemented_error
205
- Resizing.configure = @configuration_template
199
+ Resizing.configure = configuration_template
206
200
  client = Resizing::Client.new
207
201
 
208
202
  assert_raises NotImplementedError do
@@ -211,7 +205,7 @@ module Resizing
211
205
  end
212
206
 
213
207
  def test_post_raises_error_without_content_type
214
- Resizing.configure = @configuration_template
208
+ Resizing.configure = configuration_template
215
209
  client = Resizing::Client.new
216
210
 
217
211
  assert_raises ArgumentError do
@@ -220,7 +214,7 @@ module Resizing
220
214
  end
221
215
 
222
216
  def test_post_raises_error_with_invalid_io
223
- Resizing.configure = @configuration_template
217
+ Resizing.configure = configuration_template
224
218
  client = Resizing::Client.new
225
219
 
226
220
  assert_raises ArgumentError do
@@ -229,12 +223,407 @@ module Resizing
229
223
  end
230
224
 
231
225
  def test_put_raises_error_without_content_type
232
- Resizing.configure = @configuration_template
226
+ Resizing.configure = configuration_template
233
227
  client = Resizing::Client.new
234
228
 
235
- assert_raises ArgumentError do
236
- client.put('image_id', 'test/data/images/sample1.jpg', {})
229
+ capture_io do
230
+ assert_raises ArgumentError do
231
+ client.put('image_id', 'test/data/images/sample1.jpg', {})
232
+ end
233
+ end
234
+ end
235
+
236
+ # ============================================================
237
+ # 偽 HTTP クライアントを使ったリクエスト内容・レスポンス処理のテスト
238
+ # VCR カセットでは表現しづらい (URL, ヘッダ, multipart パラメータ, 異常系ステータス) を検証する
239
+ # ============================================================
240
+
241
+ # Faraday::Connection の代わりに使う偽クライアント
242
+ # 発行されたリクエスト (メソッド, URL, パラメータ, ヘッダ) を記録し、あらかじめ設定したレスポンスを返す
243
+ class FakeHttpClient
244
+ FakeRequest = Struct.new(:headers)
245
+ FakeResponse = Struct.new(:status, :body)
246
+
247
+ attr_reader :requests
248
+
249
+ def initialize(status: 200, body: '{}', respond_with_nil: false)
250
+ @response = respond_with_nil ? nil : FakeResponse.new(status, body)
251
+ @requests = []
252
+ end
253
+
254
+ %i[post put delete get].each do |verb|
255
+ define_method(verb) do |url, params = nil, &block|
256
+ request = FakeRequest.new({})
257
+ block&.call(request)
258
+ @requests << { method: verb, url: url, params: params, headers: request.headers }
259
+ @response
260
+ end
261
+ end
262
+
263
+ def last_request
264
+ @requests.last
265
+ end
266
+ end
267
+
268
+ def client_with_fake_http(**fake_options)
269
+ Resizing.configure = configuration_template
270
+ client = Resizing::Client.new
271
+ fake = FakeHttpClient.new(**fake_options)
272
+ client.instance_variable_set(:@http_client, fake)
273
+ [client, fake]
274
+ end
275
+
276
+ def base_url
277
+ "#{configuration_template[:image_host]}/projects/#{configuration_template[:project_id]}/upload/images"
278
+ end
279
+
280
+ def sample_path
281
+ 'test/data/images/sample1.jpg'
282
+ end
283
+
284
+ def not_found_body(image_id)
285
+ %({"error":"ActiveRecord::RecordNotFound","message":"Upload::Image##{image_id} not found(no record)"})
286
+ end
287
+
288
+ def forbidden_body
289
+ '{"error":"AuthenticatableSecretToken::SecretTokenError","message":"invalid token is found"}'
290
+ end
291
+
292
+ def test_post_sends_multipart_image_to_upload_url_with_auth_header
293
+ client, fake = client_with_fake_http(body: '{"id":"posted"}')
294
+
295
+ Timecop.freeze do
296
+ result = client.post(sample_path, content_type: 'image/jpeg')
297
+
298
+ request = fake.last_request
299
+ assert_equal :post, request[:method]
300
+ assert_equal "#{base_url}/", request[:url]
301
+ assert_equal client.config.generate_auth_header, request[:headers]['X-ResizingToken']
302
+
303
+ part = request[:params][:image]
304
+ assert_instance_of Faraday::Multipart::FilePart, part
305
+ assert_equal 'image/jpeg', part.content_type
306
+ assert_equal 'sample1.jpg', part.original_filename
307
+
308
+ assert_equal({ 'id' => 'posted' }, result)
309
+ end
310
+ end
311
+
312
+ def test_post_does_not_send_temporary_params_by_default
313
+ client, fake = client_with_fake_http
314
+
315
+ client.post(sample_path, content_type: 'image/jpeg')
316
+
317
+ assert_equal %i[image], fake.last_request[:params].keys
318
+ end
319
+
320
+ def test_post_sends_temporary_param
321
+ client, fake = client_with_fake_http
322
+
323
+ client.post(sample_path, content_type: 'image/jpeg', temporary: true)
324
+
325
+ params = fake.last_request[:params]
326
+ assert_equal 'true', params[:temporary]
327
+ refute params.key?(:expires_in)
328
+ end
329
+
330
+ def test_post_sends_expires_in_param_in_seconds
331
+ client, fake = client_with_fake_http
332
+
333
+ client.post(sample_path, content_type: 'image/jpeg', temporary: true, expires_in: 2.hours)
334
+
335
+ assert_equal '7200', fake.last_request[:params][:expires_in]
336
+ end
337
+
338
+ def test_post_ignores_expires_in_without_temporary
339
+ client, fake = client_with_fake_http
340
+
341
+ client.post(sample_path, content_type: 'image/jpeg', temporary: false, expires_in: 3600)
342
+
343
+ assert_equal %i[image], fake.last_request[:params].keys
344
+ end
345
+
346
+ def test_confirm_sends_put_request_to_confirm_url_with_auth_header
347
+ client, fake = client_with_fake_http(body: '{"id":"img-1","temporary":false,"expires_at":null}')
348
+
349
+ result = client.confirm('img-1')
350
+
351
+ request = fake.last_request
352
+ assert_equal :put, request[:method]
353
+ assert_equal "#{base_url}/img-1/confirm", request[:url]
354
+ assert_nil request[:params]
355
+ assert_match(/\Av1,\d+,[0-9a-f]{64}\z/, request[:headers]['X-ResizingToken'])
356
+ assert_equal({ 'id' => 'img-1', 'temporary' => false, 'expires_at' => nil }, result)
357
+ end
358
+
359
+ def test_confirm_raises_api_error_on_not_found
360
+ # 存在しない・期限切れ・削除済みの画像は確定できない
361
+ client, = client_with_fake_http(status: 404, body: not_found_body('img-1'))
362
+
363
+ error = assert_raises(Resizing::APIError) { client.confirm('img-1') }
364
+
365
+ assert_equal 'ActiveRecord::RecordNotFound', error.decoded_body['error']
366
+ end
367
+
368
+ def test_confirm_raises_api_error_when_response_is_nil
369
+ client, = client_with_fake_http(respond_with_nil: true)
370
+
371
+ assert_raises(Resizing::APIError) { client.confirm('img-1') }
372
+ end
373
+
374
+ def test_post_uses_filename_option_over_path_basename
375
+ client, fake = client_with_fake_http
376
+
377
+ client.post(sample_path, content_type: 'image/jpeg', filename: 'renamed.jpg')
378
+
379
+ assert_equal 'renamed.jpg', fake.last_request[:params][:image].original_filename
380
+ end
381
+
382
+ def test_post_accepts_io_like_object
383
+ client, fake = client_with_fake_http
384
+ io = StringIO.new(File.binread(sample_path))
385
+
386
+ client.post(io, content_type: 'image/png', filename: 'from_io.png')
387
+
388
+ part = fake.last_request[:params][:image]
389
+ assert_same io, part.io
390
+ assert_equal 'image/png', part.content_type
391
+ assert_equal 'from_io.png', part.original_filename
392
+ end
393
+
394
+ def test_post_accepts_created_status
395
+ client, = client_with_fake_http(status: 201, body: '{"id":"created"}')
396
+
397
+ assert_equal({ 'id' => 'created' }, client.post(sample_path, content_type: 'image/jpeg'))
398
+ end
399
+
400
+ def test_post_raises_api_error_with_server_message_on_error_status
401
+ client, = client_with_fake_http(status: 403, body: forbidden_body)
402
+
403
+ error = assert_raises(Resizing::APIError) { client.post(sample_path, content_type: 'image/jpeg') }
404
+
405
+ assert_equal 'invalid token is found', error.message
406
+ assert_equal JSON.parse(forbidden_body), error.decoded_body
407
+ end
408
+
409
+ def test_post_raises_api_error_on_not_found
410
+ client, = client_with_fake_http(status: 404, body: not_found_body('x'))
411
+
412
+ assert_raises(Resizing::APIError) { client.post(sample_path, content_type: 'image/jpeg') }
413
+ end
414
+
415
+ def test_post_raises_api_error_with_status_code_when_body_is_not_json
416
+ client, = client_with_fake_http(status: 502, body: '<html>Bad Gateway</html>')
417
+
418
+ error = assert_raises(Resizing::APIError) { client.post(sample_path, content_type: 'image/jpeg') }
419
+
420
+ assert_equal 'invalid http status code 502', error.message
421
+ assert_equal({}, error.decoded_body)
422
+ end
423
+
424
+ def test_post_raises_api_error_when_response_is_nil
425
+ client, = client_with_fake_http(respond_with_nil: true)
426
+
427
+ error = assert_raises(Resizing::APIError) { client.post(sample_path, content_type: 'image/jpeg') }
428
+ assert_equal 'No response is returned', error.message
429
+ end
430
+
431
+ def test_put_sends_multipart_image_to_image_url_with_auth_header
432
+ client, fake = client_with_fake_http(body: '{"id":"img-1"}')
433
+
434
+ result = nil
435
+ capture_io { result = client.put('img-1', sample_path, content_type: 'image/jpeg') }
436
+
437
+ request = fake.last_request
438
+ assert_equal :put, request[:method]
439
+ assert_equal "#{base_url}/img-1", request[:url]
440
+ assert_match(/\Av1,\d+,[0-9a-f]{64}\z/, request[:headers]['X-ResizingToken'])
441
+ part = request[:params][:image]
442
+ assert_instance_of Faraday::Multipart::FilePart, part
443
+ assert_equal 'image/jpeg', part.content_type
444
+ assert_equal 'sample1.jpg', part.original_filename
445
+ assert_equal({ 'id' => 'img-1' }, result)
446
+ end
447
+
448
+ def test_put_raises_api_error_on_error_status
449
+ client, = client_with_fake_http(status: 403, body: forbidden_body)
450
+
451
+ error = nil
452
+ capture_io do
453
+ error = assert_raises(Resizing::APIError) { client.put('img-1', sample_path, content_type: 'image/jpeg') }
454
+ end
455
+ assert_equal 'invalid token is found', error.message
456
+ end
457
+
458
+ def test_put_raises_error_with_invalid_io
459
+ Resizing.configure = configuration_template
460
+ client = Resizing::Client.new
461
+
462
+ capture_io do
463
+ assert_raises ArgumentError do
464
+ client.put('image_id', 12_345, content_type: 'image/jpeg')
465
+ end
466
+ end
467
+ end
468
+
469
+ def test_put_warns_deprecation
470
+ client, = client_with_fake_http(body: '{"id":"img-1"}')
471
+
472
+ _out, err = capture_io { client.put('img-1', sample_path, content_type: 'image/jpeg') }
473
+
474
+ assert_includes err, Resizing::Client::DEPRECATED_PUT_MESSAGE
475
+ end
476
+
477
+ def test_delete_sends_delete_request_to_image_url_with_auth_header
478
+ client, fake = client_with_fake_http(body: '{"id":"img-1"}')
479
+
480
+ result = client.delete('img-1')
481
+
482
+ request = fake.last_request
483
+ assert_equal :delete, request[:method]
484
+ assert_equal "#{base_url}/img-1", request[:url]
485
+ assert_match(/\Av1,\d+,[0-9a-f]{64}\z/, request[:headers]['X-ResizingToken'])
486
+ assert_equal({ 'id' => 'img-1' }, result)
487
+ end
488
+
489
+ def test_delete_returns_error_body_without_raising_on_not_found
490
+ client, = client_with_fake_http(status: 404, body: not_found_body('img-1'))
491
+
492
+ result = client.delete('img-1')
493
+
494
+ assert_equal 'ActiveRecord::RecordNotFound', result['error']
495
+ end
496
+
497
+ def test_delete_raises_api_error_on_other_error_status
498
+ client, = client_with_fake_http(status: 403, body: forbidden_body)
499
+
500
+ error = assert_raises(Resizing::APIError) { client.delete('img-1') }
501
+ assert_equal 'invalid token is found', error.message
502
+ end
503
+
504
+ def test_delete_raises_api_error_when_response_is_nil
505
+ client, = client_with_fake_http(respond_with_nil: true)
506
+
507
+ assert_raises(Resizing::APIError) { client.delete('img-1') }
508
+ end
509
+
510
+ def test_metadata_sends_get_request_to_metadata_url_with_auth_header
511
+ client, fake = client_with_fake_http(body: '{"id":"img-1","width":100}')
512
+
513
+ result = client.metadata('img-1')
514
+
515
+ request = fake.last_request
516
+ assert_equal :get, request[:method]
517
+ assert_equal "#{base_url}/img-1/metadata", request[:url]
518
+ assert_match(/\Av1,\d+,[0-9a-f]{64}\z/, request[:headers]['X-ResizingToken'])
519
+ assert_equal({ 'id' => 'img-1', 'width' => 100 }, result)
520
+ end
521
+
522
+ def test_metadata_returns_error_body_without_raising_on_not_found_by_default
523
+ client, = client_with_fake_http(status: 404, body: not_found_body('img-1'))
524
+
525
+ result = client.metadata('img-1')
526
+
527
+ assert_equal 'ActiveRecord::RecordNotFound', result['error']
528
+ end
529
+
530
+ def test_metadata_raises_api_error_on_not_found_when_requested
531
+ client, = client_with_fake_http(status: 404, body: not_found_body('img-1'))
532
+
533
+ error = assert_raises(Resizing::APIError) { client.metadata('img-1', when_not_found: :raise) }
534
+
535
+ assert_equal 'Upload::Image#img-1 not found(no record)', error.message
536
+ assert_equal 'ActiveRecord::RecordNotFound', error.decoded_body['error']
537
+ end
538
+
539
+ def test_metadata_raises_api_error_on_other_error_status
540
+ client, = client_with_fake_http(status: 500, body: 'Internal Server Error')
541
+
542
+ error = assert_raises(Resizing::APIError) { client.metadata('img-1') }
543
+ assert_equal 'invalid http status code 500', error.message
544
+ end
545
+
546
+ def test_metadata_raises_api_error_when_response_is_nil
547
+ client, = client_with_fake_http(respond_with_nil: true)
548
+
549
+ assert_raises(Resizing::APIError) { client.metadata('img-1') }
550
+ end
551
+
552
+ # ============================================================
553
+ # VCR カセットを使った delete / timeout のテスト
554
+ # ============================================================
555
+
556
+ def test_is_deletable
557
+ # client/delete.yml は別プロジェクト ID で記録されている
558
+ Resizing.configure = configuration_template.merge(project_id: '098a2a0d-c387-4135-a071-1254d6d7e70a')
559
+ client = Resizing::Client.new
560
+ image_id = '28c49144-c00d-4cb5-8619-98ce95977b9c'
561
+
562
+ VCR.use_cassette 'client/delete', record: :none do
563
+ r = client.delete(image_id)
564
+
565
+ assert_equal image_id, r['id']
566
+ assert_equal '098a2a0d-c387-4135-a071-1254d6d7e70a', r['project_id']
567
+ assert_equal(
568
+ "/projects/098a2a0d-c387-4135-a071-1254d6d7e70a/upload/images/#{image_id}/v1Id850__tqNsnoGWWUibtIBZ5NgjV45M",
569
+ r['public_id']
570
+ )
571
+ end
572
+ end
573
+
574
+ def test_is_timeout_with_delete_method
575
+ Resizing.configure = configuration_template.merge(project_id: 'timeout_project_id')
576
+ client = Resizing::Client.new
577
+
578
+ assert_raises Resizing::APIError do
579
+ client.delete('some_image_id')
580
+ end
581
+ end
582
+
583
+ def test_is_timeout_with_confirm_method
584
+ Resizing.configure = configuration_template.merge(project_id: 'timeout_project_id')
585
+
586
+ client = Resizing::Client.new
587
+ assert_raises Resizing::APIError do
588
+ client.confirm('img-1')
237
589
  end
238
590
  end
591
+
592
+ def test_is_timeout_with_metadata_method
593
+ Resizing.configure = configuration_template.merge(project_id: 'timeout_project_id')
594
+ client = Resizing::Client.new
595
+
596
+ assert_raises Resizing::APIError do
597
+ client.metadata('some_image_id')
598
+ end
599
+ end
600
+
601
+ # ============================================================
602
+ # 設定の受け渡し
603
+ # ============================================================
604
+
605
+ def test_is_initialized_with_hash
606
+ client = Resizing::Client.new(configuration_template)
607
+
608
+ assert_equal Resizing::Configuration.new(configuration_template), client.config
609
+ end
610
+
611
+ def test_each_client_instance_keeps_its_own_configuration
612
+ Resizing.configure = configuration_template
613
+ other = Resizing::Client.new(configuration_template.merge(project_id: 'other-project'))
614
+
615
+ assert_equal 'other-project', other.config.project_id
616
+ assert_equal configuration_template[:project_id], Resizing::Client.new.config.project_id
617
+ end
618
+
619
+ def test_client_uses_configuration_at_instantiation
620
+ Resizing.configure = configuration_template
621
+ client = Resizing::Client.new
622
+
623
+ # インスタンス生成後にグローバル設定を差し替えても既存クライアントには影響しない
624
+ Resizing.configure = configuration_template.merge(project_id: 'replaced-project')
625
+
626
+ assert_equal configuration_template[:project_id], client.config.project_id
627
+ end
239
628
  end
240
629
  end