require 'test_helper' class MixinTestController < ActionController::Base end class MixinTest < ActionController::TestCase tests MixinTestController def test_set_tab controller.set_tab :footab assert_equal(:footab, controller.tab_stack[:default]) end def test_set_tab_with_namespace controller.set_tab :footab, :namespace assert_equal(:footab, controller.tab_stack[:namespace]) end def test_set_tab_with_default_namespace controller.set_tab :footab, :default assert_equal(:footab, controller.tab_stack[:default]) end def test_set_tab_with_and_without_namespace controller.set_tab :firsttab controller.set_tab :secondtab, :custom assert_equal(:firsttab, controller.tab_stack[:default]) assert_equal(:secondtab, controller.tab_stack[:custom]) end def test_current_tab controller.tab_stack[:default] = :mytab assert_equal(:mytab, controller.current_tab) end def test_current_tab_with_namespace controller.tab_stack[:namespace] = :mytab assert_equal(:mytab, controller.current_tab(:namespace)) end def test_current_tab_with_default_namespace controller.tab_stack[:default] = :mytab assert_equal(:mytab, controller.current_tab(:default)) end def test_set_tab_with_and_without_namespace controller.tab_stack[:default] = :firsttab controller.tab_stack[:custom] = :secondtab assert_equal(:firsttab, controller.current_tab(:default)) assert_equal(:secondtab, controller.current_tab(:custom)) end def test_current_tab_question controller.tab_stack[:default] = :mytab assert( controller.current_tab?(:mytab)) assert(!controller.current_tab?(:yourtab)) end def test_current_tab_question_with_namespace controller.tab_stack[:custom] = :mytab assert( controller.current_tab?(:mytab, :custom)) assert(!controller.current_tab?(:yourtab, :custom)) end def test_current_tab_question_with_default_namespace controller.tab_stack[:default] = :mytab assert( controller.current_tab?(:mytab, :default)) assert(!controller.current_tab?(:yourtab, :default)) end def test_current_tab_question_with_and_without_namespace controller.tab_stack[:default] = :firsttab controller.tab_stack[:custom] = :secondtab assert( controller.current_tab?(:firsttab, :default)) assert(!controller.current_tab?(:secondtab, :default)) assert( controller.current_tab?(:secondtab, :custom)) assert(!controller.current_tab?(:firsttab, :custom)) end end class WorkingMixinTestController < ActionController::Base def self.controller_name; "working"; end def self.controller_path; "working"; end layout false set_tab :dashboard set_tab :welcome, :only => %w( action_welcome ) set_tab :dashboard, :only => %w( action_namespace ) set_tab :homepage, :namespace, :only => %w( action_namespace ) def action_dashboard execute("action_dashboard") end def action_namespace execute("action_namespace") end def action_welcome execute("action_welcome") end private def execute(method) if method.to_s =~ /^action_(.*)/ render :action => (params[:template] || 'default') end end class BlockBuilder < TabsOnRails::Tabs::TabsBuilder def tab_for(tab, name, options, item_options = {}, &block) item_options[:class] = item_options[:class].to_s.split(" ").push("current").join(" ") if current_tab?(tab) content = @context.link_to_unless(current_tab?(tab), name, options) do @context.content_tag(:span, name) end content += @context.capture(&block) if block_given? @context.content_tag(:li, content, item_options) end end end class WorkingMixinTest < ActionController::TestCase tests WorkingMixinTestController def test_render_default get :action_dashboard assert_dom_equal(%Q{