about summary refs log tree commit diff
path: root/spec/lib/permalink_redirector_spec.rb
blob: a0091365616f677dc83e1c58fa0cfce0e992afd2 (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
# frozen_string_literal: true

require 'rails_helper'

describe PermalinkRedirector do
  let(:remote_account) { Fabricate(:account, username: 'alice', domain: 'example.com', url: 'https://example.com/@alice', id: 2) }

  describe '#redirect_url' do
    before do
      Fabricate(:status, account: remote_account, id: 123, url: 'https://example.com/status-123')
    end

    it 'returns path for legacy account links' do
      redirector = described_class.new('accounts/2')
      expect(redirector.redirect_path).to eq 'https://example.com/@alice'
    end

    it 'returns path for legacy status links' do
      redirector = described_class.new('statuses/123')
      expect(redirector.redirect_path).to eq 'https://example.com/status-123'
    end

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

    it 'returns path for pretty status links' do
      redirector = described_class.new('@alice/123')
      expect(redirector.redirect_path).to eq 'https://example.com/status-123'
    end
  end
end