From 0bd3c81e39e52b0c66ec6dbd90b1ac3d7cf44644 Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Sun, 7 Oct 2018 13:07:27 +0200 Subject: [PATCH] Fix /users, /users/:id/identities endpoints --- config/routes.rb | 4 +++- .../{user_identeties.rb => user_identities.rb} | 0 ..._spec.rb => user_identities_controller_spec.rb} | 14 +++++++------- 3 files changed, 10 insertions(+), 8 deletions(-) rename spec/factories/{user_identeties.rb => user_identities.rb} (100%) rename spec/requests/api/v1/{users_identeties_controller_spec.rb => user_identities_controller_spec.rb} (89%) diff --git a/config/routes.rb b/config/routes.rb index 4b5ebcef1..e07102f33 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -586,7 +586,9 @@ Rails.application.routes.draw do end resources :users, only: %i(show) do resources :user_identities, - only: %i(index create show update destroy) + only: %i(index create show update destroy), + path: 'identities', + as: :identities end end end diff --git a/spec/factories/user_identeties.rb b/spec/factories/user_identities.rb similarity index 100% rename from spec/factories/user_identeties.rb rename to spec/factories/user_identities.rb diff --git a/spec/requests/api/v1/users_identeties_controller_spec.rb b/spec/requests/api/v1/user_identities_controller_spec.rb similarity index 89% rename from spec/requests/api/v1/users_identeties_controller_spec.rb rename to spec/requests/api/v1/user_identities_controller_spec.rb index 3a927f5a2..e0d80d110 100644 --- a/spec/requests/api/v1/users_identeties_controller_spec.rb +++ b/spec/requests/api/v1/user_identities_controller_spec.rb @@ -15,7 +15,7 @@ RSpec.describe 'Api::V1::UsersIdentitiesController', type: :request do describe 'GET user_identities, #index' do it 'When valid request, requested identities for current user' do hash_body = nil - get api_v1_user_user_identities_path(user_id: @user1.id), + get api_v1_user_identities_path(user_id: @user1.id), headers: @valid_headers expect { hash_body = json }.not_to raise_exception expect(hash_body[:data]).to match( @@ -28,7 +28,7 @@ RSpec.describe 'Api::V1::UsersIdentitiesController', type: :request do it 'When invalid request, requested user is not signed in user' do hash_body = nil - get api_v1_user_user_identities_path(user_id: @user2.id), + get api_v1_user_identities_path(user_id: @user2.id), headers: @valid_headers expect(response).to have_http_status(403) expect(hash_body).to match(nil) @@ -36,7 +36,7 @@ RSpec.describe 'Api::V1::UsersIdentitiesController', type: :request do it 'When invalid request, non existing user' do hash_body = nil - get api_v1_user_user_identities_path(user_id: 123), + get api_v1_user_identities_path(user_id: 123), headers: @valid_headers expect(response).to have_http_status(403) expect(hash_body).to match(nil) @@ -46,7 +46,7 @@ RSpec.describe 'Api::V1::UsersIdentitiesController', type: :request do describe 'POST user_identities, #create' do it 'When valid request, create new identity for current user' do hash_body = nil - post api_v1_user_user_identities_path(user_id: @user1.id), + post api_v1_user_identities_path(user_id: @user1.id), params: { data: { type: 'user_identities', attributes: { uid: Faker::Crypto.unique.sha1, @@ -66,7 +66,7 @@ RSpec.describe 'Api::V1::UsersIdentitiesController', type: :request do describe 'GET user_identity, #show' do it 'When valid request, requested specific identity for current user' do hash_body = nil - get api_v1_user_user_identity_path( + get api_v1_user_identity_path( user_id: @user1.id, id: @user1.user_identities.order(:id).last ), headers: @valid_headers expect { hash_body = json }.not_to raise_exception @@ -82,7 +82,7 @@ RSpec.describe 'Api::V1::UsersIdentitiesController', type: :request do describe 'PUT user_identities, #update' do it 'When valid request, update identity for current user' do hash_body = nil - put api_v1_user_user_identity_path(user_id: @user1.id, + put api_v1_user_identity_path(user_id: @user1.id, id: @user1.user_identities.order(:id).last), params: { data: { id: @user1.user_identities.order(:id).last.id, @@ -103,7 +103,7 @@ RSpec.describe 'Api::V1::UsersIdentitiesController', type: :request do describe 'DELETE user_identity, #destroy' do it 'When valid request, destroy specified identity for current user' do identity = @user1.user_identities.order(:id).last - delete api_v1_user_user_identity_path(user_id: @user1.id, id: identity), + delete api_v1_user_identity_path(user_id: @user1.id, id: identity), headers: @valid_headers expect(response).to have_http_status(200) expect(response.body).to eq('')