Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Walkthrough 6-1: Rendering XML and JSON
- Loading branch information
Jen-Mei Wu
committed
Jan 20, 2011
1 parent
668caa0
commit 8acdd41
Showing
2 changed files
with
62 additions
and
32 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 |
---|---|---|
@@ -1,50 +1,79 @@ | ||
require 'spec_helper' | ||
|
||
describe "hotels" do | ||
before do | ||
@hotel1 = Factory.create( | ||
:hotel, | ||
:name => "The Lakes" | ||
) | ||
@hotel2 = Factory.create( | ||
:hotel, | ||
:name => "St. Clair Hotel" | ||
) | ||
end | ||
|
||
describe "listing hotels" do | ||
before do | ||
@hotel1 = Factory.create( | ||
:hotel, | ||
:name => "The Lakes" | ||
) | ||
@hotel2 = Factory.create( | ||
:hotel, | ||
:name => "St. Clair Hotel" | ||
) | ||
visit "/hotels" | ||
end | ||
describe "when format is html" do | ||
before do | ||
visit "/hotels" | ||
end | ||
|
||
it "should list as many hotels as we have" do | ||
page.all('ul li').should have(2).hotels | ||
end | ||
it "should list as many hotels as we have" do | ||
page.all('ul li').should have(2).hotels | ||
end | ||
|
||
it "should list all hotel names (xpath)" do | ||
page.should have_xpath( | ||
"//li[.='#{@hotel1.name}']" | ||
) | ||
page.should have_xpath( | ||
"//li[.='#{@hotel2.name}']" | ||
) | ||
end | ||
|
||
it "should list all hotel names (css)" do | ||
hotel_names = page.all('ul li').map(&:text) | ||
hotel_names.should include(@hotel1.name) | ||
hotel_names.should include(@hotel2.name) | ||
end | ||
|
||
describe "when clicking on a link" do | ||
before do | ||
click_link(@hotel1.name) | ||
end | ||
|
||
it "should show detailed information for our hotel" do | ||
page.should have_xpath( | ||
"//h1[.='#{@hotel1.name}']" | ||
) | ||
end | ||
end | ||
|
||
it "should list all hotel names (xpath)" do | ||
page.should have_xpath( | ||
"//li[.='#{@hotel1.name}']" | ||
) | ||
page.should have_xpath( | ||
"//li[.='#{@hotel2.name}']" | ||
) | ||
end | ||
|
||
it "should list all hotel names (css)" do | ||
hotel_names = page.all('ul li').map(&:text) | ||
hotel_names.should include(@hotel1.name) | ||
hotel_names.should include(@hotel2.name) | ||
describe "when the requested format is xml" do | ||
before do | ||
visit "/hotels.xml" | ||
end | ||
|
||
it "should render the found hotels as xml" do | ||
page.should have_xpath('//hotels[@type="array"]') | ||
end | ||
end | ||
|
||
describe "when clicking on a link" do | ||
describe "when the requested format is json" do | ||
before do | ||
click_link(@hotel1.name) | ||
visit '/hotels.json' | ||
end | ||
|
||
it "should show detailed information for our hotel" do | ||
page.should have_xpath( | ||
"//h1[.='#{@hotel1.name}']" | ||
) | ||
it "should render the found hotels as json" do | ||
hotels = JSON.parse(page.body) | ||
hotels.should be_an(Array) | ||
hotels.first["hotel"]["name"].should == "St. Clair Hotel" | ||
end | ||
end | ||
|
||
end | ||
|
||
end | ||
|