Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for running tests against different DB adapters #120

Merged
merged 1 commit into from
Jan 8, 2025

Conversation

m-darbinyan
Copy link
Collaborator

@m-darbinyan m-darbinyan commented Jan 7, 2025

Closes #113

Description

This PR adds new rake tasks to support running tests with different database adapters:

  • rake test:sqlite3: Runs tests using SQLite3 (default, equivalent to rake test).
  • rake test:postgresql: Runs tests using PostgreSQL (requires Docker).
  • rake test:mysql2: Runs tests using MySQL (requires Docker).
  • rake test:all: Runs tests across all supported adapters (SQLite3, PostgreSQL, and MySQL). Docker is used for PostgreSQL and MySQL.

@m-darbinyan m-darbinyan force-pushed the issue-113-support-multiple-db-adapters-for-tests branch 3 times, most recently from 364df12 to adcaa00 Compare January 7, 2025 15:55
lib/tasks/test.rake Outdated Show resolved Hide resolved
test/test_helper.rb Outdated Show resolved Hide resolved
assert_response :redirect
get :index
message = "An error has occurred, this and all later migrations canceled:\n\nActiveRecord::IrreversibleMigration"
message = if ENV["DB_ADAPTER"] == "mysql2"
"An error has occurred, all later migrations canceled:\n\nActiveRecord::IrreversibleMigration"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"An error has occurred, all later migrations canceled:\n\nActiveRecord::IrreversibleMigration"
"An error has occurred, all subsequent migrations have been canceled:\n\nActiveRecord::IrreversibleMigration"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message is generated by Rails and is specific to the database adapter. For MySQL the message is An error has occurred, all subsequent migrations have been canceled, while for other adapters (PostgreSQL, SQLite) it's An error has occurred, this and all later migrations canceled. Making the suggested change would cause the test to fail for the MySQL adapter.

message = if ENV["DB_ADAPTER"] == "mysql2"
"An error has occurred, all later migrations canceled:\n\nActiveRecord::IrreversibleMigration"
else
"An error has occurred, this and all later migrations canceled:\n\n" \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"An error has occurred, this and all later migrations canceled:\n\n" \
"An error has occurred; this migration and all subsequent ones have been canceled:\n\n" \

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as here

@m-darbinyan m-darbinyan force-pushed the issue-113-support-multiple-db-adapters-for-tests branch from adcaa00 to 9e64161 Compare January 8, 2025 07:33
@ka8725 ka8725 merged commit 5607d6b into main Jan 8, 2025
8 checks passed
@ka8725 ka8725 deleted the issue-113-support-multiple-db-adapters-for-tests branch January 8, 2025 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for running tests against different DB adapters
2 participants