From b51e0bc3c7a3fd6b2f4b722eac452abb57c755c1 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Thu, 12 Dec 2024 04:09:35 -0500 Subject: [PATCH] Simplify model validation specs for `Report` (#33267) --- spec/models/report_spec.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/spec/models/report_spec.rb b/spec/models/report_spec.rb index 2384c73acc..0bee7dfed1 100644 --- a/spec/models/report_spec.rb +++ b/spec/models/report_spec.rb @@ -156,13 +156,13 @@ RSpec.describe Report do end end - describe 'validations' do + describe 'Validations' do let(:remote_account) { Fabricate(:account, domain: 'example.com', protocol: :activitypub, inbox_url: 'http://example.com/inbox') } it 'is invalid if comment is longer than character limit and reporter is local' do - report = Fabricate.build(:report, comment: comment_over_limit) - expect(report.valid?).to be false - expect(report).to model_have_error_on_field(:comment) + report = Fabricate.build(:report) + + expect(report).to_not allow_value(comment_over_limit).for(:comment) end it 'is valid if comment is longer than character limit and reporter is not local' do @@ -171,16 +171,16 @@ RSpec.describe Report do end it 'is invalid if it references invalid rules' do - report = Fabricate.build(:report, category: :violation, rule_ids: [-1]) - expect(report.valid?).to be false - expect(report).to model_have_error_on_field(:rule_ids) + report = Fabricate.build(:report, category: :violation) + + expect(report).to_not allow_value([-1]).for(:rule_ids) end it 'is invalid if it references rules but category is not "violation"' do rule = Fabricate(:rule) - report = Fabricate.build(:report, category: :spam, rule_ids: rule.id) - expect(report.valid?).to be false - expect(report).to model_have_error_on_field(:rule_ids) + report = Fabricate.build(:report, category: :spam) + + expect(report).to_not allow_value(rule.id).for(:rule_ids) end def comment_over_limit