Skip to content

Commit

Permalink
[94] Create league#index
Browse files Browse the repository at this point in the history
  • Loading branch information
notmarkmiranda committed Feb 15, 2019
1 parent 4b5b8f8 commit 61cb9ee
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 1 deletion.
4 changes: 4 additions & 0 deletions app/controllers/leagues_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
class LeaguesController < ApplicationController
def index
@leagues = League.non_private.decorate
end

def show
authorize league
@current_season = league.current_season
Expand Down
6 changes: 6 additions & 0 deletions app/decorators/league_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@ def game_frequency_text
h.pluralize(h.number_with_precision(object.games_every_x_weeks, precision: 2), 'week')
end
end

def public_league_stats
"# of Games: #{object.games_count} | \
Average Players per Game: #{object.average_players_per_game} | \
Average Pot: #{h.number_to_currency(object.average_pot_size, precision: 0) }"
end
end
2 changes: 2 additions & 0 deletions app/models/league.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class League < ApplicationRecord
after_create_commit :create_first_season
after_create_commit :create_adminship

scope :non_private, -> { where(privated: false) }

def admins
User
.joins(:memberships)
Expand Down
24 changes: 24 additions & 0 deletions app/views/leagues/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<div class="d-flex justify-content-center">
<div class="col-lg-10">
<div class="card leagues mb-4">
<div class="card-header header-text">
Public Leagues
</div>
<ul class="list-group list-group-flush leagues-list">
<% @leagues.each do |league| %>
<li class="list-group-item public-league">
<div class="caption-text text-primary">
Denver, Colorado
</div>
<span class="stat-line">
<%= league.name %>
</span>
<div class="caption-text text-info">
<%= league.public_league_stats %>
</div>
</li>
<% end %>
</ul>
</div>
</div>
</div>
14 changes: 13 additions & 1 deletion spec/features/leagues/league_index_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
require 'rails_helper'

describe 'Visitor can view league#index', type: :feature do
describe 'as a visitor'
describe 'as a visitor' do
let!(:public_league) { create(:league, privated: false) }

it 'should show the details for a public leagues and details for private leagues' do
visit leagues_path

within('.public-league') do
expect(page).to have_content public_league.name
expect(page).to have_content public_league.games_count
expect(page).to have_content public_league.average_players_per_game
end
end
end
end

0 comments on commit 61cb9ee

Please sign in to comment.