-
Notifications
You must be signed in to change notification settings - Fork 10
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -222,6 +222,7 @@ GEM | |
zeitwerk (2.6.12) | ||
|
||
PLATFORMS | ||
arm64-darwin-22 | ||
arm64-darwin-23 | ||
x86_64-darwin-20 | ||
x86_64-darwin-22 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
version: '3.8' | ||
|
||
services: | ||
postgres: | ||
image: postgres:14 | ||
environment: | ||
POSTGRES_USER: postgres | ||
POSTGRES_PASSWORD: password | ||
POSTGRES_DB: actual_db_schema_test | ||
ports: | ||
- "5432:5432" | ||
volumes: | ||
- ./docker/postgres-init:/docker-entrypoint-initdb.d | ||
|
||
mysql: | ||
image: mysql:8.0 | ||
environment: | ||
MYSQL_ROOT_PASSWORD: password | ||
MYSQL_DATABASE: actual_db_schema_test | ||
ports: | ||
- "3306:3306" | ||
volumes: | ||
- ./docker/mysql-init:/docker-entrypoint-initdb.d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CREATE DATABASE actual_db_schema_test_secondary; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CREATE DATABASE actual_db_schema_test_secondary; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# frozen_string_literal: true | ||
|
||
namespace :test do # rubocop:disable Metrics/BlockLength | ||
desc "Run tests with SQLite3" | ||
task :sqlite3 do | ||
ENV["DB_ADAPTER"] = "sqlite3" | ||
Rake::Task["test"].invoke | ||
Rake::Task["test"].reenable | ||
end | ||
|
||
desc "Run tests with PostgreSQL" | ||
task :postgresql do | ||
sh "docker-compose up -d postgres" | ||
wait_for_postgres | ||
|
||
begin | ||
ENV["DB_ADAPTER"] = "postgresql" | ||
Rake::Task["test"].invoke | ||
Rake::Task["test"].reenable | ||
ensure | ||
sh "docker-compose down" | ||
end | ||
end | ||
|
||
desc "Run tests with MySQL" | ||
task :mysql2 do | ||
sh "docker-compose up -d mysql" | ||
wait_for_mysql | ||
|
||
begin | ||
ENV["DB_ADAPTER"] = "mysql2" | ||
Rake::Task["test"].invoke | ||
Rake::Task["test"].reenable | ||
ensure | ||
sh "docker-compose down" | ||
end | ||
end | ||
|
||
desc "Run tests with all adapters (SQLite3, PostgreSQL, MySQL)" | ||
task all: %i[sqlite3 postgresql mysql2] | ||
|
||
def wait_for_postgres | ||
retries = 10 | ||
begin | ||
sh "docker-compose exec -T postgres pg_isready -U postgres" | ||
rescue StandardError | ||
retries -= 1 | ||
|
||
raise "PostgreSQL is not ready after several attempts." if retries < 1 | ||
|
||
sleep 2 | ||
retry | ||
end | ||
end | ||
|
||
def wait_for_mysql | ||
retries = 10 | ||
begin | ||
sh "docker-compose exec -T mysql mysqladmin ping -h 127.0.0.1 --silent" | ||
rescue StandardError | ||
retries -= 1 | ||
|
||
raise "MySQL is not ready after several attempts." if retries < 1 | ||
|
||
sleep 2 | ||
retry | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -44,35 +44,35 @@ def active_record_setup | |||||
assert_select "td", text: "20130906111511" | ||||||
assert_select "td", text: "FirstPrimary" | ||||||
assert_select "td", text: @utils.branch_for("20130906111511") | ||||||
assert_select "td", text: "tmp/primary.sqlite3" | ||||||
assert_select "td", text: @utils.primary_database | ||||||
end | ||||||
assert_select "tr" do | ||||||
assert_select "td", text: "up" | ||||||
assert_select "td", text: "20130906111512" | ||||||
assert_select "td", text: "SecondPrimary" | ||||||
assert_select "td", text: @utils.branch_for("20130906111512") | ||||||
assert_select "td", text: "tmp/primary.sqlite3" | ||||||
assert_select "td", text: @utils.primary_database | ||||||
end | ||||||
assert_select "tr" do | ||||||
assert_select "td", text: "up" | ||||||
assert_select "td", text: "20130906111514" | ||||||
assert_select "td", text: "FirstSecondary" | ||||||
assert_select "td", text: @utils.branch_for("20130906111514") | ||||||
assert_select "td", text: "tmp/secondary.sqlite3" | ||||||
assert_select "td", text: @utils.secondary_database | ||||||
end | ||||||
assert_select "tr" do | ||||||
assert_select "td", text: "up" | ||||||
assert_select "td", text: "20130906111515" | ||||||
assert_select "td", text: "SecondSecondary" | ||||||
assert_select "td", text: @utils.branch_for("20130906111515") | ||||||
assert_select "td", text: "tmp/secondary.sqlite3" | ||||||
assert_select "td", text: @utils.secondary_database | ||||||
end | ||||||
end | ||||||
end | ||||||
end | ||||||
|
||||||
test "GET #show returns a successful response" do | ||||||
get :show, params: { id: "20130906111511", database: "tmp/primary.sqlite3" } | ||||||
get :show, params: { id: "20130906111511", database: @utils.primary_database } | ||||||
assert_response :success | ||||||
assert_select "h2", text: "Migration FirstPrimary Details" | ||||||
assert_select "table" do | ||||||
|
@@ -86,7 +86,7 @@ def active_record_setup | |||||
end | ||||||
assert_select "tr" do | ||||||
assert_select "th", text: "Database" | ||||||
assert_select "td", text: "tmp/primary.sqlite3" | ||||||
assert_select "td", text: @utils.primary_database | ||||||
end | ||||||
assert_select "tr" do | ||||||
assert_select "th", text: "Branch" | ||||||
|
@@ -96,7 +96,7 @@ def active_record_setup | |||||
end | ||||||
|
||||||
test "GET #show returns a 404 response if migration not found" do | ||||||
get :show, params: { id: "nil", database: "tmp/primary.sqlite3" } | ||||||
get :show, params: { id: "nil", database: @utils.primary_database } | ||||||
assert_response :not_found | ||||||
end | ||||||
|
||||||
|
@@ -115,15 +115,20 @@ def down | |||||
RUBY | ||||||
end | ||||||
@utils.prepare_phantom_migrations(TestingState.db_config) | ||||||
post :rollback, params: { id: "20130906111513", database: "tmp/primary.sqlite3" } | ||||||
post :rollback, params: { id: "20130906111513", database: @utils.primary_database } | ||||||
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" | ||||||
else | ||||||
"An error has occurred, this and all later migrations canceled:\n\n" \ | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as here |
||||||
"ActiveRecord::IrreversibleMigration" | ||||||
end | ||||||
assert_select ".flash", text: message | ||||||
end | ||||||
|
||||||
test "POST #rollback changes migration status to down and hide migration with down status" do | ||||||
post :rollback, params: { id: "20130906111511", database: "tmp/primary.sqlite3" } | ||||||
post :rollback, params: { id: "20130906111511", database: @utils.primary_database } | ||||||
assert_response :redirect | ||||||
get :index | ||||||
assert_select "table" do | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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'sAn error has occurred, this and all later migrations canceled
. Making the suggested change would cause the test to fail for the MySQL adapter.