mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-03-25 01:14:43 +00:00
All protected routes are tested
This commit is contained in:
@@ -123,7 +123,10 @@ class StaticPagesController < ApplicationController
|
|||||||
private
|
private
|
||||||
def check_access
|
def check_access
|
||||||
if params[:tournament]
|
if params[:tournament]
|
||||||
@tournament = params[:tournament]
|
@tournament = Tournament.find(params[:tournament])
|
||||||
|
if current_user != @tournament.user
|
||||||
|
redirect_to '/static_pages/not_allowed'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,7 +1,68 @@
|
|||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class StaticPagesControllerTest < ActionController::TestCase
|
class StaticPagesControllerTest < ActionController::TestCase
|
||||||
test "the truth" do
|
include Devise::TestHelpers
|
||||||
assert true
|
|
||||||
end
|
setup do
|
||||||
|
@tournament = Tournament.find(1)
|
||||||
|
@tournament.generateMatchups
|
||||||
|
@school = @tournament.schools.first
|
||||||
|
end
|
||||||
|
|
||||||
|
def new
|
||||||
|
get :new, tournament: @tournament.id
|
||||||
|
end
|
||||||
|
|
||||||
|
def sign_in_owner
|
||||||
|
sign_in users(:one)
|
||||||
|
end
|
||||||
|
|
||||||
|
def sign_in_non_owner
|
||||||
|
sign_in users(:two)
|
||||||
|
end
|
||||||
|
|
||||||
|
def success
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
def redirect
|
||||||
|
assert_redirected_to '/static_pages/not_allowed'
|
||||||
|
end
|
||||||
|
|
||||||
|
test "logged in tournament owner can generate matches" do
|
||||||
|
sign_in_owner
|
||||||
|
get :generate_matches, tournament: 1
|
||||||
|
success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "logged in non tournament owner cannot generate matches" do
|
||||||
|
sign_in_non_owner
|
||||||
|
get :generate_matches, tournament: 1
|
||||||
|
redirect
|
||||||
|
end
|
||||||
|
|
||||||
|
test "logged in tournament owner can access weigh_ins" do
|
||||||
|
sign_in_owner
|
||||||
|
get :weigh_in, tournament: 1
|
||||||
|
success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "logged in non tournament owner cannot access weigh_ins" do
|
||||||
|
sign_in_non_owner
|
||||||
|
get :weigh_in, tournament: 1
|
||||||
|
redirect
|
||||||
|
end
|
||||||
|
|
||||||
|
test "logged in tournament owner can create custom weights" do
|
||||||
|
sign_in_owner
|
||||||
|
get :createCustomWeights, tournament: 1, customValue: 'hs'
|
||||||
|
assert_redirected_to '/tournaments/1'
|
||||||
|
end
|
||||||
|
|
||||||
|
test "logged in non tournament owner cannot create custom weights" do
|
||||||
|
sign_in_non_owner
|
||||||
|
get :createCustomWeights, tournament: 1, customValue: 'hs'
|
||||||
|
redirect
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user