Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add integration tests; force generic query compilation
- Loading branch information
Showing
9 changed files
with
153 additions
and
15 deletions.
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
|
||
if [ "$INTEGRATION" == '1' ]; then | ||
crystal spec spec/**/*_test.cr | ||
else | ||
crystal spec | ||
fi |
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,22 @@ | ||
require "../spec_helper" | ||
require "sam" | ||
require "../../../src/jennifer/sam" | ||
|
||
Jennifer::Config.configure do |conf| | ||
conf.logger.level = Logger::DEBUG | ||
conf.host = "localhost" | ||
conf.adapter = Spec.adapter | ||
conf.migration_files_path = "./examples/migrations" | ||
conf.db = "jennifer_integration_test" | ||
|
||
case Spec.adapter | ||
when "mysql" | ||
conf.user = ENV["DB_USER"]? || "root" | ||
conf.password = "" | ||
when "postgres" | ||
conf.user = ENV["DB_USER"]? || "developer" | ||
conf.password = ENV["DB_PASSWORD"]? || "1qazxsw2" | ||
end | ||
end | ||
|
||
Sam.help |
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,84 @@ | ||
require "./spec_helper.cr" | ||
require "spec" | ||
|
||
DEFAULT_DB = "jennifer_integration_test" | ||
|
||
def execute(command, options) | ||
io = IO::Memory.new | ||
|
||
status = Process.run("#{command} \"${@}\"", options, shell: true, output: io, error: io).exit_status | ||
{status, io.to_s} | ||
end | ||
|
||
def clean(db = DEFAULT_DB) | ||
yield | ||
ensure | ||
config = Jennifer::Config | ||
command = | ||
case Spec.adapter | ||
when "postgres" | ||
user = ENV["DB_USER"]? || "developer" | ||
password = ENV["DB_PASSWORD"]? || "1qazxsw2" | ||
"PGPASSWORD=#{password} dropdb #{db} -U#{user}" | ||
when "mysql" | ||
user = ENV["DB_USER"]? || "root" | ||
password = ENV["DB_PASSWORD"]? | ||
common_command = "echo \"drop database #{db};\" | mysql -u#{user}" | ||
common_command += " -p#{password}" if password | ||
common_command | ||
else | ||
raise "Unknown adapter" | ||
end | ||
Process.run(command, shell: true) | ||
end | ||
|
||
def create_db(db = DEFAULT_DB) | ||
config = Jennifer::Config | ||
command = | ||
case Spec.adapter | ||
when "postgres" | ||
user = ENV["DB_USER"]? || "developer" | ||
password = ENV["DB_PASSWORD"]? || "1qazxsw2" | ||
"PGPASSWORD=#{password} createdb #{db} -U#{user}" | ||
when "mysql" | ||
user = ENV["DB_USER"]? || "root" | ||
password = ENV["DB_PASSWORD"]? | ||
common_command = "echo \"create database #{db};\" | mysql -u#{user}" | ||
common_command += " -p#{password}" if password | ||
common_command | ||
else | ||
raise "Unknown adapter" | ||
end | ||
Process.run(command, shell: true) | ||
end | ||
|
||
# NOTE: drop existing db before running tests | ||
clean {} | ||
|
||
describe "Blank application" do | ||
describe "db:create" do | ||
it do | ||
clean do | ||
execute("crystal spec/integration/sam/blank_application.cr", ["db:create"])[0].should eq(0) | ||
end | ||
end | ||
end | ||
|
||
describe "db:drop" do | ||
it do | ||
clean do | ||
create_db | ||
execute("crystal spec/integration/sam/blank_application.cr", ["db:drop"])[0].should eq(0) | ||
end | ||
end | ||
end | ||
|
||
describe "db:migrate" do | ||
it do | ||
clean do | ||
create_db | ||
execute("crystal spec/integration/sam/blank_application.cr", ["db:migrate"])[0].should eq(0) | ||
end | ||
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require "../../src/jennifer" | ||
|
||
module Spec | ||
@@adapter = "" | ||
|
||
def self.adapter | ||
@@adapter | ||
end | ||
|
||
def self.adapter=(v) | ||
@@adapter = v | ||
end | ||
end | ||
|
||
{% if env("DB") == "mysql" %} | ||
require "../../src/jennifer/adapter/mysql" | ||
Spec.adapter = "mysql" | ||
{% elsif env("DB") == "sqlite3" %} | ||
require "../../src/jennifer/adapter/sqlite3" | ||
Spec.adapter = "sqlite3" | ||
{% else %} | ||
require "../../src/jennifer/adapter/postgres" | ||
Spec.adapter = "postgres" | ||
{% 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
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