lk & sh | posts to bike index in development when creating new bike

This commit is contained in:
Loos
2015-08-06 20:29:46 -05:00
parent 66c43e57c2
commit 3224faab0e
12 changed files with 137 additions and 2 deletions
+1
View File
@@ -6,5 +6,6 @@ FactoryGirl.define do
bike_type "Fixed Gear"
color "Black"
sequence(:serial_number)
sequence(:bike_index_id)
end
end
+14
View File
@@ -1,4 +1,18 @@
require 'spec_helper'
describe Bike do
it "posts to bike index" do
WebMock.stub_request(:post, "http://lvh.me:3000/api/v2/bikes?access_token=asdfklkjasfdljkd3asdfjkl2asdf")
.and_return(:status => 201, :body => {bike: {id: 1}}.to_json, :headers => {})
bike = create(:bike, bike_index_id: nil)
expect(bike.bike_index_id).to eq(1)
end
it "assigns bike_index_id after posting to bike index" do
WebMock.stub_request(:post, "http://lvh.me:3000/api/v2/bikes?access_token=asdfklkjasfdljkd3asdfjkl2asdf")
.and_return(:status => 400, :body => {error: "error"}.to_json, :headers => {})
bike = create(:bike, bike_index_id: nil)
expect(bike.bike_index_id).to_not be_present
end
end
@@ -0,0 +1,42 @@
require 'spec_helper'
describe BikeIndexBikeGenerator do
it "creates a bike with required attributes" do
bike = create(:bike)
bikeIndexBikeJson = BikeIndexBikeGenerator.create_bike_index_bike(bike)
bikeIndexBike = JSON.parse(bikeIndexBikeJson)
expect(bikeIndexBike["serial"]).to eq(bike.serial_number)
expect(bikeIndexBike["manufacturer"]).to eq(bike.brand)
expect(bikeIndexBike["frame_model"]).to eq(bike.model)
expect(bikeIndexBike["owner_email"]).to eq(ENV["OWNER_EMAIL"])
expect(bikeIndexBike["no_notify"]).to be_truthy
expect(bikeIndexBike["color"]).to eq(bike.color)
end
describe "freecyclery bikes" do
it "is_for_sale is false" do
bike = create(:bike, purpose: "freecyclery")
bikeIndexBikeJson = BikeIndexBikeGenerator.create_bike_index_bike(bike)
bikeIndexBike = JSON.parse(bikeIndexBikeJson)
expect(bikeIndexBike["is_for_sale"]).to be_falsey
end
end
describe "sale bikes" do
it "is_for_sale is true" do
bike = create(:bike, purpose: "sale")
bikeIndexBikeJson = BikeIndexBikeGenerator.create_bike_index_bike(bike)
bikeIndexBike = JSON.parse(bikeIndexBikeJson)
expect(bikeIndexBike["is_for_sale"]).to be_truthy
end
end
end
+1
View File
@@ -14,4 +14,5 @@ RSpec.configure do |config|
config.include Devise::TestHelpers, type: :controller
config.include FactoryGirl::Syntax::Methods
config.order = "random"
WebMock.disable_net_connect!(allow_localhost: true)
end