Permalink
Browse files

fix missing constant error raised at allowed_child_classes if the all…

…owed_children_cache is trimmed by db
  • Loading branch information...
1 parent d87e9a7 commit 9753ad2b3ef162a9a5f0dd30668b219cb0c10840 @blj blj committed with johnmuhl Feb 8, 2012
Showing with 7 additions and 1 deletion.
  1. +1 −1 app/models/menu_renderer.rb
  2. +6 −0 spec/models/menu_renderer_spec.rb
@@ -35,7 +35,7 @@ def menu_renderer_modules
end
def allowed_child_classes
- (allowed_children_cache.to_s.split(',') - Array(excluded_class_names)).map(&:constantize)
+ (allowed_children_cache.to_s.split(',') - Array(excluded_class_names)).map{|name|name.constantize rescue nil}.compact
end
def default_child_item
@@ -118,6 +118,12 @@ module SpecialTestMenuRenderer; end
special_page.allowed_child_classes
}.should_not raise_error
end
+ it 'should not raise error when the allowed_children_cache is unable to find a class' do
+ special_page.allowed_children_cache = 'Page, SpecialChildPa' #the last class name is truncated by limit in database
+ lambda{
+ special_page.allowed_child_classes
+ }.should_not raise_error
+ end
end
describe '#default_child_item' do

0 comments on commit 9753ad2

Please sign in to comment.