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

Commit d6de4da

Browse files
committed
Fix game finished results
- Say that user won when he won :D
1 parent aa9e2d4 commit d6de4da

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

app/views/games/finished.html.erb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</div>
1010
</div>
1111
<div class="too_late">
12-
<% if @game.players.include?(current_player) && current_player.won == false %>
12+
<% if @game.players.include?(current_player) && current_player.won %>
1313
<h1>Game Finished, Congratulations! You WON!</h1>
1414
<p>
1515
You're the master of the <strong><%= @game.name %></strong> room
@@ -29,7 +29,8 @@
2929
<strong><%= @game.players.last.nickname %></strong> had an epic fight deep in the space.
3030
</p>
3131
<% end %>
32-
<p>In total, the battle involved <strong><%= @game.ships.count %> ships</strong> and <strong><%= @game.ships.sum(:damage) %> damages</strong>.</p>
32+
33+
<p>In total, the battle involved <strong><%= @game.ships.count %> ships</strong> and <strong><%= @game.ships.sum(:damage) %> damages</strong>.</p>
3334

3435
<%= render 'components/social_links' %>
3536
</div>

spec/requests/games_spec.rb

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
let(:game) { Game.create!(name: 'Starship Battle', slug: 'starship-battle') }
55

66
describe "GET show" do
7-
context "url is not parametrized" do
7+
context "url is not parameterized" do
88
before :each do
99
get URI::encode("/games/#{game.name}")
1010
end
@@ -107,15 +107,42 @@
107107
end
108108

109109
context "when game is finished" do
110+
let(:rico) { Player.create!(nickname: "Rico") }
111+
let(:zim) { Player.create!(nickname: "Zim") }
112+
110113
before :each do
111114
game.update(state: "finished")
112-
Player.create!(nickname: "Zim", game: game)
113-
Player.create!(nickname: "Rico", game: game, won: true)
114115

116+
rico.update!(game: game, won: true)
117+
zim.update!(game: game, won: false)
118+
end
119+
120+
it 'displays that game is finished' do
115121
get "/games/#{game.to_param}"
122+
expect(response.body).to include("finished")
123+
end
124+
125+
context 'wen signed in player won the game' do
126+
before :each do
127+
allow_any_instance_of(ApplicationController).to receive(:current_player).and_return(rico)
128+
end
129+
130+
it 'displays that user won the game' do
131+
get "/games/#{game.to_param}"
132+
expect(response.body).to include("WON")
133+
end
116134
end
117135

118-
it { expect(response.body).to include("finished") }
136+
context 'when signed in player lost the game' do
137+
before :each do
138+
allow_any_instance_of(ApplicationController).to receive(:current_player).and_return(zim)
139+
end
140+
141+
it 'displays that user lost the game' do
142+
get "/games/#{game.to_param}"
143+
expect(response.body).to include("LOSE")
144+
end
145+
end
119146
end
120147
end
121148

0 commit comments

Comments
 (0)