diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3fa1c81a96..141d158a0e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,11 +44,11 @@ jobs: services: postgres: image: postgres:15.7 + ports: + - 5432:5432 env: POSTGRES_USER: postgres - POSTGRES_DB: theodinproject_test - POSTGRES_PASSWORD: "password" - ports: ["5432:5432"] + POSTGRES_PASSWORD: postgres redis: image: redis @@ -82,14 +82,18 @@ jobs: bin/rails css:build - name: Setup test database + run: | + bundle exec rake parallel:create + bundle exec rake parallel:load_schema + bundle exec rake parallel:migrate env: RAILS_ENV: test - DATABASE_URL: postgres://postgres:password@localhost:5432/theodinproject_test - run: | - bin/rails db:schema:load + POSTGRES_USERNAME: postgres + POSTGRES_PASSWORD: postgres - name: Run tests env: RAILS_ENV: test - DATABASE_URL: postgres://postgres:password@localhost:5432/theodinproject_test - run: bin/rspec + POSTGRES_USERNAME: postgres + POSTGRES_PASSWORD: postgres + run: bundle exec rake parallel:spec diff --git a/Gemfile b/Gemfile index 51382009b6..8b799101eb 100644 --- a/Gemfile +++ b/Gemfile @@ -68,6 +68,7 @@ end group :development, :test do gem 'dotenv-rails', '~> 3.1' + gem 'parallel_tests', '~> 4.7' gem 'rspec-rails', '~> 6.1' end diff --git a/Gemfile.lock b/Gemfile.lock index d665bce4a0..746920c70d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -346,6 +346,8 @@ GEM orm_adapter (0.5.0) pagy (6.5.0) parallel (1.26.1) + parallel_tests (4.7.1) + parallel parser (3.3.4.2) ast (~> 2.4.1) racc @@ -630,6 +632,7 @@ DEPENDENCIES omniauth-google-oauth2 (~> 1.1.1) omniauth-rails_csrf_protection (~> 1.0) pagy (~> 6.2) + parallel_tests (~> 4.7) pg (~> 1.5) propshaft (~> 0.9) public_activity (~> 3.0) diff --git a/config/database.yml b/config/database.yml index ff6383a515..d545c48832 100644 --- a/config/database.yml +++ b/config/database.yml @@ -20,7 +20,7 @@ development: &development # DO NOT PUT A REAL USERNAME AND PASSWORD IN THIS FILE test: &test <<: *default - database: <%= ENV['POSTGRES_TEST_DB'] || 'theodinproject_test' %> + database: theodinproject_test<%= ENV['TEST_ENV_NUMBER'] %> production: adapter: postgresql diff --git a/config/environments/test.rb b/config/environments/test.rb index cf1a5b3814..6ce024f720 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -40,13 +40,14 @@ config.action_mailer.perform_caching = false + test_port = 3001 + ENV['TEST_ENV_NUMBER'].to_i config.action_mailer.default_url_options = { host: ENV.fetch('HOST', 'localhost'), - port: ENV.fetch('HOST_PORT', 3001) + port: ENV.fetch('HOST_PORT', test_port) } routes.default_url_options = { host: ENV.fetch('HOST', 'localhost'), - port: ENV.fetch('HOST_PORT', 3001) + port: ENV.fetch('HOST_PORT', test_port) } # Tell Action Mailer not to deliver emails to the real world. diff --git a/db/schema.rb b/db/schema.rb index c235e9dff3..c5b8a5018d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2024_08_06_175334) do +ActiveRecord::Schema[7.1].define(version: 2024_08_06_175334) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" diff --git a/spec/services/notifications/flag_submission_spec.rb b/spec/services/notifications/flag_submission_spec.rb index 690c2d0756..06a89a3dd9 100644 --- a/spec/services/notifications/flag_submission_spec.rb +++ b/spec/services/notifications/flag_submission_spec.rb @@ -22,7 +22,7 @@ notification_message = "OdinUser has flagged a submission on #{flagged_submission.lesson.title}\n" \ "Reason: inappropriate\n" \ "Extra: I find it offensive\n" \ - 'Resolve the flag here: http://localhost:3001/admin/flags/120' + "Resolve the flag here: http://localhost:#{Rails.application.routes.default_url_options[:port]}/admin/flags/120" expect(notification.message).to eq notification_message end diff --git a/spec/support/capybara.rb b/spec/support/capybara.rb index 457d77fcc9..027379fb69 100644 --- a/spec/support/capybara.rb +++ b/spec/support/capybara.rb @@ -6,8 +6,8 @@ Capybara.configure do |config| config.test_id = 'data-test' config.automatic_label_click = true - config.server_port = 3001 - config.app_host = 'http://localhost:3001' + config.server_port = 3001 + ENV['TEST_ENV_NUMBER'].to_i + config.app_host = "http://localhost:#{config.server_port}" end Capybara.singleton_class.prepend(Module.new do