Create button to remove bots
This commit is contained in:
parent
614a53b253
commit
6330a6b4e1
@ -1,5 +1,5 @@
|
||||
class SeatsController < ApplicationController
|
||||
before_action :set_seat, only: [:show, :edit, :update, :destroy, :sit, :stand, :add_bot]
|
||||
before_action :set_seat, only: [:show, :edit, :update, :destroy, :sit, :stand, :add_bot, :remove_bot]
|
||||
|
||||
respond_to :html, :json
|
||||
|
||||
@ -85,6 +85,11 @@ class SeatsController < ApplicationController
|
||||
redirect_to @seat.table, notice: @message
|
||||
end
|
||||
|
||||
def remove_bot
|
||||
@message = @seat.remove_bot
|
||||
redirect_to @seat.table, notice: @message
|
||||
end
|
||||
|
||||
private
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_seat
|
||||
|
||||
@ -61,6 +61,20 @@ class Seat < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
def remove_bot
|
||||
if !self.occupied?
|
||||
return "Failed to remove Bot seat empty"
|
||||
else
|
||||
if self.player.is_bot?
|
||||
self.player.is_bot = false
|
||||
self.player.save
|
||||
return "Removed Bot"
|
||||
end
|
||||
|
||||
return "Failed to remove Bot"
|
||||
end
|
||||
end
|
||||
|
||||
def occupied?
|
||||
self.user_id.present? || self.user_soft_token.present? || self.try("player").try("is_bot?") == true
|
||||
end
|
||||
|
||||
@ -2,6 +2,9 @@
|
||||
.seat{class: "position-#{@seats.index(seat) + 1}"}
|
||||
.seat-controls
|
||||
- if seat.occupied?
|
||||
- if seat.player.is_bot?
|
||||
= button_to remove_bot_seat_path(seat) do
|
||||
- "- Bot"
|
||||
- if seat.occupied_by? current_user
|
||||
= button_to stand_seat_path(seat), :data => { :confirm => 'Are you sure you want to leave this seat?' } do
|
||||
- "Stand"
|
||||
|
||||
@ -22,6 +22,7 @@ Rails.application.routes.draw do
|
||||
post 'sit'
|
||||
post 'stand'
|
||||
post 'add_bot'
|
||||
post 'remove_bot'
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
22
spec/features/bots/remove_bot_players_spec.rb
Normal file
22
spec/features/bots/remove_bot_players_spec.rb
Normal file
@ -0,0 +1,22 @@
|
||||
# Feature: Remove bot from seat
|
||||
# As a user
|
||||
# I want to remove a bot from a sea
|
||||
feature 'Remove bot', type: :feature do
|
||||
before(:each) do
|
||||
@table = FactoryGirl.create :table
|
||||
visit table_path @table
|
||||
end
|
||||
# Scenario: Visitor can remove a bot from seat
|
||||
# Given I can edit the table
|
||||
# When I see the seat with a bot
|
||||
# Then I see a button to remove a bot
|
||||
scenario 'visitor can remove a bot from a seat' do
|
||||
@button = page.find_button('+ Bot', match: :first).click
|
||||
page.assert_selector('button', text: '+ Bot', count: 3)
|
||||
expect(page).to have_content "BotPlayer"
|
||||
@button = page.find_button('- Bot', match: :first).click
|
||||
expect(page).to have_content "Removed Bot"
|
||||
page.assert_selector('button', text: '+ Bot', count: 4)
|
||||
end
|
||||
|
||||
end
|
||||
Loading…
x
Reference in New Issue
Block a user