Implement GroupsController
This commit is contained in:
parent
b8116e9614
commit
a74030a7ef
|
|
@ -0,0 +1,16 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class GroupsController < ApplicationController
|
||||
before_action :set_group, only: %i[show]
|
||||
|
||||
# GET /groups/1
|
||||
def show
|
||||
render json: @group, include: '**'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_group
|
||||
@group = Group.find(params[:id])
|
||||
end
|
||||
end
|
||||
|
|
@ -12,4 +12,5 @@ Rails.application.routes.draw do
|
|||
resources :statistics, only: %i[index]
|
||||
end
|
||||
resources :match_scores, only: %i[show update]
|
||||
resources :groups, only: %i[show]
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe GroupsController, type: :controller do
|
||||
before do
|
||||
@group = create(:group)
|
||||
end
|
||||
|
||||
describe 'GET #show' do
|
||||
it 'returns a success response' do
|
||||
get :show, params: { id: @group.to_param }
|
||||
expect(response).to be_successful
|
||||
end
|
||||
|
||||
it 'should return the correct group' do
|
||||
get :show, params: { id: @group.to_param }
|
||||
body = deserialize_response response
|
||||
expect(Group.find_by(id: body[:id])).to eq(@group)
|
||||
expect(body[:number]).to eq(@group.number)
|
||||
expect(body[:matches].size).to eq(@group.matches.size)
|
||||
expect(body[:group_scores].size).to eq(@group.group_scores.size)
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Reference in New Issue