Merge pull request #15 from turniere/ticket/TURNIERE-98
Fix Tournament model spec randomly failing
This commit is contained in:
commit
e0fca9c5bd
|
|
@ -12,7 +12,16 @@ class Tournament < ApplicationRecord
|
||||||
|
|
||||||
alias_attribute :owner, :user
|
alias_attribute :owner, :user
|
||||||
|
|
||||||
after_initialize do |tournament|
|
after_initialize :generate_code
|
||||||
tournament.code ||= SecureRandom.hex 3
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def generate_code
|
||||||
|
return unless code.nil?
|
||||||
|
|
||||||
|
loop do
|
||||||
|
self.code = SecureRandom.hex(3)
|
||||||
|
break if errors['code'].blank?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,10 @@ RSpec.describe Tournament, type: :model do
|
||||||
describe 'validation' do
|
describe 'validation' do
|
||||||
it { should validate_presence_of :name }
|
it { should validate_presence_of :name }
|
||||||
it { should validate_presence_of :code }
|
it { should validate_presence_of :code }
|
||||||
it { should validate_uniqueness_of :code }
|
it do
|
||||||
|
tournament = create(:tournament, code: Faker::Dog.name)
|
||||||
|
expect(tournament).to validate_uniqueness_of :code
|
||||||
|
end
|
||||||
it { should_not validate_presence_of :description }
|
it { should_not validate_presence_of :description }
|
||||||
it { should_not validate_presence_of :public }
|
it { should_not validate_presence_of :public }
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue