1
0
Fork 0
mirror of https://github.com/mastodon/mastodon.git synced 2024-08-20 21:08:15 -07:00
This commit is contained in:
Matt Jankowski 2024-07-31 14:05:07 +00:00 committed by GitHub
commit 46928808ef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 42 additions and 164 deletions

View file

@ -155,6 +155,8 @@ group :test do
# Test harness fo rack components # Test harness fo rack components
gem 'rack-test', '~> 2.1' gem 'rack-test', '~> 2.1'
gem 'shoulda-matchers'
# Coverage formatter for RSpec test if DISABLE_SIMPLECOV is false # Coverage formatter for RSpec test if DISABLE_SIMPLECOV is false
gem 'simplecov', '~> 0.22', require: false gem 'simplecov', '~> 0.22', require: false
gem 'simplecov-lcov', '~> 0.8', require: false gem 'simplecov-lcov', '~> 0.8', require: false

View file

@ -790,6 +790,8 @@ GEM
rubyzip (>= 1.2.2, < 3.0) rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0) websocket (~> 1.0)
semantic_range (3.0.0) semantic_range (3.0.0)
shoulda-matchers (6.2.0)
activesupport (>= 5.2.0)
sidekiq (6.5.12) sidekiq (6.5.12)
connection_pool (>= 2.2.5, < 3) connection_pool (>= 2.2.5, < 3)
rack (~> 2.0) rack (~> 2.0)
@ -1038,6 +1040,7 @@ DEPENDENCIES
sanitize (~> 6.0) sanitize (~> 6.0)
scenic (~> 1.7) scenic (~> 1.7)
selenium-webdriver selenium-webdriver
shoulda-matchers
sidekiq (~> 6.5) sidekiq (~> 6.5)
sidekiq-bulk (~> 0.2.0) sidekiq-bulk (~> 0.2.0)
sidekiq-scheduler (~> 5.0) sidekiq-scheduler (~> 5.0)

View file

@ -722,11 +722,7 @@ RSpec.describe Account do
end end
describe 'validations' do describe 'validations' do
it 'is invalid without a username' do it { is_expected.to validate_presence_of(:username) }
account = Fabricate.build(:account, username: nil)
account.valid?
expect(account).to model_have_error_on_field(:username)
end
it 'squishes the username before validation' do it 'squishes the username before validation' do
account = Fabricate(:account, domain: nil, username: " \u3000bob \t \u00a0 \n ") account = Fabricate(:account, domain: nil, username: " \u3000bob \t \u00a0 \n ")

View file

@ -64,14 +64,7 @@ describe Announcement do
end end
describe 'Validations' do describe 'Validations' do
describe 'text' do it { is_expected.to validate_presence_of(:text) }
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
describe 'ends_at' do describe 'ends_at' do
it 'validates presence when starts_at is present' do it 'validates presence when starts_at is present' do

View file

@ -4,17 +4,8 @@ require 'rails_helper'
RSpec.describe Block do RSpec.describe Block do
describe 'validations' do describe 'validations' do
it 'is invalid without an account' do it { is_expected.to belong_to(:account).required }
block = Fabricate.build(:block, account: nil) it { is_expected.to belong_to(:target_account).required }
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
end end
it 'removes blocking cache after creation' do it 'removes blocking cache after creation' do

View file

@ -4,11 +4,6 @@ require 'rails_helper'
describe CustomEmojiCategory do describe CustomEmojiCategory do
describe 'validations' do describe 'validations' do
it 'validates name presence' do it { is_expected.to validate_presence_of(:name) }
record = described_class.new(name: nil)
expect(record).to_not be_valid
expect(record).to model_have_error_on_field(:name)
end
end end
end end

View file

@ -4,19 +4,8 @@ require 'rails_helper'
RSpec.describe CustomFilter do RSpec.describe CustomFilter do
describe 'Validations' do describe 'Validations' do
it 'requires presence of title' do it { is_expected.to validate_presence_of(:title) }
record = described_class.new(title: '') it { is_expected.to validate_presence_of(:context) }
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 'requires non-empty of context' do it 'requires non-empty of context' do
record = described_class.new(context: []) record = described_class.new(context: [])

View file

@ -4,11 +4,7 @@ require 'rails_helper'
describe DomainAllow do describe DomainAllow do
describe 'Validations' do describe 'Validations' do
it 'is invalid without a domain' do it { is_expected.to validate_presence_of(:domain) }
domain_allow = Fabricate.build(:domain_allow, domain: nil)
domain_allow.valid?
expect(domain_allow).to model_have_error_on_field(:domain)
end
it 'is invalid if the same normalized domain already exists' do it 'is invalid if the same normalized domain already exists' do
_domain_allow = Fabricate(:domain_allow, domain: 'にゃん') _domain_allow = Fabricate(:domain_allow, domain: 'にゃん')

View file

@ -4,11 +4,7 @@ require 'rails_helper'
RSpec.describe DomainBlock do RSpec.describe DomainBlock do
describe 'validations' do describe 'validations' do
it 'is invalid without a domain' do it { is_expected.to validate_presence_of(:domain) }
domain_block = Fabricate.build(:domain_block, domain: nil)
domain_block.valid?
expect(domain_block).to model_have_error_on_field(:domain)
end
it 'is invalid if the same normalized domain already exists' do it 'is invalid if the same normalized domain already exists' do
_domain_block = Fabricate(:domain_block, domain: 'にゃん') _domain_block = Fabricate(:domain_block, domain: 'にゃん')

View file

@ -9,17 +9,8 @@ RSpec.describe Follow do
describe 'validations' do describe 'validations' do
subject { described_class.new(account: alice, target_account: bob, rate_limit: true) } subject { described_class.new(account: alice, target_account: bob, rate_limit: true) }
it 'is invalid without an account' do it { is_expected.to belong_to(:account).required }
follow = Fabricate.build(:follow, account: nil) it { is_expected.to belong_to(:target_account).required }
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 invalid if account already follows too many people' do it 'is invalid if account already follows too many people' do
alice.update(following_count: FollowLimitValidator::LIMIT) alice.update(following_count: FollowLimitValidator::LIMIT)

View file

@ -3,19 +3,8 @@
require 'rails_helper' require 'rails_helper'
RSpec.describe Import do RSpec.describe Import do
let(:account) { Fabricate(:account) } describe 'Validations' do
let(:type) { 'following' } it { is_expected.to validate_presence_of(:type) }
let(:data) { attachment_fixture('imports.txt') } it { is_expected.to validate_presence_of(:data) }
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
end end
end end

View file

@ -4,19 +4,8 @@ require 'rails_helper'
describe IpBlock do describe IpBlock do
describe 'validations' do describe 'validations' do
it 'validates ip presence', :aggregate_failures do it { is_expected.to validate_presence_of(:ip) }
ip_block = described_class.new(ip: nil, severity: :no_access) it { is_expected.to validate_presence_of(:severity) }
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 'validates ip uniqueness', :aggregate_failures do it 'validates ip uniqueness', :aggregate_failures do
described_class.create!(ip: '127.0.0.1', severity: :no_access) described_class.create!(ip: '127.0.0.1', severity: :no_access)

View file

@ -3,14 +3,7 @@
require 'rails_helper' require 'rails_helper'
describe Marker do describe Marker do
describe 'validations' do describe 'Validations' do
describe 'timeline' do it { is_expected.to validate_inclusion_of(:timeline).in_array(described_class::TIMELINES) }
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
end end
end end

View file

@ -257,12 +257,7 @@ RSpec.describe MediaAttachment, :attachment_processing do
end end
end end
it 'is invalid without file' do it { is_expected.to validate_presence_of(:file) }
media = described_class.new
expect(media.valid?).to be false
expect(media).to model_have_error_on_field(:file)
end
describe 'size limit validation' do describe 'size limit validation' do
it 'rejects video files that are too large' do it 'rejects video files that are too large' do

View file

@ -4,16 +4,7 @@ require 'rails_helper'
RSpec.describe Mention do RSpec.describe Mention do
describe 'validations' do describe 'validations' do
it 'is invalid without an account' do it { is_expected.to belong_to(:account).required }
mention = Fabricate.build(:mention, account: nil) it { is_expected.to belong_to(:status).required }
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
end end
end end

View file

@ -32,12 +32,9 @@ describe Poll do
describe 'validations' do describe 'validations' do
context 'when not valid' 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 it { is_expected.to validate_presence_of(:expires_at) }
poll.valid?
expect(poll).to model_have_error_on_field(:expires_at)
end
end end
end end
end end

View file

@ -32,11 +32,7 @@ RSpec.describe User do
end end
describe 'validations' do describe 'validations' do
it 'is invalid without an account' do it { is_expected.to belong_to(:account).required }
user = Fabricate.build(:user, account: nil)
user.valid?
expect(user).to model_have_error_on_field(:account)
end
it 'is invalid without a valid email' do it 'is invalid without a valid email' do
user = Fabricate.build(:user, email: 'john@') user = Fabricate.build(:user, email: 'john@')

View file

@ -4,37 +4,10 @@ require 'rails_helper'
RSpec.describe WebauthnCredential do RSpec.describe WebauthnCredential do
describe 'validations' do describe 'validations' do
it 'is invalid without an external id' do it { is_expected.to validate_presence_of(:external_id) }
webauthn_credential = Fabricate.build(:webauthn_credential, external_id: nil) it { is_expected.to validate_presence_of(:public_key) }
it { is_expected.to validate_presence_of(:nickname) }
webauthn_credential.valid? it { is_expected.to validate_presence_of(:sign_count) }
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 invalid if already exist a webauthn credential with the same external id' do it 'is invalid if already exist a webauthn credential with the same external id' do
Fabricate(:webauthn_credential, external_id: '_Typ0ygudDnk9YUVWLQayw') Fabricate(:webauthn_credential, external_id: '_Typ0ygudDnk9YUVWLQayw')

View file

@ -6,12 +6,7 @@ RSpec.describe Webhook do
let(:webhook) { Fabricate(:webhook) } let(:webhook) { Fabricate(:webhook) }
describe 'Validations' do describe 'Validations' do
it 'requires presence of events' do it { is_expected.to validate_presence_of(:events) }
record = described_class.new(events: nil)
record.valid?
expect(record).to model_have_error_on_field(:events)
end
it 'requires non-empty events value' do it 'requires non-empty events value' do
record = described_class.new(events: []) record = described_class.new(events: [])

View file

@ -0,0 +1,8 @@
# frozen_string_literal: true
Shoulda::Matchers.configure do |config|
config.integrate do |with|
with.test_framework :rspec
with.library :rails
end
end