Add model test for group,match,score,stage,user

This commit is contained in:
Thor77 2018-11-17 18:26:34 +01:00
parent b09f4eceb2
commit 1ec2fa6cf5
No known key found for this signature in database
GPG Key ID: 5051E71B46AA669A
5 changed files with 93 additions and 0 deletions

15
spec/models/group_spec.rb Normal file
View File

@ -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

32
spec/models/match_spec.rb Normal file
View File

@ -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

18
spec/models/score_spec.rb Normal file
View File

@ -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

15
spec/models/stage_spec.rb Normal file
View File

@ -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

13
spec/models/user_spec.rb Normal file
View File

@ -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