From da0b64d251de3bc1dbc287f1dd7491b95286ea8d Mon Sep 17 00:00:00 2001 From: Jared Beck Date: Fri, 23 Mar 2018 19:37:47 -0400 Subject: [PATCH] More work setting up tests against rails 5.2 --- Appraisals | 8 ++++++++ gemfiles/ar_5.2.gemfile | 3 +++ spec/spec_helper.rb | 7 +++++-- spec/support/alt_db_init.rb | 8 +++++--- spec/support/paper_trail_spec_migrator.rb | 19 +++++++++++++++++++ 5 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 spec/support/paper_trail_spec_migrator.rb diff --git a/Appraisals b/Appraisals index df0c96f7..f17af5c2 100644 --- a/Appraisals +++ b/Appraisals @@ -27,4 +27,12 @@ end appraise "ar-5.2" do gem "activerecord", "~> 5.2.0.rc1" gem "rails-controller-testing" + + # bundler does not handle rc versions well + # https://github.com/airblade/paper_trail/pull/1067 + # so we specify activesupport, actionpack, and railties, which we + # would not normally do, as you can see with other rails versions above. + gem "activesupport", "~> 5.2.0.rc1" + gem "actionpack", "~> 5.2.0.rc1" + gem "railties", "~> 5.2.0.rc1" end diff --git a/gemfiles/ar_5.2.gemfile b/gemfiles/ar_5.2.gemfile index 376463cf..dd4f82dc 100644 --- a/gemfiles/ar_5.2.gemfile +++ b/gemfiles/ar_5.2.gemfile @@ -4,5 +4,8 @@ source "https://rubygems.org" gem "activerecord", "~> 5.2.0.rc1" gem "rails-controller-testing" +gem "activesupport", "~> 5.2.0.rc1" +gem "actionpack", "~> 5.2.0.rc1" +gem "railties", "~> 5.2.0.rc1" gemspec path: "../" diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 98fefa12..5d4e0d48 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -61,8 +61,11 @@ require "paper_trail/frameworks/rspec" require "ffaker" require "timecop" -# Run any available migration -ActiveRecord::Migrator.migrate File.expand_path("dummy_app/db/migrate/", __dir__) +# Migrate +require_relative "support/paper_trail_spec_migrator" +::PaperTrailSpecMigrator. + new(::File.expand_path("dummy_app/db/migrate/", __dir__)). + migrate RSpec.configure do |config| config.fixture_path = "#{::Rails.root}/spec/fixtures" diff --git a/spec/support/alt_db_init.rb b/spec/support/alt_db_init.rb index 9cebd711..47800507 100644 --- a/spec/support/alt_db_init.rb +++ b/spec/support/alt_db_init.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require_relative "paper_trail_spec_migrator" + # This file copies the test database into locations for the `Foo` and `Bar` # namespace, then defines those namespaces, then establishes the sqlite3 # connection for the namespaces to simulate an application with multiple @@ -34,7 +36,8 @@ end Foo::Base.configurations = configs Foo::Base.establish_connection(:foo) ActiveRecord::Base.establish_connection(:foo) -ActiveRecord::Migrator.migrate File.expand_path("#{db_directory}/migrate/", __FILE__) +paper_trail_migrations_path = File.expand_path("#{db_directory}/migrate/", __FILE__) +::PaperTrailSpecMigrator.new(paper_trail_migrations_path).migrate module Bar class Base < ActiveRecord::Base @@ -53,5 +56,4 @@ end Bar::Base.configurations = configs Bar::Base.establish_connection(:bar) ActiveRecord::Base.establish_connection(:bar) - -ActiveRecord::Migrator.migrate File.expand_path("#{db_directory}/migrate/", __FILE__) +::PaperTrailSpecMigrator.new(paper_trail_migrations_path).migrate diff --git a/spec/support/paper_trail_spec_migrator.rb b/spec/support/paper_trail_spec_migrator.rb new file mode 100644 index 00000000..57ffc0f3 --- /dev/null +++ b/spec/support/paper_trail_spec_migrator.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +# Looks like the API for programatically running migrations will change +# in rails 5.2. This is an undocumented change, AFAICT. Then again, +# how many people use the programmatic interface? Most people probably +# just use rake. Maybe we're doing it wrong. +class PaperTrailSpecMigrator + def initialize(migrations_path) + @migrations_path = migrations_path + end + + def migrate + if ::ActiveRecord.gem_version >= ::Gem::Version.new("5.2.0.rc1") + ::ActiveRecord::MigrationContext.new(@migrations_path).migrate + else + ::ActiveRecord::Migrator.migrate(@migrations_path) + end + end +end