Add render method to notification item component
This commit is contained in:
@@ -1,12 +1,10 @@
|
||||
<% if user %>
|
||||
<li id="notifications">
|
||||
<%= link_to notifications_path, rel: "nofollow",
|
||||
title: text,
|
||||
class: "notifications #{notifications_class}" do %>
|
||||
<span class="show-for-sr">
|
||||
<%= t("layouts.header.notification_item.notifications") %>
|
||||
</span>
|
||||
<span class="show-for-small-only"><%= text %></span>
|
||||
<% end %>
|
||||
</li>
|
||||
<% end %>
|
||||
<li id="notifications">
|
||||
<%= link_to notifications_path, rel: "nofollow",
|
||||
title: text,
|
||||
class: "notifications #{notifications_class}" do %>
|
||||
<span class="show-for-sr">
|
||||
<%= t("layouts.header.notification_item.notifications") %>
|
||||
</span>
|
||||
<span class="show-for-small-only"><%= text %></span>
|
||||
<% end %>
|
||||
</li>
|
||||
|
||||
@@ -5,6 +5,10 @@ class Layout::NotificationItemComponent < ApplicationComponent
|
||||
@user = user
|
||||
end
|
||||
|
||||
def render?
|
||||
user.present?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def text
|
||||
|
||||
15
spec/components/layout/notification_item_component_spec.rb
Normal file
15
spec/components/layout/notification_item_component_spec.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe Layout::NotificationItemComponent do
|
||||
it "is not rendered for anonymous users" do
|
||||
render_inline Layout::NotificationItemComponent.new(nil)
|
||||
|
||||
expect(page).not_to be_rendered
|
||||
end
|
||||
|
||||
it "is rendered for identified users" do
|
||||
render_inline Layout::NotificationItemComponent.new(create(:user))
|
||||
|
||||
expect(page).to be_rendered
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user