Move app/labor/reaction_image.rb to helper (#11678)

This commit is contained in:
Michael Kohl 2020-12-01 14:15:30 +07:00 committed by GitHub
parent 5185de4c91
commit 2939813168
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 24 additions and 29 deletions

View file

@ -0,0 +1,15 @@
module NotificationsHelper
REACTION_IMAGES = {
"like" => "heart-filled.svg",
"unicorn" => "unicorn-filled.svg",
"hands" => "emoji/emoji-one-hands.png",
"thinking" => "emoji/emoji-one-thinking.png",
"readinglist" => "save-filled.svg",
"thumbsdown" => "emoji/emoji-one-thumbs-down.png",
"vomit" => "emoji/emoji-one-nausea-face.png"
}.freeze
def reaction_image(category)
REACTION_IMAGES[category]
end
end

View file

@ -1,20 +0,0 @@
class ReactionImage
attr_accessor :category
def initialize(category)
@category = category
end
def path
images = {
"like" => "heart-filled.svg",
"unicorn" => "unicorn-filled.svg",
"hands" => "emoji/emoji-one-hands.png",
"thinking" => "emoji/emoji-one-thinking.png",
"readinglist" => "save-filled.svg",
"thumbsdown" => "emoji/emoji-one-thumbs-down.png",
"vomit" => "emoji/emoji-one-nausea-face.png"
}.freeze
images[category]
end
end

View file

@ -37,7 +37,7 @@
<% reaction_categories = siblings.map { |n| n["category"] } %>
<% reaction_categories.each do |cat| %>
<% image_path = ReactionImage.new(cat).path %>
<% image_path = reaction_image(cat) %>
<% if image_path.present? %>
<%= inline_svg_tag(image_path, aria: true, class: "crayons-icon reaction-image mx-1 my-1 reaction-icon--#{cat}", title: cat.to_s.humanize) %>
<% end %>

View file

@ -12,7 +12,7 @@
with
<span>
<% category = notification.json_data["reaction"]["category"] %>
<%= inline_svg_tag(ReactionImage.new(category).path, class: "crayons-icon reaction-image mx-1 reaction-icon--#{category}", title: category.to_s.humanize) %>
<%= inline_svg_tag(reaction_image(category), class: "crayons-icon reaction-image mx-1 reaction-icon--#{category}", title: category.to_s.humanize) %>
</span>
</div>
</div>

View file

@ -0,0 +1,7 @@
require "rails_helper"
RSpec.describe NotificationsHelper, type: :helper do
it "returns a category image" do
expect(helper.reaction_image("unicorn")).to eq("unicorn-filled.svg")
end
end

View file

@ -1,7 +0,0 @@
require "rails_helper"
RSpec.describe ReactionImage, type: :labor do
it "returns a category image" do
expect(described_class.new("unicorn").path).to eq("unicorn-filled.svg")
end
end