show keywords on ib posts

This commit is contained in:
Dylan Knutson
2025-06-27 22:51:17 +00:00
parent 3b6ff33ec7
commit b3c33958e6
4 changed files with 79 additions and 3 deletions

View File

@@ -473,6 +473,11 @@ module Domain::PostsHelper
post.keywords.map(&:strip).reject(&:blank?).compact
end
sig { params(post: Domain::Post::InkbunnyPost).returns(T::Array[String]) }
def keywords_for_ib_post(post)
post.keywords.map { |keyword| keyword["keyword_name"] }.compact
end
sig { params(time: T.nilable(ActiveSupport::TimeWithZone)).returns(String) }
def time_ago_in_words_no_prefix(time)
return "never" if time.nil?

View File

@@ -0,0 +1,20 @@
<%= sky_section_tag("Keywords") do %>
<% keywords = keywords_for_ib_post(post) %>
<% if keywords.any? %>
<div class="flex flex-wrap gap-2">
<% keywords.each do |keyword| %>
<span
class="<%= tailwind_tag_category_class(:general) %> rounded px-2 py-1 text-sm text-slate-600"
>
<% icon = font_awesome_category_icon(:general) %>
<% if icon %>
<i class="fa-solid <%= icon %> mr-1"></i>
<% end %>
<%= keyword %>
</span>
<% end %>
</div>
<% else %>
<div class="text-center italic text-slate-400">No keywords</div>
<% end %>
<% end%>

View File

@@ -2,6 +2,8 @@
require "rails_helper"
RSpec.describe Domain::PostsController, type: :controller do
render_views
# Create a real user with admin role
let(:user) { create(:user, :admin) }
@@ -12,9 +14,30 @@ RSpec.describe Domain::PostsController, type: :controller do
allow(controller).to receive(:authorize).and_return(true)
end
# ============================================================
# Test the controller's actual actions and their behavior
# ============================================================
describe "GET #show" do
shared_examples "a post" do
it "returns a successful response and renders the show template" do
get :show, params: { id: post.to_param }
expect(response).to be_successful
expect(response).to render_template(:show)
end
end
context "with a fa post" do
let(:post) { create(:domain_post_fa_post) }
it_behaves_like "a post"
end
context "with a ib post" do
let(:post) { create(:domain_post_inkbunny_post) }
it_behaves_like "a post"
end
context "with an e621 post" do
let(:post) { create(:domain_post_e621_post) }
it_behaves_like "a post"
end
end
describe "GET #visual_search" do
it "returns a successful response and renders the visual_search template" do

View File

@@ -4,5 +4,33 @@ FactoryBot.define do
sequence(:ib_id) { |n| 1 + n }
sequence(:title) { |n| "the_post_#{n}" }
association :creator, factory: :domain_user_inkbunny_user
keywords do
[
{
"keyword_id" => "5088",
"contributed" => "f",
"keyword_name" => "borzoi",
"submissions_count" => "410",
},
{
"keyword_id" => "303",
"contributed" => "f",
"keyword_name" => "canine",
"submissions_count" => "193033",
},
{
"keyword_id" => "3",
"contributed" => "f",
"keyword_name" => "dog",
"submissions_count" => "174009",
},
{
"keyword_id" => "443",
"contributed" => "f",
"keyword_name" => "duo",
"submissions_count" => "20734",
},
]
end
end
end