fix frozen string bug, add bsky username prefix to searched names

This commit is contained in:
Dylan Knutson
2025-08-17 19:08:44 +00:00
parent 15ea73a350
commit a8f258d5ef
3 changed files with 28 additions and 17 deletions

View File

@@ -539,7 +539,7 @@ module Domain::PostsHelper
return nil if source.blank?
# normalize the source to a lowercase string with a protocol
source.downcase!
source = source.downcase
source = "https://" + source unless source.include?("://")
begin
uri = URI.parse(source)

View File

@@ -65,7 +65,12 @@ class Domain::User::BlueskyUser < Domain::User
sig { override.returns(T::Array[String]) }
def names_for_search
[display_name, handle].compact
names = [display_name, handle]
if (h = handle)&.ends_with?(".bsky.social")
names << h.split(".").first
end
names << did
names.compact
end
sig { override.returns(T.nilable(String)) }

View File

@@ -19,6 +19,22 @@ RSpec.describe Domain::BlueskyPostHelper, type: :helper do
"Hello @alice.bsky.social! Check out https://bsky.app/profile/bob.bsky.social/post/abc123 and #hashtag"
end
# Shared test data used across multiple contexts
let(:linked_user) do
create(
:domain_user_bluesky_user,
handle: "bob.bsky.social",
did: "did:plc:bob123",
)
end
let(:linked_post) do
create(
:domain_post_bluesky_post,
rkey: "abc123",
at_uri: "at://did:plc:bob123/app.bsky.feed.post/abc123",
)
end
context "when facets is nil" do
it "returns the original text unchanged" do
result =
@@ -241,13 +257,6 @@ RSpec.describe Domain::BlueskyPostHelper, type: :helper do
end
context "with link facets" do
let(:linked_post) do
create(
:domain_post_bluesky_post,
rkey: "abc123",
at_uri: "at://did:plc:bob123/app.bsky.feed.post/abc123",
)
end
let(:text) do
"Check out https://bsky.app/profile/bob.bsky.social/post/abc123"
end
@@ -270,7 +279,10 @@ RSpec.describe Domain::BlueskyPostHelper, type: :helper do
end
context "when linked post exists in database" do
before { linked_post } # Ensure post exists
before do
linked_user # Ensure user exists
linked_post # Ensure post exists
end
it "renders inline_link_domain_post partial" do
expect(helper).to receive(:render).with(
@@ -378,13 +390,6 @@ RSpec.describe Domain::BlueskyPostHelper, type: :helper do
did: "did:plc:alice123",
)
end
let(:linked_post) do
create(
:domain_post_bluesky_post,
rkey: "abc123",
at_uri: "at://did:plc:bob123/app.bsky.feed.post/abc123",
)
end
let(:text) do
"Hey @alice.bsky.social, check https://bsky.app/profile/bob.bsky.social/post/abc123 #cool"
end
@@ -431,6 +436,7 @@ RSpec.describe Domain::BlueskyPostHelper, type: :helper do
before do
mentioned_user
linked_user
linked_post
end