From f1490559659d5fce03c0bd1ac8d73cb313ea06c2 Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Mon, 29 Apr 2019 22:11:42 +0200 Subject: [PATCH] Test teams methods of Matches, Groups and Stages --- spec/models/group_spec.rb | 15 +++++++++++++++ spec/models/match_spec.rb | 34 ++++++++++++++++++++++++++++++++++ spec/models/stage_spec.rb | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+) diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb index 0f5784a..e8c8be2 100644 --- a/spec/models/group_spec.rb +++ b/spec/models/group_spec.rb @@ -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 diff --git a/spec/models/match_spec.rb b/spec/models/match_spec.rb index 63e436a..01d34c5 100644 --- a/spec/models/match_spec.rb +++ b/spec/models/match_spec.rb @@ -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 diff --git a/spec/models/stage_spec.rb b/spec/models/stage_spec.rb index df3d79e..a14fccd 100644 --- a/spec/models/stage_spec.rb +++ b/spec/models/stage_spec.rb @@ -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