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.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
* refactor uploading a store's favicon * extract accepted content types for Store#favicon and Store#mailer_logo * add missing specs
Łukasz Adamczyka0f0d38a000e
diff --git a/backend/app/controllers/spree/admin/stores_controller.rb b/backend/app/controllers/spree/admin/stores_controller.rbindex 682cdf499f..23c9bcea4b 100644--- a/backend/app/controllers/spree/admin/stores_controller.rb+++ b/backend/app/controllers/spree/admin/stores_controller.rb@@ -58,7 +58,7 @@ module Spreeredirect_to admin_stores_pathelseflash[:error] = "#{Spree.t('store_errors.unable_to_update')}: #{@store.errors.full_messages.join(', ')}"- redirect_to edit_admin_store_path(@store)+ redirect_to spree.edit_admin_store_path(@store)endenddiff --git a/backend/app/views/spree/admin/stores/_form.html.erb b/backend/app/views/spree/admin/stores/_form.html.erbindex 4594c54e48..77f8330a4a 100644--- a/backend/app/views/spree/admin/stores/_form.html.erb+++ b/backend/app/views/spree/admin/stores/_form.html.erb@@ -25,7 +25,7 @@<% end %><%= f.field_container :mailer_logo, class: ['form-group'] do %><%= f.label :mailer_logo, Spree.t(:mailer_logo) %><br>- <%= f.file_field :mailer_logo, accept: 'image/png, image/jpeg' %>+ <%= f.file_field :mailer_logo, accept: Spree::Store::MAILER_LOGO_CONTENT_TYPES.join(',') %><%= f.error_message_on :mailer_logo %><% end %><% end %>@@ -35,7 +35,7 @@<% end %><%= f.field_container :favicon_image, class: ['form-group'] do %><%= f.label :favicon_image, Spree.t(:favicon) %><br>- <%= f.file_field :favicon_image, accept: 'image/png, image/x-icon' %>+ <%= f.file_field :favicon_image, accept: Spree::Store::FAVICON_CONTENT_TYPES.join(',') %><%= f.error_message_on :favicon_image %><% end %><% end %>diff --git a/backend/spec/features/admin/configuration/stores_spec.rb b/backend/spec/features/admin/configuration/stores_spec.rbindex bb30d6bf25..0d3df7d888 100644--- a/backend/spec/features/admin/configuration/stores_spec.rb+++ b/backend/spec/features/admin/configuration/stores_spec.rb@@ -151,6 +151,18 @@ describe 'Stores admin', type: :feature, js: true dostore.reloadexpect(store.new_order_notifications_email).to eq(store_owner_email)end++ it 'allows uploading a favicon' do+ visit spree.admin_stores_path++ within_row(1) { click_icon :edit }+ attach_file('Favicon', file_fixture('favicon.ico'))++ click_on 'Update'++ expect(page).to have_content('Store "Spree Test Store" has been successfully updated!')+ expect(store.reload.favicon_image.attached?).to be(true)+ endenddescribe 'deleting store' dodiff --git a/backend/spec/fixtures/files/favicon.ico b/backend/spec/fixtures/files/favicon.iconew file mode 100644index 0000000000..b5b89e3563Binary files /dev/null and b/backend/spec/fixtures/files/favicon.ico differdiff --git a/core/app/helpers/spree/base_helper.rb b/core/app/helpers/spree/base_helper.rbindex 61ace403d6..5a478cb62d 100644--- a/core/app/helpers/spree/base_helper.rb+++ b/core/app/helpers/spree/base_helper.rb@@ -61,7 +61,7 @@ module Spreeenddef favicon_path- main_app.url_for(current_store.favicon)+ main_app.url_for(current_store.favicon || 'favicon.ico')enddef objectdiff --git a/core/app/models/spree/app_configuration.rb b/core/app/models/spree/app_configuration.rbindex 64882ca503..1029b3cf7f 100644--- a/core/app/models/spree/app_configuration.rb+++ b/core/app/models/spree/app_configuration.rb@@ -47,7 +47,6 @@ module Spreepreference :disable_sku_validation, :boolean, default: false # when turned off disables the built-in SKU uniqueness validationpreference :expedited_exchanges, :boolean, default: false # NOTE this requires payment profiles to be supported on your gateway of choice as well as a delayed job handler to be configured with activejob. kicks off an exchange shipment upon return authorization save. charge customer if they do not return items within timely manner.preference :expedited_exchanges_days_window, :integer, default: 14 # the amount of days the customer has to return their item after the expedited exchange is shipped in order to avoid being charged- preference :favicon, :string, default: 'favicon.ico'preference :layout, :string, default: 'spree/layouts/spree_application'preference :logo, :string, default: 'logo/spree_50.png'preference :mailer_logo, :string, default: 'logo/spree_50.png'diff --git a/core/app/models/spree/store.rb b/core/app/models/spree/store.rbindex e623c2e87e..1c24b744df 100644--- a/core/app/models/spree/store.rb+++ b/core/app/models/spree/store.rb@@ -1,5 +1,8 @@module Spreeclass Store < Spree::Base+ MAILER_LOGO_CONTENT_TYPES = ['image/png', 'image/jpg', 'image/jpeg'].freeze+ FAVICON_CONTENT_TYPES = ['image/png', 'image/x-icon', 'image/vnd.microsoft.icon'].freeze+has_many :orders, class_name: 'Spree::Order'has_many :payment_methods, class_name: 'Spree::PaymentMethod'@@ -25,9 +28,8 @@ module Spreehas_one_attached :mailer_logohas_one_attached :favicon_image- validates :mailer_logo, content_type: ['image/png', 'image/jpg', 'image/jpeg']-- validates :favicon_image, content_type: ['image/png', 'image/x-icon', 'image/vnd.microsoft.icon']+ validates :mailer_logo, content_type: MAILER_LOGO_CONTENT_TYPES+ validates :favicon_image, content_type: FAVICON_CONTENT_TYPESbefore_save :ensure_default_exists_and_is_uniquebefore_save :ensure_supported_currencies, :ensure_supported_locales@@ -94,7 +96,7 @@ module Spreeenddef favicon- return Config[:favicon] unless favicon_image.attached?+ return unless favicon_image.attached?favicon_image.variant(resize: '32x32')enddiff --git a/core/spec/helpers/base_helper_spec.rb b/core/spec/helpers/base_helper_spec.rbindex 9c17931e45..f2ed2915bc 100644--- a/core/spec/helpers/base_helper_spec.rb+++ b/core/spec/helpers/base_helper_spec.rb@@ -328,11 +328,19 @@ describe Spree::BaseHelper, type: :helper doenddescribe '#favicon_path' do- let(:current_store) { create(:store, :with_favicon) }+ context 'when a store has its own favicon' 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+ it do+ expect(favicon_path).to end_with('favicon.ico')+ expect(URI.parse(favicon_path).host).to be_present+ end+ end++ context 'when a store has no favicon' do+ it do+ expect(favicon_path).to eq('favicon.ico')+ endendendenddiff --git a/core/spec/models/spree/store_spec.rb b/core/spec/models/spree/store_spec.rbindex 19a18fb0ac..f5fb613181 100644--- a/core/spec/models/spree/store_spec.rb+++ b/core/spec/models/spree/store_spec.rb@@ -330,8 +330,8 @@ describe Spree::Store, type: :model docontext 'without an attached favicon image' dolet(:store) { create(:store) }- it 'returns a default favicon' do- expect(favicon).to eq('favicon.ico')+ it 'returns a blank favicon' do+ expect(favicon).to be(nil)endendend