Skip to content

Commit

Permalink
Register game updates time.
Browse files Browse the repository at this point in the history
  • Loading branch information
lynnfaraday committed Jul 16, 2023
1 parent d279074 commit e6c5633
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/commands/api_game_register.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def handle
if (!game.valid?)
return { status: "failure", error: game.error_str }.to_json
end
game.last_ping = Time.now

game.save!
{ status: "success", data: { game_id: game.id.to_s, api_key: game.api_key } }.to_json
Expand Down
3 changes: 3 additions & 0 deletions spec/api_game_register_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
Game.should_receive(:new) { game }
game.stub(:api_key) { "ABC" }
game.stub(:id) { "123" }
Time.stub(:now) { 1 }

game.should_receive(:last_ping=).with(1)
game.should_receive(:valid?) { true }
game.should_receive(:update_from).with({ name: "Test", host: "somewhere.com", port: 1234 })
game.should_receive(:save!)
Expand Down
16 changes: 16 additions & 0 deletions spec/post_handle_create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,36 @@
@handler = PostHandleCreateCmd.new(params, @session, @server, @view_data)

File.stub(:read).with('banned.txt') { "123\n456"}
File.stub(:read).with('blacklist.txt') { "789"}

@server.should_receive(:ip_addr) { "123" }
@server.should_receive(:show_flash).with(:error, "You cannot create a handle at this time. Your site has been banned, or you're connected from a proxy/VPN server that's on our blacklist.")
@server.should_receive(:redirect_to).with('/')

@handler.handle
end

it "should show flash message and redirect if IP blacklisted" do
params = { name: "Star"}
@handler = PostHandleCreateCmd.new(params, @session, @server, @view_data)

File.stub(:read).with('banned.txt') { "123\n456"}
File.stub(:read).with('blacklist.txt') { "789"}

@server.should_receive(:ip_addr) { "789" }
@server.should_receive(:show_flash).with(:error, "You cannot create a handle at this time. Your site has been banned, or you're connected from a proxy/VPN server that's on our blacklist.")
@server.should_receive(:redirect_to).with('/')

@handler.handle
end

it "should save if handle is new and params valid" do
handle = double
params = { name: "Star", password: "pw"}
@handler = PostHandleCreateCmd.new(params, @session, @server, @view_data)

File.stub(:read).with('banned.txt') { "456\n789"}
File.stub(:read).with('blacklist.txt') { "789"}

Handle.should_receive(:new) { handle }
handle.should_receive(:create_from).with(params)
Expand Down

0 comments on commit e6c5633

Please sign in to comment.