Fix hand_type validation
This commit is contained in:
parent
44839d9ddd
commit
ef93825b94
@ -34,9 +34,9 @@ class Play < ActiveRecord::Base
|
|||||||
# current player is not the player to beat
|
# current player is not the player to beat
|
||||||
if (game.player_to_beat != player)
|
if (game.player_to_beat != player)
|
||||||
# hand_type match?
|
# hand_type match?
|
||||||
@truths << (self.hand_type == game.hand_to_beat.hand_type) if game.hand_to_beat.try(:hand_type)
|
@truths << (self.hand_type == game.play_to_beat.try("play").try("hand_type")) if game.play_to_beat.try("play").try(:hand_type)
|
||||||
# beats?
|
# beats?
|
||||||
@truths << (self.beats? self.game.hand_to_beat.try(:play))
|
@truths << (self.beats? self.game.play_to_beat.try(:play))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -122,6 +122,32 @@ RSpec.describe Play, type: :model do
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'mismatch type' do
|
||||||
|
@deck = Deck.new
|
||||||
|
# Hand to beat is a double
|
||||||
|
@cards_to_beat = [
|
||||||
|
@spade4 = PlayerCard.new(@deck.cards[4].instance_values),
|
||||||
|
@club4 = PlayerCard.new(@deck.cards[5].instance_values)
|
||||||
|
]
|
||||||
|
|
||||||
|
@play_to_beat = Play.new
|
||||||
|
@play_to_beat.player = @game.players.where.not(id: @game.active_player.id).first
|
||||||
|
@play_to_beat.player_cards << @cards_to_beat
|
||||||
|
@play_to_beat.game = @game
|
||||||
|
#@play_to_beat.save
|
||||||
|
|
||||||
|
# Attempt to play a single
|
||||||
|
@play.player_cards = [
|
||||||
|
@spade5 = PlayerCard.new(@deck.cards[8].instance_values)
|
||||||
|
]
|
||||||
|
|
||||||
|
@play.reload
|
||||||
|
@game.reload
|
||||||
|
binding.pry unless !@play.valid?
|
||||||
|
|
||||||
|
expect(@play.valid?).to eq(false)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
context 'it beats the hand_to_beat' do
|
context 'it beats the hand_to_beat' do
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user