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
* validate Store#favicon_image properties * display information about Favicon file for upload in the Store Configuration
Łukasz Adamczyk75a960a7a6c6
diff --git a/backend/app/views/spree/admin/stores/_form.html.erb b/backend/app/views/spree/admin/stores/_form.html.erbindex 77f8330a4a..6cb73bf995 100644--- a/backend/app/views/spree/admin/stores/_form.html.erb+++ b/backend/app/views/spree/admin/stores/_form.html.erb@@ -34,7 +34,7 @@<%= image_tag main_app.url_for(@store.favicon_image.variant(resize: '104x104')) %><% end %><%= f.field_container :favicon_image, class: ['form-group'] do %>- <%= f.label :favicon_image, Spree.t(:favicon) %><br>+ <%= f.label :favicon_image, "#{Spree.t(:favicon)} (#{Spree.t(:favicon_upload_info)})" %><br><%= f.file_field :favicon_image, accept: Spree::Store::FAVICON_CONTENT_TYPES.join(',') %><%= f.error_message_on :favicon_image %><% end %>diff --git a/backend/spec/features/admin/configuration/stores_spec.rb b/backend/spec/features/admin/configuration/stores_spec.rbindex 0d3df7d888..8239ccf1f6 100644--- a/backend/spec/features/admin/configuration/stores_spec.rb+++ b/backend/spec/features/admin/configuration/stores_spec.rb@@ -152,16 +152,31 @@ describe 'Stores admin', type: :feature, js: true doexpect(store.new_order_notifications_email).to eq(store_owner_email)end- it 'allows uploading a favicon' do- visit spree.admin_stores_path+ describe 'uploading a favicon' do+ let(:favicon) { file_fixture('favicon.ico') }- within_row(1) { click_icon :edit }- attach_file('Favicon', file_fixture('favicon.ico'))+ before do+ visit spree.admin_stores_path- click_on 'Update'+ within_row(1) { click_icon :edit }+ attach_file('Favicon', favicon)++ click_on 'Update'+ end- expect(page).to have_content('Store "Spree Test Store" has been successfully updated!')- expect(store.reload.favicon_image.attached?).to be(true)+ it 'allows uploading a favicon' do+ expect(page).to have_content('Store "Spree Test Store" has been successfully updated!')+ expect(store.reload.favicon_image.attached?).to be(true)+ end++ context 'when a favicon is invalid' do+ let(:favicon) { file_fixture('icon_512x512.png') }++ it 'prevents uploading a favicon and displays an error message' do+ expect(page).to have_content('Unable to update store.: Favicon image must be less than or equal to 256 x 256 pixel')+ expect(store.reload.favicon_image.attached?).to be(false)+ end+ endendenddiff --git a/backend/spec/fixtures/files/icon_512x512.png b/backend/spec/fixtures/files/icon_512x512.pngnew file mode 100644index 0000000000..2d2f28266bBinary files /dev/null and b/backend/spec/fixtures/files/icon_512x512.png differdiff --git a/core/app/models/spree/store.rb b/core/app/models/spree/store.rbindex 1c24b744df..c952c6a635 100644--- a/core/app/models/spree/store.rb+++ b/core/app/models/spree/store.rb@@ -29,7 +29,10 @@ module Spreehas_one_attached :favicon_imagevalidates :mailer_logo, content_type: MAILER_LOGO_CONTENT_TYPES- validates :favicon_image, content_type: FAVICON_CONTENT_TYPES+ validates :favicon_image, content_type: FAVICON_CONTENT_TYPES,+ dimension: { max: 256..256 },+ aspect_ratio: :square,+ size: { less_than_or_equal_to: 1.megabyte }before_save :ensure_default_exists_and_is_uniquebefore_save :ensure_supported_currencies, :ensure_supported_localesdiff --git a/core/config/locales/en.yml b/core/config/locales/en.ymlindex 02df1ad06c..5985c10331 100644--- a/core/config/locales/en.yml+++ b/core/config/locales/en.yml@@ -901,6 +901,7 @@ en:facebook: Facebookfailed_payment_attempts: Failed Payment Attemptsfavicon: 'Favicon'+ favicon_upload_info: "File format: PNG or ICO. File resolution: up to 256x256. File size: up to 1MB"filename: Filenamefill_in_customer_info: Please fill in customer infofilter: Filterdiff --git a/core/lib/spree/testing_support/factories/store_factory.rb b/core/lib/spree/testing_support/factories/store_factory.rbindex b165e6fcc1..ce4aaaa66d 100644--- a/core/lib/spree/testing_support/factories/store_factory.rb+++ b/core/lib/spree/testing_support/factories/store_factory.rb@@ -14,11 +14,13 @@ FactoryBot.define doinstagram { 'spreecommerce' }trait :with_favicon do+ transient do+ filepath { Spree::Core::Engine.root.join('spec', 'fixtures', 'favicon.ico') }+ image_type { 'image/x-icon' }+ end+favicon_image do- Rack::Test::UploadedFile.new(- Spree::Core::Engine.root.join('spec', 'fixtures', 'favicon.ico'),- 'image/x-icon'- )+ Rack::Test::UploadedFile.new(filepath, image_type)endendenddiff --git a/core/spec/fixtures/files/icon_256x256.gif b/core/spec/fixtures/files/icon_256x256.gifnew file mode 100644index 0000000000..02130fcbfdBinary files /dev/null and b/core/spec/fixtures/files/icon_256x256.gif differdiff --git a/core/spec/fixtures/files/icon_256x256.png b/core/spec/fixtures/files/icon_256x256.pngnew file mode 100644index 0000000000..2edee4a6a3Binary files /dev/null and b/core/spec/fixtures/files/icon_256x256.png differdiff --git a/core/spec/fixtures/files/icon_512x512.png b/core/spec/fixtures/files/icon_512x512.pngnew file mode 100644index 0000000000..2d2f28266bBinary files /dev/null and b/core/spec/fixtures/files/icon_512x512.png differdiff --git a/core/spec/fixtures/files/img_256x128.png b/core/spec/fixtures/files/img_256x128.pngnew file mode 100644index 0000000000..f0c4b9e137Binary files /dev/null and b/core/spec/fixtures/files/img_256x128.png differdiff --git a/core/spec/models/spree/store_spec.rb b/core/spec/models/spree/store_spec.rbindex f5fb613181..7ac1c74fd1 100644--- a/core/spec/models/spree/store_spec.rb+++ b/core/spec/models/spree/store_spec.rb@@ -1,6 +1,48 @@require 'spec_helper'describe Spree::Store, type: :model do+ describe 'validations' do+ describe 'favicon image' do+ it 'validates image properties' do+ expect(build(:store, :with_favicon, filepath: file_fixture('icon_256x256.png'))).to be_valid++ expect(build(:store, :with_favicon, filepath: file_fixture('icon_512x512.png'))).not_to be_valid+ expect(build(:store, :with_favicon, filepath: file_fixture('icon_256x256.gif'))).not_to be_valid+ expect(build(:store, :with_favicon, filepath: file_fixture('img_256x128.png'))).not_to be_valid+ end++ context 'file size' do+ let(:store) do+ store = build(:store)+ store.favicon_image.attach(io: file, filename: 'favicon.png')+ store+ end++ let(:file) { File.open(file_fixture('icon_256x256.png')) }++ before do+ allow(file).to receive(:size).and_return(size)+ end++ context 'when size is 1 megabyte' do+ let(:size) { 1.megabyte }++ it 'is valid' do+ expect(store.valid?).to be(true)+ end+ end++ context 'when size is over 1 megabyte' do+ let(:size) { 1.megabyte + 1 }++ it 'is invalid' do+ expect(store.valid?).to be(false)+ end+ end+ end+ end+ end+describe '.by_url' dolet!(:store) { create(:store, url: "website1.com\nwww.subdomain.com") }let!(:store_2) { create(:store, url: 'freethewhales.com') }