Simplify account model username presence validation spec (#31013)

This commit is contained in:
Matt Jankowski 2024-09-03 11:30:57 -04:00 committed by GitHub
parent fcb83be8b2
commit 67faaf5557
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 14 additions and 5 deletions

View file

@ -151,6 +151,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.3.1)
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)
@ -1035,6 +1037,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

@ -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