mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-04-09 23:44:52 +00:00
Added tests for matches controller
This commit is contained in:
@@ -25,7 +25,7 @@ class MatchesController < ApplicationController
|
|||||||
def update
|
def update
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
if @match.update(match_params)
|
if @match.update(match_params)
|
||||||
format.html { redirect_to root_path, notice: 'Match was successfully updated.' }
|
format.html { redirect_to tournament_path(@match.tournament_id), notice: 'Match was successfully updated.' }
|
||||||
format.json { head :no_content }
|
format.json { head :no_content }
|
||||||
else
|
else
|
||||||
format.html { render action: 'edit' }
|
format.html { render action: 'edit' }
|
||||||
@@ -48,7 +48,7 @@ class MatchesController < ApplicationController
|
|||||||
|
|
||||||
def check_access
|
def check_access
|
||||||
if current_user != @match.tournament.user
|
if current_user != @match.tournament.user
|
||||||
redirect_to root_path
|
redirect_to '/static_pages/not_allowed'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -116,6 +116,10 @@ class StaticPagesController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def not_allowed
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def check_access
|
def check_access
|
||||||
if params[:tournament]
|
if params[:tournament]
|
||||||
|
|||||||
1
app/views/static_pages/not_allowed.html.erb
Normal file
1
app/views/static_pages/not_allowed.html.erb
Normal file
@@ -0,0 +1 @@
|
|||||||
|
You do not have permissions to go there.
|
||||||
@@ -36,7 +36,7 @@ Wrestling::Application.routes.draw do
|
|||||||
get 'static_pages/generate_matches'
|
get 'static_pages/generate_matches'
|
||||||
get 'static_pages/weigh_in'
|
get 'static_pages/weigh_in'
|
||||||
post 'static_pages/weigh_in'
|
post 'static_pages/weigh_in'
|
||||||
|
get 'static_pages/not_allowed'
|
||||||
|
|
||||||
# Example of regular route:
|
# Example of regular route:
|
||||||
# get 'products/:id' => 'catalog#view'
|
# get 'products/:id' => 'catalog#view'
|
||||||
|
|||||||
@@ -1,11 +1,75 @@
|
|||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class MatchesControllerTest < ActionController::TestCase
|
class MatchesControllerTest < ActionController::TestCase
|
||||||
# setup do
|
include Devise::TestHelpers
|
||||||
# @match = matches(:one)
|
|
||||||
# end
|
|
||||||
|
|
||||||
test "the truth" do
|
setup do
|
||||||
|
@tournament = Tournament.find(1)
|
||||||
|
@tournament.generateMatchups
|
||||||
|
@match = @tournament.matches.first
|
||||||
|
end
|
||||||
|
|
||||||
|
def post_update
|
||||||
|
patch :update, id: @match.id, match: {w1: @match.w1, w2: @match.w2}
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_edit
|
||||||
|
get :edit, id: @match.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_response :redirect
|
||||||
|
end
|
||||||
|
|
||||||
|
test "the truth" do
|
||||||
assert true
|
assert true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "logged in tournament owner should get edit match page" do
|
||||||
|
sign_in_owner
|
||||||
|
get_edit
|
||||||
|
success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "logged in user should not get edit match page if not owner" do
|
||||||
|
sign_in_non_owner
|
||||||
|
get_edit
|
||||||
|
redirect
|
||||||
|
end
|
||||||
|
|
||||||
|
test "non logged in user should not get edit match page" do
|
||||||
|
get_edit
|
||||||
|
redirect
|
||||||
|
end
|
||||||
|
|
||||||
|
test "non logged in user should get post update match" do
|
||||||
|
post_update
|
||||||
|
assert_redirected_to '/static_pages/not_allowed'
|
||||||
|
end
|
||||||
|
|
||||||
|
test "logged in user should not post update match if not owner" do
|
||||||
|
sign_in_non_owner
|
||||||
|
post_update
|
||||||
|
assert_redirected_to '/static_pages/not_allowed'
|
||||||
|
end
|
||||||
|
|
||||||
|
test "logged in tournament owner should post update match" do
|
||||||
|
sign_in_owner
|
||||||
|
post_update
|
||||||
|
assert_redirected_to tournament_path(@match.tournament_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
2
test/fixtures/tournaments.yml
vendored
2
test/fixtures/tournaments.yml
vendored
@@ -7,6 +7,6 @@ one:
|
|||||||
director: Jacob Cody Wimer
|
director: Jacob Cody Wimer
|
||||||
director_email: jacob.wimer@gmail.com
|
director_email: jacob.wimer@gmail.com
|
||||||
tournament_type: Pool to bracket
|
tournament_type: Pool to bracket
|
||||||
|
user_id: 1
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
6
test/fixtures/users.yml
vendored
6
test/fixtures/users.yml
vendored
@@ -9,3 +9,9 @@
|
|||||||
# #
|
# #
|
||||||
# two: {}
|
# two: {}
|
||||||
# # column: value
|
# # column: value
|
||||||
|
one:
|
||||||
|
email: test@test.com
|
||||||
|
id: 1
|
||||||
|
two:
|
||||||
|
email: test2@test.com
|
||||||
|
id: 2
|
||||||
|
|||||||
Reference in New Issue
Block a user