From ef93825b94c08ca77fd9d87d8cf0326f4d25d5f5 Mon Sep 17 00:00:00 2001 From: "Jesse C. Fisher" Date: Wed, 28 Oct 2015 20:27:22 -0700 Subject: [PATCH] Fix hand_type validation --- app/models/play.rb | 4 ++-- spec/models/play_spec.rb | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/app/models/play.rb b/app/models/play.rb index 3b4463f7..c9fd62ab 100644 --- a/app/models/play.rb +++ b/app/models/play.rb @@ -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 diff --git a/spec/models/play_spec.rb b/spec/models/play_spec.rb index cf763b6d..235d9f6d 100644 --- a/spec/models/play_spec.rb +++ b/spec/models/play_spec.rb @@ -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