From b36e3c4251c7c9145ebcb9a0013d8fe1f1993931 Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Wed, 15 May 2019 08:53:31 +0200 Subject: [PATCH] Delegate owner of team to tournament again --- app/models/team.rb | 5 +---- spec/controllers/teams_controller_spec.rb | 3 +-- spec/factories/stages.rb | 2 +- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/app/models/team.rb b/app/models/team.rb index 7f2580b..f266f9c 100644 --- a/app/models/team.rb +++ b/app/models/team.rb @@ -7,8 +7,5 @@ class Team < ApplicationRecord validates :name, presence: true - def owner - match_scores.first.owner - # this will produce errors if we make teams reusable - end + delegate :owner, to: :tournament end diff --git a/spec/controllers/teams_controller_spec.rb b/spec/controllers/teams_controller_spec.rb index 3fc4516..8dc9eb1 100644 --- a/spec/controllers/teams_controller_spec.rb +++ b/spec/controllers/teams_controller_spec.rb @@ -4,8 +4,7 @@ require 'rails_helper' RSpec.describe TeamsController, type: :controller do before do - match_score = create(:match_score) - @team = match_score.team + @team = create(:tournament).teams.first @owner = @team.owner end diff --git a/spec/factories/stages.rb b/spec/factories/stages.rb index 8348817..0bbc826 100644 --- a/spec/factories/stages.rb +++ b/spec/factories/stages.rb @@ -26,7 +26,7 @@ FactoryBot.define do evaluator.match_count == -1 ? 2**stage.level : evaluator.match_count) stage.matches.each_with_index do |match, i| match.position = i - match.save + match.save! end end end