Test teams methods of Matches, Groups and Stages

This commit is contained in:
Daniel Schädler 2019-04-29 22:11:42 +02:00
parent 6a2c71bad7
commit f149055965
3 changed files with 81 additions and 0 deletions

View File

@ -12,4 +12,19 @@ RSpec.describe Group, type: :model do
it 'has a valid factory' do
expect(build(:group)).to be_valid
end
describe '#teams' do
before do
@group = create(:group, match_count: 1) # this is getting stubbed anyways
@teams = create_list(:team, 4)
expect_any_instance_of(Match)
.to receive(:teams)
.and_return(@teams)
end
it 'returns all teams from the matches within the matches below' do
teams = @group.teams
expect(teams).to match_array(@teams)
end
end
end

View File

@ -43,6 +43,40 @@ RSpec.describe Match, type: :model do
end
end
context '#teams' do
before do
@playoff_match = create(:running_playoff_match)
@group_match = create(:running_group_match)
@teams = create_list(:team, 2)
@match_scores = create_list(:match_score, 2)
@match_scores.each_with_index { |match, i| match.team = @teams[i] }
@playoff_match.match_scores = @match_scores
@group_match.match_scores = @match_scores
end
context 'called on group match' do
let(:call_teams_on_group_match) do
@group_match.teams
end
it 'returns 2 team objects' do
teams = call_teams_on_group_match
expect(teams).to match_array(@teams)
end
end
context 'called on playoff match' do
let(:call_teams_on_playoff_match) do
@playoff_match.teams
end
it 'returns 2 team objects' do
teams = call_teams_on_playoff_match
expect(teams).to match_array(@teams)
end
end
end
it 'has a valid factory' do
expect(build(:match)).to be_valid
expect(build(:running_playoff_match)).to be_valid

View File

@ -13,4 +13,36 @@ RSpec.describe Stage, type: :model do
expect(build(:stage)).to be_valid
expect(build(:group_stage)).to be_valid
end
describe '#teams' do
context 'group stage' do
before do
@stage = create(:group_stage, group_count: 1) # this is getting stubbed anyways
@teams = create_list(:team, 4)
expect_any_instance_of(Group)
.to receive(:teams)
.and_return(@teams)
end
it 'returns all teams from the matches within the groups below' do
teams = @stage.teams
expect(teams).to match_array(@teams)
end
end
context 'playoff stage' do
before do
@stage = create(:playoff_stage, match_count: 1) # this is getting stubbed anyways
@teams = create_list(:team, 4)
expect_any_instance_of(Match)
.to receive(:teams)
.and_return(@teams)
end
it 'returns all teams from the matches within the matches below' do
teams = @stage.teams
expect(teams).to match_array(@teams)
end
end
end
end