diff --git a/app/controllers/admin/tournaments_controller.rb b/app/controllers/admin/tournaments_controller.rb index 37d7f6f..b7a4859 100644 --- a/app/controllers/admin/tournaments_controller.rb +++ b/app/controllers/admin/tournaments_controller.rb @@ -1,5 +1,9 @@ class Admin::TournamentsController < AdminController + def index + @tournaments = Tournament.all + end + def new @tournament = Tournament.new end @@ -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) diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index b7039a1..1582d2f 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -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 diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index 0e2f16f..7c899ca 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -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| diff --git a/app/views/admin/cpanel/_admincp_manage_tournaments.html.erb b/app/views/admin/cpanel/_admincp_manage_tournaments.html.erb index 355cf2a..43dc7aa 100644 --- a/app/views/admin/cpanel/_admincp_manage_tournaments.html.erb +++ b/app/views/admin/cpanel/_admincp_manage_tournaments.html.erb @@ -10,7 +10,7 @@ - <%= link_to "edit", edit_admin_tournament_path(tourny) %> + <%= link_to "edit", edit_admin_tournament_path(tourny), id: "edit-tourny-#{tourny.id}" %> <%= link_to "tournament teams", admin_tournament_teams_path(:tournament_id => tourny.id) %> <%= link_to "matches", admin_matches_path(:tournament_id => tourny.id) %> <%= link_to "set ranks", rankings_admin_tournaments_path(:tournament_id => tourny.id) %> @@ -18,7 +18,16 @@ <% end %> -
<%= link_to "create new tournament", new_admin_tournament_path, :class => "button" %>
+
+ +
diff --git a/app/views/admin/tournaments/edit.html.erb b/app/views/admin/tournaments/edit.html.erb index 0af9a75..fa5f889 100644 --- a/app/views/admin/tournaments/edit.html.erb +++ b/app/views/admin/tournaments/edit.html.erb @@ -9,5 +9,13 @@ <%= f.input :rules %> <%= f.submit "update tournament"%> <% end %> +
+
+<% 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 %> +
diff --git a/app/views/admin/tournaments/index.html.erb b/app/views/admin/tournaments/index.html.erb new file mode 100644 index 0000000..4be2357 --- /dev/null +++ b/app/views/admin/tournaments/index.html.erb @@ -0,0 +1,33 @@ +

tournaments

+ +
+ <% if not @tournaments.any? %> + There are currently no tournaments. + <% else %> + + + + + + + + <% @tournaments.each do |tournament| %> + + + + + + + + + + + + + + + <% end %> +
NameDescriptionActive
<%= tournament.name %><%= tournament.description %><%= tournament.active.to_s.capitalize %>
<%= link_to "edit", edit_admin_tournament_path(tournament), id: "edit-tourny-#{tournament.id}" %><%= link_to "tournament teams", admin_tournament_teams_path(:tournament_id => tournament.id) %><%= link_to "matches", admin_matches_path(:tournament_id => tournament.id) %><%= link_to "set ranks", rankings_admin_tournaments_path(:tournament_id => tournament.id) %><%= link_to "set schedule", schedule_admin_tournaments_path(:tournament_id => tournament.id) %>
+ <% end %> + +
diff --git a/app/views/application/_index_news.html.erb b/app/views/application/_index_news.html.erb index 2beddcc..6bd99ea 100644 --- a/app/views/application/_index_news.html.erb +++ b/app/views/application/_index_news.html.erb @@ -8,7 +8,7 @@

<%= news.description %>

<%= link_to "read more...", news_path(news)%>

- - <% end %> + <%= paginate @news %> <% end %> + diff --git a/config/routes.rb b/config/routes.rb index 0fa0e8e..6ab59a5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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" diff --git a/spec/features/admincp_edit_tournament_spec.rb b/spec/features/admincp_edit_tournament_spec.rb new file mode 100644 index 0000000..e32870a --- /dev/null +++ b/spec/features/admincp_edit_tournament_spec.rb @@ -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 diff --git a/spec/features/admincp_spec.rb b/spec/features/admincp_spec.rb index 21c9832..c82377a 100644 --- a/spec/features/admincp_spec.rb +++ b/spec/features/admincp_spec.rb @@ -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 diff --git a/spec/features/comments_spec.rb b/spec/features/comments_spec.rb index 91ef33f..86d3317 100644 --- a/spec/features/comments_spec.rb +++ b/spec/features/comments_spec.rb @@ -6,5 +6,6 @@ end it "can be deleted by admins" do + pending end end