# encoding: utf-8 require 'spec_helper' require 'action_view' require 'active_support' include RailsBootstrapNavbar::ViewHelpers include ActionView::Helpers include ActionView::Context describe RailsBootstrapNavbar::ViewHelpers, :type => :helper do before { self.stub!("current_page?").and_return(false) } describe "nav_bar" do it "should return a basic bootstrap navbar" do nav_bar.gsub(/\s/,'').downcase.should eql(BASIC_NAVBAR.gsub(/\s/,'').downcase) end it "should set the fixed position to top" do nav_bar(:fixed => :top).gsub(/\s/,'').downcase.should eql(FIXED_TOP_NAVBAR.gsub(/\s/,'').downcase) end it "should set the fixed position to bottom" do nav_bar(:fixed => :bottom).gsub(/\s/,'').downcase.should eql(FIXED_BOTTOM_NAVBAR.gsub(/\s/,'').downcase) end it "should add the brand name and link it to the home page" do nav_bar(:brand => "Ninety Ten").gsub(/\s/,'').downcase.should eql(NAVBAR_WITH_BRAND.gsub(/\s/,'').downcase) end it "should set the container to fluid" do nav_bar(:fluid => :true).gsub(/\s/,'').downcase.should eql(BASIC_NAVBAR_FLUID.gsub(/\s/,'').downcase) end it "should add the buttons etc for a responsive layout with no block passed" do nav_bar(:responsive => true).gsub(/\s/,'').downcase.should eql(RESPONSIVE_NAVBAR.gsub(/\s/,'').downcase) end it "should add the buttons etc for a responsive layout with block passed" do nav_bar(:responsive => true) do "

Passing a block

".html_safe end.gsub(/\s/,'').downcase.should eql(RESPONSIVE_NAVBAR_WITH_BLOCK.gsub(/\s/,'').downcase) end it "should render contained items" do nav_bar do menu_group do menu_item("Home", "/") + menu_item("Products", "/products") end end.gsub(/\s/,'').downcase.should eql(PLAIN_NAVBAR_WITH_ITEM.gsub(/\s/,'').downcase) end it "should still render the brand name even with other options turned on" do nav_bar(:brand => "Something") do menu_group do menu_item "Home", "/" end end.gsub(/\s/,'').downcase.should eql(BRANDED_NAVBAR_WITH_ITEM.gsub(/\s/,'').downcase) end end describe "menu_group" do it "should return a ul with the class 'nav'" do menu_group do menu_item("Home", "/") + menu_item("Products", "/products") end.should eql '' end it "should return a ul with class .pull-left when passed the {:pull => :left} option" do menu_group(:pull => :left) do menu_item("Home", "/") end.should eql('') end end describe "menu_item" do it "should return a link within an li tag" do self.stub!("current_page?").and_return(false) menu_item("Home", "/").should eql('
  • Home
  • ') end it "should return the link with class 'active' if on current page" do self.stub!("current_page?").and_return(true) menu_item("Home", "/").should eql('
  • Home
  • ') end end describe "drop_down" do it "should do render the proper drop down code" do drop_down "Products" do menu_item "Latest", "/" end.gsub(/\s/,'').downcase.should eql(DROPDOWN_MENU.gsub(/\s/,'').downcase) end end describe "menu_divider" do it "should render
  • " do menu_divider.should eql '
  • ' end end describe "menu_text" do it "should render text within p tags" do menu_text("Strapline!").should eql("

    Strapline!

    ") end it "should be able to cope with a block too" do menu_text do "I've been rendered programmatically!" end.should eql("

    I've been rendered programmatically!

    ") end end describe "rendering forms ok" do it "should not escape anything unexpectedly" do nav_bar do form_tag "/", :method => 'get' do |f| f.text_field :search, "stub" end end.gsub(/\s/,'').downcase.should eql(PLAIN_NAVBAR_WITH_FORM.gsub(/\s/,'').downcase) end end end # HTML output BASIC_NAVBAR = <<-HTML HTML FIXED_TOP_NAVBAR = <<-HTML HTML FIXED_BOTTOM_NAVBAR = <<-HTML HTML BASIC_NAVBAR_FLUID= <<-HTML HTML NAVBAR_WITH_BRAND = <<-HTML HTML RESPONSIVE_NAVBAR = <<-HTML HTML RESPONSIVE_NAVBAR_WITH_BLOCK = <<-HTML HTML PLAIN_NAVBAR_WITH_ITEM = <<-HTML HTML BRANDED_NAVBAR_WITH_ITEM = <<-HTML HTML DROPDOWN_MENU = <<-HTML HTML PLAIN_NAVBAR_WITH_FORM = <<-HTML HTML