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
+5
View File
@@ -0,0 +1,5 @@
FactoryGirl.define do
factory :bike_brand do
brand {Faker::Commerce.product_name}
end
end
+5
View File
@@ -0,0 +1,5 @@
FactoryGirl.define do
factory :bike_condition do
condition "POOR"
end
end
+5
View File
@@ -0,0 +1,5 @@
FactoryGirl.define do
factory :bike_purpose do
purpose "SHOP"
end
end
+5
View File
@@ -0,0 +1,5 @@
FactoryGirl.define do
factory :bike_style do
style {Faker::Commerce.product_name}
end
end
+12
View File
@@ -0,0 +1,12 @@
FactoryGirl.define do
factory :bike_wheel_size do
twmm 40
rdmm 635
twin "1 1/2 [1 3/8]"
rdin 28
twfr "38B [35B]"
rdfr 700
description "a big wheel"
tire_common_score 1
end
end
+17
View File
@@ -2,6 +2,23 @@
FactoryGirl.define do
factory :bike do
sequence(:shop_id) {|n| n}
sequence :serial_number do |n|
"#{Faker::Code.isbn}-#{n}"
end
bike_brand { FactoryGirl.create(:bike_brand) }
model { Faker::Commerce.product_name }
color "FFFFFF"
bike_style { FactoryGirl.create(:bike_style) }
seat_tube_height 42
top_tube_length 42
bike_wheel_size { FactoryGirl.create(:bike_wheel_size) }
value 200
bike_condition { FactoryGirl.create(:bike_condition) }
bike_purpose { FactoryGirl.create(:bike_purpose) }
end
factory :seed_bike do
sequence(:shop_id) {|n| n}
sequence :serial_number do |n|
"#{Faker::Code.isbn}-#{n}"