From: Tom Hughes Date: Wed, 18 Dec 2024 16:45:42 +0000 (+0000) Subject: Drop unused ability to filter social sharing sites X-Git-Tag: live~362^2~3 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/dee02bccd3de5198f144bed24b658908eed0daa0 Drop unused ability to filter social sharing sites --- diff --git a/app/helpers/social_share_button_helper.rb b/app/helpers/social_share_button_helper.rb index 2980e2dda..0fdba2799 100644 --- a/app/helpers/social_share_button_helper.rb +++ b/app/helpers/social_share_button_helper.rb @@ -13,18 +13,10 @@ module SocialShareButtonHelper # Generates a set of social share buttons based on the specified options. def social_share_buttons(opts = {}) - sites = opts.fetch(:allow_sites, []) - valid_sites, invalid_sites = filter_allowed_sites(sites) - - # Log invalid sites - invalid_sites.each do |invalid_site| - Rails.logger.error("Invalid site or icon not configured: #{invalid_site}") - end - tag.div( :class => "social-share-button d-flex gap-1 align-items-end flex-wrap mb-3" ) do - valid_sites.map do |site| + SOCIAL_SHARE_CONFIG.map do |site, icon| link_options = { :rel => ["nofollow", opts[:rel]].compact, :class => "ssb-icon rounded-circle", @@ -33,7 +25,7 @@ module SocialShareButtonHelper } link_to generate_share_url(site, opts), link_options do - image_tag(icon_path(site), :alt => I18n.t("application.share.#{site}.alt"), :size => 28) + image_tag(icon, :alt => I18n.t("application.share.#{site}.alt"), :size => 28) end end.join.html_safe end @@ -41,20 +33,6 @@ module SocialShareButtonHelper private - def filter_allowed_sites(sites) - valid_sites = sites.empty? ? SOCIAL_SHARE_CONFIG.keys : sites.select { |site| valid_site?(site) } - invalid_sites = sites - valid_sites - [valid_sites, invalid_sites] - end - - def icon_path(site) - SOCIAL_SHARE_CONFIG[site.to_sym] || "" - end - - def valid_site?(site) - SOCIAL_SHARE_CONFIG.key?(site.to_sym) - end - def generate_share_url(site, params) site = site.to_sym case site diff --git a/test/helpers/social_share_button_helper_test.rb b/test/helpers/social_share_button_helper_test.rb index 970e15445..4903c3aed 100644 --- a/test/helpers/social_share_button_helper_test.rb +++ b/test/helpers/social_share_button_helper_test.rb @@ -5,7 +5,6 @@ class SocialShareButtonHelperTest < ActionView::TestCase def setup @options = { - :allow_sites => %w[x facebook linkedin], :title => "Test Title", :url => "https://example.com", :desc => "Test Description", @@ -13,24 +12,14 @@ class SocialShareButtonHelperTest < ActionView::TestCase } end - def test_social_share_buttons_with_valid_sites + def test_social_share_buttons result = social_share_buttons(@options) - assert_includes result, "x" + assert_includes result, "email" + assert_includes result, "bluesky" assert_includes result, "facebook" assert_includes result, "linkedin" - end - - def test_render_social_share_buttons_with_invalid_site - @options[:allow_sites] << "invalid_site" - result = social_share_buttons(@options) - assert_not_includes result, "invalid_site" - end - - def test_social_share_buttons_with_no_sites - @options[:allow_sites] = [] - result = social_share_buttons(@options) - SocialShareButtonHelper::SOCIAL_SHARE_CONFIG.each_key do |site| - assert_includes result, site.to_s # Convert symbol to string - end + assert_includes result, "mastodon" + assert_includes result, "telegram" + assert_includes result, "x" end end