Add Tournament model spec and factory
This commit is contained in:
parent
1d463b55c3
commit
ff63380c9c
|
|
@ -0,0 +1,9 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
FactoryBot.define do
|
||||
factory :tournament do
|
||||
name { Faker::Dog.name }
|
||||
description { Faker::Lorem.sentence }
|
||||
user
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Team, type: :model do
|
||||
describe 'validation' do
|
||||
it { should validate_presence_of :name }
|
||||
end
|
||||
|
||||
describe 'association' do
|
||||
it { should belong_to :tournament }
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Tournament, type: :model do
|
||||
before do
|
||||
@tournament = create(:tournament)
|
||||
end
|
||||
|
||||
describe 'validation' do
|
||||
it { should validate_presence_of :name }
|
||||
it { should validate_presence_of :code }
|
||||
it { should validate_uniqueness_of :code }
|
||||
it { should_not validate_presence_of :description }
|
||||
it { should_not validate_presence_of :public }
|
||||
end
|
||||
|
||||
describe 'initialization' do
|
||||
it 'should have a code' do
|
||||
assert_equal @tournament.code.length, 6
|
||||
end
|
||||
it 'should be public' do
|
||||
assert_equal @tournament.public, true
|
||||
end
|
||||
end
|
||||
|
||||
describe 'association' do
|
||||
it { should belong_to :user }
|
||||
it { should have_many :teams }
|
||||
it { should have_many :stages }
|
||||
end
|
||||
end
|
||||
Loading…
Reference in New Issue