Loos
9 years ago
12 changed files with 137 additions and 2 deletions
@ -0,0 +1,3 @@ |
|||||
|
OWNER_EMAIL: 'coolemail@example.com' |
||||
|
BIKE_INDEX_URL: 'http://lvh.me:3000' |
||||
|
BIKE_INDEX_TOKEN: 'asdfklkjasfdljkd3asdfjkl2asdf' |
@ -0,0 +1,13 @@ |
|||||
|
class BikeIndexBikeGenerator |
||||
|
def self.create_bike_index_bike(bike) |
||||
|
{ |
||||
|
serial: bike.serial_number, |
||||
|
manufacturer: bike.brand, |
||||
|
owner_email: ENV["OWNER_EMAIL"], |
||||
|
color: bike.color, |
||||
|
is_for_sale: bike.purpose != "freecyclery", |
||||
|
frame_model: bike.model, |
||||
|
no_notify: true |
||||
|
}.to_json |
||||
|
end |
||||
|
end |
@ -0,0 +1,5 @@ |
|||||
|
class AddBikeIndexIdToBikes < ActiveRecord::Migration |
||||
|
def change |
||||
|
add_column :bikes, :bike_index_id, :integer |
||||
|
end |
||||
|
end |
@ -1,4 +1,18 @@ |
|||||
require 'spec_helper' |
require 'spec_helper' |
||||
|
|
||||
describe Bike do |
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 |
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 |
Loading…
Reference in new issue