From ba411308dbfe65a734c029485b1ea1929376be0b Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Tue, 23 Aug 2022 12:12:26 +0200 Subject: [PATCH 1/6] Simulate a validation error on LegacyUser and restore spec Added a valid user param so that the action is not stopped by strong parameters. --- api/spec/requests/spree/api/users_spec.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/api/spec/requests/spree/api/users_spec.rb b/api/spec/requests/spree/api/users_spec.rb index 4fa5eb4022f..4203515546c 100644 --- a/api/spec/requests/spree/api/users_spec.rb +++ b/api/spec/requests/spree/api/users_spec.rb @@ -35,9 +35,10 @@ module Spree::Api expect(json_response['email']).to eq 'new@example.com' end - # there's no validations on LegacyUser? - xit "cannot create a new user with invalid attributes" do - post spree.api_users_path, params: { user: {}, token: user.spree_api_key } + it "cannot create a new user with invalid attributes" do + allow_any_instance_of(Spree::LegacyUser).to receive(:save).and_return(false) + + post spree.api_users_path, params: { user: { email: 'foo@example.com' }, token: user.spree_api_key } expect(response.status).to eq(422) expect(json_response["error"]).to eq("Invalid resource. Please fix errors and try again.") end From 5cdc40b573692263d8512b02bb74371bb239e883 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Tue, 23 Aug 2022 12:13:38 +0200 Subject: [PATCH 2/6] Restore SQLite specs that were previously skipped They pass with recent SQLite versions. --- api/spec/requests/spree/api/checkouts_spec.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/api/spec/requests/spree/api/checkouts_spec.rb b/api/spec/requests/spree/api/checkouts_spec.rb index cf54c013921..2822889e745 100644 --- a/api/spec/requests/spree/api/checkouts_spec.rb +++ b/api/spec/requests/spree/api/checkouts_spec.rb @@ -82,8 +82,6 @@ module Spree::Api end it "can update addresses and transition from address to delivery" do - pending "SQLite adapter fails to provide a unique index" if ActiveRecord::Base.connection.adapter_name == "SQLite" - put spree.api_checkout_path(order), params: { order_token: order.guest_token, order: { bill_address_attributes: address, @@ -109,8 +107,6 @@ module Spree::Api # Regression test for https://github.com/spree/spree/issues/4498 it "does not contain duplicate variant data in delivery return" do - pending "SQLite adapter fails to provide a unique index" if ActiveRecord::Base.connection.adapter_name == "SQLite" - put spree.api_checkout_path(order), params: { order_token: order.guest_token, order: { bill_address_attributes: address, From 5ceb7892ff17c9c51656af9c4b687a0850ac5a00 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Tue, 23 Aug 2022 13:18:51 +0200 Subject: [PATCH 3/6] Avoid the "already initialized constant" warnings with net/ libraries 'net/http' is required by 'capybara/server', triggering a few "already initialized constant" warnings when loaded from default gems. See: - https://github.com/ruby/net-protocol/issues/10 - https://stackoverflow.com/a/72474475 --- Gemfile | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Gemfile b/Gemfile index fc7fd8fd028..aa5c4f71496 100644 --- a/Gemfile +++ b/Gemfile @@ -48,6 +48,15 @@ group :backend, :frontend, :core, :api do end group :backend, :frontend do + # 'net/http' is required by 'capybara/server', triggering + # a few "already initialized constant" warnings when loaded + # from default gems. See: + # - https://github.com/ruby/net-protocol/issues/10 + # - https://stackoverflow.com/a/72474475 + if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3') + gem 'net-http', require: false + end + gem 'capybara', '~> 3.13', require: false gem 'capybara-screenshot', '>= 1.0.18', require: false gem 'selenium-webdriver', require: false From 2888203de2e9700f9697800b83cd88d58eb72e67 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Tue, 23 Aug 2022 14:54:45 +0200 Subject: [PATCH 4/6] Suppress AR migration output inside specs --- core/lib/spree/testing_support/dummy_app.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/core/lib/spree/testing_support/dummy_app.rb b/core/lib/spree/testing_support/dummy_app.rb index ddb3f39c91f..daaafb295fc 100644 --- a/core/lib/spree/testing_support/dummy_app.rb +++ b/core/lib/spree/testing_support/dummy_app.rb @@ -116,6 +116,7 @@ class Application < ::Rails::Application end config.paths['db/migrate'] = migration_dirs ActiveRecord::Migrator.migrations_paths = migration_dirs + ActiveRecord::Migration.verbose = false config.assets.paths << File.expand_path('dummy_app/assets/javascripts', __dir__) config.assets.paths << File.expand_path('dummy_app/assets/stylesheets', __dir__) From c6a1967dd6f141214bb74336cea259b3c03241f4 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Tue, 23 Aug 2022 15:02:00 +0200 Subject: [PATCH 5/6] Improve error messages for a misconfigured test DB When running bin/build with the default postgres adapter the DummyApp will interrupt the loading of the spec_helper. This means that the first spec will report the correct error (ActiveRecord::DatabaseConnectionError) but each following spec will try to load the spec_helper again and will report a confusing "Application has been already initialized." error. With this change the original ActiveRecord::DatabaseConnectionError will be reported for every spec, making it easier to fix it. --- core/lib/spree/testing_support/dummy_app.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/lib/spree/testing_support/dummy_app.rb b/core/lib/spree/testing_support/dummy_app.rb index daaafb295fc..9cf3bd66997 100644 --- a/core/lib/spree/testing_support/dummy_app.rb +++ b/core/lib/spree/testing_support/dummy_app.rb @@ -38,7 +38,7 @@ def self.setup(gem_root:, lib_name:, auto_migrate: true) ENV["LIB_NAME"] = lib_name DummyApp::Application.config.root = File.join(gem_root, 'spec', 'dummy') - DummyApp::Application.initialize! + DummyApp::Application.initialize! unless DummyApp::Application.initialized? if auto_migrate DummyApp::Migrations.auto_migrate From e81727dad102f1deb6c1cdcb74e68ffec2c7556e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Busqu=C3=A9?= Date: Wed, 7 Apr 2021 06:30:59 +0200 Subject: [PATCH 6/6] Add sqlite executor to CI The SQLite adapter is the default while developing locally and for dummy apps, even if unlikely to be used by anyone in production we need to be sure it keeps working. The test suite was only run against mysql and postgres. --- .circleci/config.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index e9b551a16e7..eb1f85f814d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -37,6 +37,14 @@ executors: - image: *image - image: cimg/mysql:5.7 + sqlite: + working_directory: *workdir + environment: + <<: *environment + DB: sqlite + docker: + - image: *image + commands: setup: steps: @@ -139,6 +147,14 @@ jobs: - setup - test + sqlite: + executor: sqlite + parallelism: *parallelism + steps: + - setup + - libvips + - test + postgres_rails60: executor: postgres parallelism: *parallelism @@ -168,6 +184,7 @@ workflows: only: /master|v\d\.\d+/ - postgres - mysql + - sqlite - postgres_rails61 - postgres_rails60 - postgres_rails52