Add coverage for model normalizations (#31734)
This commit is contained in:
parent
9ed1aab9b7
commit
14af5b47ac
11
spec/models/account_alias_spec.rb
Normal file
11
spec/models/account_alias_spec.rb
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe AccountAlias do
|
||||||
|
describe 'Normalizations' do
|
||||||
|
describe 'acct' do
|
||||||
|
it { is_expected.to normalize(:acct).from(' @username@domain ').to('username@domain') }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -3,6 +3,12 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe AccountMigration do
|
RSpec.describe AccountMigration do
|
||||||
|
describe 'Normalizations' do
|
||||||
|
describe 'acct' do
|
||||||
|
it { is_expected.to normalize(:acct).from(' @username@domain ').to('username@domain') }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe 'validations' do
|
describe 'validations' do
|
||||||
subject { described_class.new(account: source_account, acct: target_acct) }
|
subject { described_class.new(account: source_account, acct: target_acct) }
|
||||||
|
|
||||||
|
@ -723,14 +723,15 @@ RSpec.describe Account do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'Normalizations' do
|
||||||
|
describe 'username' do
|
||||||
|
it { is_expected.to normalize(:username).from(" \u3000bob \t \u00a0 \n ").to('bob') }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe 'validations' do
|
describe 'validations' do
|
||||||
it { is_expected.to validate_presence_of(:username) }
|
it { is_expected.to validate_presence_of(:username) }
|
||||||
|
|
||||||
it 'squishes the username before validation' do
|
|
||||||
account = Fabricate(:account, domain: nil, username: " \u3000bob \t \u00a0 \n ")
|
|
||||||
expect(account.username).to eq 'bob'
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when is local' do
|
context 'when is local' do
|
||||||
it 'is invalid if the username is not unique in case-insensitive comparison among local accounts' do
|
it 'is invalid if the username is not unique in case-insensitive comparison among local accounts' do
|
||||||
_account = Fabricate(:account, username: 'the_doctor')
|
_account = Fabricate(:account, username: 'the_doctor')
|
||||||
|
11
spec/models/account_warning_spec.rb
Normal file
11
spec/models/account_warning_spec.rb
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe AccountWarning do
|
||||||
|
describe 'Normalizations' do
|
||||||
|
describe 'text' do
|
||||||
|
it { is_expected.to normalize(:text).from(nil).to('') }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -79,22 +79,9 @@ RSpec.describe CustomEmoji, :attachment_processing do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe 'Normalizations' do
|
describe 'Normalizations' do
|
||||||
describe 'downcase domain value' do
|
describe 'domain' do
|
||||||
context 'with a mixed case domain value' do
|
it { is_expected.to normalize(:domain).from('wWw.MaStOdOn.CoM').to('www.mastodon.com') }
|
||||||
it 'normalizes the value to downcased' do
|
it { is_expected.to normalize(:domain).from(nil).to(nil) }
|
||||||
custom_emoji = Fabricate.build(:custom_emoji, domain: 'wWw.MaStOdOn.CoM')
|
|
||||||
|
|
||||||
expect(custom_emoji.domain).to eq('www.mastodon.com')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'with a nil domain value' do
|
|
||||||
it 'leaves the value as nil' do
|
|
||||||
custom_emoji = Fabricate.build(:custom_emoji, domain: nil)
|
|
||||||
|
|
||||||
expect(custom_emoji.domain).to be_nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -34,10 +34,8 @@ RSpec.describe CustomFilter do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe 'Normalizations' do
|
describe 'Normalizations' do
|
||||||
it 'cleans up context values' do
|
describe 'context' do
|
||||||
record = described_class.new(context: ['home', 'notifications', 'public ', ''])
|
it { is_expected.to normalize(:context).from(['home', 'notifications', 'public ', '']).to(%w(home notifications public)) }
|
||||||
|
|
||||||
expect(record.context).to eq(%w(home notifications public))
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
11
spec/models/featured_tag_spec.rb
Normal file
11
spec/models/featured_tag_spec.rb
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe FeaturedTag do
|
||||||
|
describe 'Normalizations' do
|
||||||
|
describe 'name' do
|
||||||
|
it { is_expected.to normalize(:name).from(' #hashtag ').to('hashtag') }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
11
spec/models/relay_spec.rb
Normal file
11
spec/models/relay_spec.rb
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe Relay do
|
||||||
|
describe 'Normalizations' do
|
||||||
|
describe 'inbox_url' do
|
||||||
|
it { is_expected.to normalize(:inbox_url).from(' http://host.example ').to('http://host.example') }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -59,45 +59,18 @@ RSpec.describe User do
|
|||||||
|
|
||||||
describe 'Normalizations' do
|
describe 'Normalizations' do
|
||||||
describe 'locale' do
|
describe 'locale' do
|
||||||
it 'preserves valid locale' do
|
it { is_expected.to_not normalize(:locale).from('en') }
|
||||||
user = Fabricate.build(:user, locale: 'en')
|
it { is_expected.to normalize(:locale).from('toto').to(nil) }
|
||||||
|
|
||||||
expect(user.locale).to eq('en')
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'cleans out invalid locale' do
|
|
||||||
user = Fabricate.build(:user, locale: 'toto')
|
|
||||||
|
|
||||||
expect(user.locale).to be_nil
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'time_zone' do
|
describe 'time_zone' do
|
||||||
it 'preserves valid timezone' do
|
it { is_expected.to_not normalize(:time_zone).from('UTC') }
|
||||||
user = Fabricate.build(:user, time_zone: 'UTC')
|
it { is_expected.to normalize(:time_zone).from('toto').to(nil) }
|
||||||
|
|
||||||
expect(user.time_zone).to eq('UTC')
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'cleans out invalid timezone' do
|
describe 'chosen_languages' do
|
||||||
user = Fabricate.build(:user, time_zone: 'toto')
|
it { is_expected.to normalize(:chosen_languages).from(['en', 'fr', '']).to(%w(en fr)) }
|
||||||
|
it { is_expected.to normalize(:chosen_languages).from(['']).to(nil) }
|
||||||
expect(user.time_zone).to be_nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe 'languages' do
|
|
||||||
it 'preserves valid options for languages' do
|
|
||||||
user = Fabricate.build(:user, chosen_languages: ['en', 'fr', ''])
|
|
||||||
|
|
||||||
expect(user.chosen_languages).to eq(['en', 'fr'])
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'cleans out empty string from languages' do
|
|
||||||
user = Fabricate.build(:user, chosen_languages: [''])
|
|
||||||
|
|
||||||
expect(user.chosen_languages).to be_nil
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -29,10 +29,8 @@ RSpec.describe Webhook do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe 'Normalizations' do
|
describe 'Normalizations' do
|
||||||
it 'cleans up events values' do
|
describe 'events' do
|
||||||
record = described_class.new(events: ['account.approved', 'account.created ', ''])
|
it { is_expected.to normalize(:events).from(['account.approved', 'account.created ', '']).to(%w(account.approved account.created)) }
|
||||||
|
|
||||||
expect(record.events).to eq(%w(account.approved account.created))
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user