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

Fixed redirect for match editing and added controller tests. Added wrestler school name to match edit form. Added authorization tests to all matches page.

This commit is contained in:
2019-01-23 19:22:55 +00:00
parent bb8ec92bf0
commit b001445090
9 changed files with 52 additions and 21 deletions

View File

@@ -12,6 +12,11 @@ class MatchesControllerTest < ActionController::TestCase
def post_update
patch :update, params: { id: @match.id, match: {tournament_id: 1, mat_id: 1} }
end
def post_update_from_match_edit
get :edit, params: { id: @match.id }
patch :update, params: { id: @match.id, match: {tournament_id: 1, mat_id: 1} }
end
def get_edit
get :edit, params: { id: @match.id }
@@ -94,7 +99,12 @@ class MatchesControllerTest < ActionController::TestCase
test "logged in tournament delegate should post update match" do
sign_in_tournament_delegate
post_update
assert_redirected_to mat_path(1)
assert_redirected_to tournament_path(@tournament.id)
end
test "should redirect to all matches when posting a match update from match edit" do
sign_in_owner
post_update_from_match_edit
assert_redirected_to "/tournaments/#{@tournament.id}/matches"
end
end

View File

@@ -4,9 +4,10 @@ class MatsControllerTest < ActionController::TestCase
include Devise::Test::ControllerHelpers
setup do
@tournament = Tournament.find(1)
@tournament = Tournament.find(1)
# @tournament.generateMatchups
@mat = mats(:one)
@match = Match.where("tournament_id = ? and mat_id = ?",1,1).first
@mat = mats(:one)
end
def create
@@ -65,6 +66,14 @@ class MatsControllerTest < ActionController::TestCase
@tournament.destroy_all_matches
end
def post_match_update_from_mat_show
get :show, params: { id: @mat.id }
old_controller = @controller
@controller = MatchesController.new
patch :update, params: { id: @match.id, match: {tournament_id: 1, mat_id: @mat.id} }
@controller = old_controller
end
test "logged in tournament owner should get edit mat page" do
sign_in_owner
get_edit
@@ -203,7 +212,11 @@ class MatsControllerTest < ActionController::TestCase
success
end
test "redirect to mat show when posting a match from mat show" do
sign_in_owner
post_match_update_from_mat_show
assert_redirected_to "/mats/#{@mat.id}"
end
#TESTS THAT NEED MATCHES PUT ABOVE THIS
test "redirect show if no matches" do
sign_in_owner

View File

@@ -362,5 +362,15 @@ class TournamentsControllerTest < ActionController::TestCase
redirect
end
test 'logged in non owner should not get all matches page' do
sign_in_non_owner
get :matches, params: { id: 1 }
redirect
end
test 'logged in owner should get all matches page' do
sign_in_owner
get :matches, params: { id: 1 }
success
end
end