Skip to content

Commit

Permalink
Merge pull request #2822 from AlchemyCMS/backport/7.1-stable/pr-2820
Browse files Browse the repository at this point in the history
[7.1-stable] Fix module error
  • Loading branch information
tvdeyen authored Apr 4, 2024
2 parents 41f03d3 + 6430d1a commit ae9353d
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 ae9353d

Please sign in to comment.