]> cat aescling's git repositories - mastodon.git/blob - spec/lib/formatter_spec.rb
Merge branch 'fix_626' of https://github.com/rmhasan/mastodon into rmhasan-fix_626
[mastodon.git] / spec / lib / formatter_spec.rb
1 require 'rails_helper'
2
3 RSpec.describe Formatter do
4 let(:account) { Fabricate(:account, username: 'alice') }
5 let(:local_status) { Fabricate(:status, text: 'Hello world http://google.com', account: account) }
6 let(:remote_status) { Fabricate(:status, text: '<script>alert("Hello")</script> Beep boop', uri: 'beepboop', account: account) }
7
8 describe '#format' do
9 subject { Formatter.instance.format(local_status) }
10
11 it 'returns a string' do
12 expect(subject).to be_a String
13 end
14
15 it 'contains plain text' do
16 expect(subject).to match('Hello world')
17 end
18
19 it 'contains a link' do
20 expect(subject).to match('<a href="http://google.com" rel="nofollow noopener" target="_blank"><span class="invisible">http://</span><span class="">google.com</span><span class="invisible"></span></a>')
21 end
22
23 =begin
24 it 'matches a stand-alone medium URL' do
25 expect(subject.match('https://hackernoon.com/the-power-to-build-communities-a-response-to-mark-zuckerberg-3f2cac9148a4')[0]).to eq 'https://hackernoon.com/the-power-to-build-communities-a-response-to-mark-zuckerberg-3f2cac9148a4'
26 end
27
28 it 'matches a stand-alone google URL' do
29 expect(subject.match('http://google.com')[0]).to eq 'http://google.com'
30 end
31
32 it 'matches a URL without trailing period' do
33 expect(subject.match('http://www.mcmansionhell.com/post/156408871451/50-states-of-mcmansion-hell-scottsdale-arizona. ')[0]).to eq 'http://www.mcmansionhell.com/post/156408871451/50-states-of-mcmansion-hell-scottsdale-arizona'
34 end
35
36 it 'matches a URL without closing paranthesis' do
37 expect(subject.match('(http://google.com/)')[0]).to eq 'http://google.com'
38 end
39
40 it 'matches a URL without exclamation point' do
41 expect(subject.match('http://www.google.com! ')[0]).to eq 'http://www.google.com'
42 end
43
44 it 'matches a URL with a query string' do
45 expect(subject.match('https://www.ruby-toolbox.com/search?utf8=%E2%9C%93&q=autolink')[0]).to eq 'https://www.ruby-toolbox.com/search?utf8=%E2%9C%93&q=autolink'
46 end
47
48 it 'matches a URL with parenthesis in it' do
49 expect(subject.match('https://en.wikipedia.org/wiki/Diaspora_(software)')[0]).to eq 'https://en.wikipedia.org/wiki/Diaspora_(software)'
50 end
51 =end
52 end
53
54 describe '#reformat' do
55 subject { Formatter.instance.format(remote_status) }
56
57 it 'returns a string' do
58 expect(subject).to be_a String
59 end
60
61 it 'contains plain text' do
62 expect(subject).to match('Beep boop')
63 end
64
65 it 'does not contain scripts' do
66 expect(subject).to_not match('<script>alert("Hello")</script>')
67 end
68 end
69 end
This page took 0.187827 seconds and 4 git commands to generate.