about summary refs log tree commit diff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/home_controller_spec.rb6
-rw-r--r--spec/lib/permalink_redirector_spec.rb42
2 files changed, 46 insertions, 2 deletions
diff --git a/spec/controllers/home_controller_spec.rb b/spec/controllers/home_controller_spec.rb
index 941f1dd91..70c5c42c5 100644
--- a/spec/controllers/home_controller_spec.rb
+++ b/spec/controllers/home_controller_spec.rb
@@ -8,8 +8,10 @@ RSpec.describe HomeController, type: :controller do
 
     context 'when not signed in' do
       context 'when requested path is tag timeline' do
-        before { @request.path = '/web/timelines/tag/name' }
-        it { is_expected.to redirect_to '/tags/name' }
+        it 'redirects to the tag\'s permalink' do
+          @request.path = '/web/timelines/tag/name'
+          is_expected.to redirect_to '/tags/name'
+        end
       end
 
       it 'redirects to about page' do
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