Change match state of match below
This commit is contained in:
parent
8dd1f0b07c
commit
6f44823bc6
|
|
@ -101,6 +101,13 @@ class PlayoffStageService
|
||||||
# This is not allowed in Database. The following code filters out MatchScores that contain nil as team.
|
# 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_scores = match_scores.select { |ms| ms.team.present? }
|
||||||
match_below.match_scores = match_scores
|
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
|
[match_below, match_scores].flatten
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -94,6 +94,10 @@ RSpec.describe MatchesController, type: :controller do
|
||||||
expect(@running_playoff_match.winner).to be_a(Team)
|
expect(@running_playoff_match.winner).to be_a(Team)
|
||||||
expect(@match_below.teams).to include(@running_playoff_match.winner)
|
expect(@match_below.teams).to include(@running_playoff_match.winner)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'with the right status' do
|
||||||
|
expect(@match_below.state).to eq('not_ready')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -109,6 +109,10 @@ RSpec.describe PlayoffStageService do
|
||||||
it 'finds the correct match and adds two new match_scores to it' 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)
|
expect(@match_to_find.teams).to match_array(@match.winner)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'finds the correct match and changes its state' do
|
||||||
|
expect(@match_to_find.state).to eq('not_ready')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'match below has one match_score with the winning team' do
|
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
|
it 'finds the correct match and adds no match_score' do
|
||||||
expect(@test.teams).to match_array(@match.winner)
|
expect(@test.teams).to match_array(@match.winner)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'finds the correct match and changes its state' do
|
||||||
|
expect(@test.state).to eq('not_ready')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'match below has one match_score with an unknown team' do
|
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.teams).to match_array(@match.winner)
|
||||||
expect(@test.match_scores.first.points).to_not be(1337)
|
expect(@test.match_scores.first.points).to_not be(1337)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'finds the correct match and changes its state' do
|
||||||
|
expect(@test.state).to eq('not_ready')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'match below has one match_score with the correct team' do
|
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.teams).to match_array(@match.winner)
|
||||||
expect(@test.match_scores.first.points).to be(42)
|
expect(@test.match_scores.first.points).to be(42)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'finds the correct match and changes its state' do
|
||||||
|
expect(@test.state).to eq('not_ready')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'match below has two match_scores with the correct teams' do
|
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
|
it 'finds the correct match and replaces nothing' do
|
||||||
expect(@test.teams).to match_array([@match.winner, @companion_match.winner])
|
expect(@test.teams).to match_array([@match.winner, @companion_match.winner])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'finds the correct match and changes its state' do
|
||||||
|
expect(@test.state).to eq('not_started')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue