forked from weppos/tabs_on_rails
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request weppos#12 from cgs/master
- Loading branch information
Showing
2 changed files
with
44 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |