Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Add Comment
Please, Sign In to add comment