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.
This commit is contained in:
Javi Martín
2023-09-08 13:15:32 +02:00
parent fc0511f4d3
commit 9bb2bfdd06
6 changed files with 19 additions and 16 deletions

View File

@@ -561,6 +561,9 @@ RSpec/Rails/HaveHttpStatus:
RSpec/Rails/InferredSpecType: RSpec/Rails/InferredSpecType:
Enabled: true Enabled: true
RSpec/Rails/NegationBeValid:
Enabled: true
RSpec/Rails/TravelAround: RSpec/Rails/TravelAround:
Enabled: true Enabled: true

View File

@@ -12,7 +12,7 @@ describe Budget::ContentBlock do
invalid_block = build(:heading_content_block, invalid_block = build(:heading_content_block,
heading: heading_content_block_en.heading, locale: "en") 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") expect(invalid_block.errors.full_messages).to include("Heading has already been taken")
valid_block = build(:heading_content_block, valid_block = build(:heading_content_block,

View File

@@ -30,7 +30,7 @@ RSpec.describe Legislation::Answer do
expect(answer).to be_valid expect(answer).to be_valid
second_answer = build(:legislation_answer, question: question, question_option: option_1, user: user) 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(question.answers_count).to eq 1
expect(option_2.answers_count).to eq 1 expect(option_2.answers_count).to eq 1

View File

@@ -28,42 +28,42 @@ describe Legislation::Process do
it "is invalid if draft is enabled but draft_start_date is not present" 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) 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") expect(process.errors.messages[:draft_start_date]).to include("can't be blank")
end end
it "is invalid if draft is enabled but draft_end_date is not present" do 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: "") 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") expect(process.errors.messages[:draft_end_date]).to include("can't be blank")
end end
it "is invalid if debate phase is enabled but debate_start_date is not present" do 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) 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") expect(process.errors.messages[:debate_start_date]).to include("can't be blank")
end end
it "is invalid if debate phase is enabled but debate_end_date is not present" do 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: "") 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") expect(process.errors.messages[:debate_end_date]).to include("can't be blank")
end end
it "is invalid if proposals phase is enabled but proposals_phase_start_date is not present" do 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) 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") expect(process.errors.messages[:proposals_phase_start_date]).to include("can't be blank")
end end
it "is invalid if proposals phase is enabled but proposals_phase_end_date is not present" do 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: "") 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") expect(process.errors.messages[:proposals_phase_end_date]).to include("can't be blank")
end end
@@ -71,14 +71,14 @@ describe Legislation::Process do
process = build(:legislation_process, allegations_phase_enabled: true, process = build(:legislation_process, allegations_phase_enabled: true,
allegations_start_date: nil,) 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") expect(process.errors.messages[:allegations_start_date]).to include("can't be blank")
end end
it "is invalid if allegations phase is enabled but allegations_end_date is not present" do 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: "") 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") expect(process.errors.messages[:allegations_end_date]).to include("can't be blank")
end end
@@ -160,7 +160,7 @@ describe Legislation::Process do
it "is invalid if end_date is before start_date" do it "is invalid if end_date is before start_date" do
process = build(:legislation_process, start_date: Date.current, process = build(:legislation_process, start_date: Date.current,
end_date: Date.current - 1.day) 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") expect(process.errors.messages[:end_date]).to include("must be on or after the start date")
end end
@@ -179,7 +179,7 @@ describe Legislation::Process do
it "is invalid if debate_end_date is before debate_start_date" do it "is invalid if debate_end_date is before debate_start_date" do
process = build(:legislation_process, debate_start_date: Date.current, process = build(:legislation_process, debate_start_date: Date.current,
debate_end_date: Date.current - 1.day) 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]) expect(process.errors.messages[:debate_end_date])
.to include("must be on or after the debate start date") .to include("must be on or after the debate start date")
end end
@@ -193,7 +193,7 @@ describe Legislation::Process do
it "is invalid if draft_end_date is before draft_start_date" do it "is invalid if draft_end_date is before draft_start_date" do
process = build(:legislation_process, draft_start_date: Date.current, process = build(:legislation_process, draft_start_date: Date.current,
draft_end_date: Date.current - 1.day) 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]) expect(process.errors.messages[:draft_end_date])
.to include("must be on or after the draft start date") .to include("must be on or after the draft start date")
end end
@@ -201,7 +201,7 @@ describe Legislation::Process do
it "is invalid if allegations_end_date is before allegations_start_date" do it "is invalid if allegations_end_date is before allegations_start_date" do
process = build(:legislation_process, allegations_start_date: Date.current, process = build(:legislation_process, allegations_start_date: Date.current,
allegations_end_date: Date.current - 1.day) 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]) expect(process.errors.messages[:allegations_end_date])
.to include("must be on or after the comments start date") .to include("must be on or after the comments start date")
end end

View File

@@ -11,7 +11,7 @@ RSpec.describe SiteCustomization::ContentBlock do
create(:site_customization_content_block, name: "top_links", locale: "en") create(:site_customization_content_block, name: "top_links", locale: "en")
invalid_block = build(: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") 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") valid_block = build(:site_customization_content_block, name: "top_links", locale: "es")

View File

@@ -11,7 +11,7 @@ RSpec.describe SiteCustomization::Page do
it "is invalid if slug has symbols" do it "is invalid if slug has symbols" do
custom_page = build(:site_customization_page, slug: "as/as*la") custom_page = build(:site_customization_page, slug: "as/as*la")
expect(custom_page).to be_invalid expect(custom_page).not_to be_valid
end end
it "dynamically validates the valid statuses" do it "dynamically validates the valid statuses" do