Skip to content

Commit

Permalink
Merge pull request #2821 from AlchemyCMS/backport/7.0-stable/pr-2820
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdeyen authored Apr 4, 2024
2 parents c4f47b6 + 9e8d922 commit 26e2497
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/alchemy/modules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ def register_module(module_definition)
defined_controllers.concat(definition_hash["navigation"]["sub_navigation"].map { |x| x["controller"] })
end

validate_controllers_existence(defined_controllers)
validate_controllers_existence(defined_controllers, definition_hash)
end

@@alchemy_modules |= [definition_hash]
end

private

def validate_controllers_existence(controllers)
def validate_controllers_existence(controllers, definition_hash)
controllers.each do |controller_val|
next if controller_val.blank?

Expand Down
8 changes: 6 additions & 2 deletions spec/libraries/modules_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,15 @@ class ModulesTestController < ApplicationController
end

it "fails to register a module when a matching navigation controller cannot be found" do
expect { Modules.register_module(bad_alchemy_module_a) }.to raise_error(NameError)
expect { Modules.register_module(bad_alchemy_module_a) }.to raise_error(
"Error in AlchemyCMS module definition: 'bad_module_a'. Could not find the matching controller class BadModuleController for the specified controller: 'bad_module'"
)
end

it "fails to register a module when a matching sub_navigation controller cannot be found" do
expect { Modules.register_module(bad_alchemy_module_b) }.to raise_error(NameError)
expect { Modules.register_module(bad_alchemy_module_b) }.to raise_error(
"Error in AlchemyCMS module definition: 'bad_module_b'. Could not find the matching controller class BadModuleController for the specified controller: 'bad_module'"
)
end

it "registers a module definition only once" do
Expand Down

0 comments on commit 26e2497

Please sign in to comment.