-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We were only defining the `Punditize` module if we had already defined `Pundit`. Setting `Punditize` like this broke autoloading in Rails when `Pundit` was not specified. We fixed the problem by always setting `Punditize` but keeping it empty if` Pundit` does not exist. #1339
- Loading branch information
Showing
2 changed files
with
44 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require "rails_helper" | ||
|
||
module Administrate | ||
RSpec.describe Punditize do | ||
it "exists when 'Pundit' is not defined" do | ||
unload_constants do | ||
expect { build_dummy }.not_to raise_error | ||
end | ||
end | ||
|
||
def unload_constants | ||
original = Pundit | ||
Object.send(:remove_const, "Pundit") | ||
Administrate.send(:remove_const, "Punditize") | ||
load Rails.root.join( | ||
"..", | ||
"..", | ||
"app", | ||
"controllers", | ||
"concerns", | ||
"administrate", | ||
"punditize.rb", | ||
) | ||
|
||
yield | ||
|
||
Object.const_set("Pundit", original) | ||
end | ||
|
||
def dummy_class | ||
Class.new do | ||
include Administrate::Punditize | ||
end | ||
end | ||
|
||
def build_dummy | ||
stub_const("Dummy", dummy_class) | ||
Dummy.new | ||
end | ||
end | ||
end |