Simplify conditions to render a banner
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
<div class="banner" style="background-color:<%= banner.background_color %>;">
|
<% if banner %>
|
||||||
<%= sanitize link, attributes: %w[href style] %>
|
<div class="banner" style="background-color:<%= banner.background_color %>;">
|
||||||
</div>
|
<%= sanitize link, attributes: %w[href style] %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
module BannersHelper
|
|
||||||
def has_banners?
|
|
||||||
@banners.present? && @banners.count > 0
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -1,5 +1,3 @@
|
|||||||
<% if has_banners? || controller.class == Admin::BannersController %>
|
<% banner ||= @banners&.sample %>
|
||||||
<% banner ||= @banners.sample %>
|
|
||||||
|
|
||||||
<%= render Shared::BannerComponent.new(banner) %>
|
<%= render Shared::BannerComponent.new(banner) %>
|
||||||
<% end %>
|
|
||||||
|
|||||||
15
spec/components/shared/banner_component_spec.rb
Normal file
15
spec/components/shared/banner_component_spec.rb
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
require "rails_helper"
|
||||||
|
|
||||||
|
describe Shared::BannerComponent, type: :component do
|
||||||
|
it "renders given a banner" do
|
||||||
|
render_inline Shared::BannerComponent.new(create(:banner, title: "Vote now!"))
|
||||||
|
|
||||||
|
expect(page.find(".banner")).to have_content "Vote now!"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "does not render anything given nil" do
|
||||||
|
render_inline Shared::BannerComponent.new(nil)
|
||||||
|
|
||||||
|
expect(page).not_to have_css ".banner"
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user