From 37bcbeab4aead09c4884827b8a7625c5070ab192 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Thu, 24 Oct 2024 08:52:38 -0400 Subject: [PATCH] Simplify model validation spec in AccountModerationNote/ReportNote (#31792) --- spec/models/account_moderation_note_spec.rb | 31 +++++++++------------ spec/models/report_note_spec.rb | 31 +++++++++------------ 2 files changed, 26 insertions(+), 36 deletions(-) diff --git a/spec/models/account_moderation_note_spec.rb b/spec/models/account_moderation_note_spec.rb index 079774c49..f3bcff4cd 100644 --- a/spec/models/account_moderation_note_spec.rb +++ b/spec/models/account_moderation_note_spec.rb @@ -3,29 +3,24 @@ require 'rails_helper' RSpec.describe AccountModerationNote do - describe 'chronological scope' do - it 'returns account moderation notes oldest to newest' do - account = Fabricate(:account) - note1 = Fabricate(:account_moderation_note, target_account: account) - note2 = Fabricate(:account_moderation_note, target_account: account) + describe 'Scopes' do + describe '.chronological' do + it 'returns account moderation notes oldest to newest' do + account = Fabricate(:account) + note1 = Fabricate(:account_moderation_note, target_account: account) + note2 = Fabricate(:account_moderation_note, target_account: account) - expect(account.targeted_moderation_notes.chronological).to eq [note1, note2] + expect(account.targeted_moderation_notes.chronological).to eq [note1, note2] + end end end - describe 'validations' do - it 'is invalid if the content is empty' do - report = Fabricate.build(:account_moderation_note, content: '') - expect(report.valid?).to be false - end + describe 'Validations' do + subject { Fabricate.build :account_moderation_note } - it 'is invalid if content is longer than character limit' do - report = Fabricate.build(:account_moderation_note, content: comment_over_limit) - expect(report.valid?).to be false - end - - def comment_over_limit - Faker::Lorem.paragraph_by_chars(number: described_class::CONTENT_SIZE_LIMIT * 2) + describe 'content' do + it { is_expected.to_not allow_value('').for(:content) } + it { is_expected.to validate_length_of(:content).is_at_most(described_class::CONTENT_SIZE_LIMIT) } end end end diff --git a/spec/models/report_note_spec.rb b/spec/models/report_note_spec.rb index 417971c9a..0d1c0f619 100644 --- a/spec/models/report_note_spec.rb +++ b/spec/models/report_note_spec.rb @@ -3,29 +3,24 @@ require 'rails_helper' RSpec.describe ReportNote do - describe 'chronological scope' do - it 'returns report notes oldest to newest' do - report = Fabricate(:report) - note1 = Fabricate(:report_note, report: report) - note2 = Fabricate(:report_note, report: report) + describe 'Scopes' do + describe '.chronological' do + it 'returns report notes oldest to newest' do + report = Fabricate(:report) + note1 = Fabricate(:report_note, report: report) + note2 = Fabricate(:report_note, report: report) - expect(report.notes.chronological).to eq [note1, note2] + expect(report.notes.chronological).to eq [note1, note2] + end end end - describe 'validations' do - it 'is invalid if the content is empty' do - report = Fabricate.build(:report_note, content: '') - expect(report.valid?).to be false - end + describe 'Validations' do + subject { Fabricate.build :report_note } - it 'is invalid if content is longer than character limit' do - report = Fabricate.build(:report_note, content: comment_over_limit) - expect(report.valid?).to be false - end - - def comment_over_limit - Faker::Lorem.paragraph_by_chars(number: described_class::CONTENT_SIZE_LIMIT * 2) + describe 'content' do + it { is_expected.to_not allow_value('').for(:content) } + it { is_expected.to validate_length_of(:content).is_at_most(described_class::CONTENT_SIZE_LIMIT) } end end end