resizing 1.2.0 → 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/.github/workflows/test.yml +17 -2
- data/.gitignore +6 -0
- data/Gemfile +6 -2
- data/README.md +59 -32
- data/lib/resizing/active_storage/service/resizing_service.rb +6 -2
- data/lib/resizing/active_storage/service.rb +9 -0
- data/lib/resizing/active_storage.rb +7 -0
- data/lib/resizing/carrier_wave/storage/file.rb +68 -24
- data/lib/resizing/carrier_wave/storage/remote.rb +7 -3
- data/lib/resizing/carrier_wave.rb +19 -11
- data/lib/resizing/client.rb +25 -23
- data/lib/resizing/configurable.rb +1 -1
- data/lib/resizing/configuration.rb +6 -16
- data/lib/resizing/http_clientable.rb +3 -3
- data/lib/resizing/mock_client.rb +6 -5
- data/lib/resizing/public_id.rb +5 -4
- data/lib/resizing/version.rb +1 -1
- data/lib/resizing.rb +15 -12
- data/resizing.gemspec +5 -8
- data/test/resizing/active_storage_service_test.rb +98 -0
- data/test/resizing/carrier_wave/storage/file_test.rb +149 -8
- data/test/resizing/carrier_wave/storage/remote_test.rb +75 -0
- data/test/resizing/carrier_wave_test.rb +373 -32
- data/test/resizing/client_test.rb +68 -12
- data/test/resizing/configurable_test.rb +82 -0
- data/test/resizing/configuration_test.rb +118 -2
- data/test/resizing/constants_test.rb +25 -0
- data/test/resizing/error_test.rb +73 -0
- data/test/resizing/http_clientable_test.rb +84 -0
- data/test/resizing/mock_client_test.rb +75 -0
- data/test/resizing/public_id_test.rb +1 -1
- data/test/resizing_module_test.rb +206 -0
- data/test/test_helper.rb +148 -9
- data/test/vcr/carrier_wave_test/update_image.yml +63 -0
- metadata +29 -36
- /data/{exe → bin}/console +0 -0
- /data/{exe → bin}/generate-changelog +0 -0
- /data/{exe → bin}/setup +0 -0
|
@@ -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
|
-
|
|
40
|
+
_config = Resizing::Configuration.new template
|
|
42
41
|
end
|
|
43
42
|
end
|
|
44
43
|
|
|
@@ -147,5 +146,122 @@ module Resizing
|
|
|
147
146
|
config = Resizing::Configuration.new @template
|
|
148
147
|
assert_match %r{/projects/#{config.project_id}/upload/images/[\da-z-]}, config.generate_identifier
|
|
149
148
|
end
|
|
149
|
+
|
|
150
|
+
def test_generate_image_id_returns_uuid
|
|
151
|
+
config = Resizing::Configuration.new @template
|
|
152
|
+
image_id = config.generate_image_id
|
|
153
|
+
|
|
154
|
+
assert_instance_of String, image_id
|
|
155
|
+
# UUID format: 8-4-4-4-12
|
|
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)
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
def test_generate_image_id_returns_different_uuids
|
|
160
|
+
config = Resizing::Configuration.new @template
|
|
161
|
+
id1 = config.generate_image_id
|
|
162
|
+
id2 = config.generate_image_id
|
|
163
|
+
|
|
164
|
+
refute_equal id1, id2
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
def test_equality_returns_true_for_same_configurations
|
|
168
|
+
config1 = Resizing::Configuration.new @template
|
|
169
|
+
config2 = Resizing::Configuration.new @template
|
|
170
|
+
|
|
171
|
+
assert_equal config1, config2
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
def test_equality_returns_false_for_different_image_host
|
|
175
|
+
config1 = Resizing::Configuration.new @template
|
|
176
|
+
template2 = @template.dup
|
|
177
|
+
template2[:image_host] = 'http://different.host'
|
|
178
|
+
config2 = Resizing::Configuration.new template2
|
|
179
|
+
|
|
180
|
+
refute_equal config1, config2
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
def test_equality_returns_false_for_different_project_id
|
|
184
|
+
config1 = Resizing::Configuration.new @template
|
|
185
|
+
template2 = @template.dup
|
|
186
|
+
template2[:project_id] = 'different-project-id'
|
|
187
|
+
config2 = Resizing::Configuration.new template2
|
|
188
|
+
|
|
189
|
+
refute_equal config1, config2
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
def test_equality_returns_false_for_different_class
|
|
193
|
+
config = Resizing::Configuration.new @template
|
|
194
|
+
|
|
195
|
+
refute_equal config, 'not a configuration'
|
|
196
|
+
refute_equal config, @template
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
def test_transformation_path_with_multiple_transforms
|
|
200
|
+
config = Resizing::Configuration.new @template
|
|
201
|
+
transforms = [
|
|
202
|
+
{ w: 100, h: 200 },
|
|
203
|
+
{ f: 'webp', q: 80 }
|
|
204
|
+
]
|
|
205
|
+
|
|
206
|
+
path = config.transformation_path(transforms)
|
|
207
|
+
|
|
208
|
+
assert_equal 'w_100,h_200/f_webp,q_80', path
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
def test_transformation_path_with_single_hash
|
|
212
|
+
config = Resizing::Configuration.new @template
|
|
213
|
+
transform = { w: 300, h: 300, c: 'fill' }
|
|
214
|
+
|
|
215
|
+
path = config.transformation_path(transform)
|
|
216
|
+
|
|
217
|
+
assert_equal 'w_300,h_300,c_fill', path
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
def test_transformation_path_ignores_unknown_options
|
|
221
|
+
config = Resizing::Configuration.new @template
|
|
222
|
+
transform = { w: 100, unknown_option: 'ignored', h: 200 }
|
|
223
|
+
|
|
224
|
+
path = config.transformation_path(transform)
|
|
225
|
+
|
|
226
|
+
assert_equal 'w_100,h_200', path
|
|
227
|
+
refute_includes path, 'unknown_option'
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
def test_transformation_path_with_empty_array
|
|
231
|
+
config = Resizing::Configuration.new @template
|
|
232
|
+
path = config.transformation_path([])
|
|
233
|
+
|
|
234
|
+
assert_equal '', path
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
def test_generate_identifier_includes_project_id
|
|
238
|
+
config = Resizing::Configuration.new @template
|
|
239
|
+
identifier = config.generate_identifier
|
|
240
|
+
|
|
241
|
+
assert_includes identifier, config.project_id
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
def test_generate_identifier_has_correct_format
|
|
245
|
+
config = Resizing::Configuration.new @template
|
|
246
|
+
identifier = config.generate_identifier
|
|
247
|
+
|
|
248
|
+
assert_match %r{\A/projects/[\da-z-]+/upload/images/[\da-z-]+\z}, identifier
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
def test_enable_mock_defaults_to_false
|
|
252
|
+
template = @template.dup
|
|
253
|
+
template.delete(:enable_mock)
|
|
254
|
+
config = Resizing::Configuration.new template
|
|
255
|
+
|
|
256
|
+
assert_equal false, config.enable_mock
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
def test_enable_mock_can_be_set_to_true
|
|
260
|
+
template = @template.dup
|
|
261
|
+
template[:enable_mock] = true
|
|
262
|
+
config = Resizing::Configuration.new template
|
|
263
|
+
|
|
264
|
+
assert_equal true, config.enable_mock
|
|
265
|
+
end
|
|
150
266
|
end
|
|
151
267
|
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'test_helper'
|
|
4
|
+
|
|
5
|
+
module Resizing
|
|
6
|
+
class ConstantsTest < Minitest::Test
|
|
7
|
+
def test_http_status_ok_is_defined
|
|
8
|
+
assert_equal 200, Resizing::Constants::HTTP_STATUS_OK
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def test_http_status_created_is_defined
|
|
12
|
+
assert_equal 201, Resizing::Constants::HTTP_STATUS_CREATED
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_http_status_not_found_is_defined
|
|
16
|
+
assert_equal 404, Resizing::Constants::HTTP_STATUS_NOT_FOUND
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test_constants_are_integers
|
|
20
|
+
assert_instance_of Integer, Resizing::Constants::HTTP_STATUS_OK
|
|
21
|
+
assert_instance_of Integer, Resizing::Constants::HTTP_STATUS_CREATED
|
|
22
|
+
assert_instance_of Integer, Resizing::Constants::HTTP_STATUS_NOT_FOUND
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'test_helper'
|
|
4
|
+
|
|
5
|
+
module Resizing
|
|
6
|
+
class ErrorTest < Minitest::Test
|
|
7
|
+
def test_error_is_standard_error_subclass
|
|
8
|
+
assert Resizing::Error < StandardError
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def test_configuration_error_is_error_subclass
|
|
12
|
+
assert Resizing::ConfigurationError < Resizing::Error
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_api_error_is_error_subclass
|
|
16
|
+
assert Resizing::APIError < Resizing::Error
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test_api_error_has_decoded_body_accessor
|
|
20
|
+
error = Resizing::APIError.new('test error')
|
|
21
|
+
|
|
22
|
+
assert_respond_to error, :decoded_body
|
|
23
|
+
assert_respond_to error, :decoded_body=
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_api_error_decoded_body_defaults_to_empty_hash
|
|
27
|
+
error = Resizing::APIError.new('test error')
|
|
28
|
+
|
|
29
|
+
assert_equal({}, error.decoded_body)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def test_api_error_decoded_body_can_be_set_with_hash
|
|
33
|
+
error = Resizing::APIError.new('test error')
|
|
34
|
+
body = { 'error' => 'test', 'code' => 400 }
|
|
35
|
+
|
|
36
|
+
error.decoded_body = body
|
|
37
|
+
|
|
38
|
+
assert_equal body, error.decoded_body
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def test_api_error_decoded_body_raises_argument_error_for_non_hash
|
|
42
|
+
error = Resizing::APIError.new('test error')
|
|
43
|
+
|
|
44
|
+
assert_raises ArgumentError do
|
|
45
|
+
error.decoded_body = 'not a hash'
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def test_api_error_decoded_body_raises_argument_error_for_array
|
|
50
|
+
error = Resizing::APIError.new('test error')
|
|
51
|
+
|
|
52
|
+
assert_raises ArgumentError do
|
|
53
|
+
error.decoded_body = %w[not a hash]
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def test_configuration_error_can_be_raised_with_message
|
|
58
|
+
error = assert_raises Resizing::ConfigurationError do
|
|
59
|
+
raise Resizing::ConfigurationError, 'test configuration error'
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
assert_equal 'test configuration error', error.message
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def test_api_error_can_be_raised_with_message
|
|
66
|
+
error = assert_raises Resizing::APIError do
|
|
67
|
+
raise Resizing::APIError, 'test api error'
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
assert_equal 'test api error', error.message
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'test_helper'
|
|
4
|
+
|
|
5
|
+
module Resizing
|
|
6
|
+
class HttpClientableTest < Minitest::Test
|
|
7
|
+
class TestClient
|
|
8
|
+
include HttpClientable
|
|
9
|
+
|
|
10
|
+
def config
|
|
11
|
+
@config ||= Configuration.new(
|
|
12
|
+
image_host: 'https://image.example.com',
|
|
13
|
+
project_id: 'test_project',
|
|
14
|
+
secret_token: 'test_token'
|
|
15
|
+
)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def setup
|
|
20
|
+
@client = TestClient.new
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def teardown
|
|
24
|
+
# NOP
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_http_client_initialization
|
|
28
|
+
http_client = @client.http_client
|
|
29
|
+
|
|
30
|
+
assert_instance_of Faraday::Connection, http_client
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_http_client_has_open_timeout
|
|
34
|
+
http_client = @client.http_client
|
|
35
|
+
|
|
36
|
+
assert_equal @client.config.open_timeout, http_client.options[:open_timeout]
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def test_http_client_has_response_timeout
|
|
40
|
+
http_client = @client.http_client
|
|
41
|
+
|
|
42
|
+
assert_equal @client.config.response_timeout, http_client.options[:timeout]
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def test_http_client_is_cached
|
|
46
|
+
http_client1 = @client.http_client
|
|
47
|
+
http_client2 = @client.http_client
|
|
48
|
+
|
|
49
|
+
assert_equal http_client1.object_id, http_client2.object_id
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def test_handle_faraday_error_yields_block
|
|
53
|
+
result = @client.handle_faraday_error { 'test_result' }
|
|
54
|
+
|
|
55
|
+
assert_equal 'test_result', result
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def test_handle_faraday_error_catches_timeout_error
|
|
59
|
+
assert_raises Resizing::APIError do
|
|
60
|
+
@client.handle_faraday_error do
|
|
61
|
+
raise Faraday::TimeoutError, 'timeout'
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def test_handle_timeout_error_raises_api_error
|
|
67
|
+
error = Faraday::TimeoutError.new('test timeout')
|
|
68
|
+
|
|
69
|
+
assert_raises Resizing::APIError do
|
|
70
|
+
@client.handle_timeout_error(error)
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def test_handle_timeout_error_message_includes_error_info
|
|
75
|
+
error = Faraday::TimeoutError.new('test timeout')
|
|
76
|
+
|
|
77
|
+
begin
|
|
78
|
+
@client.handle_timeout_error(error)
|
|
79
|
+
rescue Resizing::APIError => e
|
|
80
|
+
assert_includes e.message, 'TimeoutError'
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'test_helper'
|
|
4
|
+
|
|
5
|
+
module Resizing
|
|
6
|
+
class MockClientTest < Minitest::Test
|
|
7
|
+
def setup
|
|
8
|
+
@client = Resizing::MockClient.new
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def teardown
|
|
12
|
+
# NOP
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_post_returns_parsed_json
|
|
16
|
+
VCR.use_cassette('client/post', record: :none) do
|
|
17
|
+
result = @client.post(nil)
|
|
18
|
+
|
|
19
|
+
assert_instance_of Hash, result
|
|
20
|
+
assert result.key?('id')
|
|
21
|
+
assert result.key?('public_id')
|
|
22
|
+
assert result.key?('latest_version_id')
|
|
23
|
+
assert result.key?('latest_etag')
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_put_returns_parsed_json_with_modified_name
|
|
28
|
+
VCR.use_cassette('client/put', record: :none) do
|
|
29
|
+
name = 'test-image-123'
|
|
30
|
+
result = @client.put(name, nil, {})
|
|
31
|
+
|
|
32
|
+
assert_instance_of Hash, result
|
|
33
|
+
assert_equal name, result['id']
|
|
34
|
+
assert_includes result['public_id'], name
|
|
35
|
+
assert result.key?('latest_version_id')
|
|
36
|
+
assert result.key?('latest_etag')
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_delete_returns_parsed_json_with_modified_name
|
|
41
|
+
VCR.use_cassette('client/delete', record: :none) do
|
|
42
|
+
name = 'delete-test-image'
|
|
43
|
+
result = @client.delete(name)
|
|
44
|
+
|
|
45
|
+
assert_instance_of Hash, result
|
|
46
|
+
assert_equal name, result['id']
|
|
47
|
+
assert_includes result['public_id'], name
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def test_metadata_returns_parsed_json_with_modified_name
|
|
52
|
+
VCR.use_cassette('client/metadata', record: :none) do
|
|
53
|
+
name = 'metadata-test-image'
|
|
54
|
+
result = @client.metadata(name)
|
|
55
|
+
|
|
56
|
+
assert_instance_of Hash, result
|
|
57
|
+
assert_equal name, result['id']
|
|
58
|
+
# The cassette contains a fixed public_id, so we just check it exists
|
|
59
|
+
assert result.key?('public_id')
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def test_post_response_contains_expected_fields
|
|
64
|
+
VCR.use_cassette('client/post', record: :none) do
|
|
65
|
+
result = @client.post(nil)
|
|
66
|
+
|
|
67
|
+
# Verify response structure
|
|
68
|
+
assert result['id'].is_a?(String)
|
|
69
|
+
assert result['public_id'].is_a?(String)
|
|
70
|
+
assert result['latest_version_id'].is_a?(String)
|
|
71
|
+
assert result['latest_etag'].is_a?(String)
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
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(
|
|
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
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'test_helper'
|
|
4
|
+
|
|
5
|
+
class ResizingModuleTest < Minitest::Test
|
|
6
|
+
def setup
|
|
7
|
+
# Reset configure before each test to ensure clean state
|
|
8
|
+
return unless Resizing.instance_variable_defined?(:@configure)
|
|
9
|
+
|
|
10
|
+
Resizing.remove_instance_variable(:@configure)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def teardown
|
|
14
|
+
# Reset configure after each test
|
|
15
|
+
return unless Resizing.instance_variable_defined?(:@configure)
|
|
16
|
+
|
|
17
|
+
Resizing.remove_instance_variable(:@configure)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_configure_raises_error_when_not_initialized
|
|
21
|
+
assert_raises Resizing::ConfigurationError do
|
|
22
|
+
Resizing.configure
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_configure_returns_duplicate_of_configuration
|
|
27
|
+
config = Resizing::Configuration.new(
|
|
28
|
+
image_host: 'https://test.example.com',
|
|
29
|
+
project_id: 'test_id',
|
|
30
|
+
secret_token: 'test_token'
|
|
31
|
+
)
|
|
32
|
+
Resizing.configure = config
|
|
33
|
+
|
|
34
|
+
result = Resizing.configure
|
|
35
|
+
|
|
36
|
+
assert_instance_of Resizing::Configuration, result
|
|
37
|
+
assert_equal config.image_host, result.image_host
|
|
38
|
+
assert_equal config.project_id, result.project_id
|
|
39
|
+
refute_equal config.object_id, result.object_id # Should be a duplicate
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def test_configure_setter_accepts_configuration_object
|
|
43
|
+
config = Resizing::Configuration.new(
|
|
44
|
+
image_host: 'https://test.example.com',
|
|
45
|
+
project_id: 'test_id',
|
|
46
|
+
secret_token: 'test_token'
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
Resizing.configure = config
|
|
50
|
+
|
|
51
|
+
assert_equal config, Resizing.instance_variable_get(:@configure)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def test_configure_setter_converts_hash_to_configuration
|
|
55
|
+
config_hash = {
|
|
56
|
+
image_host: 'https://hash.example.com',
|
|
57
|
+
project_id: 'hash_id',
|
|
58
|
+
secret_token: 'hash_token'
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
Resizing.configure = config_hash
|
|
62
|
+
|
|
63
|
+
result = Resizing.instance_variable_get(:@configure)
|
|
64
|
+
assert_instance_of Resizing::Configuration, result
|
|
65
|
+
assert_equal 'https://hash.example.com', result.image_host
|
|
66
|
+
assert_equal 'hash_id', result.project_id
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def test_get_raises_not_implemented_error
|
|
70
|
+
assert_raises NotImplementedError do
|
|
71
|
+
Resizing.get('test')
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def test_url_from_image_id_returns_url_without_version_and_transforms
|
|
76
|
+
Resizing.configure = {
|
|
77
|
+
image_host: 'https://img.example.com',
|
|
78
|
+
project_id: 'project123',
|
|
79
|
+
secret_token: 'token123'
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
url = Resizing.url_from_image_id('image456')
|
|
83
|
+
|
|
84
|
+
assert_equal 'https://img.example.com/projects/project123/upload/images/image456', url
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def test_url_from_image_id_returns_url_with_version
|
|
88
|
+
Resizing.configure = {
|
|
89
|
+
image_host: 'https://img.example.com',
|
|
90
|
+
project_id: 'project123',
|
|
91
|
+
secret_token: 'token123'
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
url = Resizing.url_from_image_id('image456', '789')
|
|
95
|
+
|
|
96
|
+
assert_equal 'https://img.example.com/projects/project123/upload/images/image456/v789', url
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def test_url_from_image_id_returns_url_with_transformations
|
|
100
|
+
Resizing.configure = {
|
|
101
|
+
image_host: 'https://img.example.com',
|
|
102
|
+
project_id: 'project123',
|
|
103
|
+
secret_token: 'token123'
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
url = Resizing.url_from_image_id('image456', nil, [{ w: 100, h: 200 }])
|
|
107
|
+
|
|
108
|
+
assert_includes url, 'https://img.example.com/projects/project123/upload/images/image456/'
|
|
109
|
+
assert_includes url, 'w_100,h_200'
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def test_url_from_image_id_returns_url_with_version_and_transformations
|
|
113
|
+
Resizing.configure = {
|
|
114
|
+
image_host: 'https://img.example.com',
|
|
115
|
+
project_id: 'project123',
|
|
116
|
+
secret_token: 'token123'
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
url = Resizing.url_from_image_id('image456', '789', [{ w: 100 }])
|
|
120
|
+
|
|
121
|
+
assert_includes url, 'image456/v789/'
|
|
122
|
+
assert_includes url, 'w_100'
|
|
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
|
|
206
|
+
end
|