Remove connected user transformation from TwitteredMarkdown
This commit is contained in:
parent
d43e27bcd2
commit
024127e62f
|
@ -7,17 +7,7 @@ class TwitteredMarkdown < Redcarpet::Render::StripDown
|
||||||
|
|
||||||
def wrap_mentions(text)
|
def wrap_mentions(text)
|
||||||
text.gsub(/(^|\s)@([a-zA-Z0-9_]{1,16})/) do
|
text.gsub(/(^|\s)@([a-zA-Z0-9_]{1,16})/) do
|
||||||
local_user = User.find_by(screen_name: $2)
|
"#{$1}#{$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
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -40,24 +40,8 @@ describe MarkdownHelper, type: :helper do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#twitter_markdown" do
|
describe "#twitter_markdown" do
|
||||||
context "mentioned user has Twitter connected" do
|
it "should not transform the mention" do
|
||||||
let(:user) { FactoryBot.create(:user) }
|
expect(twitter_markdown("@test")).to eq("test")
|
||||||
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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should not strip weird hearts" do
|
it "should not strip weird hearts" do
|
||||||
|
@ -118,17 +102,9 @@ describe MarkdownHelper, type: :helper do
|
||||||
|
|
||||||
describe "#twitter_markdown_io" do
|
describe "#twitter_markdown_io" do
|
||||||
let(:user) { FactoryBot.create(:user) }
|
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
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue