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.
This commit is contained in:
Javi Martín
2025-10-31 14:49:03 +01:00
parent 90b1f06a7c
commit 251968ae72
2 changed files with 32 additions and 1 deletions

View File

@@ -6,7 +6,7 @@ class Debates::MarkFeaturedActionComponent < ApplicationComponent
@debate = debate
end
def render
def render?
can? :mark_featured, debate
end
end

View File

@@ -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