about summary refs log tree commit diff
path: root/spec/lib/permalink_redirector_spec.rb
blob: b916b33b22c60bee695c02ae43f33a3e8f120bef (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# frozen_string_literal: true

require 'rails_helper'

describe PermalinkRedirector do
  describe '#redirect_url' do
    before do
      account = Fabricate(:account, username: 'alice', id: 1)
      Fabricate(:status, account: account, id: 123)
    end

    it 'returns path for legacy account links' do
      redirector = described_class.new('web/accounts/1')
      expect(redirector.redirect_path).to eq 'https://cb6e6126.ngrok.io/@alice'
    end

    it 'returns path for legacy status links' do
      redirector = described_class.new('web/statuses/123')
      expect(redirector.redirect_path).to eq 'https://cb6e6126.ngrok.io/@alice/123'
    end

    it 'returns path for legacy tag links' do
      redirector = described_class.new('web/timelines/tag/hoge')
      expect(redirector.redirect_path).to eq '/tags/hoge'
    end

    it 'returns path for pretty account links' do
      redirector = described_class.new('web/@alice')
      expect(redirector.redirect_path).to eq 'https://cb6e6126.ngrok.io/@alice'
    end

    it 'returns path for pretty status links' do
      redirector = described_class.new('web/@alice/123')
      expect(redirector.redirect_path).to eq 'https://cb6e6126.ngrok.io/@alice/123'
    end

    it 'returns path for pretty tag links' do
      redirector = described_class.new('web/tags/hoge')
      expect(redirector.redirect_path).to eq '/tags/hoge'
    end
  end
end