Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
130 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,7 @@ | |
/pkg/ | ||
/spec/reports/ | ||
/tmp/ | ||
|
||
.ruby-version | ||
.byebug_history | ||
Guardfile |
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,28 @@ | ||
module Mobility | ||
module Test | ||
class Database | ||
class << self | ||
def connect | ||
::ActiveRecord::Base.establish_connection config[driver] | ||
|
||
if in_memory? | ||
::ActiveRecord::Migration.verbose = false | ||
Schema.migrate :up | ||
end | ||
end | ||
|
||
def config | ||
@config ||= YAML::load(File.open(File.expand_path("../databases.yml", __FILE__))) | ||
end | ||
|
||
def driver | ||
(ENV["DB"] or "sqlite3").downcase | ||
end | ||
|
||
def in_memory? | ||
config[driver]["database"] == ":memory:" | ||
end | ||
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,19 @@ | ||
mysql: | ||
adapter: mysql2 | ||
database: mobility_test | ||
username: root | ||
hostname: localhost | ||
encoding: utf8 | ||
|
||
postgres: | ||
adapter: postgresql | ||
host: localhost | ||
port: 5432 | ||
username: postgres | ||
database: mobility_test | ||
encoding: utf8 | ||
|
||
sqlite3: | ||
adapter: sqlite3 | ||
database: ":memory:" | ||
encoding: utf8 |
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,21 @@ | ||
module Mobility | ||
module Test | ||
class Schema < ::ActiveRecord::Migration[[::ActiveRecord::VERSION::MAJOR, ::ActiveRecord::VERSION::MINOR].join(".")] | ||
class << self | ||
def up | ||
create_table "articles" do |t| | ||
t.string :slug | ||
end | ||
|
||
create_table "mobility_translations" do |t| | ||
t.string :locale | ||
t.string :key | ||
t.text :value | ||
t.integer :translatable_id | ||
t.string :translatable_type | ||
end | ||
end | ||
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 |
---|---|---|
@@ -1,2 +1,49 @@ | ||
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) | ||
|
||
require 'active_record' | ||
require 'pry-byebug' | ||
require 'i18n' | ||
require 'rspec' | ||
require 'rspec/its' | ||
require 'shoulda-matchers' | ||
|
||
require 'mobility' | ||
|
||
I18n.enforce_available_locales = true | ||
I18n.available_locales = [:en, :ja, :fr, :de, :cz, :pl] | ||
|
||
Dir[File.expand_path("./spec/support/**/*.rb")].each { |f| require f } | ||
|
||
require "database" | ||
require "schema" | ||
|
||
Mobility::Test::Database.connect | ||
at_exit {ActiveRecord::Base.connection.disconnect!} | ||
|
||
require 'database_cleaner' | ||
DatabaseCleaner.strategy = :transaction | ||
|
||
RSpec.configure do |config| | ||
config.filter_run focus: true | ||
config.run_all_when_everything_filtered = true | ||
config.mock_with :rspec do |mocks| | ||
mocks.verify_partial_doubles = true | ||
end | ||
|
||
config.before :each do | ||
DatabaseCleaner.start | ||
Mobility.locale = :en | ||
end | ||
config.after :each do | ||
DatabaseCleaner.clean | ||
end | ||
|
||
Shoulda::Matchers.configure do |config| | ||
config.integrate do |with| | ||
with.test_framework :rspec | ||
with.library :active_record | ||
end | ||
end | ||
|
||
config.include(Shoulda::Matchers::ActiveModel, type: :model) | ||
end |