resizing 1.2.1 → 1.2.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.
- checksums.yaml +4 -4
- data/.gitignore +6 -0
- data/lib/resizing/carrier_wave/storage/file.rb +36 -11
- data/lib/resizing/carrier_wave.rb +10 -1
- data/lib/resizing/version.rb +1 -1
- data/test/resizing/carrier_wave_test.rb +289 -10
- data/test/test_helper.rb +61 -2
- data/test/vcr/carrier_wave_test/update_image.yml +63 -0
- metadata +4 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 97be4b8cf7324441cfa73563ea4f102ac47b947fc95adb9ccbad206fe802f785
|
|
4
|
+
data.tar.gz: ae8df42cb9197bdfc81874d83027e266ba523e3e0c90605ddafc93b310da4368
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 56a57d325523e21d22a6e3c77c3907e6ec8860433e6524d8ee89da79381f29f56bb7b79af37805ab4be46c921b4e70c5cceb99039de947231c50f7838c4fa544
|
|
7
|
+
data.tar.gz: 18c995f91897d11813477ea16298c2e3101c352f611ecf84e23fb57954e86b6d2c44d28a48515f3df42548b27b0bbebb2b413af85797ce246e9ef22e52d71639
|
data/.gitignore
CHANGED
|
@@ -29,7 +29,7 @@ module Resizing
|
|
|
29
29
|
@content_type || file.try(:content_type)
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
-
# rubocop:disable Metrics/AbcSize
|
|
32
|
+
# rubocop:disable Metrics/AbcSize
|
|
33
33
|
def delete
|
|
34
34
|
# Use the identifier from constructor if available, otherwise try to get from model
|
|
35
35
|
if @public_id.present?
|
|
@@ -44,23 +44,27 @@ module Resizing
|
|
|
44
44
|
@public_id = Resizing::PublicId.new(column_value)
|
|
45
45
|
end
|
|
46
46
|
|
|
47
|
-
return if @public_id.empty?
|
|
47
|
+
return if @public_id.empty?
|
|
48
48
|
|
|
49
|
-
# 以下、既存のコード(変更なし)
|
|
50
49
|
resp = client.delete(@public_id.image_id)
|
|
50
|
+
|
|
51
|
+
# NOTE: 削除時のカラムクリアは以下の理由で必要:
|
|
52
|
+
# - 画像更新時: 古い画像IDと新しい画像IDが異なるため、古い画像削除時に新しいIDを消さないようにする
|
|
53
|
+
# - 明示的なremove!時: カラムをnilにする必要がある
|
|
54
|
+
# - clear_column_if_current_imageは削除される画像IDと現在のカラム値を比較して判断
|
|
51
55
|
if resp['error'] == 'ActiveRecord::RecordNotFound' # 404 not found
|
|
52
|
-
|
|
56
|
+
clear_column_if_current_image
|
|
53
57
|
return
|
|
54
58
|
end
|
|
55
59
|
|
|
56
60
|
if @public_id.image_id == resp['id']
|
|
57
|
-
|
|
61
|
+
clear_column_if_current_image
|
|
58
62
|
return
|
|
59
63
|
end
|
|
60
64
|
|
|
61
65
|
raise APIError, "raise someone error:#{resp.inspect}"
|
|
62
66
|
end
|
|
63
|
-
# rubocop:enable Metrics/AbcSize
|
|
67
|
+
# rubocop:enable Metrics/AbcSize
|
|
64
68
|
|
|
65
69
|
def extension
|
|
66
70
|
raise NotImplementedError, 'this method is do not used. maybe'
|
|
@@ -95,6 +99,10 @@ module Resizing
|
|
|
95
99
|
end
|
|
96
100
|
|
|
97
101
|
def current_path
|
|
102
|
+
# Return the path from @public_id if set (for retrieve scenarios),
|
|
103
|
+
# otherwise fall back to reading from model
|
|
104
|
+
return @public_id.to_s if @public_id.present?
|
|
105
|
+
|
|
98
106
|
@current_path = model.send :read_attribute, serialization_column
|
|
99
107
|
end
|
|
100
108
|
alias path current_path
|
|
@@ -131,11 +139,14 @@ module Resizing
|
|
|
131
139
|
@public_id = Resizing::PublicId.new(@response['public_id'])
|
|
132
140
|
@content_type = @response['content_type']
|
|
133
141
|
|
|
134
|
-
#
|
|
135
|
-
#
|
|
136
|
-
#
|
|
137
|
-
#
|
|
138
|
-
|
|
142
|
+
# NOTE: 理想的にはStorage::File内でモデルのカラムをいじらず、CarrierWaveに任せるべきだが、
|
|
143
|
+
# 現在の実装では以下の理由で必要:
|
|
144
|
+
# - CarrierWaveは write_uploader(column, mounter.identifiers.first) でカラムを更新
|
|
145
|
+
# - mounter.identifiers -> uploaders.map(&:identifier) -> storage.identifier -> uploader.filename
|
|
146
|
+
# - resizing-gemの filenameメソッドは read_column を返す(既存のカラム値)
|
|
147
|
+
# - そのため、CarrierWaveに任せると旧い値が書き戻されてしまう
|
|
148
|
+
# TODO: これを修正するには、Remote#identifierをオーバーライドして@public_id.to_sを返すか、
|
|
149
|
+
# uploader.filenameの実装を変更する必要がある
|
|
139
150
|
# save new value to model class
|
|
140
151
|
model.send :write_attribute, serialization_column, @public_id.to_s
|
|
141
152
|
|
|
@@ -177,6 +188,20 @@ module Resizing
|
|
|
177
188
|
@serialization_column ||= model.send(:_mounter, uploader.mounted_as).send(:serialization_column)
|
|
178
189
|
end
|
|
179
190
|
|
|
191
|
+
# Only clear the column if the deleted image is the current one
|
|
192
|
+
# (not when deleting an old image during update)
|
|
193
|
+
def clear_column_if_current_image
|
|
194
|
+
return if model.destroyed?
|
|
195
|
+
|
|
196
|
+
current_value = model.send(:read_attribute, serialization_column)
|
|
197
|
+
current_public_id = Resizing::PublicId.new(current_value)
|
|
198
|
+
|
|
199
|
+
# Only clear if the deleted image is the same as the current one
|
|
200
|
+
return unless current_public_id.image_id == @public_id.image_id
|
|
201
|
+
|
|
202
|
+
model.send :write_attribute, serialization_column, nil
|
|
203
|
+
end
|
|
204
|
+
|
|
180
205
|
##
|
|
181
206
|
# client of Resizing
|
|
182
207
|
def client
|
|
@@ -29,11 +29,20 @@ module Resizing
|
|
|
29
29
|
def initialize(*args)
|
|
30
30
|
@requested_format = nil
|
|
31
31
|
@default_format = nil
|
|
32
|
+
@retrieved_identifier = nil
|
|
32
33
|
super
|
|
33
34
|
end
|
|
34
35
|
|
|
36
|
+
# Override to store the identifier and set up @file for later use
|
|
37
|
+
def retrieve_from_store!(identifier)
|
|
38
|
+
@retrieved_identifier = identifier
|
|
39
|
+
super
|
|
40
|
+
# Ensure @file is set up so that remove! can call @file.delete
|
|
41
|
+
file
|
|
42
|
+
end
|
|
43
|
+
|
|
35
44
|
def file
|
|
36
|
-
file_identifier = identifier || read_column
|
|
45
|
+
file_identifier = @retrieved_identifier || identifier || read_column
|
|
37
46
|
|
|
38
47
|
return nil if file_identifier.blank?
|
|
39
48
|
|
data/lib/resizing/version.rb
CHANGED
|
@@ -168,20 +168,299 @@ module Resizing
|
|
|
168
168
|
'upload/images/14ea7aac-a194-4330-931f-6b562aec413d/v_8c5lEhDB5RT3PZp1Fn5PYGm9YVx_x0e'
|
|
169
169
|
end
|
|
170
170
|
|
|
171
|
-
def prepare_model(
|
|
171
|
+
def prepare_model(model_class)
|
|
172
172
|
result = nil
|
|
173
173
|
VCR.use_cassette 'carrier_wave_test/save', record: :once do
|
|
174
|
-
result =
|
|
175
|
-
|
|
176
|
-
uploaded_file = ActionDispatch::Http::UploadedFile.new(
|
|
177
|
-
filename: File.basename(file.path),
|
|
178
|
-
type: 'image/jpeg',
|
|
179
|
-
tempfile: file
|
|
180
|
-
)
|
|
181
|
-
|
|
182
|
-
result.resizing_picture = uploaded_file
|
|
174
|
+
result = model_class.new
|
|
175
|
+
attach_sample_image(result)
|
|
183
176
|
end
|
|
184
177
|
result
|
|
185
178
|
end
|
|
179
|
+
|
|
180
|
+
# モデルにサンプル画像を添付するヘルパーメソッド
|
|
181
|
+
# VCRカセット内で呼び出す必要がある
|
|
182
|
+
def attach_sample_image(model)
|
|
183
|
+
file = File.open('test/data/images/sample1.jpg', 'r')
|
|
184
|
+
uploaded_file = ActionDispatch::Http::UploadedFile.new(
|
|
185
|
+
filename: File.basename(file.path),
|
|
186
|
+
type: 'image/jpeg',
|
|
187
|
+
tempfile: file
|
|
188
|
+
)
|
|
189
|
+
model.resizing_picture = uploaded_file
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
# TestModelWithCallbackTracking 用のヘルパーメソッド
|
|
193
|
+
def prepare_tracking_model
|
|
194
|
+
prepare_model(TestModelWithCallbackTracking)
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
# 既存モデルに新しい画像をアップロードするヘルパーメソッド
|
|
198
|
+
def upload_new_image(model)
|
|
199
|
+
VCR.use_cassette 'carrier_wave_test/save', record: :once do
|
|
200
|
+
attach_sample_image(model)
|
|
201
|
+
end
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
# after_commit コールバックが正しく呼ばれることを確認するテスト
|
|
205
|
+
# 通常のテスト環境ではトランザクションが使われるため、after_commit が呼ばれない問題がある
|
|
206
|
+
# このテストでは、明示的にトランザクションをコミットして after_commit が呼ばれることを確認する
|
|
207
|
+
|
|
208
|
+
def test_after_commit_callback_is_called_on_create
|
|
209
|
+
# after_commit on: :create が呼ばれることを確認
|
|
210
|
+
model = prepare_tracking_model
|
|
211
|
+
|
|
212
|
+
# 明示的なトランザクション内で save! することで after_commit が呼ばれる
|
|
213
|
+
ActiveRecord::Base.transaction do
|
|
214
|
+
model.save!
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
assert_includes model.callback_log, :create_commit,
|
|
218
|
+
'after_commit on: :create should be called after transaction commit'
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
def test_after_commit_callback_is_called_on_update
|
|
222
|
+
# after_commit on: :update が呼ばれることを確認
|
|
223
|
+
model = prepare_tracking_model
|
|
224
|
+
model.save!
|
|
225
|
+
model.callback_log.clear
|
|
226
|
+
|
|
227
|
+
# 更新時の after_commit が呼ばれることを確認
|
|
228
|
+
upload_new_image(model)
|
|
229
|
+
|
|
230
|
+
ActiveRecord::Base.transaction do
|
|
231
|
+
model.save!
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
assert_includes model.callback_log, :update_commit,
|
|
235
|
+
'after_commit on: :update should be called after transaction commit'
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
def test_after_commit_callback_is_called_on_destroy
|
|
239
|
+
# after_commit on: :destroy が呼ばれることを確認
|
|
240
|
+
model = prepare_tracking_model
|
|
241
|
+
model.save!
|
|
242
|
+
model.callback_log.clear
|
|
243
|
+
|
|
244
|
+
# destroy 時の after_commit が呼ばれることを確認
|
|
245
|
+
assert_vcr_requests_made 'carrier_wave_test/remove_resizing_picture' do
|
|
246
|
+
ActiveRecord::Base.transaction do
|
|
247
|
+
model.destroy!
|
|
248
|
+
end
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
assert_includes model.callback_log, :destroy_commit,
|
|
252
|
+
'after_commit on: :destroy should be called after transaction commit'
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
def test_carrierwave_remove_previously_stored_is_called_on_update
|
|
256
|
+
# CarrierWave が登録する remove_previously_stored_#{column} が
|
|
257
|
+
# 画像の更新時に呼ばれることを確認
|
|
258
|
+
model = prepare_model TestModel
|
|
259
|
+
model.save!
|
|
260
|
+
|
|
261
|
+
model.resizing_picture_url
|
|
262
|
+
|
|
263
|
+
# 新しい画像をアップロードして更新
|
|
264
|
+
upload_new_image(model)
|
|
265
|
+
|
|
266
|
+
# 更新時には古い画像を削除するため DELETE リクエストが発行されるべき
|
|
267
|
+
# ただし、同じカセットを使用しているため同じ URL になる
|
|
268
|
+
# 実際の環境では異なる public_id が返されるため、古い画像が削除される
|
|
269
|
+
ActiveRecord::Base.transaction do
|
|
270
|
+
model.save!
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
# モデルが更新されたことを確認
|
|
274
|
+
refute_nil model.resizing_picture_url
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
def test_delete_is_called_when_image_is_updated
|
|
278
|
+
# 画像更新時に古い画像を削除する DELETE リクエストが発行されることを確認
|
|
279
|
+
# VCR カセット update_image.yml には以下が含まれる:
|
|
280
|
+
# 1. POST (古い画像のアップロード) -> old-image-id を返す
|
|
281
|
+
# 2. POST (新しい画像のアップロード) -> new-image-id を返す
|
|
282
|
+
# 3. DELETE (古い画像の削除) -> old-image-id を削除
|
|
283
|
+
|
|
284
|
+
assert_vcr_requests_made 'carrier_wave_test/update_image' do
|
|
285
|
+
model = TestModel.new
|
|
286
|
+
model.resizing_picture = File.open(File.expand_path('../data/images/sample1.jpg', __dir__))
|
|
287
|
+
model.save!
|
|
288
|
+
|
|
289
|
+
old_public_id = model.read_attribute(:resizing_picture)
|
|
290
|
+
assert_match(/old-image-id/, old_public_id)
|
|
291
|
+
|
|
292
|
+
# 新しい画像をアップロードして更新(同じカセット内で)
|
|
293
|
+
model.resizing_picture = File.open(File.expand_path('../data/images/sample1.jpg', __dir__))
|
|
294
|
+
|
|
295
|
+
ActiveRecord::Base.transaction do
|
|
296
|
+
model.save!
|
|
297
|
+
end
|
|
298
|
+
|
|
299
|
+
# 更新後は新しい画像の public_id が設定されている
|
|
300
|
+
new_public_id = model.read_attribute(:resizing_picture)
|
|
301
|
+
assert_match(/new-image-id/, new_public_id)
|
|
302
|
+
end
|
|
303
|
+
# カセット内の全リクエスト(POST x2, DELETE x1)が発行されたことを確認
|
|
304
|
+
end
|
|
305
|
+
|
|
306
|
+
# ============================================================
|
|
307
|
+
# before_save / after_save コールバックのテスト
|
|
308
|
+
# ============================================================
|
|
309
|
+
|
|
310
|
+
def test_before_save_write_identifier_is_called
|
|
311
|
+
# before_save :write_#{column}_identifier が呼ばれ、
|
|
312
|
+
# カラムに識別子が書き込まれることを確認
|
|
313
|
+
model = prepare_model TestModel
|
|
314
|
+
|
|
315
|
+
# 保存前は識別子がDBに書き込まれていない
|
|
316
|
+
assert model.new_record?
|
|
317
|
+
|
|
318
|
+
model.save!
|
|
319
|
+
|
|
320
|
+
# 保存後は識別子がDBに書き込まれている
|
|
321
|
+
assert_match %r{/projects/.+/upload/images/.+}, model.read_attribute(:resizing_picture)
|
|
322
|
+
end
|
|
323
|
+
|
|
324
|
+
def test_after_save_store_is_called
|
|
325
|
+
# after_save :store_#{column}! が呼ばれ、
|
|
326
|
+
# ファイルがストレージに保存されることを確認
|
|
327
|
+
model = prepare_model TestModel
|
|
328
|
+
model.save!
|
|
329
|
+
|
|
330
|
+
# ファイルが保存され、URLが取得できることを確認
|
|
331
|
+
refute_nil model.resizing_picture_url
|
|
332
|
+
refute model.resizing_picture.blank?
|
|
333
|
+
end
|
|
334
|
+
|
|
335
|
+
def test_after_save_store_previous_changes_is_called
|
|
336
|
+
# after_save :store_previous_changes_for_#{column} が呼ばれ、
|
|
337
|
+
# 前の変更が追跡されることを確認
|
|
338
|
+
model = prepare_model TestModel
|
|
339
|
+
model.save!
|
|
340
|
+
|
|
341
|
+
model.read_attribute(:resizing_picture)
|
|
342
|
+
|
|
343
|
+
# 新しい画像をアップロード
|
|
344
|
+
upload_new_image(model)
|
|
345
|
+
|
|
346
|
+
model.save!
|
|
347
|
+
|
|
348
|
+
# previous_changes に resizing_picture の変更が記録されていることを確認
|
|
349
|
+
# (CarrierWave が store_previous_changes_for_#{column} で追跡)
|
|
350
|
+
assert model.previous_changes.key?('resizing_picture'),
|
|
351
|
+
'previous_changes should track resizing_picture changes'
|
|
352
|
+
end
|
|
353
|
+
|
|
354
|
+
# ============================================================
|
|
355
|
+
# after_commit :mark_remove_#{column}_false のテスト
|
|
356
|
+
# ============================================================
|
|
357
|
+
|
|
358
|
+
def test_mark_remove_column_false_is_called_after_update
|
|
359
|
+
# after_commit :mark_remove_#{column}_false, on: :update が呼ばれ、
|
|
360
|
+
# remove フラグがリセットされることを確認
|
|
361
|
+
model = prepare_model TestModel
|
|
362
|
+
model.save!
|
|
363
|
+
|
|
364
|
+
# remove フラグを設定
|
|
365
|
+
model.remove_resizing_picture = '1'
|
|
366
|
+
|
|
367
|
+
# この時点ではフラグが設定されている
|
|
368
|
+
assert_equal '1', model.remove_resizing_picture
|
|
369
|
+
|
|
370
|
+
# save 後に after_commit で mark_remove_resizing_picture_false が呼ばれる
|
|
371
|
+
assert_vcr_requests_made 'carrier_wave_test/remove_resizing_picture' do
|
|
372
|
+
ActiveRecord::Base.transaction do
|
|
373
|
+
model.save!
|
|
374
|
+
end
|
|
375
|
+
end
|
|
376
|
+
|
|
377
|
+
# after_commit 後はフラグがリセットされている
|
|
378
|
+
# CarrierWave が mark_remove_#{column}_false でフラグをリセット
|
|
379
|
+
refute model.remove_resizing_picture,
|
|
380
|
+
'remove flag should be reset after commit'
|
|
381
|
+
end
|
|
382
|
+
|
|
383
|
+
# ============================================================
|
|
384
|
+
# after_commit :remove_#{column}!, on: :destroy のテスト
|
|
385
|
+
# ============================================================
|
|
386
|
+
|
|
387
|
+
def test_remove_column_is_called_on_destroy
|
|
388
|
+
# after_commit :remove_#{column}!, on: :destroy が呼ばれ、
|
|
389
|
+
# ファイルが削除されることを確認
|
|
390
|
+
model = prepare_model TestModel
|
|
391
|
+
model.save!
|
|
392
|
+
|
|
393
|
+
refute model.resizing_picture.blank?
|
|
394
|
+
|
|
395
|
+
# destroy 時に DELETE リクエストが発行されることを確認
|
|
396
|
+
assert_vcr_requests_made 'carrier_wave_test/remove_resizing_picture' do
|
|
397
|
+
ActiveRecord::Base.transaction do
|
|
398
|
+
model.destroy!
|
|
399
|
+
end
|
|
400
|
+
end
|
|
401
|
+
|
|
402
|
+
# モデルが削除されたことを確認
|
|
403
|
+
assert model.destroyed?
|
|
404
|
+
end
|
|
405
|
+
|
|
406
|
+
# ============================================================
|
|
407
|
+
# コールバック順序のテスト
|
|
408
|
+
# ============================================================
|
|
409
|
+
|
|
410
|
+
def test_callback_order_on_create
|
|
411
|
+
# create 時のコールバック順序を確認
|
|
412
|
+
# 1. before_save :write_#{column}_identifier
|
|
413
|
+
# 2. after_save :store_#{column}!
|
|
414
|
+
# 3. after_commit (on: :create)
|
|
415
|
+
model = prepare_tracking_model
|
|
416
|
+
|
|
417
|
+
ActiveRecord::Base.transaction do
|
|
418
|
+
model.save!
|
|
419
|
+
end
|
|
420
|
+
|
|
421
|
+
# コールバックが正しい順序で呼ばれたことを確認
|
|
422
|
+
assert_equal %i[before_save after_save create_commit], model.callback_log
|
|
423
|
+
end
|
|
424
|
+
|
|
425
|
+
def test_callback_order_on_update
|
|
426
|
+
# update 時のコールバック順序を確認
|
|
427
|
+
# 1. before_save :write_#{column}_identifier
|
|
428
|
+
# 2. after_save :store_#{column}!
|
|
429
|
+
# 3. after_save :store_previous_changes_for_#{column}
|
|
430
|
+
# 4. after_commit :mark_remove_#{column}_false
|
|
431
|
+
# 5. after_commit :remove_previously_stored_#{column}
|
|
432
|
+
model = prepare_tracking_model
|
|
433
|
+
model.save!
|
|
434
|
+
model.callback_log.clear
|
|
435
|
+
|
|
436
|
+
# 更新
|
|
437
|
+
upload_new_image(model)
|
|
438
|
+
|
|
439
|
+
ActiveRecord::Base.transaction do
|
|
440
|
+
model.save!
|
|
441
|
+
end
|
|
442
|
+
|
|
443
|
+
# コールバックが正しい順序で呼ばれたことを確認
|
|
444
|
+
assert_equal %i[before_save after_save update_commit], model.callback_log
|
|
445
|
+
end
|
|
446
|
+
|
|
447
|
+
def test_callback_order_on_destroy
|
|
448
|
+
# destroy 時のコールバック順序を確認
|
|
449
|
+
# 1. before_destroy
|
|
450
|
+
# 2. after_destroy
|
|
451
|
+
# 3. after_commit :remove_#{column}!, on: :destroy
|
|
452
|
+
model = prepare_tracking_model
|
|
453
|
+
model.save!
|
|
454
|
+
model.callback_log.clear
|
|
455
|
+
|
|
456
|
+
assert_vcr_requests_made 'carrier_wave_test/remove_resizing_picture' do
|
|
457
|
+
ActiveRecord::Base.transaction do
|
|
458
|
+
model.destroy!
|
|
459
|
+
end
|
|
460
|
+
end
|
|
461
|
+
|
|
462
|
+
# コールバックが正しい順序で呼ばれたことを確認
|
|
463
|
+
assert_equal %i[before_destroy after_destroy destroy_commit], model.callback_log
|
|
464
|
+
end
|
|
186
465
|
end
|
|
187
466
|
end
|
data/test/test_helper.rb
CHANGED
|
@@ -61,7 +61,7 @@ module VCRRequestAssertions
|
|
|
61
61
|
# model.remove_resizing_picture!
|
|
62
62
|
# model.save!
|
|
63
63
|
# end
|
|
64
|
-
def assert_vcr_requests_made(cassette_name, options = {}
|
|
64
|
+
def assert_vcr_requests_made(cassette_name, options = {})
|
|
65
65
|
options = { record: :none }.merge(options)
|
|
66
66
|
|
|
67
67
|
VCR.use_cassette(cassette_name, options) do |cassette|
|
|
@@ -94,7 +94,7 @@ module VCRRequestAssertions
|
|
|
94
94
|
# assert_vcr_requests_count 'client/post', 1 do
|
|
95
95
|
# Resizing.post(file)
|
|
96
96
|
# end
|
|
97
|
-
def assert_vcr_requests_count(cassette_name, expected_count, options = {}
|
|
97
|
+
def assert_vcr_requests_count(cassette_name, expected_count, options = {})
|
|
98
98
|
options = { record: :none }.merge(options)
|
|
99
99
|
|
|
100
100
|
VCR.use_cassette(cassette_name, options) do |cassette|
|
|
@@ -197,3 +197,62 @@ end
|
|
|
197
197
|
class TestModelWithDefaultURL < ::ActiveRecord::Base
|
|
198
198
|
mount_uploader :resizing_picture, ResizingUploaderWithDefaultURL
|
|
199
199
|
end
|
|
200
|
+
|
|
201
|
+
# コールバックのテスト用モデル
|
|
202
|
+
# mount_uploader が登録する各種コールバックが正しく動作するかをテストするため
|
|
203
|
+
# カスタムコールバックを追加して呼び出しを追跡する
|
|
204
|
+
class TestModelWithCallbackTracking < ::ActiveRecord::Base
|
|
205
|
+
self.table_name = 'test_models'
|
|
206
|
+
|
|
207
|
+
mount_uploader :resizing_picture, ResizingUploader
|
|
208
|
+
|
|
209
|
+
attr_accessor :callback_log
|
|
210
|
+
|
|
211
|
+
# before_save / after_save コールバック
|
|
212
|
+
before_save :track_before_save
|
|
213
|
+
after_save :track_after_save
|
|
214
|
+
|
|
215
|
+
# before_destroy / after_destroy コールバック
|
|
216
|
+
before_destroy :track_before_destroy
|
|
217
|
+
after_destroy :track_after_destroy
|
|
218
|
+
|
|
219
|
+
# after_commit コールバック
|
|
220
|
+
after_commit :track_create_commit, on: :create
|
|
221
|
+
after_commit :track_update_commit, on: :update
|
|
222
|
+
after_commit :track_destroy_commit, on: :destroy
|
|
223
|
+
|
|
224
|
+
def initialize(*args)
|
|
225
|
+
super
|
|
226
|
+
@callback_log = []
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
private
|
|
230
|
+
|
|
231
|
+
def track_before_save
|
|
232
|
+
@callback_log << :before_save
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
def track_after_save
|
|
236
|
+
@callback_log << :after_save
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
def track_before_destroy
|
|
240
|
+
@callback_log << :before_destroy
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
def track_after_destroy
|
|
244
|
+
@callback_log << :after_destroy
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
def track_create_commit
|
|
248
|
+
@callback_log << :create_commit
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
def track_update_commit
|
|
252
|
+
@callback_log << :update_commit
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
def track_destroy_commit
|
|
256
|
+
@callback_log << :destroy_commit
|
|
257
|
+
end
|
|
258
|
+
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
---
|
|
2
|
+
http_interactions:
|
|
3
|
+
- request:
|
|
4
|
+
method: post
|
|
5
|
+
uri: http://192.168.56.101:5000/projects/e06e710d-f026-4dcf-b2c0-eab0de8bb83f/upload/images/
|
|
6
|
+
body:
|
|
7
|
+
encoding: ASCII-8BIT
|
|
8
|
+
string: ''
|
|
9
|
+
headers:
|
|
10
|
+
User-Agent:
|
|
11
|
+
- Faraday v1.0.1
|
|
12
|
+
response:
|
|
13
|
+
status:
|
|
14
|
+
code: 200
|
|
15
|
+
message: OK
|
|
16
|
+
headers:
|
|
17
|
+
content-type:
|
|
18
|
+
- application/json; charset=utf-8
|
|
19
|
+
body:
|
|
20
|
+
encoding: UTF-8
|
|
21
|
+
string: '{"id":"old-image-id-1111-1111-111111111111","project_id":"e06e710d-f026-4dcf-b2c0-eab0de8bb83f","content_type":"image/jpeg","version":"v1","public_id":"/projects/e06e710d-f026-4dcf-b2c0-eab0de8bb83f/upload/images/old-image-id-1111-1111-111111111111/v1"}'
|
|
22
|
+
recorded_at: Sun, 11 Oct 2020 04:56:48 GMT
|
|
23
|
+
- request:
|
|
24
|
+
method: post
|
|
25
|
+
uri: http://192.168.56.101:5000/projects/e06e710d-f026-4dcf-b2c0-eab0de8bb83f/upload/images/
|
|
26
|
+
body:
|
|
27
|
+
encoding: ASCII-8BIT
|
|
28
|
+
string: ''
|
|
29
|
+
headers:
|
|
30
|
+
User-Agent:
|
|
31
|
+
- Faraday v1.0.1
|
|
32
|
+
response:
|
|
33
|
+
status:
|
|
34
|
+
code: 200
|
|
35
|
+
message: OK
|
|
36
|
+
headers:
|
|
37
|
+
content-type:
|
|
38
|
+
- application/json; charset=utf-8
|
|
39
|
+
body:
|
|
40
|
+
encoding: UTF-8
|
|
41
|
+
string: '{"id":"new-image-id-2222-2222-222222222222","project_id":"e06e710d-f026-4dcf-b2c0-eab0de8bb83f","content_type":"image/jpeg","version":"v2","public_id":"/projects/e06e710d-f026-4dcf-b2c0-eab0de8bb83f/upload/images/new-image-id-2222-2222-222222222222/v2"}'
|
|
42
|
+
recorded_at: Sun, 11 Oct 2020 04:56:49 GMT
|
|
43
|
+
- request:
|
|
44
|
+
method: delete
|
|
45
|
+
uri: http://192.168.56.101:5000/projects/e06e710d-f026-4dcf-b2c0-eab0de8bb83f/upload/images/old-image-id-1111-1111-111111111111
|
|
46
|
+
body:
|
|
47
|
+
encoding: US-ASCII
|
|
48
|
+
string: ''
|
|
49
|
+
headers:
|
|
50
|
+
User-Agent:
|
|
51
|
+
- Faraday v1.0.1
|
|
52
|
+
response:
|
|
53
|
+
status:
|
|
54
|
+
code: 200
|
|
55
|
+
message: OK
|
|
56
|
+
headers:
|
|
57
|
+
content-type:
|
|
58
|
+
- application/json; charset=utf-8
|
|
59
|
+
body:
|
|
60
|
+
encoding: UTF-8
|
|
61
|
+
string: '{"id":"old-image-id-1111-1111-111111111111","project_id":"e06e710d-f026-4dcf-b2c0-eab0de8bb83f"}'
|
|
62
|
+
recorded_at: Sun, 11 Oct 2020 04:56:50 GMT
|
|
63
|
+
recorded_with: VCR 6.0.0
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: resizing
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.2.
|
|
4
|
+
version: 1.2.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Junichiro Kasuya
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-01-
|
|
11
|
+
date: 2026-01-31 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: faraday
|
|
@@ -232,6 +232,7 @@ files:
|
|
|
232
232
|
- test/test_helper.rb
|
|
233
233
|
- test/vcr/carrier_wave_test/remove_resizing_picture.yml
|
|
234
234
|
- test/vcr/carrier_wave_test/save.yml
|
|
235
|
+
- test/vcr/carrier_wave_test/update_image.yml
|
|
235
236
|
- test/vcr/client/delete.yml
|
|
236
237
|
- test/vcr/client/error.yml
|
|
237
238
|
- test/vcr/client/metadata.yml
|
|
@@ -259,7 +260,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
259
260
|
- !ruby/object:Gem::Version
|
|
260
261
|
version: '0'
|
|
261
262
|
requirements: []
|
|
262
|
-
rubygems_version: 3.
|
|
263
|
+
rubygems_version: 3.3.27
|
|
263
264
|
signing_key:
|
|
264
265
|
specification_version: 4
|
|
265
266
|
summary: Client and utilities for Resizing
|