mirror of https://github.com/fspc/BikeShed-1.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
1.8 KiB
71 lines
1.8 KiB
require 'spec_helper'
|
|
|
|
describe Api::V1::BikesController do
|
|
|
|
describe "#create" do
|
|
context "as a user" do
|
|
before(:each) do
|
|
@user = FactoryGirl.create(:user)
|
|
sign_in @user
|
|
end
|
|
it "returns 403" do
|
|
post :create
|
|
expect(@response.code.to_i).to eql 403
|
|
end
|
|
|
|
it "returns an error message" do
|
|
post :create
|
|
json = JSON.parse(@response.body)
|
|
expect(json["errors"].first).to eql Api::V1::BikesController::CANNOT_MANAGE
|
|
end
|
|
end
|
|
|
|
context "as a bike admin" do
|
|
before(:each) do
|
|
@user = FactoryGirl.create(:bike_admin)
|
|
sign_in @user
|
|
end
|
|
|
|
context "with no bike in json data" do
|
|
it "returns 400" do
|
|
post :create
|
|
expect(@response.code.to_i).to eql 400
|
|
end
|
|
|
|
it "returns an error message" do
|
|
post :create
|
|
json = JSON.parse(@response.body)
|
|
expect(json["errors"].first).to eql Api::V1::BikesController::EXPECTED_BIKE
|
|
end
|
|
end
|
|
|
|
context "with valid bike in json data" do
|
|
before(:each) do
|
|
@submit_json = { bike: {
|
|
serial_number: "XKCD",
|
|
bike_brand_id: 1,
|
|
shop_id: 1,
|
|
model: "Bike Model",
|
|
bike_style_id: 1,
|
|
seat_tube_height: 52,
|
|
bike_condition_id: 1,
|
|
bike_purpose_id: 1,
|
|
bike_wheel_size_id: 1,
|
|
}}
|
|
end
|
|
|
|
it "returns 200" do
|
|
post :create, @submit_json
|
|
expect(@response.code.to_i).to eql 200
|
|
end
|
|
|
|
it "returns the created bike json" do
|
|
post :create, @submit_json
|
|
json = JSON.parse(@response.body)
|
|
expect(json).to have_key("bike")
|
|
expect(json.to_s).to include(@submit_json[:bike][:serial_number])
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|