Apply Rails/SaveBang rubocop rule

Having exceptions is better than having silent bugs.

There are a few methods I've kept the same way they were.

The `RelatedContentScore#score_with_opposite` method is a bit peculiar:
it creates scores for both itself and the opposite related content,
which means the opposite related content will try to create the same
scores as well.

We've already got a test to check `Budget::Ballot#add_investment` when
creating a line fails ("Edge case voting a non-elegible investment").

Finally, the method `User#send_oauth_confirmation_instructions` doesn't
update the record when the email address isn't already present, leading
to the test "Try to register with the email of an already existing user,
when an unconfirmed email was provided by oauth" fo fail if we raise an
exception for an invalid user. That's because updating a user's email
doesn't update the database automatically, but instead a confirmation
email is sent.

There are also a few false positives for classes which don't have bang
methods (like the GraphQL classes) or destroying attachments.

For these reasons, I'm adding the rule with a "Refactor" severity,
meaning it's a rule we can break if necessary.
This commit is contained in:
Javi Martín
2019-10-20 03:54:56 +02:00
parent 777fb55399
commit 7ca55c44e0
167 changed files with 645 additions and 645 deletions

View File

@@ -35,19 +35,19 @@ describe Poll::Shift do
end
it "is not valid with same booth, officer, date and task" do
recount_shift.save
recount_shift.save!
expect(build(:poll_shift, booth: booth, officer: officer, date: Date.current, task: :recount_scrutiny)).not_to be_valid
end
it "is valid with same booth, officer and date but different task" do
recount_shift.save
recount_shift.save!
expect(build(:poll_shift, booth: booth, officer: officer, date: Date.current, task: :vote_collection)).to be_valid
end
it "is valid with same booth, officer and task but different date" do
recount_shift.save
recount_shift.save!
expect(build(:poll_shift, booth: booth, officer: officer, date: Date.tomorrow, task: :recount_scrutiny)).to be_valid
end
@@ -83,7 +83,7 @@ describe Poll::Shift do
it "creates final officer_assignments" do
booth_assignment = create(:poll_booth_assignment, poll: poll, booth: booth)
recount_shift.save
recount_shift.save!
officer_assignments = Poll::OfficerAssignment.all
expect(officer_assignments.count).to eq(1)
@@ -102,14 +102,14 @@ describe Poll::Shift do
let(:shift) { create(:poll_shift, officer: officer, booth: booth) }
it "maintains officer data after destroying associated user" do
shift.officer.user.destroy
shift.officer.user.destroy!
expect(shift.officer_name).to eq "Ana"
expect(shift.officer_email).to eq "ana@example.com"
end
it "maintains officer data after destroying officer role" do
shift.officer.destroy
shift.officer.destroy!
expect(shift.officer_name).to eq "Ana"
expect(shift.officer_email).to eq "ana@example.com"