Use rspec tag for skip mx check

This commit is contained in:
Matt Jankowski 2025-08-19 10:53:48 -04:00
parent 8d3bca3bb8
commit fae716002d
4 changed files with 10 additions and 8 deletions

View File

@ -137,6 +137,8 @@ class User < ApplicationRecord
attribute :external, :boolean, default: false
attribute :bypass_registration_checks, :boolean, default: false
class_attribute :skip_mx_check, default: Rails.env.local?
def self.those_who_can(*any_of_privileges)
matching_role_ids = UserRole.that_can(*any_of_privileges).map(&:id)
@ -147,10 +149,6 @@ class User < ApplicationRecord
end
end
def self.skip_mx_check?
Rails.env.local?
end
def date_of_birth=(hash_or_string)
@date_of_birth = begin
if hash_or_string.is_a?(Hash)

View File

@ -228,7 +228,7 @@ RSpec.describe Auth::RegistrationsController do
end
end
context 'when user has an email address requiring approval through a MX record' do
context 'when user has an email address requiring approval through a MX record', :enable_mx_checks do
subject do
request.headers['Accept-Language'] = accept_language
post :create, params: { user: { account_attributes: { username: 'test' }, email: 'test@example.com', password: '12345678', password_confirmation: '12345678', agreement: 'true' } }
@ -237,7 +237,6 @@ RSpec.describe Auth::RegistrationsController do
before do
Setting.registrations_mode = 'open'
Fabricate(:email_domain_block, allow_with_approval: true, domain: 'mail.example.com')
allow(User).to receive(:skip_mx_check?).and_return(false)
configure_mx(domain: 'example.com', exchange: 'mail.example.com')
end

View File

@ -139,6 +139,12 @@ RSpec.configure do |config|
example.run
end
config.around(:each, :enable_mx_checks) do |example|
User.skip_mx_check = false
example.run
User.skip_mx_check = true
end
config.around(:each, type: :search) do |example|
Chewy.settings[:enabled] = true
example.run

View File

@ -48,11 +48,10 @@ RSpec.describe AppSignUpService do
end
end
context 'when the email address requires approval through MX records' do
context 'when the email address requires approval through MX records', :enable_mx_checks do
before do
Setting.registrations_mode = 'open'
Fabricate(:email_domain_block, allow_with_approval: true, domain: 'smtp.email.com')
allow(User).to receive(:skip_mx_check?).and_return(false)
configure_mx(domain: 'email.com', exchange: 'smtp.email.com')
end