From 34ab41d39b49025e080515093611bb8cc00e4175 Mon Sep 17 00:00:00 2001 From: Jared Beck Date: Sat, 10 Dec 2016 13:49:41 -0500 Subject: [PATCH] Test AR 4.2 locally, without dropping support for 4.0 See notes in boot.rb about `enum` --- .github/CONTRIBUTING.md | 50 ++++++++++++++++++++++++++++++++------- test/dummy/config/boot.rb | 25 +++++++++++++++----- 2 files changed, 61 insertions(+), 14 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index aecfe29e..c5c33c54 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -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 diff --git a/test/dummy/config/boot.rb b/test/dummy/config/boot.rb index 7a2e617e..bdf2c11a 100644 --- a/test/dummy/config/boot.rb +++ b/test/dummy/config/boot.rb @@ -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__))