Skip to content

Commit

Permalink
Add support for Rails 6 (Sorcery#238)
Browse files Browse the repository at this point in the history
* Cache bundler on Travis

* Add support for Rails 6

Since the usage of `MigrationContext` was changed in rails/rails#36439,
adds a branch to MigrationHelper.

We are loading 'rails/all' in our test code, it implicitly load action_text from Rails 6.
ActionText requires ApplicationController, adds it.
ref: https://github.com/rails/rails/blob/v6.0.3/actiontext/lib/action_text/engine.rb#L50

* Exclude Ruby 2.4 for Rails 6

Rails 6 does't support Ruby 2.4.
ref: rails/rails#34754
  • Loading branch information
sinsoku authored Jun 16, 2020
1 parent f2c4fcf commit 31a055b
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 6 deletions.
10 changes: 9 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
language: ruby
cache: bundler

rvm:
- 2.4.9
- 2.5.7
- 2.6.5
- 2.7.1

gemfile:
- Gemfile
- gemfiles/rails_52.gemfile
- gemfiles/rails_60.gemfile

jobs:
exclude:
- rvm: 2.4.9
gemfile: gemfiles/rails_60.gemfile
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
source 'https://rubygems.org'

gem 'pry'
gem 'rails', '~> 5.2.0'
gem 'rails'
gem 'rails-controller-testing'
gem 'sqlite3', '~> 1.3.6'
gem 'sqlite3'

gemspec
7 changes: 7 additions & 0 deletions gemfiles/rails_52.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source 'https://rubygems.org'

gem 'rails', '~> 5.2.0'
gem 'rails-controller-testing'
gem 'sqlite3', '~> 1.3.6'

gemspec path: '..'
7 changes: 7 additions & 0 deletions gemfiles/rails_60.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source 'https://rubygems.org'

gem 'rails', '~> 6.0.0'
gem 'rails-controller-testing'
gem 'sqlite3', '~> 1.4'

gemspec path: '..'
2 changes: 2 additions & 0 deletions spec/rails_app/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class ApplicationController < ActionController::Base
end
2 changes: 1 addition & 1 deletion spec/rails_app/app/controllers/sorcery_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'oauth'

class SorceryController < ActionController::Base
class SorceryController < ApplicationController
protect_from_forgery

before_action :require_login_from_http_basic, only: [:test_http_basic_auth]
Expand Down
14 changes: 12 additions & 2 deletions spec/support/migration_helper.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
class MigrationHelper
class << self
def migrate(path)
if ActiveRecord.version >= Gem::Version.new('5.2.0')
if ActiveRecord.version >= Gem::Version.new('6.0.0')
ActiveRecord::MigrationContext.new(path, schema_migration).migrate
elsif ActiveRecord.version >= Gem::Version.new('5.2.0')
ActiveRecord::MigrationContext.new(path).migrate
else
ActiveRecord::Migrator.migrate(path)
end
end

def rollback(path)
if ActiveRecord.version >= Gem::Version.new('5.2.0')
if ActiveRecord.version >= Gem::Version.new('6.0.0')
ActiveRecord::MigrationContext.new(path, schema_migration).rollback
elsif ActiveRecord.version >= Gem::Version.new('5.2.0')
ActiveRecord::MigrationContext.new(path).rollback
else
ActiveRecord::Migrator.rollback(path)
end
end

private

def schema_migration
ActiveRecord::Base.connection.schema_migration
end
end
end

0 comments on commit 31a055b

Please sign in to comment.