From 67faaf555723e8b202620725b7144a183543809e Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 3 Sep 2024 11:30:57 -0400 Subject: [PATCH] Simplify account model username presence validation spec (#31013) --- Gemfile | 2 ++ Gemfile.lock | 3 +++ spec/models/account_spec.rb | 6 +----- spec/support/shoulda_matchers.rb | 8 ++++++++ 4 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 spec/support/shoulda_matchers.rb diff --git a/Gemfile b/Gemfile index 6538067cff..4c808fa480 100644 --- a/Gemfile +++ b/Gemfile @@ -151,6 +151,8 @@ group :test do # Test harness fo rack components gem 'rack-test', '~> 2.1' + gem 'shoulda-matchers' + # Coverage formatter for RSpec test if DISABLE_SIMPLECOV is false gem 'simplecov', '~> 0.22', require: false gem 'simplecov-lcov', '~> 0.8', require: false diff --git a/Gemfile.lock b/Gemfile.lock index 2e9037d8a6..461a2d43a2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -790,6 +790,8 @@ GEM rubyzip (>= 1.2.2, < 3.0) websocket (~> 1.0) semantic_range (3.0.0) + shoulda-matchers (6.3.1) + activesupport (>= 5.2.0) sidekiq (6.5.12) connection_pool (>= 2.2.5, < 3) rack (~> 2.0) @@ -1035,6 +1037,7 @@ DEPENDENCIES sanitize (~> 6.0) scenic (~> 1.7) selenium-webdriver + shoulda-matchers sidekiq (~> 6.5) sidekiq-bulk (~> 0.2.0) sidekiq-scheduler (~> 5.0) diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb index 8e5648a0b0..14528ed17b 100644 --- a/spec/models/account_spec.rb +++ b/spec/models/account_spec.rb @@ -722,11 +722,7 @@ RSpec.describe Account do end describe 'validations' do - it 'is invalid without a username' do - account = Fabricate.build(:account, username: nil) - account.valid? - expect(account).to model_have_error_on_field(:username) - end + 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 ") diff --git a/spec/support/shoulda_matchers.rb b/spec/support/shoulda_matchers.rb new file mode 100644 index 0000000000..edcf9dd859 --- /dev/null +++ b/spec/support/shoulda_matchers.rb @@ -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