about summary refs log tree commit diff
path: root/spec/lib
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2021-09-26 05:46:13 +0200
committerGitHub <noreply@github.com>2021-09-26 05:46:13 +0200
commit52e5c07948c4c91b73062846e1f19ea278ec0e24 (patch)
treeb46b76f919f51ad5a5ac288be2ad2565fa859496 /spec/lib
parent9c9290768190d412e5b3d65502ee5d0d30596412 (diff)
Change routing paths to use usernames in web UI (#16171)
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/permalink_redirector_spec.rb42
1 files changed, 42 insertions, 0 deletions
diff --git a/spec/lib/permalink_redirector_spec.rb b/spec/lib/permalink_redirector_spec.rb
new file mode 100644
index 000000000..b916b33b2
--- /dev/null
+++ b/spec/lib/permalink_redirector_spec.rb
@@ -0,0 +1,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