Permalink
Browse files

Tests for map index

  • Loading branch information...
1 parent 8be2172 commit 97e83593fbc0e647b596f751ffae84c42cdb1409 @kyledrake kyledrake committed Apr 26, 2011
Showing with 29 additions and 2 deletions.
  1. +5 −1 pdx_pacman.rb
  2. +24 −1 spec/pdx_pacman.rb
View
@@ -35,7 +35,11 @@ class PdxPacman < Sinatra::Base
end
get '/game/:layer_id/?' do
- @game = Game.first_or_create :layer_id => params[:layer_id]
+ begin
+ @game = Game.create_unless_exists params[:layer_id]
+ rescue Geoloqi::Error
+ redirect '/'
+ end
erb :'index'
end
View
@@ -58,7 +58,7 @@ def app; PdxPacman end
EM.synchrony do
get '/game/1QY/join?code=1234'
- EventMachine.stop
+ EM.stop
end
last_response.should be_redirect
last_response.headers['Location'].should == 'http://example.org/game/1QY'
@@ -69,4 +69,27 @@ def app; PdxPacman end
Team.all(:name => 'red').length.should == 1
Team.all(:name => 'blue').length.should == 1
end
+
+ it 'loads game for valid layer' do
+ EM.synchrony do
+ get '/game/1QY'
+ EM.stop
+ end
+ last_response.should be_ok
+ last_response.should =~ /map ?attack/i
+ end
+
+ it 'redirects to index for invalid layer' do
+ stub_request(:get, "https://api.geoloqi.com/1/layer/info/DADEMURPHYRULZOK").
+ with(:headers => {:authorization => "OAuth #{Geoloqi::OAUTH_TOKEN}", :content_type => 'application/json'}).
+ to_return(:status => 200, :body => {"error"=>"access_denied", "error_description"=>"Access denied to this layer"}.to_json)
+
+ EM.synchrony do
+ get '/game/DADEMURPHYRULZOK'
+ EM.stop
+ end
+ last_response.should be_redirect
+ last_response.headers['Location'].should == 'http://example.org/'
+ end
+
end

0 comments on commit 97e8359

Please sign in to comment.