Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
Admin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
osuny
Admin
Commits
20509d72
Unverified
Commit
20509d72
authored
3 years ago
by
Sébastien Gaya
Browse files
Options
Downloads
Patches
Plain Diff
variant service does not fail when format is missing
parent
3c387eba
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/services/variant_service.rb
+1
-1
1 addition, 1 deletion
app/services/variant_service.rb
test/models/variant_service_test.rb
+44
-0
44 additions, 0 deletions
test/models/variant_service_test.rb
with
45 additions
and
1 deletion
app/services/variant_service.rb
+
1
−
1
View file @
20509d72
...
...
@@ -55,7 +55,7 @@ class VariantService
end
end
transformations[:format] = @format if @format != @blob.filename.extension_without_delimiter
transformations[:format] = @format if
@format.present? &&
@format != @blob.filename.extension_without_delimiter
transformations
end
end
...
...
This diff is collapsed.
Click to expand it.
test/models/variant_service_test.rb
+
44
−
0
View file @
20509d72
...
...
@@ -31,6 +31,8 @@ class VariantServiceTest < ActiveSupport::TestCase
# dan-gold_1000x500_crop_left.jpeg
# dan-gold_1500x500_crop_left.jpeg
# dan-gold_800x840_crop_left.jpeg
# dan-gold
# dan-gold_500x500
# Params tests
...
...
@@ -155,6 +157,21 @@ class VariantServiceTest < ActiveSupport::TestCase
assert_equal expected_params, variant_service.params
end
test "params for dan-gold" do
blob = create_file_blob(filename: "dan-gold.jpeg")
expected_params = {}
variant_service = VariantService.compute(blob, 'dan-gold', nil)
assert_equal expected_params, variant_service.params
assert_nil variant_service.format
end
test "params for dan-gold_500x500" do
blob = create_file_blob(filename: "dan-gold.jpeg")
expected_params = { size: '500x500' }
variant_service = VariantService.compute(blob, 'dan-gold_500x500', nil)
assert_equal expected_params, variant_service.params
end
# Transformations tests
test "transformations for dan-gold.jpeg" do
...
...
@@ -291,6 +308,20 @@ class VariantServiceTest < ActiveSupport::TestCase
assert_equal expected_transformations, variant_service.transformations
end
test "transformations for dan-gold" do
blob = create_file_blob(filename: "dan-gold.jpeg")
expected_transformations = {}
variant_service = VariantService.compute(blob, 'dan-gold', nil)
assert_equal expected_transformations, variant_service.transformations
end
test "transformations for dan-gold_500x500" do
blob = create_file_blob(filename: "dan-gold.jpeg")
expected_transformations = { resize_to_limit: [500, 500] }
variant_service = VariantService.compute(blob, 'dan-gold_500x500', nil)
assert_equal expected_transformations, variant_service.transformations
end
# Variants tests
test "variant for dan-gold.webp" do
...
...
@@ -390,6 +421,19 @@ class VariantServiceTest < ActiveSupport::TestCase
assert_equal expected_blob.checksum, image_checksum(image)
end
test "variant for dan-gold" do
expected_blob = create_file_blob(filename: "dan-gold.jpeg")
image = load_image_from_variant_name(expected_blob.filename.base, format: nil)
assert_equal "JPEG", image.type
assert_equal expected_blob.checksum, image_checksum(image)
end
test "variant for dan-gold_500x500" do
expected_blob = create_file_blob(filename: "dan-gold_500x500.jpeg")
image = load_image_from_variant_name(expected_blob.filename.base, format: nil)
assert_equal expected_blob.checksum, image_checksum(image)
end
private
def create_file_blob(key: nil, filename: "dan-gold.jpeg", content_type: "image/jpeg", metadata: nil, service_name: nil, record: nil)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment