##// END OF EJS Templates
Fix an IndexError if all the :last menu items are deleted from a menu. #4718...
Eric Davis -
r3333:28e9bc5d823e
parent child
Show More
@@ -84,6 +84,14 module TreeNodePatch
84
84
85 end
85 end
86
86
87 # Wrapp remove! making sure to decrement the last_items counter if
88 # the removed child was a last item
89 def remove!(child)
90 @last_items_count -= +1 if child && child.last
91 super
92 end
93
94
87 # Will return the position (zero-based) of the current child in
95 # Will return the position (zero-based) of the current child in
88 # it's parent
96 # it's parent
89 def position
97 def position
@@ -352,7 +360,7 module Redmine
352 target_root.add(MenuItem.new(name, url, options))
360 target_root.add(MenuItem.new(name, url, options))
353 end
361 end
354
362
355 elsif options.delete(:last)
363 elsif options[:last] # don't delete, needs to be stored
356 target_root.add_last(MenuItem.new(name, url, options))
364 target_root.add_last(MenuItem.new(name, url, options))
357 else
365 else
358 target_root.add(MenuItem.new(name, url, options))
366 target_root.add(MenuItem.new(name, url, options))
@@ -386,7 +394,7 module Redmine
386
394
387 class MenuItem < Tree::TreeNode
395 class MenuItem < Tree::TreeNode
388 include Redmine::I18n
396 include Redmine::I18n
389 attr_reader :name, :url, :param, :condition, :parent, :child_menus
397 attr_reader :name, :url, :param, :condition, :parent, :child_menus, :last
390
398
391 def initialize(name, url, options)
399 def initialize(name, url, options)
392 raise ArgumentError, "Invalid option :if for menu item '#{name}'" if options[:if] && !options[:if].respond_to?(:call)
400 raise ArgumentError, "Invalid option :if for menu item '#{name}'" if options[:if] && !options[:if].respond_to?(:call)
@@ -403,6 +411,7 module Redmine
403 @html_options[:class] = [@html_options[:class], @name.to_s.dasherize].compact.join(' ')
411 @html_options[:class] = [@html_options[:class], @name.to_s.dasherize].compact.join(' ')
404 @parent = options[:parent]
412 @parent = options[:parent]
405 @child_menus = options[:children]
413 @child_menus = options[:children]
414 @last = options[:last] || false
406 super @name.to_sym
415 super @name.to_sym
407 end
416 end
408
417
@@ -17,7 +17,7
17
17
18 require File.dirname(__FILE__) + '/../../../../test_helper'
18 require File.dirname(__FILE__) + '/../../../../test_helper'
19
19
20 class Redmine::MenuManager::MapperTest < Test::Unit::TestCase
20 class Redmine::MenuManager::MapperTest < ActiveSupport::TestCase
21 context "Mapper#initialize" do
21 context "Mapper#initialize" do
22 should "be tested"
22 should "be tested"
23 end
23 end
@@ -163,4 +163,21 class Redmine::MenuManager::MapperTest < Test::Unit::TestCase
163 menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
163 menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
164 assert_nil menu_mapper.delete(:test_missing)
164 assert_nil menu_mapper.delete(:test_missing)
165 end
165 end
166
167 test 'deleting all items' do
168 # Exposed by deleting :last items
169 Redmine::MenuManager.map :test_menu do |menu|
170 menu.push :not_last, Redmine::Info.help_url
171 menu.push :administration, { :controller => 'projects', :action => 'show'}, {:last => true}
172 menu.push :help, Redmine::Info.help_url, :last => true
173 end
174
175 assert_nothing_raised do
176 Redmine::MenuManager.map :test_menu do |menu|
177 menu.delete(:administration)
178 menu.delete(:help)
179 menu.push :test_overview, { :controller => 'projects', :action => 'show'}, {}
180 end
181 end
182 end
166 end
183 end
General Comments 0
You need to be logged in to leave comments. Login now