Rearrange Test Code
This commit is contained in:
parent
8bdcd51e66
commit
8dd1f0b07c
|
|
@ -5,8 +5,9 @@ require 'rails_helper'
|
||||||
RSpec.describe MatchesController, type: :controller do
|
RSpec.describe MatchesController, type: :controller do
|
||||||
before do
|
before do
|
||||||
@match = create(:match, state: :not_started)
|
@match = create(:match, state: :not_started)
|
||||||
@tournament = create(:stage_tournament, stage_count: 2)
|
@amount_of_stages = 2
|
||||||
@running_playoff_match = @tournament.stages.find_by(level: 2).matches.first
|
@tournament = create(:stage_tournament, stage_count: @amount_of_stages)
|
||||||
|
@running_playoff_match = @tournament.stages.find_by(level: @amount_of_stages).matches.first
|
||||||
@match.match_scores = create_pair(:match_score)
|
@match.match_scores = create_pair(:match_score)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -83,11 +84,16 @@ RSpec.describe MatchesController, type: :controller do
|
||||||
expect(@running_playoff_match.state).to eq(finished[:state])
|
expect(@running_playoff_match.state).to eq(finished[:state])
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'populates the match below' do
|
describe 'updates the match below' do
|
||||||
match_below = @tournament.stages.find { |s| s.level == 2 }.matches
|
before do
|
||||||
.find { |m| m.position == @running_playoff_match.position / 2 }.reload
|
@match_below = @tournament.stages.find_by(level: @amount_of_stages - 1).matches
|
||||||
expect(@running_playoff_match.winner).to be_a(Team)
|
.find_by(position: @running_playoff_match.position / 2).reload
|
||||||
expect(match_below.teams).to include(@running_playoff_match.winner)
|
end
|
||||||
|
|
||||||
|
it 'with the right teams' do
|
||||||
|
expect(@running_playoff_match.winner).to be_a(Team)
|
||||||
|
expect(@match_below.teams).to include(@running_playoff_match.winner)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -100,57 +100,67 @@ RSpec.describe PlayoffStageService do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'match below has no match_scores' do
|
context 'match below has no match_scores' do
|
||||||
it 'finds the correct match and adds two new match_scores to it' do
|
before do
|
||||||
@match_to_find.match_scores = []
|
@match_to_find.match_scores = []
|
||||||
@match_to_find.save
|
@match_to_find.save
|
||||||
PlayoffStageService.populate_match_below(@match)
|
@test = PlayoffStageService.populate_match_below(@match).first
|
||||||
@match_to_find.reload
|
end
|
||||||
|
|
||||||
|
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
|
||||||
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
|
||||||
it 'finds the correct match and adds no match_score' do
|
before do
|
||||||
@match_to_find.match_scores = create_list(:match_score, 1, team: @match.winner)
|
@match_to_find.match_scores = create_list(:match_score, 1, team: @match.winner)
|
||||||
@match_to_find.save
|
@match_to_find.save
|
||||||
PlayoffStageService.populate_match_below(@match)
|
@test = PlayoffStageService.populate_match_below(@match).first
|
||||||
@match_to_find.reload
|
end
|
||||||
expect(@match_to_find.teams).to match_array(@match.winner)
|
|
||||||
|
it 'finds the correct match and adds no match_score' do
|
||||||
|
expect(@test.teams).to match_array(@match.winner)
|
||||||
end
|
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
|
||||||
it 'finds the correct match and replaces the match_score' do
|
before do
|
||||||
@match_to_find.match_scores = create_list(:match_score, 1, team: create(:team), points: 1337)
|
@match_to_find.match_scores = create_list(:match_score, 1, team: create(:team), points: 1337)
|
||||||
@match_to_find.save
|
@match_to_find.save
|
||||||
PlayoffStageService.populate_match_below(@match)
|
@test = PlayoffStageService.populate_match_below(@match).first
|
||||||
@match_to_find.reload
|
end
|
||||||
expect(@match_to_find.teams).to match_array(@match.winner)
|
|
||||||
expect(@match_to_find.match_scores.first.points).to_not be(1337)
|
it 'finds the correct match and replaces the match_score' do
|
||||||
|
expect(@test.teams).to match_array(@match.winner)
|
||||||
|
expect(@test.match_scores.first.points).to_not be(1337)
|
||||||
end
|
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
|
||||||
it 'finds the correct match and replaces nothing' do
|
before do
|
||||||
@match_to_find.match_scores = create_list(:match_score, 1, team: @match.winner, points: 42)
|
@match_to_find.match_scores = create_list(:match_score, 1, team: @match.winner, points: 42)
|
||||||
@match_to_find.save
|
@match_to_find.save
|
||||||
PlayoffStageService.populate_match_below(@match)
|
@test = PlayoffStageService.populate_match_below(@match).first
|
||||||
@match_to_find.reload
|
end
|
||||||
expect(@match_to_find.teams).to match_array(@match.winner)
|
|
||||||
expect(@match_to_find.match_scores.first.points).to be(42)
|
it 'finds the correct match and replaces nothing' do
|
||||||
|
expect(@test.teams).to match_array(@match.winner)
|
||||||
|
expect(@test.match_scores.first.points).to be(42)
|
||||||
end
|
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
|
||||||
it 'finds the correct match and replaces nothing' do
|
before do
|
||||||
@companion_match.state = :finished
|
@companion_match.state = :finished
|
||||||
@companion_match.save
|
@companion_match.save
|
||||||
@match_to_find.match_scores = [create(:match_score, team: @match.winner),
|
@match_to_find.match_scores = [create(:match_score, team: @match.winner),
|
||||||
create(:match_score, team: @companion_match.winner)]
|
create(:match_score, team: @companion_match.winner)]
|
||||||
@match_to_find.save
|
@match_to_find.save
|
||||||
PlayoffStageService.populate_match_below(@match)
|
@test = PlayoffStageService.populate_match_below(@match).first
|
||||||
@match_to_find.reload
|
end
|
||||||
expect(@match_to_find.teams).to match_array([@match.winner, @companion_match.winner])
|
|
||||||
|
it 'finds the correct match and replaces nothing' do
|
||||||
|
expect(@test.teams).to match_array([@match.winner, @companion_match.winner])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue