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

Commit 38ec52f

Browse files
committed
Changing game state through the dedicated methods (eg. Game#running!)
Thoses methods are nice, not using them would be a shame. Do note, however, that they are _not_ used in the specs for the `Game` model. I felt like staying low-level and keep the specs code below the abstraction of those methods made more sense.
1 parent 1951f70 commit 38ec52f

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

app/dispatches/bombs/drop.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def successful_payloads
8282

8383
def finish_game
8484
player.update(won: true)
85-
game.update(state: 'finished')
85+
game.finished!
8686
end
8787
end
8888
end

app/dispatches/players/enlist.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def initialize(game:, player:)
1313

1414
def assign_game_to_player!
1515
@player = Player.create!(nickname: nickname, game: game, life: Player::LIFE)
16-
game.update(state: 'running')
16+
game.running!
1717

1818
return successful_payload
1919
end

spec/requests/opponent_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
context 'when game is full' do
3939
before :each do
40-
game.update(state: 'running')
40+
game.running!
4141
game.players.create!
4242
post "/games/starship-battle/opponent"
4343
end
@@ -54,7 +54,7 @@
5454

5555
context 'when game is already finished' do
5656
before :each do
57-
game.update(state: 'finished')
57+
game.finished!
5858
post "/games/starship-battle/opponent"
5959
end
6060

0 commit comments

Comments
 (0)