From bd513c705c90a6e52e8cef5f3bd71a0c0975920c Mon Sep 17 00:00:00 2001 From: Lisa Hamm Date: Thu, 26 Feb 2015 14:10:14 -0600 Subject: [PATCH] Added game setup validation to controller --- tic_tac_toe_controller.rb | 15 +++++++-------- tic_tac_toe_controller_spec.rb | 28 ---------------------------- 2 files changed, 7 insertions(+), 36 deletions(-) delete mode 100644 tic_tac_toe_controller_spec.rb diff --git a/tic_tac_toe_controller.rb b/tic_tac_toe_controller.rb index ed4e693..9a4e5fb 100644 --- a/tic_tac_toe_controller.rb +++ b/tic_tac_toe_controller.rb @@ -11,16 +11,15 @@ class TicTacToeController < Sinatra::Base end post '/setup' do - - if !setup_valid?(params) - @invalid_input_messages = error_messages + @setup = GameSetup.new(params) + if @setup.invalid? erb :index + else + session[:mark] = params[:player_mark] + session[:opponent] = params[:opponent] + session[:player_order] = params[:player_order] + redirect to('/game') end - - session[:mark] = params[:player_mark] - session[:opponent] = params[:opponent] - session[:player_order] = params[:player_order] - redirect to('/game') end get '/game' do diff --git a/tic_tac_toe_controller_spec.rb b/tic_tac_toe_controller_spec.rb deleted file mode 100644 index d9df7cb..0000000 --- a/tic_tac_toe_controller_spec.rb +++ /dev/null @@ -1,28 +0,0 @@ -ENV['RACK_ENV'] = 'test' - - -require './../tic_tac_toe_controller' -require 'rspec' -require 'rack/test' - -describe 'The HelloWorld App' do - include Rack::Test::Methods - - def app - TicTacToeController - end - - it "says hello" do - get '/' - expect(last_response).to be_ok - expect(last_response.status).to eq 200 - expect(last_response.body).to include "Player 1, select your mark" - end - - it "starts the game" do - post "/setup", player_mark: "X", opponent: "yes" - expect(last_response).to be_redirect - - #expect(session[:mark]).to eq "O" - end -end \ No newline at end of file