From 7ca55c44e044d997f3ad24dba3c7d995cbe8bfae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sun, 20 Oct 2019 03:54:56 +0200 Subject: [PATCH] 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. --- .rubocop.yml | 3 -- .rubocop_basic.yml | 4 ++ .../admin/admin_notifications_controller.rb | 2 +- .../admin/administrators_controller.rb | 2 +- app/controllers/admin/banners_controller.rb | 2 +- .../admin/budget_groups_controller.rb | 2 +- .../admin/budget_headings_controller.rb | 2 +- .../admin/budget_investments_controller.rb | 4 +- app/controllers/admin/budgets_controller.rb | 2 +- .../administrator_tasks_controller.rb | 2 +- app/controllers/admin/geozones_controller.rb | 2 +- .../legislation/draft_versions_controller.rb | 2 +- .../admin/legislation/processes_controller.rb | 4 +- .../admin/legislation/questions_controller.rb | 2 +- .../admin/local_census_records_controller.rb | 2 +- app/controllers/admin/managers_controller.rb | 4 +- .../admin/milestone_statuses_controller.rb | 2 +- .../admin/moderators_controller.rb | 4 +- .../admin/newsletters_controller.rb | 4 +- app/controllers/admin/officials_controller.rb | 2 +- .../poll/booth_assignments_controller.rb | 4 +- .../admin/poll/officers_controller.rb | 4 +- .../admin/poll/polls_controller.rb | 2 +- .../questions/answers/images_controller.rb | 2 +- .../admin/poll/shifts_controller.rb | 2 +- app/controllers/admin/settings_controller.rb | 4 +- .../content_blocks_controller.rb | 8 +-- .../documents_controller.rb | 2 +- .../information_texts_controller.rb | 4 +- .../site_customization/pages_controller.rb | 2 +- app/controllers/admin/tags_controller.rb | 4 +- app/controllers/admin/trackers_controller.rb | 4 +- .../admin/valuator_groups_controller.rb | 2 +- app/controllers/admin/valuators_controller.rb | 4 +- .../admin/widget/cards_controller.rb | 2 +- .../admin/widget/feeds_controller.rb | 2 +- .../budgets/ballot/lines_controller.rb | 4 +- app/controllers/budgets/ballots_controller.rb | 2 +- .../budgets/investments_controller.rb | 4 +- .../dashboard/actions_controller.rb | 4 +- app/controllers/dashboard/polls_controller.rb | 2 +- app/controllers/follows_controller.rb | 4 +- .../legislation/answers_controller.rb | 2 +- app/controllers/polls/answers_controller.rb | 2 +- .../related_contents_controller.rb | 2 +- .../remote_translations_controller.rb | 2 +- app/controllers/topics_controller.rb | 2 +- .../tracking/milestones_controller.rb | 2 +- .../tracking/progress_bars_controller.rb | 2 +- .../users/confirmations_controller.rb | 2 +- .../users/omniauth_callbacks_controller.rb | 2 +- .../verification/email_controller.rb | 2 +- .../verification/letter_controller.rb | 2 +- .../verification/sms_controller.rb | 2 +- app/models/activity.rb | 2 +- app/models/admin_notification.rb | 2 +- app/models/budget/investment.rb | 2 +- app/models/budget/result.rb | 2 +- app/models/concerns/communitable.rb | 2 +- app/models/download_setting.rb | 8 +-- app/models/flag.rb | 2 +- app/models/identity.rb | 2 +- app/models/local_census_records/import.rb | 2 +- app/models/lock.rb | 2 +- app/models/officing/residence.rb | 2 +- app/models/poll/ballot_sheet.rb | 4 +- app/models/poll/question/answer.rb | 6 +-- app/models/proposal.rb | 2 +- app/models/signature_sheet.rb | 4 +- app/models/user.rb | 16 +++--- app/models/verification/email.rb | 2 +- app/models/verification/management/email.rb | 10 ++-- app/models/votation_type.rb | 12 ++--- app/models/widget/feed.rb | 2 +- db/dev_seeds/banners.rb | 10 ++-- db/dev_seeds/budgets.rb | 6 +-- db/dev_seeds/geozones.rb | 44 +++++++-------- db/dev_seeds/milestones.rb | 8 +-- db/dev_seeds/polls.rb | 51 +++++++++--------- db/dev_seeds/proposals.rb | 2 +- db/dev_seeds/users.rb | 18 +++---- db/seeds.rb | 10 ++-- lib/email_digest.rb | 2 +- lib/tasks/proposal_actions.rake | 2 +- .../features/admin/budget_investments_spec.rb | 40 +++++++------- spec/features/admin/budgets_spec.rb | 4 +- spec/features/admin/change_log_spec.rb | 2 +- .../features/admin/milestone_statuses_spec.rb | 2 +- spec/features/admin/poll/shifts_spec.rb | 2 +- spec/features/admin/settings_spec.rb | 12 ++--- spec/features/admin/signature_sheets_spec.rb | 4 +- spec/features/admin/stats_spec.rb | 2 +- spec/features/admin/translatable_spec.rb | 10 ++-- spec/features/admin/valuator_groups_spec.rb | 4 +- spec/features/budgets/ballots_spec.rb | 8 +-- spec/features/budgets/budgets_spec.rb | 46 ++++++++-------- spec/features/budgets/executions_spec.rb | 8 +-- spec/features/budgets/investments_spec.rb | 34 ++++++------ spec/features/budgets/results_spec.rb | 6 +-- spec/features/budgets/stats_spec.rb | 2 +- spec/features/budgets/votes_spec.rb | 2 +- .../comments/legislation_questions_spec.rb | 2 +- spec/features/dashboard/dashboard_spec.rb | 8 +-- spec/features/emails_spec.rb | 16 +++--- spec/features/legislation/processes_spec.rb | 2 +- .../management/budget_investments_spec.rb | 2 +- .../moderation/budget_investments_spec.rb | 2 +- .../moderation/proposal_notifications_spec.rb | 2 +- spec/features/notifications_spec.rb | 4 +- spec/features/polls/polls_spec.rb | 12 ++--- spec/features/polls/results_spec.rb | 2 +- spec/features/polls/votation_type_spec.rb | 2 +- spec/features/tags/budget_investments_spec.rb | 12 ++--- spec/features/users_spec.rb | 6 +-- .../valuation/budget_investments_spec.rb | 14 ++--- spec/features/verification/email_spec.rb | 2 +- spec/features/votes_spec.rb | 2 +- spec/features/xss_spec.rb | 10 ++-- spec/lib/acts_as_taggable_on_spec.rb | 24 ++++----- spec/lib/graphql_spec.rb | 2 +- spec/lib/tasks/budgets_spec.rb | 4 +- spec/lib/tasks/dashboards_spec.rb | 20 +++---- spec/lib/user_segments_spec.rb | 44 +++++++-------- spec/mailers/dashboard/mailer_spec.rb | 24 ++++----- spec/models/abilities/valuator_spec.rb | 2 +- spec/models/admin_notification_spec.rb | 2 +- spec/models/budget/ballot/line_spec.rb | 8 +-- spec/models/budget/group_spec.rb | 4 +- spec/models/budget/heading_spec.rb | 4 +- spec/models/budget/investment_spec.rb | 46 ++++++++-------- spec/models/budget/result_spec.rb | 4 +- spec/models/budget_spec.rb | 22 ++++---- spec/models/concerns/globalizable.rb | 20 +++---- spec/models/concerns/reportable.rb | 12 ++--- spec/models/dashboard/action_spec.rb | 28 +++++----- spec/models/debate_spec.rb | 38 ++++++------- spec/models/legislation/process/phase_spec.rb | 54 +++++++++---------- .../legislation/process/publication_spec.rb | 28 +++++----- spec/models/legislation/process_spec.rb | 4 +- spec/models/lock_spec.rb | 6 +-- spec/models/newsletter_spec.rb | 2 +- spec/models/notification_spec.rb | 2 +- spec/models/officing/residence_spec.rb | 6 +-- spec/models/poll/ballot_sheet_spec.rb | 2 +- spec/models/poll/ballot_spec.rb | 16 +++--- spec/models/poll/booth_assignment_spec.rb | 2 +- spec/models/poll/officer_spec.rb | 4 +- spec/models/poll/partial_result_spec.rb | 12 ++--- spec/models/poll/recount_spec.rb | 24 ++++----- spec/models/poll/shift_spec.rb | 12 ++--- spec/models/poll/voter_spec.rb | 6 +-- spec/models/progress_bar_spec.rb | 4 +- spec/models/proposal_notification_spec.rb | 4 +- spec/models/proposal_spec.rb | 4 +- spec/models/setting_spec.rb | 34 ++++++------ spec/models/tag_spec.rb | 4 +- spec/models/user_spec.rb | 18 +++---- spec/models/verification/letter_spec.rb | 6 +-- spec/models/verification/residence_spec.rb | 4 +- spec/shared/features/remotely_translatable.rb | 4 +- spec/shared/models/acts_as_imageable.rb | 2 +- spec/shared/models/acts_as_paranoid.rb | 14 ++--- spec/shared/models/document_validations.rb | 4 +- spec/shared/models/image_validations.rb | 4 +- spec/shared/models/map_validations.rb | 2 +- spec/shared/models/notifiable.rb | 2 +- spec/support/verifiable.rb | 16 +++--- 167 files changed, 645 insertions(+), 645 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 0d299a03f..aab3cf58e 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -51,9 +51,6 @@ Rails/OutputSafety: Rails/ReversibleMigration: Enabled: true -Rails/SaveBang: - Enabled: true - Rails/SkipsModelValidations: Enabled: true diff --git a/.rubocop_basic.yml b/.rubocop_basic.yml index e71766516..81e130604 100644 --- a/.rubocop_basic.yml +++ b/.rubocop_basic.yml @@ -181,6 +181,10 @@ Rails/SafeNavigation: Enabled: true ConvertTry: true +Rails/SaveBang: + Enabled: true + Severity: refactor + Rails/TimeZone: Enabled: true diff --git a/app/controllers/admin/admin_notifications_controller.rb b/app/controllers/admin/admin_notifications_controller.rb index 430e51f53..b821bdf93 100644 --- a/app/controllers/admin/admin_notifications_controller.rb +++ b/app/controllers/admin/admin_notifications_controller.rb @@ -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 diff --git a/app/controllers/admin/administrators_controller.rb b/app/controllers/admin/administrators_controller.rb index 5e423be81..8e77a93e6 100644 --- a/app/controllers/admin/administrators_controller.rb +++ b/app/controllers/admin/administrators_controller.rb @@ -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 diff --git a/app/controllers/admin/banners_controller.rb b/app/controllers/admin/banners_controller.rb index fed5fe8c8..9acc6f2ee 100644 --- a/app/controllers/admin/banners_controller.rb +++ b/app/controllers/admin/banners_controller.rb @@ -31,7 +31,7 @@ class Admin::BannersController < Admin::BaseController end def destroy - @banner.destroy + @banner.destroy! redirect_to admin_banners_path end diff --git a/app/controllers/admin/budget_groups_controller.rb b/app/controllers/admin/budget_groups_controller.rb index 8e44b2101..5256aa3bc 100644 --- a/app/controllers/admin/budget_groups_controller.rb +++ b/app/controllers/admin/budget_groups_controller.rb @@ -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 diff --git a/app/controllers/admin/budget_headings_controller.rb b/app/controllers/admin/budget_headings_controller.rb index 659bf6760..399407524 100644 --- a/app/controllers/admin/budget_headings_controller.rb +++ b/app/controllers/admin/budget_headings_controller.rb @@ -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") diff --git a/app/controllers/admin/budget_investments_controller.rb b/app/controllers/admin/budget_investments_controller.rb index e9291e78d..c532ef320 100644 --- a/app/controllers/admin/budget_investments_controller.rb +++ b/app/controllers/admin/budget_investments_controller.rb @@ -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 diff --git a/app/controllers/admin/budgets_controller.rb b/app/controllers/admin/budgets_controller.rb index ce97a1bb5..ccd35d547 100644 --- a/app/controllers/admin/budgets_controller.rb +++ b/app/controllers/admin/budgets_controller.rb @@ -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 diff --git a/app/controllers/admin/dashboard/administrator_tasks_controller.rb b/app/controllers/admin/dashboard/administrator_tasks_controller.rb index df4b13aef..3d8f52c88 100644 --- a/app/controllers/admin/dashboard/administrator_tasks_controller.rb +++ b/app/controllers/admin/dashboard/administrator_tasks_controller.rb @@ -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 diff --git a/app/controllers/admin/geozones_controller.rb b/app/controllers/admin/geozones_controller.rb index def75ed27..31ce38bed 100644 --- a/app/controllers/admin/geozones_controller.rb +++ b/app/controllers/admin/geozones_controller.rb @@ -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") } diff --git a/app/controllers/admin/legislation/draft_versions_controller.rb b/app/controllers/admin/legislation/draft_versions_controller.rb index 26f266f90..72bd82eb1 100644 --- a/app/controllers/admin/legislation/draft_versions_controller.rb +++ b/app/controllers/admin/legislation/draft_versions_controller.rb @@ -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 diff --git a/app/controllers/admin/legislation/processes_controller.rb b/app/controllers/admin/legislation/processes_controller.rb index 679fb3897..6c082869e 100644 --- a/app/controllers/admin/legislation/processes_controller.rb +++ b/app/controllers/admin/legislation/processes_controller.rb @@ -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 diff --git a/app/controllers/admin/legislation/questions_controller.rb b/app/controllers/admin/legislation/questions_controller.rb index 43a17f967..268312378 100644 --- a/app/controllers/admin/legislation/questions_controller.rb +++ b/app/controllers/admin/legislation/questions_controller.rb @@ -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 diff --git a/app/controllers/admin/local_census_records_controller.rb b/app/controllers/admin/local_census_records_controller.rb index e5b7fc146..4c76186c3 100644 --- a/app/controllers/admin/local_census_records_controller.rb +++ b/app/controllers/admin/local_census_records_controller.rb @@ -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 diff --git a/app/controllers/admin/managers_controller.rb b/app/controllers/admin/managers_controller.rb index 865ead3be..e001d5b72 100644 --- a/app/controllers/admin/managers_controller.rb +++ b/app/controllers/admin/managers_controller.rb @@ -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 diff --git a/app/controllers/admin/milestone_statuses_controller.rb b/app/controllers/admin/milestone_statuses_controller.rb index f365629c0..ccffa6669 100644 --- a/app/controllers/admin/milestone_statuses_controller.rb +++ b/app/controllers/admin/milestone_statuses_controller.rb @@ -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 diff --git a/app/controllers/admin/moderators_controller.rb b/app/controllers/admin/moderators_controller.rb index cd5072aa8..8d7508a12 100644 --- a/app/controllers/admin/moderators_controller.rb +++ b/app/controllers/admin/moderators_controller.rb @@ -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 diff --git a/app/controllers/admin/newsletters_controller.rb b/app/controllers/admin/newsletters_controller.rb index 8b1c2010f..ab5dc227e 100644 --- a/app/controllers/admin/newsletters_controller.rb +++ b/app/controllers/admin/newsletters_controller.rb @@ -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") diff --git a/app/controllers/admin/officials_controller.rb b/app/controllers/admin/officials_controller.rb index 5cc004c54..0b21b8533 100644 --- a/app/controllers/admin/officials_controller.rb +++ b/app/controllers/admin/officials_controller.rb @@ -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 diff --git a/app/controllers/admin/poll/booth_assignments_controller.rb b/app/controllers/admin/poll/booth_assignments_controller.rb index 627e18ef0..d932bd806 100644 --- a/app/controllers/admin/poll/booth_assignments_controller.rb +++ b/app/controllers/admin/poll/booth_assignments_controller.rb @@ -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 } diff --git a/app/controllers/admin/poll/officers_controller.rb b/app/controllers/admin/poll/officers_controller.rb index 5a24251c4..e0fc47189 100644 --- a/app/controllers/admin/poll/officers_controller.rb +++ b/app/controllers/admin/poll/officers_controller.rb @@ -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 diff --git a/app/controllers/admin/poll/polls_controller.rb b/app/controllers/admin/poll/polls_controller.rb index e9e9539a3..75fae91ff 100644 --- a/app/controllers/admin/poll/polls_controller.rb +++ b/app/controllers/admin/poll/polls_controller.rb @@ -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 diff --git a/app/controllers/admin/poll/questions/answers/images_controller.rb b/app/controllers/admin/poll/questions/answers/images_controller.rb index 1df4500ef..a312ec7d2 100644 --- a/app/controllers/admin/poll/questions/answers/images_controller.rb +++ b/app/controllers/admin/poll/questions/answers/images_controller.rb @@ -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 } diff --git a/app/controllers/admin/poll/shifts_controller.rb b/app/controllers/admin/poll/shifts_controller.rb index 3396224dc..acfc7371a 100644 --- a/app/controllers/admin/poll/shifts_controller.rb +++ b/app/controllers/admin/poll/shifts_controller.rb @@ -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 diff --git a/app/controllers/admin/settings_controller.rb b/app/controllers/admin/settings_controller.rb index fdbc2b4d5..13b632cab 100644 --- a/app/controllers/admin/settings_controller.rb +++ b/app/controllers/admin/settings_controller.rb @@ -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 diff --git a/app/controllers/admin/site_customization/content_blocks_controller.rb b/app/controllers/admin/site_customization/content_blocks_controller.rb index d92dbc88e..54b695342 100644 --- a/app/controllers/admin/site_customization/content_blocks_controller.rb +++ b/app/controllers/admin/site_customization/content_blocks_controller.rb @@ -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 diff --git a/app/controllers/admin/site_customization/documents_controller.rb b/app/controllers/admin/site_customization/documents_controller.rb index 51cee4227..a8ebbd772 100644 --- a/app/controllers/admin/site_customization/documents_controller.rb +++ b/app/controllers/admin/site_customization/documents_controller.rb @@ -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 diff --git a/app/controllers/admin/site_customization/information_texts_controller.rb b/app/controllers/admin/site_customization/information_texts_controller.rb index 4c4b07a81..2099029bd 100644 --- a/app/controllers/admin/site_customization/information_texts_controller.rb +++ b/app/controllers/admin/site_customization/information_texts_controller.rb @@ -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 diff --git a/app/controllers/admin/site_customization/pages_controller.rb b/app/controllers/admin/site_customization/pages_controller.rb index ac2c1d0bc..05bf705f7 100644 --- a/app/controllers/admin/site_customization/pages_controller.rb +++ b/app/controllers/admin/site_customization/pages_controller.rb @@ -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 diff --git a/app/controllers/admin/tags_controller.rb b/app/controllers/admin/tags_controller.rb index 5e53033c5..eebd93f6d 100644 --- a/app/controllers/admin/tags_controller.rb +++ b/app/controllers/admin/tags_controller.rb @@ -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 diff --git a/app/controllers/admin/trackers_controller.rb b/app/controllers/admin/trackers_controller.rb index 538b614f7..071e26d12 100644 --- a/app/controllers/admin/trackers_controller.rb +++ b/app/controllers/admin/trackers_controller.rb @@ -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 diff --git a/app/controllers/admin/valuator_groups_controller.rb b/app/controllers/admin/valuator_groups_controller.rb index 7e2e6bb16..a21450219 100644 --- a/app/controllers/admin/valuator_groups_controller.rb +++ b/app/controllers/admin/valuator_groups_controller.rb @@ -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 diff --git a/app/controllers/admin/valuators_controller.rb b/app/controllers/admin/valuators_controller.rb index 6dc827684..d44d0d200 100644 --- a/app/controllers/admin/valuators_controller.rb +++ b/app/controllers/admin/valuators_controller.rb @@ -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 diff --git a/app/controllers/admin/widget/cards_controller.rb b/app/controllers/admin/widget/cards_controller.rb index 514df854e..097babad3 100644 --- a/app/controllers/admin/widget/cards_controller.rb +++ b/app/controllers/admin/widget/cards_controller.rb @@ -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 diff --git a/app/controllers/admin/widget/feeds_controller.rb b/app/controllers/admin/widget/feeds_controller.rb index 2becdf28a..70af52244 100644 --- a/app/controllers/admin/widget/feeds_controller.rb +++ b/app/controllers/admin/widget/feeds_controller.rb @@ -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 diff --git a/app/controllers/budgets/ballot/lines_controller.rb b/app/controllers/budgets/ballot/lines_controller.rb index 4d255e2bd..242c3848d 100644 --- a/app/controllers/budgets/ballot/lines_controller.rb +++ b/app/controllers/budgets/ballot/lines_controller.rb @@ -26,7 +26,7 @@ module Budgets load_heading load_map - @line.destroy + @line.destroy! load_investments end @@ -41,7 +41,7 @@ module Budgets end def load_ballot - @ballot = Budget::Ballot.where(user: current_user, budget: @budget).first_or_create + @ballot = Budget::Ballot.where(user: current_user, budget: @budget).first_or_create! end def load_investment diff --git a/app/controllers/budgets/ballots_controller.rb b/app/controllers/budgets/ballots_controller.rb index 91286e2ec..0a7b1ce03 100644 --- a/app/controllers/budgets/ballots_controller.rb +++ b/app/controllers/budgets/ballots_controller.rb @@ -20,7 +20,7 @@ module Budgets 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 store_referer diff --git a/app/controllers/budgets/investments_controller.rb b/app/controllers/budgets/investments_controller.rb index 7bbec323e..59a1c930e 100644 --- a/app/controllers/budgets/investments_controller.rb +++ b/app/controllers/budgets/investments_controller.rb @@ -86,7 +86,7 @@ module Budgets end def destroy - @investment.destroy + @investment.destroy! redirect_to user_path(current_user, filter: "budget_investments"), notice: t("flash.actions.destroy.budget_investment") end @@ -143,7 +143,7 @@ module Budgets 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 load_heading diff --git a/app/controllers/dashboard/actions_controller.rb b/app/controllers/dashboard/actions_controller.rb index 01cbfd913..f0dfcd46b 100644 --- a/app/controllers/dashboard/actions_controller.rb +++ b/app/controllers/dashboard/actions_controller.rb @@ -17,7 +17,7 @@ class Dashboard::ActionsController < Dashboard::BaseController @dashboard_executed_action = Dashboard::ExecutedAction.new(source_params) if @dashboard_executed_action.save - Dashboard::AdministratorTask.create(source: @dashboard_executed_action) + Dashboard::AdministratorTask.create!(source: @dashboard_executed_action) redirect_to progress_proposal_dashboard_path(proposal.to_param), { flash: { info: t("dashboard.create_request.success") }} @@ -38,7 +38,7 @@ class Dashboard::ActionsController < Dashboard::BaseController def unexecute authorize! :dashboard, proposal - Dashboard::ExecutedAction.where(proposal: proposal, action: dashboard_action).first.destroy + Dashboard::ExecutedAction.where(proposal: proposal, action: dashboard_action).first.destroy! redirect_to request.referer end diff --git a/app/controllers/dashboard/polls_controller.rb b/app/controllers/dashboard/polls_controller.rb index cb79b29b1..26f638f17 100644 --- a/app/controllers/dashboard/polls_controller.rb +++ b/app/controllers/dashboard/polls_controller.rb @@ -42,7 +42,7 @@ class Dashboard::PollsController < Dashboard::BaseController if ::Poll::Voter.where(poll: poll).any? redirect_to proposal_dashboard_polls_path(proposal), alert: t("dashboard.polls.poll.unable_notice") else - poll.destroy + poll.destroy! redirect_to proposal_dashboard_polls_path(proposal), notice: t("dashboard.polls.poll.success_notice") end diff --git a/app/controllers/follows_controller.rb b/app/controllers/follows_controller.rb index 08753024f..a2e6c924d 100644 --- a/app/controllers/follows_controller.rb +++ b/app/controllers/follows_controller.rb @@ -3,14 +3,14 @@ class FollowsController < ApplicationController load_and_authorize_resource def create - @follow = Follow.create(user: current_user, followable: find_followable) + @follow = Follow.create!(user: current_user, followable: find_followable) flash.now[:notice] = t("shared.followable.#{followable_translation_key(@follow.followable)}.create.notice") render :refresh_follow_button end def destroy @follow = Follow.find(params[:id]) - @follow.destroy + @follow.destroy! flash.now[:notice] = t("shared.followable.#{followable_translation_key(@follow.followable)}.destroy.notice") render :refresh_follow_button end diff --git a/app/controllers/legislation/answers_controller.rb b/app/controllers/legislation/answers_controller.rb index 9f9de89ae..7da980e15 100644 --- a/app/controllers/legislation/answers_controller.rb +++ b/app/controllers/legislation/answers_controller.rb @@ -11,7 +11,7 @@ class Legislation::AnswersController < Legislation::BaseController def create if @process.debate_phase.open? @answer.user = current_user - @answer.save + @answer.save! track_event respond_to do |format| format.js diff --git a/app/controllers/polls/answers_controller.rb b/app/controllers/polls/answers_controller.rb index 13b1b3412..faa440cd8 100644 --- a/app/controllers/polls/answers_controller.rb +++ b/app/controllers/polls/answers_controller.rb @@ -7,7 +7,7 @@ class Polls::AnswersController < ApplicationController def create @question = Poll::Question.find_by(id: params[:id]) if @question.votation_type.open? && !check_question_answer_exist - @question.question_answers.create( + @question.question_answers.create!( title: params[:answer], given_order: @question.question_answers.maximum(:given_order).to_i + 1, hidden: false diff --git a/app/controllers/related_contents_controller.rb b/app/controllers/related_contents_controller.rb index a36ba23f9..34465e2da 100644 --- a/app/controllers/related_contents_controller.rb +++ b/app/controllers/related_contents_controller.rb @@ -7,7 +7,7 @@ class RelatedContentsController < ApplicationController if relationable_object && related_object if relationable_object.url != related_object.url - RelatedContent.create(parent_relationable: @relationable, child_relationable: @related, author: current_user) + RelatedContent.create!(parent_relationable: @relationable, child_relationable: @related, author: current_user) flash[:success] = t("related_content.success") else diff --git a/app/controllers/remote_translations_controller.rb b/app/controllers/remote_translations_controller.rb index dcb5aafef..a82f4e9e3 100644 --- a/app/controllers/remote_translations_controller.rb +++ b/app/controllers/remote_translations_controller.rb @@ -6,7 +6,7 @@ class RemoteTranslationsController < ApplicationController def create @remote_translations.each do |remote_translation| - RemoteTranslation.create(remote_translation) unless translations_enqueued?(remote_translation) + RemoteTranslation.create!(remote_translation) unless translations_enqueued?(remote_translation) end redirect_to request.referer, notice: t("remote_translations.create.enqueue_remote_translation") end diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb index 7c75e2fa0..eaf7b948d 100644 --- a/app/controllers/topics_controller.rb +++ b/app/controllers/topics_controller.rb @@ -40,7 +40,7 @@ class TopicsController < ApplicationController end def destroy - @topic.destroy + @topic.destroy! redirect_to community_path(@community), notice: I18n.t("flash.actions.destroy.topic") end diff --git a/app/controllers/tracking/milestones_controller.rb b/app/controllers/tracking/milestones_controller.rb index 2d99dd2c8..9d916c830 100644 --- a/app/controllers/tracking/milestones_controller.rb +++ b/app/controllers/tracking/milestones_controller.rb @@ -35,7 +35,7 @@ class Tracking::MilestonesController < Tracking::BaseController end def destroy - @milestone.destroy + @milestone.destroy! redirect_to milestoneable_path, notice: t("tracking.milestones.delete.notice") end diff --git a/app/controllers/tracking/progress_bars_controller.rb b/app/controllers/tracking/progress_bars_controller.rb index 12985dd19..0eb3340cd 100644 --- a/app/controllers/tracking/progress_bars_controller.rb +++ b/app/controllers/tracking/progress_bars_controller.rb @@ -33,7 +33,7 @@ class Tracking::ProgressBarsController < Tracking::BaseController end def destroy - @progress_bar.destroy + @progress_bar.destroy! redirect_to progress_bars_index, notice: t("tracking.progress_bars.delete.notice") end diff --git a/app/controllers/users/confirmations_controller.rb b/app/controllers/users/confirmations_controller.rb index 187b05e5f..553e07743 100644 --- a/app/controllers/users/confirmations_controller.rb +++ b/app/controllers/users/confirmations_controller.rb @@ -9,7 +9,7 @@ class Users::ConfirmationsController < Devise::ConfirmationsController resource.assign_attributes(resource_params) if resource.valid? # password is set correctly - resource.save + resource.save! set_official_position if resource.has_official_email? resource.confirm set_flash_message(:notice, :confirmed) if is_flashing_format? diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb index ccd3f8e1a..6108ed5ef 100644 --- a/app/controllers/users/omniauth_callbacks_controller.rb +++ b/app/controllers/users/omniauth_callbacks_controller.rb @@ -31,7 +31,7 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController @user = current_user || identity.user || User.first_or_initialize_for_oauth(auth) if save_user - identity.update(user: @user) + identity.update!(user: @user) sign_in_and_redirect @user, event: :authentication set_flash_message(:notice, :success, kind: provider.to_s.capitalize) if is_navigational_format? else diff --git a/app/controllers/verification/email_controller.rb b/app/controllers/verification/email_controller.rb index 9c6b10c3c..363c7731c 100644 --- a/app/controllers/verification/email_controller.rb +++ b/app/controllers/verification/email_controller.rb @@ -6,7 +6,7 @@ class Verification::EmailController < ApplicationController def show if Verification::Email.find(current_user, params[:email_verification_token]) - current_user.update(verified_at: Time.current) + current_user.update!(verified_at: Time.current) redirect_to account_path, notice: t("verification.email.show.flash.success") else redirect_to verified_user_path, alert: t("verification.email.show.alert.failure") diff --git a/app/controllers/verification/letter_controller.rb b/app/controllers/verification/letter_controller.rb index 5b36b912a..ce0c9747e 100644 --- a/app/controllers/verification/letter_controller.rb +++ b/app/controllers/verification/letter_controller.rb @@ -29,7 +29,7 @@ class Verification::LetterController < ApplicationController def update @letter = Verification::Letter.new(letter_params.merge(user: current_user, verify: true)) if @letter.valid? - current_user.update(verified_at: Time.current) + current_user.update!(verified_at: Time.current) redirect_to account_path, notice: t("verification.letter.update.flash.success") else Lock.increase_tries(@letter.user) if @letter.user diff --git a/app/controllers/verification/sms_controller.rb b/app/controllers/verification/sms_controller.rb index 0f978561e..3ced3ab87 100644 --- a/app/controllers/verification/sms_controller.rb +++ b/app/controllers/verification/sms_controller.rb @@ -27,7 +27,7 @@ class Verification::SmsController < ApplicationController def update @sms = Verification::Sms.new(sms_params.merge(user: current_user)) if @sms.verified? - current_user.update(confirmed_phone: current_user.unconfirmed_phone) + current_user.update!(confirmed_phone: current_user.unconfirmed_phone) ahoy.track(:level_2_user, user_id: current_user.id) rescue nil if VerifiedUser.phone?(current_user) diff --git a/app/models/activity.rb b/app/models/activity.rb index b356d637c..52d720c83 100644 --- a/app/models/activity.rb +++ b/app/models/activity.rb @@ -15,7 +15,7 @@ class Activity < ApplicationRecord scope :for_render, -> { includes(user: [:moderator, :administrator]).includes(:actionable) } def self.log(user, action, actionable) - create(user: user, action: action.to_s, actionable: actionable) + create!(user: user, action: action.to_s, actionable: actionable) end def self.on(actionable) diff --git a/app/models/admin_notification.rb b/app/models/admin_notification.rb index 7971bc9f3..c1e696963 100644 --- a/app/models/admin_notification.rb +++ b/app/models/admin_notification.rb @@ -30,7 +30,7 @@ class AdminNotification < ApplicationRecord def deliver list_of_recipients.each { |user| Notification.add(user, self) } - self.update(sent_at: Time.current, recipients_count: list_of_recipients.count) + update!(sent_at: Time.current, recipients_count: list_of_recipients.count) end private diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index 09d0c6733..ddef3c84a 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -256,7 +256,7 @@ class Budget def send_unfeasible_email Mailer.budget_investment_unfeasible(self).deliver_later - update(unfeasible_email_sent_at: Time.current) + update!(unfeasible_email_sent_at: Time.current) end def reason_for_not_being_selectable_by(user) diff --git a/app/models/budget/result.rb b/app/models/budget/result.rb index b28e7b2a9..11427c697 100644 --- a/app/models/budget/result.rb +++ b/app/models/budget/result.rb @@ -42,7 +42,7 @@ class Budget def set_winner @money_spent += @current_investment.price - @current_investment.update(winner: true) + @current_investment.update!(winner: true) end def winners diff --git a/app/models/concerns/communitable.rb b/app/models/concerns/communitable.rb index 415a7a3f0..83844e63c 100644 --- a/app/models/concerns/communitable.rb +++ b/app/models/concerns/communitable.rb @@ -7,7 +7,7 @@ module Communitable end def associate_community - community = Community.create + community = Community.create! self.community_id = community.id end diff --git a/app/models/download_setting.rb b/app/models/download_setting.rb index 0058a2866..3c1382280 100644 --- a/app/models/download_setting.rb +++ b/app/models/download_setting.rb @@ -7,10 +7,10 @@ class DownloadSetting < ApplicationRecord name_field: field_name, config: config) if download_setting.nil? - download_setting = DownloadSetting.create(downloadable: false, - name_model: model.name, - name_field: field_name, - config: config) + download_setting = DownloadSetting.create!(downloadable: false, + name_model: model.name, + name_field: field_name, + config: config) end download_setting end diff --git a/app/models/flag.rb b/app/models/flag.rb index b01d7b9a9..bdb31e971 100644 --- a/app/models/flag.rb +++ b/app/models/flag.rb @@ -12,7 +12,7 @@ class Flag < ApplicationRecord def self.flag(user, flaggable) return false if flagged?(user, flaggable) - create(user: user, flaggable: flaggable) + create!(user: user, flaggable: flaggable) end def self.unflag(user, flaggable) diff --git a/app/models/identity.rb b/app/models/identity.rb index 311ac61e4..73292b4cc 100644 --- a/app/models/identity.rb +++ b/app/models/identity.rb @@ -5,6 +5,6 @@ class Identity < ApplicationRecord validates :uid, presence: true, uniqueness: { scope: :provider } def self.first_or_create_from_oauth(auth) - where(uid: auth.uid, provider: auth.provider).first_or_create + where(uid: auth.uid, provider: auth.provider).first_or_create! end end diff --git a/app/models/local_census_records/import.rb b/app/models/local_census_records/import.rb index 298a1a17f..46bd1880c 100644 --- a/app/models/local_census_records/import.rb +++ b/app/models/local_census_records/import.rb @@ -45,7 +45,7 @@ class LocalCensusRecords::Import if local_census_record.invalid? invalid_records << local_census_record else - local_census_record.save + local_census_record.save! created_records << local_census_record end end diff --git a/app/models/lock.rb b/app/models/lock.rb index bcfa41196..eca3efa34 100644 --- a/app/models/lock.rb +++ b/app/models/lock.rb @@ -21,7 +21,7 @@ class Lock < ApplicationRecord end def self.increase_tries(user) - Lock.find_or_create_by(user: user).increment!(:tries).save + find_or_create_by!(user: user).increment!(:tries).save! end def self.max_tries diff --git a/app/models/officing/residence.rb b/app/models/officing/residence.rb index 4f6d73b18..7e61a0062 100644 --- a/app/models/officing/residence.rb +++ b/app/models/officing/residence.rb @@ -29,7 +29,7 @@ class Officing::Residence if user_exists? self.user = find_user_by_document - user.update(verified_at: Time.current) + user.update!(verified_at: Time.current) else user_params = { document_number: document_number, diff --git a/app/models/poll/ballot_sheet.rb b/app/models/poll/ballot_sheet.rb index 051f3cabc..787377419 100644 --- a/app/models/poll/ballot_sheet.rb +++ b/app/models/poll/ballot_sheet.rb @@ -27,7 +27,7 @@ class Poll::BallotSheet < ApplicationRecord def create_ballots(investment_ids, index) poll_ballot = Poll::Ballot.where(ballot_sheet: self, data: investment_ids, - external_id: index).first_or_create + external_id: index).first_or_create! create_ballot(poll_ballot) poll_ballot end @@ -36,7 +36,7 @@ class Poll::BallotSheet < ApplicationRecord Budget::Ballot.where(physical: true, user: nil, poll_ballot: poll_ballot, - budget: poll.budget).first_or_create + budget: poll.budget).first_or_create! end end diff --git a/app/models/poll/question/answer.rb b/app/models/poll/question/answer.rb index 5f245cb4e..c7ebc04f6 100644 --- a/app/models/poll/question/answer.rb +++ b/app/models/poll/question/answer.rb @@ -73,12 +73,12 @@ class Poll::Question::Answer < ApplicationRecord answers = question.question_answers.visibles .map { |a| count_positive_negative(a, true) - count_positive_negative(a, false) } is_most_voted = answers.none? { |a| a > total_votes_positive_negative } - update(most_voted: is_most_voted) + update!(most_voted: is_most_voted) when "prioritized" answers = question.question_answers.visibles .map { |a| Poll::Answer.where(question_id: a.question, answer: a.title).sum(:value) } is_most_voted = answers.none? { |a| a > total_votes_prioritized } - update(most_voted: is_most_voted) + update!(most_voted: is_most_voted) else for_only_votes end @@ -95,7 +95,7 @@ class Poll::Question::Answer < ApplicationRecord answers = question.question_answers.visibles .map { |a| Poll::Answer.where(question_id: a.question, answer: a.title).count } is_most_voted = answers.none? { |a| a > total_votes } - update(most_voted: is_most_voted) + update!(most_voted: is_most_voted) end end diff --git a/app/models/proposal.rb b/app/models/proposal.rb index 6c6ecb3c9..1d69690ae 100644 --- a/app/models/proposal.rb +++ b/app/models/proposal.rb @@ -96,7 +96,7 @@ class Proposal < ApplicationRecord end def publish - update(published_at: Time.current) + update!(published_at: Time.current) send_new_actions_notification_on_published end diff --git a/app/models/signature_sheet.rb b/app/models/signature_sheet.rb index eb989a9dc..1c8bb563d 100644 --- a/app/models/signature_sheet.rb +++ b/app/models/signature_sheet.rb @@ -28,10 +28,10 @@ class SignatureSheet < ApplicationRecord signature = signatures.where(document_number: document_number, date_of_birth: date_of_birth, - postal_code: postal_code).first_or_create + postal_code: postal_code).first_or_create! signature.verify end - update(processed: true) + update!(processed: true) end def parsed_required_fields_to_verify_groups diff --git a/app/models/user.rb b/app/models/user.rb index 2cbb19067..c1f032781 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -181,11 +181,11 @@ class User < ApplicationRecord def add_official_position!(position, level) return if position.blank? || level.blank? - update official_position: position, official_level: level.to_i + update! official_position: position, official_level: level.to_i end def remove_official_position! - update official_position: nil, official_level: 0 + update! official_position: nil, official_level: 0 end def has_official_email? @@ -215,7 +215,7 @@ class User < ApplicationRecord end def erase(erase_reason = nil) - update( + update!( erased_at: Time.current, erase_reason: erase_reason, username: nil, @@ -241,7 +241,7 @@ class User < ApplicationRecord .where(document_type: document_type).first if erased_user.present? take_votes_from(erased_user) - erased_user.update(document_number: nil, document_type: nil) + erased_user.update!(document_number: nil, document_type: nil) end end @@ -251,11 +251,11 @@ class User < ApplicationRecord Budget::Ballot.where(user_id: other_user.id).update_all(user_id: id) Vote.where("voter_id = ? AND voter_type = ?", other_user.id, "User").update_all(voter_id: id) data_log = "id: #{other_user.id} - #{Time.current.strftime("%Y-%m-%d %H:%M:%S")}" - update(former_users_data_log: "#{former_users_data_log} | #{data_log}") + update!(former_users_data_log: "#{former_users_data_log} | #{data_log}") end def locked? - Lock.find_or_create_by(user: self).locked? + Lock.find_or_create_by!(user: self).locked? end def self.search(term) @@ -315,11 +315,11 @@ class User < ApplicationRecord def save_requiring_finish_signup begin self.registering_with_oauth = true - save(validate: false) + save!(validate: false) # Devise puts unique constraints for the email the db, so we must detect & handle that rescue ActiveRecord::RecordNotUnique self.email = nil - save(validate: false) + save!(validate: false) end true end diff --git a/app/models/verification/email.rb b/app/models/verification/email.rb index 823f165cf..2a4815279 100644 --- a/app/models/verification/email.rb +++ b/app/models/verification/email.rb @@ -15,7 +15,7 @@ class Verification::Email return false unless valid? generate_token - user.update(email_verification_token: @plain_token) + user.update!(email_verification_token: @plain_token) end def user diff --git a/app/models/verification/management/email.rb b/app/models/verification/management/email.rb index bd291282c..b538d0505 100644 --- a/app/models/verification/management/email.rb +++ b/app/models/verification/management/email.rb @@ -25,11 +25,11 @@ class Verification::Management::Email plain_token, encrypted_token = Devise.token_generator.generate(User, :email_verification_token) - user.update(document_type: document_type, - document_number: document_number, - residence_verified_at: Time.current, - level_two_verified_at: Time.current, - email_verification_token: plain_token) + user.update!(document_type: document_type, + document_number: document_number, + residence_verified_at: Time.current, + level_two_verified_at: Time.current, + email_verification_token: plain_token) Mailer.email_verification(user, email, encrypted_token, document_type, document_number).deliver_later true diff --git a/app/models/votation_type.rb b/app/models/votation_type.rb index 891ba250e..11f3f6130 100644 --- a/app/models/votation_type.rb +++ b/app/models/votation_type.rb @@ -81,9 +81,9 @@ class VotationType < ApplicationRecord result = votes.by_author(user.id).find_by(answer: answer) if result.nil? if check_max_votes(user, votes) - result = votes.create(author: user, - answer: answer, - positive: options[:positive]) + result = votes.create!(author: user, + answer: answer, + positive: options[:positive]) end else !result.update(positive: options[:positive]) @@ -91,7 +91,7 @@ class VotationType < ApplicationRecord when "answer_couples_closed", "answer_couples_open" if check_max_votes(user, votes) - result = votes.create( + result = votes.create!( answer: answer, author: user, positive: true, @@ -114,7 +114,7 @@ class VotationType < ApplicationRecord return if questionable.question_answers.where(title: answer).any? questionable.question_answers - .create( + .create!( title: answer, given_order: questionable.question_answers.maximum(:given_order).to_i + 1, hidden: hidden @@ -140,7 +140,7 @@ class VotationType < ApplicationRecord def self.create_by_type(questionable, params) votation_type = build_by_type(questionable, params) - votation_type.save + votation_type.save! end def update_priorized_values(user) diff --git a/app/models/widget/feed.rb b/app/models/widget/feed.rb index c0a18cfc4..775048860 100644 --- a/app/models/widget/feed.rb +++ b/app/models/widget/feed.rb @@ -13,7 +13,7 @@ class Widget::Feed < ApplicationRecord def self.active KINDS.collect do |kind| - feed = find_or_create_by(kind: kind) + feed = find_or_create_by!(kind: kind) feed if feed.active? end.compact end diff --git a/db/dev_seeds/banners.rb b/db/dev_seeds/banners.rb index 90f435978..1b208fa48 100644 --- a/db/dev_seeds/banners.rb +++ b/db/dev_seeds/banners.rb @@ -20,9 +20,9 @@ section "Creating banners" do end section "Creating web sections" do - WebSection.create(name: "homepage") - WebSection.create(name: "debates") - WebSection.create(name: "proposals") - WebSection.create(name: "budgets") - WebSection.create(name: "help_page") + WebSection.create!(name: "homepage") + WebSection.create!(name: "debates") + WebSection.create!(name: "proposals") + WebSection.create!(name: "budgets") + WebSection.create!(name: "help_page") end diff --git a/db/dev_seeds/budgets.rb b/db/dev_seeds/budgets.rb index 360c38298..3904ee694 100644 --- a/db/dev_seeds/budgets.rb +++ b/db/dev_seeds/budgets.rb @@ -21,18 +21,18 @@ def add_image_to(imageable) attachment: INVESTMENT_IMAGE_FILES.sample, user: imageable.author }) - imageable.save + imageable.save! end section "Creating Budgets" do - Budget.create( + Budget.create!( name_en: "#{I18n.t("seeds.budgets.budget", locale: :en)} #{Date.current.year - 1}", name_es: "#{I18n.t("seeds.budgets.budget", locale: :es)} #{Date.current.year - 1}", currency_symbol: I18n.t("seeds.budgets.currency"), phase: "finished" ) - Budget.create( + Budget.create!( name_en: "#{I18n.t("seeds.budgets.budget", locale: :en)} #{Date.current.year}", name_es: "#{I18n.t("seeds.budgets.budget", locale: :es)} #{Date.current.year}", currency_symbol: I18n.t("seeds.budgets.currency"), diff --git a/db/dev_seeds/geozones.rb b/db/dev_seeds/geozones.rb index d0d342f57..e8addbe35 100644 --- a/db/dev_seeds/geozones.rb +++ b/db/dev_seeds/geozones.rb @@ -1,24 +1,24 @@ section "Creating Geozones" do - Geozone.create(name: I18n.t("seeds.geozones.north_district"), - external_code: "001", census_code: "01", - html_map_coordinates: "30,139,45,153,77,148,107,165,138,201,146,218,186,198,216,"\ - "196,233,203,240,215,283,194,329,185,377,184,388,165,369,126,333,113,334,84,320,"\ - "66,286,73,258,65,265,57,249,47,207,58,159,84,108,85,72,101,51,114") - Geozone.create(name: I18n.t("seeds.geozones.west_district"), - external_code: "002", census_code: "02", - html_map_coordinates: "42,153,31,176,24,202,20,221,44,235,59,249,55,320,30,354,"\ - "31,372,52,396,64,432,89,453,116,432,149,419,162,412,165,377,172,357,189,352,228,"\ - "327,246,313,262,297,234,291,210,284,193,284,176,294,158,303,154,310,146,289,140,"\ - "268,138,246,135,236,139,222,151,214,136,197,120,179,99,159,85,149,65,149,56,149") - Geozone.create(name: I18n.t("seeds.geozones.east_district"), - external_code: "003", census_code: "03", - html_map_coordinates: "175,353,162,378,161,407,153,416,167,432,184,447,225,426,"\ - "250,409,283,390,298,369,344,363,351,334,356,296,361,267,376,245,378,185,327,188,"\ - "281,195,239,216,245,221,245,232,261,244,281,238,300,242,304,251,285,262,278,277,"\ - "267,294,249,312,219,333,198,346,184,353") - Geozone.create(name: I18n.t("seeds.geozones.central_district"), - external_code: "004", census_code: "04", - html_map_coordinates: "152,308,137,258,133,235,147,216,152,214,186,194,210,196,"\ - "228,202,240,216,241,232,263,243,293,241,301,245,302,254,286,265,274,278,267,296,"\ - "243,293,226,289,209,285,195,283,177,297") + Geozone.create!(name: I18n.t("seeds.geozones.north_district"), + external_code: "001", census_code: "01", + html_map_coordinates: "30,139,45,153,77,148,107,165,138,201,146,218,186,198,216,"\ + "196,233,203,240,215,283,194,329,185,377,184,388,165,369,126,333,113,334,84,320,"\ + "66,286,73,258,65,265,57,249,47,207,58,159,84,108,85,72,101,51,114") + Geozone.create!(name: I18n.t("seeds.geozones.west_district"), + external_code: "002", census_code: "02", + html_map_coordinates: "42,153,31,176,24,202,20,221,44,235,59,249,55,320,30,354,"\ + "31,372,52,396,64,432,89,453,116,432,149,419,162,412,165,377,172,357,189,352,228,"\ + "327,246,313,262,297,234,291,210,284,193,284,176,294,158,303,154,310,146,289,140,"\ + "268,138,246,135,236,139,222,151,214,136,197,120,179,99,159,85,149,65,149,56,149") + Geozone.create!(name: I18n.t("seeds.geozones.east_district"), + external_code: "003", census_code: "03", + html_map_coordinates: "175,353,162,378,161,407,153,416,167,432,184,447,225,426,"\ + "250,409,283,390,298,369,344,363,351,334,356,296,361,267,376,245,378,185,327,188,"\ + "281,195,239,216,245,221,245,232,261,244,281,238,300,242,304,251,285,262,278,277,"\ + "267,294,249,312,219,333,198,346,184,353") + Geozone.create!(name: I18n.t("seeds.geozones.central_district"), + external_code: "004", census_code: "04", + html_map_coordinates: "152,308,137,258,133,235,147,216,152,214,186,194,210,196,"\ + "228,202,240,216,241,232,263,243,293,241,301,245,302,254,286,265,274,278,267,296,"\ + "243,293,226,289,209,285,195,283,177,297") end diff --git a/db/dev_seeds/milestones.rb b/db/dev_seeds/milestones.rb index 42b0df0b7..9c0619e4a 100644 --- a/db/dev_seeds/milestones.rb +++ b/db/dev_seeds/milestones.rb @@ -1,8 +1,8 @@ section "Creating default Milestone Statuses" do - Milestone::Status.create(name: I18n.t("seeds.budgets.statuses.studying_project")) - Milestone::Status.create(name: I18n.t("seeds.budgets.statuses.bidding")) - Milestone::Status.create(name: I18n.t("seeds.budgets.statuses.executing_project")) - Milestone::Status.create(name: I18n.t("seeds.budgets.statuses.executed")) + Milestone::Status.create!(name: I18n.t("seeds.budgets.statuses.studying_project")) + Milestone::Status.create!(name: I18n.t("seeds.budgets.statuses.bidding")) + Milestone::Status.create!(name: I18n.t("seeds.budgets.statuses.executing_project")) + Milestone::Status.create!(name: I18n.t("seeds.budgets.statuses.executed")) end section "Creating investment milestones" do diff --git a/db/dev_seeds/polls.rb b/db/dev_seeds/polls.rb index d284e93ae..ce51cf6f1 100644 --- a/db/dev_seeds/polls.rb +++ b/db/dev_seeds/polls.rb @@ -3,36 +3,35 @@ require_dependency "poll/question/answer" section "Creating polls" do - Poll.create(name: I18n.t("seeds.polls.current_poll"), - slug: I18n.t("seeds.polls.current_poll").parameterize, - starts_at: 7.days.ago, - ends_at: 7.days.from_now, - geozone_restricted: false) + Poll.create!(name: I18n.t("seeds.polls.current_poll"), + slug: I18n.t("seeds.polls.current_poll").parameterize, + starts_at: 7.days.ago, + ends_at: 7.days.from_now, + geozone_restricted: false) - Poll.create(name: I18n.t("seeds.polls.current_poll_geozone_restricted"), - slug: I18n.t("seeds.polls.current_poll_geozone_restricted").parameterize, - starts_at: 5.days.ago, - ends_at: 5.days.from_now, - geozone_restricted: true, - geozones: Geozone.reorder("RANDOM()").limit(3)) + Poll.create!(name: I18n.t("seeds.polls.current_poll_geozone_restricted"), + slug: I18n.t("seeds.polls.current_poll_geozone_restricted").parameterize, + starts_at: 5.days.ago, + ends_at: 5.days.from_now, + geozone_restricted: true, + geozones: Geozone.reorder("RANDOM()").limit(3)) - Poll.create(name: I18n.t("seeds.polls.recounting_poll"), - slug: I18n.t("seeds.polls.recounting_poll").parameterize, - starts_at: 15.days.ago, - ends_at: 2.days.ago) + Poll.create!(name: I18n.t("seeds.polls.recounting_poll"), + slug: I18n.t("seeds.polls.recounting_poll").parameterize, + starts_at: 15.days.ago, + ends_at: 2.days.ago) - Poll.create(name: I18n.t("seeds.polls.expired_poll_without_stats"), - slug: I18n.t("seeds.polls.expired_poll_without_stats").parameterize, + Poll.create!(name: I18n.t("seeds.polls.expired_poll_without_stats"), + slug: I18n.t("seeds.polls.expired_poll_without_stats").parameterize, + starts_at: 2.months.ago, + ends_at: 1.month.ago) - starts_at: 2.months.ago, - ends_at: 1.month.ago) - - Poll.create(name: I18n.t("seeds.polls.expired_poll_with_stats"), - slug: I18n.t("seeds.polls.expired_poll_with_stats").parameterize, - starts_at: 2.months.ago, - ends_at: 1.month.ago, - results_enabled: true, - stats_enabled: true) + Poll.create!(name: I18n.t("seeds.polls.expired_poll_with_stats"), + slug: I18n.t("seeds.polls.expired_poll_with_stats").parameterize, + starts_at: 2.months.ago, + ends_at: 1.month.ago, + results_enabled: true, + stats_enabled: true) Poll.find_each do |poll| name = poll.name diff --git a/db/dev_seeds/proposals.rb b/db/dev_seeds/proposals.rb index 216adf056..e825f240c 100644 --- a/db/dev_seeds/proposals.rb +++ b/db/dev_seeds/proposals.rb @@ -18,7 +18,7 @@ def add_image_to(imageable) attachment: IMAGE_FILES.sample, user: imageable.author }) - imageable.save + imageable.save! end section "Creating Proposals" do diff --git a/db/dev_seeds/users.rb b/db/dev_seeds/users.rb index d86e6f8c5..954f53282 100644 --- a/db/dev_seeds/users.rb +++ b/db/dev_seeds/users.rb @@ -22,49 +22,49 @@ section "Creating Users" do admin = create_user("admin@consul.dev", "admin") admin.create_administrator - admin.update(residence_verified_at: Time.current, + admin.update!(residence_verified_at: Time.current, confirmed_phone: Faker::PhoneNumber.phone_number, document_type: "1", verified_at: Time.current, document_number: unique_document_number) moderator = create_user("mod@consul.dev", "moderator") moderator.create_moderator - moderator.update(residence_verified_at: Time.current, + moderator.update!(residence_verified_at: Time.current, confirmed_phone: Faker::PhoneNumber.phone_number, document_type: "1", verified_at: Time.current, document_number: unique_document_number) manager = create_user("manager@consul.dev", "manager") manager.create_manager - manager.update(residence_verified_at: Time.current, + manager.update!(residence_verified_at: Time.current, confirmed_phone: Faker::PhoneNumber.phone_number, document_type: "1", verified_at: Time.current, document_number: unique_document_number) valuator = create_user("valuator@consul.dev", "valuator") valuator.create_valuator - valuator.update(residence_verified_at: Time.current, + valuator.update!(residence_verified_at: Time.current, confirmed_phone: Faker::PhoneNumber.phone_number, document_type: "1", verified_at: Time.current, document_number: unique_document_number) poll_officer = create_user("poll_officer@consul.dev", "Paul O. Fisher") poll_officer.create_poll_officer - poll_officer.update(residence_verified_at: Time.current, + poll_officer.update!(residence_verified_at: Time.current, confirmed_phone: Faker::PhoneNumber.phone_number, document_type: "1", verified_at: Time.current, document_number: unique_document_number) poll_officer2 = create_user("poll_officer2@consul.dev", "Pauline M. Espinosa") poll_officer2.create_poll_officer - poll_officer2.update(residence_verified_at: Time.current, + poll_officer2.update!(residence_verified_at: Time.current, confirmed_phone: Faker::PhoneNumber.phone_number, document_type: "1", verified_at: Time.current, document_number: unique_document_number) create_user("unverified@consul.dev", "unverified") level_2 = create_user("leveltwo@consul.dev", "level 2") - level_2.update(residence_verified_at: Time.current, + level_2.update!(residence_verified_at: Time.current, confirmed_phone: Faker::PhoneNumber.phone_number, document_number: unique_document_number, document_type: "1") verified = create_user("verified@consul.dev", "verified") - verified.update(residence_verified_at: Time.current, + verified.update!(residence_verified_at: Time.current, confirmed_phone: Faker::PhoneNumber.phone_number, document_type: "1", verified_at: Time.current, document_number: unique_document_number) @@ -80,7 +80,7 @@ section "Creating Users" do 5.times do |i| official = create_user("official#{i}@consul.dev", "Official #{i}") - official.update(official_level: i, official_position: "Official position #{i}") + official.update!(official_level: i, official_position: "Official position #{i}") end 30.times do |i| diff --git a/db/seeds.rb b/db/seeds.rb index 9ae6f7bf3..a17201607 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -9,11 +9,11 @@ end Setting.reset_defaults -WebSection.where(name: "homepage").first_or_create -WebSection.where(name: "debates").first_or_create -WebSection.where(name: "proposals").first_or_create -WebSection.where(name: "budgets").first_or_create -WebSection.where(name: "help_page").first_or_create +WebSection.where(name: "homepage").first_or_create! +WebSection.where(name: "debates").first_or_create! +WebSection.where(name: "proposals").first_or_create! +WebSection.where(name: "budgets").first_or_create! +WebSection.where(name: "help_page").first_or_create! # Default custom pages load Rails.root.join("db", "pages.rb") diff --git a/lib/email_digest.rb b/lib/email_digest.rb index 55cc65ae3..8a6bba23c 100644 --- a/lib/email_digest.rb +++ b/lib/email_digest.rb @@ -23,7 +23,7 @@ class EmailDigest def mark_as_emailed notifications.update_all(emailed_at: Time.current) - user.update(failed_email_digests_count: 0) + user.update!(failed_email_digests_count: 0) end def valid_email? diff --git a/lib/tasks/proposal_actions.rake b/lib/tasks/proposal_actions.rake index 29aa69d7e..93fdf8c1b 100644 --- a/lib/tasks/proposal_actions.rake +++ b/lib/tasks/proposal_actions.rake @@ -431,6 +431,6 @@ namespace :proposal_actions do end Setting["proposals.successful_proposal_id"] = proposal.id - proposal.update(cached_votes_up: cached_votes_up) + proposal.update!(cached_votes_up: cached_votes_up) end end diff --git a/spec/features/admin/budget_investments_spec.rb b/spec/features/admin/budget_investments_spec.rb index 86c8b8c4b..f51c23aa5 100644 --- a/spec/features/admin/budget_investments_spec.rb +++ b/spec/features/admin/budget_investments_spec.rb @@ -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) diff --git a/spec/features/admin/budgets_spec.rb b/spec/features/admin/budgets_spec.rb index 9efec72aa..1db26b847 100644 --- a/spec/features/admin/budgets_spec.rb +++ b/spec/features/admin/budgets_spec.rb @@ -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) diff --git a/spec/features/admin/change_log_spec.rb b/spec/features/admin/change_log_spec.rb index d677be010..ce58a27b5 100644 --- a/spec/features/admin/change_log_spec.rb +++ b/spec/features/admin/change_log_spec.rb @@ -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) diff --git a/spec/features/admin/milestone_statuses_spec.rb b/spec/features/admin/milestone_statuses_spec.rb index 8dc196155..11e77f33b 100644 --- a/spec/features/admin/milestone_statuses_spec.rb +++ b/spec/features/admin/milestone_statuses_spec.rb @@ -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 diff --git a/spec/features/admin/poll/shifts_spec.rb b/spec/features/admin/poll/shifts_spec.rb index 84ddada0d..0932a6ed2 100644 --- a/spec/features/admin/poll/shifts_spec.rb +++ b/spec/features/admin/poll/shifts_spec.rb @@ -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) diff --git a/spec/features/admin/settings_spec.rb b/spec/features/admin/settings_spec.rb index 72096e02c..00b115d5d 100644 --- a/spec/features/admin/settings_spec.rb +++ b/spec/features/admin/settings_spec.rb @@ -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 diff --git a/spec/features/admin/signature_sheets_spec.rb b/spec/features/admin/signature_sheets_spec.rb index 5d10d7bae..57f6ca7a8 100644 --- a/spec/features/admin/signature_sheets_spec.rb +++ b/spec/features/admin/signature_sheets_spec.rb @@ -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 diff --git a/spec/features/admin/stats_spec.rb b/spec/features/admin/stats_spec.rb index 5f9900561..8d28eedff 100644 --- a/spec/features/admin/stats_spec.rb +++ b/spec/features/admin/stats_spec.rb @@ -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" diff --git a/spec/features/admin/translatable_spec.rb b/spec/features/admin/translatable_spec.rb index 01cae2991..9a9b76d98 100644 --- a/spec/features/admin/translatable_spec.rb +++ b/spec/features/admin/translatable_spec.rb @@ -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) diff --git a/spec/features/admin/valuator_groups_spec.rb b/spec/features/admin/valuator_groups_spec.rb index 14fb3cc72..5a5e54927 100644 --- a/spec/features/admin/valuator_groups_spec.rb +++ b/spec/features/admin/valuator_groups_spec.rb @@ -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" diff --git a/spec/features/budgets/ballots_spec.rb b/spec/features/budgets/ballots_spec.rb index 9b291112b..4bc733da0 100644 --- a/spec/features/budgets/ballots_spec.rb +++ b/spec/features/budgets/ballots_spec.rb @@ -14,7 +14,7 @@ describe "Ballots" do end before do - budget.update(slug: "budget_slug") + budget.update!(slug: "budget_slug") login_as(user) end @@ -41,7 +41,7 @@ describe "Ballots" do context "Lines Load" do before do create(:budget_investment, :selected, heading: california, title: "More rain") - budget.update(slug: "budget_slug") + budget.update!(slug: "budget_slug") login_as(user) end @@ -687,7 +687,7 @@ describe "Ballots" do click_link "States" click_link "New York" - new_york.update(price: 10) + new_york.update!(price: 10) within("#budget_investment_#{investment1.id}") do expect(page).to have_selector(".in-favor a", visible: true) @@ -701,7 +701,7 @@ describe "Ballots" do end scenario "Balloting is disabled when budget isn't in the balotting phase", :js do - budget.update(phase: "accepting") + budget.update!(phase: "accepting") bi1 = create(:budget_investment, :selected, heading: california, price: 600) diff --git a/spec/features/budgets/budgets_spec.rb b/spec/features/budgets/budgets_spec.rb index aeecff8b7..fe54152b2 100644 --- a/spec/features/budgets/budgets_spec.rb +++ b/spec/features/budgets/budgets_spec.rb @@ -38,7 +38,7 @@ describe "Budgets" do heading1 = create(:budget_heading, group: group1) heading2 = create(:budget_heading, group: group2) - budget.update_attributes(phase: "informing") + budget.update_attributes!(phase: "informing") visit budgets_path @@ -51,7 +51,7 @@ describe "Budgets" do expect(page).to have_link("See all phases") end - budget.update_attributes(phase: "publishing_prices") + budget.update_attributes!(phase: "publishing_prices") visit budgets_path within("#budget_heading") do @@ -114,7 +114,7 @@ describe "Budgets" do end scenario "Show informing index without links" do - budget.update_attributes(phase: "informing") + budget.update_attributes!(phase: "informing") heading = create(:budget_heading, budget: budget) visit budgets_path @@ -132,7 +132,7 @@ describe "Budgets" do end scenario "Show finished index without heading links" do - budget.update_attributes(phase: "finished") + budget.update_attributes!(phase: "finished") heading = create(:budget_heading, budget: budget) visit budgets_path @@ -159,7 +159,7 @@ describe "Budgets" do create(:budget_heading, budget: budget) allowed_phase_list.each do |phase| - budget.update(phase: phase) + budget.update!(phase: phase) visit budgets_path @@ -178,7 +178,7 @@ describe "Budgets" do allowed_phase_list not_allowed_phase_list.each do |phase| - budget.update(phase: phase) + budget.update!(phase: phase) visit budgets_path @@ -197,7 +197,7 @@ describe "Budgets" do end scenario "Accepting" do - budget.update(phase: "accepting") + budget.update!(phase: "accepting") login_as(create(:user, :level_two)) visit budgets_path @@ -208,41 +208,41 @@ describe "Budgets" do scenario "Index shows only published phases" do - budget.update(phase: :finished) + budget.update!(phase: :finished) phases = budget.phases - phases.drafting.update(starts_at: "30-12-2017", ends_at: "31-12-2017", enabled: true, + phases.drafting.update!(starts_at: "30-12-2017", ends_at: "31-12-2017", enabled: true, description: "Description of drafting phase", summary: "

This is the summary for drafting phase

") - phases.accepting.update(starts_at: "01-01-2018", ends_at: "10-01-2018", enabled: true, + phases.accepting.update!(starts_at: "01-01-2018", ends_at: "10-01-2018", enabled: true, description: "Description of accepting phase", summary: "This is the summary for accepting phase") - phases.reviewing.update(starts_at: "11-01-2018", ends_at: "20-01-2018", enabled: false, + phases.reviewing.update!(starts_at: "11-01-2018", ends_at: "20-01-2018", enabled: false, description: "Description of reviewing phase", summary: "This is the summary for reviewing phase") - phases.selecting.update(starts_at: "21-01-2018", ends_at: "01-02-2018", enabled: true, + phases.selecting.update!(starts_at: "21-01-2018", ends_at: "01-02-2018", enabled: true, description: "Description of selecting phase", summary: "This is the summary for selecting phase") - phases.valuating.update(starts_at: "10-02-2018", ends_at: "20-02-2018", enabled: false, + phases.valuating.update!(starts_at: "10-02-2018", ends_at: "20-02-2018", enabled: false, description: "Description of valuating phase", summary: "This is the summary for valuating phase") - phases.publishing_prices.update(starts_at: "21-02-2018", ends_at: "01-03-2018", enabled: false, + phases.publishing_prices.update!(starts_at: "21-02-2018", ends_at: "01-03-2018", enabled: false, description: "Description of publishing prices phase", summary: "This is the summary for publishing_prices phase") - phases.balloting.update(starts_at: "02-03-2018", ends_at: "10-03-2018", enabled: true, + phases.balloting.update!(starts_at: "02-03-2018", ends_at: "10-03-2018", enabled: true, description: "Description of balloting phase", summary: "This is the summary for balloting phase") - phases.reviewing_ballots.update(starts_at: "11-03-2018", ends_at: "20-03-2018", enabled: false, + phases.reviewing_ballots.update!(starts_at: "11-03-2018", ends_at: "20-03-2018", enabled: false, description: "Description of reviewing ballots phase", summary: "This is the summary for reviewing_ballots phase") - phases.finished.update(starts_at: "21-03-2018", ends_at: "30-03-2018", enabled: true, + phases.finished.update!(starts_at: "21-03-2018", ends_at: "30-03-2018", enabled: true, description: "Description of finished phase", summary: "This is the summary for finished phase") @@ -295,7 +295,7 @@ describe "Budgets" do end scenario "Display all investment's map location if there are no selected", :js do - budget.update(phase: :publishing_prices) + budget.update!(phase: :publishing_prices) investment1 = create(:budget_investment, heading: heading) investment2 = create(:budget_investment, heading: heading) @@ -315,7 +315,7 @@ describe "Budgets" do end scenario "Display only selected investment's map location from publishing prices phase", :js do - budget.update(phase: :publishing_prices) + budget.update!(phase: :publishing_prices) investment1 = create(:budget_investment, :selected, heading: heading) investment2 = create(:budget_investment, :selected, heading: heading) @@ -389,7 +389,7 @@ describe "Budgets" do expect(page).not_to have_link "See unfeasible investments" expect(page).not_to have_link "See investments not selected for balloting phase" - budget.update(phase: :publishing_prices) + budget.update!(phase: :publishing_prices) visit budget_path(budget) @@ -401,7 +401,7 @@ describe "Budgets" do expect(page).not_to have_link "See unfeasible investments" expect(page).not_to have_link "See investments not selected for balloting phase" - budget.update(phase: :balloting) + budget.update!(phase: :balloting) visit budget_path(budget) @@ -413,7 +413,7 @@ describe "Budgets" do expect(page).to have_link "See unfeasible investments" expect(page).to have_link "See investments not selected for balloting phase" - budget.update(phase: :finished) + budget.update!(phase: :finished) visit budget_path(budget) @@ -486,7 +486,7 @@ describe "Budgets" do before do logout - budget.update(phase: "drafting") + budget.update!(phase: "drafting") create(:budget) end diff --git a/spec/features/budgets/executions_spec.rb b/spec/features/budgets/executions_spec.rb index c370a43cf..57b4aaff2 100644 --- a/spec/features/budgets/executions_spec.rb +++ b/spec/features/budgets/executions_spec.rb @@ -12,7 +12,7 @@ describe "Executions" do let!(:investment3) { create(:budget_investment, :incompatible, heading: heading) } scenario "finds budget by id or slug" do - budget.update(slug: "budget_slug") + budget.update!(slug: "budget_slug") visit budget_executions_path("budget_slug") within(".budgets-stats") { expect(page).to have_content budget.name } @@ -230,11 +230,11 @@ describe "Executions" do create(:milestone, milestoneable: investment2, status: status2) create(:milestone, milestoneable: investment3, status: status2) investment1.milestone_tag_list.add("tag1", "tag2") - investment1.save + investment1.save! investment2.milestone_tag_list.add("tag2") - investment2.save + investment2.save! investment3.milestone_tag_list.add("tag2") - investment3.save + investment3.save! visit budget_path(budget) diff --git a/spec/features/budgets/investments_spec.rb b/spec/features/budgets/investments_spec.rb index 702febfed..1f05877f3 100644 --- a/spec/features/budgets/investments_spec.rb +++ b/spec/features/budgets/investments_spec.rb @@ -32,8 +32,8 @@ describe "Budget Investments" do let(:investment) { create(:budget_investment, heading: heading) } before do - budget.update(slug: "budget_slug") - heading.update(slug: "heading_slug") + budget.update!(slug: "budget_slug") + heading.update!(slug: "heading_slug") end scenario "finds investment using budget slug" do @@ -536,7 +536,7 @@ describe "Budget Investments" do end scenario "by unfeasibilty link for group with one heading" do - budget.update(phase: :balloting) + budget.update!(phase: :balloting) group = create(:budget_group, name: "All City", budget: budget) heading = create(:budget_heading, name: "Madrid", group: group) @@ -550,7 +550,7 @@ describe "Budget Investments" do end scenario "by unfeasibilty link for group with many headings" do - budget.update(phase: :balloting) + budget.update!(phase: :balloting) group = create(:budget_group, name: "Districts", budget: budget) barajas = create(:budget_heading, name: "Barajas", group: group) @@ -823,7 +823,7 @@ describe "Budget Investments" do scenario "Order is random if budget is finished" do per_page.times { create(:budget_investment, :winner, heading: heading) } - budget.update(phase: "finished") + budget.update!(phase: "finished") visit budget_investments_path(budget, heading_id: heading.id) order = all(".budget-investment h3").collect { |i| i.text } @@ -837,7 +837,7 @@ describe "Budget Investments" do scenario "Order always is random for unfeasible and unselected investments" do Budget::Phase::PHASE_KINDS.each do |phase| - budget.update(phase: phase) + budget.update!(phase: phase) visit budget_investments_path(budget, heading_id: heading.id, filter: "unfeasible") @@ -1086,7 +1086,7 @@ describe "Budget Investments" do scenario "Price & explanation is shown when Budget is on published prices phase" do Budget::Phase::PUBLISHED_PRICES_PHASES.each do |phase| - budget.update(phase: phase) + budget.update!(phase: phase) visit budget_investment_path(budget, id: investment.id) expect(page).to have_content(investment.formatted_price) @@ -1105,7 +1105,7 @@ describe "Budget Investments" do scenario "Price & explanation isn't shown when Budget is not on published prices phase" do (Budget::Phase::PHASE_KINDS - Budget::Phase::PUBLISHED_PRICES_PHASES).each do |phase| - budget.update(phase: phase) + budget.update!(phase: phase) visit budget_investment_path(budget, id: investment.id) expect(page).not_to have_content(investment.formatted_price) @@ -1127,7 +1127,7 @@ describe "Budget Investments" do scenario "Price & explanation isn't shown for any Budget's phase" do Budget::Phase::PHASE_KINDS.each do |phase| - budget.update(phase: phase) + budget.update!(phase: phase) visit budget_investment_path(budget, id: investment.id) expect(page).not_to have_content(investment.formatted_price) @@ -1191,7 +1191,7 @@ describe "Budget Investments" do end scenario "Budget in selecting phase" do - budget.update(phase: "selecting") + budget.update!(phase: "selecting") visit budget_investment_path(budget, id: investment.id) expect(page).not_to have_content("Unfeasibility explanation") @@ -1250,7 +1250,7 @@ describe "Budget Investments" do end scenario "Show (winner budget investment) only if budget is finished" do - budget.update(phase: "balloting") + budget.update!(phase: "balloting") investment = create(:budget_investment, :feasible, @@ -1267,7 +1267,7 @@ describe "Budget Investments" do expect(page).not_to have_content("Winning investment project") - budget.update(phase: "finished") + budget.update!(phase: "finished") visit budget_investment_path(budget, id: investment.id) @@ -1275,7 +1275,7 @@ describe "Budget Investments" do end scenario "Show (not selected budget investment)" do - budget.update(phase: "balloting") + budget.update!(phase: "balloting") investment = create(:budget_investment, :feasible, @@ -1599,7 +1599,7 @@ describe "Budget Investments" do end scenario "Confirm", :js do - budget.update(phase: "balloting") + budget.update!(phase: "balloting") user = create(:user, :level_two) global_group = create(:budget_group, budget: budget, name: "Global Group") @@ -1664,7 +1664,7 @@ describe "Budget Investments" do end scenario "Highlight voted heading except with unfeasible filter", :js do - budget.update(phase: "balloting") + budget.update!(phase: "balloting") user = create(:user, :level_two) heading_1 = create(:budget_heading, group: group, name: "Heading 1") @@ -1799,7 +1799,7 @@ describe "Budget Investments" do expect(page).to have_content("You have voted one investment") investment.heading = heading2 - investment.save + investment.save! visit budget_ballot_path(budget) @@ -1817,7 +1817,7 @@ describe "Budget Investments" do investment.feasibility = "unfeasible" investment.unfeasibility_explanation = "too expensive" - investment.save + investment.save! visit budget_ballot_path(budget) diff --git a/spec/features/budgets/results_spec.rb b/spec/features/budgets/results_spec.rb index 7c125c2fa..3b44acdef 100644 --- a/spec/features/budgets/results_spec.rb +++ b/spec/features/budgets/results_spec.rb @@ -16,7 +16,7 @@ describe "Results" do end scenario "No links to budget results with results disabled" do - budget.update(results_enabled: false) + budget.update!(results_enabled: false) visit budgets_path @@ -105,7 +105,7 @@ describe "Results" do end scenario "If budget is in a phase different from finished results can't be accessed" do - budget.update(phase: (Budget::Phase::PHASE_KINDS - ["drafting", "finished"]).sample) + budget.update!(phase: (Budget::Phase::PHASE_KINDS - ["drafting", "finished"]).sample) visit budget_path(budget) expect(page).not_to have_link "See results" @@ -115,7 +115,7 @@ describe "Results" do scenario "No incompatible investments", :js do investment3.incompatible = false - investment3.save + investment3.save! visit budget_path(budget) click_link "See results" diff --git a/spec/features/budgets/stats_spec.rb b/spec/features/budgets/stats_spec.rb index 4663da384..dcfd00f0c 100644 --- a/spec/features/budgets/stats_spec.rb +++ b/spec/features/budgets/stats_spec.rb @@ -32,7 +32,7 @@ describe "Stats" do describe "Show" do describe "advanced stats" do scenario "advanced stats enabled" do - budget.update(advanced_stats_enabled: true) + budget.update!(advanced_stats_enabled: true) visit budget_stats_path(budget) diff --git a/spec/features/budgets/votes_spec.rb b/spec/features/budgets/votes_spec.rb index 2134de1da..d65a3346d 100644 --- a/spec/features/budgets/votes_spec.rb +++ b/spec/features/budgets/votes_spec.rb @@ -85,7 +85,7 @@ describe "Votes" do end scenario "Disable voting on investments", :js do - budget.update(phase: "reviewing") + budget.update!(phase: "reviewing") investment = create(:budget_investment, heading: heading) manuela = create(:user, verified_at: Time.current) diff --git a/spec/features/comments/legislation_questions_spec.rb b/spec/features/comments/legislation_questions_spec.rb index 9f7968efc..5cc2e7bcc 100644 --- a/spec/features/comments/legislation_questions_spec.rb +++ b/spec/features/comments/legislation_questions_spec.rb @@ -226,7 +226,7 @@ describe "Commenting legislation questions" do end scenario "Can't create comments if debate phase is not open", :js do - process.update_attributes(debate_start_date: Date.current - 2.days, debate_end_date: Date.current - 1.day) + process.update_attributes!(debate_start_date: Date.current - 2.days, debate_end_date: Date.current - 1.day) login_as(user) visit legislation_process_question_path(legislation_question.process, legislation_question) diff --git a/spec/features/dashboard/dashboard_spec.rb b/spec/features/dashboard/dashboard_spec.rb index 6eee343ab..3f11304fa 100644 --- a/spec/features/dashboard/dashboard_spec.rb +++ b/spec/features/dashboard/dashboard_spec.rb @@ -195,7 +195,7 @@ describe "Proposal's dashboard" do end scenario "Dashboard progress show available resources for published proposal" do - proposal.update(published_at: Date.current) + proposal.update!(published_at: Date.current) available = create(:dashboard_action, :resource, :active) requested = create(:dashboard_action, :resource, :admin_request, :active) @@ -506,7 +506,7 @@ describe "Proposal's dashboard" do scenario "Not display tag 'new' on resouce when there is not new resources since last login" do resource = create(:dashboard_action, :resource, :active, day_offset: 0, published_proposal: false) - proposal.author.update(last_sign_in_at: Date.current) + proposal.author.update!(last_sign_in_at: Date.current) visit progress_proposal_dashboard_path(proposal) @@ -529,7 +529,7 @@ describe "Proposal's dashboard" do scenario "Not display tag 'new' on proposed_action when there is not new since last login" do proposed_action = create(:dashboard_action, :proposed_action, :active, day_offset: 0, published_proposal: false) - proposal.author.update(last_sign_in_at: Date.current) + proposal.author.update!(last_sign_in_at: Date.current) visit progress_proposal_dashboard_path(proposal) @@ -550,7 +550,7 @@ describe "Proposal's dashboard" do scenario "Not display tag 'new' on sidebar when there is not a new resouce since last login" do create(:dashboard_action, :resource, :active, day_offset: 0, published_proposal: false) - proposal.author.update(last_sign_in_at: Date.current) + proposal.author.update!(last_sign_in_at: Date.current) visit progress_proposal_dashboard_path(proposal) diff --git a/spec/features/emails_spec.rb b/spec/features/emails_spec.rb index ac7f25f8f..938928ae4 100644 --- a/spec/features/emails_spec.rb +++ b/spec/features/emails_spec.rb @@ -63,7 +63,7 @@ describe "Emails" do end scenario "Do not send email about proposal comment unless set in preferences" do - user.update(email_on_comment: false) + user.update!(email_on_comment: false) comment_on(proposal) expect { open_last_email }.to raise_error("No email has been sent!") end @@ -90,7 +90,7 @@ describe "Emails" do end scenario "Do not send email about debate comment unless set in preferences" do - user.update(email_on_comment: false) + user.update!(email_on_comment: false) comment_on(debate) expect { open_last_email }.to raise_error("No email has been sent!") end @@ -117,7 +117,7 @@ describe "Emails" do end scenario "Do not send email about budget investment comment unless set in preferences" do - user.update(email_on_comment: false) + user.update!(email_on_comment: false) comment_on(investment) expect { open_last_email }.to raise_error("No email has been sent!") end @@ -145,7 +145,7 @@ describe "Emails" do end scenario "Do not send email about topic comment unless set in preferences" do - user.update(email_on_comment: false) + user.update!(email_on_comment: false) comment_on(topic) expect { open_last_email }.to raise_error("No email has been sent!") end @@ -172,7 +172,7 @@ describe "Emails" do end scenario "Do not send email about poll question comment unless set in preferences" do - user.update(email_on_comment: false) + user.update!(email_on_comment: false) comment_on(poll) expect { open_last_email }.to raise_error("No email has been sent!") end @@ -199,7 +199,7 @@ describe "Emails" do end scenario "Do not send email about comment reply unless set in preferences", :js do - user.update(email_on_comment_reply: false) + user.update!(email_on_comment_reply: false) reply_to(user) expect { open_last_email }.to raise_error("No email has been sent!") end @@ -372,7 +372,7 @@ describe "Emails" do end scenario "Unfeasible investment" do - budget.update(phase: "valuating") + budget.update!(phase: "valuating") valuator = create(:valuator) investment = create(:budget_investment, author: author, budget: budget, valuators: [valuator]) @@ -511,7 +511,7 @@ describe "Emails" do user_commenting = create(:user) comment = create(:comment, commentable: proposal, user: user_commenting) - user.update(email: nil) + user.update!(email: nil) Mailer.comment(comment).deliver_now diff --git a/spec/features/legislation/processes_spec.rb b/spec/features/legislation/processes_spec.rb index 248c3c446..65524392b 100644 --- a/spec/features/legislation/processes_spec.rb +++ b/spec/features/legislation/processes_spec.rb @@ -196,7 +196,7 @@ describe "Legislation" do scenario "Shows another translation when the default locale isn't available" do process = create(:legislation_process, title_fr: "Français") - process.translations.where(locale: :en).first.destroy + process.translations.where(locale: :en).first.destroy! visit legislation_process_path(process) expect(page).to have_content("Français") diff --git a/spec/features/management/budget_investments_spec.rb b/spec/features/management/budget_investments_spec.rb index f72889276..c0d21c775 100644 --- a/spec/features/management/budget_investments_spec.rb +++ b/spec/features/management/budget_investments_spec.rb @@ -336,7 +336,7 @@ describe "Budget Investments" do end scenario "Printing voted budget investments in balloting phase" do - budget.update(phase: "balloting") + budget.update!(phase: "balloting") voted_investment = create(:budget_investment, :selected, heading: heading, balloters: [create(:user)]) diff --git a/spec/features/moderation/budget_investments_spec.rb b/spec/features/moderation/budget_investments_spec.rb index d5e3a5c72..e2809f885 100644 --- a/spec/features/moderation/budget_investments_spec.rb +++ b/spec/features/moderation/budget_investments_spec.rb @@ -41,7 +41,7 @@ describe "Moderate budget investments" do end scenario "Can not hide own investment" do - investment.update(author: mod.user) + investment.update!(author: mod.user) login_as(mod.user) visit budget_investment_path(budget, investment) diff --git a/spec/features/moderation/proposal_notifications_spec.rb b/spec/features/moderation/proposal_notifications_spec.rb index 067a218f2..6a3420e96 100644 --- a/spec/features/moderation/proposal_notifications_spec.rb +++ b/spec/features/moderation/proposal_notifications_spec.rb @@ -70,7 +70,7 @@ describe "Moderate proposal notifications" do scenario "Block the author" do author = create(:user) - proposal_notification.update(author: author) + proposal_notification.update!(author: author) click_on "Block authors" expect(page).not_to have_css("#proposal_notification_#{proposal_notification.id}") expect(proposal_notification.reload).to be_hidden diff --git a/spec/features/notifications_spec.rb b/spec/features/notifications_spec.rb index 3a3ce8ac1..bba16eace 100644 --- a/spec/features/notifications_spec.rb +++ b/spec/features/notifications_spec.rb @@ -160,7 +160,7 @@ describe "Notifications" do end scenario "With internal link" do - admin_notification.update_attributes(link: "/stats") + admin_notification.update_attributes!(link: "/stats") visit notifications_path expect(page).to have_content("Notification title") @@ -171,7 +171,7 @@ describe "Notifications" do end scenario "Without a link" do - admin_notification.update_attributes(link: "/stats") + admin_notification.update_attributes!(link: "/stats") visit notifications_path expect(page).to have_content("Notification title") diff --git a/spec/features/polls/polls_spec.rb b/spec/features/polls/polls_spec.rb index af8b61c5c..7f5680936 100644 --- a/spec/features/polls/polls_spec.rb +++ b/spec/features/polls/polls_spec.rb @@ -201,7 +201,7 @@ describe "Polls" do visit polls_path expect(page).not_to have_selector(".already-answer") - poll.update(geozone_restricted: true) + poll.update!(geozone_restricted: true) poll.geozones << geozone create(:poll_question, :yes_no, poll: poll) @@ -235,7 +235,7 @@ describe "Polls" do end scenario "Level 2 users in a poll with questions for a geozone which is not theirs" do - poll.update(geozone_restricted: true) + poll.update!(geozone_restricted: true) poll.geozones << create(:geozone) question = create(:poll_question, :yes_no, poll: poll) @@ -253,7 +253,7 @@ describe "Polls" do end scenario "Level 2 users reading a same-geozone poll" do - poll.update(geozone_restricted: true) + poll.update!(geozone_restricted: true) poll.geozones << geozone question = create(:poll_question, :yes_no, poll: poll) @@ -294,7 +294,7 @@ describe "Polls" do end scenario "Level 2 users answering", :js do - poll.update(geozone_restricted: true) + poll.update!(geozone_restricted: true) poll.geozones << geozone question = create(:poll_question, :yes_no, poll: poll) @@ -312,7 +312,7 @@ describe "Polls" do end scenario "Level 2 users changing answer", :js do - poll.update(geozone_restricted: true) + poll.update!(geozone_restricted: true) poll.geozones << geozone question = create(:poll_question, :yes_no, poll: poll) @@ -335,7 +335,7 @@ describe "Polls" do end scenario "Level 2 votes, signs out, signs in, votes again", :js do - poll.update(geozone_restricted: true) + poll.update!(geozone_restricted: true) poll.geozones << geozone question = create(:poll_question, :yes_no, poll: poll) diff --git a/spec/features/polls/results_spec.rb b/spec/features/polls/results_spec.rb index 8ad18748a..7db289ae6 100644 --- a/spec/features/polls/results_spec.rb +++ b/spec/features/polls/results_spec.rb @@ -34,7 +34,7 @@ describe "Poll Results" do expect(Poll::Voter.count).to eq(3) logout - poll.update(ends_at: 1.day.ago) + poll.update!(ends_at: 1.day.ago) visit results_poll_path(poll) diff --git a/spec/features/polls/votation_type_spec.rb b/spec/features/polls/votation_type_spec.rb index cf5363d2c..46bff80a6 100644 --- a/spec/features/polls/votation_type_spec.rb +++ b/spec/features/polls/votation_type_spec.rb @@ -322,7 +322,7 @@ describe "Poll Votation Type" do end scenario "existing given order is bigger than the number of answers", :js do - answer1.update(given_order: question.question_answers.count + 1) + answer1.update!(given_order: question.question_answers.count + 1) visit poll_path(poll_current) diff --git a/spec/features/tags/budget_investments_spec.rb b/spec/features/tags/budget_investments_spec.rb index 919de6d63..6d700245b 100644 --- a/spec/features/tags/budget_investments_spec.rb +++ b/spec/features/tags/budget_investments_spec.rb @@ -233,7 +233,7 @@ describe "Tags" do scenario "Display user tags" do Budget::Phase::PHASE_KINDS.each do |phase| - budget.update(phase: phase) + budget.update!(phase: phase) login_as(admin) if budget.drafting? visit budget_investments_path(budget, heading_id: heading.id) @@ -247,7 +247,7 @@ describe "Tags" do scenario "Filter by user tags" do Budget::Phase::PHASE_KINDS.each do |phase| - budget.update(phase: phase) + budget.update!(phase: phase) [investment1, investment2, investment3].each do |investment| investment.update(selected: true, feasibility: "feasible") @@ -284,7 +284,7 @@ describe "Tags" do scenario "Display category tags" do Budget::Phase::PHASE_KINDS.each do |phase| - budget.update(phase: phase) + budget.update!(phase: phase) login_as(admin) if budget.drafting? visit budget_investments_path(budget, heading_id: heading.id) @@ -298,7 +298,7 @@ describe "Tags" do scenario "Filter by category tags" do Budget::Phase::PHASE_KINDS.each do |phase| - budget.update(phase: phase) + budget.update!(phase: phase) [investment1, investment2, investment3].each do |investment| investment.update(selected: true, feasibility: "feasible") @@ -331,7 +331,7 @@ describe "Tags" do scenario "Users do not see valuator tags" do investment = create(:budget_investment, heading: heading, tag_list: "Park") investment.set_tag_list_on(:valuation, "Education") - investment.save + investment.save! visit budget_investment_path(budget, investment) @@ -342,7 +342,7 @@ describe "Tags" do scenario "Valuators do not see user tags" do investment = create(:budget_investment, heading: heading, tag_list: "Park") investment.set_tag_list_on(:valuation, "Education") - investment.save + investment.save! login_as(admin) diff --git a/spec/features/users_spec.rb b/spec/features/users_spec.rb index 6bc5119e6..0b971d4ee 100644 --- a/spec/features/users_spec.rb +++ b/spec/features/users_spec.rb @@ -248,7 +248,7 @@ describe "Users" do scenario "Not display interests when proposal has been destroyed" do proposal = create(:proposal, tag_list: "Sport", followers: [user]) - proposal.destroy + proposal.destroy! login_as(user) visit account_path @@ -333,7 +333,7 @@ describe "Users" do scenario "Should display generic interests title" do create(:proposal, tag_list: "Sport", followers: [user]) - user.update(public_interests: true) + user.update!(public_interests: true) visit user_path(user, filter: "follows", page: "1") expect(page).to have_content("Tags of elements this user follows") @@ -342,7 +342,7 @@ describe "Users" do scenario "Should display custom interests title when user is visiting own user page" do create(:proposal, tag_list: "Sport", followers: [user]) - user.update(public_interests: true) + user.update!(public_interests: true) login_as(user) visit user_path(user, filter: "follows", page: "1") diff --git a/spec/features/valuation/budget_investments_spec.rb b/spec/features/valuation/budget_investments_spec.rb index 7c6861b89..a30efcf7a 100644 --- a/spec/features/valuation/budget_investments_spec.rb +++ b/spec/features/valuation/budget_investments_spec.rb @@ -235,7 +235,7 @@ describe "Valuation budget investments" do end scenario "visible for assigned valuators" do - investment.update(visible_to_valuators: true) + investment.update!(visible_to_valuators: true) visit valuation_budget_budget_investments_path(budget) click_link investment.title @@ -312,7 +312,7 @@ describe "Valuation budget investments" do end scenario "Dossier empty by default" do - investment.update(visible_to_valuators: true) + investment.update!(visible_to_valuators: true) visit valuation_budget_budget_investments_path(budget) click_link investment.title @@ -325,7 +325,7 @@ describe "Valuation budget investments" do end scenario "Edit dossier" do - investment.update(visible_to_valuators: true) + investment.update!(visible_to_valuators: true) visit valuation_budget_budget_investments_path(budget) within("#budget_investment_#{investment.id}") do click_link "Edit dossier" @@ -427,7 +427,7 @@ describe "Valuation budget investments" do end scenario "Finish valuation" do - investment.update(visible_to_valuators: true) + investment.update!(visible_to_valuators: true) visit valuation_budget_budget_investment_path(budget, investment) click_link "Edit dossier" @@ -486,7 +486,7 @@ describe "Valuation budget investments" do end scenario "Validates price formats" do - investment.update(visible_to_valuators: true) + investment.update!(visible_to_valuators: true) visit valuation_budget_budget_investments_path(budget) @@ -503,7 +503,7 @@ describe "Valuation budget investments" do end scenario "not visible to valuators when budget is not valuating" do - budget.update(phase: "publishing_prices") + budget.update!(phase: "publishing_prices") investment = create(:budget_investment, budget: budget, valuators: [valuator]) @@ -514,7 +514,7 @@ describe "Valuation budget investments" do end scenario "visible to admins regardless of not being in valuating phase" do - budget.update(phase: "publishing_prices") + budget.update!(phase: "publishing_prices") user = create(:user) admin = create(:administrator, user: user) diff --git a/spec/features/verification/email_spec.rb b/spec/features/verification/email_spec.rb index bfb274049..4721510f1 100644 --- a/spec/features/verification/email_spec.rb +++ b/spec/features/verification/email_spec.rb @@ -57,7 +57,7 @@ describe "Verify email" do visit verified_user_path - verified_user.destroy + verified_user.destroy! click_button "Send code" expect(page).to have_content "There was a problem with sending an email to your account" diff --git a/spec/features/votes_spec.rb b/spec/features/votes_spec.rb index 87c42143a..2d1da1fa9 100644 --- a/spec/features/votes_spec.rb +++ b/spec/features/votes_spec.rb @@ -328,7 +328,7 @@ describe "Votes" do debate = create(:debate) Setting["max_ratio_anon_votes_on_debates"] = 50 - debate.update(cached_anonymous_votes_total: 520, cached_votes_total: 1000) + debate.update!(cached_anonymous_votes_total: 520, cached_votes_total: 1000) login_as(user) diff --git a/spec/features/xss_spec.rb b/spec/features/xss_spec.rb index 8e9032fe5..46a7eb777 100644 --- a/spec/features/xss_spec.rb +++ b/spec/features/xss_spec.rb @@ -35,7 +35,7 @@ describe "Cross-Site Scripting protection", :js do end scenario "hacked translations" do - I18nContent.create(key: "admin.budget_investments.index.list.title", value: attack_code) + I18nContent.create!(key: "admin.budget_investments.index.list.title", value: attack_code) login_as(create(:administrator).user) visit admin_budget_budget_investments_path(create(:budget_investment).budget) @@ -44,7 +44,7 @@ describe "Cross-Site Scripting protection", :js do end scenario "accept terms label" do - I18nContent.create(key: "form.accept_terms", value: attack_code) + I18nContent.create!(key: "form.accept_terms", value: attack_code) login_as(create(:user)) visit new_debate_path @@ -53,7 +53,7 @@ describe "Cross-Site Scripting protection", :js do end scenario "link to sign in" do - I18nContent.create(key: "budgets.investments.index.sidebar.not_logged_in", value: attack_code) + I18nContent.create!(key: "budgets.investments.index.sidebar.not_logged_in", value: attack_code) create(:budget, phase: "accepting") visit budgets_path @@ -62,7 +62,7 @@ describe "Cross-Site Scripting protection", :js do end scenario "languages in use" do - I18nContent.create(key: "shared.translations.languages_in_use", value: attack_code) + I18nContent.create!(key: "shared.translations.languages_in_use", value: attack_code) login_as(create(:administrator).user) visit edit_admin_budget_path(create(:budget)) @@ -139,7 +139,7 @@ describe "Cross-Site Scripting protection", :js do scenario "budget phase description" do budget = create(:budget) - budget.current_phase.update(description: attack_code) + budget.current_phase.update!(description: attack_code) visit budget_path(budget) diff --git a/spec/lib/acts_as_taggable_on_spec.rb b/spec/lib/acts_as_taggable_on_spec.rb index ef118c025..cb9e6d842 100644 --- a/spec/lib/acts_as_taggable_on_spec.rb +++ b/spec/lib/acts_as_taggable_on_spec.rb @@ -8,34 +8,34 @@ describe ActsAsTaggableOn do let(:debate) { create(:debate) } it "increases and decreases the tag's custom counters" do - tag = Tag.create(name: "foo") + tag = Tag.create!(name: "foo") expect(tag.debates_count).to eq(0) expect(tag.proposals_count).to eq(0) proposal.tag_list.add("foo") - proposal.save + proposal.save! tag.reload expect(tag.debates_count).to eq(0) expect(tag.proposals_count).to eq(1) debate.tag_list.add("foo") - debate.save + debate.save! tag.reload expect(tag.debates_count).to eq(1) expect(tag.proposals_count).to eq(1) proposal.tag_list.remove("foo") - proposal.save + proposal.save! tag.reload expect(tag.debates_count).to eq(1) expect(tag.proposals_count).to eq(0) debate.tag_list.remove("foo") - debate.save + debate.save! tag.reload expect(tag.debates_count).to eq(0) @@ -51,7 +51,7 @@ describe ActsAsTaggableOn do tag = create(:tag, kind: nil) proposal = create(:proposal) proposal.tag_list.add(tag) - proposal.save + proposal.save! expect(Tag.public_for_api).to eq [tag] end @@ -60,7 +60,7 @@ describe ActsAsTaggableOn do tag = create(:tag, :category) proposal = create(:proposal) proposal.tag_list.add(tag) - proposal.save + proposal.save! expect(Tag.public_for_api).to eq [tag] end @@ -69,7 +69,7 @@ describe ActsAsTaggableOn do tag = create(:tag, kind: "foo") proposal = create(:proposal) proposal.tag_list.add(tag) - proposal.save + proposal.save! expect(Tag.public_for_api).to be_empty end @@ -93,9 +93,9 @@ describe ActsAsTaggableOn do budget_investment.tag_list.add(tag_2) debate.tag_list.add(tag_3) - proposal.save - budget_investment.save - debate.save + proposal.save! + budget_investment.save! + debate.save! expect(Tag.public_for_api).to match_array([tag_1, tag_3]) end @@ -104,7 +104,7 @@ describe ActsAsTaggableOn do tag = create(:tag) proposal = create(:proposal) proposal.tag_list.add(tag) - proposal.save + proposal.save! expect(Tag.public_for_api).to eq [tag] diff --git a/spec/lib/graphql_spec.rb b/spec/lib/graphql_spec.rb index e579ce22e..a69f0b0b5 100644 --- a/spec/lib/graphql_spec.rb +++ b/spec/lib/graphql_spec.rb @@ -262,7 +262,7 @@ describe "Consul Schema" do create(:comment, commentable: create(:proposal)) create(:comment, commentable: create(:debate)) create(:comment, commentable: create(:poll)) - build(:comment, commentable: create(:budget_investment)).save(skip_validation: true) + build(:comment, commentable: create(:budget_investment)).save!(skip_validation: true) response = execute("{ comments { edges { node { commentable_type } } } }") received_commentables = extract_fields(response, "comments", "commentable_type") diff --git a/spec/lib/tasks/budgets_spec.rb b/spec/lib/tasks/budgets_spec.rb index 58848a267..c816c2ad6 100644 --- a/spec/lib/tasks/budgets_spec.rb +++ b/spec/lib/tasks/budgets_spec.rb @@ -10,7 +10,7 @@ describe Budget do it "sets attribute original_heading_id for existing investments" do heading = create(:budget_heading) investment = create(:budget_investment, heading: heading) - investment.update(original_heading_id: nil) + investment.update!(original_heading_id: nil) expect(investment.original_heading_id).to equal(nil) @@ -24,7 +24,7 @@ describe Budget do original_heading = create(:budget_heading) new_heading = create(:budget_heading) investment = create(:budget_investment, heading: original_heading) - investment.update(heading: new_heading) + investment.update!(heading: new_heading) expect(investment.original_heading_id).to eq original_heading.id diff --git a/spec/lib/tasks/dashboards_spec.rb b/spec/lib/tasks/dashboards_spec.rb index 5841092d7..d8af4f81f 100644 --- a/spec/lib/tasks/dashboards_spec.rb +++ b/spec/lib/tasks/dashboards_spec.rb @@ -24,24 +24,24 @@ describe "Dashboards Rake" do it "when there are not news actions actived for published proposals" do create(:proposal) - action.update(published_proposal: true) - resource.update(published_proposal: true) + action.update!(published_proposal: true) + resource.update!(published_proposal: true) expect { run_rake_task }.to change { ActionMailer::Base.deliveries.count }.by(0) end it "when there are not news actions actived for draft proposals" do create(:proposal, :draft) - action.update(published_proposal: false) - resource.update(published_proposal: false) + action.update!(published_proposal: false) + resource.update!(published_proposal: false) expect { run_rake_task }.to change { ActionMailer::Base.deliveries.count }.by(0) end it "when there are news actions actived for archived proposals" do create(:proposal, :archived) - action.update(day_offset: 0, published_proposal: true) - resource.update(day_offset: 0, published_proposal: true) + action.update!(day_offset: 0, published_proposal: true) + resource.update!(day_offset: 0, published_proposal: true) expect { run_rake_task }.to change { ActionMailer::Base.deliveries.count }.by(0) end @@ -54,8 +54,8 @@ describe "Dashboards Rake" do it " when there are news actions actived for published proposals" do proposal = create(:proposal) - action.update(published_proposal: true) - resource.update(published_proposal: true) + action.update!(published_proposal: true) + resource.update!(published_proposal: true) run_rake_task email = open_last_email @@ -67,8 +67,8 @@ describe "Dashboards Rake" do it "when there are news actions actived for draft proposals" do proposal = create(:proposal, :draft) - action.update(published_proposal: false) - resource.update(published_proposal: false) + action.update!(published_proposal: false) + resource.update!(published_proposal: false) run_rake_task email = open_last_email diff --git a/spec/lib/user_segments_spec.rb b/spec/lib/user_segments_spec.rb index 8344a41a1..3aa15257e 100644 --- a/spec/lib/user_segments_spec.rb +++ b/spec/lib/user_segments_spec.rb @@ -71,7 +71,7 @@ describe UserSegments do it "returns users that have created a budget investment" do investment = create(:budget_investment, author: user1) budget = create(:budget) - investment.update(budget: budget) + investment.update!(budget: budget) investment_authors = UserSegments.investment_authors @@ -82,8 +82,8 @@ describe UserSegments do investment1 = create(:budget_investment, author: user1) investment2 = create(:budget_investment, author: user1) budget = create(:budget) - investment1.update(budget: budget) - investment2.update(budget: budget) + investment1.update!(budget: budget) + investment2.update!(budget: budget) investment_authors = UserSegments.investment_authors expect(investment_authors).to contain_exactly(user1) @@ -104,12 +104,12 @@ describe UserSegments do unfeasible_investment_finished = create(:budget_investment, :unfeasible, :finished, author: user6) budget = create(:budget) - feasible_investment_finished.update(budget: budget) - undecided_investment_finished.update(budget: budget) - feasible_investment_unfinished.update(budget: budget) - undecided_investment_unfinished.update(budget: budget) - unfeasible_investment_unfinished.update(budget: budget) - unfeasible_investment_finished.update(budget: budget) + feasible_investment_finished.update!(budget: budget) + undecided_investment_finished.update!(budget: budget) + feasible_investment_unfinished.update!(budget: budget) + undecided_investment_unfinished.update!(budget: budget) + unfeasible_investment_unfinished.update!(budget: budget) + unfeasible_investment_finished.update!(budget: budget) investment_authors = UserSegments.feasible_and_undecided_investment_authors expect(investment_authors).to match_array [user1, user2, user3, user4, user5] @@ -120,8 +120,8 @@ describe UserSegments do feasible_investment = create(:budget_investment, :feasible, author: user1) undecided_investment = create(:budget_investment, :undecided, author: user1) budget = create(:budget) - feasible_investment.update(budget: budget) - undecided_investment.update(budget: budget) + feasible_investment.update!(budget: budget) + undecided_investment.update!(budget: budget) investment_authors = UserSegments.feasible_and_undecided_investment_authors expect(investment_authors).to contain_exactly(user1) @@ -133,8 +133,8 @@ describe UserSegments do selected_investment = create(:budget_investment, :selected, author: user1) unselected_investment = create(:budget_investment, :unselected, author: user2) budget = create(:budget) - selected_investment.update(budget: budget) - unselected_investment.update(budget: budget) + selected_investment.update!(budget: budget) + unselected_investment.update!(budget: budget) investment_authors = UserSegments.selected_investment_authors @@ -145,8 +145,8 @@ describe UserSegments do selected_investment1 = create(:budget_investment, :selected, author: user1) selected_investment2 = create(:budget_investment, :selected, author: user1) budget = create(:budget) - selected_investment1.update(budget: budget) - selected_investment2.update(budget: budget) + selected_investment1.update!(budget: budget) + selected_investment2.update!(budget: budget) investment_authors = UserSegments.selected_investment_authors expect(investment_authors).to contain_exactly(user1) @@ -158,8 +158,8 @@ describe UserSegments do winner_investment = create(:budget_investment, :winner, author: user1) selected_investment = create(:budget_investment, :selected, author: user2) budget = create(:budget) - winner_investment.update(budget: budget) - selected_investment.update(budget: budget) + winner_investment.update!(budget: budget) + selected_investment.update!(budget: budget) investment_authors = UserSegments.winner_investment_authors @@ -170,8 +170,8 @@ describe UserSegments do winner_investment1 = create(:budget_investment, :winner, author: user1) winner_investment2 = create(:budget_investment, :winner, author: user1) budget = create(:budget) - winner_investment1.update(budget: budget) - winner_investment2.update(budget: budget) + winner_investment1.update!(budget: budget) + winner_investment2.update!(budget: budget) investment_authors = UserSegments.winner_investment_authors expect(investment_authors).to contain_exactly(user1) @@ -183,7 +183,7 @@ describe UserSegments do investment1 = create(:budget_investment, author: create(:user)) investment2 = create(:budget_investment, author: create(:user)) budget = create(:budget) - investment1.update(budget: budget) + investment1.update!(budget: budget) current_budget_investments = UserSegments.current_budget_investments @@ -199,8 +199,8 @@ describe UserSegments do budget = create(:budget) investment1.vote_by(voter: user1, vote: "yes") investment2.vote_by(voter: user2, vote: "yes") - investment1.update(budget: budget) - investment2.update(budget: budget) + investment1.update!(budget: budget) + investment2.update!(budget: budget) not_supported_on_current_budget = UserSegments.not_supported_on_current_budget expect(not_supported_on_current_budget).to include user3 diff --git a/spec/mailers/dashboard/mailer_spec.rb b/spec/mailers/dashboard/mailer_spec.rb index c51d9e6c1..f9d430ce7 100644 --- a/spec/mailers/dashboard/mailer_spec.rb +++ b/spec/mailers/dashboard/mailer_spec.rb @@ -62,16 +62,16 @@ describe Dashboard::Mailer do it "Disables email delivery using setting" do Setting["dashboard.emails"] = nil - action.update(published_proposal: false) - resource.update(published_proposal: false) + action.update!(published_proposal: false) + resource.update!(published_proposal: false) run_rake_task expect(ActionMailer::Base.deliveries.count).to eq(0) end it "sends emails when detect new actions for draft proposal" do - action.update(published_proposal: false) - resource.update(published_proposal: false) + action.update!(published_proposal: false) + resource.update!(published_proposal: false) run_rake_task email = open_last_email @@ -160,17 +160,17 @@ describe Dashboard::Mailer do it "Disables email delivery using setting" do Setting["dashboard.emails"] = nil - action.update(published_proposal: false) - resource.update(published_proposal: false) - proposal.save + action.update!(published_proposal: false) + resource.update!(published_proposal: false) + proposal.save! expect(ActionMailer::Base.deliveries.count).to eq(0) end it "sends emails if new actions detected when creating a proposal" do - action.update(published_proposal: false) - resource.update(published_proposal: false) - proposal.save + action.update!(published_proposal: false) + resource.update!(published_proposal: false) + proposal.save! email = open_last_email @@ -227,14 +227,14 @@ describe Dashboard::Mailer do it "Disables email delivery using setting" do Setting["dashboard.emails"] = nil - proposal.save + proposal.save! proposal.publish expect(ActionMailer::Base.deliveries.count).to eq(0) end it "sends emails when detect new actions when publish a proposal" do - proposal.save + proposal.save! proposal.publish email = open_last_email diff --git a/spec/models/abilities/valuator_spec.rb b/spec/models/abilities/valuator_spec.rb index 3ef93c799..33037fc49 100644 --- a/spec/models/abilities/valuator_spec.rb +++ b/spec/models/abilities/valuator_spec.rb @@ -13,7 +13,7 @@ describe Abilities::Valuator do let(:finished_assigned_investment) { create(:budget_investment, budget: create(:budget, :finished), valuators: [valuator]) } it "cannot valuate an assigned investment with a finished valuation" do - assigned_investment.update(valuation_finished: true) + assigned_investment.update!(valuation_finished: true) should_not be_able_to(:valuate, assigned_investment) end diff --git a/spec/models/admin_notification_spec.rb b/spec/models/admin_notification_spec.rb index db03ca383..342f32a57 100644 --- a/spec/models/admin_notification_spec.rb +++ b/spec/models/admin_notification_spec.rb @@ -81,7 +81,7 @@ describe AdminNotification do before do 2.times { create(:user) } erased_user.erase - admin_notification.update(segment_recipient: "all_users") + admin_notification.update!(segment_recipient: "all_users") end it "returns list of all active users" do diff --git a/spec/models/budget/ballot/line_spec.rb b/spec/models/budget/ballot/line_spec.rb index 3ba4ca97a..933b67ab4 100644 --- a/spec/models/budget/ballot/line_spec.rb +++ b/spec/models/budget/ballot/line_spec.rb @@ -20,24 +20,24 @@ describe Budget::Ballot::Line do describe "Money" do it "is not valid if insufficient funds" do - investment.update(price: heading.price + 1) + investment.update!(price: heading.price + 1) expect(ballot_line).not_to be_valid end it "is valid if sufficient funds" do - investment.update(price: heading.price - 1) + investment.update!(price: heading.price - 1) expect(ballot_line).to be_valid end end describe "Selectibility" do it "is not valid if investment is unselected" do - investment.update(selected: false) + investment.update!(selected: false) expect(ballot_line).not_to be_valid end it "is valid if investment is selected" do - investment.update(selected: true, price: 20000) + investment.update!(selected: true, price: 20000) expect(ballot_line).to be_valid end end diff --git a/spec/models/budget/group_spec.rb b/spec/models/budget/group_spec.rb index 28ab3cac7..f74f3efa1 100644 --- a/spec/models/budget/group_spec.rb +++ b/spec/models/budget/group_spec.rb @@ -19,13 +19,13 @@ describe Budget::Group do end it "may be repeated for the same group and a different locale" do - group.update(name_fr: "object name") + group.update!(name_fr: "object name") expect(group.translations.last).to be_valid end it "must not be repeated for a different group in any locale" do - group.update(name_en: "English", name_es: "Español") + group.update!(name_en: "English", name_es: "Español") expect(build(:budget_group, budget: budget, name_en: "English")).not_to be_valid expect(build(:budget_group, budget: budget, name_en: "Español")).not_to be_valid diff --git a/spec/models/budget/heading_spec.rb b/spec/models/budget/heading_spec.rb index 73d623e7d..fa15cd88d 100644 --- a/spec/models/budget/heading_spec.rb +++ b/spec/models/budget/heading_spec.rb @@ -40,13 +40,13 @@ describe Budget::Heading do end it "can be repeated for the same heading and a different locale" do - heading.update(name_fr: "object name") + heading.update!(name_fr: "object name") expect(heading.translations.last).to be_valid end it "must not be repeated for a different heading in any locale" do - heading.update(name_en: "English", name_es: "Español") + heading.update!(name_en: "English", name_es: "Español") expect(build(:budget_heading, group: group, name_en: "English")).not_to be_valid expect(build(:budget_heading, group: group, name_en: "Español")).not_to be_valid diff --git a/spec/models/budget/investment_spec.rb b/spec/models/budget/investment_spec.rb index a322956a7..7f0d4efa0 100644 --- a/spec/models/budget/investment_spec.rb +++ b/spec/models/budget/investment_spec.rb @@ -50,7 +50,7 @@ describe Budget::Investment do expect(investment.budget_id).to eq budget.id expect(investment.group_id).to eq group_1.id - investment.update(heading: heading_2) + investment.update!(heading: heading_2) expect(investment.budget_id).to eq budget.id expect(investment.group_id).to eq group_2.id @@ -68,7 +68,7 @@ describe Budget::Investment do expect(investment.previous_heading_id).to eq nil - investment.update(heading: heading_2) + investment.update!(heading: heading_2) expect(investment.previous_heading_id).to eq heading_1.id end @@ -220,7 +220,7 @@ describe Budget::Investment do it "returns true for selected investments which budget's phase is publishing_prices or later" do Budget::Phase::PUBLISHED_PRICES_PHASES.each do |phase| - budget.update(phase: phase) + budget.update!(phase: phase) expect(investment.should_show_price?).to eq(true) end @@ -228,7 +228,7 @@ describe Budget::Investment do it "returns false in any other phase" do (Budget::Phase::PHASE_KINDS - Budget::Phase::PUBLISHED_PRICES_PHASES).each do |phase| - budget.update(phase: phase) + budget.update!(phase: phase) expect(investment.should_show_price?).to eq(false) end @@ -255,7 +255,7 @@ describe Budget::Investment do it "returns true for selected with price_explanation & budget in publishing_prices or later" do Budget::Phase::PUBLISHED_PRICES_PHASES.each do |phase| - budget.update(phase: phase) + budget.update!(phase: phase) expect(investment.should_show_price_explanation?).to eq(true) end @@ -263,7 +263,7 @@ describe Budget::Investment do it "returns false in any other phase" do (Budget::Phase::PHASE_KINDS - Budget::Phase::PUBLISHED_PRICES_PHASES).each do |phase| - budget.update(phase: phase) + budget.update!(phase: phase) expect(investment.should_show_price_explanation?).to eq(false) end @@ -290,25 +290,25 @@ describe Budget::Investment do it "returns true for unfeasible investments with unfeasibility explanation and valuation finished" do Budget::Phase::PUBLISHED_PRICES_PHASES.each do |phase| - budget.update(phase: phase) + budget.update!(phase: phase) expect(investment.should_show_unfeasibility_explanation?).to eq(true) end end it "returns false in valuation has not finished" do - investment.update(valuation_finished: false) + investment.update!(valuation_finished: false) Budget::Phase::PUBLISHED_PRICES_PHASES.each do |phase| - budget.update(phase: phase) + budget.update!(phase: phase) expect(investment.should_show_unfeasibility_explanation?).to eq(false) end end it "returns false if not unfeasible" do - investment.update(feasibility: "undecided") + investment.update!(feasibility: "undecided") Budget::Phase::PUBLISHED_PRICES_PHASES.each do |phase| - budget.update(phase: phase) + budget.update!(phase: phase) expect(investment.should_show_unfeasibility_explanation?).to eq(false) end @@ -317,7 +317,7 @@ describe Budget::Investment do it "returns false if unfeasibility explanation blank" do investment.unfeasibility_explanation = "" Budget::Phase::PUBLISHED_PRICES_PHASES.each do |phase| - budget.update(phase: phase) + budget.update!(phase: phase) expect(investment.should_show_unfeasibility_explanation?).to eq(false) end @@ -703,7 +703,7 @@ describe Budget::Investment do end it "returns selected investments" do - budget.update(phase: "balloting") + budget.update!(phase: "balloting") investment1 = create(:budget_investment, :feasible, :selected, budget: budget) investment2 = create(:budget_investment, :feasible, :selected, budget: budget) @@ -717,7 +717,7 @@ describe Budget::Investment do end it "returns unselected investments" do - budget.update(phase: "balloting") + budget.update!(phase: "balloting") investment1 = create(:budget_investment, :feasible, :unselected, budget: budget) investment2 = create(:budget_investment, :feasible, :unselected, budget: budget) @@ -855,7 +855,7 @@ describe Budget::Investment do end it "accepts votes in multiple headings of the same group" do - group.update(max_votable_headings: 2) + group.update!(max_votable_headings: 2) carabanchel = create(:budget_heading, group: group) salamanca = create(:budget_heading, group: group) @@ -867,7 +867,7 @@ describe Budget::Investment do end it "accepts votes in any heading previously voted in" do - group.update(max_votable_headings: 2) + group.update!(max_votable_headings: 2) carabanchel = create(:budget_heading, group: group) salamanca = create(:budget_heading, group: group) @@ -927,7 +927,7 @@ describe Budget::Investment do let(:latina_investment) { create(:budget_investment, heading: latina) } it "returns true if the user has voted in less headings than the maximum" do - districts.update(max_votable_headings: 2) + districts.update!(max_votable_headings: 2) create(:vote, votable: carabanchel_investment, voter: user) @@ -935,7 +935,7 @@ describe Budget::Investment do end it "returns false if the user has already voted in the maximum number of headings" do - districts.update(max_votable_headings: 2) + districts.update!(max_votable_headings: 2) create(:vote, votable: carabanchel_investment, voter: user) create(:vote, votable: salamanca_investment, voter: user) @@ -997,7 +997,7 @@ describe Budget::Investment do it "does not get updated if the user is erased" do user.erase - user.update(document_number: nil) + user.update!(document_number: nil) expect(user.document_number).to be_blank investment.touch expect(investment.responsible_name).to eq("123456") @@ -1127,7 +1127,7 @@ describe Budget::Investment do it "returns false if budget is not balloting phase" do Budget::Phase::PHASE_KINDS.reject { |phase| phase == "balloting" }.each do |phase| - budget.update(phase: phase) + budget.update!(phase: phase) investment = create(:budget_investment, budget: budget) investment.heading = heading2 @@ -1147,7 +1147,7 @@ describe Budget::Investment do expect(investment.previous_heading_id).to eq(nil) investment.heading = heading2 - investment.save + investment.save! investment.reload expect(investment.heading_id).to eq(heading2.id) @@ -1205,7 +1205,7 @@ describe Budget::Investment do expect(investment.ballot_lines_count).to eq(3) investment.heading = heading2 - investment.save + investment.save! investment.reload expect(investment.ballot_lines_count).to eq(0) @@ -1219,7 +1219,7 @@ describe Budget::Investment do expect(investment.ballot_lines_count).to eq(3) - investment.save + investment.save! investment.reload expect(investment.ballot_lines_count).to eq(3) diff --git a/spec/models/budget/result_spec.rb b/spec/models/budget/result_spec.rb index 31d6b7f29..9837d395e 100644 --- a/spec/models/budget/result_spec.rb +++ b/spec/models/budget/result_spec.rb @@ -64,7 +64,7 @@ describe Budget::Result do create(:budget_investment, :winner, heading: heading, price: 200, ballot_lines_count: 600) create(:budget_investment, :winner, heading: heading, price: 100, ballot_lines_count: 500) - wrong_win.update(incompatible: true) + wrong_win.update!(incompatible: true) expect(heading.investments.winners.pluck(:ballot_lines_count)).to match_array([800, 700, 600]) end @@ -79,7 +79,7 @@ describe Budget::Result do create(:budget_investment, :winner, heading: heading, price: 200, ballot_lines_count: 600) create(:budget_investment, :winner, heading: heading, price: 100, ballot_lines_count: 500) - miss.update(incompatible: false) + miss.update!(incompatible: false) expect(heading.investments.winners.pluck(:ballot_lines_count)).to match_array([900, 800, 700]) end diff --git a/spec/models/budget_spec.rb b/spec/models/budget_spec.rb index 043709823..3eeebf1c9 100644 --- a/spec/models/budget_spec.rb +++ b/spec/models/budget_spec.rb @@ -22,7 +22,7 @@ describe Budget do end it "may be repeated for the same budget and a different locale" do - budget.update(name_fr: "object name") + budget.update!(name_fr: "object name") expect(budget.translations.last).to be_valid end end @@ -45,7 +45,7 @@ describe Budget do before do budget.phases.each do |phase| phase.description = phase.kind.humanize - phase.save + phase.save! end end @@ -273,28 +273,28 @@ describe Budget do describe "#formatted_amount" do it "correctly formats Euros with Spanish" do - budget.update(currency_symbol: "€") + budget.update!(currency_symbol: "€") I18n.locale = :es expect(budget.formatted_amount(1000.00)).to eq "1.000 €" end it "correctly formats Dollars with Spanish" do - budget.update(currency_symbol: "$") + budget.update!(currency_symbol: "$") I18n.locale = :es expect(budget.formatted_amount(1000.00)).to eq "1.000 $" end it "correctly formats Dollars with English" do - budget.update(currency_symbol: "$") + budget.update!(currency_symbol: "$") I18n.locale = :en expect(budget.formatted_amount(1000.00)).to eq "$1,000" end it "correctly formats Euros with English" do - budget.update(currency_symbol: "€") + budget.update!(currency_symbol: "€") I18n.locale = :en expect(budget.formatted_amount(1000.00)).to eq "€1,000" @@ -314,7 +314,7 @@ describe Budget do it "returns array of investments milestone_tags" do investment1.milestone_tag_list = "tag1" - investment1.save + investment1.save! budget.investments << investment1 expect(budget.milestone_tags).to eq(["tag1"]) @@ -322,9 +322,9 @@ describe Budget do it "returns uniq list of investments milestone_tags" do investment1.milestone_tag_list = "tag1" - investment1.save + investment1.save! investment2.milestone_tag_list = "tag1" - investment2.save + investment2.save! budget.investments << investment1 budget.investments << investment2 @@ -333,9 +333,9 @@ describe Budget do it "returns tags only for winner investments" do investment1.milestone_tag_list = "tag1" - investment1.save + investment1.save! investment3.milestone_tag_list = "tag2" - investment3.save + investment3.save! budget.investments << investment1 budget.investments << investment3 diff --git a/spec/models/concerns/globalizable.rb b/spec/models/concerns/globalizable.rb index e45df8ba0..fc4c01e61 100644 --- a/spec/models/concerns/globalizable.rb +++ b/spec/models/concerns/globalizable.rb @@ -16,7 +16,7 @@ shared_examples_for "globalizable" do |factory_name| record.update_attribute(attribute, "In English") I18n.with_locale(:es) do - record.update(required_fields.map { |field| [field, "En español"] }.to_h) + record.update!(required_fields.map { |field| [field, "En español"] }.to_h) record.update_attribute(attribute, "En español") end @@ -25,7 +25,7 @@ shared_examples_for "globalizable" do |factory_name| describe "Add a translation" do it "Maintains existing translations" do - record.update(translations_attributes: [ + record.update!(translations_attributes: [ { locale: :fr }.merge(fields.map { |field| [field, "En Français"] }.to_h) ]) record.reload @@ -36,7 +36,7 @@ shared_examples_for "globalizable" do |factory_name| end it "Works with non-underscored locale name" do - record.update(translations_attributes: [ + record.update!(translations_attributes: [ { locale: :"pt-BR" }.merge(fields.map { |field| [field, "Português"] }.to_h) ]) record.reload @@ -62,7 +62,7 @@ shared_examples_for "globalizable" do |factory_name| record.translations.destroy_all record.reload - record.update(translations_attributes: [ + record.update!(translations_attributes: [ { locale: :de }.merge(fields.map { |field| [field, "Deutsch"] }.to_h) ]) @@ -74,7 +74,7 @@ shared_examples_for "globalizable" do |factory_name| describe "Update a translation" do it "Changes the existing translation" do - record.update(translations_attributes: [ + record.update!(translations_attributes: [ { id: record.translations.find_by(locale: :es).id, attribute => "Actualizado" } ]) record.reload @@ -98,10 +98,10 @@ shared_examples_for "globalizable" do |factory_name| end it "Does not automatically add a translation for the current locale" do - record.translations.find_by(locale: :en).destroy + record.translations.find_by(locale: :en).destroy! record.reload - record.update(translations_attributes: [ + record.update!(translations_attributes: [ { id: record.translations.first.id }.merge(fields.map { |field| [field, "Cambiado"] }.to_h) ]) @@ -113,7 +113,7 @@ shared_examples_for "globalizable" do |factory_name| describe "Remove a translation" do it "Keeps the other languages" do - record.update(translations_attributes: [ + record.update!(translations_attributes: [ { id: record.translations.find_by(locale: :en).id, _destroy: true } ]) record.reload @@ -155,7 +155,7 @@ shared_examples_for "globalizable" do |factory_name| describe "Fallbacks" do before do I18n.with_locale(:de) do - record.update(required_fields.map { |field| [field, "Deutsch"] }.to_h) + record.update!(required_fields.map { |field| [field, "Deutsch"] }.to_h) record.update_attribute(attribute, "Deutsch") end end @@ -181,7 +181,7 @@ shared_examples_for "globalizable" do |factory_name| it "Falls back to the first available locale after removing a locale" do expect(record.send(attribute)).to eq "In English" - record.update(translations_attributes: [ + record.update!(translations_attributes: [ { id: record.translations.find_by(locale: :en).id, _destroy: true } ]) diff --git a/spec/models/concerns/reportable.rb b/spec/models/concerns/reportable.rb index c18caa8dd..107a739fb 100644 --- a/spec/models/concerns/reportable.rb +++ b/spec/models/concerns/reportable.rb @@ -15,13 +15,13 @@ shared_examples "reportable" do end it "can save the value to the database" do - reportable.update(results_enabled: true) + reportable.update!(results_enabled: true) saved_reportable = described_class.last expect(saved_reportable.results_enabled?).to be true expect(saved_reportable.results_enabled).to be true - reportable.update(results_enabled: false) + reportable.update!(results_enabled: false) saved_reportable = described_class.last expect(saved_reportable.results_enabled?).to be false @@ -31,7 +31,7 @@ shared_examples "reportable" do it "uses the `has_one` relation instead of the original column" do skip "there's no original column" unless reportable.has_attribute?(:results_enabled) - reportable.update(results_enabled: true) + reportable.update!(results_enabled: true) expect(reportable.read_attribute(:results_enabled)).to be false end @@ -51,13 +51,13 @@ shared_examples "reportable" do end it "can save the attribute to the database" do - reportable.update(stats_enabled: true) + reportable.update!(stats_enabled: true) saved_reportable = described_class.last expect(saved_reportable.stats_enabled?).to be true expect(saved_reportable.stats_enabled).to be true - reportable.update(stats_enabled: false) + reportable.update!(stats_enabled: false) saved_reportable = described_class.last expect(saved_reportable.stats_enabled?).to be false @@ -67,7 +67,7 @@ shared_examples "reportable" do it "uses the `has_one` relation instead of the original column" do skip "there's no original column" unless reportable.has_attribute?(:stats_enabled) - reportable.update(stats_enabled: true) + reportable.update!(stats_enabled: true) expect(reportable.read_attribute(:stats_enabled)).to be false end diff --git a/spec/models/dashboard/action_spec.rb b/spec/models/dashboard/action_spec.rb index 9d39c6ed0..e1973a7a5 100644 --- a/spec/models/dashboard/action_spec.rb +++ b/spec/models/dashboard/action_spec.rb @@ -248,32 +248,32 @@ describe Dashboard::Action do it "when there are not news actions actived for published proposals" do proposal = create(:proposal) - action.update(published_proposal: true) - resource.update(published_proposal: true) + action.update!(published_proposal: true) + resource.update!(published_proposal: true) expect(Dashboard::Action.detect_new_actions_since(Date.yesterday, proposal)).to eq [] end it "when there are news actions actived for draft_proposal but proposal is published" do proposal = create(:proposal) - action.update(published_proposal: false, day_offset: 0) - resource.update(published_proposal: false, day_offset: 0) + action.update!(published_proposal: false, day_offset: 0) + resource.update!(published_proposal: false, day_offset: 0) expect(Dashboard::Action.detect_new_actions_since(Date.yesterday, proposal)).to eq [] end it "when there are not news actions actived for draft proposals" do proposal = create(:proposal, :draft) - action.update(published_proposal: false) - resource.update(published_proposal: false) + action.update!(published_proposal: false) + resource.update!(published_proposal: false) expect(Dashboard::Action.detect_new_actions_since(Date.yesterday, proposal)).to eq [] end it "when there are news actions actived for published_proposal but proposal is draft" do proposal = create(:proposal, :draft) - action.update(published_proposal: true, day_offset: 0) - resource.update(published_proposal: true, day_offset: 0) + action.update!(published_proposal: true, day_offset: 0) + resource.update!(published_proposal: true, day_offset: 0) expect(Dashboard::Action.detect_new_actions_since(Date.yesterday, proposal)).to eq [] end @@ -301,9 +301,9 @@ describe Dashboard::Action do end it "when proposal has received a new vote today" do - proposal.update(created_at: Date.yesterday, published_at: Date.yesterday) - action.update(required_supports: 1) - resource.update(required_supports: 0) + proposal.update!(created_at: Date.yesterday, published_at: Date.yesterday) + action.update!(required_supports: 1) + resource.update!(required_supports: 0) create(:vote, voter: proposal.author, votable: proposal) expect(Dashboard::Action.detect_new_actions_since(Date.yesterday, @@ -333,9 +333,9 @@ describe Dashboard::Action do end it "when proposal has received a new vote today" do - proposal.update(created_at: Date.yesterday) - action.update(required_supports: 1) - resource.update(required_supports: 2) + proposal.update!(created_at: Date.yesterday) + action.update!(required_supports: 1) + resource.update!(required_supports: 2) create(:vote, voter: proposal.author, votable: proposal) expect(Dashboard::Action.detect_new_actions_since(Date.yesterday, diff --git a/spec/models/debate_spec.rb b/spec/models/debate_spec.rb index 7b419be0c..cc6662297 100644 --- a/spec/models/debate_spec.rb +++ b/spec/models/debate_spec.rb @@ -133,19 +133,19 @@ describe Debate do end it "is true for anonymous users if allowed anonymous votes" do - debate.update(cached_anonymous_votes_total: 420, cached_votes_total: 1000) + debate.update!(cached_anonymous_votes_total: 420, cached_votes_total: 1000) user = create(:user) expect(debate.votable_by?(user)).to be true end it "is true for anonymous users if less than 100 votes" do - debate.update(cached_anonymous_votes_total: 90, cached_votes_total: 92) + debate.update!(cached_anonymous_votes_total: 90, cached_votes_total: 92) user = create(:user) expect(debate.votable_by?(user)).to be true end it "is false for anonymous users if too many anonymous votes" do - debate.update(cached_anonymous_votes_total: 520, cached_votes_total: 1000) + debate.update!(cached_anonymous_votes_total: 520, cached_votes_total: 1000) user = create(:user) expect(debate.votable_by?(user)).to be false end @@ -417,44 +417,44 @@ describe Debate do describe "conflictive debates" do it "returns true when it has more than 1 flag for 5 positive votes" do - debate.update(cached_votes_up: 4) - debate.update(flags_count: 1) + debate.update!(cached_votes_up: 4) + debate.update!(flags_count: 1) expect(debate).to be_conflictive - debate.update(cached_votes_up: 9) - debate.update(flags_count: 2) + debate.update!(cached_votes_up: 9) + debate.update!(flags_count: 2) expect(debate).to be_conflictive - debate.update(cached_votes_up: 14) - debate.update(flags_count: 3) + debate.update!(cached_votes_up: 14) + debate.update!(flags_count: 3) expect(debate).to be_conflictive - debate.update(cached_votes_up: 2) - debate.update(flags_count: 20) + debate.update!(cached_votes_up: 2) + debate.update!(flags_count: 20) expect(debate).to be_conflictive end it "returns false when it has less than or equal to 1 flag for 5 positive votes" do - debate.update(cached_votes_up: 5) - debate.update(flags_count: 1) + debate.update!(cached_votes_up: 5) + debate.update!(flags_count: 1) expect(debate).not_to be_conflictive - debate.update(cached_votes_up: 10) - debate.update(flags_count: 2) + debate.update!(cached_votes_up: 10) + debate.update!(flags_count: 2) expect(debate).not_to be_conflictive - debate.update(cached_votes_up: 100) - debate.update(flags_count: 2) + debate.update!(cached_votes_up: 100) + debate.update!(flags_count: 2) expect(debate).not_to be_conflictive end it "returns false when it has no flags" do - debate.update(flags_count: 0) + debate.update!(flags_count: 0) expect(debate).not_to be_conflictive end it "returns false when it has not votes up" do - debate.update(cached_votes_up: 0) + debate.update!(cached_votes_up: 0) expect(debate).not_to be_conflictive end diff --git a/spec/models/legislation/process/phase_spec.rb b/spec/models/legislation/process/phase_spec.rb index 902e49bd0..d30cc6265 100644 --- a/spec/models/legislation/process/phase_spec.rb +++ b/spec/models/legislation/process/phase_spec.rb @@ -8,7 +8,7 @@ RSpec.describe Legislation::Process::Phase, type: :model do it "checks debate phase" do expect(process.debate_phase.enabled?).to be true - process.update_attributes(debate_phase_enabled: false) + process.update_attributes!(debate_phase_enabled: false) expect(process.debate_phase.enabled?).to be false end @@ -16,14 +16,14 @@ RSpec.describe Legislation::Process::Phase, type: :model do expect(process.draft_phase.enabled?).to be false expect(process_in_draft_phase.draft_phase.enabled?).to be true - process.update_attributes(draft_phase_enabled: false) + process.update_attributes!(draft_phase_enabled: false) expect(process.draft_phase.enabled?).to be false end it "checks allegations phase" do expect(process.allegations_phase.enabled?).to be true - process.update_attributes(allegations_phase_enabled: false) + process.update_attributes!(allegations_phase_enabled: false) expect(process.allegations_phase.enabled?).to be false end end @@ -31,66 +31,66 @@ RSpec.describe Legislation::Process::Phase, type: :model do describe "#started?" do it "checks debate phase" do # future - process.update_attributes(debate_start_date: Date.current + 2.days, + process.update_attributes!(debate_start_date: Date.current + 2.days, debate_end_date: Date.current + 3.days) expect(process.debate_phase.started?).to be false # started - process.update_attributes(debate_start_date: Date.current - 2.days, + process.update_attributes!(debate_start_date: Date.current - 2.days, debate_end_date: Date.current + 1.day) expect(process.debate_phase.started?).to be true # starts today - process.update_attributes(debate_start_date: Date.current, + process.update_attributes!(debate_start_date: Date.current, debate_end_date: Date.current + 1.day) expect(process.debate_phase.started?).to be true # past - process.update_attributes(debate_start_date: Date.current - 2.days, + process.update_attributes!(debate_start_date: Date.current - 2.days, debate_end_date: Date.current - 1.day) expect(process.debate_phase.started?).to be true end it "checks draft phase" do # future - process.update_attributes(draft_start_date: Date.current + 2.days, + process.update_attributes!(draft_start_date: Date.current + 2.days, draft_end_date: Date.current + 3.days, draft_phase_enabled: true) expect(process.draft_phase.started?).to be false # started - process.update_attributes(draft_start_date: Date.current - 2.days, + process.update_attributes!(draft_start_date: Date.current - 2.days, draft_end_date: Date.current + 1.day, draft_phase_enabled: true) expect(process.draft_phase.started?).to be true # starts today - process.update_attributes(draft_start_date: Date.current, + process.update_attributes!(draft_start_date: Date.current, draft_end_date: Date.current + 1.day, draft_phase_enabled: true) expect(process.draft_phase.started?).to be true # past - process.update_attributes(draft_start_date: Date.current - 2.days, + process.update_attributes!(draft_start_date: Date.current - 2.days, draft_end_date: Date.current - 1.day, draft_phase_enabled: true) expect(process.draft_phase.started?).to be true end it "checks allegations phase" do # future - process.update_attributes(allegations_start_date: Date.current + 2.days, + process.update_attributes!(allegations_start_date: Date.current + 2.days, allegations_end_date: Date.current + 3.days) expect(process.allegations_phase.started?).to be false # started - process.update_attributes(allegations_start_date: Date.current - 2.days, + process.update_attributes!(allegations_start_date: Date.current - 2.days, allegations_end_date: Date.current + 1.day) expect(process.allegations_phase.started?).to be true # starts today - process.update_attributes(allegations_start_date: Date.current, + process.update_attributes!(allegations_start_date: Date.current, allegations_end_date: Date.current + 1.day) expect(process.allegations_phase.started?).to be true # past - process.update_attributes(allegations_start_date: Date.current - 2.days, + process.update_attributes!(allegations_start_date: Date.current - 2.days, allegations_end_date: Date.current - 1.day) expect(process.allegations_phase.started?).to be true end @@ -99,44 +99,44 @@ RSpec.describe Legislation::Process::Phase, type: :model do describe "#open?" do it "checks debate phase" do # future - process.update_attributes(debate_start_date: Date.current + 2.days, + process.update_attributes!(debate_start_date: Date.current + 2.days, debate_end_date: Date.current + 3.days) expect(process.debate_phase.open?).to be false # started - process.update_attributes(debate_start_date: Date.current - 2.days, + process.update_attributes!(debate_start_date: Date.current - 2.days, debate_end_date: Date.current + 1.day) expect(process.debate_phase.open?).to be true # starts today - process.update_attributes(debate_start_date: Date.current, + process.update_attributes!(debate_start_date: Date.current, debate_end_date: Date.current + 1.day) expect(process.debate_phase.open?).to be true # past - process.update_attributes(debate_start_date: Date.current - 2.days, + process.update_attributes!(debate_start_date: Date.current - 2.days, debate_end_date: Date.current - 1.day) expect(process.debate_phase.open?).to be false end it "checks draft phase" do # future - process.update_attributes(draft_start_date: Date.current + 2.days, + process.update_attributes!(draft_start_date: Date.current + 2.days, draft_end_date: Date.current + 3.days, draft_phase_enabled: true) expect(process.draft_phase.open?).to be false # started - process.update_attributes(draft_start_date: Date.current - 2.days, + process.update_attributes!(draft_start_date: Date.current - 2.days, draft_end_date: Date.current + 1.day, draft_phase_enabled: true) expect(process.draft_phase.open?).to be true # starts today - process.update_attributes(draft_start_date: Date.current, + process.update_attributes!(draft_start_date: Date.current, draft_end_date: Date.current + 1.day, draft_phase_enabled: true) expect(process.draft_phase.open?).to be true # past - process.update_attributes(draft_start_date: Date.current - 2.days, + process.update_attributes!(draft_start_date: Date.current - 2.days, draft_end_date: Date.current - 1.day, draft_phase_enabled: true) expect(process.draft_phase.open?).to be false end @@ -144,22 +144,22 @@ RSpec.describe Legislation::Process::Phase, type: :model do it "checks allegations phase" do # future - process.update_attributes(allegations_start_date: Date.current + 2.days, + process.update_attributes!(allegations_start_date: Date.current + 2.days, allegations_end_date: Date.current + 3.days) expect(process.allegations_phase.open?).to be false # started - process.update_attributes(allegations_start_date: Date.current - 2.days, + process.update_attributes!(allegations_start_date: Date.current - 2.days, allegations_end_date: Date.current + 1.day) expect(process.allegations_phase.open?).to be true # starts today - process.update_attributes(allegations_start_date: Date.current, + process.update_attributes!(allegations_start_date: Date.current, allegations_end_date: Date.current + 1.day) expect(process.allegations_phase.open?).to be true # past - process.update_attributes(allegations_start_date: Date.current - 2.days, + process.update_attributes!(allegations_start_date: Date.current - 2.days, allegations_end_date: Date.current - 1.day) expect(process.allegations_phase.open?).to be false end diff --git a/spec/models/legislation/process/publication_spec.rb b/spec/models/legislation/process/publication_spec.rb index a2642b9eb..e09eb2f1c 100644 --- a/spec/models/legislation/process/publication_spec.rb +++ b/spec/models/legislation/process/publication_spec.rb @@ -7,14 +7,14 @@ RSpec.describe Legislation::Process::Publication, type: :model do it "checks draft publication" do expect(process.draft_publication.enabled?).to be true - process.update_attributes(draft_publication_enabled: false) + process.update_attributes!(draft_publication_enabled: false) expect(process.draft_publication.enabled?).to be false end it "checks result publication" do expect(process.result_publication.enabled?).to be true - process.update_attributes(result_publication_enabled: false) + process.update_attributes!(result_publication_enabled: false) expect(process.result_publication.enabled?).to be false end end @@ -22,29 +22,29 @@ RSpec.describe Legislation::Process::Publication, type: :model do describe "#started?" do it "checks draft publication" do # future - process.update_attributes(draft_publication_date: Date.current + 2.days) + process.update_attributes!(draft_publication_date: Date.current + 2.days) expect(process.draft_publication.started?).to be false # past - process.update_attributes(draft_publication_date: Date.current - 2.days) + process.update_attributes!(draft_publication_date: Date.current - 2.days) expect(process.draft_publication.started?).to be true # starts today - process.update_attributes(draft_publication_date: Date.current) + process.update_attributes!(draft_publication_date: Date.current) expect(process.draft_publication.started?).to be true end it "checks result publication" do # future - process.update_attributes(result_publication_date: Date.current + 2.days) + process.update_attributes!(result_publication_date: Date.current + 2.days) expect(process.result_publication.started?).to be false # past - process.update_attributes(result_publication_date: Date.current - 2.days) + process.update_attributes!(result_publication_date: Date.current - 2.days) expect(process.result_publication.started?).to be true # starts today - process.update_attributes(result_publication_date: Date.current) + process.update_attributes!(result_publication_date: Date.current) expect(process.result_publication.started?).to be true end end @@ -52,29 +52,29 @@ RSpec.describe Legislation::Process::Publication, type: :model do describe "#open?" do it "checks draft publication" do # future - process.update_attributes(draft_publication_date: Date.current + 2.days) + process.update_attributes!(draft_publication_date: Date.current + 2.days) expect(process.draft_publication.open?).to be false # past - process.update_attributes(draft_publication_date: Date.current - 2.days) + process.update_attributes!(draft_publication_date: Date.current - 2.days) expect(process.draft_publication.open?).to be true # starts today - process.update_attributes(draft_publication_date: Date.current) + process.update_attributes!(draft_publication_date: Date.current) expect(process.draft_publication.open?).to be true end it "checks result publication" do # future - process.update_attributes(result_publication_date: Date.current + 2.days) + process.update_attributes!(result_publication_date: Date.current + 2.days) expect(process.result_publication.open?).to be false # past - process.update_attributes(result_publication_date: Date.current - 2.days) + process.update_attributes!(result_publication_date: Date.current - 2.days) expect(process.result_publication.open?).to be true # starts today - process.update_attributes(result_publication_date: Date.current) + process.update_attributes!(result_publication_date: Date.current) expect(process.result_publication.open?).to be true end end diff --git a/spec/models/legislation/process_spec.rb b/spec/models/legislation/process_spec.rb index f41201e8b..ce4600981 100644 --- a/spec/models/legislation/process_spec.rb +++ b/spec/models/legislation/process_spec.rb @@ -162,12 +162,12 @@ describe Legislation::Process do describe "#status" do it "detects planned phase" do - process.update_attributes(start_date: Date.current + 2.days) + process.update_attributes!(start_date: Date.current + 2.days) expect(process.status).to eq(:planned) end it "detects closed phase" do - process.update_attributes(end_date: Date.current - 2.days) + process.update_attributes!(end_date: Date.current - 2.days) expect(process.status).to eq(:closed) end diff --git a/spec/models/lock_spec.rb b/spec/models/lock_spec.rb index 55d0bf5c1..02c05e829 100644 --- a/spec/models/lock_spec.rb +++ b/spec/models/lock_spec.rb @@ -19,15 +19,15 @@ describe Lock do describe "#lock_time" do it "increases exponentially with number of tries" do lock.tries = 5 - lock.save + lock.save! expect(lock.reload.lock_time).to be_between(30.minutes.from_now, 35.minutes.from_now) lock.tries = 10 - lock.save + lock.save! expect(lock.reload.lock_time).to be_between(16.hours.from_now, 18.hours.from_now) lock.tries = 15 - lock.save + lock.save! expect(lock.reload.lock_time).to be_between(21.days.from_now, 23.days.from_now) end end diff --git a/spec/models/newsletter_spec.rb b/spec/models/newsletter_spec.rb index 82e8087ba..f95383156 100644 --- a/spec/models/newsletter_spec.rb +++ b/spec/models/newsletter_spec.rb @@ -53,7 +53,7 @@ describe Newsletter do create(:user, newsletter: true, email: "newsletter_user@consul.dev") create(:user, newsletter: false, email: "no_news_user@consul.dev") create(:user, email: "erased_user@consul.dev").erase - newsletter.update(segment_recipient: "all_users") + newsletter.update!(segment_recipient: "all_users") end it "returns list of recipients excluding users with disabled newsletter" do diff --git a/spec/models/notification_spec.rb b/spec/models/notification_spec.rb index 15c05837a..80b442ca5 100644 --- a/spec/models/notification_spec.rb +++ b/spec/models/notification_spec.rb @@ -147,7 +147,7 @@ describe Notification do comment = create(:comment) first_notification = Notification.add(user, comment) - first_notification.update(read_at: Time.current) + first_notification.update!(read_at: Time.current) second_notification = Notification.add(user, comment) diff --git a/spec/models/officing/residence_spec.rb b/spec/models/officing/residence_spec.rb index 711a9af02..f6d76cf39 100644 --- a/spec/models/officing/residence_spec.rb +++ b/spec/models/officing/residence_spec.rb @@ -159,7 +159,7 @@ describe Officing::Residence do describe "save" do it "stores document number, document type, geozone, date of birth and gender" do - residence.save + residence.save! user = residence.user expect(user.document_number).to eq("12345678Z") @@ -183,7 +183,7 @@ describe Officing::Residence do document_number: "12345678Z", document_type: "1") - residence.save + residence.save! user = residence.user expect(user.document_number).to eq("12345678Z") @@ -201,7 +201,7 @@ describe Officing::Residence do residence = build(:officing_residence, document_number: "12345678Z", year_of_birth: 1980) expect(residence).to be_valid expect(user.reload).to be_unverified - residence.save + residence.save! expect(user.reload).to be_level_three_verified end diff --git a/spec/models/poll/ballot_sheet_spec.rb b/spec/models/poll/ballot_sheet_spec.rb index 16100fdc6..75f63fe68 100644 --- a/spec/models/poll/ballot_sheet_spec.rb +++ b/spec/models/poll/ballot_sheet_spec.rb @@ -52,7 +52,7 @@ describe Poll::BallotSheet do describe "#parsed_ballots" do it "splits ballots by ';' or '\n'" do data = "1,2,3;4,5,6\n7,8,9" - ballot_sheet.update(data: data) + ballot_sheet.update!(data: data) expect(ballot_sheet.parsed_ballots).to eq(["1,2,3", "4,5,6", "7,8,9"]) end diff --git a/spec/models/poll/ballot_spec.rb b/spec/models/poll/ballot_spec.rb index 7c1f8d883..eaeae3a10 100644 --- a/spec/models/poll/ballot_spec.rb +++ b/spec/models/poll/ballot_spec.rb @@ -18,7 +18,7 @@ describe Poll::Ballot do investment3 = create(:budget_investment, :selected, price: 2000000, heading: heading) investment4 = create(:budget_investment, :selected, price: 2000000, heading: heading) - poll_ballot.update(data: [investment.id, investment2.id, investment3.id, investment4.id].join(",")) + poll_ballot.update!(data: [investment.id, investment2.id, investment3.id, investment4.id].join(",")) poll_ballot.verify expect(poll_ballot.ballot.lines.pluck(:investment_id)).to match_array [investment.id, investment2.id, investment3.id] @@ -31,7 +31,7 @@ describe Poll::Ballot do investment3 = create(:budget_investment, :selected, price: 2000000, heading: heading) investment4 = create(:budget_investment, :selected, price: 2000000, heading: other_heading) - poll_ballot.update(data: [investment.id, investment2.id, investment3.id, investment4.id].join(",")) + poll_ballot.update!(data: [investment.id, investment2.id, investment3.id, investment4.id].join(",")) poll_ballot.verify expect(poll_ballot.ballot.lines.pluck(:investment_id)).to match_array [investment.id, investment2.id, investment3.id] @@ -42,7 +42,7 @@ describe Poll::Ballot do investment3 = create(:budget_investment, :selected, price: 2000000, heading: heading) investment4 = create(:budget_investment, price: 2000000, heading: heading) - poll_ballot.update(data: [investment.id, investment2.id, investment3.id, investment4.id].join(",")) + poll_ballot.update!(data: [investment.id, investment2.id, investment3.id, investment4.id].join(",")) poll_ballot.verify expect(poll_ballot.ballot.lines.pluck(:investment_id)).to match_array [investment.id, investment2.id, investment3.id] @@ -54,12 +54,12 @@ describe Poll::Ballot do describe "Money" do it "is not valid if insufficient funds" do - investment.update(price: heading.price + 1) + investment.update!(price: heading.price + 1) expect(poll_ballot.add_investment(investment.id)).to be(false) end it "is valid if sufficient funds" do - investment.update(price: heading.price - 1) + investment.update!(price: heading.price - 1) expect(poll_ballot.add_investment(investment.id)).to be(true) end end @@ -85,12 +85,12 @@ describe Poll::Ballot do describe "Selectibility" do it "is not valid if investment is unselected" do - investment.update(selected: false) + investment.update!(selected: false) expect(poll_ballot.add_investment(investment.id)).to be(false) end it "is valid if investment is selected" do - investment.update(selected: true, price: 20000) + investment.update!(selected: true, price: 20000) expect(poll_ballot.add_investment(investment.id)).to be(true) end end @@ -98,7 +98,7 @@ describe Poll::Ballot do describe "Budget" do it "is not valid if investment belongs to a different budget" do other_budget = create(:budget) - investment.update(budget: other_budget) + investment.update!(budget: other_budget) expect(poll_ballot.add_investment(investment.id)).to be(nil) end diff --git a/spec/models/poll/booth_assignment_spec.rb b/spec/models/poll/booth_assignment_spec.rb index 7d9ce3e26..2dafa0c1d 100644 --- a/spec/models/poll/booth_assignment_spec.rb +++ b/spec/models/poll/booth_assignment_spec.rb @@ -22,7 +22,7 @@ describe Poll::BoothAssignment do create(:poll_officer_assignment, officer: officer, booth_assignment: assignment) create(:poll_shift, booth: booth, officer: officer) - assignment.destroy + assignment.destroy! expect(Poll::Shift.all.count).to eq(0) end diff --git a/spec/models/poll/officer_spec.rb b/spec/models/poll/officer_spec.rb index b8c8a29a3..3e1911386 100644 --- a/spec/models/poll/officer_spec.rb +++ b/spec/models/poll/officer_spec.rb @@ -10,7 +10,7 @@ describe Poll::Officer do end it "returns 'User deleted' if user is deleted" do - officer.user.destroy + officer.user.destroy! expect(officer.reload.name).to eq "User deleted" end @@ -24,7 +24,7 @@ describe Poll::Officer do end it "returns 'Email deleted' if user is deleted" do - officer.user.destroy + officer.user.destroy! expect(officer.reload.email).to eq "Email deleted" end diff --git a/spec/models/poll/partial_result_spec.rb b/spec/models/poll/partial_result_spec.rb index fc143dbc0..e9124ec53 100644 --- a/spec/models/poll/partial_result_spec.rb +++ b/spec/models/poll/partial_result_spec.rb @@ -24,11 +24,11 @@ describe Poll::PartialResult do expect(partial_result.amount_log).to eq("") partial_result.amount = 33 - partial_result.save + partial_result.save! partial_result.amount = 32 - partial_result.save + partial_result.save! partial_result.amount = 34 - partial_result.save + partial_result.save! expect(partial_result.amount_log).to eq(":33:32") end @@ -41,15 +41,15 @@ describe Poll::PartialResult do partial_result.amount = 33 partial_result.officer_assignment = create(:poll_officer_assignment, id: 10) - partial_result.save + partial_result.save! partial_result.amount = 32 partial_result.officer_assignment = create(:poll_officer_assignment, id: 20) - partial_result.save + partial_result.save! partial_result.amount = 34 partial_result.officer_assignment = create(:poll_officer_assignment, id: 30) - partial_result.save + partial_result.save! expect(partial_result.amount_log).to eq(":33:32") expect(partial_result.officer_assignment_id_log).to eq(":10:20") diff --git a/spec/models/poll/recount_spec.rb b/spec/models/poll/recount_spec.rb index 3ce32056a..bdd34a7d0 100644 --- a/spec/models/poll/recount_spec.rb +++ b/spec/models/poll/recount_spec.rb @@ -13,11 +13,11 @@ describe Poll::Recount do expect(poll_recount.white_amount_log).to eq("") poll_recount.white_amount = 33 - poll_recount.save + poll_recount.save! poll_recount.white_amount = 32 - poll_recount.save + poll_recount.save! poll_recount.white_amount = 34 - poll_recount.save + poll_recount.save! expect(poll_recount.white_amount_log).to eq(":0:33:32") end @@ -28,11 +28,11 @@ describe Poll::Recount do expect(poll_recount.null_amount_log).to eq("") poll_recount.null_amount = 33 - poll_recount.save + poll_recount.save! poll_recount.null_amount = 32 - poll_recount.save + poll_recount.save! poll_recount.null_amount = 34 - poll_recount.save + poll_recount.save! expect(poll_recount.null_amount_log).to eq(":0:33:32") end @@ -43,11 +43,11 @@ describe Poll::Recount do expect(poll_recount.total_amount_log).to eq("") poll_recount.total_amount = 33 - poll_recount.save + poll_recount.save! poll_recount.total_amount = 32 - poll_recount.save + poll_recount.save! poll_recount.total_amount = 34 - poll_recount.save + poll_recount.save! expect(poll_recount.total_amount_log).to eq(":0:33:32") end @@ -60,15 +60,15 @@ describe Poll::Recount do poll_recount.white_amount = 33 poll_recount.officer_assignment = create(:poll_officer_assignment, id: 101) - poll_recount.save + poll_recount.save! poll_recount.white_amount = 32 poll_recount.officer_assignment = create(:poll_officer_assignment, id: 102) - poll_recount.save + poll_recount.save! poll_recount.white_amount = 34 poll_recount.officer_assignment = create(:poll_officer_assignment, id: 103) - poll_recount.save + poll_recount.save! expect(poll_recount.white_amount_log).to eq(":0:33:32") expect(poll_recount.officer_assignment_id_log).to eq(":#{officer_assignment.id}:101:102") diff --git a/spec/models/poll/shift_spec.rb b/spec/models/poll/shift_spec.rb index 539a5f988..757151be4 100644 --- a/spec/models/poll/shift_spec.rb +++ b/spec/models/poll/shift_spec.rb @@ -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" diff --git a/spec/models/poll/voter_spec.rb b/spec/models/poll/voter_spec.rb index 88cdc02ce..1b5d5f1bd 100644 --- a/spec/models/poll/voter_spec.rb +++ b/spec/models/poll/voter_spec.rb @@ -155,13 +155,13 @@ describe Poll::Voter do it "sets demographic info" do geozone = create(:geozone) - user = create(:user, + user = create(:user, :level_two, geozone: geozone, date_of_birth: 30.years.ago, gender: "female") voter = build(:poll_voter, user: user) - voter.save + voter.save! expect(voter.geozone).to eq(geozone) expect(voter.age).to eq(30) @@ -171,7 +171,7 @@ describe Poll::Voter do it "sets user info" do user = create(:user, document_number: "1234A", document_type: "1") voter = build(:poll_voter, user: user, token: "1234abcd") - voter.save + voter.save! expect(voter.document_number).to eq("1234A") expect(voter.document_type).to eq("1") diff --git a/spec/models/progress_bar_spec.rb b/spec/models/progress_bar_spec.rb index e09663e0a..41e681538 100644 --- a/spec/models/progress_bar_spec.rb +++ b/spec/models/progress_bar_spec.rb @@ -70,7 +70,7 @@ describe ProgressBar do end it "cannot have another primary progress bar for the same progressable" do - progress_bar.save + progress_bar.save! duplicate = build(:progress_bar, progressable: progress_bar.progressable) expect(duplicate).not_to be_valid @@ -90,7 +90,7 @@ describe ProgressBar do end it "can have another secondary progress bar for the same progressable" do - progress_bar.save + progress_bar.save! duplicate = build(:progress_bar, progressable: progress_bar.progressable) expect(duplicate).to be_valid diff --git a/spec/models/proposal_notification_spec.rb b/spec/models/proposal_notification_spec.rb index 48bee9d69..b47dbaeda 100644 --- a/spec/models/proposal_notification_spec.rb +++ b/spec/models/proposal_notification_spec.rb @@ -110,7 +110,7 @@ describe ProposalNotification do it "returns false when the proposal is not available" do notification = create(:notification, notifiable: notifiable) - notifiable.proposal.destroy + notifiable.proposal.destroy! expect(notification.notifiable_available?).to be(false) end @@ -142,7 +142,7 @@ describe ProposalNotification do it "returns false if the resource is retired" do notification = create(:notification, notifiable: notifiable) - notifiable.proposal.update(retired_at: Time.current, + notifiable.proposal.update!(retired_at: Time.current, retired_explanation: "Unfeasible reason explanation", retired_reason: "unfeasible") expect(notification.check_availability(proposal)).to be(false) diff --git a/spec/models/proposal_spec.rb b/spec/models/proposal_spec.rb index 625ef2fc5..eb33273ef 100644 --- a/spec/models/proposal_spec.rb +++ b/spec/models/proposal_spec.rb @@ -100,11 +100,11 @@ describe Proposal do it "is not updated when the author is deleted" do author = create(:user, :level_three, document_number: "12345678Z") proposal.author = author - proposal.save + proposal.save! proposal.author.erase - proposal.save + proposal.save! expect(proposal.responsible_name).to eq "12345678Z" end end diff --git a/spec/models/setting_spec.rb b/spec/models/setting_spec.rb index 125805211..b2006a24a 100644 --- a/spec/models/setting_spec.rb +++ b/spec/models/setting_spec.rb @@ -19,64 +19,64 @@ describe Setting do describe "#prefix" do it "returns the prefix of its key" do - expect(Setting.create(key: "prefix.key_name").prefix).to eq "prefix" + expect(Setting.create!(key: "prefix.key_name").prefix).to eq "prefix" end it "returns the whole key for a non prefixed key" do - expect(Setting.create(key: "key_name").prefix).to eq "key_name" + expect(Setting.create!(key: "key_name").prefix).to eq "key_name" end end describe "#type" do it "returns the key prefix for 'process' settings" do - process_setting = Setting.create(key: "process.whatever") + process_setting = Setting.create!(key: "process.whatever") expect(process_setting.type).to eq "process" end it "returns the key prefix for 'feature' settings" do - feature_setting = Setting.create(key: "feature.whatever") + feature_setting = Setting.create!(key: "feature.whatever") expect(feature_setting.type).to eq "feature" end it "returns the key prefix for 'map' settings" do - map_setting = Setting.create(key: "map.whatever") + map_setting = Setting.create!(key: "map.whatever") expect(map_setting.type).to eq "map" end it "returns the key prefix for 'html' settings" do - html_setting = Setting.create(key: "html.whatever") + html_setting = Setting.create!(key: "html.whatever") expect(html_setting.type).to eq "html" end it "returns the key prefix for 'homepage' settings" do - homepage_setting = Setting.create(key: "homepage.whatever") + homepage_setting = Setting.create!(key: "homepage.whatever") expect(homepage_setting.type).to eq "homepage" end it "returns the key prefix for 'remote_census.general' settings" do - remote_census_general_setting = Setting.create(key: "remote_census.general.whatever") + remote_census_general_setting = Setting.create!(key: "remote_census.general.whatever") expect(remote_census_general_setting.type).to eq "remote_census.general" end it "returns the key prefix for 'remote_census_request' settings" do - remote_census_request_setting = Setting.create(key: "remote_census.request.whatever") + remote_census_request_setting = Setting.create!(key: "remote_census.request.whatever") expect(remote_census_request_setting.type).to eq "remote_census.request" end it "returns the key prefix for 'remote_census_response' settings" do - remote_census_response_setting = Setting.create(key: "remote_census.response.whatever") + remote_census_response_setting = Setting.create!(key: "remote_census.response.whatever") expect(remote_census_response_setting.type).to eq "remote_census.response" end it "returns 'configuration' for the rest of the settings" do - configuration_setting = Setting.create(key: "whatever") + configuration_setting = Setting.create!(key: "whatever") expect(configuration_setting.type).to eq "configuration" end end describe "#enabled?" do it "is true if value is present" do - setting = Setting.create(key: "feature.whatever", value: 1) + setting = Setting.create!(key: "feature.whatever", value: 1) expect(setting.enabled?).to eq true setting.value = "true" @@ -87,7 +87,7 @@ describe Setting do end it "is false if value is blank" do - setting = Setting.create(key: "feature.whatever") + setting = Setting.create!(key: "feature.whatever") expect(setting.enabled?).to eq false setting.value = "" @@ -97,18 +97,18 @@ describe Setting do describe "#content_type?" do it "returns true if the last part of the key is content_types" do - expect(Setting.create(key: "key_name.content_types").content_type?).to be true + expect(Setting.create!(key: "key_name.content_types").content_type?).to be true end it "returns false if the last part of the key is not content_types" do - expect(Setting.create(key: "key_name.whatever").content_type?).to be false + expect(Setting.create!(key: "key_name.whatever").content_type?).to be false end end describe "#content_type_group" do it "returns the group for content_types settings" do - images = Setting.create(key: "update.images.content_types") - documents = Setting.create(key: "update.documents.content_types") + images = Setting.create!(key: "update.images.content_types") + documents = Setting.create!(key: "update.documents.content_types") expect(images.content_type_group).to eq "images" expect(documents.content_type_group).to eq "documents" diff --git a/spec/models/tag_spec.rb b/spec/models/tag_spec.rb index 59dad7137..f0b6d40fa 100644 --- a/spec/models/tag_spec.rb +++ b/spec/models/tag_spec.rb @@ -8,7 +8,7 @@ describe Tag do expect(tag.taggings_count).to eq(1) - debate.update(hidden_at: Time.current) + debate.update!(hidden_at: Time.current) tag.reload expect(tag.taggings_count).to eq(0) @@ -20,7 +20,7 @@ describe Tag do expect(tag.taggings_count).to eq(1) - proposal.update(hidden_at: Time.current) + proposal.update!(hidden_at: Time.current) tag.reload expect(tag.taggings_count).to eq(0) diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 85dc77ddf..d97679bdd 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -148,7 +148,7 @@ describe User do end it "is true when the user is an admin" do - subject.save + subject.save! create(:administrator, user: subject) expect(subject.administrator?).to be true end @@ -160,7 +160,7 @@ describe User do end it "is true when the user is a moderator" do - subject.save + subject.save! create(:moderator, user: subject) expect(subject.moderator?).to be true end @@ -172,7 +172,7 @@ describe User do end it "is true when the user is a valuator" do - subject.save + subject.save! create(:valuator, user: subject) expect(subject.valuator?).to be true end @@ -184,7 +184,7 @@ describe User do end it "is true when the user is a manager" do - subject.save + subject.save! create(:manager, user: subject) expect(subject.manager?).to be true end @@ -196,7 +196,7 @@ describe User do end it "is true when the user is a poll officer" do - subject.save + subject.save! create(:poll_officer, user: subject) expect(subject.poll_officer?).to be true end @@ -265,14 +265,14 @@ describe User do it "is true when the user is an official" do subject.official_level = 3 - subject.save + subject.save! expect(subject.official?).to be true end end describe "add_official_position!" do - it "is false when level not valid" do - expect(subject.add_official_position!("Boss", 89)).to be false + it "raises an exception when level not valid" do + expect { subject.add_official_position!("Boss", 89) }.to raise_error ActiveRecord::RecordInvalid end it "updates official position fields" do @@ -336,7 +336,7 @@ describe User do expect(user4.has_official_email?).to eq(false) # We reset the officials' domain setting - Setting.find_by(key: "email_domain_for_officials").update(value: "") + Setting.find_by(key: "email_domain_for_officials").update!(value: "") end end diff --git a/spec/models/verification/letter_spec.rb b/spec/models/verification/letter_spec.rb index 093b5a50d..4c7577bb9 100644 --- a/spec/models/verification/letter_spec.rb +++ b/spec/models/verification/letter_spec.rb @@ -34,7 +34,7 @@ describe Verification::Letter do let(:letter) { build(:verification_letter, verify: true) } it "incorrect code" do - letter.user.update(letter_verification_code: "123456") + letter.user.update!(letter_verification_code: "123456") letter.verification_code = "5555" expect(letter.valid?).to eq(false) @@ -42,7 +42,7 @@ describe Verification::Letter do end it "correct code" do - letter.user.update(letter_verification_code: "123456") + letter.user.update!(letter_verification_code: "123456") letter.verification_code = "123456" expect(letter.valid?).to eq(true) @@ -50,7 +50,7 @@ describe Verification::Letter do end it "ignores trailing zeros" do - letter.user.update(letter_verification_code: "003456") + letter.user.update!(letter_verification_code: "003456") letter.verification_code = "3456" expect(letter.valid?).to eq(true) diff --git a/spec/models/verification/residence_spec.rb b/spec/models/verification/residence_spec.rb index 9767dfb96..06365c2d0 100644 --- a/spec/models/verification/residence_spec.rb +++ b/spec/models/verification/residence_spec.rb @@ -36,7 +36,7 @@ describe Verification::Residence do it "validates uniquness of document_number" do user = create(:user) residence.user = user - residence.save + residence.save! build(:verification_residence) @@ -68,7 +68,7 @@ describe Verification::Residence do it "stores document number, document type, geozone, date of birth and gender" do user = create(:user) residence.user = user - residence.save + residence.save! user.reload expect(user.document_number).to eq("12345678Z") diff --git a/spec/shared/features/remotely_translatable.rb b/spec/shared/features/remotely_translatable.rb index ecebd8d43..98e9a5650 100644 --- a/spec/shared/features/remotely_translatable.rb +++ b/spec/shared/features/remotely_translatable.rb @@ -43,7 +43,7 @@ shared_examples "remotely_translatable" do |factory_name, path_name, path_argume scenario "should not be present when there are no resources to translate", :js do skip("only index_path") if show_path?(path_name) - resource.destroy + resource.destroy! visit path select("Deutsch", from: "locale-switcher") @@ -230,7 +230,7 @@ end def add_translations(resource) new_translation = resource.translations.first.dup - new_translation.update(locale: :de) + new_translation.update!(locale: :de) resource end diff --git a/spec/shared/models/acts_as_imageable.rb b/spec/shared/models/acts_as_imageable.rb index 53371b17c..135879475 100644 --- a/spec/shared/models/acts_as_imageable.rb +++ b/spec/shared/models/acts_as_imageable.rb @@ -67,7 +67,7 @@ shared_examples "acts as imageable" do |imageable_factory| end it "image destroy should remove image from file storage" do - image.save + image.save! image_url = image.attachment.url new_url = "/attachments/original/missing.png" diff --git a/spec/shared/models/acts_as_paranoid.rb b/spec/shared/models/acts_as_paranoid.rb index dbe3d337e..499090b68 100644 --- a/spec/shared/models/acts_as_paranoid.rb +++ b/spec/shared/models/acts_as_paranoid.rb @@ -2,7 +2,7 @@ shared_examples "acts as paranoid" do |factory_name| let!(:resource) { create(factory_name) } it "#{described_class} can be recovered after soft deletion" do - resource.destroy + resource.destroy! resource.reload expect(resource.hidden_at).not_to be_blank @@ -15,7 +15,7 @@ shared_examples "acts as paranoid" do |factory_name| describe "#{described_class} translations" do it "is hidden after parent resource destroy" do - resource.destroy + resource.destroy! resource.reload expect(resource.translations.with_deleted.first.hidden_at).not_to be_blank @@ -26,16 +26,16 @@ shared_examples "acts as paranoid" do |factory_name| end it "cannot be recovered through non recursive restore" do - resource.destroy + resource.destroy! resource.reload expect { resource.restore }.not_to change { resource.translations.with_deleted.first.hidden_at } end it "can be recovered through recursive restore after non-recursive restore" do - resource.destroy + resource.destroy! resource.restore - resource.destroy + resource.destroy! resource.reload expect { resource.restore(recursive: true) }.to change { resource.translations.with_deleted.first.hidden_at } @@ -48,10 +48,10 @@ shared_examples "acts as paranoid" do |factory_name| new_translation.send("#{translated_attribute_name}=", original_translation.send(translated_attribute_name)) end new_translation.locale = :fr - new_translation.save + new_translation.save! expect(resource.translations.with_deleted.count).to eq(2) - resource.destroy + resource.destroy! resource.reload expect(resource.translations.with_deleted.count).to eq(2) expect(resource.translations.with_deleted.first.hidden_at).not_to be_blank diff --git a/spec/shared/models/document_validations.rb b/spec/shared/models/document_validations.rb index c0717d87b..5e289cc88 100644 --- a/spec/shared/models/document_validations.rb +++ b/spec/shared/models/document_validations.rb @@ -47,14 +47,14 @@ shared_examples "document validations" do |documentable_factory| end it "is not valid without a documentable_id" do - document.save + document.save! document.documentable_id = nil expect(document).not_to be_valid end it "is not valid without a documentable_type" do - document.save + document.save! document.documentable_type = nil expect(document).not_to be_valid diff --git a/spec/shared/models/image_validations.rb b/spec/shared/models/image_validations.rb index c2b02a636..c9123ba05 100644 --- a/spec/shared/models/image_validations.rb +++ b/spec/shared/models/image_validations.rb @@ -55,14 +55,14 @@ shared_examples "image validations" do |imageable_factory| end it "is not valid without a imageable_id" do - image.save + image.save! image.imageable_id = nil expect(image).not_to be_valid end it "is not valid without a imageable_type" do - image.save + image.save! image.imageable_type = nil expect(image).not_to be_valid diff --git a/spec/shared/models/map_validations.rb b/spec/shared/models/map_validations.rb index e76e766c0..1eb828f7c 100644 --- a/spec/shared/models/map_validations.rb +++ b/spec/shared/models/map_validations.rb @@ -51,7 +51,7 @@ shared_examples "map validations" do it "expires cache when the map is updated" do map_location = create(:map_location) mappable.map_location = map_location - mappable.save + mappable.save! expect { map_location.update(latitude: 12.34) } .to change { mappable.reload.updated_at } diff --git a/spec/shared/models/notifiable.rb b/spec/shared/models/notifiable.rb index 263d89117..169cf53f1 100644 --- a/spec/shared/models/notifiable.rb +++ b/spec/shared/models/notifiable.rb @@ -78,7 +78,7 @@ shared_examples "notifiable" do notification = create(:notification, notifiable: notifiable) if notifiable.respond_to?(:retired_at) - notifiable.update(retired_at: Time.current, retired_reason: "unfeasible", + notifiable.update!(retired_at: Time.current, retired_reason: "unfeasible", retired_explanation: "Unfeasibility explanation ...") expect(notification.check_availability(notifiable)).to be(false) end diff --git a/spec/support/verifiable.rb b/spec/support/verifiable.rb index 78c436a1b..c57d30759 100644 --- a/spec/support/verifiable.rb +++ b/spec/support/verifiable.rb @@ -197,10 +197,10 @@ shared_examples_for "verifiable" do it "is true if skipped" do expect(user.level_two_verified?).to eq(true) - user.update(residence_verified_at: Time.current) + user.update!(residence_verified_at: Time.current) expect(user.level_two_verified?).to eq(true) - user.update(confirmed_phone: "123456789", residence_verified_at: false) + user.update!(confirmed_phone: "123456789", residence_verified_at: false) expect(user.level_two_verified?).to eq(true) end end @@ -219,26 +219,26 @@ shared_examples_for "verifiable" do describe "#verification_sms_sent?" do it "is true if skipped" do - user.update(unconfirmed_phone: nil, sms_confirmation_code: "666") + user.update!(unconfirmed_phone: nil, sms_confirmation_code: "666") expect(user.verification_sms_sent?).to eq(true) - user.update(unconfirmed_phone: "666666666", sms_confirmation_code: nil) + user.update!(unconfirmed_phone: "666666666", sms_confirmation_code: nil) expect(user.verification_sms_sent?).to eq(true) - user.update(unconfirmed_phone: nil, sms_confirmation_code: nil) + user.update!(unconfirmed_phone: nil, sms_confirmation_code: nil) expect(user.verification_sms_sent?).to eq(true) end end describe "#verification_letter_sent?" do it "is true if skipped" do - user.update(letter_requested_at: nil, letter_verification_code: "666") + user.update!(letter_requested_at: nil, letter_verification_code: "666") expect(user.verification_letter_sent?).to eq(true) - user.update(letter_requested_at: Time.current, letter_verification_code: nil) + user.update!(letter_requested_at: Time.current, letter_verification_code: nil) expect(user.verification_letter_sent?).to eq(true) - user.update(letter_requested_at: nil, letter_verification_code: nil) + user.update!(letter_requested_at: nil, letter_verification_code: nil) expect(user.verification_letter_sent?).to eq(true) end end