From de7cdc66f7053e0ef4b69a361d2a9ffd0963358e Mon Sep 17 00:00:00 2001 From: Nikita Bulai Date: Thu, 9 Apr 2020 00:01:29 +0300 Subject: [PATCH] [ga skip] Fix Rake tasks Rake tasks could be initializers when AR already loaded Fix #1319 --- CHANGELOG.md | 2 +- lib/doorkeeper.rb | 2 +- lib/doorkeeper/orm/active_record.rb | 12 ++++++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 03d33f382..afe952106 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ User-visible changes worth mentioning. ## master -- [#PR number] Your changes description. +- [#1395] Fix `NameError: uninitialized constant Doorkeeper::AccessToken` for Rake tasks. ## 5.4.0.rc1 - [#1366] Sets expiry of token generated using `refresh_token` to that of original token. (Fixes #1364) diff --git a/lib/doorkeeper.rb b/lib/doorkeeper.rb index 694814218..8f5055fb8 100644 --- a/lib/doorkeeper.rb +++ b/lib/doorkeeper.rb @@ -6,8 +6,8 @@ # Main Doorkeeper namespace. # module Doorkeeper - autoload :OAuth, "doorkeeper/oauth" autoload :Errors, "doorkeeper/errors" + autoload :OAuth, "doorkeeper/oauth" autoload :Rake, "doorkeeper/rake" autoload :Request, "doorkeeper/request" autoload :Server, "doorkeeper/server" diff --git a/lib/doorkeeper/orm/active_record.rb b/lib/doorkeeper/orm/active_record.rb index d250d0e51..77494d414 100644 --- a/lib/doorkeeper/orm/active_record.rb +++ b/lib/doorkeeper/orm/active_record.rb @@ -33,12 +33,20 @@ def self.initialize_application_owner! lazy_load do require "doorkeeper/models/concerns/ownership" - Doorkeeper.config.application_model.send :include, Doorkeeper::Models::Ownership + Doorkeeper.config.application_model.include(Doorkeeper::Models::Ownership) end end def self.lazy_load(&block) - ActiveSupport.on_load(:active_record, {}, &block) + # ActiveSupport has no public interface to check if something + # already lazy-loaded :( + loaded = ActiveSupport.instance_variable_get(:"@loaded") || {} + + if loaded.key?(:active_record) + block.call + else + ActiveSupport.on_load(:active_record, {}, &block) + end end def self.models