end
+ # Wrapp remove! making sure to decrement the last_items counter if
+ # the removed child was a last item
+ def remove!(child)
+ @last_items_count -= +1 if child && child.last
+ super
+ end
+
+
# Will return the position (zero-based) of the current child in
# it's parent
def position
target_root.add(MenuItem.new(name, url, options))
end
- elsif options.delete(:last)
+ elsif options[:last] # don't delete, needs to be stored
target_root.add_last(MenuItem.new(name, url, options))
else
target_root.add(MenuItem.new(name, url, options))
class MenuItem < Tree::TreeNode
include Redmine::I18n
- attr_reader :name, :url, :param, :condition, :parent, :child_menus
+ attr_reader :name, :url, :param, :condition, :parent, :child_menus, :last
def initialize(name, url, options)
raise ArgumentError, "Invalid option :if for menu item '#{name}'" if options[:if] && !options[:if].respond_to?(:call)
@html_options[:class] = [@html_options[:class], @name.to_s.dasherize].compact.join(' ')
@parent = options[:parent]
@child_menus = options[:children]
+ @last = options[:last] || false
super @name.to_sym
end
require File.dirname(__FILE__) + '/../../../../test_helper'
-class Redmine::MenuManager::MapperTest < Test::Unit::TestCase
+class Redmine::MenuManager::MapperTest < ActiveSupport::TestCase
context "Mapper#initialize" do
should "be tested"
end
menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
assert_nil menu_mapper.delete(:test_missing)
end
+
+ test 'deleting all items' do
+ # Exposed by deleting :last items
+ Redmine::MenuManager.map :test_menu do |menu|
+ menu.push :not_last, Redmine::Info.help_url
+ menu.push :administration, { :controller => 'projects', :action => 'show'}, {:last => true}
+ menu.push :help, Redmine::Info.help_url, :last => true
+ end
+
+ assert_nothing_raised do
+ Redmine::MenuManager.map :test_menu do |menu|
+ menu.delete(:administration)
+ menu.delete(:help)
+ menu.push :test_overview, { :controller => 'projects', :action => 'show'}, {}
+ end
+ end
+ end
end