From c70a04905af026755cb0eb8667f662a6bc4d020b Mon Sep 17 00:00:00 2001 From: Jonathan Rochkind Date: Wed, 10 Oct 2018 13:27:52 -0600 Subject: [PATCH 1/4] get RAILS_GEM=edge testing of rails edge 6.x working in tests --- Gemfile | 36 +++++++++++++++++++++++++----------- attr_json.gemspec | 6 +++++- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/Gemfile b/Gemfile index 2053062..3977d48 100644 --- a/Gemfile +++ b/Gemfile @@ -6,12 +6,34 @@ gemspec # for our integration test in a real rails env, we add em in development too, # so we can bring up the app or a console in development to play with it. group :test, :development do - gem 'combustion', '~> 0.9.0' + if ENV['RAILS_GEM'] == "edge" + # we need unreleased combustion + gem 'combustion', git: "https://github.com/pat/combustion.git" + else + gem 'combustion', '~> 0.9.0' + end + # all of rails is NOT a dependency, just activerecord. # But we use it for integration testing with combustion. Hmm, a bit annoying # that now our other tests can't be sure they're depending, this might not # be the way to do it. - gem "rails", ENV["RAILS_GEM"] && ENV["RAILS_GEM"].split(",") + if ENV['RAILS_GEM'] == "edge" + gem "rails", git: "https://github.com/rails/rails.git", branch: "master" + gem "railties" + + # I think we need coffee-rails as an explicit dependency just for weird transistory + # reasons on rails edge being in progress. We're not actually using it at all. + gem 'coffee-rails' + else + gem "rails", ENV["RAILS_GEM"] && ENV["RAILS_GEM"].split(",") + + gem "activerecord", ENV["RAILS_GEM"] && ENV['RAILS_GEM'].split(",") + # This shouldn't really be needed, but seems to maybe be a bundler bug, + # this makes standalone_migrations dependencies resolve properly even when our + # RAILS_REQ is for 5.2.0.rc2. If in the future you delete this and everything + # still passes, feel free to remove. + gem "railties", ENV["RAILS_GEM"] && ENV['RAILS_GEM'].split(",") + end # Rails 5.0 won't work with pg 1.0, but that isn't actually in it's gemspec. # So we specify a compatible PG_GEM spec when testing with rails 5. @@ -27,16 +49,8 @@ group :test, :development do gem "selenium-webdriver" # rails 5.1+ includes it by default, but rails 5.0 needs it: gem 'rails-ujs', require: false -end - -if ENV['RAILS_GEM'] - gem "activerecord", ENV['RAILS_GEM'].split(",") - # This shouldn't really be needed, but seems to maybe be a bundler bug, - # this makes standalone_migrations dependencies resolve properly even when our - # RAILS_REQ is for 5.2.0.rc2. If in the future you delete this and everything - # still passes, feel free to remove. - gem "railties", ENV['RAILS_GEM'].split(",") + gem 'capybara-screenshot', :group => :test end gem "byebug" diff --git a/attr_json.gemspec b/attr_json.gemspec index 8338fc9..18040d9 100644 --- a/attr_json.gemspec +++ b/attr_json.gemspec @@ -42,7 +42,11 @@ attributes use as much of the existing ActiveRecord architecture as we can.} spec.required_ruby_version = '>= 2.4.0' - spec.add_runtime_dependency "activerecord", ">= 5.0.0", "< 5.3" + # Only to get CI to work on versions of Rails other than we release with, + # should never release a gem with RAILS_GEM set! + unless ENV['RAILS_GEM'] + spec.add_runtime_dependency "activerecord", ">= 5.0.0", "< 5.3" + end spec.add_development_dependency "bundler", "~> 1.14" spec.add_development_dependency "rake", ">= 10.0" From 787d5f9e7b228e29ae7dc6bf4b981c387e08e43c Mon Sep 17 00:00:00 2001 From: Jonathan Rochkind Date: Wed, 10 Oct 2018 13:28:35 -0600 Subject: [PATCH 2/4] travis test rails edge, current rails 6.x --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 13e93e2..ebbb285 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,5 +13,6 @@ env: - RAILS_GEM="~> 5.0.0" PG_GEM="~> 0.18" - RAILS_GEM="~> 5.1.0" - RAILS_GEM=">= 5.2.0.rc2,< 5.3.0" + - RAILS_GEM="edge" before_install: - gem install bundler -v 1.14.6 From dab6e456a818e458e15026d4ff81605c68aa4cf9 Mon Sep 17 00:00:00 2001 From: Jonathan Rochkind Date: Wed, 10 Oct 2018 20:23:11 -0600 Subject: [PATCH 3/4] use 'appraisal' gem for testing under multiple rails versions --- .gitignore | 1 + .travis.yml | 13 +++--- Appraisals | 40 ++++++++++++++++++ Gemfile | 80 ++++++++++++++--------------------- README.md | 2 + attr_json.gemspec | 3 +- gemfiles/.bundle/config | 2 + gemfiles/rails_5_0.gemfile | 19 +++++++++ gemfiles/rails_5_1.gemfile | 18 ++++++++ gemfiles/rails_5_2.gemfile | 18 ++++++++ gemfiles/rails_edge_6.gemfile | 19 +++++++++ 11 files changed, 160 insertions(+), 55 deletions(-) create mode 100644 Appraisals create mode 100644 gemfiles/.bundle/config create mode 100644 gemfiles/rails_5_0.gemfile create mode 100644 gemfiles/rails_5_1.gemfile create mode 100644 gemfiles/rails_5_2.gemfile create mode 100644 gemfiles/rails_edge_6.gemfile diff --git a/.gitignore b/.gitignore index 2011c3d..238651b 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ /spec/internal/tmp/cache /tmp/ .byebug_history +/gemfiles/*.lock diff --git a/.travis.yml b/.travis.yml index ebbb285..caa0165 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,10 +9,13 @@ cache: bundler rvm: - 2.4 - 2.5.0 -env: - - RAILS_GEM="~> 5.0.0" PG_GEM="~> 0.18" - - RAILS_GEM="~> 5.1.0" - - RAILS_GEM=">= 5.2.0.rc2,< 5.3.0" - - RAILS_GEM="edge" +gemfile: + - gemfiles/rails_5_0.gemfile + - gemfiles/rails_5_1.gemfile + - gemfiles/rails_5_2.gemfile + - gemfiles/rails_edge_6.gemfile before_install: - gem install bundler -v 1.14.6 +matrix: + allow_failures: + - gemfile: gemfiles/rails_edge_6.gemfile diff --git a/Appraisals b/Appraisals new file mode 100644 index 0000000..b3fc4fb --- /dev/null +++ b/Appraisals @@ -0,0 +1,40 @@ +appraise "rails-5-0" do + gem 'combustion', '~> 0.9.0' + + gem "rails", "~> 5.0.0" + + # rails 5.1+ includes it by default, but rails 5.0 needs it: + gem 'rails-ujs', require: false + + # Rails 5 won't work with pg 1.0 even though it doesn't say so + gem "pg", "~> 0.18" +end + +appraise "rails-5-1" do + gem 'combustion', '~> 0.9.0' + + gem "rails", "~> 5.1.0" + + gem "pg", "~> 1.0" +end + +appraise "rails-5-2" do + gem 'combustion', '~> 0.9.0' + + gem "rails", "~> 5.2.0" + gem "pg", "~> 1.0" +end + +appraise "rails-edge-6" do + # Edge rails needs unreleased combustion + # https://github.com/pat/combustion/issues/92 + gem 'combustion', git: "https://github.com/pat/combustion.git" + + gem "rails", git: "https://github.com/rails/rails.git", branch: "master" + gem "pg", "~> 1.0" + + # We don't actually use coffeescript at all, we need coffee-rails as an explicit + # dependency just for transitory edge weirdness using current sprockets release + # with rails 6 edge. + gem 'coffee-rails' +end diff --git a/Gemfile b/Gemfile index 3977d48..af5ae9d 100644 --- a/Gemfile +++ b/Gemfile @@ -3,54 +3,36 @@ source 'https://rubygems.org' # Specify your gem's dependencies in attr_json.gemspec gemspec -# for our integration test in a real rails env, we add em in development too, -# so we can bring up the app or a console in development to play with it. -group :test, :development do - if ENV['RAILS_GEM'] == "edge" - # we need unreleased combustion - gem 'combustion', git: "https://github.com/pat/combustion.git" - else - gem 'combustion', '~> 0.9.0' - end - - # all of rails is NOT a dependency, just activerecord. - # But we use it for integration testing with combustion. Hmm, a bit annoying - # that now our other tests can't be sure they're depending, this might not - # be the way to do it. - if ENV['RAILS_GEM'] == "edge" - gem "rails", git: "https://github.com/rails/rails.git", branch: "master" - gem "railties" - - # I think we need coffee-rails as an explicit dependency just for weird transistory - # reasons on rails edge being in progress. We're not actually using it at all. - gem 'coffee-rails' - else - gem "rails", ENV["RAILS_GEM"] && ENV["RAILS_GEM"].split(",") - - gem "activerecord", ENV["RAILS_GEM"] && ENV['RAILS_GEM'].split(",") - # This shouldn't really be needed, but seems to maybe be a bundler bug, - # this makes standalone_migrations dependencies resolve properly even when our - # RAILS_REQ is for 5.2.0.rc2. If in the future you delete this and everything - # still passes, feel free to remove. - gem "railties", ENV["RAILS_GEM"] && ENV['RAILS_GEM'].split(",") - end - - # Rails 5.0 won't work with pg 1.0, but that isn't actually in it's gemspec. - # So we specify a compatible PG_GEM spec when testing with rails 5. - ENV['PG_GEM'] ||= ">= 0.18.1" - gem "pg", ENV['PG_GEM'] - - gem "rspec-rails", "~> 3.7" - gem "simple_form", ">= 4.0" - gem 'cocoon', ">= 1.2" - gem 'jquery-rails' - gem 'capybara', "~> 3.0" - gem "chromedriver-helper" - gem "selenium-webdriver" - # rails 5.1+ includes it by default, but rails 5.0 needs it: - gem 'rails-ujs', require: false - - gem 'capybara-screenshot', :group => :test -end +# Dependencies for testing and development. To let appraisal override them, we +# do NOT put them in group :test,:development -- which anyway doesn't make a +# lot of sense in a gem Gemfile anyway, there is no "production" in a gem Gemfile. +# +# We also have these development dependencies here in the Gemfile instead of the +# gemspec so appraisal can override them from our Appraisal file. + +gem 'combustion', '~> 0.9.0' + +# all of rails is NOT a dependency, just activerecord. +# But we use it for integration testing with combustion. Hmm, a bit annoying +# that now our other tests can't be sure they're depending, this might not +# be the way to do it. +gem 'rails' + +# We should not really need to mention railties, it's already a dependency of +# rails, but seems to be necessary to get around some mystery bug in bundler +# dependency resolution. +gem 'railties' + +gem "pg" +gem "rspec-rails", "~> 3.7" +gem "simple_form", ">= 4.0" +gem 'cocoon', ">= 1.2" +gem 'jquery-rails' + +gem 'capybara', "~> 3.0" +gem "chromedriver-helper" +gem "selenium-webdriver" gem "byebug" + + diff --git a/README.md b/README.md index a351f17..7a4eed4 100644 --- a/README.md +++ b/README.md @@ -424,6 +424,8 @@ At present this does mean that all our automated tests are run in a full Rails e Tests are in rspec, run tests simply with `./bin/rspec`. +We use [appraisal](https://github.com/thoughtbot/appraisal) to test with multiple rails versions, including on travis. Locally you can run `bundle exec appraisal rspec` to run tests multiple times for each rails version, or eg `bundle exec appraisal rails-5-1 rspec`. If the `Gemfile` _or_ `Appraisal` file changes, you may need to re-run `bundle exec appraisal install` and commit changes. (Try to put dev dependencies in gemspec instead of Gemfile, but sometimes it gets weird.) + There is a `./bin/console` that will give you a console in the context of attr_json and all it's dependencies, including the combustion rails app, and the models defined there. ## Acknowledements and Prior Art diff --git a/attr_json.gemspec b/attr_json.gemspec index 18040d9..ad33b43 100644 --- a/attr_json.gemspec +++ b/attr_json.gemspec @@ -44,7 +44,7 @@ attributes use as much of the existing ActiveRecord architecture as we can.} # Only to get CI to work on versions of Rails other than we release with, # should never release a gem with RAILS_GEM set! - unless ENV['RAILS_GEM'] + unless ENV['APPRAISAL_INITIALIZED'] || ENV["TRAVIS"] spec.add_runtime_dependency "activerecord", ">= 5.0.0", "< 5.3" end @@ -53,4 +53,5 @@ attributes use as much of the existing ActiveRecord architecture as we can.} spec.add_development_dependency "rspec", "~> 3.7" spec.add_development_dependency "database_cleaner", "~> 1.5" spec.add_development_dependency "yard-activesupport-concern" + spec.add_development_dependency "appraisal", "~> 2.2" end diff --git a/gemfiles/.bundle/config b/gemfiles/.bundle/config new file mode 100644 index 0000000..c127f80 --- /dev/null +++ b/gemfiles/.bundle/config @@ -0,0 +1,2 @@ +--- +BUNDLE_RETRY: "1" diff --git a/gemfiles/rails_5_0.gemfile b/gemfiles/rails_5_0.gemfile new file mode 100644 index 0000000..69064f0 --- /dev/null +++ b/gemfiles/rails_5_0.gemfile @@ -0,0 +1,19 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "combustion", "~> 0.9.0" +gem "rails", "~> 5.0.0" +gem "railties" +gem "pg", "~> 0.18" +gem "rspec-rails", "~> 3.7" +gem "simple_form", ">= 4.0" +gem "cocoon", ">= 1.2" +gem "jquery-rails" +gem "capybara", "~> 3.0" +gem "chromedriver-helper" +gem "selenium-webdriver" +gem "byebug" +gem "rails-ujs", require: false + +gemspec path: "../" diff --git a/gemfiles/rails_5_1.gemfile b/gemfiles/rails_5_1.gemfile new file mode 100644 index 0000000..d83ef7a --- /dev/null +++ b/gemfiles/rails_5_1.gemfile @@ -0,0 +1,18 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "combustion", "~> 0.9.0" +gem "rails", "~> 5.1.0" +gem "railties" +gem "pg", "~> 1.0" +gem "rspec-rails", "~> 3.7" +gem "simple_form", ">= 4.0" +gem "cocoon", ">= 1.2" +gem "jquery-rails" +gem "capybara", "~> 3.0" +gem "chromedriver-helper" +gem "selenium-webdriver" +gem "byebug" + +gemspec path: "../" diff --git a/gemfiles/rails_5_2.gemfile b/gemfiles/rails_5_2.gemfile new file mode 100644 index 0000000..58bc4c0 --- /dev/null +++ b/gemfiles/rails_5_2.gemfile @@ -0,0 +1,18 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "combustion", "~> 0.9.0" +gem "rails", "~> 5.2.0" +gem "railties" +gem "pg", "~> 1.0" +gem "rspec-rails", "~> 3.7" +gem "simple_form", ">= 4.0" +gem "cocoon", ">= 1.2" +gem "jquery-rails" +gem "capybara", "~> 3.0" +gem "chromedriver-helper" +gem "selenium-webdriver" +gem "byebug" + +gemspec path: "../" diff --git a/gemfiles/rails_edge_6.gemfile b/gemfiles/rails_edge_6.gemfile new file mode 100644 index 0000000..72e7ea5 --- /dev/null +++ b/gemfiles/rails_edge_6.gemfile @@ -0,0 +1,19 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "combustion", git: "https://github.com/pat/combustion.git" +gem "rails", git: "https://github.com/rails/rails.git", branch: "master" +gem "railties" +gem "pg", "~> 1.0" +gem "rspec-rails", "~> 3.7" +gem "simple_form", ">= 4.0" +gem "cocoon", ">= 1.2" +gem "jquery-rails" +gem "capybara", "~> 3.0" +gem "chromedriver-helper" +gem "selenium-webdriver" +gem "byebug" +gem "coffee-rails" + +gemspec path: "../" From a6fcb1a54b671f97693f2fe5e816eb1e22b0f01e Mon Sep 17 00:00:00 2001 From: Jonathan Rochkind Date: Wed, 10 Oct 2018 20:49:18 -0600 Subject: [PATCH 4/4] update travis use ruby 2.5.1 instead of 2.5.0 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index caa0165..2bf0d7b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ language: ruby cache: bundler rvm: - 2.4 - - 2.5.0 + - 2.5.1 gemfile: - gemfiles/rails_5_0.gemfile - gemfiles/rails_5_1.gemfile