<commit_before>require File.dirname(__FILE__) + '/spec_helper'

class Application < Merb::Controller
  create_menu :main do
    submenu :cakes, :href => "/cakes" do
      item :cheese
      item :chocolate
      item :devils_food, :anchor => "Devil's Food"
    end

    submenu :beers, :href => "/beers" do
      item :budweiser
      item :rolling_rock
      item :fosters, :anchor => "Foster's"
      item :fat_tire
    end
  end
end

class Cakes < Application
  use_menu :main

  # this should be associated with item :cheese
  def cheese

    puts "The current menu is: #{Merb::Menus.current_menu.name}"
    'hello'
  end

  def chocolate
    menu_item :beers, :budweiser

    'word up'
  end

  def not_devils_food
    # associate this action with item :devils_food
    menu_item :devils_food

    ':)'
  end
end

class Beer < Application
end

class Snack < Application
  use_menu :main, :cakes

  def cheese_cake
    menu_item :cheese
    'foo'
  end
end

describe "menu generator" do
  before do
    @menu = Merb::Menus[:main]
  end

  it "should create the menu" do
    @menu.name.should == :main
  end

  it "should create all the submenus" do
    @menu.submenus.should have(2).things
    @menu.submenus.first.name.should == :cakes
  end

  it "should create the submenu items" do
    @menu.submenus.first.items.should have(3).things
    @menu.submenus.first.items.map{|e| e.name}.should == [:cheese, :chocolate, :devils_food]

    @menu.submenus[1].items.should have(4).things
    @menu.submenus[1].items.map{|e| e.name}.should == [:budweiser, :rolling_rock, :fosters, :fat_tire]
  end

  it "is accessible from child controllers"

  it "sets the current menu properly" do
    request('/cakes/cheese')
    top = Merb::Menus[:main]

    top.current_submenu.name.should == :cakes

    top.current_submenu.current_item.name.should == :cheese
  end

  it "overrides actions default menu item" do
    request('/cakes/chocolate')
    top = Merb::Menus[:main]
    top.current_submenu.name.should == :beers
    top.current_submenu.current_item.name.should == :budweiser
  end

end

<commit_msg>sum more controller integration<commit_after>require File.dirname(__FILE__) + '/spec_helper'

class Application < Merb::Controller
  create_menu :main do
    submenu :cakes, :href => "/cakes" do
      item :cheese
      item :chocolate
      item :devils_food, :anchor => "Devil's Food"
    end

    submenu :beers, :href => "/beers" do
      item :budweiser
      item :rolling_rock
      item :fosters, :anchor => "Foster's"
      item :fat_tire
    end
  end
end

class Cakes < Application
  use_menu :main

  # this should be associated with item :cheese
  def cheese

    puts "The current menu is: #{Merb::Menus.current_menu.name}"
    'hello'
  end

  def chocolate
    menu_item :beers, :budweiser

    'word up'
  end

  def not_devils_food
    # associate this action with item :devils_food
    menu_item :devils_food

    ':)'
  end
end

class Beers < Application
  def fat_tire
    'yoink'
  end
end

class Snack < Application
  use_menu :main, :cakes

  def cheese_cake
    menu_item :cheese
    'foo'
  end
end

describe "menu generator" do
  before do
    @menu = Merb::Menus[:main]
  end

  it "should create the menu" do
    @menu.name.should == :main
  end

  it "should create all the submenus" do
    @menu.submenus.should have(2).things
    @menu.submenus.first.name.should == :cakes
  end

  it "should create the submenu items" do
    @menu.submenus.first.items.should have(3).things
    @menu.submenus.first.items.map{|e| e.name}.should == [:cheese, :chocolate, :devils_food]

    @menu.submenus[1].items.should have(4).things
    @menu.submenus[1].items.map{|e| e.name}.should == [:budweiser, :rolling_rock, :fosters, :fat_tire]
  end

  it "is accessible from child controllers"

  it "sets the current menu properly" do
    request('/cakes/cheese')
    top = Merb::Menus[:main]
    top.current_submenu.name.should == :cakes
    top.current_submenu.current_item.name.should == :cheese
  end

  it "overrides actions default menu item" do
    request('/cakes/chocolate')
    top = Merb::Menus[:main]
    top.current_submenu.name.should == :beers
    top.current_submenu.current_item.name.should == :budweiser
  end

  it "finds the correct controller/action combo automagically" do
    request '/beers/fat_tire'
    Merb::Menus.current_menu.name.should == :main
    Merb::Menus.current_menu.current_submenu.should == :beers
    Merb::Menus.current_menu.current_submenu.current_item.should == :fat_tire
  end
end


{'fraction_non_alphanumeric': 0.11248345831495368, 'fraction_numerical': 0.0022055580061755625, 'mean_word_length': 3.242282507015903, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '479694', 'n_tokens_mistral': 1631, 'n_tokens_neox': 1570, 'n_words': 406}