Created
July 11, 2010 20:48
-
-
Save biot023/471821 to your computer and use it in GitHub Desktop.
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
require "spec_helper" | |
describe TabsCell, "show", :type => :cell_controller do | |
before( :each ) do | |
@cell = TabsCell.new | |
@selected_tab_title = "Tab Article" | |
assign_to_cell( :selected_tab_title, @selected_tab_title ) | |
@tab_articles = mock( :tab_articles_relation ) | |
TabArticle.stub!( :get_all_for_tabs ).and_return( @tab_articles ) | |
@cell.stub!( :render ) | |
end | |
def do_action | |
@cell.show | |
end | |
it "should get and assign all tab articles" do | |
TabArticle.should_receive( :get_all_for_tabs ).and_return( @tab_articles ) | |
do_action | |
assigned_to_cell( :tab_articles ).should == @tab_articles | |
end | |
it "should get and assign the selected_tab title" do | |
do_action | |
assigned_to_cell( :selected_tab_title ).should == @selected_tab_title | |
end | |
it "should render the cell" do | |
@cell.should_receive( :render ) | |
do_action | |
end | |
end | |
describe TabsCell, "helper methods", :type => :cell_controller do | |
before( :each ) do | |
@cell = TabsCell.new | |
end | |
describe "li_for_tab_article( tab_article, selected_tab_title )" do | |
before( :each ) do | |
@tab_article = Factory.stub( :tab_article, | |
title: "Home", | |
tab_title: "Home", | |
url_title: "home" ) | |
end | |
def do_call | |
@li = Nokogiri::HTML( @cell.send( :li_for_tab_article, @tab_article, @selected_tab_title ) ).xpath( "/*" ).first | |
end | |
it "should render an li item containing a link containing an image" do | |
do_call | |
@li.xpath( "//li" ).size.should == 1 | |
@li.xpath( "//li/a/img" ).should_not be_empty | |
end | |
it "should give the li item the url title as an id" do | |
do_call.xpath( "//li[@id = '#{ @tab_article.url_title }']" ).should_not be_empty | |
end | |
context "when the tab_article has a tab title of 'Home'" do | |
it "should set the link to go to the home page" do | |
do_call.xpath( "//a[@href = '#{ home_path }']" ).should_not be_empty | |
end | |
context "when there is no selected tab title" do | |
it "should render the li with the 'selected' class" do | |
do_call.xpath( "//li[@class = 'selected']" ).should_not be_empty | |
end | |
it "should use the tab article's selected image" do | |
do_call.xpath( "//img[@src = '#{ @tab_article.selected_image.url }']" ).should_not be_empty | |
end | |
end | |
context "when the selected tab title matches the tab article's" do | |
before( :each ) do | |
@selected_tab_title = "Home" | |
end | |
it "should render the li with the 'selected' class" do | |
do_call.xpath( "//li[@class = 'selected']" ).should_not be_empty | |
end | |
it "should use the tab article's selected image" do | |
do_call.xpath( "//img[@src = '#{ @tab_article.selected_image.url }']" ).should_not be_empty | |
end | |
end | |
context "when the selected tab title does not match the tab article's" do | |
before( :each ) do | |
@selected_tab_title = "No Match" | |
end | |
it "should not render the li with the 'selected' class" do | |
do_call.xpath( "//li[@class = 'selected']" ).should be_empty | |
end | |
it "should use the tab article's image" do | |
do_call.xpath( "//img[@src = '#{ @tab_article.image.url }']" ).should_not be_empty | |
end | |
end | |
end | |
context "when the tab_article does not have a tab title of 'Home'" do | |
before( :each ) do | |
@tab_article = Factory.stub( :tab_article, | |
title: "About", | |
tab_title: "About", | |
url_title: "about" ) | |
end | |
it "should set the link to go to the tab article page for the tab article" do | |
do_call.xpath( "//a[@href = '#{ tab_article_path( @tab_article.url_title ) }']" ).should_not be_empty | |
end | |
context "when there is no selected tab title" do | |
it "should not render the li with the 'selected' class" do | |
do_call.xpath( "//li[@class = 'selected']" ).should be_empty | |
end | |
it "should use the tab article's image" do | |
do_call.xpath( "//img[@src = '#{ @tab_article.image.url }']" ).should_not be_empty | |
end | |
end | |
context "when the selected tab title matches the tab article's" do | |
before( :each ) do | |
@selected_tab_title = "About" | |
end | |
it "should render the li with the 'selected' class" do | |
do_call.xpath( "//li[@class = 'selected']" ).should_not be_empty | |
end | |
it "should use the tab article's selected image" do | |
do_call.xpath( "//img[@src = '#{ @tab_article.selected_image.url }']" ).should_not be_empty | |
end | |
end | |
context "when the selected tab title does not match the tab article's" do | |
before( :each ) do | |
@selected_tab_title = "No Match" | |
end | |
it "should not render the li with the 'selected' class" do | |
do_call.xpath( "//li[@class = 'selected']" ).should be_empty | |
end | |
it "should use the tab article's image" do | |
do_call.xpath( "//img[@src = '#{ @tab_article.image.url }']" ).should_not be_empty | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment