resizing 1.0.1 → 1.0.2

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.
@@ -4,6 +4,8 @@ require 'test_helper'
4
4
 
5
5
  module Resizing
6
6
  class CarrierWaveTest < Minitest::Test
7
+ include VCRRequestAssertions
8
+
7
9
  def setup
8
10
  TestModel.delete_all
9
11
  TestJPGModel.delete_all
@@ -23,33 +25,42 @@ module Resizing
23
25
 
24
26
  def test_remove_resizing_picture
25
27
  model = prepare_model TestModel
28
+ model.save!
26
29
 
27
- VCR.use_cassette 'carrier_wave_test/remove_resizing_picture' do
30
+ # VCRカセットのDELETEリクエストが実際に発行されたことを確認
31
+ assert_vcr_requests_made 'carrier_wave_test/remove_resizing_picture' do
28
32
  model.remove_resizing_picture!
29
-
30
- assert_nil model.resizing_picture_url
33
+ model.save!
31
34
  end
35
+
36
+ # DELETEが成功した結果、URLがnilになることを確認
37
+ assert_nil model.resizing_picture_url
32
38
  end
33
39
 
34
- def test_do_not_raise_if_empty_column_is_removed
40
+ def test_remove_calls_delete_immediately
35
41
  model = prepare_model TestModel
42
+ model.save!
36
43
 
37
- VCR.use_cassette 'carrier_wave_test/remove_resizing_picture' do
44
+ # remove!を呼んだとき即時にDELETEリクエストがとぶことを確認する
45
+ assert_vcr_requests_made 'carrier_wave_test/remove_resizing_picture' do
38
46
  model.resizing_picture.remove!
39
47
  end
40
48
  end
41
49
 
42
50
  def test_blank_returns_true_after_remove
43
51
  model = prepare_model TestModel
52
+ model.save!
44
53
 
45
- VCR.use_cassette 'carrier_wave_test/remove_resizing_picture' do
46
- refute model.resizing_picture.blank?, 'resizing_picture should not be blank before remove'
54
+ refute model.resizing_picture.blank?, 'resizing_picture should not be blank before remove'
47
55
 
56
+ # DELETEリクエストが発行されたことを確認
57
+ assert_vcr_requests_made 'carrier_wave_test/remove_resizing_picture' do
48
58
  model.remove_resizing_picture!
49
-
50
- assert model.resizing_picture.blank?, 'resizing_picture should be blank after remove'
51
- assert_nil model.resizing_picture_url
59
+ model.save!
52
60
  end
61
+
62
+ assert model.resizing_picture.blank?, 'resizing_picture should be blank after remove'
63
+ assert_nil model.resizing_picture_url
53
64
  end
54
65
 
55
66
  def test_blank_returns_true_for_new_record
@@ -57,6 +68,24 @@ module Resizing
57
68
  assert model.resizing_picture.blank?, 'resizing_picture should be blank for new record'
58
69
  end
59
70
 
71
+ def test_remove_resizing_picture_with_flag_and_save
72
+ model = prepare_model TestModel
73
+ model.save!
74
+
75
+ refute model.resizing_picture.blank?, 'resizing_picture should not be blank before remove'
76
+
77
+ model.remove_resizing_picture = true
78
+
79
+ # save時にDELETEリクエストが発行されたことを確認
80
+ assert_vcr_requests_made 'carrier_wave_test/remove_resizing_picture' do
81
+ model.save!
82
+ end
83
+
84
+ # DELETEが成功した結果、blank?がtrueになることを確認
85
+ assert model.resizing_picture.blank?, 'resizing_picture should be blank after save'
86
+ assert_nil model.resizing_picture_url
87
+ end
88
+
60
89
  def test_picture_url_return_correct_value_and_when_model_reloaded
61
90
  model = prepare_model TestModel
62
91
  model.save!
@@ -98,9 +127,15 @@ module Resizing
98
127
  end
99
128
 
100
129
  def test_is_successful
101
- model = prepare_model_with_tempfile TestModel
102
- model.save!
103
- # assert_equal('http://192.168.56.101:5000/projects/098a2a0d-c387-4135-a071-1254d6d7e70a/upload/images/28c49144-c00d-4cb5-8619-98ce95977b9c/v1Id850__tqNsnoGWWUibtIBZ5NgjV45M/', model.resizing_picture_url)
130
+ model = TestModel.new
131
+
132
+ # POSTリクエストが発行されたことを確認
133
+ assert_vcr_requests_made 'carrier_wave_test/save' do
134
+ file = File.open('test/data/images/sample1.jpg', 'r')
135
+ model.resizing_picture = file
136
+ end
137
+
138
+ assert_equal('http://192.168.56.101:5000/projects/e06e710d-f026-4dcf-b2c0-eab0de8bb83f/upload/images/14ea7aac-a194-4330-931f-6b562aec413d/v_8c5lEhDB5RT3PZp1Fn5PYGm9YVx_x0e/', model.resizing_picture_url)
104
139
  end
105
140
 
106
141
  def test_file_returns_same_instance_on_multiple_calls
@@ -129,13 +164,14 @@ module Resizing
129
164
  end
130
165
 
131
166
  def expect_url
132
- 'http://192.168.56.101:5000/projects/e06e710d-f026-4dcf-b2c0-eab0de8bb83f/' +
167
+ 'http://192.168.56.101:5000/projects/e06e710d-f026-4dcf-b2c0-eab0de8bb83f/' \
133
168
  'upload/images/14ea7aac-a194-4330-931f-6b562aec413d/v_8c5lEhDB5RT3PZp1Fn5PYGm9YVx_x0e'
134
169
  end
135
170
 
136
171
  def prepare_model(model)
172
+ result = nil
137
173
  VCR.use_cassette 'carrier_wave_test/save', record: :once do
138
- model = model.new
174
+ result = model.new
139
175
  file = File.open('test/data/images/sample1.jpg', 'r')
140
176
  uploaded_file = ActionDispatch::Http::UploadedFile.new(
141
177
  filename: File.basename(file.path),
@@ -143,18 +179,9 @@ module Resizing
143
179
  tempfile: file
144
180
  )
145
181
 
146
- model.resizing_picture = uploaded_file
147
- return model
148
- end
149
- end
150
-
151
- def prepare_model_with_tempfile(model)
152
- VCR.use_cassette 'carrier_wave_test/save', record: :once do
153
- model = model.new
154
- file = File.open('test/data/images/sample1.jpg', 'r')
155
- model.resizing_picture = file
156
- return model
182
+ result.resizing_picture = uploaded_file
157
183
  end
184
+ result
158
185
  end
159
186
  end
160
187
  end
@@ -38,7 +38,7 @@ module Resizing
38
38
  Resizing.configure = @configuration_template
39
39
 
40
40
  client = Resizing::Client.new
41
- VCR.use_cassette 'client/post', record: :once do
41
+ VCR.use_cassette 'client/post', record: :once do
42
42
  r = client.post('test/data/images/sample1.jpg', content_type: 'image/jpeg')
43
43
  assert_equal(r['id'], '87263920-2081-498e-a107-9625f4fde01b')
44
44
  assert_equal(r['project_id'], Resizing.configure.project_id)
@@ -56,7 +56,7 @@ module Resizing
56
56
  Resizing.configure = @configuration_template
57
57
 
58
58
  client = Resizing::Client.new
59
- VCR.use_cassette 'client/post', record: :once do
59
+ VCR.use_cassette 'client/post', record: :once do
60
60
  assert_raises ArgumentError do
61
61
  client.post('file_is_not_exists', content_type: 'image/jpeg')
62
62
  end
@@ -67,7 +67,7 @@ module Resizing
67
67
  Resizing.configure = @configuration_template
68
68
 
69
69
  client = Resizing::Client.new
70
- VCR.use_cassette 'client/post', record: :once do
70
+ VCR.use_cassette 'client/post', record: :once do
71
71
  f = File.open('test/data/images/sample1.jpg', 'r')
72
72
  r = client.post(f, content_type: 'image/jpeg')
73
73
  assert_equal(r['id'], '87263920-2081-498e-a107-9625f4fde01b')
@@ -122,7 +122,7 @@ module Resizing
122
122
  f = File.open('test/data/images/sample1.jpg', 'r')
123
123
 
124
124
  assert_raises Resizing::APIError do
125
- r = client.put(name, f, content_type: 'image/jpeg')
125
+ _r = client.put(name, f, content_type: 'image/jpeg')
126
126
  end
127
127
  end
128
128
 
@@ -152,7 +152,7 @@ module Resizing
152
152
  rescue Resizing::APIError => e
153
153
  response = e.decoded_body
154
154
  end
155
- assert_equal response, {"error"=>"Magick::ImageMagickError", "message"=>"invalid image format found"}
155
+ assert_equal response, { 'error' => 'Magick::ImageMagickError', 'message' => 'invalid image format found' }
156
156
  end
157
157
  end
158
158
 
@@ -165,20 +165,76 @@ module Resizing
165
165
  VCR.use_cassette 'client/metadata', record: :once do
166
166
  name = '87263920-2081-498e-a107-9625f4fde01b'
167
167
  r = client.metadata(name)
168
+ # r.body
169
+ # {
170
+ # "id":"87263920-2081-498e-a107-9625f4fde01b",
171
+ # "project_id":"e06e710d-f026-4dcf-b2c0-eab0de8bb83f",
172
+ # "content_type":"image/jpeg",
173
+ # "latest_version_id":"Hg9VFvdI6HRzLFbV495VdwVmHIspLRCo",
174
+ # "latest_etag":"\"5766f95a7f28e6a53dd6fd179bf03a32\"",
175
+ # "size":848590,
176
+ # "created_at":"2020-10-11T05:02:25.912Z",
177
+ # "updated_at":"2020-10-11T05:02:25.912Z",
178
+ # "filename":"sample1.jpg",
179
+ # "width":4032,
180
+ # "height":3016,
181
+ # "format":"jpeg",
182
+ # "version":"Hg9VFvdI6HRzLFbV495VdwVmHIspLRCo",
183
+ # "public_id":"/projects/e06e710d-f026-4dcf-b2c0-eab0de8bb83f/upload/images/87263920-2081-498e-a107-9625f4fde01b/vHg9VFvdI6HRzLFbV495VdwVmHIspLRCo"
184
+ # }
185
+
168
186
  assert_equal(r['id'], name)
169
187
  assert_equal(r['project_id'], Resizing.configure.project_id)
170
188
  assert_equal(r['content_type'], 'image/jpeg')
171
- assert(r['latest_version_id'] != nil)
172
- assert(r['latest_etag'] != nil)
173
- assert(r['created_at'] != nil)
174
- assert(r['updated_at'] != nil)
175
- assert(r['height'] != nil)
176
- assert(r['width'] != nil)
189
+ assert_equal(r['latest_version_id'], 'Hg9VFvdI6HRzLFbV495VdwVmHIspLRCo')
190
+ assert_equal(r['latest_etag'], '"5766f95a7f28e6a53dd6fd179bf03a32"')
191
+ assert_equal(r['created_at'], '2020-10-11T05:02:25.912Z')
192
+ assert_equal(r['updated_at'], '2020-10-11T05:02:25.912Z')
193
+ assert_equal(r['width'], 4032)
194
+ assert_equal(r['height'], 3016)
195
+ assert_equal(r['format'], 'jpeg')
196
+ assert_equal(r['version'], 'Hg9VFvdI6HRzLFbV495VdwVmHIspLRCo')
177
197
  assert_equal(
178
198
  r['public_id'],
179
- "/projects/e06e710d-f026-4dcf-b2c0-eab0de8bb83f/upload/images/87263920-2081-498e-a107-9625f4fde01b/vHg9VFvdI6HRzLFbV495VdwVmHIspLRCo"
199
+ '/projects/e06e710d-f026-4dcf-b2c0-eab0de8bb83f/upload/images/87263920-2081-498e-a107-9625f4fde01b/vHg9VFvdI6HRzLFbV495VdwVmHIspLRCo'
180
200
  )
181
201
  end
182
202
  end
203
+
204
+ def test_get_raises_not_implemented_error
205
+ Resizing.configure = @configuration_template
206
+ client = Resizing::Client.new
207
+
208
+ assert_raises NotImplementedError do
209
+ client.get('some_image_id')
210
+ end
211
+ end
212
+
213
+ def test_post_raises_error_without_content_type
214
+ Resizing.configure = @configuration_template
215
+ client = Resizing::Client.new
216
+
217
+ assert_raises ArgumentError do
218
+ client.post('test/data/images/sample1.jpg', {})
219
+ end
220
+ end
221
+
222
+ def test_post_raises_error_with_invalid_io
223
+ Resizing.configure = @configuration_template
224
+ client = Resizing::Client.new
225
+
226
+ assert_raises ArgumentError do
227
+ client.post(12_345, content_type: 'image/jpeg')
228
+ end
229
+ end
230
+
231
+ def test_put_raises_error_without_content_type
232
+ Resizing.configure = @configuration_template
233
+ client = Resizing::Client.new
234
+
235
+ assert_raises ArgumentError do
236
+ client.put('image_id', 'test/data/images/sample1.jpg', {})
237
+ end
238
+ end
183
239
  end
184
240
  end
@@ -23,7 +23,6 @@ module Resizing
23
23
  template = @template.dup
24
24
  template.delete(:image_host)
25
25
  config = Resizing::Configuration.new template
26
- assert_equal(config.host, Resizing::Configuration::DEFAULT_IMAGE_HOST)
27
26
  assert_equal(config.image_host, Resizing::Configuration::DEFAULT_IMAGE_HOST)
28
27
  end
29
28
 
@@ -38,7 +37,7 @@ module Resizing
38
37
  template = @template.dup
39
38
  template[:host] = 'need raise execption if host is presented'
40
39
  assert_raises ConfigurationError do
41
- config = Resizing::Configuration.new template
40
+ _config = Resizing::Configuration.new template
42
41
  end
43
42
  end
44
43
 
@@ -154,7 +153,7 @@ module Resizing
154
153
 
155
154
  assert_instance_of String, image_id
156
155
  # UUID format: 8-4-4-4-12
157
- assert_match /\A[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\z/, image_id
156
+ assert_match(/\A[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\z/, image_id)
158
157
  end
159
158
 
160
159
  def test_generate_image_id_returns_different_uuids
@@ -18,29 +18,29 @@ module Resizing
18
18
 
19
19
  def test_api_error_has_decoded_body_accessor
20
20
  error = Resizing::APIError.new('test error')
21
-
21
+
22
22
  assert_respond_to error, :decoded_body
23
23
  assert_respond_to error, :decoded_body=
24
24
  end
25
25
 
26
26
  def test_api_error_decoded_body_defaults_to_empty_hash
27
27
  error = Resizing::APIError.new('test error')
28
-
28
+
29
29
  assert_equal({}, error.decoded_body)
30
30
  end
31
31
 
32
32
  def test_api_error_decoded_body_can_be_set_with_hash
33
33
  error = Resizing::APIError.new('test error')
34
34
  body = { 'error' => 'test', 'code' => 400 }
35
-
35
+
36
36
  error.decoded_body = body
37
-
37
+
38
38
  assert_equal body, error.decoded_body
39
39
  end
40
40
 
41
41
  def test_api_error_decoded_body_raises_argument_error_for_non_hash
42
42
  error = Resizing::APIError.new('test error')
43
-
43
+
44
44
  assert_raises ArgumentError do
45
45
  error.decoded_body = 'not a hash'
46
46
  end
@@ -48,9 +48,9 @@ module Resizing
48
48
 
49
49
  def test_api_error_decoded_body_raises_argument_error_for_array
50
50
  error = Resizing::APIError.new('test error')
51
-
51
+
52
52
  assert_raises ArgumentError do
53
- error.decoded_body = ['not', 'a', 'hash']
53
+ error.decoded_body = %w[not a hash]
54
54
  end
55
55
  end
56
56
 
@@ -58,7 +58,7 @@ module Resizing
58
58
  error = assert_raises Resizing::ConfigurationError do
59
59
  raise Resizing::ConfigurationError, 'test configuration error'
60
60
  end
61
-
61
+
62
62
  assert_equal 'test configuration error', error.message
63
63
  end
64
64
 
@@ -66,7 +66,7 @@ module Resizing
66
66
  error = assert_raises Resizing::APIError do
67
67
  raise Resizing::APIError, 'test api error'
68
68
  end
69
-
69
+
70
70
  assert_equal 'test api error', error.message
71
71
  end
72
72
  end
@@ -58,7 +58,7 @@ module Resizing
58
58
  def test_handle_faraday_error_catches_timeout_error
59
59
  assert_raises Resizing::APIError do
60
60
  @client.handle_faraday_error do
61
- raise Faraday::TimeoutError.new('timeout')
61
+ raise Faraday::TimeoutError, 'timeout'
62
62
  end
63
63
  end
64
64
  end
@@ -30,7 +30,7 @@ module Resizing
30
30
 
31
31
  def test_expect_equal_identifier
32
32
  public_id = Resizing::PublicId.new @public_id_as_string
33
- assert_equal @public_id_as_string.gsub(/\/v.*$/, ''), public_id.identifier
33
+ assert_equal @public_id_as_string.gsub(%r{/v.*$}, ''), public_id.identifier
34
34
  end
35
35
 
36
36
  def test_expect_equal_public_id
@@ -5,16 +5,16 @@ require 'test_helper'
5
5
  class ResizingModuleTest < Minitest::Test
6
6
  def setup
7
7
  # Reset configure before each test to ensure clean state
8
- if Resizing.instance_variable_defined?(:@configure)
9
- Resizing.remove_instance_variable(:@configure)
10
- end
8
+ return unless Resizing.instance_variable_defined?(:@configure)
9
+
10
+ Resizing.remove_instance_variable(:@configure)
11
11
  end
12
12
 
13
13
  def teardown
14
14
  # Reset configure after each test
15
- if Resizing.instance_variable_defined?(:@configure)
16
- Resizing.remove_instance_variable(:@configure)
17
- end
15
+ return unless Resizing.instance_variable_defined?(:@configure)
16
+
17
+ Resizing.remove_instance_variable(:@configure)
18
18
  end
19
19
 
20
20
  def test_configure_raises_error_when_not_initialized
@@ -121,4 +121,86 @@ class ResizingModuleTest < Minitest::Test
121
121
  assert_includes url, 'image456/v789/'
122
122
  assert_includes url, 'w_100'
123
123
  end
124
+
125
+ def test_generate_identifier_returns_identifier_string
126
+ Resizing.configure = {
127
+ image_host: 'https://img.example.com',
128
+ project_id: 'project123',
129
+ secret_token: 'token123'
130
+ }
131
+
132
+ identifier = Resizing.generate_identifier
133
+
134
+ assert_instance_of String, identifier
135
+ assert_includes identifier, 'project123'
136
+ assert_match %r{/projects/project123/upload/images/}, identifier
137
+ end
138
+
139
+ def test_client_returns_mock_client_when_enable_mock_is_true
140
+ Resizing.configure = {
141
+ image_host: 'https://img.example.com',
142
+ project_id: 'project123',
143
+ secret_token: 'token123',
144
+ enable_mock: true
145
+ }
146
+
147
+ client = Resizing.client
148
+
149
+ assert_instance_of Resizing::MockClient, client
150
+ end
151
+
152
+ def test_client_returns_real_client_when_enable_mock_is_false
153
+ Resizing.configure = {
154
+ image_host: 'https://img.example.com',
155
+ project_id: 'project123',
156
+ secret_token: 'token123',
157
+ enable_mock: false
158
+ }
159
+
160
+ client = Resizing.client
161
+
162
+ assert_instance_of Resizing::Client, client
163
+ end
164
+
165
+ def test_put_delegates_to_client
166
+ Resizing.configure = {
167
+ image_host: 'https://img.example.com',
168
+ project_id: 'project123',
169
+ secret_token: 'token123',
170
+ enable_mock: true
171
+ }
172
+
173
+ result = Resizing.put('image_id', 'dummy', content_type: 'image/jpeg')
174
+
175
+ assert_instance_of Hash, result
176
+ assert_equal 'image_id', result['id']
177
+ end
178
+
179
+ def test_delete_delegates_to_client
180
+ Resizing.configure = {
181
+ image_host: 'https://img.example.com',
182
+ project_id: 'project123',
183
+ secret_token: 'token123',
184
+ enable_mock: true
185
+ }
186
+
187
+ result = Resizing.delete('image_id')
188
+
189
+ assert_instance_of Hash, result
190
+ assert_equal 'image_id', result['id']
191
+ end
192
+
193
+ def test_metadata_delegates_to_client
194
+ Resizing.configure = {
195
+ image_host: 'https://img.example.com',
196
+ project_id: 'project123',
197
+ secret_token: 'token123',
198
+ enable_mock: true
199
+ }
200
+
201
+ result = Resizing.metadata('image_id', {})
202
+
203
+ assert_instance_of Hash, result
204
+ assert_equal 'image_id', result['id']
205
+ end
124
206
  end
data/test/test_helper.rb CHANGED
@@ -1,9 +1,10 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'simplecov'
3
4
  require 'simplecov-cobertura'
4
5
 
5
6
  SimpleCov.start do
6
- add_filter "/test/"
7
+ add_filter '/test/'
7
8
 
8
9
  if ENV['CI']
9
10
  formatter SimpleCov::Formatter::CoberturaFormatter
@@ -28,6 +29,7 @@ require 'rails'
28
29
  require 'active_record'
29
30
  require 'fog-aws'
30
31
  require 'carrierwave'
32
+ require 'carrierwave/orm/activerecord'
31
33
  require 'resizing'
32
34
  require 'pry-byebug'
33
35
 
@@ -40,11 +42,93 @@ VCR.configure do |c|
40
42
  c.allow_http_connections_when_no_cassette = false
41
43
 
42
44
  # raise Faraday::TimeoutError, when project_id is timeout_project_id
43
- c.before_http_request(lambda {|r| URI(r.uri).path.match? %r(/projects/timeout_project_id) } ) do
45
+ c.before_http_request(->(r) { URI(r.uri).path.match? %r{/projects/timeout_project_id} }) do
44
46
  raise Faraday::TimeoutError
45
47
  end
46
48
  end
47
49
 
50
+ # VCRカセットのリクエストが実際に使用されたかを検証するヘルパー
51
+ module VCRRequestAssertions
52
+ # VCRカセット内でブロックを実行し、カセットのインタラクションがすべて使用されたことを確認
53
+ #
54
+ # @param cassette_name [String] VCRカセット名
55
+ # @param options [Hash] VCR.use_cassetteに渡すオプション
56
+ # @yield 実行するブロック
57
+ # @return [void]
58
+ #
59
+ # @example
60
+ # assert_vcr_requests_made 'carrier_wave_test/remove_resizing_picture' do
61
+ # model.remove_resizing_picture!
62
+ # model.save!
63
+ # end
64
+ def assert_vcr_requests_made(cassette_name, options = {}, &block)
65
+ options = { record: :none }.merge(options)
66
+
67
+ VCR.use_cassette(cassette_name, options) do |cassette|
68
+ interaction_list = cassette.http_interactions
69
+ initial_count = interaction_list.remaining_unused_interaction_count
70
+
71
+ assert initial_count.positive?,
72
+ "Cassette '#{cassette_name}' should have at least 1 interaction"
73
+
74
+ yield cassette if block_given?
75
+
76
+ remaining_count = interaction_list.remaining_unused_interaction_count
77
+ used_count = initial_count - remaining_count
78
+
79
+ assert_equal 0, remaining_count,
80
+ "Expected all #{initial_count} cassette interactions to be used, " \
81
+ "but #{remaining_count} remain unused (#{used_count} were used)"
82
+ end
83
+ end
84
+
85
+ # VCRカセット内でブロックを実行し、指定した数のインタラクションが使用されたことを確認
86
+ #
87
+ # @param cassette_name [String] VCRカセット名
88
+ # @param expected_count [Integer] 使用されるべきインタラクション数
89
+ # @param options [Hash] VCR.use_cassetteに渡すオプション
90
+ # @yield 実行するブロック
91
+ # @return [void]
92
+ #
93
+ # @example
94
+ # assert_vcr_requests_count 'client/post', 1 do
95
+ # Resizing.post(file)
96
+ # end
97
+ def assert_vcr_requests_count(cassette_name, expected_count, options = {}, &block)
98
+ options = { record: :none }.merge(options)
99
+
100
+ VCR.use_cassette(cassette_name, options) do |cassette|
101
+ interaction_list = cassette.http_interactions
102
+ initial_count = interaction_list.remaining_unused_interaction_count
103
+
104
+ yield cassette if block_given?
105
+
106
+ remaining_count = interaction_list.remaining_unused_interaction_count
107
+ used_count = initial_count - remaining_count
108
+
109
+ assert_equal expected_count, used_count,
110
+ "Expected #{expected_count} cassette interactions to be used, " \
111
+ "but #{used_count} were used"
112
+ end
113
+ end
114
+
115
+ # VCRカセット内でブロックを実行し、リクエストが発行されないことを確認
116
+ #
117
+ # @param cassette_name [String] VCRカセット名
118
+ # @param options [Hash] VCR.use_cassetteに渡すオプション
119
+ # @yield 実行するブロック
120
+ # @return [void]
121
+ #
122
+ # @example
123
+ # assert_vcr_no_requests 'carrier_wave_test/remove_resizing_picture' do
124
+ # model.remove_resizing_picture = true
125
+ # # save!を呼ばないのでリクエストは発行されない
126
+ # end
127
+ def assert_vcr_no_requests(cassette_name, options = {}, &block)
128
+ assert_vcr_requests_count(cassette_name, 0, options, &block)
129
+ end
130
+ end
131
+
48
132
  ActiveRecord::Base.establish_connection(
49
133
  adapter: 'mysql2',
50
134
  host: '127.0.0.1',
@@ -58,7 +142,7 @@ ActiveRecord::Base.establish_connection(
58
142
  ActiveRecord::Schema.define do
59
143
  self.verbose = false
60
144
 
61
- %i(test_models test_jpg_models test_model_with_default_urls).each do |model_name|
145
+ %i[test_models test_jpg_models test_model_with_default_urls].each do |model_name|
62
146
  connection.execute "drop table if exists #{model_name}"
63
147
 
64
148
  create_table model_name do |t|
@@ -103,19 +187,13 @@ class ResizingUploaderWithDefaultURL < CarrierWave::Uploader::Base
103
187
  end
104
188
 
105
189
  class TestModel < ::ActiveRecord::Base
106
- extend CarrierWave::Mount
107
-
108
190
  mount_uploader :resizing_picture, ResizingUploader
109
191
  end
110
192
 
111
193
  class TestJPGModel < ::ActiveRecord::Base
112
- extend CarrierWave::Mount
113
-
114
194
  mount_uploader :resizing_picture, ResizingJPGUploader
115
195
  end
116
196
 
117
197
  class TestModelWithDefaultURL < ::ActiveRecord::Base
118
- extend CarrierWave::Mount
119
-
120
198
  mount_uploader :resizing_picture, ResizingUploaderWithDefaultURL
121
199
  end