Fix player count game validation
This commit is contained in:
parent
ef17b1f8f9
commit
2134ea02ce
@ -50,10 +50,10 @@ class Game < ActiveRecord::Base
|
|||||||
def validate_startable
|
def validate_startable
|
||||||
@player_count = players.count
|
@player_count = players.count
|
||||||
@user_count = players.where.not(soft_token: nil).count
|
@user_count = players.where.not(soft_token: nil).count
|
||||||
errors[:players] = 'Must be at least 2 players.' if @user_count < 2
|
errors.add(:players, 'Must be at least 2 players.') if @player_count < 2
|
||||||
errors[:players] = 'Must be less than 5 players.' if @user_count > 4
|
errors.add(:players, 'Must be less than 5 players.') if @player_count > 4
|
||||||
errors[:status] = 'Game already started...' if self.status.nil? == false
|
errors.add(:status, 'Game already started...') if self.status.nil? == false
|
||||||
errors[:player_cards] = 'Cards already dealt...' unless player_cards.empty?
|
errors.add(:player_cards, 'Cards already dealt...') unless player_cards.empty?
|
||||||
fail StandardError, errors if errors.count > 0
|
fail StandardError, errors if errors.count > 0
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|||||||
@ -67,6 +67,7 @@ RSpec.describe Game, type: :model do
|
|||||||
@game.players.new(user_id: User.last.id)
|
@game.players.new(user_id: User.last.id)
|
||||||
expect { @game.validate_startable }.to raise_error StandardError
|
expect { @game.validate_startable }.to raise_error StandardError
|
||||||
expect(@game.startable?).to eq(false)
|
expect(@game.startable?).to eq(false)
|
||||||
|
binding.pry
|
||||||
expect(@game.errors[:players])
|
expect(@game.errors[:players])
|
||||||
.to include 'Must be less than 5 players.'
|
.to include 'Must be less than 5 players.'
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user