From 923a5970772dcbd0a34ef3f9ea7282ce4bdd4a72 Mon Sep 17 00:00:00 2001 From: kennethrioja <59597207+kennethrioja@users.noreply.github.com> Date: Wed, 22 Jul 2026 16:41:44 +0200 Subject: [PATCH] feat(featured_trainer): choose how many trainers to feature --- app/controllers/static_controller.rb | 2 +- config/tess.example.yml | 2 +- test/controllers/static_controller_test.rb | 13 +++++++++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/controllers/static_controller.rb b/app/controllers/static_controller.rb index e5b3e5538..0c9f3f471 100644 --- a/app/controllers/static_controller.rb +++ b/app/controllers/static_controller.rb @@ -38,7 +38,7 @@ def set_featured_trainer trainers = Trainer.joins(:user).order(:id) f_trainers = trainers.where.not(users: { image_file_size: nil }) trainers = f_trainers.exists? ? f_trainers : trainers - trainers.sample(1) + trainers.sample(TeSS::Config.site.dig('home_page', 'featured_trainer')) end def set_content_providers diff --git a/config/tess.example.yml b/config/tess.example.yml index 70560649e..c8a51db5e 100644 --- a/config/tess.example.yml +++ b/config/tess.example.yml @@ -109,7 +109,7 @@ default: &default promo_blocks: false upcoming_events: # Number of events on home page. Leave blank to turn off latest_materials: # Number of materials on home page. Leave blank to turn off - featured_trainer: false + featured_trainer: # Number of trainers to feature on home page. Leave blank to turn off counters: false # Whether or not to show number of database objects in separate blocks search_box: true # Whether or not to show the search box additional_links: # Add custom links in separate blocks diff --git a/test/controllers/static_controller_test.rb b/test/controllers/static_controller_test.rb index 8e57815c1..ba9315646 100644 --- a/test/controllers/static_controller_test.rb +++ b/test/controllers/static_controller_test.rb @@ -312,11 +312,20 @@ class StaticControllerTest < ActionController::TestCase end test 'should show featured trainer' do - with_settings({ site: { home_page: { featured_trainer: true } } }) do + with_settings({ site: { home_page: { featured_trainer: 2 } } }) do get :home assert_select 'section#featured_trainer', count: 1 assert_select 'section#featured_trainer h2', count: 1 - assert_select 'section#featured_trainer li', count: 1 + assert_select 'section#featured_trainer li', count: 2 + end + end + + test 'should not show featured trainer' do + with_settings({ site: { home_page: { featured_trainer: nil } } }) do + get :home + assert_select 'section#featured_trainer', count: 0 + assert_select 'section#featured_trainer h2', count: 0 + assert_select 'section#featured_trainer li', count: 0 end end