Skip to content
This repository was archived by the owner on Jan 9, 2024. It is now read-only.

Commit f9764cd

Browse files
committed
[hysteria] Cleanup player update
1 parent 7984669 commit f9764cd

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

app/controllers/players_controller.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ class PlayersController < ApplicationController
22
before_action :set_player
33

44
def update
5-
return render json: {error: "Cannot update another user"}, status: 401 if @player != current_player
5+
return render json: { error: "Cannot update another user" }, status: 401 if @player != current_player
66

77
@player.update(player_params)
8-
render json: {status: :ok}, status: 200
8+
render json: { status: :ok }, status: 200
99
end
1010

1111
private
12+
1213
def set_player
1314
@player = Player.find(params[:id])
1415
end

app/views/games/show.html.erb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
<li class="life_bar"><%= render "games/hud/life" %></li>
2020
<li class="life_bar"><%= render "games/hud/life" %></li>
2121
</ul>
22-
<!-- <h1 class="player">Casimir</h1> -->
2322
<div id="current_player" data-player-id="<%= current_player.id %>" data-player-nickname="<%= current_player.nickname %>"></div>
2423
<%= form_for(current_player, url: player_path(current_player), class: "player") do |f|%>
2524
<%= f.text_field :nickname, id: 'current_player_nickname' %>

spec/requests/players_spec.rb

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
require "rails_helper"
22

33
RSpec.describe "Players", type: :request do
4-
let(:player) { Player.create!(nickname: "Rico") }
4+
let(:player) { Player.create!(nickname: "Rico") }
55

66
describe "PUT update" do
77
context 'update current_player' do
88
before :each do
99
allow_any_instance_of(ApplicationController).to receive(:current_player).and_return(player)
10+
put "/players/#{player.id}", params: { player: { nickname: "Zim" }}
1011
end
1112

12-
before { put "/players/#{player.id}", params: {player: {nickname: "Zim"}} }
1313
it { expect(response).to have_http_status(200) }
1414
it { expect(player.reload.nickname).to eq("Zim") }
1515
end
16-
end
1716

18-
context 'update another player' do
19-
let(:other_player) { Player.create!(nickname: "Carmen") }
20-
before :each do
21-
allow_any_instance_of(ApplicationController).to receive(:current_player).and_return(other_player)
22-
end
17+
context 'update another player' do
18+
let(:other_player) { Player.create!(nickname: "Carmen") }
19+
20+
before :each do
21+
allow_any_instance_of(ApplicationController).to receive(:current_player).and_return(other_player)
22+
put "/players/#{player.id}", params: { player: { nickname: "Ace" }}
23+
end
2324

24-
before { put "/players/#{player.id}", params: {player: {nickname: "Ace"}} }
25-
it { expect(response).to have_http_status(401) }
26-
it { expect(player.reload.nickname).to eq("Rico") }
25+
it { expect(response).to have_http_status(401) }
26+
it { expect(player.reload.nickname).to eq("Rico") }
27+
end
2728
end
28-
end
29+
end

0 commit comments

Comments
 (0)