More work setting up tests against rails 5.2
This commit is contained in:
parent
2b3824e29c
commit
da0b64d251
|
@ -27,4 +27,12 @@ end
|
||||||
appraise "ar-5.2" do
|
appraise "ar-5.2" do
|
||||||
gem "activerecord", "~> 5.2.0.rc1"
|
gem "activerecord", "~> 5.2.0.rc1"
|
||||||
gem "rails-controller-testing"
|
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
|
end
|
||||||
|
|
|
@ -4,5 +4,8 @@ source "https://rubygems.org"
|
||||||
|
|
||||||
gem "activerecord", "~> 5.2.0.rc1"
|
gem "activerecord", "~> 5.2.0.rc1"
|
||||||
gem "rails-controller-testing"
|
gem "rails-controller-testing"
|
||||||
|
gem "activesupport", "~> 5.2.0.rc1"
|
||||||
|
gem "actionpack", "~> 5.2.0.rc1"
|
||||||
|
gem "railties", "~> 5.2.0.rc1"
|
||||||
|
|
||||||
gemspec path: "../"
|
gemspec path: "../"
|
||||||
|
|
|
@ -61,8 +61,11 @@ require "paper_trail/frameworks/rspec"
|
||||||
require "ffaker"
|
require "ffaker"
|
||||||
require "timecop"
|
require "timecop"
|
||||||
|
|
||||||
# Run any available migration
|
# Migrate
|
||||||
ActiveRecord::Migrator.migrate File.expand_path("dummy_app/db/migrate/", __dir__)
|
require_relative "support/paper_trail_spec_migrator"
|
||||||
|
::PaperTrailSpecMigrator.
|
||||||
|
new(::File.expand_path("dummy_app/db/migrate/", __dir__)).
|
||||||
|
migrate
|
||||||
|
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require_relative "paper_trail_spec_migrator"
|
||||||
|
|
||||||
# This file copies the test database into locations for the `Foo` and `Bar`
|
# This file copies the test database into locations for the `Foo` and `Bar`
|
||||||
# namespace, then defines those namespaces, then establishes the sqlite3
|
# namespace, then defines those namespaces, then establishes the sqlite3
|
||||||
# connection for the namespaces to simulate an application with multiple
|
# connection for the namespaces to simulate an application with multiple
|
||||||
|
@ -34,7 +36,8 @@ end
|
||||||
Foo::Base.configurations = configs
|
Foo::Base.configurations = configs
|
||||||
Foo::Base.establish_connection(:foo)
|
Foo::Base.establish_connection(:foo)
|
||||||
ActiveRecord::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
|
module Bar
|
||||||
class Base < ActiveRecord::Base
|
class Base < ActiveRecord::Base
|
||||||
|
@ -53,5 +56,4 @@ end
|
||||||
Bar::Base.configurations = configs
|
Bar::Base.configurations = configs
|
||||||
Bar::Base.establish_connection(:bar)
|
Bar::Base.establish_connection(:bar)
|
||||||
ActiveRecord::Base.establish_connection(:bar)
|
ActiveRecord::Base.establish_connection(:bar)
|
||||||
|
::PaperTrailSpecMigrator.new(paper_trail_migrations_path).migrate
|
||||||
ActiveRecord::Migrator.migrate File.expand_path("#{db_directory}/migrate/", __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
|
Loading…
Reference in New Issue