-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
73 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,5 +81,6 @@ function moveToStepTwo() { | |
} | ||
|
||
function moveToStepThree() { | ||
// make ajax post request to new bracks | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,24 @@ | ||
class Api::V1::BracksController < ApplicationController | ||
class Api::V1::BracksController < ActionController::API | ||
|
||
def index | ||
latlng = params[:latlng] | ||
@bracks = Brack.sort_by_distance(latlng) | ||
render json: @bracks, latlng: latlng | ||
end | ||
|
||
def create | ||
@brack = Brack.add_new(brack_params) | ||
if @brack.save | ||
render json: @brack | ||
else | ||
render json: @bracj.errors.full_messages, status: 500 | ||
end | ||
end | ||
|
||
private | ||
|
||
def brack_params | ||
params.require(:brack).permit(:user_id, :lat, :long) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require 'rails_helper' | ||
|
||
describe "Bracks Create API" do | ||
let(:user1) {create(:user)} | ||
let(:user2) {create(:user, organization: nil)} | ||
let(:brack) {build(:brack, cross_streets: nil)} | ||
it "adds a new brack location owned by user with an organization" do | ||
expect(Brack.count).to eq(0) | ||
|
||
post '/api/v1/bracks', params: {brack: {user_id: user1.id, lat: brack.lat, long: brack.long}} | ||
|
||
expect(response).to be_success | ||
expect(Brack.count).to eq(1) | ||
|
||
new_brack = Brack.all[0] | ||
|
||
expect(new_brack.lat).to eq(39.749598) | ||
expect(new_brack.long).to eq(brack.long) | ||
expect(new_brack.cross_streets).to eq("15th St & Blake St") | ||
expect(new_brack.owner).to eq(user1.organization) | ||
end | ||
it "adds a new brack location owned by user without an organization" do | ||
expect(Brack.count).to eq(0) | ||
|
||
post '/api/v1/bracks', params: {brack: {user_id: user2.id, lat: brack.lat, long: brack.long}} | ||
|
||
expect(response).to be_success | ||
expect(Brack.count).to eq(1) | ||
|
||
new_brack = Brack.all[0] | ||
user_name = "#{user2.first_name} #{user2.last_name[0]}." | ||
|
||
expect(new_brack.lat).to eq(39.749598) | ||
expect(new_brack.long).to eq(brack.long) | ||
expect(new_brack.cross_streets).to eq("15th St & Blake St") | ||
expect(new_brack.owner).to eq(user_name) | ||
end | ||
end |