From d08f1112d517788fb66d2683766cc168bac48315 Mon Sep 17 00:00:00 2001 From: masarakki Date: Sat, 6 May 2017 02:48:22 +0900 Subject: use Twitter::Extractor for creating links (#2502) --- spec/lib/formatter_spec.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'spec/lib/formatter_spec.rb') diff --git a/spec/lib/formatter_spec.rb b/spec/lib/formatter_spec.rb index b762907b2..81eaf00e8 100644 --- a/spec/lib/formatter_spec.rb +++ b/spec/lib/formatter_spec.rb @@ -6,6 +6,10 @@ RSpec.describe Formatter do let(:local_status) { Fabricate(:status, text: local_text, account: account) } let(:remote_status) { Fabricate(:status, text: ' Beep boop', uri: 'beepboop', account: account) } + let(:local_text_with_mention) { "@#{account.username} @#{account.username}@example.com #{local_text}?x=@#{account.username} #hashtag" } + let(:local_status_with_mention) { Fabricate(:status, text: local_text_with_mention, + account: account, mentions: [Fabricate(:mention, account: account)]) } + describe '#format' do subject { Formatter.instance.format(local_status) } @@ -21,6 +25,18 @@ RSpec.describe Formatter do expect(subject).to match('google.com/') end + it 'contains a mention' do + result = Formatter.instance.format(local_status_with_mention) + expect(result).to match "@#{account.username}" + expect(result).to match %r{href=\"http://google.com/\?x=@#{account.username}} + expect(result).not_to match "href=\"https://example.com/@#{account.username}" + end + + it 'contains a hashtag' do + result = Formatter.instance.format(local_status_with_mention) + expect(result).to match("/tags/hashtag\" class=\"mention hashtag\">#hashtag") + end + context 'matches a stand-alone medium URL' do let(:local_text) { 'https://hackernoon.com/the-power-to-build-communities-a-response-to-mark-zuckerberg-3f2cac9148a4' } it 'has valid url' do -- cgit