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.

add specs

Łukasz Adamczyk9d8188341cf4
diff --git a/core/app/models/spree/store.rb b/core/app/models/spree/store.rb
index 0227ac747f..e623c2e87e 100644
--- a/core/app/models/spree/store.rb
+++ b/core/app/models/spree/store.rb
@@ -95,9 +95,8 @@ module Spree
def favicon
return Config[:favicon] unless favicon_image.attached?
- return favicon_image.variant(resize: '32x32') if favicon_image.variable?
- favicon_image
+ favicon_image.variant(resize: '32x32')
end
private
diff --git a/core/lib/spree/testing_support/factories/store_factory.rb b/core/lib/spree/testing_support/factories/store_factory.rb
index 8f6f8126d4..b165e6fcc1 100644
--- a/core/lib/spree/testing_support/factories/store_factory.rb
+++ b/core/lib/spree/testing_support/factories/store_factory.rb
@@ -12,5 +12,14 @@ FactoryBot.define do
facebook { 'spreecommerce' }
twitter { 'spreecommerce' }
instagram { 'spreecommerce' }
+
+ trait :with_favicon do
+ favicon_image do
+ Rack::Test::UploadedFile.new(
+ Spree::Core::Engine.root.join('spec', 'fixtures', 'favicon.ico'),
+ 'image/x-icon'
+ )
+ end
+ end
end
end
diff --git a/core/spec/fixtures/favicon.ico b/core/spec/fixtures/favicon.ico
new file mode 100644
index 0000000000..b5b89e3563
Binary files /dev/null and b/core/spec/fixtures/favicon.ico differ
diff --git a/core/spec/helpers/base_helper_spec.rb b/core/spec/helpers/base_helper_spec.rb
index 38267788cd..9c17931e45 100644
--- a/core/spec/helpers/base_helper_spec.rb
+++ b/core/spec/helpers/base_helper_spec.rb
@@ -326,4 +326,13 @@ describe Spree::BaseHelper, type: :helper do
end
end
end
+
+ describe '#favicon_path' do
+ let(:current_store) { create(:store, :with_favicon) }
+
+ it do
+ expect(favicon_path).to end_with('favicon.ico')
+ expect(URI.parse(favicon_path).host).to be_present
+ end
+ end
end
diff --git a/core/spec/models/spree/store_spec.rb b/core/spec/models/spree/store_spec.rb
index 2233798d44..19a18fb0ac 100644
--- a/core/spec/models/spree/store_spec.rb
+++ b/core/spec/models/spree/store_spec.rb
@@ -313,4 +313,26 @@ describe Spree::Store, type: :model do
it { expect { store.save! }.not_to change(store, :supported_currencies) }
end
end
+
+ describe '#favicon' do
+ subject(:favicon) { store.favicon }
+
+ context 'with an attached favicon image' do
+ let(:store) { create(:store, :with_favicon) }
+ let(:favicon_variation) { favicon.processed.variation }
+
+ it 'returns a resized favicon' do
+ expect(favicon_variation).to be_present
+ expect(favicon_variation.transformations.fetch(:resize)).to eq('32x32')
+ end
+ end
+
+ context 'without an attached favicon image' do
+ let(:store) { create(:store) }
+
+ it 'returns a default favicon' do
+ expect(favicon).to eq('favicon.ico')
+ end
+ end
+ end
end