mirror of
https://github.com/funamitech/mastodon
synced 2024-11-23 14:46:52 +09:00
Simplify basic presence validations (#29664)
This commit is contained in:
parent
bc435c63bd
commit
5acec087ca
@ -64,14 +64,7 @@ RSpec.describe Announcement do
|
||||
end
|
||||
|
||||
describe 'Validations' do
|
||||
describe 'text' do
|
||||
it 'validates presence of attribute' do
|
||||
record = Fabricate.build(:announcement, text: nil)
|
||||
|
||||
expect(record).to_not be_valid
|
||||
expect(record.errors[:text]).to be_present
|
||||
end
|
||||
end
|
||||
it { is_expected.to validate_presence_of(:text) }
|
||||
|
||||
describe 'ends_at' do
|
||||
it 'validates presence when starts_at is present' do
|
||||
|
@ -4,17 +4,8 @@ require 'rails_helper'
|
||||
|
||||
RSpec.describe Block do
|
||||
describe 'validations' do
|
||||
it 'is invalid without an account' do
|
||||
block = Fabricate.build(:block, account: nil)
|
||||
block.valid?
|
||||
expect(block).to model_have_error_on_field(:account)
|
||||
end
|
||||
|
||||
it 'is invalid without a target_account' do
|
||||
block = Fabricate.build(:block, target_account: nil)
|
||||
block.valid?
|
||||
expect(block).to model_have_error_on_field(:target_account)
|
||||
end
|
||||
it { is_expected.to belong_to(:account).required }
|
||||
it { is_expected.to belong_to(:target_account).required }
|
||||
end
|
||||
|
||||
it 'removes blocking cache after creation' do
|
||||
|
@ -4,11 +4,6 @@ require 'rails_helper'
|
||||
|
||||
RSpec.describe CustomEmojiCategory do
|
||||
describe 'validations' do
|
||||
it 'validates name presence' do
|
||||
record = described_class.new(name: nil)
|
||||
|
||||
expect(record).to_not be_valid
|
||||
expect(record).to model_have_error_on_field(:name)
|
||||
end
|
||||
it { is_expected.to validate_presence_of(:name) }
|
||||
end
|
||||
end
|
||||
|
@ -4,19 +4,8 @@ require 'rails_helper'
|
||||
|
||||
RSpec.describe CustomFilter do
|
||||
describe 'Validations' do
|
||||
it 'requires presence of title' do
|
||||
record = described_class.new(title: '')
|
||||
record.valid?
|
||||
|
||||
expect(record).to model_have_error_on_field(:title)
|
||||
end
|
||||
|
||||
it 'requires presence of context' do
|
||||
record = described_class.new(context: nil)
|
||||
record.valid?
|
||||
|
||||
expect(record).to model_have_error_on_field(:context)
|
||||
end
|
||||
it { is_expected.to validate_presence_of(:title) }
|
||||
it { is_expected.to validate_presence_of(:context) }
|
||||
|
||||
it 'requires non-empty of context' do
|
||||
record = described_class.new(context: [])
|
||||
|
@ -4,11 +4,7 @@ require 'rails_helper'
|
||||
|
||||
RSpec.describe DomainAllow do
|
||||
describe 'Validations' do
|
||||
it 'is invalid without a domain' do
|
||||
domain_allow = Fabricate.build(:domain_allow, domain: nil)
|
||||
domain_allow.valid?
|
||||
expect(domain_allow).to model_have_error_on_field(:domain)
|
||||
end
|
||||
it { is_expected.to validate_presence_of(:domain) }
|
||||
|
||||
it 'is invalid if the same normalized domain already exists' do
|
||||
_domain_allow = Fabricate(:domain_allow, domain: 'にゃん')
|
||||
|
@ -4,11 +4,7 @@ require 'rails_helper'
|
||||
|
||||
RSpec.describe DomainBlock do
|
||||
describe 'validations' do
|
||||
it 'is invalid without a domain' do
|
||||
domain_block = Fabricate.build(:domain_block, domain: nil)
|
||||
domain_block.valid?
|
||||
expect(domain_block).to model_have_error_on_field(:domain)
|
||||
end
|
||||
it { is_expected.to validate_presence_of(:domain) }
|
||||
|
||||
it 'is invalid if the same normalized domain already exists' do
|
||||
_domain_block = Fabricate(:domain_block, domain: 'にゃん')
|
||||
|
@ -9,17 +9,8 @@ RSpec.describe Follow do
|
||||
describe 'validations' do
|
||||
subject { described_class.new(account: alice, target_account: bob, rate_limit: true) }
|
||||
|
||||
it 'is invalid without an account' do
|
||||
follow = Fabricate.build(:follow, account: nil)
|
||||
follow.valid?
|
||||
expect(follow).to model_have_error_on_field(:account)
|
||||
end
|
||||
|
||||
it 'is invalid without a target_account' do
|
||||
follow = Fabricate.build(:follow, target_account: nil)
|
||||
follow.valid?
|
||||
expect(follow).to model_have_error_on_field(:target_account)
|
||||
end
|
||||
it { is_expected.to belong_to(:account).required }
|
||||
it { is_expected.to belong_to(:target_account).required }
|
||||
|
||||
it 'is invalid if account already follows too many people' do
|
||||
alice.update(following_count: FollowLimitValidator::LIMIT)
|
||||
|
@ -3,19 +3,8 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Import do
|
||||
let(:account) { Fabricate(:account) }
|
||||
let(:type) { 'following' }
|
||||
let(:data) { attachment_fixture('imports.txt') }
|
||||
|
||||
describe 'validations' do
|
||||
it 'is invalid without an type' do
|
||||
import = described_class.create(account: account, data: data)
|
||||
expect(import).to model_have_error_on_field(:type)
|
||||
end
|
||||
|
||||
it 'is invalid without a data' do
|
||||
import = described_class.create(account: account, type: type)
|
||||
expect(import).to model_have_error_on_field(:data)
|
||||
end
|
||||
describe 'Validations' do
|
||||
it { is_expected.to validate_presence_of(:type) }
|
||||
it { is_expected.to validate_presence_of(:data) }
|
||||
end
|
||||
end
|
||||
|
@ -4,19 +4,8 @@ require 'rails_helper'
|
||||
|
||||
RSpec.describe IpBlock do
|
||||
describe 'validations' do
|
||||
it 'validates ip presence', :aggregate_failures do
|
||||
ip_block = described_class.new(ip: nil, severity: :no_access)
|
||||
|
||||
expect(ip_block).to_not be_valid
|
||||
expect(ip_block).to model_have_error_on_field(:ip)
|
||||
end
|
||||
|
||||
it 'validates severity presence', :aggregate_failures do
|
||||
ip_block = described_class.new(ip: '127.0.0.1', severity: nil)
|
||||
|
||||
expect(ip_block).to_not be_valid
|
||||
expect(ip_block).to model_have_error_on_field(:severity)
|
||||
end
|
||||
it { is_expected.to validate_presence_of(:ip) }
|
||||
it { is_expected.to validate_presence_of(:severity) }
|
||||
|
||||
it 'validates ip uniqueness', :aggregate_failures do
|
||||
described_class.create!(ip: '127.0.0.1', severity: :no_access)
|
||||
|
@ -3,14 +3,7 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Marker do
|
||||
describe 'validations' do
|
||||
describe 'timeline' do
|
||||
it 'must be included in valid list' do
|
||||
record = described_class.new(timeline: 'not real timeline')
|
||||
|
||||
expect(record).to_not be_valid
|
||||
expect(record).to model_have_error_on_field(:timeline)
|
||||
end
|
||||
end
|
||||
describe 'Validations' do
|
||||
it { is_expected.to validate_inclusion_of(:timeline).in_array(described_class::TIMELINES) }
|
||||
end
|
||||
end
|
||||
|
@ -257,12 +257,7 @@ RSpec.describe MediaAttachment, :attachment_processing do
|
||||
end
|
||||
end
|
||||
|
||||
it 'is invalid without file' do
|
||||
media = described_class.new
|
||||
|
||||
expect(media.valid?).to be false
|
||||
expect(media).to model_have_error_on_field(:file)
|
||||
end
|
||||
it { is_expected.to validate_presence_of(:file) }
|
||||
|
||||
describe 'size limit validation' do
|
||||
it 'rejects video files that are too large' do
|
||||
|
@ -4,16 +4,7 @@ require 'rails_helper'
|
||||
|
||||
RSpec.describe Mention do
|
||||
describe 'validations' do
|
||||
it 'is invalid without an account' do
|
||||
mention = Fabricate.build(:mention, account: nil)
|
||||
mention.valid?
|
||||
expect(mention).to model_have_error_on_field(:account)
|
||||
end
|
||||
|
||||
it 'is invalid without a status' do
|
||||
mention = Fabricate.build(:mention, status: nil)
|
||||
mention.valid?
|
||||
expect(mention).to model_have_error_on_field(:status)
|
||||
end
|
||||
it { is_expected.to belong_to(:account).required }
|
||||
it { is_expected.to belong_to(:status).required }
|
||||
end
|
||||
end
|
||||
|
@ -32,12 +32,9 @@ RSpec.describe Poll do
|
||||
|
||||
describe 'validations' do
|
||||
context 'when not valid' do
|
||||
let(:poll) { Fabricate.build(:poll, expires_at: nil) }
|
||||
subject { Fabricate.build(:poll) }
|
||||
|
||||
it 'is invalid without an expire date' do
|
||||
poll.valid?
|
||||
expect(poll).to model_have_error_on_field(:expires_at)
|
||||
end
|
||||
it { is_expected.to validate_presence_of(:expires_at) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -32,11 +32,7 @@ RSpec.describe User do
|
||||
end
|
||||
|
||||
describe 'validations' do
|
||||
it 'is invalid without an account' do
|
||||
user = Fabricate.build(:user, account: nil)
|
||||
user.valid?
|
||||
expect(user).to model_have_error_on_field(:account)
|
||||
end
|
||||
it { is_expected.to belong_to(:account).required }
|
||||
|
||||
it 'is invalid without a valid email' do
|
||||
user = Fabricate.build(:user, email: 'john@')
|
||||
|
@ -4,37 +4,10 @@ require 'rails_helper'
|
||||
|
||||
RSpec.describe WebauthnCredential do
|
||||
describe 'validations' do
|
||||
it 'is invalid without an external id' do
|
||||
webauthn_credential = Fabricate.build(:webauthn_credential, external_id: nil)
|
||||
|
||||
webauthn_credential.valid?
|
||||
|
||||
expect(webauthn_credential).to model_have_error_on_field(:external_id)
|
||||
end
|
||||
|
||||
it 'is invalid without a public key' do
|
||||
webauthn_credential = Fabricate.build(:webauthn_credential, public_key: nil)
|
||||
|
||||
webauthn_credential.valid?
|
||||
|
||||
expect(webauthn_credential).to model_have_error_on_field(:public_key)
|
||||
end
|
||||
|
||||
it 'is invalid without a nickname' do
|
||||
webauthn_credential = Fabricate.build(:webauthn_credential, nickname: nil)
|
||||
|
||||
webauthn_credential.valid?
|
||||
|
||||
expect(webauthn_credential).to model_have_error_on_field(:nickname)
|
||||
end
|
||||
|
||||
it 'is invalid without a sign_count' do
|
||||
webauthn_credential = Fabricate.build(:webauthn_credential, sign_count: nil)
|
||||
|
||||
webauthn_credential.valid?
|
||||
|
||||
expect(webauthn_credential).to model_have_error_on_field(:sign_count)
|
||||
end
|
||||
it { is_expected.to validate_presence_of(:external_id) }
|
||||
it { is_expected.to validate_presence_of(:public_key) }
|
||||
it { is_expected.to validate_presence_of(:nickname) }
|
||||
it { is_expected.to validate_presence_of(:sign_count) }
|
||||
|
||||
it 'is invalid if already exist a webauthn credential with the same external id' do
|
||||
Fabricate(:webauthn_credential, external_id: '_Typ0ygudDnk9YUVWLQayw')
|
||||
|
@ -6,12 +6,7 @@ RSpec.describe Webhook do
|
||||
let(:webhook) { Fabricate(:webhook) }
|
||||
|
||||
describe 'Validations' do
|
||||
it 'requires presence of events' do
|
||||
record = described_class.new(events: nil)
|
||||
record.valid?
|
||||
|
||||
expect(record).to model_have_error_on_field(:events)
|
||||
end
|
||||
it { is_expected.to validate_presence_of(:events) }
|
||||
|
||||
it 'requires non-empty events value' do
|
||||
record = described_class.new(events: [])
|
||||
|
Loading…
Reference in New Issue
Block a user