From 1ec2fa6cf591824c586109411b9bc49b178e997e Mon Sep 17 00:00:00 2001 From: Thor77 Date: Sat, 17 Nov 2018 18:26:34 +0100 Subject: [PATCH] Add model test for group,match,score,stage,user --- spec/models/group_spec.rb | 15 +++++++++++++++ spec/models/match_spec.rb | 32 ++++++++++++++++++++++++++++++++ spec/models/score_spec.rb | 18 ++++++++++++++++++ spec/models/stage_spec.rb | 15 +++++++++++++++ spec/models/user_spec.rb | 13 +++++++++++++ 5 files changed, 93 insertions(+) create mode 100644 spec/models/group_spec.rb create mode 100644 spec/models/match_spec.rb create mode 100644 spec/models/score_spec.rb create mode 100644 spec/models/stage_spec.rb create mode 100644 spec/models/user_spec.rb diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb new file mode 100644 index 0000000..0f5784a --- /dev/null +++ b/spec/models/group_spec.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe Group, type: :model do + describe 'association' do + it { should belong_to :stage } + it { should have_many :matches } + it { should have_many :group_scores } + end + + it 'has a valid factory' do + expect(build(:group)).to be_valid + end +end diff --git a/spec/models/match_spec.rb b/spec/models/match_spec.rb new file mode 100644 index 0000000..1162808 --- /dev/null +++ b/spec/models/match_spec.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe Match, type: :model do + context 'association' do + it { should have_many :scores } + it { should belong_to :stage } + it { should belong_to :group } + end + + context 'scores' do + before do + @match = create(:match) + @match.scores << build_pair(:score) + end + + it 'can only have two scores' do + @match.scores << build(:score) + expect(@match).to be_invalid + end + + it 'can access its scores' do + @match.scores[0].score = 0 + @match.scores[1].score = 0 + end + end + + it 'has a valid factory' do + expect(build(:match)).to be_valid + end +end diff --git a/spec/models/score_spec.rb b/spec/models/score_spec.rb new file mode 100644 index 0000000..06ff6f0 --- /dev/null +++ b/spec/models/score_spec.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe Score, type: :model do + describe 'validation' do + it { should validate_presence_of :score } + end + + describe 'association' do + it { should belong_to :match } + it { should belong_to :team } + end + + it 'has a valid factory' do + expect(build(:score)).to be_valid + end +end diff --git a/spec/models/stage_spec.rb b/spec/models/stage_spec.rb new file mode 100644 index 0000000..4af3c30 --- /dev/null +++ b/spec/models/stage_spec.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe Stage, type: :model do + describe 'association' do + it { should belong_to :tournament } + it { should have_many :matches } + it { should have_many :groups } + end + + it 'has a valid factory' do + expect(build(:stage)).to be_valid + end +end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb new file mode 100644 index 0000000..c4ab25f --- /dev/null +++ b/spec/models/user_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe User, type: :model do + describe 'association' do + it { should have_many :tournaments } + end + + it 'has a valid factory' do + expect(build(:user)).to be_valid + end +end