Skip to content

Commit

Permalink
Add support for doorkeeper 5.6.0.rc1
Browse files Browse the repository at this point in the history
Doorkeeper 5.6.0.rc1 changes how the autoloading works for orms. This patch autoloads its extensions using the built-in autoloader. When used with older doorkeeper versions, the  `initialize_models!` call should continue to work.
  • Loading branch information
danielcooper committed Mar 8, 2022
1 parent be3b943 commit cae7b08
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion doorkeeper-openid_connect.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Gem::Specification.new do |spec|

spec.required_ruby_version = '>= 2.5'

spec.add_runtime_dependency 'doorkeeper', '>= 5.5', '< 5.6'
spec.add_runtime_dependency 'doorkeeper', '>= 5.5', '< 5.7'
spec.add_runtime_dependency 'json-jwt', '>= 1.11.0'

spec.add_development_dependency 'conventional-changelog', '~> 1.2'
Expand Down
15 changes: 15 additions & 0 deletions lib/doorkeeper/openid_connect/orm/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,29 @@

module Doorkeeper
module OpenidConnect
autoload :AccessGrant, "doorkeeper/openid_connect/orm/active_record/access_grant"
autoload :Request, "doorkeeper/openid_connect/orm/active_record/request"

module Orm
module ActiveRecord
def run_hooks
super
Doorkeeper::AccessGrant.prepend Doorkeeper::OpenidConnect::AccessGrant
if Doorkeeper.configuration.active_record_options[:establish_connection]
[Doorkeeper::OpenidConnect::Request].each do |c|
c.send :establish_connection, Doorkeeper.configuration.active_record_options[:establish_connection]
end
end
end

def initialize_models!
super
ActiveSupport.on_load(:active_record) do
require 'doorkeeper/openid_connect/orm/active_record/access_grant'
require 'doorkeeper/openid_connect/orm/active_record/request'

Doorkeeper::AccessGrant.prepend Doorkeeper::OpenidConnect::AccessGrant

if Doorkeeper.configuration.active_record_options[:establish_connection]
[Doorkeeper::OpenidConnect::Request].each do |c|
c.send :establish_connection, Doorkeeper.configuration.active_record_options[:establish_connection]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,4 @@ def self.prepended(base)
end
end
end

AccessGrant.prepend OpenidConnect::AccessGrant
end
4 changes: 4 additions & 0 deletions spec/models/access_grant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
})
end

it 'extends the base doorkeeper AccessGrant' do
expect(subject).to respond_to(:"openid_request=")
end

describe '#delete' do
it 'cascades to oauth_openid_requests' do
if Rails::VERSION::MAJOR >= 6
Expand Down

0 comments on commit cae7b08

Please sign in to comment.