From e44a39584292797a592a2352cab39a54d53e120e Mon Sep 17 00:00:00 2001 From: Nikita Bulai Date: Mon, 30 Jan 2023 22:05:10 +0300 Subject: [PATCH] Apply ORM configuration in #to_prepare block to avoid autoloading errors --- CHANGELOG.md | 1 + lib/doorkeeper.rb | 4 ++-- lib/doorkeeper/engine.rb | 2 +- spec/lib/config_spec.rb | 4 ++++ spec/models/doorkeeper/application_spec.rb | 11 ++++++++++- 5 files changed, 18 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 387c5d86c..825cada02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ User-visible changes worth mentioning. ## main - [#ID] Add your PR description here. +- [#1633] Apply ORM configuration in #to_prepare block to avoid autoloading errors. # 5.6.3 diff --git a/lib/doorkeeper.rb b/lib/doorkeeper.rb index 6153e958c..2400bc9c4 100644 --- a/lib/doorkeeper.rb +++ b/lib/doorkeeper.rb @@ -137,8 +137,6 @@ def configured? def setup setup_orm_adapter - run_orm_hooks - config.clear_cache! # Deprecated, will be removed soon unless configuration.orm == :active_record @@ -160,6 +158,8 @@ def setup_orm_adapter end def run_orm_hooks + config.clear_cache! + if @orm_adapter.respond_to?(:run_hooks) @orm_adapter.run_hooks else diff --git a/lib/doorkeeper/engine.rb b/lib/doorkeeper/engine.rb index 41a41b852..9d90d3f02 100644 --- a/lib/doorkeeper/engine.rb +++ b/lib/doorkeeper/engine.rb @@ -21,7 +21,7 @@ class Engine < Rails::Engine end config.to_prepare do - Doorkeeper.setup + Doorkeeper.run_orm_hooks end if defined?(Sprockets) && Sprockets::VERSION.chr.to_i >= 4 diff --git a/spec/lib/config_spec.rb b/spec/lib/config_spec.rb index c61ea55f5..3d4ed79f0 100644 --- a/spec/lib/config_spec.rb +++ b/spec/lib/config_spec.rb @@ -372,6 +372,8 @@ class ApplicationWithOwner < ActiveRecord::Base application_class "ApplicationWithOwner" end + + Doorkeeper.run_orm_hooks end it "adds support for application owner" do @@ -398,6 +400,8 @@ class ApplicationWithOwner < ActiveRecord::Base application_class "ApplicationWithOwner" end + + Doorkeeper.run_orm_hooks end it "adds support for application owner" do diff --git a/spec/models/doorkeeper/application_spec.rb b/spec/models/doorkeeper/application_spec.rb index 5225d6349..35aabefd9 100644 --- a/spec/models/doorkeeper/application_spec.rb +++ b/spec/models/doorkeeper/application_spec.rb @@ -106,8 +106,9 @@ def self.generate orm DOORKEEPER_ORM enable_application_owner end - end + Doorkeeper.run_orm_hooks + end it "is valid given valid attributes" do expect(new_application).to be_valid @@ -120,6 +121,8 @@ def self.generate orm DOORKEEPER_ORM enable_application_owner confirmation: true end + + Doorkeeper.run_orm_hooks end it "is invalid without an owner" do @@ -495,6 +498,8 @@ def self.generate orm DOORKEEPER_ORM enable_application_owner confirmation: false end + + Doorkeeper.run_orm_hooks end it "includes all the attributes" do @@ -527,6 +532,8 @@ class CustomApp < ::ActiveRecord::Base application_class "CustomApp" enable_application_owner confirmation: false end + + Doorkeeper.run_orm_hooks end it "is valid given valid attributes" do @@ -541,6 +548,8 @@ class CustomApp < ::ActiveRecord::Base application_class "CustomApp" enable_application_owner confirmation: true end + + Doorkeeper.run_orm_hooks end it "is invalid without owner" do