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)

View File

@@ -185,7 +185,7 @@ describe "Admin budgets" do
let!(:budget) { create(:budget) }
scenario "Show phases table" do
budget.update(phase: "selecting")
budget.update!(phase: "selecting")
visit admin_budgets_path
click_link "Edit budget"
@@ -217,7 +217,7 @@ describe "Admin budgets" do
end
scenario "Changing name for current locale will update the slug if budget is in draft phase", :js do
budget.update(phase: "drafting")
budget.update!(phase: "drafting")
old_slug = budget.slug
visit edit_admin_budget_path(budget)

View File

@@ -48,7 +48,7 @@ describe "Admin change log" do
expect(page).to have_content(budget_investment.heading.name)
expect(page).to have_content("There are not changes logged")
budget_investment.update(title: "test")
budget_investment.update!(title: "test")
visit admin_budget_budget_investments_path(budget_investment.budget)

View File

@@ -12,7 +12,7 @@ describe "Admin milestone statuses" do
status1 = create(:milestone_status)
status2 = create(:milestone_status)
status1.destroy
status1.destroy!
visit admin_milestone_statuses_path

View File

@@ -244,7 +244,7 @@ describe "Admin shifts" do
officer = create(:poll_officer)
create(:poll_shift, officer: officer, booth: booth)
officer.destroy
officer.destroy!
visit new_admin_booth_shift_path(booth)

View File

@@ -103,7 +103,7 @@ describe "Admin settings" do
describe "Update content types" do
scenario "stores the correct mime types" do
setting = Setting.create(key: "upload.images.content_types", value: "image/png")
setting = Setting.create!(key: "upload.images.content_types", value: "image/png")
admin = create(:administrator).user
login_as(admin)
visit admin_settings_path
@@ -194,7 +194,7 @@ describe "Admin settings" do
end
scenario "On #tab-configuration", :js do
configuration_setting = Setting.create(key: "whatever")
configuration_setting = Setting.create!(key: "whatever")
admin = create(:administrator).user
login_as(admin)
visit admin_settings_path
@@ -216,7 +216,7 @@ describe "Admin settings" do
end
scenario "On #tab-map-configuration", :js do
map_setting = Setting.create(key: "map.whatever")
map_setting = Setting.create!(key: "map.whatever")
admin = create(:administrator).user
login_as(admin)
visit admin_settings_path
@@ -233,7 +233,7 @@ describe "Admin settings" do
end
scenario "On #tab-proposals", :js do
proposal_dashboard_setting = Setting.create(key: "proposals.whatever")
proposal_dashboard_setting = Setting.create!(key: "proposals.whatever")
admin = create(:administrator).user
login_as(admin)
visit admin_settings_path
@@ -249,7 +249,7 @@ describe "Admin settings" do
end
scenario "On #tab-participation-processes", :js do
process_setting = Setting.create(key: "process.whatever")
process_setting = Setting.create!(key: "process.whatever")
admin = create(:administrator).user
login_as(admin)
visit admin_settings_path
@@ -264,7 +264,7 @@ describe "Admin settings" do
end
scenario "On #tab-feature-flags", :js do
feature_setting = Setting.create(key: "feature.whatever")
feature_setting = Setting.create!(key: "feature.whatever")
admin = create(:administrator).user
login_as(admin)
visit admin_settings_path

View File

@@ -55,7 +55,7 @@ describe "Signature sheets" do
scenario "Budget Investment" do
investment = create(:budget_investment)
budget = investment.budget
budget.update(phase: "selecting")
budget.update!(phase: "selecting")
visit new_admin_signature_sheet_path
@@ -108,7 +108,7 @@ describe "Signature sheets" do
scenario "Budget Investment" do
investment = create(:budget_investment)
budget = investment.budget
budget.update(phase: "selecting")
budget.update!(phase: "selecting")
visit new_admin_signature_sheet_path

View File

@@ -285,7 +285,7 @@ describe "Stats" do
scenario "Deleted proposals" do
proposal_notification = create(:proposal_notification)
proposal_notification.proposal.destroy
proposal_notification.proposal.destroy!
visit admin_stats_path
click_link "Proposal notifications"

View File

@@ -2,7 +2,7 @@ require "rails_helper"
describe "Admin edit translatable records" do
before do
translatable.update(attributes)
translatable.update!(attributes)
login_as(create(:administrator).user)
end
@@ -311,7 +311,7 @@ describe "Admin edit translatable records" do
before do
translatable.translations.destroy_all
translatable.translations.create(locale: :fr, title: "Titre en Français")
translatable.translations.create!(locale: :fr, title: "Titre en Français")
end
scenario "Does not add a translation for the current locale" do
@@ -398,7 +398,7 @@ describe "Admin edit translatable records" do
let(:translatable) { create(:admin_notification, segment_recipient: "all_users") }
scenario "Shows first available fallback" do
translatable.update({ title_fr: "Titre en Français", body_fr: "Texte en Français" })
translatable.update!({ title_fr: "Titre en Français", body_fr: "Texte en Français" })
visit edit_admin_admin_notification_path(translatable)
@@ -417,7 +417,7 @@ describe "Admin edit translatable records" do
let(:translatable) { create(:budget).phases.last }
scenario "Shows first available fallback" do
translatable.update({ description_fr: "Phase en Français", summary_fr: "Phase résumé" })
translatable.update!({ description_fr: "Phase en Français", summary_fr: "Phase résumé" })
visit edit_admin_budget_budget_phase_path(translatable.budget, translatable)
@@ -438,7 +438,7 @@ describe "Admin edit translatable records" do
let(:translatable) { create(:active_poll) }
scenario "Shows first available fallback" do
translatable.update({ description_fr: "Sondage en Français" })
translatable.update!({ description_fr: "Sondage en Français" })
visit edit_admin_active_polls_path(translatable)

View File

@@ -96,7 +96,7 @@ describe "Valuator groups" do
end
scenario "Update a valuator's group" do
valuator.update(valuator_group: create(:valuator_group, name: "Economy"))
valuator.update!(valuator_group: create(:valuator_group, name: "Economy"))
create(:valuator_group, name: "Health")
visit edit_admin_valuator_path(valuator)
@@ -108,7 +108,7 @@ describe "Valuator groups" do
end
scenario "Remove a valuator from a group" do
valuator.update(valuator_group: create(:valuator_group, name: "Health"))
valuator.update!(valuator_group: create(:valuator_group, name: "Health"))
visit edit_admin_valuator_path(valuator)
select "", from: "valuator_valuator_group_id"