mirror of
https://github.com/paper-trail-gem/paper_trail.git
synced 2022-11-09 11:33:19 -05:00
Adding Full Support to Test Against Multiple DB engines.
Accomplished by swapping out database.yml files for the dummy rails instance with en engine specific one.
This commit is contained in:
parent
12a9ca9b31
commit
0e80cd8779
13 changed files with 127 additions and 41 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,6 +1,7 @@
|
|||
NOTES
|
||||
test/debug.log
|
||||
test/paper_trail_plugin.sqlite3.db
|
||||
test/dummy/config/database.yml
|
||||
test/dummy/db/*.sqlite3
|
||||
test/dummy/log/*
|
||||
test/dummy/tmp/*
|
||||
|
|
17
.travis.yml
17
.travis.yml
|
@ -5,8 +5,21 @@ rvm:
|
|||
- 1.8.7
|
||||
- jruby-19mode
|
||||
- jruby-18mode
|
||||
env:
|
||||
- DB=mysql
|
||||
- DB=postgres
|
||||
- DB=sqlite
|
||||
|
||||
before_install: gem update --system 2.2.1
|
||||
before_install:
|
||||
- gem update --system 2.2.1
|
||||
|
||||
before_script:
|
||||
- sh -c "if [ \"$DB\" = 'mysql' ]; then mysql -e 'create database paper_trail_test;'; fi"
|
||||
- sh -c "if [ \"$DB\" = 'mysql' ]; then mysql -e 'create database paper_trail_bar; '; fi"
|
||||
- sh -c "if [ \"$DB\" = 'mysql' ]; then mysql -e 'create database paper_trail_foo; '; fi"
|
||||
- sh -c "if [ \"$DB\" = 'postgres' ]; then psql -c 'create database paper_trail_test;' -U postgres; fi"
|
||||
- sh -c "if [ \"$DB\" = 'postgres' ]; then psql -c 'create database paper_trail_bar;' -U postgres; fi"
|
||||
- sh -c "if [ \"$DB\" = 'postgres' ]; then psql -c 'create database paper_trail_foo;' -U postgres; fi"
|
||||
|
||||
gemfile:
|
||||
- Gemfile
|
||||
|
@ -19,3 +32,5 @@ matrix:
|
|||
gemfile: Gemfile
|
||||
- rvm: 1.8.7
|
||||
gemfile: Gemfile
|
||||
- env: DB=mysql
|
||||
|
15
Rakefile
15
Rakefile
|
@ -2,6 +2,19 @@ require 'bundler'
|
|||
Bundler::GemHelper.install_tasks
|
||||
|
||||
require 'rake/testtask'
|
||||
|
||||
desc 'Set a relevant database.yml'
|
||||
task :prepare do
|
||||
ENV["DB"] ||= "sqlite"
|
||||
if RUBY_VERSION.to_f >= 1.9
|
||||
FileUtils.cp "test/dummy/config/database.#{ENV["DB"]}.yml", "test/dummy/config/database.yml"
|
||||
else
|
||||
require 'ftools'
|
||||
File.cp "test/dummy/config/database.#{ENV["DB"]}.yml", "test/dummy/config/database.yml"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
desc 'Run tests on PaperTrail with Test::Unit.'
|
||||
Rake::TestTask.new(:test) do |t|
|
||||
t.libs << 'lib'
|
||||
|
@ -15,4 +28,4 @@ desc 'Run PaperTrail specs for the RSpec helper.'
|
|||
RSpec::Core::RakeTask.new(:spec)
|
||||
|
||||
desc 'Default: run all available test suites'
|
||||
task :default => [:test, :spec]
|
||||
task :default => [:prepare, :test, :spec]
|
||||
|
|
|
@ -14,19 +14,26 @@ group :development, :test do
|
|||
gem 'sinatra', '~> 1.0'
|
||||
gem 'rack-test', '>= 0.6'
|
||||
|
||||
# Use sqlite3 gem for regular Ruby
|
||||
gem 'sqlite3', '~> 1.2', :platform => :ruby
|
||||
|
||||
# RSpec testing
|
||||
gem 'rspec-rails', '~> 2.14'
|
||||
gem 'generator_spec'
|
||||
|
||||
platforms :ruby do
|
||||
gem 'sqlite3', '~> 1.2'
|
||||
gem 'mysql2', '~> 0.3'
|
||||
gem 'pg', '~> 0.17'
|
||||
end
|
||||
|
||||
platforms :jruby, :ruby_18 do
|
||||
# shoulda-matchers > 2.0 is not compatible with Ruby18.
|
||||
# Since we can't specify difference between JRuby 18/19, we need to use shoulda-matchers 1.5 for all JRuby testing.
|
||||
gem 'shoulda-matchers', '~> 1.5'
|
||||
end
|
||||
|
||||
# Use jRuby's sqlite3 adapter for jRuby
|
||||
gem 'activerecord-jdbcsqlite3-adapter', '~> 1.2.9', :platform => :jruby
|
||||
platforms :jruby do
|
||||
# Use jRuby's sqlite3 adapter for jRuby
|
||||
gem 'activerecord-jdbcsqlite3-adapter', '~> 1.3'
|
||||
gem 'activerecord-jdbcpostgresql-adapter', '~> 1.3'
|
||||
gem 'activerecord-jdbcmysql-adapter', '~> 1.3'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -35,7 +35,11 @@ Gem::Specification.new do |s|
|
|||
# JRuby support for the test ENV
|
||||
unless defined?(JRUBY_VERSION)
|
||||
s.add_development_dependency 'sqlite3', '~> 1.2'
|
||||
s.add_development_dependency 'mysql2', '~> 0.3'
|
||||
s.add_development_dependency 'pg', '~> 0.17'
|
||||
else
|
||||
s.add_development_dependency 'activerecord-jdbcsqlite3-adapter', '~> 1.3'
|
||||
s.add_development_dependency 'activerecord-jdbcpostgresql-adapter', '~> 1.3'
|
||||
s.add_development_dependency 'activerecord-jdbcmysql-adapter', '~> 1.3'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,15 +2,21 @@
|
|||
# then defines those namespaces, then establishes the sqlite3 connection for the namespaces
|
||||
# to simulate an application with multiple database connections.
|
||||
|
||||
#Load database yaml to use
|
||||
configs = YAML.load_file("#{Rails.root}/config/database.yml")
|
||||
|
||||
#If we are testing with sqlite make it quick
|
||||
db_directory = "#{Rails.root}/db"
|
||||
# setup alternate databases
|
||||
if RUBY_VERSION.to_f >= 1.9
|
||||
FileUtils.cp "#{db_directory}/test.sqlite3", "#{db_directory}/test-foo.sqlite3"
|
||||
FileUtils.cp "#{db_directory}/test.sqlite3", "#{db_directory}/test-bar.sqlite3"
|
||||
else
|
||||
require 'ftools'
|
||||
File.cp "#{db_directory}/test.sqlite3", "#{db_directory}/test-foo.sqlite3"
|
||||
File.cp "#{db_directory}/test.sqlite3", "#{db_directory}/test-bar.sqlite3"
|
||||
if ENV["DB"] == "sqlite"
|
||||
if RUBY_VERSION.to_f >= 1.9
|
||||
FileUtils.cp "#{db_directory}/test.sqlite3", "#{db_directory}/test-foo.sqlite3"
|
||||
FileUtils.cp "#{db_directory}/test.sqlite3", "#{db_directory}/test-bar.sqlite3"
|
||||
else
|
||||
require 'ftools'
|
||||
File.cp "#{db_directory}/test.sqlite3", "#{db_directory}/test-foo.sqlite3"
|
||||
File.cp "#{db_directory}/test.sqlite3", "#{db_directory}/test-bar.sqlite3"
|
||||
end
|
||||
end
|
||||
|
||||
module Foo
|
||||
|
@ -26,7 +32,11 @@ module Foo
|
|||
has_paper_trail :class_name => 'Foo::Version'
|
||||
end
|
||||
end
|
||||
Foo::Base.establish_connection(:adapter => 'sqlite3', :database => "#{db_directory}/test-foo.sqlite3")
|
||||
|
||||
Foo::Base.configurations = configs
|
||||
Foo::Base.establish_connection(:foo)
|
||||
ActiveRecord::Base.establish_connection(:foo)
|
||||
ActiveRecord::Migrator.migrate File.expand_path("#{db_directory}/migrate/", __FILE__)
|
||||
|
||||
module Bar
|
||||
class Base < ActiveRecord::Base
|
||||
|
@ -41,4 +51,9 @@ module Bar
|
|||
has_paper_trail :class_name => 'Bar::Version'
|
||||
end
|
||||
end
|
||||
Bar::Base.establish_connection(:adapter => 'sqlite3', :database => "#{db_directory}/test-bar.sqlite3")
|
||||
|
||||
Bar::Base.configurations = configs
|
||||
Bar::Base.establish_connection(:bar)
|
||||
ActiveRecord::Base.establish_connection(:bar)
|
||||
|
||||
ActiveRecord::Migrator.migrate File.expand_path("#{db_directory}/migrate/", __FILE__)
|
||||
|
|
19
test/dummy/config/database.mysql.yml
Normal file
19
test/dummy/config/database.mysql.yml
Normal file
|
@ -0,0 +1,19 @@
|
|||
test: &test
|
||||
adapter: mysql2
|
||||
encoding: utf8
|
||||
database: paper_trail_test
|
||||
pool: 5
|
||||
username: root
|
||||
password:
|
||||
host: localhost
|
||||
|
||||
# Warning: The database defined as "test" will be erased and
|
||||
# re-generated from your development database when you run "rake".
|
||||
# Do not set this db to the same as development or production.
|
||||
foo:
|
||||
<<: *test
|
||||
database: paper_trail_foo
|
||||
|
||||
bar:
|
||||
<<: *test
|
||||
database: paper_trail_bar
|
15
test/dummy/config/database.postgres.yml
Normal file
15
test/dummy/config/database.postgres.yml
Normal file
|
@ -0,0 +1,15 @@
|
|||
test: &test
|
||||
adapter: postgresql
|
||||
database: paper_trail_test
|
||||
username: postgres
|
||||
password:
|
||||
host: localhost
|
||||
port: 5432
|
||||
|
||||
foo:
|
||||
<<: *test
|
||||
database: paper_trail_foo
|
||||
|
||||
bar:
|
||||
<<: *test
|
||||
database: paper_trail_bar
|
15
test/dummy/config/database.sqlite.yml
Normal file
15
test/dummy/config/database.sqlite.yml
Normal file
|
@ -0,0 +1,15 @@
|
|||
# SQLite version 3.x
|
||||
# gem install sqlite3-ruby (not necessary on OS X Leopard)
|
||||
test: &test
|
||||
adapter: sqlite3
|
||||
pool: 5
|
||||
timeout: 5000
|
||||
database: db/test.sqlite3
|
||||
|
||||
foo:
|
||||
<<: *test
|
||||
database: db/test-foo.sqlite3
|
||||
|
||||
bar:
|
||||
<<: *test
|
||||
database: db/test-bar.sqlite3
|
|
@ -1,22 +0,0 @@
|
|||
# SQLite version 3.x
|
||||
# gem install sqlite3-ruby (not necessary on OS X Leopard)
|
||||
development:
|
||||
adapter: sqlite3
|
||||
database: db/development.sqlite3
|
||||
pool: 5
|
||||
timeout: 5000
|
||||
|
||||
# Warning: The database defined as "test" will be erased and
|
||||
# re-generated from your development database when you run "rake".
|
||||
# Do not set this db to the same as development or production.
|
||||
test:
|
||||
adapter: sqlite3
|
||||
database: db/test.sqlite3
|
||||
pool: 5
|
||||
timeout: 5000
|
||||
|
||||
production:
|
||||
adapter: sqlite3
|
||||
database: db/production.sqlite3
|
||||
pool: 5
|
||||
timeout: 5000
|
|
@ -3,7 +3,9 @@ require 'sinatra/base'
|
|||
|
||||
# --- Tests for modular `Sinatra::Base` style ----
|
||||
class BaseApp < Sinatra::Base
|
||||
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => File.expand_path('../../dummy/db/test.sqlite3', __FILE__))
|
||||
configs = YAML.load_file(File.expand_path('../../dummy/config/database.yml', __FILE__))
|
||||
ActiveRecord::Base.configurations = configs
|
||||
ActiveRecord::Base.establish_connection(:test)
|
||||
register PaperTrail::Sinatra
|
||||
|
||||
get '/test' do
|
||||
|
|
|
@ -3,7 +3,9 @@ require 'test_helper'
|
|||
|
||||
# --- Tests for non-modular `Sinatra::Application` style ----
|
||||
class Sinatra::Application
|
||||
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => File.expand_path('../../dummy/db/test.sqlite3', __FILE__))
|
||||
configs = YAML.load_file(File.expand_path('../../dummy/config/database.yml', __FILE__))
|
||||
ActiveRecord::Base.configurations = configs
|
||||
ActiveRecord::Base.establish_connection(:test)
|
||||
register PaperTrail::Sinatra # we shouldn't actually need this line if I'm not mistaken but the tests seem to fail without it ATM
|
||||
|
||||
get '/test' do
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# Configure Rails Envinronment
|
||||
ENV["RAILS_ENV"] = "test"
|
||||
|
||||
ENV["DB"] ||= "sqlite"
|
||||
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
||||
require "rails/test_help"
|
||||
require 'shoulda'
|
||||
|
|
Loading…
Reference in a new issue