diff --git a/spec/factories/tournaments.rb b/spec/factories/tournaments.rb new file mode 100644 index 0000000..36ae8bc --- /dev/null +++ b/spec/factories/tournaments.rb @@ -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 diff --git a/spec/models/team_spec.rb b/spec/models/team_spec.rb new file mode 100644 index 0000000..03ed7c4 --- /dev/null +++ b/spec/models/team_spec.rb @@ -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 diff --git a/spec/models/tournament_spec.rb b/spec/models/tournament_spec.rb new file mode 100644 index 0000000..814ce96 --- /dev/null +++ b/spec/models/tournament_spec.rb @@ -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