Add model test for group,match,score,stage,user
This commit is contained in:
parent
b09f4eceb2
commit
1ec2fa6cf5
|
|
@ -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
|
||||||
|
|
@ -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
|
||||||
|
|
@ -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
|
||||||
|
|
@ -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
|
||||||
|
|
@ -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
|
||||||
Loading…
Reference in New Issue