Remove connected user transformation from TwitteredMarkdown

This commit is contained in:
Andreas Nedbal 2023-02-05 21:13:37 +01:00 committed by Andreas Nedbal
parent d43e27bcd2
commit 024127e62f
2 changed files with 4 additions and 38 deletions

View File

@ -7,17 +7,7 @@ class TwitteredMarkdown < Redcarpet::Render::StripDown
def wrap_mentions(text)
text.gsub(/(^|\s)@([a-zA-Z0-9_]{1,16})/) do
local_user = User.find_by(screen_name: $2)
if local_user.nil?
"#{$1}#{$2}"
else
service = local_user.services.where(type: "Services::Twitter").first
if service.nil?
"#{$1}#{$2}"
else
"#{$1}@#{service.nickname}"
end
end
"#{$1}#{$2}"
end
end
end

View File

@ -40,24 +40,8 @@ describe MarkdownHelper, type: :helper do
end
describe "#twitter_markdown" do
context "mentioned user has Twitter connected" do
let(:user) { FactoryBot.create(:user) }
let(:service) { Services::Twitter.create(user: user) }
before do
service.nickname = "test"
service.save!
end
it "should transform a internal mention to a Twitter mention" do
expect(twitter_markdown("@#{user.screen_name}")).to eq("@test")
end
end
context "mentioned user doesnt have Twitter connected" do
it "should not transform the mention" do
expect(twitter_markdown("@test")).to eq("test")
end
it "should not transform the mention" do
expect(twitter_markdown("@test")).to eq("test")
end
it "should not strip weird hearts" do
@ -118,17 +102,9 @@ describe MarkdownHelper, type: :helper do
describe "#twitter_markdown_io" do
let(:user) { FactoryBot.create(:user) }
let(:service) { Services::Twitter.create(user: user) }
before do
user.screen_name = "test"
user.save!
service.nickname = "ObamaGaming"
service.save!
end
it "should return the expected text" do
expect(twitter_markdown_io("spec/fixtures/markdown/twitter.md")).to eq("@ObamaGaming")
expect(twitter_markdown_io("spec/fixtures/markdown/twitter.md")).to eq("test")
end
end