Skip to content

Commit

Permalink
Merge pull request weppos#12 from cgs/master
Browse files Browse the repository at this point in the history
  • Loading branch information
weppos committed May 20, 2011
2 parents b0b5663 + f5b4cb8 commit 56cc057
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/tabs_on_rails/tabs.rb
Expand Up @@ -38,8 +38,8 @@ def initialize(context, options = {})
end # end
end

def method_missing(*args)
@builder.tab_for(*args)
def method_missing(*args, &block)
@builder.tab_for(*args, &block)
end

def render(&block)
Expand Down
42 changes: 42 additions & 0 deletions test/tabs_on_rails/tabs/custom_builder_test.rb
@@ -0,0 +1,42 @@
require 'test_helper'

class CustomBuilderTest < ActionView::TestCase
tests TabsOnRails::ActionController::HelperMethods

include ActionView::Helpers::TagHelper
include ActionView::Helpers::UrlHelper

def current_tab(namespace)
case namespace
when nil, :default
:dashboard
when :foospace
:footab
else
:elsetab
end
end

class CustomBuilder < 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(name, options)
content += @context.capture(&block) if block_given?
@context.content_tag(:li, content, item_options)
end
end

def setup
@klass = CustomBuilder
@builder = @klass.new(self)
end

def test_tab_for_with_block
expected = %Q{<li class="current"><a href="http://dashboard.com/">Foo Bar</a><p>More Content</p></li>}
actual = @builder.tab_for(:dashboard, 'Foo Bar', 'http://dashboard.com/') do
content_tag(:p, "More Content")
end

assert_dom_equal expected, actual
end
end

0 comments on commit 56cc057

Please sign in to comment.