Fix hand_type validation

This commit is contained in:
Jesse C. Fisher 2015-10-28 20:27:22 -07:00
parent 44839d9ddd
commit ef93825b94
2 changed files with 28 additions and 2 deletions

View File

@ -34,9 +34,9 @@ class Play < ActiveRecord::Base
# current player is not the player to beat
if (game.player_to_beat != player)
# 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?
@truths << (self.beats? self.game.hand_to_beat.try(:play))
@truths << (self.beats? self.game.play_to_beat.try(:play))
end
end

View File

@ -122,6 +122,32 @@ RSpec.describe Play, type: :model do
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
context 'it beats the hand_to_beat' do