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.

Fix MySQL build (#12528)

Damian Legawiecbad4b9e508b6
diff --git a/.circleci/config.yml b/.circleci/config.yml
index 854f021063..6ca6dd5fd0 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -7,55 +7,34 @@ defaults: &defaults
BUNDLE_JOBS: 4
BUNDLE_RETRY: 3
BUNDLE_PATH: ~/spree/vendor/bundle
- DB: postgres # default value, this will speed up bundle install for all postgres builds
DB_HOST: localhost
+ DB: postgres # default value, this will speed up bundle install for all postgres builds
DB_USERNAME: postgres
working_directory: ~/spree
docker:
- image: &ruby_image cimg/ruby:3.3.0-browsers
-jobs:
- build:
- <<: *defaults
+commands:
+ bundle_install:
steps:
- - checkout
- restore_cache:
keys:
- spree-bundle-v10-ruby-{{ checksum ".ruby-version" }}-{{ .Branch }}
- spree-bundle-v10-ruby-{{ checksum ".ruby-version" }}
- - run:
- name: Install libvips
- command: sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 32EE5355A6BC6E42 && sudo apt-get update && sudo apt-get install libvips42
+ - install_libvips
- run:
name: Install global dependencies
command: bundle check || bundle install
- run:
name: Install per-project gem dependencies
command: bin/build-ci.rb install
- - save_cache:
- key: spree-bundle-v10-ruby-{{ checksum ".ruby-version" }}-{{ .Branch }}
- paths:
- - ~/spree/vendor/bundle
-
- run_test: &run_test
- <<: *defaults
- steps: &default_steps
- - checkout
- - attach_workspace:
- at: /tmp
- - restore_cache:
- keys:
- - spree-bundle-v10-ruby-{{ checksum ".ruby-version" }}-{{ .Branch }}
- - spree-bundle-v10-ruby-{{ checksum ".ruby-version" }}
+ install_libvips:
+ steps:
- run:
name: Install libvips
command: sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 32EE5355A6BC6E42 && sudo apt-get update && sudo apt-get install libvips42
- - run:
- name: Ensure gems are installed
- command: bin/build-ci.rb install
- - run:
- name: Run tests
- command: bin/build-ci.rb test
+ store_all_artifacts:
+ steps:
- store_artifacts:
path: /tmp/test-artifacts
destination: test-artifacts
@@ -67,85 +46,146 @@ jobs:
destination: raw-test-output
- store_test_results:
path: /tmp/test-results
-
- tests_core: &tests_core
- <<: *run_test
+jobs:
+ build:
+ <<: *defaults
+ steps:
+ - checkout
+ - bundle_install
+ - save_cache:
+ key: spree-bundle-v10-ruby-{{ checksum ".ruby-version" }}-{{ .Branch }}
+ paths:
+ - ~/spree/vendor/bundle
+ test: &test
+ <<: *defaults
docker:
- image: *ruby_image
- image: cimg/postgres:16.2
environment:
POSTGRES_USER: postgres
+ steps: &default_steps
+ - checkout
+ - attach_workspace:
+ at: /tmp
+ - install_libvips
+ - bundle_install
+ - run:
+ name: Run tests
+ command: bin/build-ci.rb test
+ - store_all_artifacts
+
+ test_mysql: &test_mysql
+ <<: *test
+ docker:
+ - image: *ruby_image
+ - image: cimg/mysql:8.0
+ command: [--default-authentication-plugin=mysql_native_password]
+ environment:
+ MYSQL_ROOT_PASSWORD: password
+ environment: &mysql_environment
+ <<: *environment
+ DB: mysql
+ DB_USERNAME: root
+ DB_PASSWORD: password
+ DB_HOST: 127.0.0.1
+
+ # postgres tests
+ test_core_postgres:
+ <<: *test
parallelism: 6
environment:
<<: *environment
PROJECTS: core
-
- tests_api: &tests_api
- <<: *run_test
+ test_api_postgres:
+ <<: *test
parallelism: 4
- docker:
- - image: *ruby_image
- - image: cimg/postgres:16.2
- environment:
- POSTGRES_USER: postgres
environment:
<<: *environment
PROJECTS: api
-
- tests_admin: &tests_admin
- <<: *run_test
- docker:
- - image: *ruby_image
- - image: cimg/postgres:16.2
- environment:
- POSTGRES_USER: postgres
+ test_admin_postgres:
+ <<: *test
environment:
<<: *environment
PROJECTS: admin
-
- tests_storefront: &tests_storefront
- <<: *run_test
- docker:
- - image: *ruby_image
- - image: cimg/postgres:16.2
- environment:
- POSTGRES_USER: postgres
+ test_storefront_postgres:
+ <<: *test
environment:
<<: *environment
PROJECTS: storefront
-
- tests_other: &tests_other
- <<: *run_test
- docker:
- - image: *ruby_image
- - image: cimg/postgres:16.2
- environment:
- POSTGRES_USER: postgres
+ test_other_postgres:
+ <<: *test
environment:
<<: *environment
PROJECTS: emails,sample
+ # mysql tests
+ test_core_mysql:
+ <<: *test_mysql
+ parallelism: 6
+ environment:
+ <<: *mysql_environment
+ PROJECTS: core
+ test_api_mysql:
+ <<: *test_mysql
+ parallelism: 4
+ environment:
+ <<: *mysql_environment
+ PROJECTS: api
+ test_admin_mysql:
+ <<: *test_mysql
+ environment:
+ <<: *mysql_environment
+ PROJECTS: admin
+ test_storefront_mysql:
+ <<: *test_mysql
+ environment:
+ <<: *mysql_environment
+ PROJECTS: storefront
+ test_other_mysql:
+ <<: *test_mysql
+ environment:
+ <<: *mysql_environment
+ PROJECTS: emails,sample
+
workflows:
main:
jobs:
- build
- - tests_core:
- name: tests_rails_postgres_core
+ # postgres tests
+ - test_core_postgres:
+ requires:
+ - build
+ - test_api_postgres:
+ requires:
+ - build
+ - test_admin_postgres:
+ requires:
+ - build
+ - test_storefront_postgres:
+ requires:
+ - build
+ - test_other_postgres:
+ requires:
+ - build
+
+ # mysql tests
+ - test_core_mysql:
requires:
- build
- - tests_api:
- name: tests_rails_postgres_api
+ - test_core_postgres
+ - test_api_mysql:
requires:
- build
- - tests_admin:
- name: tests_rails_postgres_admin
+ - test_api_postgres
+ - test_admin_mysql:
requires:
- build
- - tests_storefront:
- name: tests_rails_postgres_storefront
+ - test_admin_postgres
+ - test_storefront_mysql:
requires:
- build
- - tests_other:
- name: tests_rails_postgres_other
+ - test_storefront_postgres
+ - test_other_mysql:
requires:
- build
+ - test_other_postgres
\ No newline at end of file
diff --git a/admin/spec/controllers/spree/admin/return_authorizations_controller_spec.rb b/admin/spec/controllers/spree/admin/return_authorizations_controller_spec.rb
index efb50dd6fa..ae720dccdd 100644
--- a/admin/spec/controllers/spree/admin/return_authorizations_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/return_authorizations_controller_spec.rb
@@ -58,7 +58,15 @@ RSpec.describe Spree::Admin::ReturnAuthorizationsController do
end
describe '#collection' do
- let!(:return_authorizations) { create_list(:return_authorization, 3) }
+ let!(:return_authorizations) do
+ [
+ create(:return_authorization, order: order, created_at: 3.days.ago),
+ create(:return_authorization, order: order, created_at: 1.hour.ago),
+ create(:return_authorization, order: order, created_at: 10.minutes.ago)
+ ]
+ end
+
+ let(:return_authorization) { create(:return_authorization, order: order, created_at: 1.week.ago) }
before do
# Create one for a different store to test store filtering
diff --git a/api/spec/requests/spree/api/v2/storefront/stores_spec.rb b/api/spec/requests/spree/api/v2/storefront/stores_spec.rb
index bbdc162afa..bf86c506e8 100644
--- a/api/spec/requests/spree/api/v2/storefront/stores_spec.rb
+++ b/api/spec/requests/spree/api/v2/storefront/stores_spec.rb
@@ -64,6 +64,11 @@ describe 'Storefront API v2 Stores spec', type: :request do
get "/api/v2/storefront/stores/#{store.code}?locale=pl"
end
+ after do
+ I18n.locale = :en
+ Spree::Store.default.update!(supported_locales: 'en')
+ end
+
it 'return store with translated attributes' do
expect(json_response['data']).to have_attribute(:name).with_value('Test Store PL')
expect(json_response['data']).to have_attribute(:meta_description).with_value('Meta Desc PL')
diff --git a/core/app/models/spree/order.rb b/core/app/models/spree/order.rb
index 6be1c2f9b6..dc8cf2321a 100644
--- a/core/app/models/spree/order.rb
+++ b/core/app/models/spree/order.rb
@@ -684,7 +684,7 @@ module Spree
# This query will select the first available shipping method from the shipments.
# It will use subquery to first select the shipping method id from the shipments' selected_shipping_rate.
Spree::ShippingMethod.
- where(id: shipments.with_selected_shipping_method.limit(1)).
+ where(id: shipments.with_selected_shipping_method.limit(1).pluck(:shipping_method_id)).
limit(1).
first
end
diff --git a/core/app/models/spree/promotion/actions/create_line_items.rb b/core/app/models/spree/promotion/actions/create_line_items.rb
index ef7644cf40..43a045557b 100644
--- a/core/app/models/spree/promotion/actions/create_line_items.rb
+++ b/core/app/models/spree/promotion/actions/create_line_items.rb
@@ -100,6 +100,9 @@ module Spree
# upsert the rest
records_for_upsert = promotion_action_line_items_attributes.map { |key, params| params["_destroy"] != "1" ? params : nil }.compact
+ opts = {}
+ opts[:unique_by] = [:promotion_action_id, :variant_id] unless ActiveRecord::Base.connection.adapter_name == 'Mysql2'
+
promotion_action_line_items.upsert_all(
records_for_upsert.map do |params|
{
@@ -108,7 +111,7 @@ module Spree
promotion_action_id: id
}
end,
- unique_by: %i[promotion_action_id variant_id]
+ **opts
)
end
end
diff --git a/core/app/models/spree/promotion/rules/product.rb b/core/app/models/spree/promotion/rules/product.rb
index 731ab4917a..752c2108ba 100644
--- a/core/app/models/spree/promotion/rules/product.rb
+++ b/core/app/models/spree/promotion/rules/product.rb
@@ -89,9 +89,8 @@ module Spree
return if product_ids_to_add.nil?
product_promotion_rules.delete_all
- product_promotion_rules.upsert_all(
- product_ids_to_add.map { |product_id| { product_id: product_id, promotion_rule_id: id } },
- unique_by: [:product_id, :promotion_rule_id]
+ product_promotion_rules.insert_all(
+ product_ids_to_add.map { |product_id| { product_id: product_id, promotion_rule_id: id } }
)
end
end
diff --git a/core/app/models/spree/promotion/rules/taxon.rb b/core/app/models/spree/promotion/rules/taxon.rb
index 6b79314597..9627c44a3a 100644
--- a/core/app/models/spree/promotion/rules/taxon.rb
+++ b/core/app/models/spree/promotion/rules/taxon.rb
@@ -96,9 +96,8 @@ module Spree
return if taxon_ids_to_add.nil?
promotion_rule_taxons.delete_all
- promotion_rule_taxons.upsert_all(
- taxon_ids_to_add.map { |taxon_id| { taxon_id: taxon_id, promotion_rule_id: id } },
- unique_by: [:taxon_id, :promotion_rule_id]
+ promotion_rule_taxons.insert_all(
+ taxon_ids_to_add.map { |taxon_id| { taxon_id: taxon_id, promotion_rule_id: id } }
)
end
end
diff --git a/core/app/models/spree/promotion/rules/user.rb b/core/app/models/spree/promotion/rules/user.rb
index 6c7193640d..bc72099441 100644
--- a/core/app/models/spree/promotion/rules/user.rb
+++ b/core/app/models/spree/promotion/rules/user.rb
@@ -50,9 +50,8 @@ module Spree
return if user_ids_to_add.nil?
promotion_rule_users.delete_all
- promotion_rule_users.upsert_all(
- user_ids_to_add.map { |user_id| { user_id: user_id, promotion_rule_id: id } },
- unique_by: [:user_id, :promotion_rule_id]
+ promotion_rule_users.insert_all(
+ user_ids_to_add.map { |user_id| { user_id: user_id, promotion_rule_id: id } }
)
end
end
diff --git a/core/app/services/spree/taxons/remove_products.rb b/core/app/services/spree/taxons/remove_products.rb
index d80e6acee9..c7109f66f2 100644
--- a/core/app/services/spree/taxons/remove_products.rb
+++ b/core/app/services/spree/taxons/remove_products.rb
@@ -32,9 +32,12 @@ module Spree
end
if classifications_params.any?
+ opts = {}
+ opts[:unique_by] = :index_spree_products_taxons_on_product_id_and_taxon_id unless ActiveRecord::Base.connection.adapter_name == 'Mysql2'
+
Spree::Classification.upsert_all(
classifications_params,
- unique_by: :index_spree_products_taxons_on_product_id_and_taxon_id
+ **opts
)
end
end
diff --git a/core/lib/spree/testing_support/metadata.rb b/core/lib/spree/testing_support/metadata.rb
index c747cba4a6..7383fe8d7a 100644
--- a/core/lib/spree/testing_support/metadata.rb
+++ b/core/lib/spree/testing_support/metadata.rb
@@ -60,7 +60,7 @@ shared_examples_for 'metadata' do |factory: described_class.name.demodulize.unde
subject.save!
expect(described_class.where("JSON_EXTRACT(public_metadata, '$.color') = ?", 'red').count).to eq(1)
- expect(described_class.where("JSON_EXTRACT(public_metadata, '$.priority') = ?", 1).count).to eq(1)
+ expect(described_class.where("JSON_EXTRACT(public_metadata, '$.priority') = 1").count).to eq(1)
expect(described_class.where("JSON_EXTRACT(public_metadata, '$.additional_data.size') = :size", size: 'big').count).to eq(1)
end
end
diff --git a/emails/spec/mailers/spree/order_mailer_spec.rb b/emails/spec/mailers/spree/order_mailer_spec.rb
index a7077b37de..06ae266886 100644
--- a/emails/spec/mailers/spree/order_mailer_spec.rb
+++ b/emails/spec/mailers/spree/order_mailer_spec.rb
@@ -179,6 +179,16 @@ describe Spree::OrderMailer, type: :mailer do
pt_br_cancel_mail = { spree: { order_mailer: { cancel_email: { order_summary_canceled: 'Resumo da Pedido [CANCELADA]' } } } }
I18n.backend.store_translations :'pt-BR', pt_br_confirm_mail
I18n.backend.store_translations :'pt-BR', pt_br_cancel_mail
+
+ I18n.backend.store_translations :'pt-BR', {
+ spree: {
+ default_post_categories: {
+ articles: 'Artigos',
+ news: 'Notícias',
+ resources: 'Recursos'
+ }
+ }
+ }
end
after do
@@ -213,6 +223,7 @@ describe Spree::OrderMailer, type: :mailer do
after do
I18n.locale = :en
+ first_store.update(default_locale: 'en')
end
it_behaves_like 'translates emails'
@@ -224,6 +235,11 @@ describe Spree::OrderMailer, type: :mailer do
order.store.update!(default_locale: 'pt-BR')
end
+ after do
+ I18n.locale = :en
+ order.store.reload.update(default_locale: 'en')
+ end
+
it_behaves_like 'translates emails'
end
end
diff --git a/sample/db/samples/products.rb b/sample/db/samples/products.rb
index 38aab3386b..25b1269f57 100644
--- a/sample/db/samples/products.rb
+++ b/sample/db/samples/products.rb
@@ -37,8 +37,14 @@ store_ids = Spree::Store.ids
product_ids = Spree::Product.ids
store_ids.each do |store_id|
- Spree::StoreProduct.upsert_all(
- product_ids.map { |product_id| { store_id: store_id, product_id: product_id } },
- unique_by: [:store_id, :product_id]
- )
+ if ActiveRecord::Base.connection.adapter_name == 'Mysql2'
+ Spree::StoreProduct.upsert_all(
+ product_ids.map { |product_id| { store_id: store_id, product_id: product_id } }
+ )
+ else
+ Spree::StoreProduct.upsert_all(
+ product_ids.map { |product_id| { store_id: store_id, product_id: product_id } },
+ unique_by: [:store_id, :product_id]
+ )
+ end
end
diff --git a/sample/db/samples/reimbursement_types.rb b/sample/db/samples/reimbursement_types.rb
index e91e2580a9..2a8b1bf90c 100644
--- a/sample/db/samples/reimbursement_types.rb
+++ b/sample/db/samples/reimbursement_types.rb
@@ -6,4 +6,6 @@ reasons = [
{ name: name, type: kind }
end
-Spree::ReimbursementType.insert_all(reasons, unique_by: :name)
+reasons.each do |reason|
+ Spree::ReimbursementType.find_or_create_by!(name: reason[:name], type: reason[:type])
+end
diff --git a/sample/db/samples/return_authorization_reasons.rb b/sample/db/samples/return_authorization_reasons.rb
index 266d043de7..bee4c2359a 100644
--- a/sample/db/samples/return_authorization_reasons.rb
+++ b/sample/db/samples/return_authorization_reasons.rb
@@ -12,4 +12,8 @@ reasons = [
{name: name}
end
-Spree::ReturnAuthorizationReason.insert_all(reasons, unique_by: :name)
+if ActiveRecord::Base.connection.adapter_name == 'Mysql2'
+ Spree::ReturnAuthorizationReason.insert_all(reasons)
+else
+ Spree::ReturnAuthorizationReason.upsert_all(reasons, unique_by: :name)
+end