From df2b8ab3df52d263c66965d1d4161d7ebefc10ed Mon Sep 17 00:00:00 2001 From: Urban Rotnik Date: Wed, 2 Dec 2020 11:44:37 +0100 Subject: [PATCH] Remove jsonapi_parameters gem, accept rails params in controller --- Gemfile | 1 - Gemfile.lock | 4 --- .../api/v1/project_folders_controller.rb | 2 +- app/controllers/api/v1/projects_controller.rb | 2 +- .../api/v1/project_folders_controller_spec.rb | 22 +++----------- .../api/v1/projects_controller_spec.rb | 29 +++++-------------- 6 files changed, 14 insertions(+), 46 deletions(-) diff --git a/Gemfile b/Gemfile index 65f985e2e..5a7bb6ae3 100644 --- a/Gemfile +++ b/Gemfile @@ -34,7 +34,6 @@ gem 'omniauth-rails_csrf_protection', '~> 0.1' gem 'active_model_serializers', '~> 0.10.7' gem 'json-jwt' gem 'jsonapi-renderer', '~> 0.2.2' -gem 'jsonapi_parameters' gem 'jwt', '~> 1.5' gem 'kaminari' gem 'rack-attack' diff --git a/Gemfile.lock b/Gemfile.lock index ab56db094..865903db8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -307,9 +307,6 @@ GEM json_schema json_schema (0.20.7) jsonapi-renderer (0.2.2) - jsonapi_parameters (2.2.0) - actionpack (>= 4.1.8) - activesupport (>= 4.1.8) jwt (1.5.6) kaminari (1.2.1) activesupport (>= 4.1.0) @@ -651,7 +648,6 @@ DEPENDENCIES json-jwt json_matchers jsonapi-renderer (~> 0.2.2) - jsonapi_parameters jwt (~> 1.5) kaminari listen (~> 3.0) diff --git a/app/controllers/api/v1/project_folders_controller.rb b/app/controllers/api/v1/project_folders_controller.rb index 91e6c40e3..77bd480a7 100644 --- a/app/controllers/api/v1/project_folders_controller.rb +++ b/app/controllers/api/v1/project_folders_controller.rb @@ -44,7 +44,7 @@ module Api def folder_params raise TypeError unless params.require(:data).require(:type) == 'project_folders' - params.from_jsonapi.require(:project_folder).permit(:name, :parent_folder_id) + params.permit(data: { attributes: %i(name parent_folder_id) })[:data][:attributes] end def update_folder_params diff --git a/app/controllers/api/v1/projects_controller.rb b/app/controllers/api/v1/projects_controller.rb index 3e6a0579f..2a69ba515 100644 --- a/app/controllers/api/v1/projects_controller.rb +++ b/app/controllers/api/v1/projects_controller.rb @@ -62,7 +62,7 @@ module Api def project_params raise TypeError unless params.require(:data).require(:type) == 'projects' - params.from_jsonapi.require(:project).permit(:name, :visibility, :archived, :project_folder_id) + params.require(:data).require(:attributes).permit(:name, :visibility, :archived, :project_folder_id) end def load_project_for_managing diff --git a/spec/requests/api/v1/project_folders_controller_spec.rb b/spec/requests/api/v1/project_folders_controller_spec.rb index 5c7609eaf..4dce99d66 100644 --- a/spec/requests/api/v1/project_folders_controller_spec.rb +++ b/spec/requests/api/v1/project_folders_controller_spec.rb @@ -67,15 +67,8 @@ RSpec.describe 'Api::V1::ProjectFoldersController', type: :request do data: { type: 'project_folders', attributes: { - name: project_folder_name - }, - relationships: { - parent_folder: { - data: { - type: 'project_folders', - id: parent_folder_id - } - } + name: project_folder_name, + parent_folder_id: parent_folder_id } } } @@ -138,15 +131,8 @@ RSpec.describe 'Api::V1::ProjectFoldersController', type: :request do id: project_folder.id, type: 'project_folders', attributes: { - name: project_folder_name - }, - relationships: { - parent_folder: { - data: { - type: 'project_folders', - id: parent_folder_id - } - } + name: project_folder_name, + parent_folder_id: parent_folder_id } } } diff --git a/spec/requests/api/v1/projects_controller_spec.rb b/spec/requests/api/v1/projects_controller_spec.rb index 731e92994..4bdecd13a 100644 --- a/spec/requests/api/v1/projects_controller_spec.rb +++ b/spec/requests/api/v1/projects_controller_spec.rb @@ -148,27 +148,20 @@ RSpec.describe 'Api::V1::ProjectsController', type: :request do ) end - context 'when includes folder relation' do + context 'when includes project_folder relation' do let(:request_body) do { data: { type: 'projects', attributes: { name: 'Project name', - visibility: 'hidden' - }, - relationships: { - project_folder: { - data: { - type: 'project_folders', - id: folder.id - } - } + visibility: 'hidden', + project_folder_id: project_folder.id } } } end - let(:folder) { create :project_folder, team: @teams.first } + let(:project_folder) { create :project_folder, team: @teams.first } it 'renders 201' do action @@ -248,24 +241,18 @@ RSpec.describe 'Api::V1::ProjectsController', type: :request do ) end - context 'when includes folder relation' do + context 'when includes project_folder relation' do let(:request_body) do { data: { type: 'projects', - attributes: {}, - relationships: { - project_folder: { - data: { - type: 'project_folders', - id: folder.id - } - } + attributes: { + project_folder_id: project_folder.id } } } end - let(:folder) { create :project_folder, team: @teams.first } + let(:project_folder) { create :project_folder, team: @teams.first } it 'renders 201' do action