Add tests for match winner method
This commit is contained in:
parent
e8465df700
commit
802ff678cf
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue