From 400a396f00cc4fec0afcb0031131cf173def0a7d Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Sat, 26 Oct 2019 01:23:15 +0200 Subject: [PATCH] Test match index controller with filter --- spec/controllers/matches_controller_spec.rb | 35 +++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/spec/controllers/matches_controller_spec.rb b/spec/controllers/matches_controller_spec.rb index 061c4e8..38bc536 100644 --- a/spec/controllers/matches_controller_spec.rb +++ b/spec/controllers/matches_controller_spec.rb @@ -2,6 +2,14 @@ require 'rails_helper' +def test_get_index_with_filter(filter_state) + get :index, params: {state: filter_state, tournament_id: @tournament.to_param} + body = deserialize_response response + body.each do |match| + expect(match[:state]).to eq(filter_state) + end +end + RSpec.describe MatchesController, type: :controller do before do @match = create(:match, state: :not_started) @@ -12,6 +20,33 @@ RSpec.describe MatchesController, type: :controller do @match.match_scores = create_pair(:match_score) end + describe 'GET #index' do + context 'on a running group stage' do + before do + @tournament = create(:group_stage_tournament, match_factory: :running_group_match) + @tournament.matches.each_with_index do |m, i| + m.state = :not_started if i.even? + m.save! + end + end + + it 'filters running matches when told to do so' do + test_get_index_with_filter('running') + end + + it 'filters not_started matches when told to do so' do + test_get_index_with_filter('not_started') + end + + it 'doesn\'t break if the filter contains rubbish' do + filter_state = 'saftladen' + get :index, params: { state: filter_state, tournament_id: @tournament.to_param } + body = deserialize_response response + expect(body.empty?).to be true + end + end + end + describe 'GET #show' do it 'should return success' do get :show, params: { id: @match.to_param }