From a74030a7ef4b0479821e5b18641bc70381056984 Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Sat, 15 Jun 2019 22:09:20 +0200 Subject: [PATCH] Implement GroupsController --- app/controllers/groups_controller.rb | 16 ++++++++++++++ config/routes.rb | 1 + spec/controllers/groups_controller_spec.rb | 25 ++++++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 app/controllers/groups_controller.rb create mode 100644 spec/controllers/groups_controller_spec.rb diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb new file mode 100644 index 0000000..3e6147e --- /dev/null +++ b/app/controllers/groups_controller.rb @@ -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 diff --git a/config/routes.rb b/config/routes.rb index 10cafbf..63c742d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/spec/controllers/groups_controller_spec.rb b/spec/controllers/groups_controller_spec.rb new file mode 100644 index 0000000..6781b63 --- /dev/null +++ b/spec/controllers/groups_controller_spec.rb @@ -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