Added bike show api method

This commit is contained in:
Jason Denney
2014-03-08 15:03:52 -05:00
parent 523046b042
commit dc0a567a27
11 changed files with 111 additions and 10 deletions
+44 -4
View File
@@ -1,6 +1,7 @@
require 'spec_helper'
describe Api::V1::BikesController do
render_views
describe "#create" do
context "as a user" do
@@ -41,7 +42,7 @@ describe Api::V1::BikesController do
context "with valid bike in json data" do
before(:each) do
@submit_json = { bike: {
@submit_json = { bikes: [{
serial_number: "XKCD",
bike_brand_id: 1,
shop_id: 1,
@@ -51,11 +52,12 @@ describe Api::V1::BikesController do
bike_condition_id: 1,
bike_purpose_id: 1,
bike_wheel_size_id: 1,
}}
}]}
end
it "returns 200" do
post :create, @submit_json
puts @response.inspect
expect(@response.code.to_i).to eql 200
end
@@ -69,9 +71,9 @@ describe Api::V1::BikesController do
context "with invalid bike in json data" do
before(:each) do
@submit_json = { bike: {
@submit_json = { bikes: [{
serial_number: "XKCD",
}}
}]}
end
it "returns 422" do
@@ -88,4 +90,42 @@ describe Api::V1::BikesController do
end
end
end
describe "#show" do
context "as a user" do
before(:each) do
@user = FactoryGirl.create(:user)
sign_in @user
end
context "no bike exists" do
it "returns 404" do
get :show, id: 999
expect(@response.code.to_i).to eql 404
end
it "returns an error message" do
get :show, id: 999
json = JSON.parse(@response.body)
expect(json["errors"].first).to eql Api::V1::BikesController::NOT_FOUND
end
end
context "a bike exists" do
let!(:bike){ FactoryGirl.create(:bike) }
it "returns 200" do
get :show, id: bike.id, format: :json
expect(@response.code.to_i).to eql 200
end
it "returns the bike json" do
get :show, id: bike.id, format: :json
json = JSON.parse(@response.body)
expect(json).to have_key("bikes")
expect(json.to_s).to include(bike.serial_number)
end
end
end
end
end