1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-03-25 01:14:43 +00:00

Merge branch 'development' of https://github.com/jcwimer/wrestlingApp into development

This commit is contained in:
2016-01-12 07:40:39 -05:00
37 changed files with 652 additions and 72 deletions

View File

@@ -1,6 +1,7 @@
class SchoolsController < ApplicationController
before_action :set_school, only: [:show, :edit, :update, :destroy]
before_filter :check_access, only: [:new,:create,:update,:destroy,:edit]
before_filter :check_access_director, only: [:new,:create,:destroy]
before_filter :check_access_delegate, only: [:update,:edit]
# GET /schools/1
@@ -76,15 +77,21 @@ class SchoolsController < ApplicationController
params.require(:school).permit(:name, :score, :tournament_id)
end
def check_access
def check_access_director
if params[:tournament]
@tournament = Tournament.find(params[:tournament])
elsif params[:school]
@tournament = Tournament.find(params[:school]["tournament_id"])
elsif @school
@tournament = @school.tournament
elsif school_params
@tournament = Tournament.find(school_params[:tournament_id])
end
authorize! :manage, @tournament
end
def check_access_delegate
authorize! :manage, @school
end
end

View File

@@ -5,6 +5,7 @@ class StaticPagesController < ApplicationController
tournaments_delegated = current_user.delegated_tournaments
all_tournaments = tournaments_created + tournaments_delegated
@tournaments = all_tournaments.sort_by{|t| t.daysUntil}
@schools = current_user.delegated_schools
end
def not_allowed

View File

@@ -1,10 +1,73 @@
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_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_action :set_tournament, only: [:remove_school_delegate,:remove_delegate,:school_delegate,:delegate,: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_manage, only: [:remove_school_delegate,:school_delegate,:weigh_in,:weigh_in_weight,:create_custom_weights,:update,:edit,:generate_matches,:matches]
before_filter :check_access_destroy, only: [:destroy,:delegate,:remove_delegate]
before_filter :check_for_matches, only: [:up_matches,:bracket,:all_brackets]
def remove_delegate
if params[:delegate]
@delegate = TournamentDelegate.find(params[:delegate])
@delegate.destroy
respond_to do |format|
format.html { redirect_to "/tournaments/#{@tournament.id}/delegate", notice: 'Delegated permissions removed successfully' }
end
end
end
def remove_school_delegate
if params[:delegate]
@delegate = SchoolDelegate.find(params[:delegate])
@delegate.destroy
respond_to do |format|
format.html { redirect_to "/tournaments/#{@tournament.id}/school_delegate", notice: 'Delegated permissions removed successfully' }
end
end
end
def school_delegate
if params[:search]
@users = User.search(params[:search])
elsif params[:school_delegate]
@delegate = SchoolDelegate.new
@delegate.user_id = params[:school_delegate]["user_id"]
@delegate.school_id = params[:school_delegate]["school_id"]
respond_to do |format|
if @delegate.save
format.html { redirect_to "/tournaments/#{@tournament.id}/school_delegate", notice: 'Delegated permissions added successfully' }
else
format.html { redirect_to "/tournaments/#{@tournament.id}/school_delegate", notice: 'There was an issue delegating permissions please try again' }
end
end
else
@users_delegates = []
@tournament.schools.each do |s|
s.delegates.each do |d|
@users_delegates << d
end
end
end
end
def delegate
if params[:search]
@users = User.search(params[:search])
elsif params[:tournament_delegate]
@delegate = TournamentDelegate.new
@delegate.user_id = params[:tournament_delegate]["user_id"]
@delegate.tournament_id = @tournament.id
respond_to do |format|
if @delegate.save
format.html { redirect_to "/tournaments/#{@tournament.id}/delegate", notice: 'Delegated permissions added successfully' }
else
format.html { redirect_to "/tournaments/#{@tournament.id}/delegate", notice: 'There was an issue delegating permissions please try again' }
end
end
else
@users_delegates = @tournament.delegates
end
end
def matches
@matches = @tournament.matches.sort_by{|m| m.bout_number}
if @match

View File

@@ -92,13 +92,16 @@ class WrestlersController < ApplicationController
def check_access
if params[:school]
@school = School.find(params[:school])
@tournament = Tournament.find(@school.tournament.id)
#@tournament = Tournament.find(@school.tournament.id)
elsif params[:wrestler]
@school = School.find(params[:wrestler]["school_id"])
@tournament = Tournament.find(@school.tournament.id)
#@tournament = Tournament.find(@school.tournament.id)
elsif @wrestler
@tournament = @wrestler.tournament
@school = @wrestler.school
#@tournament = @wrestler.tournament
elsif wrestler_params
@school = School.find(wrestler_params[:school_id])
end
authorize! :manage, @tournament
authorize! :manage, @school
end
end

View File

@@ -40,7 +40,7 @@ class Ability
end
#Can manage school if tournament owner
can :manage, School do |school|
school.tournament.map(&:user_id).include? user.id
school.tournament.user_id == user.id
end
#Can manage school if tournament delegate
can :manage, School do |school|

View File

@@ -21,7 +21,7 @@ class Mat < ActiveRecord::Base
end
def assignNextMatch
t_matches = tournament.matches.select{|m| m.mat_id == nil}
t_matches = tournament.matches.select{|m| m.mat_id == nil && m.finished != 1}
if t_matches.size > 0
match = t_matches.sort_by{|m| m.bout_number}.first
match.mat_id = self.id

View File

@@ -52,9 +52,11 @@ class Match < ActiveRecord::Base
if self.w1 && self.w2
@w1 = wrestler1
@w2 = wrestler2
@w1.advanceInBracket
@w2.advanceInBracket
self.mat.assignNextMatch
@w1.advanceInBracket(self)
@w2.advanceInBracket(self)
if self.mat
self.mat.assignNextMatch
end
end
end
if Rails.env.production?

View File

@@ -1,7 +1,8 @@
class PoolAdvance
def initialize(wrestler)
def initialize(wrestler,previousMatch)
@wrestler = wrestler
@previousMatch = previousMatch
end
def advanceWrestler
@@ -29,10 +30,10 @@ class PoolAdvance
end
def bracketAdvancment
if @wrestler.winnerOfLastMatch?
if @previousMatch.winner_id == @wrestler.id
winnerAdvance
end
if !@wrestler.winnerOfLastMatch?
if @previousMatch.winner_id != @wrestler.id
loserAdvance
end
end

View File

@@ -1,2 +1,4 @@
class SchoolDelegate < ActiveRecord::Base
belongs_to :school
belongs_to :user
end

View File

@@ -79,7 +79,7 @@ class Tournament < ActiveRecord::Base
end
def resetMats
matchesToReset = matches.select{|m| m.finished != 1 && m.mat_id != nil}
matchesToReset = matches.select{|m| m.mat_id != nil}
# matchesToReset.update_all( {:mat_id => nil } )
matchesToReset.each do |m|
m.mat_id = nil

View File

@@ -1,4 +1,4 @@
class TournamentDelegate < ActiveRecord::Base
# belongs_to :tournament
# has_one :user
belongs_to :tournament
belongs_to :user
end

View File

@@ -2,10 +2,29 @@ class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
has_many :tournaments
has_many :delegated_tournaments, class_name: "TournamentDelegate"
has_many :delegated_schools, class_name: "SchoolDelegate"
has_many :delegated_tournament_permissions, class_name: "TournamentDelegate"
has_many :delegated_school_permissions, class_name: "SchoolDelegate"
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
def delegated_tournaments
tournaments_delegated = []
delegated_tournament_permissions.each do |t|
tournaments_delegated << t.tournament
end
tournaments_delegated
end
def delegated_schools
schools_delegated = []
delegated_school_permissions.each do |t|
schools_delegated << t.school
end
schools_delegated
end
def self.search(search)
where("email LIKE ?", "%#{search}%")
end
end

View File

@@ -201,7 +201,7 @@ class Wrestler < ActiveRecord::Base
end
end
def advanceInBracket
PoolAdvance.new(self).advanceWrestler
def advanceInBracket(match)
PoolAdvance.new(self,match).advanceWrestler
end
end

View File

@@ -12,5 +12,8 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.map"></script>
<!--Mobile and tablet detection-->
<script type='text/javascript' src="//wurfl.io/wurfl.js"></script>
<style>
</style>

View File

@@ -7,9 +7,15 @@
<li><%= link_to "Browse Tournaments", "/tournaments/" %></li>
<li><%= link_to "About", "/static_pages/about" %></li>
<% if user_signed_in? %>
<li><%=link_to "Log out", destroy_user_session_url ,:method => 'delete' %></li>
<li><%=link_to "Edit user", edit_user_registration_path %></li>
<li><%=link_to "My tournaments","/static_pages/my_tournaments" %></li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#"><%= current_user.email %>
<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><%=link_to "Log out", destroy_user_session_url ,:method => 'delete' %></li>
<li><%=link_to "Edit user", edit_user_registration_path %></li>
<li><%=link_to "My tournaments and schools","/static_pages/my_tournaments" %></li>
</ul>
</li>
<% else %>
<li><%= link_to "Log In" , new_user_session_path %></li>
<% end %>

View File

@@ -21,6 +21,10 @@
<br><%= link_to "Weigh In Page" , "/tournaments/#{@tournament.id}/weigh_in" %>
<br><%= link_to "All Matches" , "/tournaments/#{@tournament.id}/matches" %>
<br><%= link_to "Full Screen Bout Board" , "/tournaments/#{@tournament.id}/up_matches?print=true" %>
<% if can? :destroy, @tournament %>
<br><%= link_to "Tournament Delegation" , "/tournaments/#{@tournament.id}/delegate" %>
<% end %>
<br><%= link_to "School Delegation" , "/tournaments/#{@tournament.id}/school_delegate"%>
<br><br><strong>Time Savers</strong><br>
<br><%= link_to "Create High School Weights" , "/tournaments/#{@tournament.id}/create_custom_weights?customValue=hs",data: { confirm: 'Are you sure? This will delete all current weights.' } %>
@@ -31,7 +35,33 @@
</div>
<% end %>
<% end %>
<br><br>
<br>
<% if Rails.env.production? %>
<div class="adLNav">
<script type="text/javascript">
if(WURFL.is_mobile){
//Mobile and tablet ad
(function (){
if(window.CHITIKA===undefined) {window.CHITIKA = {'units' :[]};};
var unit = {"calltype":"async[2]","publisher":"cwimer","width":468,"height":60,"sid":"Chitika Default"};
var placement_id = window.CHITIKA.units.length;
window.CHITIKA.units.push(unit);
document.write('<div id="chitikaAdBlock-' + placement_id + '"></div>');
}());
} else {
//Desktop ad
(function (){
if(window.CHITIKA===undefined) {window.CHITIKA = {'units' :[]};};
var unit = {"calltype":"async[2]","publisher":"cwimer","width":160,"height":160,"sid":"Chitika Default"};
var placement_id = window.CHITIKA.units.length;
window.CHITIKA.units.push(unit);
document.write('<div id="chitikaAdBlock-' + placement_id + '"></div>');
}());
}
</script>
<script type="text/javascript" src="//cdn.chitika.net/getads.js" async></script>
</div>
<% end %>

View File

@@ -1,6 +1,27 @@
<% if Rails.env.production? %>
<div class="ad">
<script type='text/javascript' src='//eclkmpbn.com/adServe/banners?tid=85597_138467_6&size=158x21'></script>
<div class="adRnav">
<script type="text/javascript">
if(WURFL.is_mobile){
//Mobile and tablet ad
(function (){
if(window.CHITIKA===undefined) {window.CHITIKA = {'units' :[]};};
var unit = {"calltype":"async[2]","publisher":"cwimer","width":468,"height":60,"sid":"Chitika Default"};
var placement_id = window.CHITIKA.units.length;
window.CHITIKA.units.push(unit);
document.write('<div id="chitikaAdBlock-' + placement_id + '"></div>');
}());
} else {
//Desktop ad
(function (){
if(window.CHITIKA===undefined) {window.CHITIKA = {'units' :[]};};
var unit = {"calltype":"async[2]","publisher":"cwimer","width":120,"height":600,"sid":"Chitika Default"};
var placement_id = window.CHITIKA.units.length;
window.CHITIKA.units.push(unit);
document.write('<div id="chitikaAdBlock-' + placement_id + '"></div>');
}());
}
</script>
<script type="text/javascript" src="//cdn.chitika.net/getads.js" async></script>
</div>
<% end %>
<div class="afs_ads">&nbsp;</div>

View File

@@ -1,7 +1,7 @@
<p id="notice"><%= notice %></p>
<%= link_to "Back to #{@tournament.name}", "/tournaments/#{@tournament.id}",:class=>"btn btn-default" %>
<% if can? :manage, @tournament %>
<% if can? :manage, @school %>
| <%= link_to "Edit #{@school.name}", edit_school_path(@school),:class=>"btn btn-primary" %>
<% end %>
@@ -27,7 +27,7 @@
<br>
<% if can? :manage, @tournament %>
<% if can? :manage, @school %>
<%= link_to "New #{@school.name} Wrestler" , "/wrestlers/new?school=#{@school.id}", :class=>"btn btn-success"%>
<% end %>
<br>
@@ -39,8 +39,6 @@
<th>Name</th>
<th>Weight</th>
<th>Seed</th>
<th>Record</th>
<th>Seed Criteria</th>
<th>Team Points Scored</th>
<th>Extra?</th>
<th>Next Bout/Mat</th>
@@ -57,8 +55,6 @@
<td>
<%= wrestler.original_seed %>
</td>
<td><%= wrestler.season_win %>-<%= wrestler.season_loss %></td>
<td><%= wrestler.criteria %> Win <%= wrestler.seasonWinPercentage %>%</td>
<td><%= wrestler.totalTeamPoints - wrestler.totalDeductedPoints %></td>
<td><% if wrestler.extra? == true %>
Yes
@@ -66,7 +62,7 @@
<td><%= wrestler.nextMatchBoutNumber %> <%= wrestler.nextMatchMatName %></td>
<td>
<%= link_to 'Show', wrestler , :class=>"btn btn-default btn-sm" %>
<% if can? :manage, @tournament %>
<% if can? :manage, wrestler.school %>
<%= 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 btn-sm" %>
<% end %>

View File

@@ -27,6 +27,8 @@
<td><%= link_to 'Show', tournament, :class=>"btn btn-default btn-sm" %>
<% if can? :manage, tournament %>
<%= link_to 'Edit', edit_tournament_path(tournament), :class=>"btn btn-primary btn-sm" %>
<% end %>
<% if can? :destroy, tournament %>
<%= link_to 'Destroy', tournament, method: :delete, data: { confirm: 'Are you sure?' }, :class=>"btn btn-danger btn-sm" %>
<% end %>
</td>
@@ -34,7 +36,38 @@
<% end %>
</tbody>
</table>
<br>
<br>
<% if @schools.size > 0 %>
<h1>My Schools</h1>
<br>
<br>
<table class="table table-striped table-bordered table-condensed" id="tournamentList">
<thead>
<tr>
<th>Name</th>
<th>Tournament Name</th>
<th>Tournament Date</th>
<th></th>
</tr>
</thead>
<tbody>
<% @schools.each do |school| %>
<tr>
<td><%= school.name %></td>
<td><%= school.tournament.name %></td>
<td><%= school.tournament.date %></td>
<td><%= link_to 'Show', school, :class=>"btn btn-default btn-sm" %>
<% if can? :manage, school %>
<%= link_to 'Edit', edit_school_path(school), :class=>"btn btn-primary btn-sm" %>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% end %>
<br>

View File

@@ -18,9 +18,6 @@
</style>
<%= link_to "Back to #{@tournament.name} weights", "/tournaments/#{@tournament.id}/brackets" %>
<br>
<br>
<div id="exportable">
<% @tournament.weights.sort_by{|w| w.max}.each do |w| %>
<table class='pagebreak'>

View File

@@ -0,0 +1,66 @@
<%= link_to "Back to #{@tournament_name}", "/tournaments/#{@tournament_id}", :class=>"btn btn-default" %>
<br>
<br>
<% if @users %>
<h1>Search results</h1> <%= form_tag(tournament_delegate_path, :method => "get", id: "search-form") do %>
<%= text_field_tag :search, params[:search], placeholder: "Search users" %>
<%= submit_tag "Search" %>
<% end %>
<p>Search by email address</p>
</br>
</br>
<table class="table table-striped table-bordered table-condensed">
<thead>
<tr>
<th>User Email</th>
<th></th>
</tr>
</thead>
<tbody>
<% @users.each do |user| %>
<tr>
<td><%= user.email %></td>
<td>
<%= form_for TournamentDelegate.new, :url => url_for(:controller => 'tournaments', :action => 'delegate', :method => "post") do |f| %>
<%= f.hidden_field :user_id, :value => user.id %>
<% if can? :manage, @tournament %>
<%= submit_tag "Give permissions", :class=>"btn btn-success"%>
<% end %>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% end %>
<% if @users_delegates %>
<h1>Delegated users</h1> <%= form_tag(tournament_delegate_path, :method => "get", id: "search-form") do %>
<%= text_field_tag :search, params[:search], placeholder: "Search users" %>
<%= submit_tag "Search" %>
<% end %>
<p>Search by email address</p>
</br>
</br>
<table class="table table-striped table-bordered table-condensed">
<thead>
<tr>
<th>User Email</th>
<th></th>
</tr>
</thead>
<tbody>
<% @users_delegates.each do |delegate| %>
<tr>
<td><%= delegate.user.email %></td>
<td><%= link_to 'Remove permissions', "/tournaments/#{@tournament.id}/#{delegate.id}/remove_delegate", method: :delete, confirm: 'Are you sure?', :class=>"btn btn-danger btn-sm" %></td>
</tr>
<% end %>
</tbody>
</table>
<% end %>

View File

@@ -31,6 +31,8 @@
<td><%= link_to 'Show', tournament, :class=>"btn btn-default btn-sm" %>
<% if can? :manage, tournament %>
<%= link_to 'Edit', edit_tournament_path(tournament), :class=>"btn btn-primary btn-sm" %>
<% end %>
<% if can? :destroy, tournament %>
<%= link_to 'Destroy', tournament, method: :delete, data: { confirm: 'Are you sure?' }, :class=>"btn btn-danger btn-sm" %>
<% end %>
</td>

View File

@@ -0,0 +1,71 @@
<%= link_to "Back to #{@tournament_name}", "/tournaments/#{@tournament_id}", :class=>"btn btn-default" %>
<br>
<br>
<% if @users %>
<h1>Search results</h1> <%= form_tag(school_delegate_path, :method => "get", id: "search-form") do %>
<%= text_field_tag :search, params[:search], placeholder: "Search users" %>
<%= submit_tag "Search" %>
<% end %>
<p>Search by email address</p>
</br>
</br>
<table class="table table-striped table-bordered table-condensed">
<thead>
<tr>
<th>User Email</th>
<th>School to delegate</th>
<th></th>
</tr>
</thead>
<tbody>
<% @users.each do |user| %>
<tr>
<td><%= user.email %></td>
<%= form_for SchoolDelegate.new, :url => url_for(:controller => 'tournaments', :action => 'school_delegate', :method => "post") do |f| %>
<td><%= f.collection_select :school_id, @tournament.schools, :id, :name %></td>
<td>
<%= f.hidden_field :user_id, :value => user.id %>
<% if can? :manage, @tournament %>
<%= submit_tag "Give permissions", :class=>"btn btn-success"%>
<% end %>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% end %>
<% if @users_delegates %>
<h1>Delegated users schools</h1> <%= form_tag(school_delegate_path, :method => "get", id: "search-form") do %>
<%= text_field_tag :search, params[:search], placeholder: "Search users" %>
<%= submit_tag "Search" %>
<% end %>
<p>Search by email address</p>
</br>
</br>
<table class="table table-striped table-bordered table-condensed">
<thead>
<tr>
<th>User Email</th>
<th>School</th>
<th></th>
</tr>
</thead>
<tbody>
<% @users_delegates.each do |delegate| %>
<tr>
<td><%= delegate.user.email %></td>
<td><%= delegate.school.name %></td>
<td><%= link_to 'Remove permissions', "/tournaments/#{@tournament.id}/#{delegate.id}/remove_school_delegate", method: :delete, confirm: 'Are you sure?', :class=>"btn btn-danger btn-sm" %></td>
</tr>
<% end %>
</tbody>
</table>
<% end %>

View File

@@ -53,8 +53,10 @@
<tr>
<td><%= school.name %></td>
<td><%= link_to 'Show', school, :class=>"btn btn-default btn-sm" %>
<% if can? :manage, @tournament %>
<% if can? :manage, school %>
<%= link_to 'Edit', edit_school_path(school), :class=>"btn btn-primary btn-sm" %>
<% end %>
<% if can? :manage, @tournament %>
<%= link_to 'Destroy', school, method: :delete, data: { confirm: 'Are you sure?' }, :class=>"btn btn-danger btn-sm" %>
<% end %>
</td>

View File

@@ -2,7 +2,7 @@
<p id="notice"><%= notice %></p>
<%= link_to "Back to #{@school.name}", "/schools/#{@school.id}", :class=>"btn btn-default" %>
<% if can? :manage, @tournament %>
<% if can? :manage, @school %>
| <%= link_to "Edit #{@wrestler.name}", edit_wrestler_path(@wrestler), :class=>"btn btn-primary" %>
<% end %>
<% cache ["wrestlers", @wrestler] do %>

View File

@@ -22,7 +22,6 @@ Wrestling::Application.routes.draw do
# You can have the root of your site routed with "root"
root 'static_pages#home'
get 'admin/index'
get 'static_pages/control_match'
get 'static_pages/not_allowed'
get 'static_pages/about'
@@ -34,12 +33,18 @@ Wrestling::Application.routes.draw do
get 'tournaments/:id/create_custom_weights' => 'tournaments#create_custom_weights'
get 'tournaments/:id/all_brackets' => 'tournaments#all_brackets'
get 'tournaments/:id/brackets' => 'tournaments#brackets'
get 'tournaments/:id/brackets/:weight' => 'tournaments#bracket'
get 'tournaments/:id/brackets/:weight' => 'tournaments#bracket', :as => :weight_bracket
get 'tournaments/:id/generate_matches' => 'tournaments#generate_matches'
get 'tournaments/:id/team_scores' => 'tournaments#team_scores'
get 'tournaments/:id/up_matches' => 'tournaments#up_matches'
get 'tournaments/:id/up_matches' => 'tournaments#up_matches', :as => :up_matches
get 'tournaments/:id/no_matches' => 'tournaments#no_matches'
get 'tournaments/:id/matches' => 'tournaments#matches'
get 'tournaments/:id/delegate' => 'tournaments#delegate', :as => :tournament_delegate
post 'tournaments/:id/delegate' => 'tournaments#delegate', :as => :set_tournament_delegate
delete 'tournaments/:id/:delegate/remove_delegate' => 'tournaments#remove_delegate', :as => :delete_delegate_path
get 'tournaments/:id/school_delegate' => 'tournaments#school_delegate', :as => :school_delegate
post 'tournaments/:id/school_delegate' => 'tournaments#school_delegate', :as => :set_school_delegate
delete 'tournaments/:id/:delegate/remove_school_delegate' => 'tournaments#remove_school_delegate', :as => :delete_school_delegate_path
# Example of regular route:
# get 'products/:id' => 'catalog#view'

View File

@@ -4,7 +4,7 @@ FROM ruby:2.2.3
RUN apt-get update
RUN apt-get -y upgrade
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install build-essential libssl-dev libyaml-dev libreadline-dev openssl curl git-core zlib1g-dev bison libxml2-dev libxslt1-dev libcurl4-openssl-dev libsqlite3-dev sqlite3 wget apache2 apt-transport-https nodejs mysql-client
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install build-essential libssl-dev libyaml-dev libreadline-dev openssl curl git-core zlib1g-dev bison libxml2-dev libxslt1-dev libcurl4-openssl-dev libsqlite3-dev sqlite3 wget apache2 apt-transport-https nodejs mysql-client postfix
#New Relic
#RUN echo deb http://apt.newrelic.com/debian/ newrelic non-free >> /etc/apt/sources.list.d/newrelic.list

View File

@@ -28,6 +28,10 @@ class MatchesControllerTest < ActionController::TestCase
def sign_in_tournament_delegate
sign_in users(:three)
end
def sign_in_school_delegate
sign_in users(:four)
end
def success
assert_response :success
@@ -52,6 +56,12 @@ class MatchesControllerTest < ActionController::TestCase
get_edit
redirect
end
test "logged school delegate should not get edit match page if not owner" do
sign_in_school_delegate
get_edit
redirect
end
test "non logged in user should not get edit match page" do
get_edit
@@ -68,6 +78,12 @@ class MatchesControllerTest < ActionController::TestCase
post_update
assert_redirected_to '/static_pages/not_allowed'
end
test "logged school delegate should not post update match if not owner" do
sign_in_school_delegate
post_update
assert_redirected_to '/static_pages/not_allowed'
end
test "logged in tournament delegate should get edit match page" do
sign_in_tournament_delegate

View File

@@ -44,7 +44,11 @@ class MatsControllerTest < ActionController::TestCase
def sign_in_tournament_delegate
sign_in users(:three)
end
def sign_in_school_delegate
sign_in users(:four)
end
def success
assert_response :success
end
@@ -78,6 +82,12 @@ class MatsControllerTest < ActionController::TestCase
get_edit
redirect
end
test "logged school delegate should not get edit mat page if not owner" do
sign_in_school_delegate
get_edit
redirect
end
test "non logged in user should not get edit mat page" do
get_edit
@@ -94,6 +104,12 @@ class MatsControllerTest < ActionController::TestCase
post_update
redirect
end
test "logged school delegate should not post update mat if not owner" do
sign_in_school_delegate
post_update
redirect
end
test "logged in tournament owner should post update mat" do
sign_in_owner
@@ -130,6 +146,14 @@ class MatsControllerTest < ActionController::TestCase
create
redirect
end
test "logged school delegate not tournament owner cannot create a mat" do
sign_in_school_delegate
new
redirect
create
redirect
end
test "logged in tournament owner can destroy a mat" do
sign_in_owner
@@ -149,11 +173,23 @@ class MatsControllerTest < ActionController::TestCase
redirect
end
test "logged school delegate not tournament owner cannot destroy mat" do
sign_in_school_delegate
destroy
redirect
end
test "logged in user should not get show mat" do
sign_in_non_owner
show
redirect
end
test "logged school delegate should not get show mat" do
sign_in_school_delegate
show
redirect
end
test "logged in tournament owner should get show mat" do
sign_in_owner

View File

@@ -40,6 +40,10 @@ class SchoolsControllerTest < ActionController::TestCase
def sign_in_tournament_delegate
sign_in users(:three)
end
def sign_in_school_delegate
sign_in users(:four)
end
def success
assert_response :success
@@ -60,6 +64,12 @@ class SchoolsControllerTest < ActionController::TestCase
get_edit
success
end
test "logged in school delegate should get edit school page" do
sign_in_school_delegate
get_edit
success
end
test "logged in user should not get edit school page if not owner" do
sign_in_non_owner
@@ -94,6 +104,12 @@ class SchoolsControllerTest < ActionController::TestCase
post_update
assert_redirected_to tournament_path(@school.tournament_id)
end
test "logged in school delegate should post update school" do
sign_in_school_delegate
post_update
assert_redirected_to tournament_path(@school.tournament_id)
end
test "logged in tournament owner can create a new school" do
sign_in_owner
@@ -110,6 +126,14 @@ class SchoolsControllerTest < ActionController::TestCase
create
assert_redirected_to tournament_path(@school.tournament_id)
end
test "logged in school delegate cannot create a new school" do
sign_in_school_delegate
new
redirect
create
redirect
end
test "logged in user not tournament owner cannot create a school" do
sign_in_non_owner
@@ -130,6 +154,12 @@ class SchoolsControllerTest < ActionController::TestCase
destroy
assert_redirected_to tournament_path(@tournament.id)
end
test "logged in school delegate can destroy a school" do
sign_in_school_delegate
destroy
redirect
end
test "logged in user not tournament owner cannot destroy school" do
sign_in_non_owner

View File

@@ -29,6 +29,10 @@ include Devise::TestHelpers
def sign_in_delegate
sign_in users(:three)
end
def sign_in_school_delegate
sign_in users(:four)
end
def success
assert_response :success
@@ -61,6 +65,12 @@ include Devise::TestHelpers
get :generate_matches, id: 1
redirect
end
test "logged in school delegate cannot generate matches" do
sign_in_school_delegate
get :generate_matches, id: 1
redirect
end
test "logged in tournament owner can create custom weights" do
sign_in_owner
@@ -73,6 +83,12 @@ include Devise::TestHelpers
get :create_custom_weights, id: 1, customValue: 'hs'
redirect
end
test "logged in school delegate cannot create custom weights" do
sign_in_school_delegate
get :create_custom_weights, id: 1, customValue: 'hs'
redirect
end
test "logged in tournament owner can access weigh_ins" do
@@ -86,6 +102,12 @@ include Devise::TestHelpers
get :weigh_in, id: 1
redirect
end
test "logged in school delegate cannot access weigh_ins" do
sign_in_school_delegate
get :weigh_in, id: 1
redirect
end
test "logged in tournament owner can access weigh_in_weight" do
sign_in_owner
@@ -99,6 +121,12 @@ include Devise::TestHelpers
redirect
end
test "logged in school delegate cannot access weigh_in_weight" do
sign_in_school_delegate
get :weigh_in_weight, id: 1, weight: 1
redirect
end
test "logged in tournament owner can access post weigh_in_weight" do
sign_in_owner
post :weigh_in, id: 1, weight: 1, wrestler: @wrestlers
@@ -109,6 +137,12 @@ include Devise::TestHelpers
post :weigh_in_weight, id: 1, weight: 1, wrestler: @wrestlers
redirect
end
test "logged in school delegate cannot access post weigh_in_weight" do
sign_in_school_delegate
post :weigh_in_weight, id: 1, weight: 1, wrestler: @wrestlers
redirect
end
test "logged in tournament owner should get edit tournament page" do
@@ -122,6 +156,12 @@ include Devise::TestHelpers
get_edit
redirect
end
test "logged in school delegate should not get edit tournament page if not owner" do
sign_in_school_delegate
get_edit
redirect
end
test "non logged in user should not get edit tournament page" do
get_edit
@@ -138,6 +178,12 @@ include Devise::TestHelpers
post_update
assert_redirected_to '/static_pages/not_allowed'
end
test "logged in school delegate should not post update tournament if not owner" do
sign_in_school_delegate
post_update
assert_redirected_to '/static_pages/not_allowed'
end
test "logged in tournament owner should post update tournament" do
sign_in_owner
@@ -158,6 +204,12 @@ include Devise::TestHelpers
redirect
end
test "logged in school delegate not tournament owner cannot destroy tournament" do
sign_in_school_delegate
destroy
redirect
end
#TESTS THAT NEED MATCHES PUT ABOVE THIS
test "redirect up_matches if no matches" do
@@ -221,5 +273,55 @@ include Devise::TestHelpers
destroy
redirect
end
test 'logged in tournament owner can delegate a user' do
sign_in_owner
get :delegate, id: 1
success
end
test 'logged in tournament delegate cannot delegate a user' do
sign_in_delegate
get :delegate, id: 1
redirect
end
test 'logged in tournament owner can delegate a school user' do
sign_in_owner
get :school_delegate, id: 1
success
end
test 'logged in tournament delegate can delegate a school user' do
sign_in_delegate
get :school_delegate, id: 1
success
end
test 'logged in tournament owner can delete a school delegate' do
sign_in_owner
patch :remove_school_delegate, id: 1, delegate: SchoolDelegate.find(1)
assert_redirected_to "/tournaments/#{@tournament.id}/school_delegate"
end
test 'logged in tournament delegate can delete a school delegate' do
sign_in_delegate
patch :remove_school_delegate, id: 1, delegate: SchoolDelegate.find(1)
assert_redirected_to "/tournaments/#{@tournament.id}/school_delegate"
end
test 'logged in tournament owner can delete a delegate' do
sign_in_owner
patch :remove_delegate, id: 1, delegate: TournamentDelegate.find(1)
assert_redirected_to "/tournaments/#{@tournament.id}/delegate"
end
test 'logged in tournament delegate cannot delete a delegate' do
sign_in_delegate
patch :remove_delegate, id: 1, delegate: TournamentDelegate.find(1)
redirect
end
end

View File

@@ -40,6 +40,10 @@ class WeightsControllerTest < ActionController::TestCase
def sign_in_tournament_delegate
sign_in users(:three)
end
def sign_in_school_delegate
sign_in users(:four)
end
def success
assert_response :success
@@ -66,6 +70,12 @@ class WeightsControllerTest < ActionController::TestCase
get_edit
redirect
end
test "logged school delegate should not get edit weight page if not owner" do
sign_in_school_delegate
get_edit
redirect
end
test "non logged in user should not get edit weight page" do
get_edit
@@ -82,6 +92,12 @@ class WeightsControllerTest < ActionController::TestCase
post_update
redirect
end
test "logged school delegate should not post update weight if not owner" do
sign_in_school_delegate
post_update
redirect
end
test "logged in tournament owner should post update weight" do
sign_in_owner
@@ -118,6 +134,14 @@ class WeightsControllerTest < ActionController::TestCase
create
redirect
end
test "logged school delegate not tournament owner cannot create a weight" do
sign_in_school_delegate
new
redirect
create
redirect
end
test "logged in tournament owner can destroy a weight" do
sign_in_owner
@@ -136,6 +160,12 @@ class WeightsControllerTest < ActionController::TestCase
destroy
redirect
end
test "logged school delegate not tournament owner cannot destroy weight" do
sign_in_school_delegate
destroy
redirect
end
test "view wegiht" do
get :show, id: 1

View File

@@ -41,6 +41,10 @@ class WrestlersControllerTest < ActionController::TestCase
def sign_in_tournament_delegate
sign_in users(:three)
end
def sign_in_school_delegate
sign_in users(:four)
end
def success
assert_response :success
@@ -61,6 +65,12 @@ class WrestlersControllerTest < ActionController::TestCase
get_edit
success
end
test "logged in school delegate should get edit wrestler page" do
sign_in_school_delegate
get_edit
success
end
test "logged in user should not get edit wrestler page if not owner" do
sign_in_non_owner
@@ -95,6 +105,12 @@ class WrestlersControllerTest < ActionController::TestCase
post_update
assert_redirected_to school_path(@school.id)
end
test "logged in school delegate should post update wrestler" do
sign_in_school_delegate
post_update
assert_redirected_to school_path(@school.id)
end
test "logged in tournament owner can create a new wrestler" do
sign_in_owner
@@ -111,6 +127,14 @@ class WrestlersControllerTest < ActionController::TestCase
create
assert_redirected_to school_path(@school.id)
end
test "logged in school delegate can create a new wrestler" do
sign_in_school_delegate
new
success
create
assert_redirected_to school_path(@school.id)
end
test "logged in user not tournament owner cannot create a wrestler" do
sign_in_non_owner
@@ -131,6 +155,12 @@ class WrestlersControllerTest < ActionController::TestCase
destroy
assert_redirected_to school_path(@school.id)
end
test "logged in school delegate can destroy a wrestler" do
sign_in_school_delegate
destroy
assert_redirected_to school_path(@school.id)
end
test "logged in user not tournament owner cannot destroy wrestler" do
sign_in_non_owner

View File

@@ -7,3 +7,8 @@
# two:
# user_id: 1
# school_id: 1
one:
id: 1
user_id: 4
school_id: 1

View File

@@ -9,5 +9,6 @@
# tournament_id: 1
one:
id: 1
user_id: 3
tournament_id: 1

View File

@@ -19,3 +19,7 @@ two:
three:
email: test3@test.com
id: 3
four:
email: test4@test.com
id: 4

View File

@@ -222,9 +222,7 @@ class PoolAdvancementTest < ActionDispatch::IntegrationTest
match.winner_id = translateNameToId(winner)
match.win_type = "Decision"
match.score = 1-0
#Need to manually assign mat_id because thise weight class is not currently assigned a mat
mat = @tournament.mats.first
match.mat_id = mat.id
match.save
end
@@ -234,9 +232,7 @@ class PoolAdvancementTest < ActionDispatch::IntegrationTest
match.winner_id = translateNameToId(winner)
match.win_type = "Decision"
match.score = 0-2
#Need to manually assign mat_id because thise weight class is not currently assigned a mat
mat = @tournament.mats.first
match.mat_id = mat.id
match.save
end
@@ -246,9 +242,7 @@ class PoolAdvancementTest < ActionDispatch::IntegrationTest
match.winner_id = translateNameToId(winner)
match.win_type = "Major"
match.score = 8-0
#Need to manually assign mat_id because thise weight class is not currently assigned a mat
mat = @tournament.mats.first
match.mat_id = mat.id
match.save
end
@@ -257,9 +251,7 @@ class PoolAdvancementTest < ActionDispatch::IntegrationTest
match.finished = 1
match.winner_id = translateNameToId(winner)
match.win_type = "Tech Fall"
#Need to manually assign mat_id because thise weight class is not currently assigned a mat
mat = @tournament.mats.first
match.mat_id = mat.id
match.save
end
@@ -269,9 +261,7 @@ class PoolAdvancementTest < ActionDispatch::IntegrationTest
match.winner_id = translateNameToId(winner)
match.win_type = "Pin"
match.score = "5:00"
#Need to manually assign mat_id because thise weight class is not currently assigned a mat
mat = @tournament.mats.first
match.mat_id = mat.id
match.save
end
@@ -281,9 +271,7 @@ class PoolAdvancementTest < ActionDispatch::IntegrationTest
match.winner_id = translateNameToId(winner)
match.win_type = "Pin"
match.score = "0:20"
#Need to manually assign mat_id because thise weight class is not currently assigned a mat
mat = @tournament.mats.first
match.mat_id = mat.id
match.save
end
@@ -293,9 +281,7 @@ class PoolAdvancementTest < ActionDispatch::IntegrationTest
match.winner_id = translateNameToId(winner)
match.win_type = "Pin"
match.score = "1:20"
#Need to manually assign mat_id because thise weight class is not currently assigned a mat
mat = @tournament.mats.first
match.mat_id = mat.id
match.save
end
@@ -550,6 +536,16 @@ class PoolAdvancementTest < ActionDispatch::IntegrationTest
assert_equal 2, wrestler.teamPointsEarned
end
test "Test mat assignment when adding a mat and when destroying a mat" do
@mat2 = Mat.new
@mat2.name = "2"
@mat2.tournament_id = 1
@mat2.save
assert_equal 4, @mat2.matches.size
elevenManBracketFinished
@mat2.destroy
@mat1 = Mat.find(1)
assert_equal 4, @mat1.matches.size
end
end