mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 10:20:58 -06:00
1fb97f8bba
Previously, all handles and hashtags were replaced in one go which could result in a wrong result if a handle was a substring of another one.
22 lines
738 B
Ruby
22 lines
738 B
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
describe TwitterApi do
|
|
context '.link_handles_in' do
|
|
it 'correctly replaces handles' do
|
|
expect(TwitterApi.send(:link_handles_in, "@foo @foobar")).to match_html <<~HTML
|
|
<a href='https://twitter.com/foo' target='_blank'>@foo</a> <a href='https://twitter.com/foobar' target='_blank'>@foobar</a>
|
|
HTML
|
|
end
|
|
end
|
|
|
|
context '.link_hashtags_in' do
|
|
it 'correctly replaces hashtags' do
|
|
expect(TwitterApi.send(:link_hashtags_in, "#foo #foobar")).to match_html <<~HTML
|
|
<a href='https://twitter.com/search?q=%23foo' target='_blank'>#foo</a> <a href='https://twitter.com/search?q=%23foobar' target='_blank'>#foobar</a>
|
|
HTML
|
|
end
|
|
end
|
|
end
|