From 251968ae72a9efe8e1fb3bf576560577b267cfc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 31 Oct 2025 14:49:03 +0100 Subject: [PATCH] Fix mark as featured button being rendered to everyone We introduced this issue in commit f8faabf7d. Since this component didn't have any tests (there are system tests for it, though), we're also adding tests that check that only the right buttons are rendered when accessing as administrator. --- .../debates/mark_featured_action_component.rb | 2 +- .../mark_featured_action_component_spec.rb | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 spec/components/debates/mark_featured_action_component_spec.rb diff --git a/app/components/debates/mark_featured_action_component.rb b/app/components/debates/mark_featured_action_component.rb index 38e5e59da..a742a70d9 100644 --- a/app/components/debates/mark_featured_action_component.rb +++ b/app/components/debates/mark_featured_action_component.rb @@ -6,7 +6,7 @@ class Debates::MarkFeaturedActionComponent < ApplicationComponent @debate = debate end - def render + def render? can? :mark_featured, debate end end diff --git a/spec/components/debates/mark_featured_action_component_spec.rb b/spec/components/debates/mark_featured_action_component_spec.rb new file mode 100644 index 000000000..95505f9fa --- /dev/null +++ b/spec/components/debates/mark_featured_action_component_spec.rb @@ -0,0 +1,31 @@ +require "rails_helper" + +describe Debates::MarkFeaturedActionComponent do + let(:debate) { create(:debate) } + + it "is not rendered for regular users" do + sign_in(create(:user, :verified)) + + render_inline Debates::MarkFeaturedActionComponent.new(debate) + + expect(page).not_to be_rendered + end + + context "administradors", :admin do + it "renders a button to mark debates as featured" do + render_inline Debates::MarkFeaturedActionComponent.new(debate) + + expect(page).to have_button "Featured" + expect(page).to have_button count: 1 + end + + it "renders a button to unmark featured debates" do + debate = create(:debate, featured_at: Time.current) + + render_inline Debates::MarkFeaturedActionComponent.new(debate) + + expect(page).to have_button "Unmark featured" + expect(page).to have_button count: 1 + end + end +end