resizing 1.0.0.pre → 1.0.1
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 +61 -0
- data/Gemfile +4 -0
- data/lib/resizing/active_storage/service/resizing_service.rb +2 -0
- 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 +26 -15
- data/lib/resizing/carrier_wave/storage/remote.rb +7 -3
- data/lib/resizing/carrier_wave.rb +5 -3
- data/lib/resizing/client.rb +23 -24
- data/lib/resizing/version.rb +1 -1
- data/lib/resizing.rb +2 -0
- data/resizing.gemspec +6 -3
- 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 +63 -28
- data/test/resizing/client_test.rb +30 -1
- data/test/resizing/configurable_test.rb +82 -0
- data/test/resizing/configuration_test.rb +117 -0
- 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_module_test.rb +124 -0
- data/test/test_helper.rb +20 -0
- metadata +73 -22
- data/.circleci/config.yml +0 -73
- data/lib/resizing/video/client.rb +0 -116
- data/lib/resizing/video.rb +0 -8
- data/test/resizing/video/client_test.rb +0 -158
- data/test/vcr/video/metadata/success.yml +0 -47
- data/test/vcr/video/prepare/success.yml +0 -47
- data/test/vcr/video/upload_completed/success.yml +0 -47
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c8fa9990c253b1b932fb5b2c599aa93f045ad22dafbeef6e5b2d298f6fa1a59e
|
|
4
|
+
data.tar.gz: c58047443368aee638f48b0b4c899fcbd8a79b73c111655942ffa63ef73f9d74
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0d287c87564b117378394d19d4c5e5172afa056b1865ba9f4e54e4d9811aa70a88e6e70b5e76b720c06c5f6731d040350d08f4170a336e9bffc325f815de8ea9
|
|
7
|
+
data.tar.gz: 5b4a247eb8747d23632c65c078a338a8db3dfc5db9cceffce67845941dbf36386ac981f93f90203b155afdee39e14b156d5adc7dba5766710464ffd96bf0eb20
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
name: test
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
push:
|
|
6
|
+
branches:
|
|
7
|
+
- master
|
|
8
|
+
|
|
9
|
+
permissions:
|
|
10
|
+
id-token: write # This is required for requesting the JWT
|
|
11
|
+
contents: read # This is required for actions/checkout
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
test:
|
|
15
|
+
name: Ruby ${{ matrix.ruby }} / Rails ${{ matrix.rails }}
|
|
16
|
+
strategy:
|
|
17
|
+
fail-fast: false
|
|
18
|
+
matrix:
|
|
19
|
+
ruby: ['3.1']
|
|
20
|
+
rails: ['6.1', '7.0']
|
|
21
|
+
|
|
22
|
+
runs-on: ubuntu-22.04
|
|
23
|
+
|
|
24
|
+
env:
|
|
25
|
+
RAILS_VERSION: ${{ matrix.rails }}
|
|
26
|
+
|
|
27
|
+
steps:
|
|
28
|
+
- uses: actions/checkout@v4
|
|
29
|
+
|
|
30
|
+
- uses: mirromutth/mysql-action@v1.1
|
|
31
|
+
with:
|
|
32
|
+
host port: 3306
|
|
33
|
+
container port: 3306
|
|
34
|
+
character set server: 'utf8mb4'
|
|
35
|
+
collation server: 'utf8mb4_general_ci'
|
|
36
|
+
mysql version: '5.7'
|
|
37
|
+
mysql database: 'resizing_gem_test'
|
|
38
|
+
mysql root password: secret
|
|
39
|
+
|
|
40
|
+
- name: "Install ruby dependencies"
|
|
41
|
+
run: |
|
|
42
|
+
sudo apt update
|
|
43
|
+
sudo apt install -y libyaml-dev curl libmysqlclient-dev
|
|
44
|
+
|
|
45
|
+
- uses: ruby/setup-ruby@v1
|
|
46
|
+
with:
|
|
47
|
+
ruby-version: ${{ matrix.ruby }}
|
|
48
|
+
bundler-cache: false
|
|
49
|
+
|
|
50
|
+
- name: bundle install
|
|
51
|
+
run: |
|
|
52
|
+
bundle install
|
|
53
|
+
|
|
54
|
+
- name: Run test
|
|
55
|
+
run: |
|
|
56
|
+
bundle exec rake test
|
|
57
|
+
|
|
58
|
+
- name: Upload coverage reports to Codecov
|
|
59
|
+
uses: codecov/codecov-action@v3
|
|
60
|
+
env:
|
|
61
|
+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
|
data/Gemfile
CHANGED
|
@@ -5,6 +5,10 @@ source 'https://rubygems.org'
|
|
|
5
5
|
# Specify your gem's dependencies in resizing.gemspec
|
|
6
6
|
gemspec
|
|
7
7
|
|
|
8
|
+
# Allow testing against different Rails versions
|
|
9
|
+
rails_version = ENV['RAILS_VERSION'] || '7.0'
|
|
10
|
+
gem 'rails', "~> #{rails_version}"
|
|
11
|
+
|
|
8
12
|
gem 'rake', '~> 13.0'
|
|
9
13
|
gem 'github_changelog_generator'
|
|
10
14
|
gem 'mysql2'
|
|
@@ -29,9 +29,22 @@ module Resizing
|
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
def delete
|
|
32
|
-
|
|
32
|
+
# Use the identifier from constructor if available, otherwise try to get from model
|
|
33
|
+
if @public_id.present?
|
|
34
|
+
# Already set from constructor or retrieve
|
|
35
|
+
elsif model.respond_to?(:attribute_was)
|
|
36
|
+
# Try to get the value before changes (for remove! scenario)
|
|
37
|
+
column_value = model.attribute_was(serialization_column) || model.send(:read_attribute,
|
|
38
|
+
serialization_column)
|
|
39
|
+
@public_id = Resizing::PublicId.new(column_value)
|
|
40
|
+
else
|
|
41
|
+
column_value = model.send(:read_attribute, serialization_column)
|
|
42
|
+
@public_id = Resizing::PublicId.new(column_value)
|
|
43
|
+
end
|
|
44
|
+
|
|
33
45
|
return if @public_id.empty? # do nothing
|
|
34
46
|
|
|
47
|
+
# 以下、既存のコード(変更なし)
|
|
35
48
|
resp = client.delete(@public_id.image_id)
|
|
36
49
|
if resp['error'] == 'ActiveRecord::RecordNotFound' # 404 not found
|
|
37
50
|
model.send :write_attribute, serialization_column, nil unless model.destroyed?
|
|
@@ -89,24 +102,22 @@ module Resizing
|
|
|
89
102
|
raise NotImplementedError, 'new file is required duplicating'
|
|
90
103
|
end
|
|
91
104
|
|
|
92
|
-
if new_file.respond_to? :content_type
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
105
|
+
@content_type ||= if new_file.respond_to? :content_type
|
|
106
|
+
new_file.content_type
|
|
107
|
+
else
|
|
108
|
+
# guess content-type from extension
|
|
109
|
+
MIME::Types.type_for(new_file.path).first.content_type
|
|
110
|
+
end
|
|
98
111
|
|
|
99
112
|
original_filename = new_file.try(:original_filename) || new_file.try(:filename) || new_file.try(:path)
|
|
100
|
-
if original_filename.present?
|
|
101
|
-
original_filename = ::File.basename(original_filename)
|
|
102
|
-
end
|
|
113
|
+
original_filename = ::File.basename(original_filename) if original_filename.present?
|
|
103
114
|
|
|
104
115
|
content = if new_file.respond_to?(:to_io)
|
|
105
116
|
new_file.to_io.tap(&:rewind)
|
|
106
117
|
elsif new_file.respond_to?(:read) && new_file.respond_to?(:rewind)
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
118
|
+
# Pass the IO object itself, not the read result
|
|
119
|
+
new_file.rewind
|
|
120
|
+
new_file
|
|
110
121
|
else
|
|
111
122
|
new_file
|
|
112
123
|
end
|
|
@@ -127,7 +138,7 @@ module Resizing
|
|
|
127
138
|
end
|
|
128
139
|
|
|
129
140
|
def name(options = {})
|
|
130
|
-
@public_id = PublicId.new(model.send
|
|
141
|
+
@public_id = PublicId.new(model.send(:read_attribute, serialization_column))
|
|
131
142
|
CGI.unescape(@public_id.filename)
|
|
132
143
|
end
|
|
133
144
|
|
|
@@ -138,6 +149,7 @@ module Resizing
|
|
|
138
149
|
def retrieve(identifier)
|
|
139
150
|
@public_id = Resizing::PublicId.new(identifier)
|
|
140
151
|
end
|
|
152
|
+
|
|
141
153
|
private
|
|
142
154
|
|
|
143
155
|
attr_reader :uploader
|
|
@@ -195,7 +207,6 @@ module Resizing
|
|
|
195
207
|
parameters.count == 2 && parameters[1].include?(:options)
|
|
196
208
|
end
|
|
197
209
|
|
|
198
|
-
|
|
199
210
|
# def retrieve_from_cache!(identifier)
|
|
200
211
|
# raise NotImplementedError,
|
|
201
212
|
# "Need to implement #retrieve_from_cache! if you want to use #{self.class.name} as a cache storage."
|
|
@@ -18,9 +18,13 @@ module Resizing
|
|
|
18
18
|
f
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
def retrieve!(identifier)
|
|
22
|
+
return nil if identifier.blank?
|
|
23
|
+
|
|
24
|
+
f = Resizing::CarrierWave::Storage::File.new(uploader, identifier)
|
|
25
|
+
f.retrieve(identifier)
|
|
26
|
+
f
|
|
27
|
+
end
|
|
24
28
|
|
|
25
29
|
def cache!(new_file)
|
|
26
30
|
f = Resizing::CarrierWave::Storage::File.new(uploader)
|
|
@@ -32,11 +32,12 @@ module Resizing
|
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
def file
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
file_identifier = identifier || read_column
|
|
36
|
+
|
|
37
|
+
return nil if file_identifier.blank?
|
|
37
38
|
|
|
38
39
|
@file ||= Resizing::CarrierWave::Storage::File.new(self)
|
|
39
|
-
@file.retrieve(
|
|
40
|
+
@file.retrieve(file_identifier)
|
|
40
41
|
@file
|
|
41
42
|
end
|
|
42
43
|
|
|
@@ -46,6 +47,7 @@ module Resizing
|
|
|
46
47
|
transforms = args.map do |version|
|
|
47
48
|
version = version.intern
|
|
48
49
|
raise "No version is found: #{version}, #{versions.keys} are exists." unless versions.has_key? version
|
|
50
|
+
|
|
49
51
|
versions[version].transform_string
|
|
50
52
|
end.compact
|
|
51
53
|
|
data/lib/resizing/client.rb
CHANGED
|
@@ -37,16 +37,14 @@ module Resizing
|
|
|
37
37
|
raise NotImplementedError
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
-
def post(
|
|
40
|
+
def post(filename_or_io, options = {})
|
|
41
41
|
ensure_content_type(options)
|
|
42
|
+
ensure_filename_or_io(filename_or_io)
|
|
43
|
+
filename = gather_filename filename_or_io, options
|
|
42
44
|
|
|
43
45
|
url = build_post_url
|
|
44
|
-
|
|
45
|
-
filename = gather_filename file_or_binary, options
|
|
46
|
-
|
|
47
|
-
body = to_io(file_or_binary)
|
|
48
46
|
params = {
|
|
49
|
-
image: Faraday::
|
|
47
|
+
image: Faraday::Multipart::FilePart.new(filename_or_io, options[:content_type], filename)
|
|
50
48
|
}
|
|
51
49
|
|
|
52
50
|
response = handle_faraday_error do
|
|
@@ -59,16 +57,14 @@ module Resizing
|
|
|
59
57
|
result
|
|
60
58
|
end
|
|
61
59
|
|
|
62
|
-
def put(image_id,
|
|
60
|
+
def put(image_id, filename_or_io, options)
|
|
63
61
|
ensure_content_type(options)
|
|
62
|
+
ensure_filename_or_io(filename_or_io)
|
|
63
|
+
filename = gather_filename filename_or_io, options
|
|
64
64
|
|
|
65
65
|
url = build_put_url(image_id)
|
|
66
|
-
|
|
67
|
-
filename = gather_filename file_or_binary, options
|
|
68
|
-
|
|
69
|
-
body = to_io(file_or_binary)
|
|
70
66
|
params = {
|
|
71
|
-
image: Faraday::
|
|
67
|
+
image: Faraday::Multipart::FilePart.new(filename_or_io, options[:content_type], filename)
|
|
72
68
|
}
|
|
73
69
|
|
|
74
70
|
response = handle_faraday_error do
|
|
@@ -117,9 +113,9 @@ module Resizing
|
|
|
117
113
|
"#{config.image_host}/projects/#{config.project_id}/upload/images/"
|
|
118
114
|
end
|
|
119
115
|
|
|
120
|
-
def gather_filename
|
|
116
|
+
def gather_filename(filename_or_io, options)
|
|
121
117
|
filename = options[:filename]
|
|
122
|
-
filename ||=
|
|
118
|
+
filename ||= filename_or_io.respond_to?(:path) ? File.basename(filename_or_io.path) : nil
|
|
123
119
|
end
|
|
124
120
|
|
|
125
121
|
def build_put_url(image_id)
|
|
@@ -134,20 +130,23 @@ module Resizing
|
|
|
134
130
|
"#{config.image_host}/projects/#{config.project_id}/upload/images/#{image_id}/metadata"
|
|
135
131
|
end
|
|
136
132
|
|
|
133
|
+
def ensure_content_type(options)
|
|
134
|
+
raise ArgumentError, "need options[:content_type] for #{options.inspect}" unless options[:content_type]
|
|
135
|
+
end
|
|
137
136
|
|
|
138
|
-
def
|
|
139
|
-
return
|
|
137
|
+
def ensure_filename_or_io(filename_or_io)
|
|
138
|
+
return if filename_or_io.is_a?(File)
|
|
140
139
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
140
|
+
# Accept IO-like objects (StringIO, Tempfile, etc.)
|
|
141
|
+
return if filename_or_io.respond_to?(:read) && filename_or_io.respond_to?(:rewind)
|
|
142
|
+
|
|
143
|
+
if filename_or_io.is_a?(String)
|
|
144
|
+
if File.exist?(filename_or_io)
|
|
145
|
+
return
|
|
146
|
+
end
|
|
146
147
|
end
|
|
147
|
-
end
|
|
148
148
|
|
|
149
|
-
|
|
150
|
-
raise ArgumentError, "need options[:content_type] for #{options.inspect}" unless options[:content_type]
|
|
149
|
+
raise ArgumentError, "filename_or_io must be a File object, an IO-like object, or a path to a file (#{filename_or_io.class})"
|
|
151
150
|
end
|
|
152
151
|
|
|
153
152
|
def handle_create_response(response)
|
data/lib/resizing/version.rb
CHANGED
data/lib/resizing.rb
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require 'resizing/version'
|
|
4
4
|
require 'faraday'
|
|
5
|
+
require 'faraday/multipart'
|
|
5
6
|
require 'json'
|
|
6
7
|
|
|
7
8
|
module Resizing
|
|
@@ -14,6 +15,7 @@ module Resizing
|
|
|
14
15
|
autoload :CarrierWave, 'resizing/carrier_wave'
|
|
15
16
|
autoload :PublicId, 'resizing/public_id'
|
|
16
17
|
autoload :Video, 'resizing/video'
|
|
18
|
+
autoload :ActiveStorage, 'resizing/active_storage'
|
|
17
19
|
|
|
18
20
|
class Error < StandardError; end
|
|
19
21
|
class ConfigurationError < Error; end
|
data/resizing.gemspec
CHANGED
|
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
|
|
|
12
12
|
spec.description = 'Client and utilities for Resizing '
|
|
13
13
|
spec.homepage = 'https://github.com/jksy/resizing-gem'
|
|
14
14
|
spec.license = 'MIT'
|
|
15
|
-
spec.required_ruby_version = Gem::Requirement.new('>=
|
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 3.0.0')
|
|
16
16
|
|
|
17
17
|
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
|
18
18
|
|
|
@@ -29,12 +29,15 @@ Gem::Specification.new do |spec|
|
|
|
29
29
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
30
30
|
spec.require_paths = ['lib']
|
|
31
31
|
spec.add_runtime_dependency 'faraday', '~> 1.0'
|
|
32
|
-
spec.add_development_dependency 'rails',
|
|
32
|
+
spec.add_development_dependency 'rails', ">= 6.0", '< 7.1'
|
|
33
33
|
spec.add_development_dependency 'carrierwave', '~> 1.3.2'
|
|
34
34
|
spec.add_development_dependency 'fog-aws'
|
|
35
|
-
spec.add_development_dependency 'minitest'
|
|
35
|
+
spec.add_development_dependency 'minitest', '~> 5.16'
|
|
36
36
|
spec.add_development_dependency 'minitest-ci'
|
|
37
37
|
spec.add_development_dependency 'rubocop'
|
|
38
38
|
spec.add_development_dependency 'timecop'
|
|
39
39
|
spec.add_development_dependency 'vcr'
|
|
40
|
+
spec.add_development_dependency 'mysql2'
|
|
41
|
+
spec.add_development_dependency 'simplecov'
|
|
42
|
+
spec.add_development_dependency 'simplecov-cobertura'
|
|
40
43
|
end
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'test_helper'
|
|
4
|
+
|
|
5
|
+
module Resizing
|
|
6
|
+
module ActiveStorage
|
|
7
|
+
module Service
|
|
8
|
+
class ResizingServiceTest < Minitest::Test
|
|
9
|
+
def setup
|
|
10
|
+
@service = Resizing::ActiveStorage::Service::ResizingService.new
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def teardown
|
|
14
|
+
# NOP
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def test_service_initialization
|
|
18
|
+
assert_instance_of Resizing::ActiveStorage::Service::ResizingService, @service
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def test_upload_raises_not_implemented_error
|
|
22
|
+
assert_raises NotImplementedError do
|
|
23
|
+
@service.upload('test_key', StringIO.new('test data'))
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_download_raises_not_implemented_error
|
|
28
|
+
assert_raises NotImplementedError do
|
|
29
|
+
@service.download('test_key')
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_download_chunk_raises_not_implemented_error
|
|
34
|
+
assert_raises NotImplementedError do
|
|
35
|
+
@service.download_chunk('test_key', 0..99)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def test_delete_raises_not_implemented_error
|
|
40
|
+
assert_raises NotImplementedError do
|
|
41
|
+
@service.delete('test_key')
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def test_exist_raises_not_implemented_error
|
|
46
|
+
assert_raises NotImplementedError do
|
|
47
|
+
@service.exist?('test_key')
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def test_url_for_direct_upload_raises_not_implemented_error
|
|
52
|
+
assert_raises NotImplementedError do
|
|
53
|
+
@service.url_for_direct_upload(
|
|
54
|
+
'test_key',
|
|
55
|
+
expires_in: 3600,
|
|
56
|
+
content_type: 'image/png',
|
|
57
|
+
conteont_length: 1024,
|
|
58
|
+
checksum: 'test_checksum'
|
|
59
|
+
)
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def test_headers_for_direct_upload_raises_not_implemented_error
|
|
64
|
+
assert_raises NotImplementedError do
|
|
65
|
+
@service.headers_for_direct_upload(
|
|
66
|
+
'test_key',
|
|
67
|
+
content_type: 'image/png',
|
|
68
|
+
checksum: 'test_checksum'
|
|
69
|
+
)
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def test_private_url_raises_not_implemented_error
|
|
74
|
+
assert_raises NotImplementedError do
|
|
75
|
+
@service.send(
|
|
76
|
+
:private_url,
|
|
77
|
+
'test_key',
|
|
78
|
+
expires_in: 3600,
|
|
79
|
+
filename: 'test.png',
|
|
80
|
+
content_type: 'image/png',
|
|
81
|
+
disposition: :attachment
|
|
82
|
+
)
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def test_public_url_raises_not_implemented_error
|
|
87
|
+
assert_raises NotImplementedError do
|
|
88
|
+
@service.send(
|
|
89
|
+
:public_url,
|
|
90
|
+
'test_key',
|
|
91
|
+
filename: 'test.png'
|
|
92
|
+
)
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
@@ -7,22 +7,163 @@ module Resizing
|
|
|
7
7
|
module Storage
|
|
8
8
|
class FileTest < Minitest::Test
|
|
9
9
|
def setup
|
|
10
|
-
|
|
10
|
+
@configuration_template = {
|
|
11
|
+
image_host: 'http://192.168.56.101:5000',
|
|
12
|
+
video_host: 'http://192.168.56.101:5000',
|
|
13
|
+
project_id: 'e06e710d-f026-4dcf-b2c0-eab0de8bb83f',
|
|
14
|
+
secret_token: 'ewbym2r1pk49x1d2lxdbiiavnqp25j2kh00hsg3koy0ppm620x5mhlmgl3rq5ci8',
|
|
15
|
+
open_timeout: 10,
|
|
16
|
+
response_timeout: 20
|
|
17
|
+
}
|
|
18
|
+
Resizing.configure = @configuration_template
|
|
11
19
|
end
|
|
12
20
|
|
|
13
21
|
def teardown
|
|
14
22
|
# NOP
|
|
15
23
|
end
|
|
16
24
|
|
|
17
|
-
def
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
25
|
+
def test_initialize_without_identifier
|
|
26
|
+
model = TestModel.new
|
|
27
|
+
uploader = model.resizing_picture
|
|
28
|
+
file = Resizing::CarrierWave::Storage::File.new(uploader)
|
|
29
|
+
|
|
30
|
+
assert_instance_of Resizing::CarrierWave::Storage::File, file
|
|
31
|
+
assert file.public_id.empty?
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def test_initialize_with_identifier
|
|
35
|
+
model = TestModel.new
|
|
36
|
+
uploader = model.resizing_picture
|
|
37
|
+
identifier = '/projects/e06e710d-f026-4dcf-b2c0-eab0de8bb83f/upload/images/14ea7aac-a194-4330-931f-6b562aec413d/v_8c5lEhDB5RT3PZp1Fn5PYGm9YVx_x0e'
|
|
38
|
+
file = Resizing::CarrierWave::Storage::File.new(uploader, identifier)
|
|
39
|
+
|
|
40
|
+
assert_instance_of Resizing::CarrierWave::Storage::File, file
|
|
41
|
+
assert_equal identifier, file.public_id.to_s
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def test_retrieve_sets_public_id
|
|
45
|
+
model = TestModel.new
|
|
46
|
+
uploader = model.resizing_picture
|
|
47
|
+
file = Resizing::CarrierWave::Storage::File.new(uploader)
|
|
48
|
+
identifier = '/projects/e06e710d-f026-4dcf-b2c0-eab0de8bb83f/upload/images/14ea7aac-a194-4330-931f-6b562aec413d/v_8c5lEhDB5RT3PZp1Fn5PYGm9YVx_x0e'
|
|
49
|
+
|
|
50
|
+
file.retrieve(identifier)
|
|
51
|
+
|
|
52
|
+
assert_equal identifier, file.public_id.to_s
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def test_delete_does_nothing_when_public_id_empty
|
|
56
|
+
model = TestModel.new
|
|
57
|
+
uploader = model.resizing_picture
|
|
58
|
+
file = Resizing::CarrierWave::Storage::File.new(uploader)
|
|
59
|
+
|
|
60
|
+
# Should not raise any error and should return early
|
|
61
|
+
result = file.delete
|
|
62
|
+
assert_nil result
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def test_current_path_returns_nil_for_new_model
|
|
66
|
+
model = TestModel.new
|
|
67
|
+
uploader = model.resizing_picture
|
|
68
|
+
file = Resizing::CarrierWave::Storage::File.new(uploader)
|
|
69
|
+
|
|
70
|
+
assert_nil file.current_path
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def test_path_alias
|
|
74
|
+
model = TestModel.new
|
|
75
|
+
uploader = model.resizing_picture
|
|
76
|
+
file = Resizing::CarrierWave::Storage::File.new(uploader)
|
|
77
|
+
|
|
78
|
+
assert_nil file.current_path
|
|
79
|
+
assert_nil file.path
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def test_authenticated_url_returns_nil
|
|
83
|
+
model = TestModel.new
|
|
84
|
+
uploader = model.resizing_picture
|
|
85
|
+
file = Resizing::CarrierWave::Storage::File.new(uploader)
|
|
86
|
+
|
|
87
|
+
assert_nil file.authenticated_url
|
|
22
88
|
end
|
|
23
89
|
|
|
24
|
-
def
|
|
25
|
-
|
|
90
|
+
def test_authenticated_url_with_options_returns_nil
|
|
91
|
+
model = TestModel.new
|
|
92
|
+
uploader = model.resizing_picture
|
|
93
|
+
file = Resizing::CarrierWave::Storage::File.new(uploader)
|
|
94
|
+
|
|
95
|
+
assert_nil file.authenticated_url(expires_in: 3600)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def test_extension_raises_not_implemented_error
|
|
99
|
+
model = TestModel.new
|
|
100
|
+
uploader = model.resizing_picture
|
|
101
|
+
file = Resizing::CarrierWave::Storage::File.new(uploader)
|
|
102
|
+
|
|
103
|
+
assert_raises(NotImplementedError) do
|
|
104
|
+
file.extension
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def test_name_returns_image_id_from_public_id
|
|
109
|
+
model = TestModel.new
|
|
110
|
+
identifier = '/projects/e06e710d-f026-4dcf-b2c0-eab0de8bb83f/upload/images/14ea7aac-a194-4330-931f-6b562aec413d/v_8c5lEhDB5RT3PZp1Fn5PYGm9YVx_x0e'
|
|
111
|
+
# Use write_attribute to set the column directly
|
|
112
|
+
model.send(:write_attribute, :resizing_picture, identifier)
|
|
113
|
+
uploader = model.resizing_picture
|
|
114
|
+
file = Resizing::CarrierWave::Storage::File.new(uploader, identifier)
|
|
115
|
+
|
|
116
|
+
# name returns image_id (UUID) from public_id
|
|
117
|
+
assert_equal '14ea7aac-a194-4330-931f-6b562aec413d', file.name
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def test_store_uploads_file_and_sets_public_id
|
|
121
|
+
VCR.use_cassette 'carrier_wave_test/save', record: :once do
|
|
122
|
+
model = TestModel.new
|
|
123
|
+
uploader = model.resizing_picture
|
|
124
|
+
file = Resizing::CarrierWave::Storage::File.new(uploader)
|
|
125
|
+
|
|
126
|
+
source_file = ::File.open('test/data/images/sample1.jpg', 'r')
|
|
127
|
+
uploaded_file = ActionDispatch::Http::UploadedFile.new(
|
|
128
|
+
filename: ::File.basename(source_file.path),
|
|
129
|
+
type: 'image/jpeg',
|
|
130
|
+
tempfile: source_file
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
result = file.store(uploaded_file)
|
|
134
|
+
|
|
135
|
+
assert result
|
|
136
|
+
refute file.public_id.empty?
|
|
137
|
+
assert_equal 'image/jpeg', file.content_type
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def test_store_with_file_object
|
|
142
|
+
VCR.use_cassette 'carrier_wave_test/save', record: :once do
|
|
143
|
+
model = TestModel.new
|
|
144
|
+
uploader = model.resizing_picture
|
|
145
|
+
file = Resizing::CarrierWave::Storage::File.new(uploader)
|
|
146
|
+
|
|
147
|
+
source_file = ::File.open('test/data/images/sample1.jpg', 'r')
|
|
148
|
+
|
|
149
|
+
result = file.store(source_file)
|
|
150
|
+
|
|
151
|
+
assert result
|
|
152
|
+
refute file.public_id.empty?
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
def test_delete_with_valid_public_id
|
|
157
|
+
VCR.use_cassette 'carrier_wave_test/remove_resizing_picture' do
|
|
158
|
+
model = TestModel.new
|
|
159
|
+
identifier = '/projects/e06e710d-f026-4dcf-b2c0-eab0de8bb83f/upload/images/14ea7aac-a194-4330-931f-6b562aec413d/v_8c5lEhDB5RT3PZp1Fn5PYGm9YVx_x0e'
|
|
160
|
+
model.send(:write_attribute, :resizing_picture, identifier)
|
|
161
|
+
uploader = model.resizing_picture
|
|
162
|
+
file = Resizing::CarrierWave::Storage::File.new(uploader, identifier)
|
|
163
|
+
|
|
164
|
+
# This should call delete on Resizing API
|
|
165
|
+
file.delete
|
|
166
|
+
end
|
|
26
167
|
end
|
|
27
168
|
end
|
|
28
169
|
end
|