about summary refs log tree commit diff
path: root/spec/lib
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2021-11-06 00:15:38 +0100
committerClaire <claire.github-309c@sitedethib.com>2021-11-06 00:15:38 +0100
commit4bb6b1a1e788abac7d1745e0f4eb72ad4d4ec110 (patch)
treea329d65c115e752c3be5c262ebf96f69cd13861a /spec/lib
parente0f39626973fd9f5cce2d4cd3b166fb47e9c9059 (diff)
parent6da135a493cc039d92bb5925c2a1ef66025623bf (diff)
Merge branch 'main' into glitch-soc/merge-upstream
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/link_details_extractor_spec.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/spec/lib/link_details_extractor_spec.rb b/spec/lib/link_details_extractor_spec.rb
new file mode 100644
index 000000000..850857b2d
--- /dev/null
+++ b/spec/lib/link_details_extractor_spec.rb
@@ -0,0 +1,29 @@
+require 'rails_helper'
+
+RSpec.describe LinkDetailsExtractor do
+  let(:original_url) { '' }
+  let(:html) { '' }
+  let(:html_charset) { nil }
+
+  subject { described_class.new(original_url, html, html_charset) }
+
+  describe '#canonical_url' do
+    let(:original_url) { 'https://foo.com/article?bar=baz123' }
+
+    context 'when canonical URL points to another host' do
+      let(:html) { '<!doctype html><link rel="canonical" href="https://bar.com/different-article" />' }
+
+      it 'ignores the canonical URLs' do
+        expect(subject.canonical_url).to eq original_url
+      end
+    end
+
+    context 'when canonical URL points to the same host' do
+      let(:html) { '<!doctype html><link rel="canonical" href="https://foo.com/article" />' }
+
+      it 'ignores the canonical URLs' do
+        expect(subject.canonical_url).to eq 'https://foo.com/article'
+      end
+    end
+  end
+end