diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index c0ffd51080..d434a54e3e 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -143,18 +143,14 @@ jobs: image: postgres:17 env: POSTGRES_USER: alchemy_user - POSTGRES_PASSWORD: password - POSTGRES_DB: alchemy_cms_dummy_test + POSTGRES_HOST_AUTH_METHOD: trust ports: ["5432:5432"] options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 mariadb: image: mariadb:latest ports: ["3307:3306"] env: - MARIADB_USER: alchemy_user - MARIADB_PASSWORD: password - MARIADB_DATABASE: alchemy_cms_dummy_test - MARIADB_ROOT_PASSWORD: password + MARIADB_ALLOW_EMPTY_ROOT_PASSWORD: 1 options: --health-cmd="mariadb-admin ping" --health-interval=10s --health-timeout=5s --health-retries=5 steps: - uses: actions/checkout@v6 @@ -200,9 +196,12 @@ jobs: - name: Prepare database run: | bundle exec rake alchemy:spec:prepare + cd spec/dummy + bin/rails parallel:setup + cd - - name: Run tests run: | - bundle exec rspec + bin/parallel_rspec - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v5 if: matrix.rails == '8.0' && matrix.ruby == '3.4' diff --git a/Gemfile b/Gemfile index 57ea84ff25..7ef55fa7d8 100644 --- a/Gemfile +++ b/Gemfile @@ -23,6 +23,7 @@ end group :development, :test do gem "execjs", "~> 2.10.0" + gem "parallel_tests", "~> 5.5" gem "rubocop", require: false gem "standard", "~> 1.25", require: false diff --git a/README.md b/README.md index 2079d4ed78..e700c2042c 100644 --- a/README.md +++ b/README.md @@ -336,6 +336,34 @@ $ bundle exec rake *) This default task executes the database preparations and runs all defined test cases. +### Run specs in parallel + +Using https://github.com/grosser/parallel_tests + +#### Once before running + +``` +bundle exec rake alchemy:spec:prepare +cd spec/dummy +bin/rails parallel:setup +cd - +``` + +#### Start a parallel test run + +``` +bin/parallel_rspec +``` + +#### After adding a new migration + +``` +cd spec/dummy +bin/rails alchemy:install:migrations +bin/rails parallel:migrate +cd - +``` + ### Start the dummy app You can even start the dummy app and use it to manually test your changes with: diff --git a/app/components/alchemy/ingredients/color_view.rb b/app/components/alchemy/ingredients/color_view.rb index 191f892afa..5c054346e4 100644 --- a/app/components/alchemy/ingredients/color_view.rb +++ b/app/components/alchemy/ingredients/color_view.rb @@ -2,7 +2,7 @@ module Alchemy module Ingredients class ColorView < BaseView def call - value + value.html_safe end def render? diff --git a/app/components/alchemy/ingredients/select_view.rb b/app/components/alchemy/ingredients/select_view.rb index 0921733344..0b3d0a5f5c 100644 --- a/app/components/alchemy/ingredients/select_view.rb +++ b/app/components/alchemy/ingredients/select_view.rb @@ -3,7 +3,7 @@ module Ingredients class SelectView < BaseView def call if ingredient.multiple? && value.is_a?(Array) - value.to_sentence + value.to_sentence.html_safe else super end diff --git a/bin/parallel_rspec b/bin/parallel_rspec new file mode 100755 index 0000000000..0e2e66547f --- /dev/null +++ b/bin/parallel_rspec @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +require "bundler/setup" +load Gem.bin_path("parallel_tests", "parallel_rspec") diff --git a/spec/dummy/config/database.yml b/spec/dummy/config/database.yml index 6f09d943a3..9b4b45b3ba 100644 --- a/spec/dummy/config/database.yml +++ b/spec/dummy/config/database.yml @@ -1,21 +1,20 @@ sqlite: &sqlite adapter: sqlite3 - database: db/<%= Rails.env %>.sqlite3 + database: db/<%= Rails.env %><%= ENV['TEST_ENV_NUMBER'] %>.sqlite3 mysql: &mysql adapter: mysql2 encoding: utf8mb4 username: <%= ENV['DB_USER'] %> password: <%= ENV['DB_PASSWORD'] %> - database: alchemy_cms_dummy_<%= Rails.env %> + database: alchemy_cms_dummy_<%= Rails.env %><%= ENV['TEST_ENV_NUMBER'] %> mariadb: &mariadb adapter: mysql2 encoding: utf8mb4 port: 3307 - username: <%= ENV['DB_USER'] %> - password: <%= ENV['DB_PASSWORD'] %> - database: alchemy_cms_dummy_<%= Rails.env %> + username: root + database: alchemy_cms_dummy_<%= Rails.env %><%= ENV['TEST_ENV_NUMBER'] %> postgresql: &postgresql adapter: postgresql @@ -23,7 +22,7 @@ postgresql: &postgresql username: <%= ENV['DB_USER'] %> password: <%= ENV['DB_PASSWORD'] %> <% end %> - database: alchemy_cms_dummy_<%= Rails.env %> + database: alchemy_cms_dummy_<%= Rails.env %><%= ENV['TEST_ENV_NUMBER'] %> min_messages: ERROR defaults: &defaults diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 1e657a1dc9..786537ea02 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -12,6 +12,13 @@ add_filter "/lib/generators" end +if ENV["TEST_ENV_NUMBER"] # parallel specs + SimpleCov.at_exit do + result = SimpleCov.result + result.format! if ParallelTests.number_of_running_processes <= 1 + end +end + require "rspec/core" RSpec.configure do |config| @@ -19,4 +26,5 @@ config.run_all_when_everything_filtered = true config.pattern = "**/*_spec.rb" config.filter_run :focus + config.silence_filter_announcements = true if ENV["TEST_ENV_NUMBER"] end