From 6e48322055cf09e1b133f6193e29661e486a1353 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 6 Aug 2025 08:19:43 -0400 Subject: [PATCH] Add spec for `CanonicalEmailBlock.matching_email` scope (#35692) --- spec/models/canonical_email_block_spec.rb | 30 +++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/spec/models/canonical_email_block_spec.rb b/spec/models/canonical_email_block_spec.rb index c63483f968f..0b8dcfb9c19 100644 --- a/spec/models/canonical_email_block_spec.rb +++ b/spec/models/canonical_email_block_spec.rb @@ -3,6 +3,36 @@ require 'rails_helper' RSpec.describe CanonicalEmailBlock do + describe 'Associations' do + it { is_expected.to belong_to(:reference_account).class_name('Account').optional } + end + + describe 'Scopes' do + describe '.matching_email' do + subject { described_class.matching_email(email) } + + let!(:block) { Fabricate :canonical_email_block, email: 'test@example.com' } + + context 'when email is exact match' do + let(:email) { 'test@example.com' } + + it { is_expected.to contain_exactly(block) } + end + + context 'when email does not match' do + let(:email) { 'test@example.ORG' } + + it { is_expected.to be_empty } + end + + context 'when email is different but normalizes to same hash' do + let(:email) { 'te.st+more@EXAMPLE.com' } + + it { is_expected.to contain_exactly(block) } + end + end + end + describe '#email=' do let(:target_hash) { '973dfe463ec85785f5f95af5ba3906eedb2d931c24e69824a89ea65dba4e813b' }