Created
November 24, 2010 02:38
-
-
Save whalec/713001 to your computer and use it in GitHub Desktop.
These specs are failing in certain orders.
This file contains hidden or 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 File.expand_path(File.dirname(__FILE__) + '/acceptance_helper') | |
describe "Finding a phone" do | |
before do | |
5.times { make_phone! } | |
5.times { Plan.make } | |
@phones = Phone.find(:all) | |
@plan = Plan.find(:all) | |
end | |
after do | |
Phone.destroy_all | |
Plan.destroy_all | |
end | |
it "should Find Phones" do | |
get "/phones.json" | |
result = ActiveSupport::JSON.decode(last_response.body) | |
result.should have_key("phones") | |
result["phones"].length.should eql(5) | |
end | |
it "should Find a Phone" do | |
get "/phones/#{@phones.first.id}.json" | |
result = ActiveSupport::JSON.decode(last_response.body) | |
result.should have_key("phone") | |
result["phone"]["model"].should eql(@phones.first.name) | |
end | |
end | |
describe "Creating a phone" do | |
before do | |
@plan = Plan.make | |
end | |
it "should create Phone successfully" do | |
@attributes = { | |
:manufacturer_name => "Nokia", | |
:model => Sham.name, | |
:url => Sham.url, | |
:features_attributes => ["First feature", "Second Feature"], | |
:plans_attributes => [{:plan_id => @plan.id, :monthlyHandSetCost => 20}] | |
} | |
post "/phones.json", :phone => @attributes | |
result = ActiveSupport::JSON.decode(last_response.body) | |
result.should have_key("phone") | |
result["phone"]["model"].should eql(@attributes[:model]) | |
end | |
it "should create Phone unsuccessfully" do | |
@attributes = { | |
:manufacturer_name => "Nokia", | |
} | |
post "/phones.json", :phone => @attributes | |
result = ActiveSupport::JSON.decode(last_response.body) | |
result.should have_key("errors") | |
result["errors"]["phone"]["name"].should include("can't be blank") | |
result["errors"]["phone"]["url"].should include("can't be blank") | |
end | |
end | |
describe "Updating a phone" do | |
it "should update a Phone successfully" do | |
@phone = make_phone! | |
put "/phones/#{@phone.id}.json", :phone => { :model => "Foo" } | |
result = ActiveSupport::JSON.decode(last_response.body) | |
result.should have_key("phone") | |
result["phone"]["model"].should eql("Foo") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment