Skip to content

Commit

Permalink
Merge pull request #81 from notmarkmiranda/76-clicking-on-player-in-u…
Browse files Browse the repository at this point in the history
…ncomplete-game-error

Fix clicking on player from uncomplete game
  • Loading branch information
notmarkmiranda committed Feb 12, 2019
2 parents 869a247 + da93edc commit 37de1d4
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
2 changes: 2 additions & 0 deletions app/controllers/user_stats_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ def show
@players = @user.players.joins(:game)
.where('games.season_id = ?', params[:season])
.order('games.date DESC')
.decorate
else
@season = nil
@players = @user.players.joins(:game)
.order('games.date DESC')
.decorate
end
end
end
7 changes: 7 additions & 0 deletions app/decorators/player_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ def name_with_place
end
end

def place_and_score
return unless object.finishing_place && object.score
h.content_tag(:div, class: 'caption-text text-danger') do
"#{object.finishing_place.ordinalize} place out of #{h.pluralize(object.game_players_count, 'player')} | Score: #{object.score}"
end
end

def score_text
additional_expense = object.has_additional_expense?
if game_object.completed?
Expand Down
7 changes: 3 additions & 4 deletions app/views/user_stats/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@
<ul class="list-group list-group-flush">
<% @players.each do |player| %>
<%= link_to game_path(player.game), class: 'list-group-item list-group-item-action' do %>
<div class="caption-text text-danger">
<%= player.finishing_place.ordinalize %> place out of <%= pluralize(player.game_players_count, 'player') %>
| Score: <%= player.score %>
</div>
<%= player.place_and_score %>

<div class="header-text">
<%= player.game_formatted_full_date %>
<% unless @season %>
Expand Down
15 changes: 15 additions & 0 deletions spec/decorators/player_decorator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,21 @@
end
end

context '#place_and_score' do
subject(:place_and_score) { player.place_and_score }

it 'returns nil' do
player.update(finishing_place: nil)

expect(place_and_score).to be nil
end

it 'returns the correct text' do
expected_return = "<div class=\"caption-text text-danger\">1st place out of 1 player | Score: 1.5</div>"
expect(place_and_score).to eq(expected_return)
end
end

context '#score_text' do
subject { player.score_text }

Expand Down

0 comments on commit 37de1d4

Please sign in to comment.