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
@@ -0,0 +1,225 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ module Resizing
6
+ # Resizing::CarrierWave を include したアップローダ単体の挙動をテストする
7
+ # (モデルの保存・削除を伴う結合テストは carrier_wave_test.rb を参照)
8
+ class CarrierWaveUploaderTest < Minitest::Test
9
+ include VCRRequestAssertions
10
+ include ResizingTestConfiguration
11
+
12
+ IDENTIFIER = ResizingTestConfiguration::UPLOADED_IDENTIFIER
13
+
14
+ class TransformationUploader < ::CarrierWave::Uploader::Base
15
+ include Resizing::CarrierWave
16
+
17
+ process resize_to_fit: [100, 200]
18
+ process transformation: { quality: 80, fetch_format: 'webp' }
19
+ end
20
+
21
+ class FormatOverridesFetchFormatUploader < ::CarrierWave::Uploader::Base
22
+ include Resizing::CarrierWave
23
+
24
+ process transformation: { fetch_format: 'webp', format: 'png' }
25
+ end
26
+
27
+ class UnsupportedProcessorUploader < ::CarrierWave::Uploader::Base
28
+ include Resizing::CarrierWave
29
+
30
+ process convert: 'png'
31
+ end
32
+
33
+ class NoProcessorUploader < ::CarrierWave::Uploader::Base
34
+ include Resizing::CarrierWave
35
+ end
36
+
37
+ def setup
38
+ configure_resizing
39
+ end
40
+
41
+ def teardown
42
+ # NOP
43
+ end
44
+
45
+ def model_with_image(model_class = TestModel, identifier = IDENTIFIER)
46
+ model = model_class.new
47
+ model.send(:write_attribute, :resizing_picture, identifier)
48
+ model
49
+ end
50
+
51
+ # ============================================================
52
+ # include 時の設定
53
+ # ============================================================
54
+
55
+ def test_including_module_sets_remote_storage
56
+ assert_equal Resizing::CarrierWave::Storage::Remote, NoProcessorUploader.storage
57
+ assert_instance_of Resizing::CarrierWave::Storage::Remote, NoProcessorUploader.new.send(:storage)
58
+ end
59
+
60
+ def test_railtie_is_defined
61
+ assert Resizing::CarrierWave::Railtie < ::Rails::Railtie
62
+ end
63
+
64
+ # ============================================================
65
+ # transform_string
66
+ # ============================================================
67
+
68
+ def test_transform_string_for_resize_to_limit_without_height
69
+ assert_equal 'c_limit,w_1000', ResizingUploader.new.transform_string
70
+ end
71
+
72
+ def test_transform_string_for_version_with_resize_to_fill
73
+ assert_equal 'c_fill,w_40,h_40', TestModel.new.resizing_picture.versions[:small].transform_string
74
+ end
75
+
76
+ def test_transform_string_joins_multiple_processors_with_slash
77
+ assert_equal 'c_fit,w_100,h_200/q_80,f_webp', TransformationUploader.new.transform_string
78
+ end
79
+
80
+ def test_transform_string_format_takes_precedence_over_fetch_format
81
+ assert_equal 'f_png', FormatOverridesFetchFormatUploader.new.transform_string
82
+ end
83
+
84
+ def test_transform_string_is_empty_without_processors
85
+ assert_equal '', NoProcessorUploader.new.transform_string
86
+ end
87
+
88
+ def test_transform_string_raises_for_unsupported_processor
89
+ error = assert_raises(NotImplementedError) { UnsupportedProcessorUploader.new.transform_string }
90
+ assert_includes error.message, 'convert'
91
+ end
92
+
93
+ # ============================================================
94
+ # url
95
+ # ============================================================
96
+
97
+ def test_url_is_built_from_configured_image_host_and_column_value
98
+ model = model_with_image
99
+
100
+ assert_equal "http://192.168.56.101:5000#{IDENTIFIER}/", model.resizing_picture.url
101
+
102
+ # image_host を差し替えると URL も追従する (保存済みカラム値にはホストを含まない)
103
+ configure_resizing(image_host: 'https://cdn.example.com')
104
+ assert_equal "https://cdn.example.com#{IDENTIFIER}/", model.resizing_picture.url
105
+ end
106
+
107
+ def test_url_with_version_appends_transform_string
108
+ model = model_with_image
109
+
110
+ assert_equal "http://192.168.56.101:5000#{IDENTIFIER}/c_fill,w_40,h_40", model.resizing_picture.url(:small)
111
+ end
112
+
113
+ def test_url_accepts_string_version_name
114
+ model = model_with_image
115
+
116
+ assert_equal model.resizing_picture.url(:small), model.resizing_picture.url('small')
117
+ end
118
+
119
+ def test_url_raises_for_unknown_version
120
+ model = model_with_image
121
+
122
+ error = assert_raises(RuntimeError) { model.resizing_picture.url(:nope) }
123
+ assert_includes error.message, 'nope'
124
+ assert_includes error.message, 'small'
125
+ end
126
+
127
+ def test_url_returns_default_url_when_column_is_blank
128
+ assert_nil TestModel.new.resizing_picture.url
129
+ assert_equal 'http://example.com/test.jpg', TestModelWithDefaultURL.new.resizing_picture.url
130
+ end
131
+
132
+ def test_url_ignores_version_when_column_is_blank
133
+ # カラムが空なら version 指定があっても default_url を返す
134
+ assert_nil TestModel.new.resizing_picture.url(:small)
135
+ end
136
+
137
+ def test_model_url_helper_delegates_to_uploader_url
138
+ model = model_with_image
139
+
140
+ assert_equal model.resizing_picture.url, model.resizing_picture_url
141
+ assert_equal model.resizing_picture.url(:small), model.resizing_picture_url(:small)
142
+ end
143
+
144
+ # ============================================================
145
+ # identifier / filename / file
146
+ # ============================================================
147
+
148
+ def test_filename_and_identifier_return_column_value
149
+ model = model_with_image
150
+
151
+ assert_equal IDENTIFIER, model.resizing_picture.filename
152
+ assert_equal IDENTIFIER, model.resizing_picture.identifier
153
+ end
154
+
155
+ def test_file_reflects_column_value
156
+ model = model_with_image
157
+ file = model.resizing_picture.file
158
+
159
+ assert_instance_of Resizing::CarrierWave::Storage::File, file
160
+ assert_equal IDENTIFIER, file.public_id.to_s
161
+ assert_equal IDENTIFIER, file.path
162
+ end
163
+
164
+ def test_uploader_is_present_when_column_has_value
165
+ model = model_with_image
166
+
167
+ assert model.resizing_picture.present?
168
+ refute model.resizing_picture.blank?
169
+ end
170
+
171
+ # ============================================================
172
+ # cache! / store_versions! / remove_versions! / rename
173
+ # ============================================================
174
+
175
+ def test_cache_with_nil_does_nothing
176
+ uploader = TestModel.new.resizing_picture
177
+
178
+ assert_vcr_no_requests 'carrier_wave_test/save' do
179
+ assert_nil uploader.cache!(nil)
180
+ end
181
+ assert_nil uploader.file
182
+ end
183
+
184
+ def test_store_versions_and_remove_versions_are_noop
185
+ uploader = TestModel.new.resizing_picture
186
+
187
+ assert_nil uploader.store_versions!
188
+ assert_nil uploader.remove_versions!
189
+ assert_nil uploader.retrieve_versions_from_cache!(IDENTIFIER)
190
+ end
191
+
192
+ def test_cache_expires_in_defaults_to_nil
193
+ assert_nil TestModel.new.resizing_picture.cache_expires_in
194
+ end
195
+
196
+ def test_cached_file_is_not_deleted_after_storing
197
+ # 一時画像は確定するとそのまま保存済みの画像になるので、保存後に削除してはいけない
198
+ assert_equal false, TestModel.new.resizing_picture.delete_tmp_file_after_storage
199
+ end
200
+
201
+ def test_cache_name_is_nil_when_nothing_is_cached
202
+ assert_nil TestModel.new.resizing_picture.cache_name
203
+ end
204
+
205
+ def test_rename_raises_not_implemented_error
206
+ assert_raises(NotImplementedError) { TestModel.new.resizing_picture.rename }
207
+ end
208
+
209
+ # ============================================================
210
+ # format
211
+ # ============================================================
212
+
213
+ def test_format_related_methods_default_to_nil
214
+ uploader = TestModel.new.resizing_picture
215
+
216
+ assert_nil uploader.requested_format
217
+ assert_nil uploader.default_format
218
+ assert_nil uploader.format
219
+ end
220
+
221
+ def test_format_uses_overridden_default_format
222
+ assert_equal 'jpg', TestJPGModel.new.resizing_picture.format
223
+ end
224
+ end
225
+ end