-<% @redirect_path = request.original_fullpath %>
<% if @match %>
<%= render 'matches/form' %>
<% else %>
diff --git a/test/controllers/matches_controller_test.rb b/test/controllers/matches_controller_test.rb
index e17cf75..2c5c2d3 100644
--- a/test/controllers/matches_controller_test.rb
+++ b/test/controllers/matches_controller_test.rb
@@ -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
diff --git a/test/controllers/mats_controller_test.rb b/test/controllers/mats_controller_test.rb
index e415a9e..934e787 100644
--- a/test/controllers/mats_controller_test.rb
+++ b/test/controllers/mats_controller_test.rb
@@ -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
diff --git a/test/controllers/tournaments_controller_test.rb b/test/controllers/tournaments_controller_test.rb
index da0c695..371baab 100644
--- a/test/controllers/tournaments_controller_test.rb
+++ b/test/controllers/tournaments_controller_test.rb
@@ -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