From 9bb2bfdd068afffe910f398bb6e960bdd942a980 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 8 Sep 2023 13:15:32 +0200 Subject: [PATCH] Add and apply RSpec/Rails/NegationBeValid rule This rule was added in rubocop-rspec 2.23.0. We were already applying it most of the time. --- .rubocop.yml | 3 +++ spec/models/budget/content_block_spec.rb | 2 +- spec/models/legislation/answer_spec.rb | 2 +- spec/models/legislation/process_spec.rb | 24 +++++++++---------- .../site_customization/content_block_spec.rb | 2 +- spec/models/site_customization/page_spec.rb | 2 +- 6 files changed, 19 insertions(+), 16 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 1e8dc07ad..83e79bbaa 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -561,6 +561,9 @@ RSpec/Rails/HaveHttpStatus: RSpec/Rails/InferredSpecType: Enabled: true +RSpec/Rails/NegationBeValid: + Enabled: true + RSpec/Rails/TravelAround: Enabled: true diff --git a/spec/models/budget/content_block_spec.rb b/spec/models/budget/content_block_spec.rb index 9c54ffb24..543035e6e 100644 --- a/spec/models/budget/content_block_spec.rb +++ b/spec/models/budget/content_block_spec.rb @@ -12,7 +12,7 @@ describe Budget::ContentBlock do invalid_block = build(:heading_content_block, heading: heading_content_block_en.heading, locale: "en") - expect(invalid_block).to be_invalid + expect(invalid_block).not_to be_valid expect(invalid_block.errors.full_messages).to include("Heading has already been taken") valid_block = build(:heading_content_block, diff --git a/spec/models/legislation/answer_spec.rb b/spec/models/legislation/answer_spec.rb index faec3c406..6d33220eb 100644 --- a/spec/models/legislation/answer_spec.rb +++ b/spec/models/legislation/answer_spec.rb @@ -30,7 +30,7 @@ RSpec.describe Legislation::Answer do expect(answer).to be_valid second_answer = build(:legislation_answer, question: question, question_option: option_1, user: user) - expect(second_answer).to be_invalid + expect(second_answer).not_to be_valid expect(question.answers_count).to eq 1 expect(option_2.answers_count).to eq 1 diff --git a/spec/models/legislation/process_spec.rb b/spec/models/legislation/process_spec.rb index dde6408b2..5b62b98f4 100644 --- a/spec/models/legislation/process_spec.rb +++ b/spec/models/legislation/process_spec.rb @@ -28,42 +28,42 @@ describe Legislation::Process do it "is invalid if draft is enabled but draft_start_date is not present" do process = build(:legislation_process, draft_phase_enabled: true, draft_start_date: nil) - expect(process).to be_invalid + expect(process).not_to be_valid expect(process.errors.messages[:draft_start_date]).to include("can't be blank") end it "is invalid if draft is enabled but draft_end_date is not present" do process = build(:legislation_process, draft_phase_enabled: true, draft_end_date: "") - expect(process).to be_invalid + expect(process).not_to be_valid expect(process.errors.messages[:draft_end_date]).to include("can't be blank") end it "is invalid if debate phase is enabled but debate_start_date is not present" do process = build(:legislation_process, debate_phase_enabled: true, debate_start_date: nil) - expect(process).to be_invalid + expect(process).not_to be_valid expect(process.errors.messages[:debate_start_date]).to include("can't be blank") end it "is invalid if debate phase is enabled but debate_end_date is not present" do process = build(:legislation_process, debate_phase_enabled: true, debate_end_date: "") - expect(process).to be_invalid + expect(process).not_to be_valid expect(process.errors.messages[:debate_end_date]).to include("can't be blank") end it "is invalid if proposals phase is enabled but proposals_phase_start_date is not present" do process = build(:legislation_process, proposals_phase_enabled: true, proposals_phase_start_date: nil) - expect(process).to be_invalid + expect(process).not_to be_valid expect(process.errors.messages[:proposals_phase_start_date]).to include("can't be blank") end it "is invalid if proposals phase is enabled but proposals_phase_end_date is not present" do process = build(:legislation_process, proposals_phase_enabled: true, proposals_phase_end_date: "") - expect(process).to be_invalid + expect(process).not_to be_valid expect(process.errors.messages[:proposals_phase_end_date]).to include("can't be blank") end @@ -71,14 +71,14 @@ describe Legislation::Process do process = build(:legislation_process, allegations_phase_enabled: true, allegations_start_date: nil,) - expect(process).to be_invalid + expect(process).not_to be_valid expect(process.errors.messages[:allegations_start_date]).to include("can't be blank") end it "is invalid if allegations phase is enabled but allegations_end_date is not present" do process = build(:legislation_process, allegations_phase_enabled: true, allegations_end_date: "") - expect(process).to be_invalid + expect(process).not_to be_valid expect(process.errors.messages[:allegations_end_date]).to include("can't be blank") end @@ -160,7 +160,7 @@ describe Legislation::Process do it "is invalid if end_date is before start_date" do process = build(:legislation_process, start_date: Date.current, end_date: Date.current - 1.day) - expect(process).to be_invalid + expect(process).not_to be_valid expect(process.errors.messages[:end_date]).to include("must be on or after the start date") end @@ -179,7 +179,7 @@ describe Legislation::Process do it "is invalid if debate_end_date is before debate_start_date" do process = build(:legislation_process, debate_start_date: Date.current, debate_end_date: Date.current - 1.day) - expect(process).to be_invalid + expect(process).not_to be_valid expect(process.errors.messages[:debate_end_date]) .to include("must be on or after the debate start date") end @@ -193,7 +193,7 @@ describe Legislation::Process do it "is invalid if draft_end_date is before draft_start_date" do process = build(:legislation_process, draft_start_date: Date.current, draft_end_date: Date.current - 1.day) - expect(process).to be_invalid + expect(process).not_to be_valid expect(process.errors.messages[:draft_end_date]) .to include("must be on or after the draft start date") end @@ -201,7 +201,7 @@ describe Legislation::Process do it "is invalid if allegations_end_date is before allegations_start_date" do process = build(:legislation_process, allegations_start_date: Date.current, allegations_end_date: Date.current - 1.day) - expect(process).to be_invalid + expect(process).not_to be_valid expect(process.errors.messages[:allegations_end_date]) .to include("must be on or after the comments start date") end diff --git a/spec/models/site_customization/content_block_spec.rb b/spec/models/site_customization/content_block_spec.rb index 056a273ee..a61753f12 100644 --- a/spec/models/site_customization/content_block_spec.rb +++ b/spec/models/site_customization/content_block_spec.rb @@ -11,7 +11,7 @@ RSpec.describe SiteCustomization::ContentBlock do create(:site_customization_content_block, name: "top_links", locale: "en") invalid_block = build(:site_customization_content_block, name: "top_links", locale: "en") - expect(invalid_block).to be_invalid + expect(invalid_block).not_to be_valid expect(invalid_block.errors.full_messages).to include("Name has already been taken") valid_block = build(:site_customization_content_block, name: "top_links", locale: "es") diff --git a/spec/models/site_customization/page_spec.rb b/spec/models/site_customization/page_spec.rb index 8ab77b4d3..5c03d776f 100644 --- a/spec/models/site_customization/page_spec.rb +++ b/spec/models/site_customization/page_spec.rb @@ -11,7 +11,7 @@ RSpec.describe SiteCustomization::Page do it "is invalid if slug has symbols" do custom_page = build(:site_customization_page, slug: "as/as*la") - expect(custom_page).to be_invalid + expect(custom_page).not_to be_valid end it "dynamically validates the valid statuses" do