diff --git a/spec/factories/matches.rb b/spec/factories/matches.rb index 3f0a89c..13d84f3 100644 --- a/spec/factories/matches.rb +++ b/spec/factories/matches.rb @@ -10,7 +10,18 @@ FactoryBot.define do after(:create) do |match, evaluator| match.match_scores = create_list(:match_score, evaluator.match_scores_count) end - state { 3 } + state { :in_progress } + end + + factory :decided_playoff_match do + transient do + match_scores_count { 2 } + end + after(:create) do |match, evaluator| + match.match_scores = create_list(:match_score, evaluator.match_scores_count, points: rand(10)) + match.match_scores.first.points += 1 + end + state { :finished } end end @@ -23,7 +34,17 @@ FactoryBot.define do after(:create) do |match, evaluator| match.match_scores = create_list(:match_score, evaluator.match_scores_count) end - state { 3 } + state { :in_progress } + end + + factory :undecided_group_match do + transient do + match_scores_count { 2 } + end + after(:create) do |match, evaluator| + match.match_scores = create_list(:match_score, evaluator.match_scores_count, points: 3) + end + state { :finished } end end end diff --git a/spec/models/match_spec.rb b/spec/models/match_spec.rb index 01d34c5..f24ce70 100644 --- a/spec/models/match_spec.rb +++ b/spec/models/match_spec.rb @@ -43,6 +43,23 @@ RSpec.describe Match, type: :model do end end + context '#winner' do + before do + @undecided_match = create(:undecided_group_match) + @decided_match = create(:decided_playoff_match) + end + + it 'returns a winner Team for a decided match' do + winner = @decided_match.winner + expect(winner).to be_a Team + end + + it 'returns nil for an undecided match' do + winner = @undecided_match.winner + expect(winner).to be(nil) + end + end + context '#teams' do before do @playoff_match = create(:running_playoff_match)