Add "simple" parameter to tournament show

This commit is contained in:
Thor77 2019-10-25 23:15:28 +02:00
parent 46c903e109
commit d317585168
No known key found for this signature in database
GPG Key ID: 5051E71B46AA669A
2 changed files with 18 additions and 1 deletions

View File

@ -25,7 +25,11 @@ class TournamentsController < ApplicationController
# GET /tournaments/1
def show
render json: @tournament, include: '**'
if show_params.fetch(:simple, 'false') == 'true'
render json: @tournament, serializer: SimpleTournamentSerializer
else
render json: @tournament, include: '**'
end
end
# POST /tournaments
@ -116,6 +120,10 @@ class TournamentsController < ApplicationController
params.permit(:type)
end
def show_params
params.permit(:simple)
end
def tournament_params
params.slice(:name, :description, :public, :teams, :group_stage, :playoff_teams_amount).permit!
end

View File

@ -102,6 +102,15 @@ RSpec.describe TournamentsController, type: :controller do
get :show, params: { id: @tournament.to_param }
expect(deserialize_response(response)[:id].to_i).to eq(@tournament.id)
end
context 'with simple=true parameter' do
it 'returns no relations' do
get :show, params: { id: @tournament.to_param, simple: 'true' }
body = deserialize_response response
expect(body[:stages]).to be_nil
expect(body[:teams]).to be_nil
end
end
end
describe 'POST #create' do