diff --git a/app/models/play.rb b/app/models/play.rb index 3b4463f..c9fd62a 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 cf763b6..235d9f6 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