Add Tournament model spec and factory

This commit is contained in:
Thor77 2018-11-13 20:39:28 +01:00
parent 1d463b55c3
commit ff63380c9c
No known key found for this signature in database
GPG Key ID: 5051E71B46AA669A
3 changed files with 54 additions and 0 deletions

View File

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

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

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

View File

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