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

Hide ads on schools#show, wrestlers#new, wrestlers#edit, and mats#show

This commit is contained in:
2026-02-11 07:55:49 -05:00
parent fcc8a9b9a9
commit d57aaac09d
4 changed files with 74 additions and 8 deletions

View File

@@ -1,9 +1,15 @@
module ApplicationHelper
def hide_ads?
return false unless controller_name == "schools"
return false unless %w[show edit new].include?(action_name)
user_signed_in? || school_permission_key_present?
case controller_name
when "schools"
action_name == "show" && (user_signed_in? || school_permission_key_present?)
when "wrestlers"
%w[new edit].include?(action_name) && (user_signed_in? || school_permission_key_present?)
when "mats"
action_name == "show" && user_signed_in?
else
false
end
end
def school_permission_key_present?

View File

@@ -66,6 +66,15 @@ class MatsControllerTest < ActionController::TestCase
def redirect
assert_redirected_to '/static_pages/not_allowed'
end
def assert_ads_hidden
assert_no_match(/blocked_message/, response.body)
assert_no_match(/adsbygoogle/, response.body)
end
def assert_ads_visible
assert_match(/blocked_message/, response.body)
end
def no_matches
assert_redirected_to "/tournaments/#{@tournament.id}/no_matches"
@@ -221,6 +230,13 @@ class MatsControllerTest < ActionController::TestCase
success
end
test "ads are hidden on mat show" do
sign_in_owner
show
success
assert_ads_hidden
end
test "redirect to mat show when posting a match from mat show" do
sign_in_owner
post_match_update_from_mat_show

View File

@@ -408,21 +408,21 @@ Some Guy
success
end
test "ads are hidden for logged in user on school show" do
test "ads are hidden on school show when logged in" do
sign_in_owner
get_show
success
assert_ads_hidden
end
test "ads are hidden for school permission key on edit" do
test "ads are hidden on school show with school permission key" do
@tournament.update(is_public: false)
get_edit(school_permission_key: @school_permission_key)
get_show(school_permission_key: @school_permission_key)
success
assert_ads_hidden
end
test "ads are visible for anonymous user without school permission key on show" do
test "ads are visible on school show for anonymous user without key" do
@tournament.update(is_public: true)
get_show
success

View File

@@ -56,6 +56,15 @@ class WrestlersControllerTest < ActionController::TestCase
assert_redirected_to '/static_pages/not_allowed'
end
def assert_ads_hidden
assert_no_match(/blocked_message/, response.body)
assert_no_match(/adsbygoogle/, response.body)
end
def assert_ads_visible
assert_match(/blocked_message/, response.body)
end
test "logged in tournament owner should get edit wrestler page" do
sign_in_owner
get_edit
@@ -305,4 +314,39 @@ class WrestlersControllerTest < ActionController::TestCase
assert_select "a[href=?]", school_path(@school), text: /Back to/
end
test "ads are hidden on wrestler new" do
sign_in_owner
new
success
assert_ads_hidden
end
test "ads are hidden on wrestler edit" do
sign_in_owner
get_edit
success
assert_ads_hidden
end
test "ads are hidden on wrestler new with school permission key" do
valid_key = @school.permission_key
get :new, params: { school: @school.id, school_permission_key: valid_key }
success
assert_ads_hidden
end
test "ads are hidden on wrestler edit with school permission key" do
valid_key = @school.permission_key
get :edit, params: { id: @wrestler.id, school_permission_key: valid_key }
success
assert_ads_hidden
end
test "ads are visible on wrestler show" do
sign_in_owner
get :show, params: { id: @wrestler.id }
success
assert_ads_visible
end
end