Skip to content

Commit

Permalink
Fix loading of Punditize
Browse files Browse the repository at this point in the history
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
purinkle committed Aug 9, 2019
1 parent 8e13a25 commit df9fb3c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app/controllers/concerns/administrate/punditize.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
if Object.const_defined?("Pundit")
module Administrate
module Punditize
module Administrate
module Punditize
if Object.const_defined?("Pundit")
extend ActiveSupport::Concern
include Pundit

Expand Down
41 changes: 41 additions & 0 deletions spec/controllers/concerns/administrate/punditize_spec.rb
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

0 comments on commit df9fb3c

Please sign in to comment.