Test AR 4.2 locally, without dropping support for 4.0

See notes in boot.rb about `enum`
This commit is contained in:
Jared Beck 2016-12-10 13:49:41 -05:00
parent b05964a466
commit 34ab41d39b
2 changed files with 61 additions and 14 deletions

View File

@ -28,43 +28,73 @@ Testing is a little awkward because the test suite:
1. Contains a "dummy" rails app with three databases (test, foo, and bar)
1. Supports three different RDBMS': sqlite, mysql, and postgres
### Run tests with sqlite
### Test sqlite, AR 4.2
```
# Create the appropriate database config. file
rm test/dummy/config/database.yml
DB=sqlite bundle exec rake prepare
# If this is the first test run ever, create databases
# If this is the first test run ever, create databases.
# We can't use `appraisal` inside the test dummy, so we must set `BUNDLE_GEMFILE`.
# See test/dummy/config/boot.rb for a complete explanation.
cd test/dummy
export BUNDLE_GEMFILE=../../gemfiles/ar_4.2.gemfile
RAILS_ENV=test bundle exec rake db:setup
RAILS_ENV=foo bundle exec rake db:setup
RAILS_ENV=bar bundle exec rake db:setup
unset BUNDLE_GEMFILE
cd ../..
# Run tests
DB=sqlite bundle exec appraisal ar-4.2 rake
```
### Test sqlite, AR 5
```
# Create the appropriate database config. file
rm test/dummy/config/database.yml
DB=sqlite bundle exec rake prepare
# If this is the first test run ever, create databases.
# We can't use `appraisal` inside the test dummy, so we must set `BUNDLE_GEMFILE`.
# See test/dummy/config/boot.rb for a complete explanation.
cd test/dummy
export BUNDLE_GEMFILE=../../gemfiles/ar_5.0.gemfile
RAILS_ENV=test bundle exec rake db:environment:set db:setup
RAILS_ENV=foo bundle exec rake db:environment:set db:setup
RAILS_ENV=bar bundle exec rake db:environment:set db:setup
unset BUNDLE_GEMFILE
cd ../..
# Run tests
DB=sqlite bundle exec appraisal ar-5.0 rake
```
### Run tests with mysql
### Test mysql, AR 5
```
# Create the appropriate database config. file
rm test/dummy/config/database.yml
DB=mysql bundle exec rake prepare
# If this is the first test run ever, create databases
# If this is the first test run ever, create databases.
# We can't use `appraisal` inside the test dummy, so we must set `BUNDLE_GEMFILE`.
# See test/dummy/config/boot.rb for a complete explanation.
cd test/dummy
RAILS_ENV=test bundle exec rake db:setup
RAILS_ENV=foo bundle exec rake db:setup
RAILS_ENV=bar bundle exec rake db:setup
export BUNDLE_GEMFILE=../../gemfiles/ar_5.0.gemfile
RAILS_ENV=test bundle exec rake db:environment:set db:setup
RAILS_ENV=foo bundle exec rake db:environment:set db:setup
RAILS_ENV=bar bundle exec rake db:environment:set db:setup
unset BUNDLE_GEMFILE
cd ../..
# Run tests
DB=mysql bundle exec appraisal ar-5.0 rake
```
### Run tests with postgres
### Test postgres, AR 5
```
# Create the appropriate database config. file
@ -73,10 +103,14 @@ DB=postgres bundle exec rake prepare
# If this is the first test run ever, create databases.
# Unlike mysql, use create/migrate instead of setup.
# We can't use `appraisal` inside the test dummy, so we must set `BUNDLE_GEMFILE`.
# See test/dummy/config/boot.rb for a complete explanation.
cd test/dummy
export BUNDLE_GEMFILE=../../gemfiles/ar_5.0.gemfile
DB=postgres RAILS_ENV=test bundle exec rake db:drop db:create db:migrate
DB=postgres RAILS_ENV=foo bundle exec rake db:drop db:create db:migrate
DB=postgres RAILS_ENV=bar bundle exec rake db:drop db:create db:migrate
unset BUNDLE_GEMFILE
cd ../..
# Run tests

View File

@ -1,10 +1,23 @@
require "rubygems"
gemfile = File.expand_path("../../../../Gemfile", __FILE__)
if File.exist?(gemfile)
ENV["BUNDLE_GEMFILE"] = gemfile
require "bundler"
Bundler.setup
# Set ENV['BUNDLE_GEMFILE'] as follows:
#
# Our test dummy app uses `enum`, so it must use AR >= 4.1. However, we want our
# gemspec to support AR >= 4.0. For local test runs, using our root Gemfile
# would be problematic here. For TravisCI it seems to be fine. Maybe Travis
# overwrites the root Gemfile?
if ENV.key?("BUNDLE_GEMFILE")
# This is a local test run, and we are running rake tasks in this dummy app,
# and we can't use the project's root Gemfile for the reasons given above.
puts "Booting PT test dummy app: Using BUNDLE_GEMFILE: #{ENV.fetch('BUNDLE_GEMFILE')}"
else
gemfile = File.expand_path("../../../../Gemfile", __FILE__)
if File.exist?(gemfile)
puts "Booting PT test dummy app: Using gemfile: #{gemfile}"
ENV["BUNDLE_GEMFILE"] = gemfile
end
end
require "bundler"
Bundler.setup
$LOAD_PATH.unshift File.expand_path("../../../../lib", __FILE__)
$LOAD_PATH.unshift(File.expand_path("../../../../lib", __FILE__))