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:
@@ -41,7 +41,7 @@ class Admin::AdminNotificationsController < Admin::BaseController
|
||||
|
||||
def destroy
|
||||
@admin_notification = AdminNotification.find(params[:id])
|
||||
@admin_notification.destroy
|
||||
@admin_notification.destroy!
|
||||
|
||||
notice = t("admin.admin_notifications.delete_success")
|
||||
redirect_to admin_admin_notifications_path, notice: notice
|
||||
|
||||
@@ -14,7 +14,7 @@ class Admin::AdministratorsController < Admin::BaseController
|
||||
|
||||
def create
|
||||
@administrator.user_id = params[:user_id]
|
||||
@administrator.save
|
||||
@administrator.save!
|
||||
|
||||
redirect_to admin_administrators_path
|
||||
end
|
||||
|
||||
@@ -31,7 +31,7 @@ class Admin::BannersController < Admin::BaseController
|
||||
end
|
||||
|
||||
def destroy
|
||||
@banner.destroy
|
||||
@banner.destroy!
|
||||
redirect_to admin_banners_path
|
||||
end
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ class Admin::BudgetGroupsController < Admin::BaseController
|
||||
if @group.headings.any?
|
||||
redirect_to groups_index, alert: t("admin.budget_groups.destroy.unable_notice")
|
||||
else
|
||||
@group.destroy
|
||||
@group.destroy!
|
||||
redirect_to groups_index, notice: t("admin.budget_groups.destroy.success_notice")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -37,7 +37,7 @@ class Admin::BudgetHeadingsController < Admin::BaseController
|
||||
|
||||
def destroy
|
||||
if @heading.can_be_deleted?
|
||||
@heading.destroy
|
||||
@heading.destroy!
|
||||
redirect_to headings_index, notice: t("admin.budget_headings.destroy.success_notice")
|
||||
else
|
||||
redirect_to headings_index, alert: t("admin.budget_headings.destroy.unable_notice")
|
||||
|
||||
@@ -62,7 +62,7 @@ class Admin::BudgetInvestmentsController < Admin::BaseController
|
||||
|
||||
def toggle_selection
|
||||
@investment.toggle :selected
|
||||
@investment.save
|
||||
@investment.save!
|
||||
load_investments
|
||||
end
|
||||
|
||||
@@ -127,7 +127,7 @@ class Admin::BudgetInvestmentsController < Admin::BaseController
|
||||
|
||||
def load_ballot
|
||||
query = Budget::Ballot.where(user: current_user, budget: @budget)
|
||||
@ballot = @budget.balloting? ? query.first_or_create : query.first_or_initialize
|
||||
@ballot = @budget.balloting? ? query.first_or_create! : query.first_or_initialize
|
||||
end
|
||||
|
||||
def parse_valuation_filters
|
||||
|
||||
@@ -66,7 +66,7 @@ class Admin::BudgetsController < Admin::BaseController
|
||||
elsif @budget.poll.present?
|
||||
redirect_to admin_budgets_path, alert: t("admin.budgets.destroy.unable_notice_polls")
|
||||
else
|
||||
@budget.destroy
|
||||
@budget.destroy!
|
||||
redirect_to admin_budgets_path, notice: t("admin.budgets.destroy.success_notice")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -15,7 +15,7 @@ class Admin::Dashboard::AdministratorTasksController < Admin::Dashboard::BaseCon
|
||||
def update
|
||||
authorize! :update, administrator_task
|
||||
|
||||
administrator_task.update(user: current_user, executed_at: Time.current)
|
||||
administrator_task.update!(user: current_user, executed_at: Time.current)
|
||||
redirect_to admin_dashboard_administrator_tasks_path,
|
||||
{ flash: { notice: t("admin.dashboard.administrator_tasks.update.success") }}
|
||||
end
|
||||
|
||||
@@ -34,7 +34,7 @@ class Admin::GeozonesController < Admin::BaseController
|
||||
|
||||
def destroy
|
||||
if @geozone.safe_to_destroy?
|
||||
@geozone.destroy
|
||||
@geozone.destroy!
|
||||
redirect_to admin_geozones_path, notice: t("admin.geozones.delete.success")
|
||||
else
|
||||
redirect_to admin_geozones_path, flash: { error: t("admin.geozones.delete.error") }
|
||||
|
||||
@@ -32,7 +32,7 @@ class Admin::Legislation::DraftVersionsController < Admin::Legislation::BaseCont
|
||||
end
|
||||
|
||||
def destroy
|
||||
@draft_version.destroy
|
||||
@draft_version.destroy!
|
||||
notice = t("admin.legislation.draft_versions.destroy.notice")
|
||||
redirect_to admin_legislation_process_draft_versions_path, notice: notice
|
||||
end
|
||||
|
||||
@@ -46,7 +46,7 @@ class Admin::Legislation::ProcessesController < Admin::Legislation::BaseControll
|
||||
end
|
||||
|
||||
def destroy
|
||||
@process.destroy
|
||||
@process.destroy!
|
||||
notice = t("admin.legislation.processes.destroy.notice")
|
||||
redirect_to admin_legislation_processes_path, notice: notice
|
||||
end
|
||||
@@ -93,7 +93,7 @@ class Admin::Legislation::ProcessesController < Admin::Legislation::BaseControll
|
||||
|
||||
def set_tag_list
|
||||
@process.set_tag_list_on(:customs, process_params[:custom_list])
|
||||
@process.save
|
||||
@process.save!
|
||||
end
|
||||
|
||||
def resource
|
||||
|
||||
@@ -33,7 +33,7 @@ class Admin::Legislation::QuestionsController < Admin::Legislation::BaseControll
|
||||
end
|
||||
|
||||
def destroy
|
||||
@question.destroy
|
||||
@question.destroy!
|
||||
notice = t("admin.legislation.questions.destroy.notice")
|
||||
redirect_to admin_legislation_process_questions_path, notice: notice
|
||||
end
|
||||
|
||||
@@ -26,7 +26,7 @@ class Admin::LocalCensusRecordsController < Admin::BaseController
|
||||
end
|
||||
|
||||
def destroy
|
||||
@local_census_record.destroy
|
||||
@local_census_record.destroy!
|
||||
redirect_to admin_local_census_records_path,
|
||||
notice: t("admin.local_census_records.destroy.notice")
|
||||
end
|
||||
|
||||
@@ -14,13 +14,13 @@ class Admin::ManagersController < Admin::BaseController
|
||||
|
||||
def create
|
||||
@manager.user_id = params[:user_id]
|
||||
@manager.save
|
||||
@manager.save!
|
||||
|
||||
redirect_to admin_managers_path
|
||||
end
|
||||
|
||||
def destroy
|
||||
@manager.destroy
|
||||
@manager.destroy!
|
||||
redirect_to admin_managers_path
|
||||
end
|
||||
end
|
||||
|
||||
@@ -34,7 +34,7 @@ class Admin::MilestoneStatusesController < Admin::BaseController
|
||||
end
|
||||
|
||||
def destroy
|
||||
@status.destroy
|
||||
@status.destroy!
|
||||
redirect_to admin_milestone_statuses_path,
|
||||
notice: t("admin.statuses.delete.notice")
|
||||
end
|
||||
|
||||
@@ -14,13 +14,13 @@ class Admin::ModeratorsController < Admin::BaseController
|
||||
|
||||
def create
|
||||
@moderator.user_id = params[:user_id]
|
||||
@moderator.save
|
||||
@moderator.save!
|
||||
|
||||
redirect_to admin_moderators_path
|
||||
end
|
||||
|
||||
def destroy
|
||||
@moderator.destroy
|
||||
@moderator.destroy!
|
||||
redirect_to admin_moderators_path
|
||||
end
|
||||
end
|
||||
|
||||
@@ -39,7 +39,7 @@ class Admin::NewslettersController < Admin::BaseController
|
||||
|
||||
def destroy
|
||||
@newsletter = Newsletter.find(params[:id])
|
||||
@newsletter.destroy
|
||||
@newsletter.destroy!
|
||||
|
||||
redirect_to admin_newsletters_path, notice: t("admin.newsletters.delete_success")
|
||||
end
|
||||
@@ -49,7 +49,7 @@ class Admin::NewslettersController < Admin::BaseController
|
||||
|
||||
if @newsletter.valid?
|
||||
@newsletter.delay.deliver
|
||||
@newsletter.update(sent_at: Time.current)
|
||||
@newsletter.update!(sent_at: Time.current)
|
||||
flash[:notice] = t("admin.newsletters.send_success")
|
||||
else
|
||||
flash[:error] = t("admin.segment_recipient.invalid_recipients_segment")
|
||||
|
||||
@@ -14,7 +14,7 @@ class Admin::OfficialsController < Admin::BaseController
|
||||
|
||||
def update
|
||||
@user = User.find(params[:id])
|
||||
@user.update(user_params)
|
||||
@user.update!(user_params)
|
||||
redirect_to admin_officials_path, notice: t("admin.officials.flash.official_updated")
|
||||
end
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ class Admin::Poll::BoothAssignmentsController < Admin::Poll::BaseController
|
||||
@booth_assignment = ::Poll::BoothAssignment.new(poll: @poll,
|
||||
booth: @booth)
|
||||
|
||||
@booth_assignment.save
|
||||
@booth_assignment.save!
|
||||
|
||||
respond_to do |format|
|
||||
format.js { render layout: false }
|
||||
@@ -41,7 +41,7 @@ class Admin::Poll::BoothAssignmentsController < Admin::Poll::BaseController
|
||||
@booth = Poll::Booth.find(booth_assignment_params[:booth_id])
|
||||
@booth_assignment = ::Poll::BoothAssignment.find(params[:id])
|
||||
|
||||
@booth_assignment.destroy
|
||||
@booth_assignment.destroy!
|
||||
|
||||
respond_to do |format|
|
||||
format.js { render layout: false }
|
||||
|
||||
@@ -20,13 +20,13 @@ class Admin::Poll::OfficersController < Admin::Poll::BaseController
|
||||
|
||||
def create
|
||||
@officer.user_id = params[:user_id]
|
||||
@officer.save
|
||||
@officer.save!
|
||||
|
||||
redirect_to admin_officers_path
|
||||
end
|
||||
|
||||
def destroy
|
||||
@officer.destroy
|
||||
@officer.destroy!
|
||||
redirect_to admin_officers_path
|
||||
end
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ class Admin::Poll::PollsController < Admin::Poll::BaseController
|
||||
if ::Poll::Voter.where(poll: @poll).any?
|
||||
redirect_to admin_poll_path(@poll), alert: t("admin.polls.destroy.unable_notice")
|
||||
else
|
||||
@poll.destroy
|
||||
@poll.destroy!
|
||||
|
||||
redirect_to admin_polls_path, notice: t("admin.polls.destroy.success_notice")
|
||||
end
|
||||
|
||||
@@ -22,7 +22,7 @@ class Admin::Poll::Questions::Answers::ImagesController < Admin::Poll::BaseContr
|
||||
|
||||
def destroy
|
||||
@image = ::Image.find(params[:id])
|
||||
@image.destroy
|
||||
@image.destroy!
|
||||
|
||||
respond_to do |format|
|
||||
format.js { render layout: false }
|
||||
|
||||
@@ -30,7 +30,7 @@ class Admin::Poll::ShiftsController < Admin::Poll::BaseController
|
||||
alert = t("admin.poll_shifts.flash.unable_to_destroy")
|
||||
redirect_to new_admin_booth_shift_path(@booth), alert: alert
|
||||
else
|
||||
@shift.destroy
|
||||
@shift.destroy!
|
||||
notice = t("admin.poll_shifts.flash.destroy")
|
||||
redirect_to new_admin_booth_shift_path(@booth), notice: notice
|
||||
end
|
||||
|
||||
@@ -22,7 +22,7 @@ class Admin::SettingsController < Admin::BaseController
|
||||
|
||||
def update
|
||||
@setting = Setting.find(params[:id])
|
||||
@setting.update(settings_params)
|
||||
@setting.update!(settings_params)
|
||||
redirect_to request_referer, notice: t("admin.settings.flash.updated")
|
||||
end
|
||||
|
||||
@@ -39,7 +39,7 @@ class Admin::SettingsController < Admin::BaseController
|
||||
mime_type_values = content_type_params.keys.map do |content_type|
|
||||
Setting.mime_types[group][content_type]
|
||||
end
|
||||
setting.update value: mime_type_values.join(" ")
|
||||
setting.update! value: mime_type_values.join(" ")
|
||||
redirect_to admin_settings_path, notice: t("admin.settings.flash.updated")
|
||||
end
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ class Admin::SiteCustomization::ContentBlocksController < Admin::SiteCustomizati
|
||||
if is_heading_content_block?(params[:site_customization_content_block][:name])
|
||||
heading_content_block = new_heading_content_block
|
||||
if heading_content_block.save
|
||||
@content_block.destroy
|
||||
@content_block.destroy!
|
||||
notice = t("admin.site_customization.content_blocks.create.notice")
|
||||
redirect_to admin_site_customization_content_blocks_path, notice: notice
|
||||
else
|
||||
@@ -61,13 +61,13 @@ class Admin::SiteCustomization::ContentBlocksController < Admin::SiteCustomizati
|
||||
end
|
||||
|
||||
def destroy
|
||||
@content_block.destroy
|
||||
@content_block.destroy!
|
||||
notice = t("admin.site_customization.content_blocks.destroy.notice")
|
||||
redirect_to admin_site_customization_content_blocks_path, notice: notice
|
||||
end
|
||||
|
||||
def delete_heading_content_block
|
||||
Budget::ContentBlock.find(params[:id]).destroy
|
||||
Budget::ContentBlock.find(params[:id]).destroy!
|
||||
notice = t("admin.site_customization.content_blocks.destroy.notice")
|
||||
redirect_to admin_site_customization_content_blocks_path, notice: notice
|
||||
end
|
||||
@@ -101,7 +101,7 @@ class Admin::SiteCustomization::ContentBlocksController < Admin::SiteCustomizati
|
||||
@content_block.locale = params[:locale]
|
||||
@content_block.body = params[:body]
|
||||
if @content_block.save
|
||||
heading_content_block.destroy
|
||||
heading_content_block.destroy!
|
||||
notice = t("admin.site_customization.content_blocks.update.notice")
|
||||
redirect_to admin_site_customization_content_blocks_path, notice: notice
|
||||
else
|
||||
|
||||
@@ -21,7 +21,7 @@ class Admin::SiteCustomization::DocumentsController < Admin::SiteCustomization::
|
||||
|
||||
def destroy
|
||||
@document = Document.find(params[:id])
|
||||
@document.destroy
|
||||
@document.destroy!
|
||||
|
||||
notice = t("admin.documents.destroy.success_notice")
|
||||
redirect_to admin_site_customization_documents_path, notice: notice
|
||||
|
||||
@@ -17,9 +17,9 @@ class Admin::SiteCustomization::InformationTextsController < Admin::SiteCustomiz
|
||||
if value == t(content[:id], locale: locale) || value.match(/translation missing/)
|
||||
next
|
||||
else
|
||||
text = I18nContent.find_or_create_by(key: content[:id])
|
||||
text = I18nContent.find_or_create_by!(key: content[:id])
|
||||
Globalize.locale = locale
|
||||
text.update(value: value)
|
||||
text.update!(value: value)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -27,7 +27,7 @@ class Admin::SiteCustomization::PagesController < Admin::SiteCustomization::Base
|
||||
end
|
||||
|
||||
def destroy
|
||||
@page.destroy
|
||||
@page.destroy!
|
||||
notice = t("admin.site_customization.pages.destroy.notice")
|
||||
redirect_to admin_site_customization_pages_path, notice: notice
|
||||
end
|
||||
|
||||
@@ -9,12 +9,12 @@ class Admin::TagsController < Admin::BaseController
|
||||
end
|
||||
|
||||
def create
|
||||
Tag.category.create(tag_params)
|
||||
Tag.category.create!(tag_params)
|
||||
redirect_to admin_tags_path
|
||||
end
|
||||
|
||||
def destroy
|
||||
@tag.destroy
|
||||
@tag.destroy!
|
||||
redirect_to admin_tags_path
|
||||
end
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ class Admin::TrackersController < Admin::BaseController
|
||||
|
||||
def create
|
||||
@tracker = Tracker.new(tracker_params)
|
||||
@tracker.save
|
||||
@tracker.save!
|
||||
|
||||
redirect_to admin_trackers_path
|
||||
end
|
||||
@@ -40,7 +40,7 @@ class Admin::TrackersController < Admin::BaseController
|
||||
end
|
||||
|
||||
def destroy
|
||||
@tracker.destroy
|
||||
@tracker.destroy!
|
||||
redirect_to admin_trackers_path
|
||||
end
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ class Admin::ValuatorGroupsController < Admin::BaseController
|
||||
|
||||
def destroy
|
||||
@group = ValuatorGroup.find(params[:id])
|
||||
@group.destroy
|
||||
@group.destroy!
|
||||
notice = t("flash.actions.destroy.valuator_group")
|
||||
redirect_to [:admin, :valuator_groups], notice: notice
|
||||
end
|
||||
|
||||
@@ -18,7 +18,7 @@ class Admin::ValuatorsController < Admin::BaseController
|
||||
|
||||
def create
|
||||
@valuator = Valuator.new(valuator_params)
|
||||
@valuator.save
|
||||
@valuator.save!
|
||||
|
||||
redirect_to admin_valuators_path
|
||||
end
|
||||
@@ -39,7 +39,7 @@ class Admin::ValuatorsController < Admin::BaseController
|
||||
end
|
||||
|
||||
def destroy
|
||||
@valuator.destroy
|
||||
@valuator.destroy!
|
||||
redirect_to admin_valuators_path
|
||||
end
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ class Admin::Widget::CardsController < Admin::BaseController
|
||||
|
||||
def destroy
|
||||
@card = ::Widget::Card.find(params[:id])
|
||||
@card.destroy
|
||||
@card.destroy!
|
||||
|
||||
redirect_to_customization_page_cards_or_homepage
|
||||
end
|
||||
|
||||
@@ -2,7 +2,7 @@ class Admin::Widget::FeedsController < Admin::BaseController
|
||||
|
||||
def update
|
||||
@feed = ::Widget::Feed.find(params[:id])
|
||||
@feed.update(feed_params)
|
||||
@feed.update!(feed_params)
|
||||
|
||||
head :ok
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user