Played cards vs inventory control

This commit is contained in:
Jesse C. Fisher 2015-08-08 04:41:23 -07:00
parent aca20160a0
commit ca423cae99
3 changed files with 69 additions and 7 deletions

View File

@ -8,4 +8,8 @@ class Player < ActiveRecord::Base
validates :user_id, presence: true
validates :game_id, presence: true
def inventory
player_cards.where(play_id: nil).order(:value)
end
end

View File

@ -32,15 +32,15 @@
%strong= "My Turn " if @game.control_player == player
// Show the players' cards
- unless player.player_cards.empty?
- unless player.inventory.empty?
%ul.cards
- player.player_cards.order(:value).each do |card|
- player.inventory.each do |card|
%li
%label
// If the cards belong to the user, allow them to select the cards to play as a hand
= check_box_tag 'player_card_ids[]', card.id, false, form: "edit_game_#{@game.id}" if player.user == current_user
// Show the card TODO hide values of cards of other players
= [card.rank, card.suit].join(' ')
= card.to_s
-# TODO better logic, not in view
- unless @game.status == nil

View File

@ -41,15 +41,73 @@ feature 'Play a hand', type: :feature do
"First hand must contain the lowest card: #{game.lowest_card.to_s}"
end
# Scenario: Played cards leave the players inventory
# Given I am the current player
# When I play a hand
# Then the cards played should leave my inventory
scenario 'played cards are removed from the players inventory' do
game = setup_game
# Store initial state of players inventory
@player = game.current_player
@player_inventory = @player.player_cards.order(:value).join(' ')
@player_inventory = @player.inventory.order(:value).join(' ')
login_as(game.current_player.user, scope: :user)
visit game_path game
@card_to_play = game.current_player.player_cards.order(:value).first
check @card_to_play.to_s
click_button 'Play Hand'
# Played hand is rendered
expect(page).to have_content('Played ' + game.lowest_card.to_s)
# Player inventory is rendered without played cards
expect(page).to have_content(@player_inventory.gsub(@card_to_play.to_s,''))
# Player inventory method does not return played cards
expect(@player.inventory.order(:value).join(' ')).to_not have_content(@card_to_play.to_s)
end
# Scenario: Current player status updates after successful play
# Given I am the current player
# When I play a hand
# Then the next player becomes the current player
scenario 'current player rotates after a valid hand' do
skip 'to be implemented'
game = setup_game
login_as(game.current_player.user, scope: :user)
@current_player_id = game.current_player.id
@current_player_index = game.players.index(game.current_player)
visit game_path game
@card_to_play = game.current_player.player_cards.order(:value).first
check @card_to_play.to_s
click_button 'Play Hand'
expect(page).to have_content('Played ' + @card_to_play.to_s)
expect(game.current_player.id).to_not eq(@current_player_id)
expect(game.players.index(game.current_player)).to eq( (@current_player_id + 1) % 2)
end
# Scenario: Player can play a valid hand on their turn
# Given I am the active player
# When I play a valid hand
# And the last played card was a single card
# When I play a valid hand of one higher card
# Then I see a successful play message
scenario 'active player can play a valid hand' do
# create game with players
# current_player plays a valid hand
# expect successful play message
skip 'to be implemented'
# create game with players
game = setup_game
# current_player plays the lowest card
login_as(game.current_player.user, scope: :user)
visit game_path game
@card_to_play = game.lowest_card
check @card_to_play.to_s
click_button 'Play Hand'
expect(page).to have_content('Played ' + game.lowest_card.to_s)
# next player plays a valid hand
login_as(game.current_player.user, scope: :user)
visit game_path game
expect(page).to have_content('Played ' + game.lowest_card.to_s)
@card_to_play = game.current_player.player_cards.order(:value).first
check @card_to_play.to_s
click_button 'Play Hand'
expect(page).to have_content('Played ' + @card_to_play.to_s)
# expect successful play message
end
# Scenario: Player can not play an invalid hand on their turn