More work setting up tests against rails 5.2

This commit is contained in:
Jared Beck 2018-03-23 19:37:47 -04:00
parent 2b3824e29c
commit da0b64d251
5 changed files with 40 additions and 5 deletions

View File

@ -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

View File

@ -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: "../"

View File

@ -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"

View File

@ -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

View File

@ -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