From 7f16397f3c37a8e378239974b73afbfe2b6e6844 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Fri, 27 Feb 2026 12:05:29 -0500 Subject: [PATCH] Add validation spec for `Form::Redirect` model (#38011) --- spec/models/form/redirect_spec.rb | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 spec/models/form/redirect_spec.rb diff --git a/spec/models/form/redirect_spec.rb b/spec/models/form/redirect_spec.rb new file mode 100644 index 0000000000..4427a0bb86 --- /dev/null +++ b/spec/models/form/redirect_spec.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe Form::Redirect do + describe 'Validations' do + it { is_expected.to validate_presence_of(:acct) } + + describe 'target account validation' do + subject { described_class.new(account:) } + + context 'when target_account is missing' do + let(:account) { Fabricate.build :account } + + it { is_expected.to_not allow_value(nil).for(:target_account).against(:acct).with_message(I18n.t('migrations.errors.not_found')) } + end + + context 'when account already moved' do + let(:account) { Fabricate.build :account, moved_to_account_id: target_account.id } + let(:target_account) { Fabricate :account } + + it { is_expected.to_not allow_value(target_account).for(:target_account).against(:acct).with_message(I18n.t('migrations.errors.already_moved')) } + end + + context 'when moving to self' do + let(:account) { Fabricate :account } + + it { is_expected.to_not allow_value(account).for(:target_account).against(:acct).with_message(I18n.t('migrations.errors.move_to_self')) } + end + end + end +end