From 787ed810d7b6b7afb5f219e3695c4f0f9c4954b6 Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Fri, 10 May 2019 20:44:18 +0200 Subject: [PATCH] Remove link between team.owner and tournament --- app/models/match_score.rb | 2 +- app/models/team.rb | 5 ++++- spec/controllers/teams_controller_spec.rb | 3 ++- spec/controllers/tournaments_controller_spec.rb | 4 ++-- spec/factories/teams.rb | 5 ----- spec/models/team_spec.rb | 1 - 6 files changed, 9 insertions(+), 11 deletions(-) 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 diff --git a/spec/models/team_spec.rb b/spec/models/team_spec.rb index d1e477b..ce229fa 100644 --- a/spec/models/team_spec.rb +++ b/spec/models/team_spec.rb @@ -15,6 +15,5 @@ RSpec.describe Team, type: :model do it 'has a valid factory' do expect(build(:team)).to be_valid - expect(build(:detached_team)).to be_valid end end