Add feature: Play now
This commit is contained in:
parent
b655e90a43
commit
15a75bc462
@ -95,6 +95,13 @@ class GamesController < ApplicationController
|
||||
respond_with(@game)
|
||||
end
|
||||
|
||||
def play_now
|
||||
# First joinable game or create new game
|
||||
@game = Game.where(status:nil).joins("LEFT OUTER JOIN players ON players.game_id = games.id").group("games.id").having("count(players) < 4").first || Game.create(title: "Game " + current_user.soft_token[0..4])
|
||||
@game.add_player_from_user current_user
|
||||
redirect_to @game
|
||||
end
|
||||
|
||||
def join
|
||||
@game.add_player_from_user(current_user)
|
||||
flash[:notice] = 'Successfully joined game...'
|
||||
|
||||
@ -2,6 +2,6 @@
|
||||
%h1 Thirteen <br/>Tien Len
|
||||
|
||||
#main-menu
|
||||
= link_to 'Play Now', '#'
|
||||
= link_to 'Play Now', play_now_path
|
||||
= link_to 'Browse Tables', '#'
|
||||
= link_to 'Tutorial', '#'
|
||||
|
||||
@ -13,7 +13,7 @@ Rails.application.routes.draw do
|
||||
|
||||
mount Upmin::Engine => '/admin'
|
||||
root to: 'visitors#index'
|
||||
get '/quick-play', to: 'visitors#quick-play'
|
||||
get '/quick-play', to: 'games#play_now', as: 'play_now'
|
||||
devise_for :users, controllers: { registrations: "users/registrations" }
|
||||
resources :users
|
||||
get '/loaderio-456644f4db1fcd1e8578be882d2fc476.txt', to: redirect('/assets/loaderio-456644f4db1fcd1e8578be882d2fc476.txt')
|
||||
|
||||
28
spec/features/play_now_spec.rb
Normal file
28
spec/features/play_now_spec.rb
Normal file
@ -0,0 +1,28 @@
|
||||
# Feature: Play now
|
||||
# As a visitor
|
||||
# I want to quickly join a game
|
||||
# So I can play
|
||||
feature 'Play now', :devise do
|
||||
before { @game = FactoryGirl.create :game }
|
||||
# Scenario: Visitor can play now
|
||||
# Given I am not signed in
|
||||
# When I click Play Now
|
||||
# Then I join a game
|
||||
scenario 'visitor can join a game', js: true do
|
||||
visit root_path
|
||||
click_link 'Play Now'
|
||||
expect(page).to have_content "Test Game"
|
||||
expect(current_path).to eq game_path(@game)
|
||||
@player = @game.players.last
|
||||
@playerComponent = page.find("#player-1")
|
||||
expect(@playerComponent.text).to have_content("Guest#{@player.soft_token[0..5]}")
|
||||
|
||||
# Add another player
|
||||
@game.add_player_from_user FactoryGirl.create :user
|
||||
#TODO: Remove race condition
|
||||
visit current_path
|
||||
click_button 'Start'
|
||||
visit current_path
|
||||
expect(page).to have_content 'Inventory'
|
||||
end
|
||||
end
|
||||
Loading…
x
Reference in New Issue
Block a user