resizing 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a68f3747dc45de527ea32a40bb2586783a0ea14d76717bd85186aae178ef18bd
4
- data.tar.gz: 5ecebffc8b0eb31c22e3bb408eea3d99db21b90bcdba5178e74f1f0704261ed5
3
+ metadata.gz: 67c72ad237f9dbd4b471d9b249ed6fbc21cdb4c99a9ff8c86e3c4aec72233c21
4
+ data.tar.gz: 67377bf88e061f477443d37c3d5f9362e1fc8546dd09336585e5b26820b13efe
5
5
  SHA512:
6
- metadata.gz: 233c87e03b19be35e89d373a4456aa81cdd82c110eea4cff47f2d8498a852ed203c0443567f0afb8b6d85bd419da49b6accb5e52038e823beddf40d88f84e94d
7
- data.tar.gz: 66f18b1648e93a2cbdf73a2a457b9e2591262b795dfbebd232cd0388ca7787a755068a85c84f763f1c28fa7e10c61a4169915aff35184d1f602c6498cca8f63e
6
+ metadata.gz: 982272977e217042ba1cb332a918f8877667b87731a2587cecf285664ebf669f96e2265e254f43afb42a4d8101bfda07010e5790b2cce1440363924efa05d1ab
7
+ data.tar.gz: fb4da505d292795e84ef79577029d0317ac199db177e0e91d51be75a2c92f89fe4bf2a3a9c0102da20c1552d1450f46ea0471065b6d10d3e8f777ead16367767
@@ -9,6 +9,7 @@ module Resizing
9
9
  autoload :MockClient, 'resizing/mock_client'
10
10
  autoload :Configuration, 'resizing/configuration'
11
11
  autoload :CarrierWave, 'resizing/carrier_wave'
12
+ autoload :PublicId, 'resizing/public_id'
12
13
 
13
14
  class Error < StandardError; end
14
15
  class ConfigurationError < Error; end
@@ -41,6 +42,14 @@ module Resizing
41
42
  self.client.put name, file_or_binary, options
42
43
  end
43
44
 
45
+ def self.delete(name)
46
+ self.client.delete name
47
+ end
48
+
49
+ def self.metadata(name, options)
50
+ self.client.metadata name, options
51
+ end
52
+
44
53
  # TODO: refactoring
45
54
  #
46
55
  # identifier:
@@ -54,7 +63,7 @@ module Resizing
54
63
  end
55
64
 
56
65
  def self.separate_public_id public_id
57
- public_id.match('/projects/(?<project_id>[0-9a-f-]+)/upload/images/(?<image_id>[0-9a-f-]+)(/v(?<version>[^/]+))?')
66
+ public_id.match('/projects/(?<project_id>[0-9a-f-]+)/upload/images/(?<image_id>[^/]+)(/v(?<version>[^/]+))?')
58
67
  end
59
68
 
60
69
  def self.client
@@ -25,23 +25,30 @@ module Resizing
25
25
  base.extend ClassMethods
26
26
  end
27
27
 
28
+ def initialize(*args)
29
+ @requested_format = nil
30
+ @default_format = nil
31
+ super
32
+ end
33
+
28
34
  def url(*args)
29
35
  return nil unless read_column.present?
30
36
 
31
- transforms = [transform_string]
37
+ transforms = args.map do |version|
38
+ version = version.intern
39
+ raise "No version is found: #{version}, #{versions.keys} are exists." unless versions.has_key? version
40
+ versions[version].transform_string
41
+ end.compact
32
42
 
33
- while (version = args.pop)
34
- transforms << versions[version].transform_string
35
- end
36
43
  "#{default_url}/#{transforms.join('/')}"
37
44
  end
38
45
 
39
46
  def read_column
40
- model.read_attribute(mounted_as)
47
+ model.read_attribute(serialization_column)
41
48
  end
42
49
 
43
50
  def default_url
44
- "#{Resizing.configure.host}#{model.read_attribute(mounted_as)}"
51
+ "#{Resizing.configure.host}#{model.read_attribute(serialization_column)}"
45
52
  end
46
53
 
47
54
  def transform_string
@@ -79,16 +86,21 @@ module Resizing
79
86
  # save to resizing directly
80
87
  # @cache_id = file.public_id
81
88
 
82
- @filename = file.public_id
89
+ @filename = file.public_id.to_s
83
90
  @file = file
84
91
  end
85
92
 
93
+ def filename
94
+ read_column
95
+ end
96
+
86
97
  def store!
87
98
  # DO NOTHING
88
99
  super
89
100
  end
90
101
 
91
- module ClassMethods
102
+ def serialization_column
103
+ model.send(:_mounter, mounted_as).send(:serialization_column)
92
104
  end
93
105
 
94
106
  # store_versions! is called after store!
@@ -105,6 +117,23 @@ module Resizing
105
117
  # NOP
106
118
  end
107
119
 
120
+ def requested_format
121
+ # TODO
122
+ # The request with uploading format parameter is not working on the Resizing until 2020/09/25
123
+ @requested_format
124
+ end
125
+
126
+ def default_format
127
+ @default_format
128
+ end
129
+
130
+ def format
131
+ requested_format || default_format
132
+ end
133
+
134
+ module ClassMethods
135
+ end
136
+
108
137
  private
109
138
 
110
139
  # rubocop:disable Metrics/AbcSize
@@ -9,9 +9,11 @@ module Resizing
9
9
  def initialize(uploader, identifier = nil)
10
10
  @uploader = uploader
11
11
  @content_type = nil
12
- @identifier = identifier
12
+ @public_id = Resizing::PublicId.new identifier
13
13
  end
14
14
 
15
+ attr_reader :public_id
16
+
15
17
  def attributes
16
18
  file.attributes
17
19
  end
@@ -24,24 +26,18 @@ module Resizing
24
26
  @content_type || file.try(:content_type)
25
27
  end
26
28
 
27
- attr_writer :content_type
28
-
29
29
  def delete
30
- public_id = model.send :read_attribute, serialization_column
31
- return if public_id.nil? # do nothing
32
-
33
- # TODO:
34
- # refactoring
35
- separted = Resizing.separate_public_id(public_id)
36
- image_id = separted[:image_id]
37
- resp = client.delete(image_id)
30
+ @public_id = Resizing::PublicId.new(model.send :read_attribute, serialization_column)
31
+ return if @public_id.empty? # do nothing
32
+
33
+ resp = client.delete(@public_id.image_id)
38
34
  if resp['error'] == 'ActiveRecord::RecordNotFound' # 404 not found
39
- model.send :write_attribute, serialization_column, nil
35
+ model.send :write_attribute, serialization_column, nil unless model.destroyed?
40
36
  return
41
37
  end
42
38
 
43
- if public_id == resp['public_id']
44
- model.send :write_attribute, serialization_column, nil
39
+ if @public_id.image_id == resp['id']
40
+ model.send :write_attribute, serialization_column, nil unless model.destroyed?
45
41
  return
46
42
  end
47
43
 
@@ -86,9 +82,22 @@ module Resizing
86
82
  raise NotImplementedError, 'new file is required duplicating'
87
83
  end
88
84
 
89
- @content_type ||= new_file.content_type
90
- @response = Resizing.put(identifier, new_file.read, { content_type: @content_type })
91
- @public_id = @response['public_id']
85
+ if new_file.respond_to? :content_type
86
+ @content_type ||= new_file.content_type
87
+ else
88
+ # guess content-type from extension
89
+ @content_type ||= MIME::Types.type_for(new_file.path).first.content_type
90
+ end
91
+ @public_id = PublicId.new(model.send :read_attribute, serialization_column)
92
+
93
+ image_id = if @public_id.empty?
94
+ Resizing.configure.generate_image_id
95
+ else
96
+ @public_id.image_id
97
+ end
98
+
99
+ @response = Resizing.put(image_id, new_file.read, { content_type: @content_type })
100
+ @public_id = Resizing::PublicId.new(@response['public_id'])
92
101
 
93
102
  # force update column
94
103
  # model_class
@@ -96,26 +105,14 @@ module Resizing
96
105
  # .update_all(serialization_column=>@public_id)
97
106
 
98
107
  # save new value to model class
99
- model.send :write_attribute, serialization_column, @public_id
108
+ model.send :write_attribute, serialization_column, @public_id.to_s
100
109
 
101
110
  true
102
111
  end
103
112
 
104
- attr_reader :public_id
105
-
106
- def identifier
107
- if public_id.present?
108
- public_id
109
- else
110
- @identifier = SecureRandom.uuid
111
- end
112
- end
113
-
114
- def filename(options = {})
115
- file_url = url(options)
116
- return unless file_url
117
-
118
- CGI.unescape(file_url.split('?').first).gsub(%r{.*/(.*?$)}, '\1')
113
+ def name(options = {})
114
+ @public_id = PublicId.new(model.send :read_attribute, serialization_column)
115
+ CGI.unescape(@public_id.filename)
119
116
  end
120
117
 
121
118
  # def copy_to(new_path)
@@ -9,7 +9,14 @@ module Resizing
9
9
  def store!(file)
10
10
  f = Resizing::CarrierWave::Storage::File.new(uploader)
11
11
  f.store(file)
12
- @filename = f.public_id
12
+ @filename = f.public_id.to_s
13
+ f
14
+ end
15
+
16
+ def remove!(file)
17
+ f = Resizing::CarrierWave::Storage::File.new(uploader)
18
+ f.delete(file)
19
+ @filename = f.public_id.to_s
13
20
  f
14
21
  end
15
22
 
@@ -41,7 +41,7 @@ module Resizing
41
41
  end
42
42
  end
43
43
 
44
- def get(name)
44
+ def get(image_id)
45
45
  raise NotImplementedError
46
46
  end
47
47
 
@@ -63,10 +63,10 @@ module Resizing
63
63
  result
64
64
  end
65
65
 
66
- def put(name, file_or_binary, options)
66
+ def put(image_id, file_or_binary, options)
67
67
  ensure_content_type(options)
68
68
 
69
- url = build_put_url(name)
69
+ url = build_put_url(image_id)
70
70
 
71
71
  body = to_io(file_or_binary)
72
72
  params = {
@@ -81,8 +81,8 @@ module Resizing
81
81
  result
82
82
  end
83
83
 
84
- def delete(name)
85
- url = build_delete_url(name)
84
+ def delete(image_id)
85
+ url = build_delete_url(image_id)
86
86
 
87
87
  response = http_client.delete(url) do |request|
88
88
  request.headers['X-ResizingToken'] = config.generate_auth_header
@@ -92,22 +92,37 @@ module Resizing
92
92
  result
93
93
  end
94
94
 
95
+ def metadata(image_id, options = {})
96
+ url = build_metadata_url(image_id)
97
+
98
+ response = http_client.get(url) do |request|
99
+ request.headers['X-ResizingToken'] = config.generate_auth_header
100
+ end
101
+
102
+ result = handle_metadata_response(response)
103
+ result
104
+ end
105
+
95
106
  private
96
107
 
97
- def build_get_url(name)
98
- "#{config.host}/projects/#{config.project_id}/upload/images/#{name}"
108
+ def build_get_url(image_id)
109
+ "#{config.host}/projects/#{config.project_id}/upload/images/#{image_id}"
99
110
  end
100
111
 
101
112
  def build_post_url
102
113
  "#{config.host}/projects/#{config.project_id}/upload/images/"
103
114
  end
104
115
 
105
- def build_put_url(name)
106
- "#{config.host}/projects/#{config.project_id}/upload/images/#{name}"
116
+ def build_put_url(image_id)
117
+ "#{config.host}/projects/#{config.project_id}/upload/images/#{image_id}"
118
+ end
119
+
120
+ def build_delete_url(image_id)
121
+ "#{config.host}/projects/#{config.project_id}/upload/images/#{image_id}"
107
122
  end
108
123
 
109
- def build_delete_url(name)
110
- "#{config.host}/projects/#{config.project_id}/upload/images/#{name}"
124
+ def build_metadata_url(image_id)
125
+ "#{config.host}/projects/#{config.project_id}/upload/images/#{image_id}/metadata"
111
126
  end
112
127
 
113
128
  def http_client
@@ -150,7 +165,18 @@ module Resizing
150
165
  raise APIError, "no response is returned" if response.nil?
151
166
 
152
167
  case response.status
153
- when HTTP_STATUS_OK, HTTP_STATUS_CREATED, HTTP_STATUS_NOT_FOUND
168
+ when HTTP_STATUS_OK, HTTP_STATUS_NOT_FOUND
169
+ JSON.parse(response.body)
170
+ else
171
+ raise APIError, "invalid http status code #{response.status}"
172
+ end
173
+ end
174
+
175
+ def handle_metadata_response(response)
176
+ raise APIError, "no response is returned" if response.nil?
177
+
178
+ case response.status
179
+ when HTTP_STATUS_OK, HTTP_STATUS_NOT_FOUND
154
180
  JSON.parse(response.body)
155
181
  else
156
182
  raise APIError, "invalid http status code #{response.status}"
@@ -69,9 +69,11 @@ module Resizing
69
69
  # たぶんここにおくものではない
70
70
  # もしくはキャッシュしない
71
71
  def generate_identifier
72
- @image_id ||= ::SecureRandom.uuid
72
+ "/projects/#{project_id}/upload/images/#{generate_image_id}"
73
+ end
73
74
 
74
- "/projects/#{project_id}/upload/images/#{@image_id}"
75
+ def generate_image_id
76
+ ::SecureRandom.uuid
75
77
  end
76
78
 
77
79
  def ==(other)
@@ -3,17 +3,37 @@
3
3
  module Resizing
4
4
  class MockClient
5
5
  def post(file_or_binary, options = {})
6
- load_yaml('test/vcr/client/post.yml')
6
+ r = load_yaml('test/vcr/client/post.yml')
7
+ JSON.parse(r['string'])
7
8
  end
8
9
 
9
10
  def put(name, file_or_binary, options)
10
- load_yaml('test/vcr/client/put.yml')
11
+ r = load_yaml('test/vcr/client/put.yml')
12
+ result = JSON.parse(r['string'])
13
+ # replace name, public_id and version by name argument
14
+ result['id'] = name
15
+ result['public_id'].gsub!(/AWEaewfAreaweFAFASfwe/, name)
16
+ result['public_id'].gsub!(/v6Ew3HmDAYfb3NMRdLxR45i_gXMbLlGyi/, "v#{Time.now.to_f}")
17
+ result
11
18
  end
12
19
 
13
20
  def delete(name)
14
- load_yaml('test/vcr/client/delete.yml')
21
+ r = load_yaml('test/vcr/client/delete.yml')
22
+ result = JSON.parse(r['string'])
23
+ # replace name and public_id by name argument
24
+ result['id'] = name
25
+ result['public_id'].gsub!(/28c49144-c00d-4cb5-8619-98ce95977b9c/, name)
26
+ result
15
27
  end
16
28
 
29
+ def metadata(name)
30
+ r = load_yaml('test/vcr/client/metadata.yml')
31
+ result = JSON.parse(r['string'])
32
+ # replace name and public_id by name argument
33
+ result['id'] = name
34
+ result['public_id'].gsub!(/bfdaf2b3-7ec5-41f4-9caa-d53247dd9666/, name)
35
+ result
36
+ end
17
37
  private
18
38
 
19
39
  def load_yaml filename
@@ -0,0 +1,50 @@
1
+ module Resizing
2
+ class PublicId
3
+ def initialize public_id
4
+ @public_id = public_id
5
+ parsed
6
+ end
7
+
8
+ def empty?
9
+ @public_id.to_s.empty?
10
+ end
11
+
12
+ def image_id
13
+ parsed[:image_id] if parsed
14
+ end
15
+
16
+ def project_id
17
+ parsed[:project_id] if parsed
18
+ end
19
+
20
+ def version
21
+ parsed[:version] if parsed
22
+ end
23
+
24
+ # temporary
25
+ def filename
26
+ image_id
27
+ end
28
+
29
+ def identifier
30
+ "/projects/#{project_id}/upload/images/#{image_id}"
31
+ end
32
+
33
+ def to_s
34
+ @public_id.to_s
35
+ end
36
+
37
+ private
38
+
39
+ def parsed
40
+ return nil if @public_id.nil?
41
+ unless defined? @parsed
42
+ @parsed = Resizing.separate_public_id(@public_id)
43
+ raise "type error #{@public_id}" if @parsed == nil
44
+ end
45
+ @parsed
46
+ end
47
+
48
+ private
49
+ end
50
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Resizing
4
- VERSION = '0.3.2'
4
+ VERSION = '0.4.0'
5
5
  end
@@ -6,6 +6,7 @@ module Resizing
6
6
  class CarrierWaveTest < Minitest::Test
7
7
  def setup
8
8
  TestModel.delete_all
9
+ TestJPGModel.delete_all
9
10
 
10
11
  @configuration_template = {
11
12
  host: 'http://192.168.56.101:5000',
@@ -20,7 +21,7 @@ module Resizing
20
21
  def teardown; end
21
22
 
22
23
  def test_remove_resizing_picture
23
- model = prepare_model
24
+ model = prepare_model TestModel
24
25
 
25
26
  VCR.use_cassette 'carrier_wave_test/remove_resizing_picture' do
26
27
  SecureRandom.stub :uuid, '28c49144-c00d-4cb5-8619-98ce95977b9c' do
@@ -32,7 +33,7 @@ module Resizing
32
33
  end
33
34
 
34
35
  def test_do_not_raise_if_empty_column_is_removed
35
- model = prepare_model
36
+ model = prepare_model TestModel
36
37
 
37
38
  VCR.use_cassette 'carrier_wave_test/remove_resizing_picture' do
38
39
  SecureRandom.stub :uuid, '28c49144-c00d-4cb5-8619-98ce95977b9c' do
@@ -42,23 +43,42 @@ module Resizing
42
43
  end
43
44
 
44
45
  def test_picture_url_return_correct_value_and_when_model_reloaded
45
- model = prepare_model
46
+ model = prepare_model TestModel
46
47
  model.save!
47
- assert_equal(expect_url, model.resizing_picture_url)
48
+ assert_equal("#{expect_url}/", model.resizing_picture_url)
48
49
 
49
50
  model.reload
50
- assert_equal(expect_url, model.resizing_picture_url)
51
+ assert_equal("#{expect_url}/", model.resizing_picture_url)
52
+ end
53
+
54
+ def test_picture_url_return_with_transform_strings
55
+ model = prepare_model TestModel
56
+ model.save!
57
+ assert_equal("#{expect_url}/c_fill,w_40,h_40", model.resizing_picture_url(:small))
58
+ end
59
+
60
+ def test_format_method_is_callable
61
+ model = prepare_model TestModel
62
+ model.save!
63
+ assert_nil model.resizing_picture.format
64
+ end
65
+
66
+ def test_format_method_is_return_jpg_with_overriden
67
+ model = prepare_model TestJPGModel
68
+ model.save!
69
+ model.resizing_picture.format
70
+ assert_equal('jpg', model.resizing_picture.format)
51
71
  end
52
72
 
53
73
  def expect_url
54
74
  'http://192.168.56.101:5000/projects/098a2a0d-c387-4135-a071-1254d6d7e70a/'+
55
- 'upload/images/28c49144-c00d-4cb5-8619-98ce95977b9c/v1Id850__tqNsnoGWWUibtIBZ5NgjV45M/c_limit,w_1000'
75
+ 'upload/images/28c49144-c00d-4cb5-8619-98ce95977b9c/v1Id850__tqNsnoGWWUibtIBZ5NgjV45M'
56
76
  end
57
77
 
58
- def prepare_model
78
+ def prepare_model model
59
79
  VCR.use_cassette 'carrier_wave_test/save' do
60
80
  SecureRandom.stub :uuid, '28c49144-c00d-4cb5-8619-98ce95977b9c' do
61
- model = TestModel.new
81
+ model = model.new
62
82
  file = File.open('test/data/images/sample1.jpg', 'r')
63
83
  uploaded_file = ActionDispatch::Http::UploadedFile.new(
64
84
  filename: File.basename(file.path),
@@ -19,7 +19,7 @@ module Resizing
19
19
  # NOP
20
20
  end
21
21
 
22
- def test_that_it_is_initialized
22
+ def test_is_initialized
23
23
  Resizing.configure = @configuration_template
24
24
 
25
25
  client = Resizing::Client.new
@@ -27,18 +27,18 @@ module Resizing
27
27
  assert_equal(client.config, Resizing.configure)
28
28
  end
29
29
 
30
- def test_that_it_is_initialized_with_configuration
30
+ def test_is_initialized_with_configuration
31
31
  config = Resizing::Configuration.new(@configuration_template)
32
32
  client = Resizing::Client.new(config)
33
33
  assert(!client.config.nil?)
34
34
  assert_equal(client.config, config)
35
35
  end
36
36
 
37
- def test_that_it_postable_file
37
+ def test_is_postable_file
38
38
  Resizing.configure = @configuration_template
39
39
 
40
40
  client = Resizing::Client.new
41
- VCR.use_cassette 'client/post' do
41
+ VCR.use_cassette 'client/post', record: :once do
42
42
  f = File.open('test/data/images/sample1.jpg', 'r')
43
43
  r = client.post(f, content_type: 'image/jpeg')
44
44
  assert_equal(r['id'], 'bfdaf2b3-7ec5-41f4-9caa-d53247dd9666')
@@ -52,11 +52,11 @@ module Resizing
52
52
  end
53
53
  end
54
54
 
55
- def test_that_it_putable_file
55
+ def test_is_putable_file
56
56
  Resizing.configure = @configuration_template
57
57
 
58
58
  client = Resizing::Client.new
59
- VCR.use_cassette 'client/put' do
59
+ VCR.use_cassette 'client/put', record: :once do
60
60
  f = File.open('test/data/images/sample1.jpg', 'r')
61
61
  name = 'AWEaewfAreaweFAFASfwe'
62
62
  r = client.put(name, f, content_type: 'image/jpeg')
@@ -73,5 +73,30 @@ module Resizing
73
73
  )
74
74
  end
75
75
  end
76
+
77
+ def test_get_the_metadata
78
+ # TODO
79
+
80
+ Resizing.configure = @configuration_template
81
+
82
+ client = Resizing::Client.new
83
+ VCR.use_cassette 'client/metadata', record: :once do
84
+ name = 'bfdaf2b3-7ec5-41f4-9caa-d53247dd9666'
85
+ r = client.metadata(name)
86
+ assert_equal(r['id'], name)
87
+ assert_equal(r['project_id'], Resizing.configure.project_id)
88
+ assert_equal(r['content_type'], 'image/jpeg')
89
+ assert(!r['latest_version_id'].nil?)
90
+ assert(!r['latest_etag'].nil?)
91
+ assert(!r['created_at'].nil?)
92
+ assert(!r['updated_at'].nil?)
93
+ assert(!r['height'].nil?)
94
+ assert(!r['width'].nil?)
95
+ assert_equal(
96
+ r['public_id'],
97
+ "/projects/098a2a0d-c387-4135-a071-1254d6d7e70a/upload/images/#{name}/v6Ew3HmDAYfb3NMRdLxR45i_gXMbLlGyi"
98
+ )
99
+ end
100
+ end
76
101
  end
77
102
  end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ module Resizing
6
+ class PublicIdTest < Minitest::Test
7
+ def setup
8
+ @project_id = '098a2a0d-c387-4135-a071-1254d6d7e70a'
9
+ @image_id = '28c49144-c00d-4cb5-8619-98ce95977b9c'
10
+ @version = '1Id850q34fgsaer23w'
11
+ @public_id_as_string = "/projects/#{@project_id}/upload/images/#{@image_id}/v#{@version}"
12
+ end
13
+
14
+ def teardown; end
15
+
16
+ def test_expect_equal_project_id
17
+ public_id = Resizing::PublicId.new @public_id_as_string
18
+ assert_equal @project_id, public_id.project_id
19
+ end
20
+
21
+ def test_expect_equal_image_id
22
+ public_id = Resizing::PublicId.new @public_id_as_string
23
+ assert_equal @image_id, public_id.image_id
24
+ end
25
+
26
+ def test_expect_equal_version
27
+ public_id = Resizing::PublicId.new @public_id_as_string
28
+ assert_equal @version, public_id.version
29
+ end
30
+
31
+ def test_expect_equal_identifier
32
+ public_id = Resizing::PublicId.new @public_id_as_string
33
+ assert_equal @public_id_as_string.gsub(/\/v.*$/, ''), public_id.identifier
34
+ end
35
+
36
+ def test_expect_equal_public_id
37
+ public_id = Resizing::PublicId.new @public_id_as_string
38
+ assert_equal @public_id_as_string, public_id.to_s
39
+ end
40
+ end
41
+ end
@@ -32,17 +32,35 @@ ActiveRecord::Base.establish_connection(
32
32
 
33
33
  ActiveRecord::Schema.define do
34
34
  self.verbose = false
35
- connection.execute 'drop table if exists test_models'
36
35
 
37
- create_table :test_models do |t|
38
- t.string :resizing_picture, null: true, default: nil
36
+ %i(test_models test_jpg_models).each do |model_name|
37
+ connection.execute "drop table if exists #{model_name}"
38
+
39
+ create_table model_name do |t|
40
+ t.string :resizing_picture, null: true, default: nil
41
+ end
39
42
  end
40
43
  end
41
44
 
42
45
  class ResizingUploader < CarrierWave::Uploader::Base
43
46
  include Resizing::CarrierWave
44
47
 
48
+ version :small do
49
+ process resize_to_fill: [40, 40]
50
+ end
51
+
52
+ process resize_to_limit: [1000]
53
+ end
54
+
55
+ class ResizingJPGUploader < CarrierWave::Uploader::Base
56
+ include Resizing::CarrierWave
57
+
45
58
  process resize_to_limit: [1000]
59
+
60
+ # override Resizing::CarrierWave#default_format
61
+ def default_format
62
+ 'jpg'
63
+ end
46
64
  end
47
65
 
48
66
  class TestModel < ::ActiveRecord::Base
@@ -50,3 +68,9 @@ class TestModel < ::ActiveRecord::Base
50
68
 
51
69
  mount_uploader :resizing_picture, ResizingUploader
52
70
  end
71
+
72
+ class TestJPGModel < ::ActiveRecord::Base
73
+ extend CarrierWave::Mount
74
+
75
+ mount_uploader :resizing_picture, ResizingJPGUploader
76
+ end
@@ -0,0 +1,49 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://192.168.56.101:5000/projects/098a2a0d-c387-4135-a071-1254d6d7e70a/upload/images/bfdaf2b3-7ec5-41f4-9caa-d53247dd9666/metadata
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v1.0.1
12
+ X-ResizingToken:
13
+ - v1,1600356576,4ba7fd9315775f99e73b109edcc72d79fd629d2335e3609ddd83d178936f6ba7
14
+ response:
15
+ status:
16
+ code: 200
17
+ message: OK
18
+ headers:
19
+ x-frame-options:
20
+ - SAMEORIGIN
21
+ x-xss-protection:
22
+ - 1; mode=block
23
+ x-content-type-options:
24
+ - nosniff
25
+ x-download-options:
26
+ - noopen
27
+ x-permitted-cross-domain-policies:
28
+ - none
29
+ referrer-policy:
30
+ - strict-origin-when-cross-origin
31
+ content-type:
32
+ - application/json; charset=utf-8
33
+ etag:
34
+ - W/"893e75186d2d771d47456ad4bb2394ae"
35
+ cache-control:
36
+ - max-age=0, private, must-revalidate
37
+ x-request-id:
38
+ - 18d0bbe0-110b-49fb-b055-75b93532735a
39
+ x-runtime:
40
+ - '0.649316'
41
+ connection:
42
+ - close
43
+ transfer-encoding:
44
+ - chunked
45
+ body:
46
+ encoding: UTF-8
47
+ string: '{"id":"bfdaf2b3-7ec5-41f4-9caa-d53247dd9666","project_id":"098a2a0d-c387-4135-a071-1254d6d7e70a","content_type":"image/jpeg","format":"jpeg","latest_version_id":"AyWaxx96gLaAzB9Bq.VbX1_pxfXJ0Jcq","latest_etag":"\"190143614e6c342637584f46f18f8c58\"","created_at":"2020-05-29T03:22:55.241Z","updated_at":"2020-05-29T03:22:55.241Z","public_id":"/projects/098a2a0d-c387-4135-a071-1254d6d7e70a/upload/images/bfdaf2b3-7ec5-41f4-9caa-d53247dd9666/v6Ew3HmDAYfb3NMRdLxR45i_gXMbLlGyi", "height": 200, "width": 200}'
48
+ recorded_at: Fri, 29 May 2020 03:22:55 GMT
49
+ 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: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Junichiro Kasuya
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-09-11 00:00:00.000000000 Z
11
+ date: 2020-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -203,6 +203,7 @@ files:
203
203
  - lib/resizing/client.rb
204
204
  - lib/resizing/configuration.rb
205
205
  - lib/resizing/mock_client.rb
206
+ - lib/resizing/public_id.rb
206
207
  - lib/resizing/version.rb
207
208
  - resizing.gemspec
208
209
  - test/data/images/sample1.jpg
@@ -211,11 +212,13 @@ files:
211
212
  - test/resizing/carrier_wave_test.rb
212
213
  - test/resizing/client_test.rb
213
214
  - test/resizing/configuration_test.rb
215
+ - test/resizing/public_id_test.rb
214
216
  - test/resizing_test.rb
215
217
  - test/test_helper.rb
216
218
  - test/vcr/carrier_wave_test/remove_resizing_picture.yml
217
219
  - test/vcr/carrier_wave_test/save.yml
218
220
  - test/vcr/client/delete.yml
221
+ - test/vcr/client/metadata.yml
219
222
  - test/vcr/client/post.yml
220
223
  - test/vcr/client/put.yml
221
224
  homepage: https://github.com/jksy/resizing-gem