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

@@ -105,7 +105,7 @@ describe "Admin budget investments" do
expect(page).to have_content("Health")
end
budget_investment3.update(administrator_id: admin.id)
budget_investment3.update!(administrator_id: admin.id)
visit admin_budget_budget_investments_path(budget_id: budget.id)
within("#budget_investment_#{budget_investment3.id}") do
@@ -518,8 +518,8 @@ describe "Admin budget investments" do
investment1.set_tag_list_on(:valuation, "Teachers")
investment2.set_tag_list_on(:valuation, "Hospitals")
investment1.save
investment2.save
investment1.save!
investment2.save!
visit admin_budget_budget_investments_path(budget_id: budget.id)
@@ -534,8 +534,8 @@ describe "Admin budget investments" do
investment1.set_tag_list_on(:valuation, "Roads")
investment2.set_tag_list_on(:valuation, "Accessibility")
investment1.save
investment2.save
investment1.save!
investment2.save!
visit admin_budget_budget_investments_path(budget_id: budget.id)
@@ -544,7 +544,7 @@ describe "Admin budget investments" do
end
scenario "Disable 'Calculate winner' button if incorrect phase" do
budget.update(phase: "reviewing_ballots")
budget.update!(phase: "reviewing_ballots")
visit admin_budget_budget_investments_path(budget)
@@ -558,7 +558,7 @@ describe "Admin budget investments" do
expect(page).to have_link "Calculate Winner Investments"
budget.update(phase: "accepting")
budget.update!(phase: "accepting")
visit admin_budget_budget_investments_path(budget)
@@ -1202,7 +1202,7 @@ describe "Admin budget investments" do
scenario "Adds existing valuation tags", :js do
budget_investment1 = create(:budget_investment)
budget_investment1.set_tag_list_on(:valuation, "Education, Health")
budget_investment1.save
budget_investment1.save!
budget_investment2 = create(:budget_investment)
@@ -1240,7 +1240,7 @@ describe "Admin budget investments" do
scenario "Changes valuation and user generated tags" do
budget_investment = create(:budget_investment, tag_list: "Park")
budget_investment.set_tag_list_on(:valuation, "Education")
budget_investment.save
budget_investment.save!
visit admin_budget_budget_investment_path(budget_investment.budget, budget_investment)
@@ -1480,7 +1480,7 @@ describe "Admin budget investments" do
end
scenario "Show only selected text when budget is finished" do
budget.update(phase: "finished")
budget.update!(phase: "finished")
visit admin_budget_budget_investments_path(budget)
@@ -1582,8 +1582,8 @@ describe "Admin budget investments" do
scenario "Mark as visible to valuator", :js do
investment1.valuators << valuator
investment2.valuators << valuator
investment1.update(administrator: admin)
investment2.update(administrator: admin)
investment1.update!(administrator: admin)
investment2.update!(administrator: admin)
visit admin_budget_budget_investments_path(budget)
click_link "Advanced filters"
@@ -1605,13 +1605,13 @@ describe "Admin budget investments" do
end
scenario "Shows the correct investments to valuators" do
investment1.update(visible_to_valuators: true)
investment2.update(visible_to_valuators: false)
investment1.update!(visible_to_valuators: true)
investment2.update!(visible_to_valuators: false)
investment1.valuators << valuator
investment2.valuators << valuator
investment1.update(administrator: admin)
investment2.update(administrator: admin)
investment1.update!(administrator: admin)
investment2.update!(administrator: admin)
login_as(valuator.user.reload)
visit root_path
@@ -1627,12 +1627,12 @@ describe "Admin budget investments" do
end
scenario "Unmark as visible to valuator", :js do
budget.update(phase: "valuating")
budget.update!(phase: "valuating")
investment1.valuators << valuator
investment2.valuators << valuator
investment1.update(administrator: admin, visible_to_valuators: true)
investment2.update(administrator: admin, visible_to_valuators: true)
investment1.update!(administrator: admin, visible_to_valuators: true)
investment2.update!(administrator: admin, visible_to_valuators: true)
visit admin_budget_budget_investments_path(budget)
@@ -1682,7 +1682,7 @@ describe "Admin budget investments" do
scenario "Keeps the valuation tags", :js do
investment1.set_tag_list_on(:valuation, %w[Possimpible Truthiness])
investment1.save
investment1.save!
visit admin_budget_budget_investments_path(budget)