Project

General

Profile

« Previous | Next » 

Revision 902c71ef

Added by Dmitri Dolguikh about 10 years ago

fixes #5537: it's possible to specify menu item url directly now

View differences:

app/services/menu/item.rb
raise ArgumentError, "Cannot set the :parent to be the same as this item" if options[:parent] == name.to_sym
raise ArgumentError, "Invalid option :children for menu item '#{name}'" if options[:children] && !options[:children].respond_to?(:call)
@name = name
@url = options[:url]
@url_hash = options[:url_hash]
@condition = options[:if]
@caption = options[:caption]
......
end
def url
add_relative_path(@context.routes.url_for(url_hash.merge(:only_path=>true)))
add_relative_path(@url || @context.routes.url_for(url_hash.merge(:only_path=>true)))
end
def url_hash
test/unit/menu_item_test.rb
assert Menu::Item.new(:test_good_menu, :url_hash => {:controller=>'test', :action=>'index'}, :after => :me)
end
def test_menu_item_should_use_url_parameter_when_available
item = Menu::Item.new(:test_good_menu, :url => '/overriden/url', :url_hash => {:controller=>'test', :action=>'index'}, :after => :me)
assert_equal '/overriden/url', item.url
end
def test_menu_item_uses_url_hash_by_default
item = Menu::Item.new(:test_good_menu, :url_hash => {:controller=>'test', :action=>'index'}, :after => :me)
ActionDispatch::Routing::RouteSet.any_instance.expects(:url_for).with(:controller=>'test', :action=>'index', :only_path => true).returns('/url')
assert_equal '/url', item.url
end
def test_new_menu_item_should_require_a_proc_to_use_for_the_if_condition
assert_raises ArgumentError do
Menu::Item.new(:test_error, :if => ['not_a_proc'] )
......
assert_equal get_menu_item(:test_menu, :child_menu), parent_item.children[0]
assert_equal get_menu_item(:test_menu, :child2_menu), parent_item.children[1]
end
end
end

Also available in: Unified diff