Skip to content

Commit

Permalink
Merge pull request #1633 from doorkeeper-gem/fix-custom-models
Browse files Browse the repository at this point in the history
Apply ORM configuration in #to_prepare block to avoid autoloading errors
  • Loading branch information
nbulaj authored Jan 30, 2023
2 parents 6364c29 + e44a395 commit b967c4c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions lib/doorkeeper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/doorkeeper/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions spec/lib/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,8 @@ class ApplicationWithOwner < ActiveRecord::Base

application_class "ApplicationWithOwner"
end

Doorkeeper.run_orm_hooks
end

it "adds support for application owner" do
Expand All @@ -398,6 +400,8 @@ class ApplicationWithOwner < ActiveRecord::Base

application_class "ApplicationWithOwner"
end

Doorkeeper.run_orm_hooks
end

it "adds support for application owner" do
Expand Down
11 changes: 10 additions & 1 deletion spec/models/doorkeeper/application_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit b967c4c

Please sign in to comment.