diff --git a/app/models/match_score.rb b/app/models/match_score.rb index 408952d..b2a3f0c 100644 --- a/app/models/match_score.rb +++ b/app/models/match_score.rb @@ -4,5 +4,5 @@ class MatchScore < ApplicationRecord belongs_to :match belongs_to :team - delegate :owner, to: :team + delegate :owner, to: :match end diff --git a/app/models/team.rb b/app/models/team.rb index f266f9c..7f2580b 100644 --- a/app/models/team.rb +++ b/app/models/team.rb @@ -7,5 +7,8 @@ class Team < ApplicationRecord validates :name, presence: true - delegate :owner, to: :tournament + def owner + match_scores.first.owner + # this will produce errors if we make teams reusable + end end diff --git a/spec/controllers/teams_controller_spec.rb b/spec/controllers/teams_controller_spec.rb index 7bcbdb8..3fc4516 100644 --- a/spec/controllers/teams_controller_spec.rb +++ b/spec/controllers/teams_controller_spec.rb @@ -4,7 +4,8 @@ require 'rails_helper' RSpec.describe TeamsController, type: :controller do before do - @team = create(:team) + match_score = create(:match_score) + @team = match_score.team @owner = @team.owner end diff --git a/spec/controllers/tournaments_controller_spec.rb b/spec/controllers/tournaments_controller_spec.rb index da27ca7..7231e60 100644 --- a/spec/controllers/tournaments_controller_spec.rb +++ b/spec/controllers/tournaments_controller_spec.rb @@ -8,8 +8,8 @@ RSpec.describe TournamentsController, type: :controller do @user = @tournament.owner @another_user = create(:user) @private_tournament = create(:tournament, user: @another_user, public: false) - @teams = create_list(:detached_team, 4) - @teams16 = create_list(:detached_team, 16) + @teams = create_list(:team, 4) + @teams16 = create_list(:team, 16) @groups = create_list(:group, 4) end diff --git a/spec/factories/teams.rb b/spec/factories/teams.rb index b33adc4..234f71c 100644 --- a/spec/factories/teams.rb +++ b/spec/factories/teams.rb @@ -3,10 +3,5 @@ FactoryBot.define do factory :team do name { Faker::Creature::Dog.name } - tournament - end - - factory :detached_team, class: Team do - name { Faker::Creature::Dog.name } end end