Skip to content

Commit

Permalink
fix autoextend detecting nested modules from autoloading
Browse files Browse the repository at this point in the history
fixes CNVS-34248

Change-Id: I8b4c899568f06886354d66f1a1462141a557d3da
Reviewed-on: https://gerrit.instructure.com/99225
Tested-by: Jenkins
Reviewed-by: Simon Williams <[email protected]>
Product-Review: Cody Cutrer <[email protected]>
QA-Review: Cody Cutrer <[email protected]>
  • Loading branch information
ccutrer authored and simonista committed Jan 10, 2017
1 parent a898652 commit 6ea37ac
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
16 changes: 14 additions & 2 deletions gems/autoextend/lib/autoextend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,21 @@ def included(klass)

module Autoextend::ActiveSupport
module Dependencies
def notify_autoextend_of_new_constant(constant)
Autoextend.const_added(constant, source: :'ActiveSupport::Dependencies')
# check for nested constants
constant.constants(false).each do |child|
child_const = constant.const_get(child, false)
next unless child_const.is_a?(Module)
notify_autoextend_of_new_constant(child_const)
end
end

def new_constants_in(*_descs)
super.each do |constant|
Autoextend.const_added(constant, source: :'ActiveSupport::Dependencies')
super.each do |constant_name|
constant = Object.const_get(constant_name, false)
next unless constant.is_a?(Module)
notify_autoextend_of_new_constant(constant)
end
end

Expand Down
11 changes: 7 additions & 4 deletions gems/autoextend/spec/autoextend_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,19 @@ module AutoextendSpec::MyExtension; end
# be run in the same process as other specs
describe "ActiveSupport" do
it "should hook an autoloaded module" do
hooked = false
hooked = 0
Autoextend.hook(:"AutoextendSpec::TestModule") do
hooked = true
hooked += 1
end
Autoextend.hook(:"AutoextendSpec::TestModule::Nested") do
hooked += 1
end
defined?(AutoextendSpec::TestModule).must_equal(nil)
hooked.must_equal(false)
hooked.must_equal(0)
_x = AutoextendSpec::TestModule
# this could have only been detected by Rails' autoloading
defined?(AutoextendSpec::TestModule).must_equal('constant')
hooked.must_equal(true)
hooked.must_equal(2)
end
end
end
3 changes: 2 additions & 1 deletion gems/autoextend/spec/autoextend_spec/test_module.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module AutoextendSpec::TestModule

module Nested
end
end
1 change: 1 addition & 0 deletions spec/models/general_model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def protect_attributes
it "protects attributes somehow" do
ignore_classes = [
ActiveRecord::Base,
CASClient::Tickets::Storage::CasPgtiou,
Delayed::Backend::ActiveRecord::Job,
Delayed::Backend::ActiveRecord::Job::Failed,
EventStream::Failure,
Expand Down

0 comments on commit 6ea37ac

Please sign in to comment.