diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index b35e977..0c00b1d 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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? diff --git a/test/controllers/mats_controller_test.rb b/test/controllers/mats_controller_test.rb index 875be1d..2a6e8e5 100644 --- a/test/controllers/mats_controller_test.rb +++ b/test/controllers/mats_controller_test.rb @@ -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 diff --git a/test/controllers/schools_controller_test.rb b/test/controllers/schools_controller_test.rb index 3b220b6..586237d 100644 --- a/test/controllers/schools_controller_test.rb +++ b/test/controllers/schools_controller_test.rb @@ -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 diff --git a/test/controllers/wrestlers_controller_test.rb b/test/controllers/wrestlers_controller_test.rb index 2274a1c..7628cc1 100644 --- a/test/controllers/wrestlers_controller_test.rb +++ b/test/controllers/wrestlers_controller_test.rb @@ -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