From 81f776ccd25daac2675adbc21fadfaab9a30df21 Mon Sep 17 00:00:00 2001 From: abhishek Tanwar Date: Tue, 12 May 2026 10:44:50 +0530 Subject: [PATCH 1/2] fix: rspec test cases for model UsernameBlock instance methods. This commit brings all instance methods defined in the UsernameBlock model. The impact of this commit is that the test coverage tends to range from 75% to 100%. --- spec/models/username_block_spec.rb | 44 ++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/spec/models/username_block_spec.rb b/spec/models/username_block_spec.rb index 72dbe028bdf..fc14f0a5431 100644 --- a/spec/models/username_block_spec.rb +++ b/spec/models/username_block_spec.rb @@ -60,4 +60,48 @@ RSpec.describe UsernameBlock do end end end + + describe 'instance methods' do + subject(:username_block) { described_class.new } + + describe '#comparison' do + subject(:username_block) { described_class.new(exact: exact) } + + context 'when exact is true' do + let(:exact) { true } + + it 'returns equals' do + expect(username_block.comparison).to eq('equals') + end + end + + context 'when exact is false' do + let(:exact) { false } + + it 'returns contains' do + expect(username_block.comparison).to eq('contains') + end + end + end + + describe '#comparison=' do + it 'sets exact to true when equals is passed' do + username_block.comparison = 'equals' + expect(username_block.exact).to be(true) + end + + it 'sets exact to false when contains is passed' do + username_block.comparison = 'contains' + expect(username_block.exact).to be(false) + end + end + + describe '#to_log_human_identifier' do + it 'returns the username' do + username_block.username = 'harry' + + expect(username_block.to_log_human_identifier).to eq('harry') + end + end + end end From 7afb1eb3222f621841b315ee2c7a5f5faa86770e Mon Sep 17 00:00:00 2001 From: abhishek Tanwar Date: Wed, 13 May 2026 07:04:02 +0530 Subject: [PATCH 2/2] spec: applied feedback changes 1. added newly method test coverage to existing top level ``` #matches? ``` 2. applied one liner style with basic 'truth table' sort of things. --- spec/models/username_block_spec.rb | 73 ++++++++++++++++-------------- 1 file changed, 38 insertions(+), 35 deletions(-) diff --git a/spec/models/username_block_spec.rb b/spec/models/username_block_spec.rb index fc14f0a5431..78e78705478 100644 --- a/spec/models/username_block_spec.rb +++ b/spec/models/username_block_spec.rb @@ -61,47 +61,50 @@ RSpec.describe UsernameBlock do end end - describe 'instance methods' do - subject(:username_block) { described_class.new } + describe '#comparison' do + subject { username_block.comparison } - describe '#comparison' do - subject(:username_block) { described_class.new(exact: exact) } + let(:username_block) { Fabricate.build(:username_block, exact: exact) } - context 'when exact is true' do - let(:exact) { true } + context 'when exact is true' do + let(:exact) { true } - it 'returns equals' do - expect(username_block.comparison).to eq('equals') - end - end - - context 'when exact is false' do - let(:exact) { false } - - it 'returns contains' do - expect(username_block.comparison).to eq('contains') - end - end + it { is_expected.to eq('equals') } end - describe '#comparison=' do - it 'sets exact to true when equals is passed' do - username_block.comparison = 'equals' - expect(username_block.exact).to be(true) - end + context 'when exact is false' do + let(:exact) { false } - it 'sets exact to false when contains is passed' do - username_block.comparison = 'contains' - expect(username_block.exact).to be(false) - end - end - - describe '#to_log_human_identifier' do - it 'returns the username' do - username_block.username = 'harry' - - expect(username_block.to_log_human_identifier).to eq('harry') - end + it { is_expected.to eq('contains') } end end + + describe '#comparison=' do + subject do + username_block.comparison = comparison + username_block.exact + end + + let(:username_block) { Fabricate.build(:username_block) } + + context 'when comparison is equals' do + let(:comparison) { 'equals' } + + it { is_expected.to be(true) } + end + + context 'when comparison is contains' do + let(:comparison) { 'contains' } + + it { is_expected.to be(false) } + end + end + + describe '#to_log_human_identifier' do + subject { username_block.to_log_human_identifier } + + let(:username_block) { Fabricate.build(:username_block, username: 'harry') } + + it { is_expected.to eq('harry') } + end end