mirror of
https://github.com/glitch-soc/mastodon.git
synced 2026-03-29 03:00:33 +02:00
Add coverage for TagManager#normalize_domain (#35994)
This commit is contained in:
@@ -18,7 +18,7 @@ class TagManager
|
||||
return if domain.nil?
|
||||
|
||||
uri = Addressable::URI.new
|
||||
uri.host = domain.delete_suffix('/')
|
||||
uri.host = domain.strip.delete_suffix('/')
|
||||
uri.normalized_host
|
||||
end
|
||||
|
||||
|
||||
@@ -54,12 +54,44 @@ RSpec.describe TagManager do
|
||||
end
|
||||
|
||||
describe '#normalize_domain' do
|
||||
it 'returns nil if the given parameter is nil' do
|
||||
expect(described_class.instance.normalize_domain(nil)).to be_nil
|
||||
subject { described_class.instance.normalize_domain(domain) }
|
||||
|
||||
context 'with a nil value' do
|
||||
let(:domain) { nil }
|
||||
|
||||
it { is_expected.to be_nil }
|
||||
end
|
||||
|
||||
it 'returns normalized domain' do
|
||||
expect(described_class.instance.normalize_domain('DoMaIn.Example.com/')).to eq 'domain.example.com'
|
||||
context 'with a blank value' do
|
||||
let(:domain) { '' }
|
||||
|
||||
it { is_expected.to be_blank }
|
||||
end
|
||||
|
||||
context 'with a mixed case string' do
|
||||
let(:domain) { 'DoMaIn.Example.com' }
|
||||
|
||||
it { is_expected.to eq('domain.example.com') }
|
||||
end
|
||||
|
||||
context 'with a trailing slash string' do
|
||||
let(:domain) { 'domain.example.com/' }
|
||||
|
||||
it { is_expected.to eq('domain.example.com') }
|
||||
end
|
||||
|
||||
context 'with a space padded string' do
|
||||
let(:domain) { ' domain.example.com ' }
|
||||
|
||||
it { is_expected.to eq('domain.example.com') }
|
||||
end
|
||||
|
||||
context 'with an invalid domain string' do
|
||||
let(:domain) { ' !@#$@#$@$@# ' }
|
||||
|
||||
it 'raises invalid uri error' do
|
||||
expect { subject }.to raise_error(Addressable::URI::InvalidURIError)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ require 'rails_helper'
|
||||
RSpec.describe InstanceModerationNote do
|
||||
describe 'chronological' do
|
||||
it 'returns the instance notes sorted by oldest first' do
|
||||
instance = Instance.find_or_initialize_by(domain: TagManager.instance.normalize_domain('mastodon.example'))
|
||||
instance = Instance.find_or_initialize_by(domain: 'mastodon.example')
|
||||
|
||||
note1 = Fabricate(:instance_moderation_note, domain: instance.domain)
|
||||
note2 = Fabricate(:instance_moderation_note, domain: instance.domain)
|
||||
|
||||
Reference in New Issue
Block a user