1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-03-24 17:04:43 +00:00

Added logic to delegate tournament access

This commit is contained in:
2016-01-06 18:38:02 +00:00
parent eb9037b078
commit f46029efaf
46 changed files with 417 additions and 121 deletions

View File

@@ -1,5 +0,0 @@
class AdminController < ApplicationController
def index
end
end

View File

@@ -3,4 +3,8 @@ class ApplicationController < ActionController::Base
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
rescue_from CanCan::AccessDenied do |exception|
# flash[:error] = "Access denied!"
redirect_to '/static_pages/not_allowed'
end
end

View File

@@ -49,8 +49,6 @@ class MatchesController < ApplicationController
end
def check_access
if current_user != @match.tournament.user
redirect_to '/static_pages/not_allowed'
end
authorize! :manage, @match.tournament
end
end

View File

@@ -89,9 +89,7 @@ class MatsController < ApplicationController
elsif @mat
@tournament = @mat.tournament
end
if current_user != @tournament.user
redirect_to '/static_pages/not_allowed'
end
authorize! :manage, @tournament
end

View File

@@ -84,9 +84,7 @@ class SchoolsController < ApplicationController
elsif @school
@tournament = @school.tournament
end
if current_user != @tournament.user
redirect_to '/static_pages/not_allowed'
end
authorize! :manage, @tournament
end
end

View File

@@ -1,7 +1,10 @@
class StaticPagesController < ApplicationController
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
def not_allowed

View File

@@ -1,6 +1,8 @@
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, 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]
def matches
@@ -149,10 +151,12 @@ class TournamentsController < ApplicationController
end
#Check for tournament owner
def check_access
if current_user != @tournament.user
redirect_to '/static_pages/not_allowed'
end
def check_access_destroy
authorize! :destroy, @tournament
end
def check_access_manage
authorize! :manage, @tournament
end
def check_for_matches

View File

@@ -63,9 +63,6 @@ class WeightsController < ApplicationController
# DELETE /weights/1.json
def destroy
@tournament = Tournament.find(@weight.tournament_id)
if current_user != @tournament.user
redirect_to root_path
end
@weight.destroy
respond_to do |format|
format.html { redirect_to @tournament }
@@ -91,9 +88,7 @@ class WeightsController < ApplicationController
elsif @weight
@tournament = @weight.tournament
end
if current_user != @tournament.user
redirect_to '/static_pages/not_allowed'
end
authorize! :manage, @tournament
end

View File

@@ -99,8 +99,6 @@ class WrestlersController < ApplicationController
elsif @wrestler
@tournament = @wrestler.tournament
end
if current_user != @tournament.user
redirect_to '/static_pages/not_allowed'
end
authorize! :manage, @tournament
end
end

View File

@@ -1,14 +1,4 @@
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

58
app/models/ability.rb Normal file
View 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

View File

@@ -30,7 +30,7 @@ class Mat < ActiveRecord::Base
end
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

View File

@@ -2,6 +2,7 @@ class School < ActiveRecord::Base
belongs_to :tournament, touch: true
has_many :wrestlers, dependent: :destroy
has_many :deductedPoints, through: :wrestlers
has_many :delegates, class_name: "SchoolDelegate"
validates :name, presence: true

View File

@@ -0,0 +1,2 @@
class SchoolDelegate < ActiveRecord::Base
end

View File

@@ -8,6 +8,7 @@ class Tournament < ActiveRecord::Base
has_many :mats, dependent: :destroy
has_many :wrestlers, through: :weights
has_many :matches, dependent: :destroy
has_many :delegates, class_name: "TournamentDelegate"
validates :date, :name, :tournament_type, :address, :director, :director_email , presence: true

View File

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

View File

@@ -2,7 +2,10 @@ 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"
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
end

View File

@@ -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>

View File

@@ -12,7 +12,7 @@
<li><%= link_to "Team Scores" , "/tournaments/#{@tournament.id}/team_scores" %></li>
</ul>
</div>
<% if tournament_permissions(@tournament) %>
<% if can? :manage, @tournament %>
<br><br>
<div class="" style="padding-right: 1%;">
<h4>Tournament Director Links</h4>

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 tournament_permissions(@school.tournament) %>
<% if can? :manage, @tournament %>
| <%= link_to "Edit #{@school.name}", edit_school_path(@school),:class=>"btn btn-primary" %>
<% end %>
@@ -19,7 +19,7 @@
<p>
<strong>Tournament:</strong>
<%= Tournament.find(@school.tournament_id).name %>
<%= @school.tournament.name %>
</p>
@@ -27,13 +27,13 @@
<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"%>
<% end %>
<br>
<br>
<% cache ["schools", @school] do %>
<table class="table table-striped table-bordered">
<table class="table table-striped table-bordered table-condensed">
<thead>
<tr>
<th>Name</th>
@@ -53,7 +53,7 @@
<% if wrestler.school_id == @school.id %>
<tr>
<td><%= wrestler.name %></td>
<td><%= Weight.find(wrestler.weight_id).max %></td>
<td><%= wrestler.weight.max %></td>
<td>
<%= wrestler.original_seed %>
</td>
@@ -65,10 +65,10 @@
<% end %></td>
<td><%= wrestler.nextMatchBoutNumber %> <%= wrestler.nextMatchMatName %></td>
<td>
<%= link_to 'Show', wrestler , :class=>"btn btn-default" %>
<% if tournament_permissions(@school.tournament) %>
<%= link_to 'Edit', edit_wrestler_path(wrestler),:class=>"btn btn-primary" %>
<%= link_to 'Destroy', wrestler, method: :delete, data: { confirm: 'Are you sure?' }, :class=>"btn btn-danger" %>
<%= link_to 'Show', wrestler , :class=>"btn btn-default btn-sm" %>
<% if can? :manage, @tournament %>
<%= 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 %>
</td>
</tr>

View File

@@ -10,7 +10,7 @@
<% end %>
</br>
</br>
<table class="table table-striped table-bordered" id="tournamentList">
<table class="table table-striped table-bordered table-condensed" id="tournamentList">
<thead>
<tr>
<th>Name</th>
@@ -24,10 +24,10 @@
<tr>
<td><%= tournament.name %></td>
<td><%= tournament.date %></td>
<td><%= link_to 'Show', tournament, :class=>"btn btn-default" %>
<% if tournament_permissions(tournament) %>
<%= link_to 'Edit', edit_tournament_path(tournament), :class=>"btn btn-primary" %>
<%= link_to 'Destroy', tournament, method: :delete, data: { confirm: 'Are you sure?' }, :class=>"btn btn-danger" %>
<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" %>
<%= link_to 'Destroy', tournament, method: :delete, data: { confirm: 'Are you sure?' }, :class=>"btn btn-danger btn-sm" %>
<% end %>
</td>
</tr>

View File

@@ -2,7 +2,7 @@
<% @pool = 1 %>
<% until @wrestlers.select{|w| w.generatePoolNumber == @pool}.blank? %>
<h5>Pool <%= @pool %></h5>
<table class="table table-striped table-bordered">
<table class="table table-striped table-bordered table-condensed">
<thead>
<tr>
<th>Name</th>

View File

@@ -5,6 +5,6 @@
<%= link_to "#{weight.max}" , "/tournaments/#{@tournament.id}/brackets/#{weight.id}" %>
<br>
<% end %>
<% if tournament_permissions(@tournament) %>
<% if can? :manage, @tournament %>
<%= link_to "All Brackets (Printable)", "/tournaments/#{@tournament.id}/all_brackets?print=true" %>
<% end %>

View File

@@ -14,7 +14,7 @@
<% end %>
</br>
</br>
<table class="table table-striped table-bordered" id="tournamentList">
<table class="table table-striped table-bordered table-condensed" id="tournamentList">
<thead>
<tr>
<th>Name</th>
@@ -28,10 +28,10 @@
<tr>
<td><%= tournament.name %></td>
<td><%= tournament.date %></td>
<td><%= link_to 'Show', tournament, :class=>"btn btn-default" %>
<% if tournament_permissions(tournament) %>
<%= link_to 'Edit', edit_tournament_path(tournament), :class=>"btn btn-primary" %>
<%= link_to 'Destroy', tournament, method: :delete, data: { confirm: 'Are you sure?' }, :class=>"btn btn-danger" %>
<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" %>
<%= link_to 'Destroy', tournament, method: :delete, data: { confirm: 'Are you sure?' }, :class=>"btn btn-danger btn-sm" %>
<% end %>
</td>
</tr>

View File

@@ -12,7 +12,7 @@
</script>
</br>
</br>
<table class="table table-striped table-bordered" id="matchesList">
<table class="table table-striped table-bordered table-condensed" id="matchesList">
<thead>
<tr>
<th>Bout number</th>
@@ -28,8 +28,8 @@
<td><%= match.bout_number %></td>
<td><%= match.w1_name %> vs <%= match.w2_name %></td>
<td><%= match.finished %></td>
<td><%= link_to 'Show', match, :class=>"btn btn-default" %>
<%= link_to 'Edit', edit_match_path(match), :class=>"btn btn-primary" %>
<td><%= link_to 'Show', match, :class=>"btn btn-default btn-sm" %>
<%= link_to 'Edit', edit_match_path(match), :class=>"btn btn-primary btn-sm" %>
</td>
</tr>
<% end %>

View File

@@ -1,6 +1,6 @@
<p id="notice"><%= notice %></p>
<%= 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" %>
<% end %>
@@ -34,12 +34,12 @@
<br>
<h3>School Lineups</h3>
<br>
<% if tournament_permissions(@tournament) %>
<%= link_to "New #{@tournament.name} School" , "/schools/new?tournament=#{@tournament.id}", :class=>"btn btn-success" %>
<% if can? :manage, @tournament %>
<%= link_to "New #{@tournament.name} School" , "/schools/new?tournament=#{@tournament.id}", :class=>"btn btn-success btn-sm" %>
<br>
<br>
<% end %>
<table class="table table-striped table-bordered">
<table class="table table-striped table-bordered table-condensed">
<thead>
<tr>
<th>Name</th>
@@ -52,10 +52,10 @@
<% @schools.each do |school| %>
<tr>
<td><%= school.name %></td>
<td><%= link_to 'Show', school, :class=>"btn btn-default" %>
<% if tournament_permissions(@tournament) %>
<%= link_to 'Edit', edit_school_path(school), :class=>"btn btn-primary" %>
<%= link_to 'Destroy', school, method: :delete, data: { confirm: 'Are you sure?' }, :class=>"btn btn-danger" %>
<td><%= link_to 'Show', school, :class=>"btn btn-default btn-sm" %>
<% if can? :manage, @tournament %>
<%= 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 btn-sm" %>
<% end %>
</td>
</tr>
@@ -68,12 +68,12 @@
<h3>Weight Class Seeds</h3>
<br>
<% if tournament_permissions(@tournament) %>
<%= link_to "New #{@tournament.name} Weight" , "/weights/new?tournament=#{@tournament.id}", :class=>"btn btn-success" %>
<% if can? :manage, @tournament %>
<%= link_to "New #{@tournament.name} Weight" , "/weights/new?tournament=#{@tournament.id}", :class=>"btn btn-success btn-sm" %>
<br>
<br>
<% end %>
<table class="table table-striped table-bordered">
<table class="table table-striped table-bordered table-condensed">
<thead>
<tr>
<th>Weight Class</th>
@@ -87,10 +87,10 @@
<tr>
<td><%= weight.max %></td>
<td><%= weight.bracket_size %></td>
<td><%= link_to 'Show', weight, :class=>"btn btn-default" %>
<% if tournament_permissions(@tournament) %>
<%= link_to 'Edit', edit_weight_path(weight), :class=>"btn btn-primary" %>
<%= link_to 'Destroy', weight, method: :delete, data: { confirm: 'Are you sure?' }, :class=>"btn btn-danger" %>
<td><%= link_to 'Show', weight, :class=>"btn btn-default btn-sm" %>
<% if can? :manage, @tournament %>
<%= 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 btn-sm" %>
<% end %>
</td>
</tr>
@@ -98,15 +98,15 @@
</tbody>
</table>
<% if tournament_permissions(@tournament) %>
<% if can? :manage, @tournament %>
<br>
<br>
<h3>Mats</h3>
<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>
<table class="table table-striped table-bordered">
<table class="table table-striped table-bordered table-condensed">
<thead>
<tr>
<th>Name</th>
@@ -119,9 +119,9 @@
<tr>
<td><%= mat.name %></td>
<td>
<% if tournament_permissions(@tournament) %>
<%= link_to 'Show', mat, :class=>"btn btn-default" %>
<%= link_to 'Destroy', mat, method: :delete, data: { confirm: 'Are you sure?' }, :class=>"btn btn-danger" %>
<% if can? :manage, @tournament %>
<%= 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 btn-sm" %>
<% end %>
</td>
</tr>

View File

@@ -6,7 +6,7 @@
<br>
<% end %>
<br>
<% if tournament_permissions(@tournament) %>
<% if can? :manage, @tournament %>
<%= form_for(@tournament) do |f| %>
<div class="field">
<%= f.label :weigh_in_ref %><br>

View File

@@ -19,7 +19,7 @@
<% if wrestler.weight_id == @weight.id %>
<tr>
<td><%= wrestler.name %></td>
<td><%= School.find(wrestler.school_id).name %></td>
<td><%= wrestler.school.name %></td>
<td><%= wrestler.original_seed %></td>
<td><%= wrestler.weight.max %></td>
<td>
@@ -37,7 +37,7 @@
</tbody>
</table>
<%= hidden_field_tag :tournament, @tournament_id %>
<% if tournament_permissions(@tournament) %>
<% if can? :manage, @tournament %>
<%= submit_tag "Save", :class=>"btn btn-success"%>
<% end %>
<% end %>

View File

@@ -3,7 +3,7 @@
<%= 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" %>
<% end %>
@@ -11,7 +11,7 @@
<h1>Weight Class:<%= @weight.max %></h1>
<br>
<br>
<table class="table table-striped table-bordered">
<table class="table table-striped table-bordered table-condensed">
<thead>
<tr>
<th>Name</th>
@@ -20,7 +20,7 @@
<th>Record</th>
<th>Seed Criteria</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>
</thead>
<tbody>
@@ -29,9 +29,9 @@
<% if wrestler.weight_id == @weight.id %>
<tr>
<td><%= wrestler.name %></td>
<td><%= School.find(wrestler.school_id).name %></td>
<td><%= wrestler.school.name %></td>
<td>
<% if tournament_permissions(@tournament) %>
<% if can? :manage, @tournament %>
<%= fields_for "wrestler[]", wrestler do |w| %>
<%= w.text_field :original_seed %>
<% end %>
@@ -44,9 +44,9 @@
<td><% if wrestler.extra? == true %>
Yes
<% end %></td>
<% if tournament_permissions(@tournament) %>
<td><%= link_to 'Show', wrestler , :class=>"btn btn-default" %>
<%= link_to 'Destroy', wrestler, method: :delete, data: { confirm: 'Are you sure?' } , :class=>"btn btn-danger" %></td>
<% if can? :manage, @tournament %>
<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 btn-sm" %></td>
<% end %>
</tr>
<% end %>
@@ -54,7 +54,7 @@
</tbody>
</table>
<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>
<%= submit_tag "Save", :class=>"btn btn-success"%>
<% end %>

View File

@@ -30,10 +30,6 @@
<%= f.collection_select :weight_id, @weights, :id, :max %>
</div>
<div class="field">
<%= f.label :original_seed %><br>
<%= f.number_field :original_seed %>
</div>
<div class="field">
<%= f.label "Season Wins" %><br>
<%= f.number_field :season_win %>

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 tournament_permissions(@wrestler.tournament) %>
<% if can? :manage, @tournament %>
| <%= link_to "Edit #{@wrestler.name}", edit_wrestler_path(@wrestler), :class=>"btn btn-primary" %>
<% end %>
<% cache ["wrestlers", @wrestler] do %>

View 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

View 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

View File

@@ -11,7 +11,7 @@
#
# 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|
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"
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|
t.string "name"
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"
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|
t.string "name"
t.string "address"

View File

@@ -1,7 +0,0 @@
require 'test_helper'
class AdminControllerTest < ActionController::TestCase
test "the truth" do
assert true
end
end

View File

@@ -24,6 +24,10 @@ class MatchesControllerTest < ActionController::TestCase
def sign_in_non_owner
sign_in users(:two)
end
def sign_in_tournament_delegate
sign_in users(:three)
end
def success
assert_response :success
@@ -65,11 +69,16 @@ class MatchesControllerTest < ActionController::TestCase
assert_redirected_to '/static_pages/not_allowed'
end
test "logged in tournament owner should post update match" do
sign_in_owner
test "logged in tournament delegate should get edit match page" do
sign_in_tournament_delegate
get_edit
success
end
test "logged in tournament delegate should post update match" do
sign_in_tournament_delegate
post_update
assert_redirected_to mat_path(1)
end
end

View File

@@ -40,6 +40,10 @@ class MatsControllerTest < ActionController::TestCase
def sign_in_non_owner
sign_in users(:two)
end
def sign_in_tournament_delegate
sign_in users(:three)
end
def success
assert_response :success
@@ -62,6 +66,12 @@ class MatsControllerTest < ActionController::TestCase
get_edit
success
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
sign_in_non_owner
@@ -90,6 +100,12 @@ class MatsControllerTest < ActionController::TestCase
post_update
assert_redirected_to tournament_path(@mat.tournament_id)
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
sign_in_owner
@@ -98,6 +114,14 @@ class MatsControllerTest < ActionController::TestCase
create
assert_redirected_to tournament_path(@mat.tournament_id)
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
sign_in_non_owner
@@ -112,6 +136,12 @@ class MatsControllerTest < ActionController::TestCase
destroy
assert_redirected_to tournament_path(@tournament.id)
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
sign_in_non_owner
@@ -130,6 +160,12 @@ class MatsControllerTest < ActionController::TestCase
show
success
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

View File

@@ -36,6 +36,10 @@ class SchoolsControllerTest < ActionController::TestCase
def sign_in_non_owner
sign_in users(:two)
end
def sign_in_tournament_delegate
sign_in users(:three)
end
def success
assert_response :success
@@ -50,6 +54,12 @@ class SchoolsControllerTest < ActionController::TestCase
get_edit
success
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
sign_in_non_owner
@@ -78,6 +88,12 @@ class SchoolsControllerTest < ActionController::TestCase
post_update
assert_redirected_to tournament_path(@school.tournament_id)
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
sign_in_owner
@@ -86,6 +102,14 @@ class SchoolsControllerTest < ActionController::TestCase
create
assert_redirected_to tournament_path(@school.tournament_id)
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
sign_in_non_owner
@@ -100,6 +124,12 @@ class SchoolsControllerTest < ActionController::TestCase
destroy
assert_redirected_to tournament_path(@tournament.id)
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
sign_in_non_owner

View File

@@ -25,6 +25,10 @@ include Devise::TestHelpers
def sign_in_non_owner
sign_in users(:two)
end
def sign_in_delegate
sign_in users(:three)
end
def success
assert_response :success
@@ -169,5 +173,53 @@ include Devise::TestHelpers
get :bracket, id: 1, weight: 1
no_matches
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

View File

@@ -36,6 +36,10 @@ class WeightsControllerTest < ActionController::TestCase
def sign_in_non_owner
sign_in users(:two)
end
def sign_in_tournament_delegate
sign_in users(:three)
end
def success
assert_response :success
@@ -50,6 +54,12 @@ class WeightsControllerTest < ActionController::TestCase
get_edit
success
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
sign_in_non_owner
@@ -78,6 +88,12 @@ class WeightsControllerTest < ActionController::TestCase
post_update
assert_redirected_to tournament_path(@weight.tournament_id)
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
sign_in_owner
@@ -86,6 +102,14 @@ class WeightsControllerTest < ActionController::TestCase
create
assert_redirected_to tournament_path(@weight.tournament_id)
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
sign_in_non_owner
@@ -100,6 +124,12 @@ class WeightsControllerTest < ActionController::TestCase
destroy
assert_redirected_to tournament_path(@tournament.id)
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
sign_in_non_owner

View File

@@ -37,6 +37,10 @@ class WrestlersControllerTest < ActionController::TestCase
def sign_in_non_owner
sign_in users(:two)
end
def sign_in_tournament_delegate
sign_in users(:three)
end
def success
assert_response :success
@@ -51,6 +55,12 @@ class WrestlersControllerTest < ActionController::TestCase
get_edit
success
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
sign_in_non_owner
@@ -79,6 +89,12 @@ class WrestlersControllerTest < ActionController::TestCase
post_update
assert_redirected_to school_path(@school.id)
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
sign_in_owner
@@ -87,6 +103,14 @@ class WrestlersControllerTest < ActionController::TestCase
create
assert_redirected_to school_path(@school.id)
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
sign_in_non_owner
@@ -101,6 +125,12 @@ class WrestlersControllerTest < ActionController::TestCase
destroy
assert_redirected_to school_path(@school.id)
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
sign_in_non_owner

9
test/fixtures/school_delegates.yml vendored Normal file
View 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
View 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

View File

@@ -15,3 +15,7 @@ one:
two:
email: test2@test.com
id: 2
three:
email: test3@test.com
id: 3

View File

@@ -0,0 +1,7 @@
require 'test_helper'
class SchoolDelegateTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

View File

@@ -0,0 +1,7 @@
require 'test_helper'
class TournamentDelegateTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end