Skip to content

Commit

Permalink
Combined test suites
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Feb 3, 2023
1 parent bda88d7 commit fe72be4
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 78 deletions.
9 changes: 2 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,21 @@ jobs:
bundler-cache: true

- run: bundle exec rake test
- run: bundle exec rake test:query_methods:sqlite

- uses: ankane/setup-postgres@v1
with:
database: ahoy_test
- run: ADAPTER=postgresql bundle exec rake test
- run: bundle exec rake test:query_methods:postgresql

- uses: ankane/setup-mysql@v1
with:
database: ahoy_test
- run: ADAPTER=mysql bundle exec rake test
- run: bundle exec rake test:query_methods:mysql
- run: ADAPTER=mysql2 bundle exec rake test

- uses: ankane/setup-mariadb@v1
with:
database: ahoy_test
- run: ADAPTER=mysql bundle exec rake test
- run: bundle exec rake test:query_methods:mysql
- run: ADAPTER=mysql2 bundle exec rake test

- uses: ankane/setup-mongodb@v1
- run: ADAPTER=mongoid bundle exec rake test
- run: bundle exec rake test:query_methods:mongoid
22 changes: 3 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -811,26 +811,10 @@ bundle install
bundle exec rake test
```

To test Mongoid, use:
To test different adapters, use:

```sh
ADAPTER=postgresql bundle exec rake test
ADAPTER=mysql2 bundle exec rake test
ADAPTER=mongoid bundle exec rake test
```

To test query methods, use:

```sh
# Postgres
createdb ahoy_test
bundle exec rake test:query_methods:postgresql

# SQLite
bundle exec rake test:query_methods:sqlite

# MySQL and MariaDB
mysqladmin create ahoy_test
bundle exec rake test:query_methods:mysql

# MongoDB
bundle exec rake test:query_methods:mongoid
```
26 changes: 0 additions & 26 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,3 @@ Rake::TestTask.new do |t|
t.pattern = "test/*_test.rb"
t.warning = false # for bson, mongoid, device_detector, browser
end

ADAPTERS = %w(postgresql mysql sqlite mongoid)

namespace :test do
namespace :query_methods do
ADAPTERS.each do |adapter|
task("env:#{adapter}") { ENV["ADAPTER"] = adapter }

Rake::TestTask.new(adapter => "env:#{adapter}") do |t|
t.description = "Run query method tests for #{adapter}"
t.libs << "test"
t.pattern = "test/query_methods/#{adapter}*_test.rb"
t.warning = false
end
end
end
end

desc "Run query method tests for all adapters"
namespace :test do
task :query_methods do
ADAPTERS.each do |adapter|
Rake::Task["test:query_methods:#{adapter}"].invoke
end
end
end
4 changes: 2 additions & 2 deletions test/internal/config/database.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
test:
adapter: <%= ENV["AR_ADAPTER"] %>
database: <%= ["postgresql", "mysql2"].include?(ENV["AR_ADAPTER"]) ? "ahoy_test" : "db/combustion_test.sqlite" %>
adapter: <%= ENV["ADAPTER"] || "sqlite3" %>
database: <%= ["postgresql", "mysql2"].include?(ENV["ADAPTER"]) ? "ahoy_test" : "db/combustion_test.sqlite" %>
8 changes: 2 additions & 6 deletions test/query_methods/query_methods_helper.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
require_relative "../test_helper"

adapter = ENV["ADAPTER"]
abort "No adapter specified" unless adapter

puts "Using #{adapter}"
case adapter
when "mysql"
case ENV["ADAPTER"]
when "mysql2"
require_relative "../support/mysql"
when "postgresql"
require_relative "../support/postgresql"
Expand Down
15 changes: 15 additions & 0 deletions test/query_methods_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require_relative "test_helper"

case ENV["ADAPTER"]
when "mysql2"
require_relative "query_methods/mysql_json_test"
require_relative "query_methods/mysql_text_test"
when "postgresql"
require_relative "query_methods/postgresql_hstore_test"
require_relative "query_methods/postgresql_json_test"
require_relative "query_methods/postgresql_jsonb_test"
when "mongoid"
require_relative "query_methods/mongoid_test"
else
require_relative "query_methods/sqlite_text_test"
end
2 changes: 0 additions & 2 deletions test/support/mysql.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
ActiveRecord::Base.establish_connection adapter: "mysql2", database: "ahoy_test"

ActiveRecord::Schema.define do
create_table :mysql_text_events, force: true do |t|
t.string :name
Expand Down
2 changes: 0 additions & 2 deletions test/support/postgresql.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
ActiveRecord::Base.establish_connection adapter: "postgresql", database: "ahoy_test"

ActiveRecord::Schema.define do
enable_extension "hstore"

Expand Down
2 changes: 0 additions & 2 deletions test/support/sqlite.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"

ActiveRecord::Schema.define do
create_table :text_events, force: true do |t|
t.string :name
Expand Down
15 changes: 3 additions & 12 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
require "minitest/autorun"
require "minitest/pride"

ENV["ADAPTER"] ||= "sqlite3"
puts "Using #{ENV["ADAPTER"]}"

logger = ActiveSupport::Logger.new(ENV["VERBOSE"] ? STDOUT : nil)

frameworks = [:action_controller, :active_job]
Expand All @@ -19,18 +22,6 @@
Mongo::Logger.logger = logger
else
frameworks << :active_record

ENV["AR_ADAPTER"] =
case ENV["ADAPTER"]
when "mysql"
"mysql2"
when "sqlite", nil
"sqlite3"
when "postgresql"
"postgresql"
else
ENV["ADAPTER"]
end
end

Combustion.path = "test/internal"
Expand Down

0 comments on commit fe72be4

Please sign in to comment.