Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Remove `combine_options` from attachment#variant since is deprecated in rails 6.1

Damian Kaczmarczyka5fbc439513c
diff --git a/core/app/models/spree/image.rb b/core/app/models/spree/image.rb
index 61f3984f4c..629d77f5c0 100644
--- a/core/app/models/spree/image.rb
+++ b/core/app/models/spree/image.rb
@@ -15,13 +15,13 @@ module Spree
width, height = size.chop.split('x')
{
- url: polymorphic_path(attachment.variant(combine_options: {
- gravity: 'center',
- resize: size,
- extent: size,
- background: 'snow2',
- quality: 80
- }), only_path: true),
+ url: polymorphic_path(attachment.variant(
+ gravity: 'center',
+ resize: size,
+ extent: size,
+ background: 'snow2',
+ quality: 80
+ ), only_path: true),
width: width,
height: height
}
@@ -35,13 +35,13 @@ module Spree
width, height = size.chop.split('x')
{
- url: polymorphic_path(attachment.variant(combine_options: {
- gravity: 'center',
- resize: size,
- extent: size,
- background: 'snow2',
- quality: 80
- }), only_path: true),
+ url: polymorphic_path(attachment.variant(
+ gravity: 'center',
+ resize: size,
+ extent: size,
+ background: 'snow2',
+ quality: 80
+ ), only_path: true),
size: size,
width: width,
height: height
diff --git a/core/spec/models/spree/image_spec.rb b/core/spec/models/spree/image_spec.rb
index fd37c20c7c..5da7d45582 100644
--- a/core/spec/models/spree/image_spec.rb
+++ b/core/spec/models/spree/image_spec.rb
@@ -1,11 +1,11 @@
require 'spec_helper'
describe Spree::Image, type: :model do
- context 'validation' do
- let(:spree_image) { Spree::Image.new }
- let(:image_file) { File.open(Spree::Core::Engine.root + 'spec/fixtures' + 'thinking-cat.jpg') }
- let(:text_file) { File.open(Spree::Core::Engine.root + 'spec/fixtures' + 'text-file.txt') }
+ let(:spree_image) { described_class.new }
+ let(:image_file) { File.open("#{Spree::Core::Engine.root}/spec/fixtures/thinking-cat.jpg") }
+ let(:text_file) { File.open("#{Spree::Core::Engine.root}/spec/fixtures/text-file.txt") }
+ context 'validation' do
it 'has attachment present' do
spree_image.attachment.attach(io: image_file, filename: 'thinking-cat.jpg')
expect(spree_image).to be_valid
@@ -16,7 +16,7 @@ describe Spree::Image, type: :model do
expect(spree_image).not_to be_valid
end
- it 'has allowed attachment content type' do
+ it 'has allowed attachment content type' do
spree_image.attachment.attach(io: image_file, filename: 'thinking-cat.jpg', content_type: 'image/jpeg')
expect(spree_image).to be_valid
end
@@ -26,4 +26,24 @@ describe Spree::Image, type: :model do
expect(spree_image).not_to be_valid
end
end
+
+ describe '#styles' do
+ it 'will return all styles for the image' do
+ spree_image.attachment.attach(io: image_file, filename: 'thinking-cat.jpg', content_type: 'image/jpeg')
+ res = spree_image.styles
+
+ expect(res.length).to eq described_class.styles.keys.length
+ end
+ end
+
+ describe '#style' do
+ it 'will return style for the given name' do
+ spree_image.attachment.attach(io: image_file, filename: 'thinking-cat.jpg', content_type: 'image/jpeg')
+ styles = described_class.styles.keys
+ random_style_name = styles.sample
+ res = spree_image.style(random_style_name)
+
+ expect(res[:size]).to eq described_class.styles[random_style_name]
+ end
+ end
end