diff --git a/app/services/playoff_stage_service.rb b/app/services/playoff_stage_service.rb index 080df96..38ccabc 100644 --- a/app/services/playoff_stage_service.rb +++ b/app/services/playoff_stage_service.rb @@ -101,6 +101,13 @@ class PlayoffStageService # This is not allowed in Database. The following code filters out MatchScores that contain nil as team. match_scores = match_scores.select { |ms| ms.team.present? } match_below.match_scores = match_scores + match_below.state = if match_below.match_scores.empty? || match_below.match_scores.size == 1 + :not_ready + elsif match_below.match_scores.size == 2 + :not_started + else + raise 'Unprocessable amount of match_scores found' + end [match_below, match_scores].flatten end diff --git a/spec/controllers/matches_controller_spec.rb b/spec/controllers/matches_controller_spec.rb index c034a1a..f50e67a 100644 --- a/spec/controllers/matches_controller_spec.rb +++ b/spec/controllers/matches_controller_spec.rb @@ -94,6 +94,10 @@ RSpec.describe MatchesController, type: :controller do expect(@running_playoff_match.winner).to be_a(Team) expect(@match_below.teams).to include(@running_playoff_match.winner) end + + it 'with the right status' do + expect(@match_below.state).to eq('not_ready') + end end end end diff --git a/spec/services/playoff_stage_service_spec.rb b/spec/services/playoff_stage_service_spec.rb index ccab2d3..91e3149 100644 --- a/spec/services/playoff_stage_service_spec.rb +++ b/spec/services/playoff_stage_service_spec.rb @@ -109,6 +109,10 @@ RSpec.describe PlayoffStageService do it 'finds the correct match and adds two new match_scores to it' do expect(@match_to_find.teams).to match_array(@match.winner) end + + it 'finds the correct match and changes its state' do + expect(@match_to_find.state).to eq('not_ready') + end end context 'match below has one match_score with the winning team' do @@ -121,6 +125,10 @@ RSpec.describe PlayoffStageService do it 'finds the correct match and adds no match_score' do expect(@test.teams).to match_array(@match.winner) end + + it 'finds the correct match and changes its state' do + expect(@test.state).to eq('not_ready') + end end context 'match below has one match_score with an unknown team' do @@ -134,6 +142,10 @@ RSpec.describe PlayoffStageService do expect(@test.teams).to match_array(@match.winner) expect(@test.match_scores.first.points).to_not be(1337) end + + it 'finds the correct match and changes its state' do + expect(@test.state).to eq('not_ready') + end end context 'match below has one match_score with the correct team' do @@ -147,6 +159,10 @@ RSpec.describe PlayoffStageService do expect(@test.teams).to match_array(@match.winner) expect(@test.match_scores.first.points).to be(42) end + + it 'finds the correct match and changes its state' do + expect(@test.state).to eq('not_ready') + end end context 'match below has two match_scores with the correct teams' do @@ -162,6 +178,10 @@ RSpec.describe PlayoffStageService do it 'finds the correct match and replaces nothing' do expect(@test.teams).to match_array([@match.winner, @companion_match.winner]) end + + it 'finds the correct match and changes its state' do + expect(@test.state).to eq('not_started') + end end end end