rails test fails with database reference error

Background

I set up Rails and MySQL in Docker and tried to run the test with rails test, but I got an error.

docker-compose.yml


services:
  mysql_test:
    image: mysql:5.7
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: aaa
      MYSQL_USER: user
      MYSQL_PASSWORD: password
      TZ: 'Asia/Tokyo'
    command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
$ rails test test/integration/aaa_test.rb
Error:
AaaTest#aaa:
ActiveRecord::ConnectionNotEstablished: Access denied for user 'user'@'%' to database 'aaa-1'

Looking at the error content, it refers to aaa-1, and there is no database for it, so an error occurs.

solution

Due to the effect of parallelize (workers:: number_of_processors) in test_helper.rb, change PARALLEL_WORKERS to remove the suffix.

$ PARALLEL_WORKERS=1 rails test test/integration/aaa_test.rb

This will work.

Recommended Posts

rails test fails with database reference error
[Rails] Test with RSpec
Let's unit test with [rails] Rspec!
[Ruby on Rails] View test with RSpec
[Ruby on Rails] Controller test with RSpec
[Ruby on Rails] Model test with RSpec
JUnit 5 gradle test fails with lombok annotation
Let's make an error screen with Rails
Rails database basics
[Rails] rails new to create a database with PostgreSQL
Rails tutorial test
[Rails] Error resolution when generating tokens with PAYJP
Error deploying rails5 + Mysql to heroku with Docker-compose
[Ruby on Rails Tutorial] Error in the test in Chapter 3
Error encountered with notes when deploying docker on rails
Rails5 Rspec test error ArgumentError: Factory not registered: user
[Note] Rails error list
Catch Rails Routing Error
Integration Test with Gradle
Rails deploy with Docker
Test run on rails
[Rails 6] RuntimeError with $ rails s
[Rails error] unexpected tIDENTIFIER
Mac Rails Install Error
Handle devise with Rails
[Rails] Learning with Rails tutorial
rails heroku error log
rails error resolution summary
Test Nokogiri with Rspec.
[Rails] Development with MySQL
Automatically test with Gauge
Unit test with Junit.
Supports multilingualization with Rails!
Double polymorphic with Rails
exited with code 1 error resolution with docker-compose up in rails environment
[Rails 6] jQuery introduction ・ uncaught reference error $ is not defined Error solution
Using another database for phpunit test on Laravel 6 with docker-compose.