Skip to content

Commit

Permalink
Use user single resources instead of /users/me
Browse files Browse the repository at this point in the history
  • Loading branch information
MaicolBen committed Mar 10, 2017
1 parent 895b2c6 commit 27cb458
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
18 changes: 9 additions & 9 deletions apiary.apib
Original file line number Diff line number Diff line change
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 All @@ -50,7 +50,7 @@ API BASE is an internal TopTier project created to facilitate and standardize de
}


## Current user's profile [/api/v1/user/{id}]
## Current user's profile [/api/v1/user/]

### Get current user profile [GET]

Expand All @@ -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 @@ -177,8 +177,8 @@ API BASE is an internal TopTier project created to facilitate and standardize de
}


## Login with Facebook [/api/v1/users/facebook]
## Login with Facebook [/api/v1/user/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
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace :v1, defaults: { format: :json } do
devise_scope :user do
get :status, to: 'api#status'
resources :users, only: [:show, :update] do
resource :user, only: [:show, :update] do
controller :sessions do
post :facebook, on: :collection
end
Expand Down
18 changes: 9 additions & 9 deletions spec/controllers/api/v1/users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@

describe Api::V1::UsersController do
render_views
let!(:user) { create(:user) }
let!(:user) { create :user }
before do
auth_request user
end

describe 'GET show' do
it 'returns success' do
get :show, params: { id: :me, format: :json }
get :show, params: { format: :json }
expect(response).to have_http_status(:success)
end

it 'returns user\'s data' do
get :show, params: { id: :me, format: :json }
get :show, params: { format: :json }

expect(parsed_response[:user][:id]).to eq user.id
expect(parsed_response[:user][:first_name]).to eq user.first_name
Expand All @@ -28,17 +28,17 @@

context 'with valid params' do
it 'returns success' do
put :update, params: { id: :me, user: params, format: 'json' }
put :update, params: { user: params, format: 'json' }
expect(response).to have_http_status(:success)
end

it 'updates the user' do
put :update, params: { id: :me, user: params, format: 'json' }
put :update, params: { user: params, format: 'json' }
expect(user.reload.username).to eq(params[:username])
end

it 'returns the user' do
put :update, params: { id: :me, user: params, format: 'json' }
put :update, params: { user: params, format: 'json' }

expect(parsed_response[:user][:id]).to eq user.id
expect(parsed_response[:user][:first_name]).to eq user.first_name
Expand All @@ -49,17 +49,17 @@
let(:params) { { email: 'notanemail' } }

it 'does not return success' do
put :update, params: { id: :me, user: params, format: 'json' }
put :update, params: { user: params, format: 'json' }
expect(response).to_not have_http_status(:success)
end

it 'does not update the user' do
put :update, params: { id: :me, user: params, format: 'json' }
put :update, params: { user: params, format: 'json' }
expect(user.reload.email).to_not eq(params[:email])
end

it 'returns the error' do
put :update, params: { id: :me, user: params, format: 'json' }
put :update, params: { user: params, format: 'json' }
expect(parsed_response[:errors][:email]).to include('is not an email')
end
end
Expand Down

0 comments on commit 27cb458

Please sign in to comment.