mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-03-25 01:14:43 +00:00
Added logic to delegate tournament access
This commit is contained in:
@@ -1,5 +0,0 @@
|
|||||||
class AdminController < ApplicationController
|
|
||||||
def index
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -3,4 +3,8 @@ class ApplicationController < ActionController::Base
|
|||||||
# For APIs, you may want to use :null_session instead.
|
# For APIs, you may want to use :null_session instead.
|
||||||
protect_from_forgery with: :exception
|
protect_from_forgery with: :exception
|
||||||
|
|
||||||
|
rescue_from CanCan::AccessDenied do |exception|
|
||||||
|
# flash[:error] = "Access denied!"
|
||||||
|
redirect_to '/static_pages/not_allowed'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -49,8 +49,6 @@ class MatchesController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def check_access
|
def check_access
|
||||||
if current_user != @match.tournament.user
|
authorize! :manage, @match.tournament
|
||||||
redirect_to '/static_pages/not_allowed'
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -89,9 +89,7 @@ class MatsController < ApplicationController
|
|||||||
elsif @mat
|
elsif @mat
|
||||||
@tournament = @mat.tournament
|
@tournament = @mat.tournament
|
||||||
end
|
end
|
||||||
if current_user != @tournament.user
|
authorize! :manage, @tournament
|
||||||
redirect_to '/static_pages/not_allowed'
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -84,9 +84,7 @@ class SchoolsController < ApplicationController
|
|||||||
elsif @school
|
elsif @school
|
||||||
@tournament = @school.tournament
|
@tournament = @school.tournament
|
||||||
end
|
end
|
||||||
if current_user != @tournament.user
|
authorize! :manage, @tournament
|
||||||
redirect_to '/static_pages/not_allowed'
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
class StaticPagesController < ApplicationController
|
class StaticPagesController < ApplicationController
|
||||||
|
|
||||||
def my_tournaments
|
def my_tournaments
|
||||||
@tournaments = current_user.tournaments.sort_by{|t| t.daysUntil}
|
tournaments_created = current_user.tournaments
|
||||||
|
tournaments_delegated = current_user.delegated_tournaments
|
||||||
|
all_tournaments = tournaments_created + tournaments_delegated
|
||||||
|
@tournaments = all_tournaments.sort_by{|t| t.daysUntil}
|
||||||
end
|
end
|
||||||
|
|
||||||
def not_allowed
|
def not_allowed
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
class TournamentsController < ApplicationController
|
class TournamentsController < ApplicationController
|
||||||
before_action :set_tournament, only: [:matches,:weigh_in,:weigh_in_weight,:create_custom_weights,:show,:edit,:update,:destroy,:up_matches,:no_matches,:team_scores,:brackets,:generate_matches,:bracket,:all_brackets]
|
before_action :set_tournament, only: [:matches,:weigh_in,:weigh_in_weight,:create_custom_weights,:show,:edit,:update,:destroy,:up_matches,:no_matches,:team_scores,:brackets,:generate_matches,:bracket,:all_brackets]
|
||||||
before_filter :check_access, only: [:weigh_in,:weigh_in_weight,:create_custom_weights,:update,:edit,:destroy,:generate_matches,:matches]
|
before_filter :check_access_manage, only: [:weigh_in,:weigh_in_weight,:create_custom_weights,:update,:edit,:generate_matches,:matches]
|
||||||
|
before_filter :check_access_destroy, only: [:destroy]
|
||||||
|
|
||||||
before_filter :check_for_matches, only: [:up_matches,:bracket,:all_brackets]
|
before_filter :check_for_matches, only: [:up_matches,:bracket,:all_brackets]
|
||||||
|
|
||||||
def matches
|
def matches
|
||||||
@@ -149,10 +151,12 @@ class TournamentsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
#Check for tournament owner
|
#Check for tournament owner
|
||||||
def check_access
|
def check_access_destroy
|
||||||
if current_user != @tournament.user
|
authorize! :destroy, @tournament
|
||||||
redirect_to '/static_pages/not_allowed'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def check_access_manage
|
||||||
|
authorize! :manage, @tournament
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_for_matches
|
def check_for_matches
|
||||||
|
|||||||
@@ -63,9 +63,6 @@ class WeightsController < ApplicationController
|
|||||||
# DELETE /weights/1.json
|
# DELETE /weights/1.json
|
||||||
def destroy
|
def destroy
|
||||||
@tournament = Tournament.find(@weight.tournament_id)
|
@tournament = Tournament.find(@weight.tournament_id)
|
||||||
if current_user != @tournament.user
|
|
||||||
redirect_to root_path
|
|
||||||
end
|
|
||||||
@weight.destroy
|
@weight.destroy
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { redirect_to @tournament }
|
format.html { redirect_to @tournament }
|
||||||
@@ -91,9 +88,7 @@ class WeightsController < ApplicationController
|
|||||||
elsif @weight
|
elsif @weight
|
||||||
@tournament = @weight.tournament
|
@tournament = @weight.tournament
|
||||||
end
|
end
|
||||||
if current_user != @tournament.user
|
authorize! :manage, @tournament
|
||||||
redirect_to '/static_pages/not_allowed'
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -99,8 +99,6 @@ class WrestlersController < ApplicationController
|
|||||||
elsif @wrestler
|
elsif @wrestler
|
||||||
@tournament = @wrestler.tournament
|
@tournament = @wrestler.tournament
|
||||||
end
|
end
|
||||||
if current_user != @tournament.user
|
authorize! :manage, @tournament
|
||||||
redirect_to '/static_pages/not_allowed'
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,14 +1,4 @@
|
|||||||
module ApplicationHelper
|
module ApplicationHelper
|
||||||
def tournament_permissions(tournament)
|
|
||||||
if user_signed_in?
|
|
||||||
if tournament.user == current_user
|
|
||||||
return true
|
|
||||||
else
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
else
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
58
app/models/ability.rb
Normal file
58
app/models/ability.rb
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
class Ability
|
||||||
|
include CanCan::Ability
|
||||||
|
|
||||||
|
def initialize(user)
|
||||||
|
# Define abilities for the passed in user here. For example:
|
||||||
|
#
|
||||||
|
# user ||= User.new # guest user (not logged in)
|
||||||
|
# if user.admin?
|
||||||
|
# can :manage, :all
|
||||||
|
# else
|
||||||
|
# can :read, :all
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# The first argument to `can` is the action you are giving the user
|
||||||
|
# permission to do.
|
||||||
|
# If you pass :manage it will apply to every action. Other common actions
|
||||||
|
# here are :read, :create, :update and :destroy.
|
||||||
|
#
|
||||||
|
# The second argument is the resource the user can perform the action on.
|
||||||
|
# If you pass :all it will apply to every resource. Otherwise pass a Ruby
|
||||||
|
# class of the resource.
|
||||||
|
#
|
||||||
|
# The third argument is an optional hash of conditions to further filter the
|
||||||
|
# objects.
|
||||||
|
# For example, here the user can only update published articles.
|
||||||
|
#
|
||||||
|
# can :update, Article, :published => true
|
||||||
|
#
|
||||||
|
# See the wiki for details:
|
||||||
|
# https://github.com/CanCanCommunity/cancancan/wiki/Defining-Abilities
|
||||||
|
if !user.nil?
|
||||||
|
#Can manage tournament if tournament owner
|
||||||
|
can :manage, Tournament, :user_id => user.id
|
||||||
|
#Can manage but cannot destroy tournament if tournament delegate
|
||||||
|
can :manage, Tournament do |tournament|
|
||||||
|
tournament.delegates.map(&:user_id).include? user.id
|
||||||
|
end
|
||||||
|
cannot :destroy, Tournament do |tournament|
|
||||||
|
tournament.delegates.map(&:user_id).include? user.id
|
||||||
|
end
|
||||||
|
#Can manage school if tournament owner
|
||||||
|
can :manage, School do |school|
|
||||||
|
school.tournament.map(&:user_id).include? user.id
|
||||||
|
end
|
||||||
|
#Can manage school if tournament delegate
|
||||||
|
can :manage, School do |school|
|
||||||
|
school.tournament.delegates.map(&:user_id).include? user.id
|
||||||
|
end
|
||||||
|
#Can manage but cannot destroy school if school delegate
|
||||||
|
can :manage, School do |school|
|
||||||
|
school.delegates.map(&:user_id).include? user.id
|
||||||
|
end
|
||||||
|
cannot :destroy, School do |school|
|
||||||
|
school.delegates.map(&:user_id).include? user.id
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -30,7 +30,7 @@ class Mat < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def unfinishedMatches
|
def unfinishedMatches
|
||||||
matches.select{|m| m.finished == nil}.sort_by{|m| m.bout_number}
|
matches.select{|m| m.finished != 1}.sort_by{|m| m.bout_number}
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ class School < ActiveRecord::Base
|
|||||||
belongs_to :tournament, touch: true
|
belongs_to :tournament, touch: true
|
||||||
has_many :wrestlers, dependent: :destroy
|
has_many :wrestlers, dependent: :destroy
|
||||||
has_many :deductedPoints, through: :wrestlers
|
has_many :deductedPoints, through: :wrestlers
|
||||||
|
has_many :delegates, class_name: "SchoolDelegate"
|
||||||
|
|
||||||
validates :name, presence: true
|
validates :name, presence: true
|
||||||
|
|
||||||
|
|||||||
2
app/models/school_delegate.rb
Normal file
2
app/models/school_delegate.rb
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
class SchoolDelegate < ActiveRecord::Base
|
||||||
|
end
|
||||||
@@ -8,6 +8,7 @@ class Tournament < ActiveRecord::Base
|
|||||||
has_many :mats, dependent: :destroy
|
has_many :mats, dependent: :destroy
|
||||||
has_many :wrestlers, through: :weights
|
has_many :wrestlers, through: :weights
|
||||||
has_many :matches, dependent: :destroy
|
has_many :matches, dependent: :destroy
|
||||||
|
has_many :delegates, class_name: "TournamentDelegate"
|
||||||
|
|
||||||
validates :date, :name, :tournament_type, :address, :director, :director_email , presence: true
|
validates :date, :name, :tournament_type, :address, :director, :director_email , presence: true
|
||||||
|
|
||||||
|
|||||||
4
app/models/tournament_delegate.rb
Normal file
4
app/models/tournament_delegate.rb
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
class TournamentDelegate < ActiveRecord::Base
|
||||||
|
# belongs_to :tournament
|
||||||
|
# has_one :user
|
||||||
|
end
|
||||||
@@ -2,7 +2,10 @@ class User < ActiveRecord::Base
|
|||||||
# Include default devise modules. Others available are:
|
# Include default devise modules. Others available are:
|
||||||
# :confirmable, :lockable, :timeoutable and :omniauthable
|
# :confirmable, :lockable, :timeoutable and :omniauthable
|
||||||
has_many :tournaments
|
has_many :tournaments
|
||||||
|
has_many :delegated_tournaments, class_name: "TournamentDelegate"
|
||||||
|
has_many :delegated_schools, class_name: "SchoolDelegate"
|
||||||
|
|
||||||
devise :database_authenticatable, :registerable,
|
devise :database_authenticatable, :registerable,
|
||||||
:recoverable, :rememberable, :trackable, :validatable
|
:recoverable, :rememberable, :trackable, :validatable
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
<%= link_to "Go to Schools", '/schools/' %>
|
|
||||||
<br>
|
|
||||||
<%= link_to "Go to Weights", '/weights/' %>
|
|
||||||
<br>
|
|
||||||
<%= link_to "Go to Wrestlers", '/wrestlers/' %>
|
|
||||||
<br>
|
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
<li><%= link_to "Team Scores" , "/tournaments/#{@tournament.id}/team_scores" %></li>
|
<li><%= link_to "Team Scores" , "/tournaments/#{@tournament.id}/team_scores" %></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<% if tournament_permissions(@tournament) %>
|
<% if can? :manage, @tournament %>
|
||||||
<br><br>
|
<br><br>
|
||||||
<div class="" style="padding-right: 1%;">
|
<div class="" style="padding-right: 1%;">
|
||||||
<h4>Tournament Director Links</h4>
|
<h4>Tournament Director Links</h4>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
<p id="notice"><%= notice %></p>
|
<p id="notice"><%= notice %></p>
|
||||||
<%= link_to "Back to #{@tournament.name}", "/tournaments/#{@tournament.id}",:class=>"btn btn-default" %>
|
<%= link_to "Back to #{@tournament.name}", "/tournaments/#{@tournament.id}",:class=>"btn btn-default" %>
|
||||||
<% if tournament_permissions(@school.tournament) %>
|
<% if can? :manage, @tournament %>
|
||||||
| <%= link_to "Edit #{@school.name}", edit_school_path(@school),:class=>"btn btn-primary" %>
|
| <%= link_to "Edit #{@school.name}", edit_school_path(@school),:class=>"btn btn-primary" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
<p>
|
<p>
|
||||||
<strong>Tournament:</strong>
|
<strong>Tournament:</strong>
|
||||||
<%= Tournament.find(@school.tournament_id).name %>
|
<%= @school.tournament.name %>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|
||||||
@@ -27,13 +27,13 @@
|
|||||||
|
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
<% if tournament_permissions(@school.tournament) %>
|
<% if can? :manage, @tournament %>
|
||||||
<%= link_to "New #{@school.name} Wrestler" , "/wrestlers/new?school=#{@school.id}", :class=>"btn btn-success"%>
|
<%= link_to "New #{@school.name} Wrestler" , "/wrestlers/new?school=#{@school.id}", :class=>"btn btn-success"%>
|
||||||
<% end %>
|
<% end %>
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
<% cache ["schools", @school] do %>
|
<% cache ["schools", @school] do %>
|
||||||
<table class="table table-striped table-bordered">
|
<table class="table table-striped table-bordered table-condensed">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
@@ -53,7 +53,7 @@
|
|||||||
<% if wrestler.school_id == @school.id %>
|
<% if wrestler.school_id == @school.id %>
|
||||||
<tr>
|
<tr>
|
||||||
<td><%= wrestler.name %></td>
|
<td><%= wrestler.name %></td>
|
||||||
<td><%= Weight.find(wrestler.weight_id).max %></td>
|
<td><%= wrestler.weight.max %></td>
|
||||||
<td>
|
<td>
|
||||||
<%= wrestler.original_seed %>
|
<%= wrestler.original_seed %>
|
||||||
</td>
|
</td>
|
||||||
@@ -65,10 +65,10 @@
|
|||||||
<% end %></td>
|
<% end %></td>
|
||||||
<td><%= wrestler.nextMatchBoutNumber %> <%= wrestler.nextMatchMatName %></td>
|
<td><%= wrestler.nextMatchBoutNumber %> <%= wrestler.nextMatchMatName %></td>
|
||||||
<td>
|
<td>
|
||||||
<%= link_to 'Show', wrestler , :class=>"btn btn-default" %>
|
<%= link_to 'Show', wrestler , :class=>"btn btn-default btn-sm" %>
|
||||||
<% if tournament_permissions(@school.tournament) %>
|
<% if can? :manage, @tournament %>
|
||||||
<%= link_to 'Edit', edit_wrestler_path(wrestler),:class=>"btn btn-primary" %>
|
<%= link_to 'Edit', edit_wrestler_path(wrestler),:class=>"btn btn-primary btn-sm" %>
|
||||||
<%= link_to 'Destroy', wrestler, method: :delete, data: { confirm: 'Are you sure?' }, :class=>"btn btn-danger" %>
|
<%= link_to 'Destroy', wrestler, method: :delete, data: { confirm: 'Are you sure?' }, :class=>"btn btn-danger btn-sm" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
</br>
|
</br>
|
||||||
</br>
|
</br>
|
||||||
<table class="table table-striped table-bordered" id="tournamentList">
|
<table class="table table-striped table-bordered table-condensed" id="tournamentList">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
@@ -24,10 +24,10 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td><%= tournament.name %></td>
|
<td><%= tournament.name %></td>
|
||||||
<td><%= tournament.date %></td>
|
<td><%= tournament.date %></td>
|
||||||
<td><%= link_to 'Show', tournament, :class=>"btn btn-default" %>
|
<td><%= link_to 'Show', tournament, :class=>"btn btn-default btn-sm" %>
|
||||||
<% if tournament_permissions(tournament) %>
|
<% if can? :manage, tournament %>
|
||||||
<%= link_to 'Edit', edit_tournament_path(tournament), :class=>"btn btn-primary" %>
|
<%= link_to 'Edit', edit_tournament_path(tournament), :class=>"btn btn-primary btn-sm" %>
|
||||||
<%= link_to 'Destroy', tournament, method: :delete, data: { confirm: 'Are you sure?' }, :class=>"btn btn-danger" %>
|
<%= link_to 'Destroy', tournament, method: :delete, data: { confirm: 'Are you sure?' }, :class=>"btn btn-danger btn-sm" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<% @pool = 1 %>
|
<% @pool = 1 %>
|
||||||
<% until @wrestlers.select{|w| w.generatePoolNumber == @pool}.blank? %>
|
<% until @wrestlers.select{|w| w.generatePoolNumber == @pool}.blank? %>
|
||||||
<h5>Pool <%= @pool %></h5>
|
<h5>Pool <%= @pool %></h5>
|
||||||
<table class="table table-striped table-bordered">
|
<table class="table table-striped table-bordered table-condensed">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
|
|||||||
@@ -5,6 +5,6 @@
|
|||||||
<%= link_to "#{weight.max}" , "/tournaments/#{@tournament.id}/brackets/#{weight.id}" %>
|
<%= link_to "#{weight.max}" , "/tournaments/#{@tournament.id}/brackets/#{weight.id}" %>
|
||||||
<br>
|
<br>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if tournament_permissions(@tournament) %>
|
<% if can? :manage, @tournament %>
|
||||||
<%= link_to "All Brackets (Printable)", "/tournaments/#{@tournament.id}/all_brackets?print=true" %>
|
<%= link_to "All Brackets (Printable)", "/tournaments/#{@tournament.id}/all_brackets?print=true" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
</br>
|
</br>
|
||||||
</br>
|
</br>
|
||||||
<table class="table table-striped table-bordered" id="tournamentList">
|
<table class="table table-striped table-bordered table-condensed" id="tournamentList">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
@@ -28,10 +28,10 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td><%= tournament.name %></td>
|
<td><%= tournament.name %></td>
|
||||||
<td><%= tournament.date %></td>
|
<td><%= tournament.date %></td>
|
||||||
<td><%= link_to 'Show', tournament, :class=>"btn btn-default" %>
|
<td><%= link_to 'Show', tournament, :class=>"btn btn-default btn-sm" %>
|
||||||
<% if tournament_permissions(tournament) %>
|
<% if can? :manage, tournament %>
|
||||||
<%= link_to 'Edit', edit_tournament_path(tournament), :class=>"btn btn-primary" %>
|
<%= link_to 'Edit', edit_tournament_path(tournament), :class=>"btn btn-primary btn-sm" %>
|
||||||
<%= link_to 'Destroy', tournament, method: :delete, data: { confirm: 'Are you sure?' }, :class=>"btn btn-danger" %>
|
<%= link_to 'Destroy', tournament, method: :delete, data: { confirm: 'Are you sure?' }, :class=>"btn btn-danger btn-sm" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
</script>
|
</script>
|
||||||
</br>
|
</br>
|
||||||
</br>
|
</br>
|
||||||
<table class="table table-striped table-bordered" id="matchesList">
|
<table class="table table-striped table-bordered table-condensed" id="matchesList">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Bout number</th>
|
<th>Bout number</th>
|
||||||
@@ -28,8 +28,8 @@
|
|||||||
<td><%= match.bout_number %></td>
|
<td><%= match.bout_number %></td>
|
||||||
<td><%= match.w1_name %> vs <%= match.w2_name %></td>
|
<td><%= match.w1_name %> vs <%= match.w2_name %></td>
|
||||||
<td><%= match.finished %></td>
|
<td><%= match.finished %></td>
|
||||||
<td><%= link_to 'Show', match, :class=>"btn btn-default" %>
|
<td><%= link_to 'Show', match, :class=>"btn btn-default btn-sm" %>
|
||||||
<%= link_to 'Edit', edit_match_path(match), :class=>"btn btn-primary" %>
|
<%= link_to 'Edit', edit_match_path(match), :class=>"btn btn-primary btn-sm" %>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<p id="notice"><%= notice %></p>
|
<p id="notice"><%= notice %></p>
|
||||||
<%= link_to 'Back to browse tournaments', '/tournaments', :class=>"btn btn-default" %>
|
<%= link_to 'Back to browse tournaments', '/tournaments', :class=>"btn btn-default" %>
|
||||||
<% if tournament_permissions(@tournament) %>
|
<% if can? :manage, @tournament %>
|
||||||
| <%= link_to "Edit #{@tournament.name}", edit_tournament_path(@tournament), :class=>"btn btn-primary" %>
|
| <%= link_to "Edit #{@tournament.name}", edit_tournament_path(@tournament), :class=>"btn btn-primary" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
@@ -34,12 +34,12 @@
|
|||||||
<br>
|
<br>
|
||||||
<h3>School Lineups</h3>
|
<h3>School Lineups</h3>
|
||||||
<br>
|
<br>
|
||||||
<% if tournament_permissions(@tournament) %>
|
<% if can? :manage, @tournament %>
|
||||||
<%= link_to "New #{@tournament.name} School" , "/schools/new?tournament=#{@tournament.id}", :class=>"btn btn-success" %>
|
<%= link_to "New #{@tournament.name} School" , "/schools/new?tournament=#{@tournament.id}", :class=>"btn btn-success btn-sm" %>
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
<% end %>
|
<% end %>
|
||||||
<table class="table table-striped table-bordered">
|
<table class="table table-striped table-bordered table-condensed">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
@@ -52,10 +52,10 @@
|
|||||||
<% @schools.each do |school| %>
|
<% @schools.each do |school| %>
|
||||||
<tr>
|
<tr>
|
||||||
<td><%= school.name %></td>
|
<td><%= school.name %></td>
|
||||||
<td><%= link_to 'Show', school, :class=>"btn btn-default" %>
|
<td><%= link_to 'Show', school, :class=>"btn btn-default btn-sm" %>
|
||||||
<% if tournament_permissions(@tournament) %>
|
<% if can? :manage, @tournament %>
|
||||||
<%= link_to 'Edit', edit_school_path(school), :class=>"btn btn-primary" %>
|
<%= link_to 'Edit', edit_school_path(school), :class=>"btn btn-primary btn-sm" %>
|
||||||
<%= link_to 'Destroy', school, method: :delete, data: { confirm: 'Are you sure?' }, :class=>"btn btn-danger" %>
|
<%= link_to 'Destroy', school, method: :delete, data: { confirm: 'Are you sure?' }, :class=>"btn btn-danger btn-sm" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -68,12 +68,12 @@
|
|||||||
|
|
||||||
<h3>Weight Class Seeds</h3>
|
<h3>Weight Class Seeds</h3>
|
||||||
<br>
|
<br>
|
||||||
<% if tournament_permissions(@tournament) %>
|
<% if can? :manage, @tournament %>
|
||||||
<%= link_to "New #{@tournament.name} Weight" , "/weights/new?tournament=#{@tournament.id}", :class=>"btn btn-success" %>
|
<%= link_to "New #{@tournament.name} Weight" , "/weights/new?tournament=#{@tournament.id}", :class=>"btn btn-success btn-sm" %>
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
<% end %>
|
<% end %>
|
||||||
<table class="table table-striped table-bordered">
|
<table class="table table-striped table-bordered table-condensed">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Weight Class</th>
|
<th>Weight Class</th>
|
||||||
@@ -87,10 +87,10 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td><%= weight.max %></td>
|
<td><%= weight.max %></td>
|
||||||
<td><%= weight.bracket_size %></td>
|
<td><%= weight.bracket_size %></td>
|
||||||
<td><%= link_to 'Show', weight, :class=>"btn btn-default" %>
|
<td><%= link_to 'Show', weight, :class=>"btn btn-default btn-sm" %>
|
||||||
<% if tournament_permissions(@tournament) %>
|
<% if can? :manage, @tournament %>
|
||||||
<%= link_to 'Edit', edit_weight_path(weight), :class=>"btn btn-primary" %>
|
<%= link_to 'Edit', edit_weight_path(weight), :class=>"btn btn-primary btn-sm" %>
|
||||||
<%= link_to 'Destroy', weight, method: :delete, data: { confirm: 'Are you sure?' }, :class=>"btn btn-danger" %>
|
<%= link_to 'Destroy', weight, method: :delete, data: { confirm: 'Are you sure?' }, :class=>"btn btn-danger btn-sm" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -98,15 +98,15 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<% if tournament_permissions(@tournament) %>
|
<% if can? :manage, @tournament %>
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
<h3>Mats</h3>
|
<h3>Mats</h3>
|
||||||
<br>
|
<br>
|
||||||
<%= link_to "New #{@tournament.name} Mat" , "/mats/new?tournament=#{@tournament.id}", :class=>"btn btn-success" %>
|
<%= link_to "New #{@tournament.name} Mat" , "/mats/new?tournament=#{@tournament.id}", :class=>"btn btn-success btn-sm" %>
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
<table class="table table-striped table-bordered">
|
<table class="table table-striped table-bordered table-condensed">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
@@ -119,9 +119,9 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td><%= mat.name %></td>
|
<td><%= mat.name %></td>
|
||||||
<td>
|
<td>
|
||||||
<% if tournament_permissions(@tournament) %>
|
<% if can? :manage, @tournament %>
|
||||||
<%= link_to 'Show', mat, :class=>"btn btn-default" %>
|
<%= link_to 'Show', mat, :class=>"btn btn-default btn-sm" %>
|
||||||
<%= link_to 'Destroy', mat, method: :delete, data: { confirm: 'Are you sure?' }, :class=>"btn btn-danger" %>
|
<%= link_to 'Destroy', mat, method: :delete, data: { confirm: 'Are you sure?' }, :class=>"btn btn-danger btn-sm" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<br>
|
<br>
|
||||||
<% end %>
|
<% end %>
|
||||||
<br>
|
<br>
|
||||||
<% if tournament_permissions(@tournament) %>
|
<% if can? :manage, @tournament %>
|
||||||
<%= form_for(@tournament) do |f| %>
|
<%= form_for(@tournament) do |f| %>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<%= f.label :weigh_in_ref %><br>
|
<%= f.label :weigh_in_ref %><br>
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
<% if wrestler.weight_id == @weight.id %>
|
<% if wrestler.weight_id == @weight.id %>
|
||||||
<tr>
|
<tr>
|
||||||
<td><%= wrestler.name %></td>
|
<td><%= wrestler.name %></td>
|
||||||
<td><%= School.find(wrestler.school_id).name %></td>
|
<td><%= wrestler.school.name %></td>
|
||||||
<td><%= wrestler.original_seed %></td>
|
<td><%= wrestler.original_seed %></td>
|
||||||
<td><%= wrestler.weight.max %></td>
|
<td><%= wrestler.weight.max %></td>
|
||||||
<td>
|
<td>
|
||||||
@@ -37,7 +37,7 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<%= hidden_field_tag :tournament, @tournament_id %>
|
<%= hidden_field_tag :tournament, @tournament_id %>
|
||||||
<% if tournament_permissions(@tournament) %>
|
<% if can? :manage, @tournament %>
|
||||||
<%= submit_tag "Save", :class=>"btn btn-success"%>
|
<%= submit_tag "Save", :class=>"btn btn-success"%>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
|
|
||||||
<%= link_to "Back to #{@tournament.name}", "/tournaments/#{@tournament.id}", :class=>"btn btn-default" %>
|
<%= link_to "Back to #{@tournament.name}", "/tournaments/#{@tournament.id}", :class=>"btn btn-default" %>
|
||||||
<% if tournament_permissions(@tournament) %>
|
<% if can? :manage, @tournament %>
|
||||||
| <%= link_to "Edit #{@weight.max} Weight Class", edit_weight_path(@weight), :class=>"btn btn-primary" %>
|
| <%= link_to "Edit #{@weight.max} Weight Class", edit_weight_path(@weight), :class=>"btn btn-primary" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
<h1>Weight Class:<%= @weight.max %></h1>
|
<h1>Weight Class:<%= @weight.max %></h1>
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
<table class="table table-striped table-bordered">
|
<table class="table table-striped table-bordered table-condensed">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
<th>Record</th>
|
<th>Record</th>
|
||||||
<th>Seed Criteria</th>
|
<th>Seed Criteria</th>
|
||||||
<th>Extra?</th>
|
<th>Extra?</th>
|
||||||
<% if tournament_permissions(@tournament) %><th>Actions for wrestler</th><% end %>
|
<% if can? :manage, @tournament %> %><th>Actions for wrestler</th><% end %>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@@ -29,9 +29,9 @@
|
|||||||
<% if wrestler.weight_id == @weight.id %>
|
<% if wrestler.weight_id == @weight.id %>
|
||||||
<tr>
|
<tr>
|
||||||
<td><%= wrestler.name %></td>
|
<td><%= wrestler.name %></td>
|
||||||
<td><%= School.find(wrestler.school_id).name %></td>
|
<td><%= wrestler.school.name %></td>
|
||||||
<td>
|
<td>
|
||||||
<% if tournament_permissions(@tournament) %>
|
<% if can? :manage, @tournament %>
|
||||||
<%= fields_for "wrestler[]", wrestler do |w| %>
|
<%= fields_for "wrestler[]", wrestler do |w| %>
|
||||||
<%= w.text_field :original_seed %>
|
<%= w.text_field :original_seed %>
|
||||||
<% end %>
|
<% end %>
|
||||||
@@ -44,9 +44,9 @@
|
|||||||
<td><% if wrestler.extra? == true %>
|
<td><% if wrestler.extra? == true %>
|
||||||
Yes
|
Yes
|
||||||
<% end %></td>
|
<% end %></td>
|
||||||
<% if tournament_permissions(@tournament) %>
|
<% if can? :manage, @tournament %>
|
||||||
<td><%= link_to 'Show', wrestler , :class=>"btn btn-default" %>
|
<td><%= link_to 'Show', wrestler , :class=>"btn btn-default btn-sm" %>
|
||||||
<%= link_to 'Destroy', wrestler, method: :delete, data: { confirm: 'Are you sure?' } , :class=>"btn btn-danger" %></td>
|
<%= link_to 'Destroy', wrestler, method: :delete, data: { confirm: 'Are you sure?' } , :class=>"btn btn-danger btn-sm" %></td>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
@@ -54,7 +54,7 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<br><p>*All wrestlers without a seed (determined by tournament director) will be assigned a random seed.</p>
|
<br><p>*All wrestlers without a seed (determined by tournament director) will be assigned a random seed.</p>
|
||||||
<% if tournament_permissions(@tournament) %>
|
<% if can? :manage, @tournament %>
|
||||||
<br>
|
<br>
|
||||||
<%= submit_tag "Save", :class=>"btn btn-success"%>
|
<%= submit_tag "Save", :class=>"btn btn-success"%>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -30,10 +30,6 @@
|
|||||||
<%= f.collection_select :weight_id, @weights, :id, :max %>
|
<%= f.collection_select :weight_id, @weights, :id, :max %>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class="field">
|
|
||||||
<%= f.label :original_seed %><br>
|
|
||||||
<%= f.number_field :original_seed %>
|
|
||||||
</div>
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<%= f.label "Season Wins" %><br>
|
<%= f.label "Season Wins" %><br>
|
||||||
<%= f.number_field :season_win %>
|
<%= f.number_field :season_win %>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<p id="notice"><%= notice %></p>
|
<p id="notice"><%= notice %></p>
|
||||||
|
|
||||||
<%= link_to "Back to #{@school.name}", "/schools/#{@school.id}", :class=>"btn btn-default" %>
|
<%= link_to "Back to #{@school.name}", "/schools/#{@school.id}", :class=>"btn btn-default" %>
|
||||||
<% if tournament_permissions(@wrestler.tournament) %>
|
<% if can? :manage, @tournament %>
|
||||||
| <%= link_to "Edit #{@wrestler.name}", edit_wrestler_path(@wrestler), :class=>"btn btn-primary" %>
|
| <%= link_to "Edit #{@wrestler.name}", edit_wrestler_path(@wrestler), :class=>"btn btn-primary" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% cache ["wrestlers", @wrestler] do %>
|
<% cache ["wrestlers", @wrestler] do %>
|
||||||
|
|||||||
10
db/migrate/20160106025920_create_tournament_delegates.rb
Normal file
10
db/migrate/20160106025920_create_tournament_delegates.rb
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
class CreateTournamentDelegates < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table :tournament_delegates do |t|
|
||||||
|
t.integer :user_id
|
||||||
|
t.integer :tournament_id
|
||||||
|
|
||||||
|
t.timestamps null: false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
10
db/migrate/20160106031418_create_school_delegates.rb
Normal file
10
db/migrate/20160106031418_create_school_delegates.rb
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
class CreateSchoolDelegates < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table :school_delegates do |t|
|
||||||
|
t.integer :user_id
|
||||||
|
t.integer :school_id
|
||||||
|
|
||||||
|
t.timestamps null: false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
16
db/schema.rb
16
db/schema.rb
@@ -11,7 +11,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20151230164000) do
|
ActiveRecord::Schema.define(version: 20160106031418) do
|
||||||
|
|
||||||
create_table "delayed_jobs", force: :cascade do |t|
|
create_table "delayed_jobs", force: :cascade do |t|
|
||||||
t.integer "priority", default: 0, null: false
|
t.integer "priority", default: 0, null: false
|
||||||
@@ -64,6 +64,13 @@ ActiveRecord::Schema.define(version: 20151230164000) do
|
|||||||
|
|
||||||
add_index "mats", ["tournament_id"], name: "index_mats_on_tournament_id"
|
add_index "mats", ["tournament_id"], name: "index_mats_on_tournament_id"
|
||||||
|
|
||||||
|
create_table "school_delegates", force: :cascade do |t|
|
||||||
|
t.integer "user_id"
|
||||||
|
t.integer "school_id"
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
end
|
||||||
|
|
||||||
create_table "schools", force: :cascade do |t|
|
create_table "schools", force: :cascade do |t|
|
||||||
t.string "name"
|
t.string "name"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
@@ -83,6 +90,13 @@ ActiveRecord::Schema.define(version: 20151230164000) do
|
|||||||
|
|
||||||
add_index "teampointadjusts", ["wrestler_id"], name: "index_teampointadjusts_on_wrestler_id"
|
add_index "teampointadjusts", ["wrestler_id"], name: "index_teampointadjusts_on_wrestler_id"
|
||||||
|
|
||||||
|
create_table "tournament_delegates", force: :cascade do |t|
|
||||||
|
t.integer "user_id"
|
||||||
|
t.integer "tournament_id"
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
end
|
||||||
|
|
||||||
create_table "tournaments", force: :cascade do |t|
|
create_table "tournaments", force: :cascade do |t|
|
||||||
t.string "name"
|
t.string "name"
|
||||||
t.string "address"
|
t.string "address"
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
require 'test_helper'
|
|
||||||
|
|
||||||
class AdminControllerTest < ActionController::TestCase
|
|
||||||
test "the truth" do
|
|
||||||
assert true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -25,6 +25,10 @@ class MatchesControllerTest < ActionController::TestCase
|
|||||||
sign_in users(:two)
|
sign_in users(:two)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def sign_in_tournament_delegate
|
||||||
|
sign_in users(:three)
|
||||||
|
end
|
||||||
|
|
||||||
def success
|
def success
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
@@ -65,11 +69,16 @@ class MatchesControllerTest < ActionController::TestCase
|
|||||||
assert_redirected_to '/static_pages/not_allowed'
|
assert_redirected_to '/static_pages/not_allowed'
|
||||||
end
|
end
|
||||||
|
|
||||||
test "logged in tournament owner should post update match" do
|
test "logged in tournament delegate should get edit match page" do
|
||||||
sign_in_owner
|
sign_in_tournament_delegate
|
||||||
|
get_edit
|
||||||
|
success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "logged in tournament delegate should post update match" do
|
||||||
|
sign_in_tournament_delegate
|
||||||
post_update
|
post_update
|
||||||
assert_redirected_to mat_path(1)
|
assert_redirected_to mat_path(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -41,6 +41,10 @@ class MatsControllerTest < ActionController::TestCase
|
|||||||
sign_in users(:two)
|
sign_in users(:two)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def sign_in_tournament_delegate
|
||||||
|
sign_in users(:three)
|
||||||
|
end
|
||||||
|
|
||||||
def success
|
def success
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
@@ -63,6 +67,12 @@ class MatsControllerTest < ActionController::TestCase
|
|||||||
success
|
success
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "logged in tournament delegate should get edit mat page" do
|
||||||
|
sign_in_tournament_delegate
|
||||||
|
get_edit
|
||||||
|
success
|
||||||
|
end
|
||||||
|
|
||||||
test "logged in user should not get edit mat page if not owner" do
|
test "logged in user should not get edit mat page if not owner" do
|
||||||
sign_in_non_owner
|
sign_in_non_owner
|
||||||
get_edit
|
get_edit
|
||||||
@@ -91,6 +101,12 @@ class MatsControllerTest < ActionController::TestCase
|
|||||||
assert_redirected_to tournament_path(@mat.tournament_id)
|
assert_redirected_to tournament_path(@mat.tournament_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "logged in tournament delegate should post update mat" do
|
||||||
|
sign_in_tournament_delegate
|
||||||
|
post_update
|
||||||
|
assert_redirected_to tournament_path(@mat.tournament_id)
|
||||||
|
end
|
||||||
|
|
||||||
test "logged in tournament owner can create a new mat" do
|
test "logged in tournament owner can create a new mat" do
|
||||||
sign_in_owner
|
sign_in_owner
|
||||||
new
|
new
|
||||||
@@ -99,6 +115,14 @@ class MatsControllerTest < ActionController::TestCase
|
|||||||
assert_redirected_to tournament_path(@mat.tournament_id)
|
assert_redirected_to tournament_path(@mat.tournament_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "logged in tournament delegate can create a new mat" do
|
||||||
|
sign_in_tournament_delegate
|
||||||
|
new
|
||||||
|
success
|
||||||
|
create
|
||||||
|
assert_redirected_to tournament_path(@mat.tournament_id)
|
||||||
|
end
|
||||||
|
|
||||||
test "logged in user not tournament owner cannot create a mat" do
|
test "logged in user not tournament owner cannot create a mat" do
|
||||||
sign_in_non_owner
|
sign_in_non_owner
|
||||||
new
|
new
|
||||||
@@ -113,6 +137,12 @@ class MatsControllerTest < ActionController::TestCase
|
|||||||
assert_redirected_to tournament_path(@tournament.id)
|
assert_redirected_to tournament_path(@tournament.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "logged in tournament delegate can destroy a mat" do
|
||||||
|
sign_in_tournament_delegate
|
||||||
|
destroy
|
||||||
|
assert_redirected_to tournament_path(@tournament.id)
|
||||||
|
end
|
||||||
|
|
||||||
test "logged in user not tournament owner cannot destroy mat" do
|
test "logged in user not tournament owner cannot destroy mat" do
|
||||||
sign_in_non_owner
|
sign_in_non_owner
|
||||||
destroy
|
destroy
|
||||||
@@ -131,6 +161,12 @@ class MatsControllerTest < ActionController::TestCase
|
|||||||
success
|
success
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "logged in tournament delegate should get show mat" do
|
||||||
|
sign_in_tournament_delegate
|
||||||
|
show
|
||||||
|
success
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
#TESTS THAT NEED MATCHES PUT ABOVE THIS
|
#TESTS THAT NEED MATCHES PUT ABOVE THIS
|
||||||
test "redirect show if no matches" do
|
test "redirect show if no matches" do
|
||||||
|
|||||||
@@ -37,6 +37,10 @@ class SchoolsControllerTest < ActionController::TestCase
|
|||||||
sign_in users(:two)
|
sign_in users(:two)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def sign_in_tournament_delegate
|
||||||
|
sign_in users(:three)
|
||||||
|
end
|
||||||
|
|
||||||
def success
|
def success
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
@@ -51,6 +55,12 @@ class SchoolsControllerTest < ActionController::TestCase
|
|||||||
success
|
success
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "logged in tournament delegate should get edit school page" do
|
||||||
|
sign_in_tournament_delegate
|
||||||
|
get_edit
|
||||||
|
success
|
||||||
|
end
|
||||||
|
|
||||||
test "logged in user should not get edit school page if not owner" do
|
test "logged in user should not get edit school page if not owner" do
|
||||||
sign_in_non_owner
|
sign_in_non_owner
|
||||||
get_edit
|
get_edit
|
||||||
@@ -79,6 +89,12 @@ class SchoolsControllerTest < ActionController::TestCase
|
|||||||
assert_redirected_to tournament_path(@school.tournament_id)
|
assert_redirected_to tournament_path(@school.tournament_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "logged in tournament delegate should post update school" do
|
||||||
|
sign_in_tournament_delegate
|
||||||
|
post_update
|
||||||
|
assert_redirected_to tournament_path(@school.tournament_id)
|
||||||
|
end
|
||||||
|
|
||||||
test "logged in tournament owner can create a new school" do
|
test "logged in tournament owner can create a new school" do
|
||||||
sign_in_owner
|
sign_in_owner
|
||||||
new
|
new
|
||||||
@@ -87,6 +103,14 @@ class SchoolsControllerTest < ActionController::TestCase
|
|||||||
assert_redirected_to tournament_path(@school.tournament_id)
|
assert_redirected_to tournament_path(@school.tournament_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "logged in tournament delegate can create a new school" do
|
||||||
|
sign_in_tournament_delegate
|
||||||
|
new
|
||||||
|
success
|
||||||
|
create
|
||||||
|
assert_redirected_to tournament_path(@school.tournament_id)
|
||||||
|
end
|
||||||
|
|
||||||
test "logged in user not tournament owner cannot create a school" do
|
test "logged in user not tournament owner cannot create a school" do
|
||||||
sign_in_non_owner
|
sign_in_non_owner
|
||||||
new
|
new
|
||||||
@@ -101,6 +125,12 @@ class SchoolsControllerTest < ActionController::TestCase
|
|||||||
assert_redirected_to tournament_path(@tournament.id)
|
assert_redirected_to tournament_path(@tournament.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "logged in tournament delegate can destroy a school" do
|
||||||
|
sign_in_tournament_delegate
|
||||||
|
destroy
|
||||||
|
assert_redirected_to tournament_path(@tournament.id)
|
||||||
|
end
|
||||||
|
|
||||||
test "logged in user not tournament owner cannot destroy school" do
|
test "logged in user not tournament owner cannot destroy school" do
|
||||||
sign_in_non_owner
|
sign_in_non_owner
|
||||||
destroy
|
destroy
|
||||||
|
|||||||
@@ -26,6 +26,10 @@ include Devise::TestHelpers
|
|||||||
sign_in users(:two)
|
sign_in users(:two)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def sign_in_delegate
|
||||||
|
sign_in users(:three)
|
||||||
|
end
|
||||||
|
|
||||||
def success
|
def success
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
@@ -170,4 +174,52 @@ include Devise::TestHelpers
|
|||||||
no_matches
|
no_matches
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "logged in tournament delegate can generate matches" do
|
||||||
|
sign_in_delegate
|
||||||
|
get :generate_matches, id: 1
|
||||||
|
success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "logged in tournament delegate can create custom weights" do
|
||||||
|
sign_in_delegate
|
||||||
|
get :create_custom_weights, id: 1, customValue: 'hs'
|
||||||
|
assert_redirected_to '/tournaments/1'
|
||||||
|
end
|
||||||
|
|
||||||
|
test "logged in tournament delegate can access weigh_ins" do
|
||||||
|
sign_in_delegate
|
||||||
|
get :weigh_in, id: 1
|
||||||
|
success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "logged in tournament delegate can access weigh_in_weight" do
|
||||||
|
sign_in_delegate
|
||||||
|
get :weigh_in, id: 1, weight: 1
|
||||||
|
success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "logged in tournament delegate should get edit tournament page" do
|
||||||
|
sign_in_delegate
|
||||||
|
get_edit
|
||||||
|
success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "logged in tournament delegate can access post weigh_in_weight" do
|
||||||
|
sign_in_delegate
|
||||||
|
post :weigh_in, id: 1, weight: 1, wrestler: @wrestlers
|
||||||
|
end
|
||||||
|
|
||||||
|
test "logged in tournament delegate should post update tournament" do
|
||||||
|
sign_in_delegate
|
||||||
|
post_update
|
||||||
|
assert_redirected_to tournament_path(1)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
test "logged in tournament delegate cannot destroy a tournament" do
|
||||||
|
sign_in_delegate
|
||||||
|
destroy
|
||||||
|
redirect
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -37,6 +37,10 @@ class WeightsControllerTest < ActionController::TestCase
|
|||||||
sign_in users(:two)
|
sign_in users(:two)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def sign_in_tournament_delegate
|
||||||
|
sign_in users(:three)
|
||||||
|
end
|
||||||
|
|
||||||
def success
|
def success
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
@@ -51,6 +55,12 @@ class WeightsControllerTest < ActionController::TestCase
|
|||||||
success
|
success
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "logged in tournament delegate should get edit weight page" do
|
||||||
|
sign_in_tournament_delegate
|
||||||
|
get_edit
|
||||||
|
success
|
||||||
|
end
|
||||||
|
|
||||||
test "logged in user should not get edit weight page if not owner" do
|
test "logged in user should not get edit weight page if not owner" do
|
||||||
sign_in_non_owner
|
sign_in_non_owner
|
||||||
get_edit
|
get_edit
|
||||||
@@ -79,6 +89,12 @@ class WeightsControllerTest < ActionController::TestCase
|
|||||||
assert_redirected_to tournament_path(@weight.tournament_id)
|
assert_redirected_to tournament_path(@weight.tournament_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "logged in tournament delegate should post update weight" do
|
||||||
|
sign_in_tournament_delegate
|
||||||
|
post_update
|
||||||
|
assert_redirected_to tournament_path(@weight.tournament_id)
|
||||||
|
end
|
||||||
|
|
||||||
test "logged in tournament owner can create a new weight" do
|
test "logged in tournament owner can create a new weight" do
|
||||||
sign_in_owner
|
sign_in_owner
|
||||||
new
|
new
|
||||||
@@ -87,6 +103,14 @@ class WeightsControllerTest < ActionController::TestCase
|
|||||||
assert_redirected_to tournament_path(@weight.tournament_id)
|
assert_redirected_to tournament_path(@weight.tournament_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "logged in tournament delegate can create a new weight" do
|
||||||
|
sign_in_tournament_delegate
|
||||||
|
new
|
||||||
|
success
|
||||||
|
create
|
||||||
|
assert_redirected_to tournament_path(@weight.tournament_id)
|
||||||
|
end
|
||||||
|
|
||||||
test "logged in user not tournament owner cannot create a weight" do
|
test "logged in user not tournament owner cannot create a weight" do
|
||||||
sign_in_non_owner
|
sign_in_non_owner
|
||||||
new
|
new
|
||||||
@@ -101,6 +125,12 @@ class WeightsControllerTest < ActionController::TestCase
|
|||||||
assert_redirected_to tournament_path(@tournament.id)
|
assert_redirected_to tournament_path(@tournament.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "logged in tournament delegate can destroy a weight" do
|
||||||
|
sign_in_tournament_delegate
|
||||||
|
destroy
|
||||||
|
assert_redirected_to tournament_path(@tournament.id)
|
||||||
|
end
|
||||||
|
|
||||||
test "logged in user not tournament owner cannot destroy weight" do
|
test "logged in user not tournament owner cannot destroy weight" do
|
||||||
sign_in_non_owner
|
sign_in_non_owner
|
||||||
destroy
|
destroy
|
||||||
|
|||||||
@@ -38,6 +38,10 @@ class WrestlersControllerTest < ActionController::TestCase
|
|||||||
sign_in users(:two)
|
sign_in users(:two)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def sign_in_tournament_delegate
|
||||||
|
sign_in users(:three)
|
||||||
|
end
|
||||||
|
|
||||||
def success
|
def success
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
@@ -52,6 +56,12 @@ class WrestlersControllerTest < ActionController::TestCase
|
|||||||
success
|
success
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "logged in tournament delegate should get edit wrestler page" do
|
||||||
|
sign_in_tournament_delegate
|
||||||
|
get_edit
|
||||||
|
success
|
||||||
|
end
|
||||||
|
|
||||||
test "logged in user should not get edit wrestler page if not owner" do
|
test "logged in user should not get edit wrestler page if not owner" do
|
||||||
sign_in_non_owner
|
sign_in_non_owner
|
||||||
get_edit
|
get_edit
|
||||||
@@ -80,6 +90,12 @@ class WrestlersControllerTest < ActionController::TestCase
|
|||||||
assert_redirected_to school_path(@school.id)
|
assert_redirected_to school_path(@school.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "logged in tournament delegate should post update wrestler" do
|
||||||
|
sign_in_tournament_delegate
|
||||||
|
post_update
|
||||||
|
assert_redirected_to school_path(@school.id)
|
||||||
|
end
|
||||||
|
|
||||||
test "logged in tournament owner can create a new wrestler" do
|
test "logged in tournament owner can create a new wrestler" do
|
||||||
sign_in_owner
|
sign_in_owner
|
||||||
new
|
new
|
||||||
@@ -88,6 +104,14 @@ class WrestlersControllerTest < ActionController::TestCase
|
|||||||
assert_redirected_to school_path(@school.id)
|
assert_redirected_to school_path(@school.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "logged in tournament delegate can create a new wrestler" do
|
||||||
|
sign_in_tournament_delegate
|
||||||
|
new
|
||||||
|
success
|
||||||
|
create
|
||||||
|
assert_redirected_to school_path(@school.id)
|
||||||
|
end
|
||||||
|
|
||||||
test "logged in user not tournament owner cannot create a wrestler" do
|
test "logged in user not tournament owner cannot create a wrestler" do
|
||||||
sign_in_non_owner
|
sign_in_non_owner
|
||||||
new
|
new
|
||||||
@@ -102,6 +126,12 @@ class WrestlersControllerTest < ActionController::TestCase
|
|||||||
assert_redirected_to school_path(@school.id)
|
assert_redirected_to school_path(@school.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "logged in tournament delegate can destroy a wrestler" do
|
||||||
|
sign_in_tournament_delegate
|
||||||
|
destroy
|
||||||
|
assert_redirected_to school_path(@school.id)
|
||||||
|
end
|
||||||
|
|
||||||
test "logged in user not tournament owner cannot destroy wrestler" do
|
test "logged in user not tournament owner cannot destroy wrestler" do
|
||||||
sign_in_non_owner
|
sign_in_non_owner
|
||||||
destroy
|
destroy
|
||||||
|
|||||||
9
test/fixtures/school_delegates.yml
vendored
Normal file
9
test/fixtures/school_delegates.yml
vendored
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
||||||
|
# one:
|
||||||
|
# user_id: 1
|
||||||
|
# school_id: 1
|
||||||
|
|
||||||
|
# two:
|
||||||
|
# user_id: 1
|
||||||
|
# school_id: 1
|
||||||
13
test/fixtures/tournament_delegates.yml
vendored
Normal file
13
test/fixtures/tournament_delegates.yml
vendored
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
||||||
|
# one:
|
||||||
|
# user_id: 1
|
||||||
|
# tournament_id: 1
|
||||||
|
|
||||||
|
# two:
|
||||||
|
# user_id: 1
|
||||||
|
# tournament_id: 1
|
||||||
|
|
||||||
|
one:
|
||||||
|
user_id: 3
|
||||||
|
tournament_id: 1
|
||||||
4
test/fixtures/users.yml
vendored
4
test/fixtures/users.yml
vendored
@@ -15,3 +15,7 @@ one:
|
|||||||
two:
|
two:
|
||||||
email: test2@test.com
|
email: test2@test.com
|
||||||
id: 2
|
id: 2
|
||||||
|
|
||||||
|
three:
|
||||||
|
email: test3@test.com
|
||||||
|
id: 3
|
||||||
|
|||||||
7
test/models/school_delegate_test.rb
Normal file
7
test/models/school_delegate_test.rb
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class SchoolDelegateTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
||||||
7
test/models/tournament_delegate_test.rb
Normal file
7
test/models/tournament_delegate_test.rb
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class TournamentDelegateTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user