diff --git a/app/components/shared/banner_component.html.erb b/app/components/shared/banner_component.html.erb index cbea18d0e..fe020302a 100644 --- a/app/components/shared/banner_component.html.erb +++ b/app/components/shared/banner_component.html.erb @@ -1,3 +1,5 @@ -
+<% if banner %> + +<% end %> diff --git a/app/helpers/banners_helper.rb b/app/helpers/banners_helper.rb deleted file mode 100644 index 973f353af..000000000 --- a/app/helpers/banners_helper.rb +++ /dev/null @@ -1,5 +0,0 @@ -module BannersHelper - def has_banners? - @banners.present? && @banners.count > 0 - end -end diff --git a/app/views/shared/_banner.html.erb b/app/views/shared/_banner.html.erb index 358b6e2f3..c98b1185d 100644 --- a/app/views/shared/_banner.html.erb +++ b/app/views/shared/_banner.html.erb @@ -1,5 +1,3 @@ -<% if has_banners? || controller.class == Admin::BannersController %> - <% banner ||= @banners.sample %> +<% banner ||= @banners&.sample %> - <%= render Shared::BannerComponent.new(banner) %> -<% end %> +<%= render Shared::BannerComponent.new(banner) %> diff --git a/spec/components/shared/banner_component_spec.rb b/spec/components/shared/banner_component_spec.rb new file mode 100644 index 000000000..77168e63a --- /dev/null +++ b/spec/components/shared/banner_component_spec.rb @@ -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