Test match index controller with filter

This commit is contained in:
Daniel Schädler 2019-10-26 01:23:15 +02:00
parent 82e4ff90dc
commit 400a396f00
1 changed files with 35 additions and 0 deletions

View File

@ -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 }