Skip to content

Commit

Permalink
Merge pull request #22 from x3igh7/challonge
Browse files Browse the repository at this point in the history
added tournament activation and deactivation
  • Loading branch information
x3igh7 committed Feb 7, 2014
2 parents 715adbe + 4b63f0b commit 5ee3cd6
Show file tree
Hide file tree
Showing 11 changed files with 147 additions and 6 deletions.
28 changes: 28 additions & 0 deletions app/controllers/admin/tournaments_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
class Admin::TournamentsController < AdminController

def index
@tournaments = Tournament.all
end

def new
@tournament = Tournament.new
end
Expand Down Expand Up @@ -82,6 +86,30 @@ def create_schedule

end

def deactivate
@tournament = Tournament.find(params[:tournament_id])
@tournament.active = false
if @tournament.save
flash[:notice] = "Tournament deactivated"
redirect_to admin_root_path
else
flash[:alert] = "Failed to deactivate tournament"
render :edit
end
end

def activate
@tournament = Tournament.find(params[:tournament_id])
@tournament.active = true
if @tournament.save
flash[:notice] = "Tournament activated"
redirect_to admin_root_path
else
flash[:alert] = "Failed to activate tournament"
render :edit
end
end

private

def date_converter(params)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class HomeController < ApplicationController

def home
@news = News.where(newsable_id: 0)
@news = News.where(newsable_id: 0).page params[:page]
if user_signed_in?
@user = current_user
@teams = @user.teams
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/tournaments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def show
@active_tournament_team = nil
@tournament_team = TournamentTeam.new
@matches = Match.current_week_matches(@tournament)
@news = @tournament.news
@news = @tournament.news.page params[:page]
@current_user_teams = []
if user_signed_in?
current_user.teams.each do |team|
Expand Down
13 changes: 11 additions & 2 deletions app/views/admin/cpanel/_admincp_manage_tournaments.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,24 @@
<td class="hide-management"><button>hide</button></td>
</tr>
<tr class="management">
<td><%= link_to "edit", edit_admin_tournament_path(tourny) %></td>
<td><%= link_to "edit", edit_admin_tournament_path(tourny), id: "edit-tourny-#{tourny.id}" %></td>
<td><%= link_to "tournament teams", admin_tournament_teams_path(:tournament_id => tourny.id) %></td>
<td><%= link_to "matches", admin_matches_path(:tournament_id => tourny.id) %></td>
<td><%= link_to "set ranks", rankings_admin_tournaments_path(:tournament_id => tourny.id) %></td>
<td><%= link_to "set schedule", schedule_admin_tournaments_path(:tournament_id => tourny.id) %></td>
</tr>
<% end %>
</table>
<div><%= link_to "create new tournament", new_admin_tournament_path, :class => "button" %></div>
<div>
<ul style="list-style-type:none">
<li style="display:inline-block">
<%= link_to "create new tournament", new_admin_tournament_path, :class => "button" %>
</li>
<li style="display:inline-block">
<%= link_to "view all tournaments", admin_tournaments_path, :class => "button" %>
</li>
</ul>
</div>
</div>

</div>
8 changes: 8 additions & 0 deletions app/views/admin/tournaments/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,13 @@
<%= f.input :rules %>
<%= f.submit "update tournament"%>
<% end %>
<div class="spacer" style="margin-bottom:25px"></div>
<div class="content-inner-inner">
<% if @tournament.active %>
<%= button_to "deactivate tournament", admin_tournament_deactivate_path(@tournament), method: :put %>
<% else %>
<%= button_to "activate tournament", admin_tournament_activate_path(@tournament), method: :put %>
<% end %>
</div>

</div>
33 changes: 33 additions & 0 deletions app/views/admin/tournaments/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<h1>tournaments</h1>

<div class="content-inner">
<% if not @tournaments.any? %>
There are currently no tournaments.
<% else %>
<table>
<tr>
<th>Name</th>
<th>Description</th>
<th>Active</th>
<th></th>
</tr>
<% @tournaments.each do |tournament| %>
<tr>
<td><%= tournament.name %></td>
<td><%= tournament.description %></td>
<td><%= tournament.active.to_s.capitalize %></td>
<td class="show-management" style="float:right;"><button id=<%= "manage-tourny-#{tournament.id}" %>>manage</button></td>
<td class="hide-management"><button>hide</button></td>
</tr>
<tr class="management">
<td><%= link_to "edit", edit_admin_tournament_path(tournament), id: "edit-tourny-#{tournament.id}" %></td>
<td><%= link_to "tournament teams", admin_tournament_teams_path(:tournament_id => tournament.id) %></td>
<td><%= link_to "matches", admin_matches_path(:tournament_id => tournament.id) %></td>
<td><%= link_to "set ranks", rankings_admin_tournaments_path(:tournament_id => tournament.id) %></td>
<td><%= link_to "set schedule", schedule_admin_tournaments_path(:tournament_id => tournament.id) %></td>
</tr>
<% end %>
</table>
<% end %>

</div>
4 changes: 2 additions & 2 deletions app/views/application/_index_news.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<p><%= news.description %></p>
<p><%= link_to "read more...", news_path(news)%></a></p>
</div>


<% end %>
<%= paginate @news %>
<% end %>

2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
resources :memberships, :only => [:destroy]
resources :teams, :only => [:edit, :update, :destroy]
resources :tournaments do
put "deactivate"
put "activate"
collection do
get "rankings"
put "update_rankings"
Expand Down
56 changes: 56 additions & 0 deletions spec/features/admincp_edit_tournament_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
require 'spec_helper'

describe "Tournament Edit" do
let!(:tournament1) {FactoryGirl.create(:tournament)}
let!(:tournament2) {FactoryGirl.create(:tournament, active: false)}
let!(:admin) {FactoryGirl.create(:user)}
let!(:team) { FactoryGirl.create(:team) }
let!(:team2) { FactoryGirl.create(:team) }
let!(:tournament_team) {FactoryGirl.create(:tournament_team, team: team, tournament: tournament1)}
let!(:tournament_team2) {FactoryGirl.create(:tournament_team, team: team2, tournament: tournament1)}
let!(:match) { FactoryGirl.create(:match, home_team_id: tournament_team.id, away_team_id: tournament_team2.id, tournament_id: tournament1.id) }

before do
admin.roles = :admin
admin.save
sign_in_as admin
end

it "a tournament can be editted", :js => true do
manage
click_on "edit-tourny-#{tournament1.id}"
fill_in "Rules", with: "New rules"
click_on "update tournament"
expect(Tournament.find(tournament1.id).rules).to eq("New rules")
end

it "a tourament can be deactivated", :js => true do
manage
click_on "edit-tourny-#{tournament1.id}"
click_on "deactivate tournament"
expect(Tournament.find(tournament1.id).active).to be_false
expect(current_path).to eq(admin_root_path)
end

it "deactivated (all) tournaments can be viewed" do
visit admin_root_path
click_on "view all tournaments"
expect(page).to have_content(tournament2.name)
end

it "a non-active tournament can be activated", :js => true do
visit admin_root_path
click_on "view all tournaments"
click_on "manage-tourny-#{tournament2.id}"
click_on "edit-tourny-#{tournament2.id}"
click_on "activate tournament"
expect(Tournament.find(tournament2.id).active).to be_true
expect(current_path).to eq(admin_root_path)
end

end

def manage
visit admin_root_path
click_button "manage"
end
4 changes: 4 additions & 0 deletions spec/features/admincp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
expect(page).to have_content("set schedule")
end

it "can edit a tournament" do

end

end

context "creating a tournament" do
Expand Down
1 change: 1 addition & 0 deletions spec/features/comments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
end

it "can be deleted by admins" do
pending
end
end

0 comments on commit 5ee3cd6

Please sign in to comment.