Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added 500 handler & make facebook webmock more flexible #58

Merged
merged 1 commit into from
Jun 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions apiary.apib
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ HOST: http://rails5-api-base.herokuapp.com

# API BASE

API BASE is an internal TopTier project created to facilitate and standardize developers work.
API BASE is an internal Rootstrap project created to facilitate and standardize developers work.

## Users Collection [/api/v1/users]

Expand Down Expand Up @@ -36,7 +36,7 @@ API BASE is an internal TopTier project created to facilitate and standardize de


+ Body

{
"id": 102,
"email": "test@test.com",
Expand Down Expand Up @@ -75,7 +75,7 @@ API BASE is an internal TopTier project created to facilitate and standardize de


+ Body

{
"user":
{
Expand Down Expand Up @@ -118,7 +118,7 @@ API BASE is an internal TopTier project created to facilitate and standardize de


+ Body

{
"user":
{
Expand All @@ -131,7 +131,7 @@ API BASE is an internal TopTier project created to facilitate and standardize de


## Login [/api/v1/users/sign_in]

### Login [POST]

+ Request (application/json)
Expand Down Expand Up @@ -160,7 +160,7 @@ API BASE is an internal TopTier project created to facilitate and standardize de


+ Body

{
"data":
{
Expand All @@ -178,7 +178,7 @@ API BASE is an internal TopTier project created to facilitate and standardize de


## Login with Facebook [/api/v1/users/facebook]

### Login with Facebook [POST]


Expand Down Expand Up @@ -239,7 +239,7 @@ https://github.com/lynndylanhurley/devise_token_auth/wiki/Reset-Password-Flow
+ Response 200 (application/json)
+ Body

{
{
"success": true,
"data":
{
Expand Down
6 changes: 6 additions & 0 deletions app/controllers/api/v1/api_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class ApiController < ApplicationController
layout false
respond_to :json

rescue_from Exception, with: :render_error
rescue_from ActiveRecord::RecordNotFound, with: :render_not_found
rescue_from ActiveRecord::RecordInvalid, with: :render_record_invalid
rescue_from ActionController::RoutingError, with: :render_not_found
Expand All @@ -21,6 +22,11 @@ def status
render json: { online: true }
end

def render_error(_exception)
logger.error(exception) # Report to your error managment tool here
render json: { error: 'An error ocurred' }, status: 500 unless performed?
end

def render_not_found(exception)
logger.info(exception) # for logging
render json: { error: "Couldn't find the record" }, status: :not_found
Expand Down
15 changes: 10 additions & 5 deletions spec/requests/api/v1/sessions/facebook_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
require 'rails_helper'

describe 'POST api/v1/users/facebook', type: :request do
let(:user) { create(:user) }
let(:facebook_path) { facebook_api_v1_users_path }
let(:user) { create(:user) }
let(:facebook_path) { facebook_api_v1_users_path }
let(:facebook_api_path) { 'https://graph.facebook.com/me' }
let(:facebook_response) do
{
first_name: 'Test',
Expand Down Expand Up @@ -30,7 +31,8 @@
}
end
before do
stub_request(:get, 'https://graph.facebook.com/me?access_token=123456&fields=email,first_name,last_name')
stub_request(:get, facebook_api_path)
.with(query: hash_including(access_token: '123456', fields: 'email,first_name,last_name'))
.to_return(status: 200, body: facebook_response.to_json)
end

Expand Down Expand Up @@ -77,7 +79,9 @@
end
before do
facebook_response[:email] = ''
stub_request(:get, 'https://graph.facebook.com/me?access_token=without_email&fields=email,first_name,last_name')
fields = 'email,first_name,last_name'
stub_request(:get, facebook_api_path)
.with(query: hash_including(access_token: 'without_email', fields: fields))
.to_return(status: 200, body: facebook_response.to_json)
end

Expand Down Expand Up @@ -121,7 +125,8 @@
code: 190
}
}
stub_request(:get, 'https://graph.facebook.com/me?access_token=invalid&fields=email,first_name,last_name')
stub_request(:get, facebook_api_path)
.with(query: hash_including(access_token: 'invalid', fields: 'email,first_name,last_name'))
.to_return(status: 400, body: facebook_response.to_json)
end

Expand Down