From 659c3e7c2f9bbe6928d213c3e1eabc645ad627b7 Mon Sep 17 00:00:00 2001 From: Gabriel Jablonski Date: Thu, 3 Apr 2025 23:10:23 -0300 Subject: [PATCH] chore: apply Rails/SaveBang cop (#15) * chore: apply Rails/SaveBang cop * fix: correct locale validation in category model spec * fix: update save methods to avoid Rails/SaveBang cop violations --- .rubocop.yml | 7 +++ .../messages/messenger/message_builder.rb | 2 +- .../api/v1/accounts/callbacks_controller.rb | 2 +- .../accounts/integrations/slack_controller.rb | 2 +- .../v1/accounts/notifications_controller.rb | 8 ++-- .../api/v1/accounts/portals_controller.rb | 2 +- app/controllers/api/v1/profiles_controller.rb | 2 +- .../api/v1/widget/contacts_controller.rb | 2 +- .../platform/api/v1/accounts_controller.rb | 2 +- .../platform/api/v1/agent_bots_controller.rb | 2 +- .../api/v1/inboxes/contacts_controller.rb | 2 +- .../super_admin/app_configs_controller.rb | 2 +- app/jobs/bulk_actions_job.rb | 4 +- app/jobs/conversations/user_mention_job.rb | 2 +- app/mailers/conversation_reply_mailer.rb | 2 +- app/models/article.rb | 2 +- app/models/channel/twilio_sms.rb | 2 +- .../concerns/conversation_mute_helpers.rb | 4 +- app/models/concerns/featurable.rb | 4 +- app/models/conversation.rb | 4 +- app/models/message.rb | 8 ++-- app/models/portal.rb | 2 +- app/models/team.rb | 2 +- app/services/action_service.rb | 2 +- .../agent_assignment_service.rb | 2 +- app/services/data_import/contact_manager.rb | 2 +- .../instagram/webhooks_base_service.rb | 2 +- app/services/twilio/webhook_setup_service.rb | 2 +- .../providers/whatsapp_360_dialog_service.rb | 2 +- .../providers/whatsapp_cloud_service.rb | 2 +- ...0230515051424_update_article_image_keys.rb | 2 +- .../captain/assistant_responses_controller.rb | 2 +- .../accounts/captain/assistants_controller.rb | 2 +- .../captain/bulk_actions_controller.rb | 2 +- .../accounts/captain/documents_controller.rb | 2 +- .../enterprise/api/v1/accounts_controller.rb | 2 +- .../app/jobs/enterprise/delete_object_job.rb | 2 +- .../account/plan_usage_and_limits.rb | 6 +-- .../models/enterprise/audit/inbox_member.rb | 2 +- .../models/enterprise/audit/team_member.rb | 2 +- .../app/models/enterprise/channelable.rb | 2 +- .../account_updater_service.rb | 2 +- lib/action_view/template/handlers/liquid.rb | 2 +- lib/config_loader.rb | 2 +- lib/global_config_service.rb | 2 +- lib/integrations/slack/channel_builder.rb | 18 +++---- lib/vapid_service.rb | 2 +- spec/builders/notification_builder_spec.rb | 4 +- spec/builders/v2/report_builder_spec.rb | 4 +- .../api/v1/accounts/agents_controller_spec.rb | 2 +- .../accounts/bulk_actions_controller_spec.rb | 8 ++-- .../v1/accounts/contacts_controller_spec.rb | 4 +- .../custom_filters_controller_spec.rb | 2 +- .../api/v1/accounts/macros_controller_spec.rb | 2 +- .../v1/accounts/portals_controller_spec.rb | 2 +- .../api/v1/accounts_controller_spec.rb | 6 +-- .../widget/conversations_controller_spec.rb | 4 +- .../public/api/v1/portals_controller_spec.rb | 2 +- .../api/v1/accounts/agents_controller_spec.rb | 6 +-- .../accounts/applied_slas_controller_spec.rb | 4 +- .../accounts/conversations_controller_spec.rb | 2 +- .../v1/accounts/portals_controller_spec.rb | 2 +- .../api/v1/accounts_controller_spec.rb | 8 ++-- spec/enterprise/models/account_spec.rb | 14 +++--- .../enterprise/models/automation_rule_spec.rb | 2 +- spec/enterprise/models/inbox_member_spec.rb | 2 +- spec/enterprise/models/inbox_spec.rb | 14 +++--- spec/enterprise/models/macro_spec.rb | 2 +- spec/enterprise/models/team_member_spec.rb | 2 +- spec/enterprise/models/team_spec.rb | 2 +- spec/enterprise/models/user_spec.rb | 2 +- spec/enterprise/models/webhook_spec.rb | 2 +- .../permission_filter_service_spec.rb | 8 ++-- .../sla/evaluate_applied_sla_service_spec.rb | 24 +++++----- spec/finders/email_channel_finder_spec.rb | 12 ++--- ...ersations_resolution_scheduler_job_spec.rb | 2 +- .../jobs/conversations/resolution_job_spec.rb | 6 +-- .../jobs/webhooks/whatsapp_events_job_spec.rb | 2 +- .../dialogflow/processor_service_spec.rb | 2 +- .../facebook/delivery_status_spec.rb | 4 +- spec/lib/online_status_tracker_spec.rb | 2 +- spec/listeners/action_cable_listener_spec.rb | 2 +- .../automation_rule_listener_old_spec.rb | 8 ++-- spec/listeners/notification_listener_spec.rb | 6 +-- .../reporting_event_listener_spec.rb | 2 +- spec/listeners/webhook_listener_spec.rb | 2 +- spec/mailboxes/application_mailbox_spec.rb | 6 +-- .../mailers/conversation_reply_mailer_spec.rb | 48 +++++++++---------- spec/models/account_spec.rb | 14 +++--- spec/models/category_spec.rb | 2 +- spec/models/channel/twilio_sms_spec.rb | 6 +-- .../concerns/assignment_handler_shared.rb | 8 ++-- .../auto_assignment_handler_shared.rb | 2 +- spec/models/contact_inbox_spec.rb | 4 +- spec/models/conversation_spec.rb | 20 ++++---- spec/models/inbox_spec.rb | 10 ++-- spec/models/label_spec.rb | 4 +- spec/models/message_spec.rb | 2 +- spec/models/portal_spec.rb | 6 +-- spec/models/working_hour_spec.rb | 6 +-- .../integrations/slack_request_spec.rb | 4 +- .../automation_rules/action_service_spec.rb | 4 +- .../condition_validation_service_spec.rb | 14 +++--- .../conditions_filter_service_spec.rb | 18 +++---- spec/services/contacts/filter_service_spec.rb | 6 +-- .../services/contacts/sync_attributes_spec.rb | 4 +- .../refresh_oauth_token_service_spec.rb | 2 +- .../hook_execution_service_spec.rb | 28 +++++------ .../refresh_oauth_token_service_spec.rb | 2 +- .../sms/incoming_message_service_spec.rb | 12 ++--- .../twilio/incoming_message_service_spec.rb | 12 ++--- .../oneoff_sms_campaign_service_spec.rb | 6 +-- .../twilio/send_on_twilio_service_spec.rb | 12 ++--- .../whatsapp/incoming_message_service_spec.rb | 12 ++--- 114 files changed, 301 insertions(+), 298 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 679531c66..2dcf6eec4 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -170,3 +170,10 @@ AllCops: Layout/LeadingCommentSpace: Enabled: false + +Rails/SaveBang: + Enabled: true + AllowedReceivers: + - Stripe::Subscription + - Stripe::Customer + - FactoryBot diff --git a/app/builders/messages/messenger/message_builder.rb b/app/builders/messages/messenger/message_builder.rb index f01a236c9..4866769fd 100644 --- a/app/builders/messages/messenger/message_builder.rb +++ b/app/builders/messages/messenger/message_builder.rb @@ -77,7 +77,7 @@ class Messages::Messenger::MessageBuilder rescue Koala::Facebook::ClientError => e # The exception occurs when we are trying fetch the deleted story or blocked story. @message.attachments.destroy_all - @message.update(content: I18n.t('conversations.messages.instagram_deleted_story_content')) + @message.update!(content: I18n.t('conversations.messages.instagram_deleted_story_content')) Rails.logger.error e {} rescue StandardError => e diff --git a/app/controllers/api/v1/accounts/callbacks_controller.rb b/app/controllers/api/v1/accounts/callbacks_controller.rb index 6e119ca3d..960fc5725 100644 --- a/app/controllers/api/v1/accounts/callbacks_controller.rb +++ b/app/controllers/api/v1/accounts/callbacks_controller.rb @@ -39,7 +39,7 @@ class Api::V1::Accounts::CallbacksController < Api::V1::Accounts::BaseController return if response['instagram_business_account'].blank? instagram_id = response['instagram_business_account']['id'] - facebook_channel.update(instagram_id: instagram_id) + facebook_channel.update!(instagram_id: instagram_id) rescue StandardError => e Rails.logger.error "Error in set_instagram_id: #{e.message}" end diff --git a/app/controllers/api/v1/accounts/integrations/slack_controller.rb b/app/controllers/api/v1/accounts/integrations/slack_controller.rb index eaa18c2de..eadd46e4a 100644 --- a/app/controllers/api/v1/accounts/integrations/slack_controller.rb +++ b/app/controllers/api/v1/accounts/integrations/slack_controller.rb @@ -16,7 +16,7 @@ class Api::V1::Accounts::Integrations::SlackController < Api::V1::Accounts::Base end def update - @hook = channel_builder.update(permitted_params[:reference_id]) + @hook = channel_builder.update_reference_id(permitted_params[:reference_id]) render json: { error: I18n.t('errors.slack.invalid_channel_id') }, status: :unprocessable_entity if @hook.blank? end diff --git a/app/controllers/api/v1/accounts/notifications_controller.rb b/app/controllers/api/v1/accounts/notifications_controller.rb index 52035ce64..874fb67a4 100644 --- a/app/controllers/api/v1/accounts/notifications_controller.rb +++ b/app/controllers/api/v1/accounts/notifications_controller.rb @@ -25,17 +25,17 @@ class Api::V1::Accounts::NotificationsController < Api::V1::Accounts::BaseContro end def update - @notification.update(read_at: DateTime.now.utc) + @notification.update!(read_at: DateTime.now.utc) render json: @notification end def unread - @notification.update(read_at: nil) + @notification.update!(read_at: nil) render json: @notification end def destroy - @notification.destroy + @notification.destroy! head :ok end @@ -55,7 +55,7 @@ class Api::V1::Accounts::NotificationsController < Api::V1::Accounts::BaseContro def snooze updated_meta = (@notification.meta || {}).merge('last_snoozed_at' => nil) - @notification.update(snoozed_until: parse_date_time(params[:snoozed_until].to_s), meta: updated_meta) if params[:snoozed_until] + @notification.update!(snoozed_until: parse_date_time(params[:snoozed_until].to_s), meta: updated_meta) if params[:snoozed_until] render json: @notification end diff --git a/app/controllers/api/v1/accounts/portals_controller.rb b/app/controllers/api/v1/accounts/portals_controller.rb index 6cfed161f..73bba60eb 100644 --- a/app/controllers/api/v1/accounts/portals_controller.rb +++ b/app/controllers/api/v1/accounts/portals_controller.rb @@ -38,7 +38,7 @@ class Api::V1::Accounts::PortalsController < Api::V1::Accounts::BaseController end def archive - @portal.update(archive: true) + @portal.update!(archive: true) head :ok end diff --git a/app/controllers/api/v1/profiles_controller.rb b/app/controllers/api/v1/profiles_controller.rb index ae1a1fe30..7eabf686f 100644 --- a/app/controllers/api/v1/profiles_controller.rb +++ b/app/controllers/api/v1/profiles_controller.rb @@ -29,7 +29,7 @@ class Api::V1::ProfilesController < Api::BaseController end def set_active_account - @user.account_users.find_by(account_id: profile_params[:account_id]).update(active_at: Time.now.utc) + @user.account_users.find_by(account_id: profile_params[:account_id]).update!(active_at: Time.now.utc) head :ok end diff --git a/app/controllers/api/v1/widget/contacts_controller.rb b/app/controllers/api/v1/widget/contacts_controller.rb index 5138fe675..32d89f450 100644 --- a/app/controllers/api/v1/widget/contacts_controller.rb +++ b/app/controllers/api/v1/widget/contacts_controller.rb @@ -19,7 +19,7 @@ class Api::V1::Widget::ContactsController < Api::V1::Widget::BaseController contact = @contact end - @contact_inbox.update(hmac_verified: true) if should_verify_hmac? && valid_hmac? + @contact_inbox.update!(hmac_verified: true) if should_verify_hmac? && valid_hmac? identify_contact(contact) end diff --git a/app/controllers/platform/api/v1/accounts_controller.rb b/app/controllers/platform/api/v1/accounts_controller.rb index e11cf9d4a..4b3c7cfee 100644 --- a/app/controllers/platform/api/v1/accounts_controller.rb +++ b/app/controllers/platform/api/v1/accounts_controller.rb @@ -5,7 +5,7 @@ class Platform::Api::V1::AccountsController < PlatformController @resource = Account.create!(account_params) update_resource_features @resource.save! - @platform_app.platform_app_permissibles.find_or_create_by(permissible: @resource) + @platform_app.platform_app_permissibles.find_or_create_by!(permissible: @resource) end def update diff --git a/app/controllers/platform/api/v1/agent_bots_controller.rb b/app/controllers/platform/api/v1/agent_bots_controller.rb index dd70a1ba5..a3ed639fd 100644 --- a/app/controllers/platform/api/v1/agent_bots_controller.rb +++ b/app/controllers/platform/api/v1/agent_bots_controller.rb @@ -12,7 +12,7 @@ class Platform::Api::V1::AgentBotsController < PlatformController @resource = AgentBot.new(agent_bot_params.except(:avatar_url)) @resource.save! process_avatar_from_url - @platform_app.platform_app_permissibles.find_or_create_by(permissible: @resource) + @platform_app.platform_app_permissibles.find_or_create_by!(permissible: @resource) end def update diff --git a/app/controllers/public/api/v1/inboxes/contacts_controller.rb b/app/controllers/public/api/v1/inboxes/contacts_controller.rb index 835c2596b..246c95d25 100644 --- a/app/controllers/public/api/v1/inboxes/contacts_controller.rb +++ b/app/controllers/public/api/v1/inboxes/contacts_controller.rb @@ -31,7 +31,7 @@ class Public::Api::V1::Inboxes::ContactsController < Public::Api::V1::InboxesCon return if params[:identifier_hash].blank? && !@inbox_channel.hmac_mandatory raise StandardError, 'HMAC failed: Invalid Identifier Hash Provided' unless valid_hmac? - @contact_inbox.update(hmac_verified: true) if @contact_inbox.present? + @contact_inbox.update!(hmac_verified: true) if @contact_inbox.present? end def valid_hmac? diff --git a/app/controllers/super_admin/app_configs_controller.rb b/app/controllers/super_admin/app_configs_controller.rb index 550b6c893..4ff461672 100644 --- a/app/controllers/super_admin/app_configs_controller.rb +++ b/app/controllers/super_admin/app_configs_controller.rb @@ -18,7 +18,7 @@ class SuperAdmin::AppConfigsController < SuperAdmin::ApplicationController params['app_config'].each do |key, value| next unless @allowed_configs.include?(key) - i = InstallationConfig.where(name: key).first_or_create(value: value, locked: false) + i = InstallationConfig.where(name: key).first_or_create!(value: value, locked: false) i.value = value i.save! end diff --git a/app/jobs/bulk_actions_job.rb b/app/jobs/bulk_actions_job.rb index 73fa1b151..59248e9b9 100644 --- a/app/jobs/bulk_actions_job.rb +++ b/app/jobs/bulk_actions_job.rb @@ -26,7 +26,7 @@ class BulkActionsJob < ApplicationJob records.each do |conversation| bulk_add_labels(conversation) bulk_snoozed_until(conversation) - conversation.update(params) if params + conversation.update!(params) if params end end @@ -54,7 +54,7 @@ class BulkActionsJob < ApplicationJob return unless @params[:labels] && @params[:labels][:remove] labels = conversation.label_list - @params[:labels][:remove] - conversation.update(label_list: labels) + conversation.update!(label_list: labels) end def records_to_updated(ids) diff --git a/app/jobs/conversations/user_mention_job.rb b/app/jobs/conversations/user_mention_job.rb index fe162792e..e6ca1afcd 100644 --- a/app/jobs/conversations/user_mention_job.rb +++ b/app/jobs/conversations/user_mention_job.rb @@ -17,7 +17,7 @@ class Conversations::UserMentionJob < ApplicationJob account_id: account_id ) else - mention.update(mentioned_at: Time.zone.now) + mention.update!(mentioned_at: Time.zone.now) end end end diff --git a/app/mailers/conversation_reply_mailer.rb b/app/mailers/conversation_reply_mailer.rb index 7c00d92d0..b55f848d5 100644 --- a/app/mailers/conversation_reply_mailer.rb +++ b/app/mailers/conversation_reply_mailer.rb @@ -35,7 +35,7 @@ class ConversationReplyMailer < ApplicationMailer init_conversation_attributes(message.conversation) @message = message reply_mail_object = prepare_mail(true) - message.update(source_id: reply_mail_object.message_id) + message.update!(source_id: reply_mail_object.message_id) end def conversation_transcript(conversation, to_email) diff --git a/app/models/article.rb b/app/models/article.rb index 48e0529a2..c4ba15b20 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -107,7 +107,7 @@ class Article < ApplicationRecord root_article_id = self.class.find_root_article_id(article) - update(associated_article_id: root_article_id) if root_article_id.present? + update!(associated_article_id: root_article_id) if root_article_id.present? end # Make sure we always associate the parent's associated id to avoid the deeper associations od articles. diff --git a/app/models/channel/twilio_sms.rb b/app/models/channel/twilio_sms.rb index 935ab2a14..20ebe519e 100644 --- a/app/models/channel/twilio_sms.rb +++ b/app/models/channel/twilio_sms.rb @@ -49,7 +49,7 @@ class Channel::TwilioSms < ApplicationRecord params = send_message_from.merge(to: to, body: body) params[:media_url] = media_url if media_url.present? params[:status_callback] = twilio_delivery_status_index_url - client.messages.create(**params) + client.messages.create!(**params) end private diff --git a/app/models/concerns/conversation_mute_helpers.rb b/app/models/concerns/conversation_mute_helpers.rb index c6ea4c7b1..0db70467f 100644 --- a/app/models/concerns/conversation_mute_helpers.rb +++ b/app/models/concerns/conversation_mute_helpers.rb @@ -3,12 +3,12 @@ module ConversationMuteHelpers def mute! resolved! - contact.update(blocked: true) + contact.update!(blocked: true) create_muted_message end def unmute! - contact.update(blocked: false) + contact.update!(blocked: false) create_unmuted_message end diff --git a/app/models/concerns/featurable.rb b/app/models/concerns/featurable.rb index ff4aa961b..919dddd41 100644 --- a/app/models/concerns/featurable.rb +++ b/app/models/concerns/featurable.rb @@ -27,7 +27,7 @@ module Featurable def enable_features!(*) enable_features(*) - save + save! end def disable_features(*names) @@ -38,7 +38,7 @@ module Featurable def disable_features!(*) disable_features(*) - save + save! end def feature_enabled?(name) diff --git a/app/models/conversation.rb b/app/models/conversation.rb index e09e6efaf..32a214759 100644 --- a/app/models/conversation.rb +++ b/app/models/conversation.rb @@ -159,12 +159,12 @@ class Conversation < ApplicationRecord # FIXME: implement state machine with aasm self.status = open? ? :resolved : :open self.status = :open if pending? || snoozed? - save + save! end def toggle_priority(priority = nil) self.priority = priority.presence - save + save! end def bot_handoff! diff --git a/app/models/message.rb b/app/models/message.rb index c6c737fe6..101b0c176 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -268,7 +268,7 @@ class Message < ApplicationRecord end def update_contact_activity - sender.update(last_activity_at: DateTime.now) if sender.is_a?(Contact) + sender.update!(last_activity_at: DateTime.now) if sender.is_a?(Contact) end def update_waiting_since @@ -276,9 +276,9 @@ class Message < ApplicationRecord Rails.configuration.dispatcher.dispatch( REPLY_CREATED, Time.zone.now, waiting_since: conversation.waiting_since, message: self ) - conversation.update(waiting_since: nil) + conversation.update!(waiting_since: nil) end - conversation.update(waiting_since: created_at) if incoming? && conversation.waiting_since.blank? + conversation.update!(waiting_since: created_at) if incoming? && conversation.waiting_since.blank? end def human_response? @@ -296,7 +296,7 @@ class Message < ApplicationRecord if valid_first_reply? Rails.configuration.dispatcher.dispatch(FIRST_REPLY_CREATED, Time.zone.now, message: self, performed_by: Current.executed_by) - conversation.update(first_reply_created_at: created_at, waiting_since: nil) + conversation.update!(first_reply_created_at: created_at, waiting_since: nil) else update_waiting_since end diff --git a/app/models/portal.rb b/app/models/portal.rb index cb87929f5..623ec4a03 100644 --- a/app/models/portal.rb +++ b/app/models/portal.rb @@ -66,6 +66,6 @@ class Portal < ApplicationRecord def config_json_format config['default_locale'] = default_locale denied_keys = config.keys - CONFIG_JSON_KEYS - errors.add(:cofig, "in portal on #{denied_keys.join(',')} is not supported.") if denied_keys.any? + errors.add(:config, "in portal on #{denied_keys.join(',')} is not supported.") if denied_keys.any? end end diff --git a/app/models/team.rb b/app/models/team.rb index a2b69c7fb..731138e85 100644 --- a/app/models/team.rb +++ b/app/models/team.rb @@ -36,7 +36,7 @@ class Team < ApplicationRecord # @return [Array] Array of newly added members def add_members(user_ids) team_members_to_create = user_ids.map { |user_id| { user_id: user_id } } - created_members = team_members.create(team_members_to_create) + created_members = team_members.create!(team_members_to_create) added_users = created_members.filter_map(&:user) update_account_cache diff --git a/app/services/action_service.rb b/app/services/action_service.rb index 4f33a302b..21a3fa087 100644 --- a/app/services/action_service.rb +++ b/app/services/action_service.rb @@ -46,7 +46,7 @@ class ActionService return if labels.empty? labels = @conversation.label_list - labels - @conversation.update(label_list: labels) + @conversation.update!(label_list: labels) end def assign_team(team_ids = []) diff --git a/app/services/auto_assignment/agent_assignment_service.rb b/app/services/auto_assignment/agent_assignment_service.rb index 5beaee2c3..934a4bd14 100644 --- a/app/services/auto_assignment/agent_assignment_service.rb +++ b/app/services/auto_assignment/agent_assignment_service.rb @@ -10,7 +10,7 @@ class AutoAssignment::AgentAssignmentService def perform new_assignee = find_assignee - conversation.update(assignee: new_assignee) if new_assignee + conversation.update!(assignee: new_assignee) if new_assignee end private diff --git a/app/services/data_import/contact_manager.rb b/app/services/data_import/contact_manager.rb index 460a83726..d02f6f66e 100644 --- a/app/services/data_import/contact_manager.rb +++ b/app/services/data_import/contact_manager.rb @@ -53,7 +53,7 @@ class DataImport::ContactManager contact.email = params[:email] if params[:email].present? contact.phone_number = format_phone_number(params[:phone_number]) if params[:phone_number].present? update_contact_attributes(params, contact) - contact.save + contact.save # rubocop:disable Rails/SaveBang end private diff --git a/app/services/instagram/webhooks_base_service.rb b/app/services/instagram/webhooks_base_service.rb index 419270d70..75dcb92d8 100644 --- a/app/services/instagram/webhooks_base_service.rb +++ b/app/services/instagram/webhooks_base_service.rb @@ -27,6 +27,6 @@ class Instagram::WebhooksBaseService # TODO: Remove this once we show the social_instagram_user_name in the UI instead of the username @contact.additional_attributes = @contact.additional_attributes.merge({ 'social_profiles': { 'instagram': user['username'] } }) @contact.additional_attributes = @contact.additional_attributes.merge({ 'social_instagram_user_name': user['username'] }) - @contact.save + @contact.save! end end diff --git a/app/services/twilio/webhook_setup_service.rb b/app/services/twilio/webhook_setup_service.rb index b949bf37c..5a666f3ed 100644 --- a/app/services/twilio/webhook_setup_service.rb +++ b/app/services/twilio/webhook_setup_service.rb @@ -29,7 +29,7 @@ class Twilio::WebhookSetupService else twilio_client .incoming_phone_numbers(phonenumber_sid) - .update(sms_method: 'POST', sms_url: twilio_callback_index_url) + .update(sms_method: 'POST', sms_url: twilio_callback_index_url) # rubocop:disable Rails/SaveBang end end diff --git a/app/services/whatsapp/providers/whatsapp_360_dialog_service.rb b/app/services/whatsapp/providers/whatsapp_360_dialog_service.rb index 61cdeebf1..17da55ced 100644 --- a/app/services/whatsapp/providers/whatsapp_360_dialog_service.rb +++ b/app/services/whatsapp/providers/whatsapp_360_dialog_service.rb @@ -28,7 +28,7 @@ class Whatsapp::Providers::Whatsapp360DialogService < Whatsapp::Providers::BaseS # ensuring that channels with wrong provider config wouldn't keep trying to sync templates whatsapp_channel.mark_message_templates_updated response = HTTParty.get("#{api_base_path}/configs/templates", headers: api_headers) - whatsapp_channel.update(message_templates: response['waba_templates'], message_templates_last_updated: Time.now.utc) if response.success? + whatsapp_channel.update!(message_templates: response['waba_templates'], message_templates_last_updated: Time.now.utc) if response.success? end def validate_provider_config? diff --git a/app/services/whatsapp/providers/whatsapp_cloud_service.rb b/app/services/whatsapp/providers/whatsapp_cloud_service.rb index ec2275920..5856f1520 100644 --- a/app/services/whatsapp/providers/whatsapp_cloud_service.rb +++ b/app/services/whatsapp/providers/whatsapp_cloud_service.rb @@ -30,7 +30,7 @@ class Whatsapp::Providers::WhatsappCloudService < Whatsapp::Providers::BaseServi # ensuring that channels with wrong provider config wouldn't keep trying to sync templates whatsapp_channel.mark_message_templates_updated templates = fetch_whatsapp_templates("#{business_account_path}/message_templates?access_token=#{whatsapp_channel.provider_config['api_key']}") - whatsapp_channel.update(message_templates: templates, message_templates_last_updated: Time.now.utc) if templates.present? + whatsapp_channel.update!(message_templates: templates, message_templates_last_updated: Time.now.utc) if templates.present? end def fetch_whatsapp_templates(url) diff --git a/db/migrate/20230515051424_update_article_image_keys.rb b/db/migrate/20230515051424_update_article_image_keys.rb index b80e6c86e..60bc4312d 100644 --- a/db/migrate/20230515051424_update_article_image_keys.rb +++ b/db/migrate/20230515051424_update_article_image_keys.rb @@ -5,7 +5,7 @@ class ArticleKeyConverter def process new_content = replace(@article.content) - @article.update(content: new_content) + @article.update!(content: new_content) end private diff --git a/enterprise/app/controllers/api/v1/accounts/captain/assistant_responses_controller.rb b/enterprise/app/controllers/api/v1/accounts/captain/assistant_responses_controller.rb index c7b0366dd..a22f73ddb 100644 --- a/enterprise/app/controllers/api/v1/accounts/captain/assistant_responses_controller.rb +++ b/enterprise/app/controllers/api/v1/accounts/captain/assistant_responses_controller.rb @@ -40,7 +40,7 @@ class Api::V1::Accounts::Captain::AssistantResponsesController < Api::V1::Accoun end def destroy - @response.destroy + @response.destroy! head :no_content end diff --git a/enterprise/app/controllers/api/v1/accounts/captain/assistants_controller.rb b/enterprise/app/controllers/api/v1/accounts/captain/assistants_controller.rb index e424a8a62..3bafd7420 100644 --- a/enterprise/app/controllers/api/v1/accounts/captain/assistants_controller.rb +++ b/enterprise/app/controllers/api/v1/accounts/captain/assistants_controller.rb @@ -19,7 +19,7 @@ class Api::V1::Accounts::Captain::AssistantsController < Api::V1::Accounts::Base end def destroy - @assistant.destroy + @assistant.destroy! head :no_content end diff --git a/enterprise/app/controllers/api/v1/accounts/captain/bulk_actions_controller.rb b/enterprise/app/controllers/api/v1/accounts/captain/bulk_actions_controller.rb index 5d6875cbb..00408c8df 100644 --- a/enterprise/app/controllers/api/v1/accounts/captain/bulk_actions_controller.rb +++ b/enterprise/app/controllers/api/v1/accounts/captain/bulk_actions_controller.rb @@ -37,7 +37,7 @@ class Api::V1::Accounts::Captain::BulkActionsController < Api::V1::Accounts::Bas case params[:fields][:status] when 'approve' - responses.pending.update(status: 'approved') + responses.pending.update!(status: 'approved') responses when 'delete' responses.destroy_all diff --git a/enterprise/app/controllers/api/v1/accounts/captain/documents_controller.rb b/enterprise/app/controllers/api/v1/accounts/captain/documents_controller.rb index 594aa0642..cfc25b2f1 100644 --- a/enterprise/app/controllers/api/v1/accounts/captain/documents_controller.rb +++ b/enterprise/app/controllers/api/v1/accounts/captain/documents_controller.rb @@ -28,7 +28,7 @@ class Api::V1::Accounts::Captain::DocumentsController < Api::V1::Accounts::BaseC end def destroy - @document.destroy + @document.destroy! head :no_content end diff --git a/enterprise/app/controllers/enterprise/api/v1/accounts_controller.rb b/enterprise/app/controllers/enterprise/api/v1/accounts_controller.rb index 70f1d177d..3cb668688 100644 --- a/enterprise/app/controllers/enterprise/api/v1/accounts_controller.rb +++ b/enterprise/app/controllers/enterprise/api/v1/accounts_controller.rb @@ -6,7 +6,7 @@ class Enterprise::Api::V1::AccountsController < Api::BaseController def subscription if stripe_customer_id.blank? && @account.custom_attributes['is_creating_customer'].blank? - @account.update(custom_attributes: { is_creating_customer: true }) + @account.update!(custom_attributes: { is_creating_customer: true }) Enterprise::CreateStripeCustomerJob.perform_later(@account) end head :no_content diff --git a/enterprise/app/jobs/enterprise/delete_object_job.rb b/enterprise/app/jobs/enterprise/delete_object_job.rb index d7a7f2f17..e419a1378 100644 --- a/enterprise/app/jobs/enterprise/delete_object_job.rb +++ b/enterprise/app/jobs/enterprise/delete_object_job.rb @@ -6,7 +6,7 @@ module Enterprise::DeleteObjectJob def create_audit_entry(object, user, ip) return unless ['Inbox'].include?(object.class.to_s) && user.present? - Enterprise::AuditLog.create( + Enterprise::AuditLog.create!( auditable: object, audited_changes: object.attributes, action: 'destroy', diff --git a/enterprise/app/models/enterprise/account/plan_usage_and_limits.rb b/enterprise/app/models/enterprise/account/plan_usage_and_limits.rb index ce03efa41..5b76600fc 100644 --- a/enterprise/app/models/enterprise/account/plan_usage_and_limits.rb +++ b/enterprise/app/models/enterprise/account/plan_usage_and_limits.rb @@ -18,18 +18,18 @@ module Enterprise::Account::PlanUsageAndLimits def increment_response_usage current_usage = custom_attributes[CAPTAIN_RESPONSES_USAGE].to_i || 0 custom_attributes[CAPTAIN_RESPONSES_USAGE] = current_usage + 1 - save + save! end def reset_response_usage custom_attributes[CAPTAIN_RESPONSES_USAGE] = 0 - save + save! end def update_document_usage # this will ensure that the document count is always accurate custom_attributes[CAPTAIN_DOCUMENTS_USAGE] = captain_documents.count - save + save! end def subscribed_features diff --git a/enterprise/app/models/enterprise/audit/inbox_member.rb b/enterprise/app/models/enterprise/audit/inbox_member.rb index d5f3362b2..1a0e8e83d 100644 --- a/enterprise/app/models/enterprise/audit/inbox_member.rb +++ b/enterprise/app/models/enterprise/audit/inbox_member.rb @@ -19,7 +19,7 @@ module Enterprise::Audit::InboxMember def create_audit_log_entry(action) return if inbox.blank? - Enterprise::AuditLog.create( + Enterprise::AuditLog.create!( auditable_id: id, auditable_type: 'InboxMember', action: action, diff --git a/enterprise/app/models/enterprise/audit/team_member.rb b/enterprise/app/models/enterprise/audit/team_member.rb index 9be448b6c..c9c2b8e08 100644 --- a/enterprise/app/models/enterprise/audit/team_member.rb +++ b/enterprise/app/models/enterprise/audit/team_member.rb @@ -19,7 +19,7 @@ module Enterprise::Audit::TeamMember def create_audit_log_entry(action) return if team.blank? - Enterprise::AuditLog.create( + Enterprise::AuditLog.create!( auditable_id: id, auditable_type: 'TeamMember', action: action, diff --git a/enterprise/app/models/enterprise/channelable.rb b/enterprise/app/models/enterprise/channelable.rb index 6fcae73d8..403f21915 100644 --- a/enterprise/app/models/enterprise/channelable.rb +++ b/enterprise/app/models/enterprise/channelable.rb @@ -24,7 +24,7 @@ module Enterprise::Channelable # skip audit log creation if the only change is whatsapp channel template update return if messaging_template_updates?(audited_changes) - Enterprise::AuditLog.create( + Enterprise::AuditLog.create!( auditable_id: auditable_id, auditable_type: auditable_type, action: 'update', diff --git a/enterprise/app/services/internal/account_analysis/account_updater_service.rb b/enterprise/app/services/internal/account_analysis/account_updater_service.rb index feb54881b..e3f9271c1 100644 --- a/enterprise/app/services/internal/account_analysis/account_updater_service.rb +++ b/enterprise/app/services/internal/account_analysis/account_updater_service.rb @@ -19,7 +19,7 @@ class Internal::AccountAnalysis::AccountUpdaterService def save_error(error_message) @account.internal_attributes['security_flagged'] = true @account.internal_attributes['security_flag_reason'] = "Error: #{error_message}" - @account.save + @account.save! end def save_analysis_results(analysis) diff --git a/lib/action_view/template/handlers/liquid.rb b/lib/action_view/template/handlers/liquid.rb index 65c0b1b3e..ad281bd45 100644 --- a/lib/action_view/template/handlers/liquid.rb +++ b/lib/action_view/template/handlers/liquid.rb @@ -33,7 +33,7 @@ class ActionView::Template::Handlers::Liquid def drops droppables = @controller.send(:liquid_droppables) if @controller.respond_to?(:liquid_droppables, true) - droppables.update(droppables) { |_, obj| obj.try(:to_drop) || nil } + droppables.update(droppables) { |_, obj| obj.try(:to_drop) || nil } # rubocop:disable Rails/SaveBang end def filters diff --git a/lib/config_loader.rb b/lib/config_loader.rb index f637c4588..9062a4fd7 100644 --- a/lib/config_loader.rb +++ b/lib/config_loader.rb @@ -86,6 +86,6 @@ class ConfigLoader # update the existing feature flag values with default values and add new feature flags with default values (account_features + config.value).uniq { |h| h['name'] } end - config.update({ name: 'ACCOUNT_LEVEL_FEATURE_DEFAULTS', value: features, locked: true }) + config.update!({ name: 'ACCOUNT_LEVEL_FEATURE_DEFAULTS', value: features, locked: true }) end end diff --git a/lib/global_config_service.rb b/lib/global_config_service.rb index 8de1c50c9..44b08526a 100644 --- a/lib/global_config_service.rb +++ b/lib/global_config_service.rb @@ -9,7 +9,7 @@ class GlobalConfigService return if config_value.blank? - i = InstallationConfig.where(name: config_key).first_or_create(value: config_value, locked: false) + i = InstallationConfig.where(name: config_key).first_or_create!(value: config_value, locked: false) # To clear a nil value that might have been cached in the previous call GlobalConfig.clear_cache i.value diff --git a/lib/integrations/slack/channel_builder.rb b/lib/integrations/slack/channel_builder.rb index 1edacf8f7..504803852 100644 --- a/lib/integrations/slack/channel_builder.rb +++ b/lib/integrations/slack/channel_builder.rb @@ -9,8 +9,13 @@ class Integrations::Slack::ChannelBuilder channels end - def update(reference_id) - update_reference_id(reference_id) + def update_reference_id(reference_id) + channel = find_channel(reference_id) + return if channel.blank? + + slack_client.conversations_join(channel: channel[:id]) if channel[:is_private] == false + @hook.update!(reference_id: channel[:id], settings: { channel_name: channel[:name] }, status: 'enabled') + @hook end private @@ -36,13 +41,4 @@ class Integrations::Slack::ChannelBuilder def find_channel(reference_id) channels.find { |channel| channel['id'] == reference_id } end - - def update_reference_id(reference_id) - channel = find_channel(reference_id) - return if channel.blank? - - slack_client.conversations_join(channel: channel[:id]) if channel[:is_private] == false - @hook.update!(reference_id: channel[:id], settings: { channel_name: channel[:name] }, status: 'enabled') - @hook - end end diff --git a/lib/vapid_service.rb b/lib/vapid_service.rb index ea3498658..237e826ea 100644 --- a/lib/vapid_service.rb +++ b/lib/vapid_service.rb @@ -17,7 +17,7 @@ class VapidService public_key = ENV.fetch('VAPID_PUBLIC_KEY') { keys.public_key } private_key = ENV.fetch('VAPID_PRIVATE_KEY') { keys.private_key } - i = InstallationConfig.where(name: 'VAPID_KEYS').first_or_create(value: { public_key: public_key, private_key: private_key }) + i = InstallationConfig.where(name: 'VAPID_KEYS').first_or_create!(value: { public_key: public_key, private_key: private_key }) i.value end diff --git a/spec/builders/notification_builder_spec.rb b/spec/builders/notification_builder_spec.rb index 1b28f6adf..8b3cb3b2a 100644 --- a/spec/builders/notification_builder_spec.rb +++ b/spec/builders/notification_builder_spec.rb @@ -73,7 +73,7 @@ describe NotificationBuilder do end it 'will not create a notification if conversation contact is blocked and notification type is not conversation_mention' do - primary_actor.contact.update(blocked: true) + primary_actor.contact.update!(blocked: true) expect do described_class.new( @@ -86,7 +86,7 @@ describe NotificationBuilder do end it 'will create a notification if conversation contact is blocked and notification type is conversation_mention' do - primary_actor.contact.update(blocked: true) + primary_actor.contact.update!(blocked: true) expect do described_class.new( diff --git a/spec/builders/v2/report_builder_spec.rb b/spec/builders/v2/report_builder_spec.rb index 2ad62e2d6..1424acfdb 100644 --- a/spec/builders/v2/report_builder_spec.rb +++ b/spec/builders/v2/report_builder_spec.rb @@ -173,7 +173,7 @@ describe V2::ReportBuilder do conversations = account.conversations.where('created_at < ?', 1.day.ago) conversations.each do |conversation| conversation.pending! - conversation.messages.outgoing.all.update(sender: nil) + conversation.messages.outgoing.all.update!(sender: nil) end perform_enqueued_jobs do @@ -346,7 +346,7 @@ describe V2::ReportBuilder do end it 'returns average first response time' do - label_2.reporting_events.update(value: 1.5) + label_2.reporting_events.update!(value: 1.5) params = { metric: 'avg_first_response_time', diff --git a/spec/controllers/api/v1/accounts/agents_controller_spec.rb b/spec/controllers/api/v1/accounts/agents_controller_spec.rb index a74cbe21e..0429cbb7d 100644 --- a/spec/controllers/api/v1/accounts/agents_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/agents_controller_spec.rb @@ -29,7 +29,7 @@ RSpec.describe 'Agents API', type: :request do end it 'returns custom fields on agents if present' do - agent.update(custom_attributes: { test: 'test' }) + agent.update!(custom_attributes: { test: 'test' }) get "/api/v1/accounts/#{account.id}/agents", headers: agent.create_new_auth_token, diff --git a/spec/controllers/api/v1/accounts/bulk_actions_controller_spec.rb b/spec/controllers/api/v1/accounts/bulk_actions_controller_spec.rb index ec6af61be..7bccce514 100644 --- a/spec/controllers/api/v1/accounts/bulk_actions_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/bulk_actions_controller_spec.rb @@ -119,8 +119,8 @@ RSpec.describe 'Api::V1::Accounts::BulkActionsController', type: :request do end it 'Bulk remove assignee id from conversations' do - Conversation.first.update(assignee_id: agent_1.id) - Conversation.second.update(assignee_id: agent_2.id) + Conversation.first.update!(assignee_id: agent_1.id) + Conversation.second.update!(assignee_id: agent_2.id) params = { type: 'Conversation', fields: { assignee_id: nil }, ids: Conversation.first(3).pluck(:display_id) } expect(Conversation.first.status).to eq('open') @@ -141,8 +141,8 @@ RSpec.describe 'Api::V1::Accounts::BulkActionsController', type: :request do end it 'Do not bulk update status to nil' do - Conversation.first.update(assignee_id: agent_1.id) - Conversation.second.update(assignee_id: agent_2.id) + Conversation.first.update!(assignee_id: agent_1.id) + Conversation.second.update!(assignee_id: agent_2.id) params = { type: 'Conversation', fields: { status: nil }, ids: Conversation.first(3).pluck(:display_id) } expect(Conversation.first.status).to eq('open') diff --git a/spec/controllers/api/v1/accounts/contacts_controller_spec.rb b/spec/controllers/api/v1/accounts/contacts_controller_spec.rb index c9805003a..2594667f0 100644 --- a/spec/controllers/api/v1/accounts/contacts_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/contacts_controller_spec.rb @@ -358,7 +358,7 @@ RSpec.describe 'Contacts API', type: :request do end it 'searches contacts using company name' do - contact2.update(additional_attributes: { company_name: 'acme.inc' }) + contact2.update!(additional_attributes: { company_name: 'acme.inc' }) get "/api/v1/accounts/#{account.id}/contacts/search", params: { q: 'acme.inc' }, headers: admin.create_new_auth_token, @@ -658,7 +658,7 @@ RSpec.describe 'Contacts API', type: :request do end it 'allows unblocking of contact' do - contact.update(blocked: true) + contact.update!(blocked: true) patch "/api/v1/accounts/#{account.id}/contacts/#{contact.id}", params: { blocked: false }, headers: admin.create_new_auth_token, diff --git a/spec/controllers/api/v1/accounts/custom_filters_controller_spec.rb b/spec/controllers/api/v1/accounts/custom_filters_controller_spec.rb index 760100cf3..0576b89e8 100644 --- a/spec/controllers/api/v1/accounts/custom_filters_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/custom_filters_controller_spec.rb @@ -18,7 +18,7 @@ RSpec.describe 'Custom Filters API', type: :request do custom_attribute_type: '' } ] } - custom_filter.save + custom_filter.save! end describe 'GET /api/v1/accounts/{account.id}/custom_filters' do diff --git a/spec/controllers/api/v1/accounts/macros_controller_spec.rb b/spec/controllers/api/v1/accounts/macros_controller_spec.rb index 5fb8fb2b4..d3d8c09a5 100644 --- a/spec/controllers/api/v1/accounts/macros_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/macros_controller_spec.rb @@ -318,7 +318,7 @@ RSpec.describe 'Api::V1::Accounts::MacrosController', type: :request do end it 'Assign the agent when he is not inbox member' do - InboxMember.last.destroy + InboxMember.last.destroy! expect(conversation.assignee).to be_nil diff --git a/spec/controllers/api/v1/accounts/portals_controller_spec.rb b/spec/controllers/api/v1/accounts/portals_controller_spec.rb index aeec9cab4..eb251dc0a 100644 --- a/spec/controllers/api/v1/accounts/portals_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/portals_controller_spec.rb @@ -52,7 +52,7 @@ RSpec.describe 'Api::V1::Accounts::Portals', type: :request do end it 'returns portal articles metadata' do - portal.update(config: { allowed_locales: %w[en es], default_locale: 'en' }) + portal.update!(config: { allowed_locales: %w[en es], default_locale: 'en' }) en_cat = create(:category, locale: :en, portal_id: portal.id, slug: 'en-cat') es_cat = create(:category, locale: :es, portal_id: portal.id, slug: 'es-cat') create(:article, category_id: en_cat.id, portal_id: portal.id, author_id: agent.id) diff --git a/spec/controllers/api/v1/accounts_controller_spec.rb b/spec/controllers/api/v1/accounts_controller_spec.rb index bd604f650..bb173d006 100644 --- a/spec/controllers/api/v1/accounts_controller_spec.rb +++ b/spec/controllers/api/v1/accounts_controller_spec.rb @@ -119,7 +119,7 @@ RSpec.describe 'Accounts API', type: :request do context 'when it is an authenticated user' do it 'shows an account' do - account.update(auto_resolve_duration: 30) + account.update!(auto_resolve_duration: 30) get "/api/v1/accounts/#{account.id}", headers: admin.create_new_auth_token, @@ -141,7 +141,7 @@ RSpec.describe 'Accounts API', type: :request do let(:admin) { create(:user, account: account, role: :administrator) } it 'returns cache_keys as expected' do - account.update(auto_resolve_duration: 30) + account.update!(auto_resolve_duration: 30) get "/api/v1/accounts/#{account.id}/cache_keys", headers: admin.create_new_auth_token, @@ -214,7 +214,7 @@ RSpec.describe 'Accounts API', type: :request do end it 'updates onboarding step to invite_team if onboarding step is present in account custom attributes' do - account.update(custom_attributes: { onboarding_step: 'account_update' }) + account.update!(custom_attributes: { onboarding_step: 'account_update' }) put "/api/v1/accounts/#{account.id}", params: params, headers: admin.create_new_auth_token, diff --git a/spec/controllers/api/v1/widget/conversations_controller_spec.rb b/spec/controllers/api/v1/widget/conversations_controller_spec.rb index 6966c87ea..226550fac 100644 --- a/spec/controllers/api/v1/widget/conversations_controller_spec.rb +++ b/spec/controllers/api/v1/widget/conversations_controller_spec.rb @@ -205,7 +205,7 @@ RSpec.describe '/api/v1/widget/conversations/toggle_typing', type: :request do describe 'POST /api/v1/widget/conversations/transcript' do context 'with a conversation' do it 'sends transcript email' do - contact.update(email: 'test@test.com') + contact.update!(email: 'test@test.com') mailer = double allow(ConversationReplyMailer).to receive(:with).and_return(mailer) allow(mailer).to receive(:conversation_transcript) @@ -217,7 +217,7 @@ RSpec.describe '/api/v1/widget/conversations/toggle_typing', type: :request do expect(response).to have_http_status(:success) expect(mailer).to have_received(:conversation_transcript).with(conversation, 'test@test.com') - contact.update(email: nil) + contact.update!(email: nil) end end end diff --git a/spec/controllers/public/api/v1/portals_controller_spec.rb b/spec/controllers/public/api/v1/portals_controller_spec.rb index 004d013ea..9ee26f2f9 100644 --- a/spec/controllers/public/api/v1/portals_controller_spec.rb +++ b/spec/controllers/public/api/v1/portals_controller_spec.rb @@ -20,7 +20,7 @@ RSpec.describe Public::Api::V1::PortalsController, type: :request do end it 'Throws unauthorised error for unknown domain' do - portal.update(custom_domain: 'www.something.com') + portal.update!(custom_domain: 'www.something.com') get "/hc/#{portal.slug}/en" diff --git a/spec/enterprise/controllers/api/v1/accounts/agents_controller_spec.rb b/spec/enterprise/controllers/api/v1/accounts/agents_controller_spec.rb index e5a8a5b7d..8b8e0cf01 100644 --- a/spec/enterprise/controllers/api/v1/accounts/agents_controller_spec.rb +++ b/spec/enterprise/controllers/api/v1/accounts/agents_controller_spec.rb @@ -11,7 +11,7 @@ RSpec.describe 'Agents API', type: :request do params = { name: 'NewUser', email: Faker::Internet.email, role: :agent } before do - account.update(limits: { agents: 4 }) + account.update!(limits: { agents: 4 }) create_list(:user, 4, account: account, role: :agent) end @@ -31,7 +31,7 @@ RSpec.describe 'Agents API', type: :request do context 'when exceeding agent limit' do it 'prevents creating agents and returns a payment required status' do # Set the limit to be less than the number of emails - account.update(limits: { agents: 2 }) + account.update!(limits: { agents: 2 }) expect do post "/api/v1/accounts/#{account.id}/agents/bulk_create", params: bulk_create_params, headers: admin.create_new_auth_token @@ -44,7 +44,7 @@ RSpec.describe 'Agents API', type: :request do context 'when onboarding step is present in account custom attributes' do it 'removes onboarding step from account custom attributes' do - account.update(custom_attributes: { onboarding_step: 'completed' }) + account.update!(custom_attributes: { onboarding_step: 'completed' }) post "/api/v1/accounts/#{account.id}/agents/bulk_create", params: bulk_create_params, headers: admin.create_new_auth_token diff --git a/spec/enterprise/controllers/api/v1/accounts/applied_slas_controller_spec.rb b/spec/enterprise/controllers/api/v1/accounts/applied_slas_controller_spec.rb index 423f65711..13bf6ebc7 100644 --- a/spec/enterprise/controllers/api/v1/accounts/applied_slas_controller_spec.rb +++ b/spec/enterprise/controllers/api/v1/accounts/applied_slas_controller_spec.rb @@ -116,8 +116,8 @@ RSpec.describe 'Applied SLAs API', type: :request do it 'returns a CSV file with breached conversations' do create(:applied_sla, sla_policy: sla_policy1, conversation: conversation1, sla_status: 'missed') create(:applied_sla, sla_policy: sla_policy1, conversation: conversation2, sla_status: 'missed') - conversation1.update(status: 'open') - conversation2.update(status: 'resolved') + conversation1.update!(status: 'open') + conversation2.update!(status: 'resolved') get "/api/v1/accounts/#{account.id}/applied_slas/download", headers: administrator.create_new_auth_token diff --git a/spec/enterprise/controllers/enterprise/api/v1/accounts/conversations_controller_spec.rb b/spec/enterprise/controllers/enterprise/api/v1/accounts/conversations_controller_spec.rb index fb028b76f..d49f094af 100644 --- a/spec/enterprise/controllers/enterprise/api/v1/accounts/conversations_controller_spec.rb +++ b/spec/enterprise/controllers/enterprise/api/v1/accounts/conversations_controller_spec.rb @@ -27,7 +27,7 @@ RSpec.describe 'Enterprise Conversations API', type: :request do end it 'throws error if conversation already has a different sla' do - conversation.update(sla_policy: create(:sla_policy, account: account)) + conversation.update!(sla_policy: create(:sla_policy, account: account)) patch "/api/v1/accounts/#{account.id}/conversations/#{conversation.display_id}", params: params, headers: agent.create_new_auth_token, diff --git a/spec/enterprise/controllers/enterprise/api/v1/accounts/portals_controller_spec.rb b/spec/enterprise/controllers/enterprise/api/v1/accounts/portals_controller_spec.rb index cb296494c..fe66d5f84 100644 --- a/spec/enterprise/controllers/enterprise/api/v1/accounts/portals_controller_spec.rb +++ b/spec/enterprise/controllers/enterprise/api/v1/accounts/portals_controller_spec.rb @@ -50,7 +50,7 @@ RSpec.describe 'Enterprise Portal API', type: :request do describe 'POST /api/v1/accounts/:account_id/portals' do let(:portal_params) do - { portal: { + { portal: { name: 'test_portal', slug: 'test_kbase', custom_domain: 'https://support.chatwoot.dev' diff --git a/spec/enterprise/controllers/enterprise/api/v1/accounts_controller_spec.rb b/spec/enterprise/controllers/enterprise/api/v1/accounts_controller_spec.rb index 0bd917c06..47bc64a5e 100644 --- a/spec/enterprise/controllers/enterprise/api/v1/accounts_controller_spec.rb +++ b/spec/enterprise/controllers/enterprise/api/v1/accounts_controller_spec.rb @@ -122,8 +122,8 @@ RSpec.describe 'Enterprise Billing APIs', type: :request do context 'when it is an authenticated user' do before do - InstallationConfig.where(name: 'DEPLOYMENT_ENV').first_or_create(value: 'cloud') - InstallationConfig.where(name: 'CHATWOOT_CLOUD_PLANS').first_or_create(value: [{ 'name': 'Hacker' }]) + InstallationConfig.where(name: 'DEPLOYMENT_ENV').first_or_create!(value: 'cloud') + InstallationConfig.where(name: 'CHATWOOT_CLOUD_PLANS').first_or_create!(value: [{ 'name': 'Hacker' }]) end context 'when it is an agent' do @@ -158,8 +158,8 @@ RSpec.describe 'Enterprise Billing APIs', type: :request do before do create(:conversation, account: account) create(:channel_api, account: account) - InstallationConfig.where(name: 'DEPLOYMENT_ENV').first_or_create(value: 'cloud') - InstallationConfig.where(name: 'CHATWOOT_CLOUD_PLANS').first_or_create(value: [{ 'name': 'Hacker' }]) + InstallationConfig.where(name: 'DEPLOYMENT_ENV').first_or_create!(value: 'cloud') + InstallationConfig.where(name: 'CHATWOOT_CLOUD_PLANS').first_or_create!(value: [{ 'name': 'Hacker' }]) end it 'returns the limits if the plan is default' do diff --git a/spec/enterprise/models/account_spec.rb b/spec/enterprise/models/account_spec.rb index 4d851d50e..8186167b9 100644 --- a/spec/enterprise/models/account_spec.rb +++ b/spec/enterprise/models/account_spec.rb @@ -132,7 +132,7 @@ RSpec.describe Account, type: :model do describe 'when limits are configured for an account' do before do create(:installation_config, name: 'CAPTAIN_CLOUD_PLAN_LIMITS', value: captain_limits.to_json) - account.update(limits: { captain_documents: 5555, captain_responses: 9999 }) + account.update!(limits: { captain_documents: 5555, captain_responses: 9999 }) end it 'returns limits based on custom attributes' do @@ -149,7 +149,7 @@ RSpec.describe Account, type: :model do end it 'creates audit logs when account is updated' do - account.update(name: 'New Name') + account.update!(name: 'New Name') expect(Audited::Audit.where(auditable_type: 'Account', action: 'update').count).to eq 1 end end @@ -159,23 +159,23 @@ RSpec.describe Account, type: :model do end it 'returns max limits from account when enterprise version' do - account.update(limits: { agents: 10 }) + account.update!(limits: { agents: 10 }) expect(account.usage_limits[:agents]).to eq(10) end it 'returns limits based on subscription' do - account.update(limits: { agents: 10 }, custom_attributes: { subscribed_quantity: 5 }) + account.update!(limits: { agents: 10 }, custom_attributes: { subscribed_quantity: 5 }) expect(account.usage_limits[:agents]).to eq(5) end it 'returns max limits from global config if account limit is absent' do - account.update(limits: { agents: '' }) + account.update!(limits: { agents: '' }) expect(account.usage_limits[:agents]).to eq(20) end it 'returns max limits from app limit if account limit and installation config is absent' do - account.update(limits: { agents: '' }) - InstallationConfig.where(name: 'ACCOUNT_AGENTS_LIMIT').update(value: '') + account.update!(limits: { agents: '' }) + InstallationConfig.where(name: 'ACCOUNT_AGENTS_LIMIT').update!(value: '') expect(account.usage_limits[:agents]).to eq(ChatwootApp.max_limit) end diff --git a/spec/enterprise/models/automation_rule_spec.rb b/spec/enterprise/models/automation_rule_spec.rb index e2e929d2c..7f175e225 100644 --- a/spec/enterprise/models/automation_rule_spec.rb +++ b/spec/enterprise/models/automation_rule_spec.rb @@ -14,7 +14,7 @@ RSpec.describe AutomationRule do context 'when automation rule is updated' do it 'has associated audit log created' do - automation_rule.update(name: 'automation rule 2') + automation_rule.update!(name: 'automation rule 2') expect(Audited::Audit.where(auditable_type: 'AutomationRule', action: 'update').count).to eq 1 end end diff --git a/spec/enterprise/models/inbox_member_spec.rb b/spec/enterprise/models/inbox_member_spec.rb index b4559bfc6..70165be8d 100644 --- a/spec/enterprise/models/inbox_member_spec.rb +++ b/spec/enterprise/models/inbox_member_spec.rb @@ -21,7 +21,7 @@ RSpec.describe InboxMember, type: :model do context 'when inbox member is destroyed' do it 'has associated audit log created' do - inbox_member.destroy + inbox_member.destroy! audit_log = Audited::Audit.find_by(auditable: inbox_member, action: 'destroy') expect(audit_log).to be_present expect(audit_log.audited_changes['inbox_id']).to eq(inbox.id) diff --git a/spec/enterprise/models/inbox_spec.rb b/spec/enterprise/models/inbox_spec.rb index 3e3e060d8..1a3705d5e 100644 --- a/spec/enterprise/models/inbox_spec.rb +++ b/spec/enterprise/models/inbox_spec.rb @@ -28,7 +28,7 @@ RSpec.describe Inbox do it 'returns member ids with assignment capacity with inbox max_assignment_limit is configured' do # agent 1 has 1 conversations, agent 2 has 2 conversations, agent 3 has 3 conversations and agent 4 with none - inbox.update(auto_assignment_config: { max_assignment_limit: 2 }) + inbox.update!(auto_assignment_config: { max_assignment_limit: 2 }) expect(inbox.member_ids_with_assignment_capacity).to contain_exactly(inbox_member_1.user_id, inbox_member_4.user_id) end @@ -46,7 +46,7 @@ RSpec.describe Inbox do context 'when inbox is updated' do it 'has associated audit log created' do - inbox.update(name: 'Updated Inbox') + inbox.update!(name: 'Updated Inbox') expect(Audited::Audit.where(auditable_type: 'Inbox', action: 'update').count).to eq(1) end end @@ -55,7 +55,7 @@ RSpec.describe Inbox do it 'has associated audit log created' do previous_color = inbox.channel.widget_color new_color = '#ff0000' - inbox.channel.update(widget_color: new_color) + inbox.channel.update!(widget_color: new_color) # check if channel update creates an audit log against inbox expect(Audited::Audit.where(auditable_type: 'Inbox', action: 'update').count).to eq(1) @@ -78,7 +78,7 @@ RSpec.describe Inbox do context 'when inbox is updated' do it 'has associated audit log created' do - inbox.update(name: 'Updated Inbox') + inbox.update!(name: 'Updated Inbox') expect(Audited::Audit.where(auditable_type: 'Inbox', action: 'update').count).to eq(1) end end @@ -87,7 +87,7 @@ RSpec.describe Inbox do it 'has associated audit log created' do previous_webhook = inbox.channel.webhook_url new_webhook = 'https://example2.com' - inbox.channel.update(webhook_url: new_webhook) + inbox.channel.update!(webhook_url: new_webhook) # check if channel update creates an audit log against inbox expect(Audited::Audit.where(auditable_type: 'Inbox', action: 'update').count).to eq(1) @@ -122,7 +122,7 @@ RSpec.describe Inbox do context 'when inbox is updated' do it 'has associated audit log created' do - inbox.update(name: 'Updated Inbox') + inbox.update!(name: 'Updated Inbox') expect(Audited::Audit.where(auditable_type: 'Inbox', action: 'update').count).to eq(1) end end @@ -131,7 +131,7 @@ RSpec.describe Inbox do it 'has associated audit log created' do previous_phone_number = inbox.channel.phone_number new_phone_number = '1234567890' - inbox.channel.update(phone_number: new_phone_number) + inbox.channel.update!(phone_number: new_phone_number) # check if channel update creates an audit log against inbox expect(Audited::Audit.where(auditable_type: 'Inbox', action: 'update').count).to eq(1) diff --git a/spec/enterprise/models/macro_spec.rb b/spec/enterprise/models/macro_spec.rb index ff3368438..c06313893 100644 --- a/spec/enterprise/models/macro_spec.rb +++ b/spec/enterprise/models/macro_spec.rb @@ -15,7 +15,7 @@ RSpec.describe Macro do context 'when macro is updated' do it 'has associated audit log created' do - macro.update(name: 'awesome macro') + macro.update!(name: 'awesome macro') expect(Audited::Audit.where(auditable_type: 'Macro', action: 'update').count).to eq 1 end end diff --git a/spec/enterprise/models/team_member_spec.rb b/spec/enterprise/models/team_member_spec.rb index 9ce2bd90f..3ad9be42b 100644 --- a/spec/enterprise/models/team_member_spec.rb +++ b/spec/enterprise/models/team_member_spec.rb @@ -21,7 +21,7 @@ RSpec.describe TeamMember, type: :model do context 'when team member is destroyed' do it 'has associated audit log created' do - team_member.destroy + team_member.destroy! audit_log = Audited::Audit.find_by(auditable: team_member, action: 'destroy') expect(audit_log).to be_present expect(audit_log.audited_changes['team_id']).to eq(team.id) diff --git a/spec/enterprise/models/team_spec.rb b/spec/enterprise/models/team_spec.rb index af8bcdc1b..407f5b033 100644 --- a/spec/enterprise/models/team_spec.rb +++ b/spec/enterprise/models/team_spec.rb @@ -15,7 +15,7 @@ RSpec.describe Team do context 'when team is updated' do it 'has associated audit log created' do - team.update(description: 'awesome team') + team.update!(description: 'awesome team') expect(Audited::Audit.where(auditable_type: 'Team', action: 'update').count).to eq 1 end end diff --git a/spec/enterprise/models/user_spec.rb b/spec/enterprise/models/user_spec.rb index 21e398709..b99e0911e 100644 --- a/spec/enterprise/models/user_spec.rb +++ b/spec/enterprise/models/user_spec.rb @@ -35,7 +35,7 @@ RSpec.describe User do it 'will not add error when trying to update a existing user' do allow(ChatwootHub).to receive(:pricing_plan_quantity).and_return(1) - existing_user.update(name: 'new name') + existing_user.update!(name: 'new name') # since there is user and existing user, we are already over limits existing_user.valid? expect(existing_user.errors[:base]).to be_empty diff --git a/spec/enterprise/models/webhook_spec.rb b/spec/enterprise/models/webhook_spec.rb index ac7d23384..242821f19 100644 --- a/spec/enterprise/models/webhook_spec.rb +++ b/spec/enterprise/models/webhook_spec.rb @@ -15,7 +15,7 @@ RSpec.describe Webhook do context 'when webhook is updated' do it 'has associated audit log created' do - webhook.update(url: 'https://example.com') + webhook.update!(url: 'https://example.com') expect(Audited::Audit.where(auditable_type: 'Webhook', action: 'update').count).to eq 1 end end diff --git a/spec/enterprise/services/enterprise/conversations/permission_filter_service_spec.rb b/spec/enterprise/services/enterprise/conversations/permission_filter_service_spec.rb index b26832faf..800d85979 100644 --- a/spec/enterprise/services/enterprise/conversations/permission_filter_service_spec.rb +++ b/spec/enterprise/services/enterprise/conversations/permission_filter_service_spec.rb @@ -60,7 +60,7 @@ RSpec.describe Enterprise::Conversations::PermissionFilterService do # Create custom role with conversation_manage permission test_custom_role = create(:custom_role, account: test_account, permissions: ['conversation_manage']) account_user = AccountUser.find_by(user: test_agent, account: test_account) - account_user.update(role: :agent, custom_role: test_custom_role) + account_user.update!(role: :agent, custom_role: test_custom_role) # Create some conversations assigned_conversation = create(:conversation, account: test_account, inbox: test_inbox, assignee: test_agent) @@ -96,7 +96,7 @@ RSpec.describe Enterprise::Conversations::PermissionFilterService do test_custom_role = create(:custom_role, account: test_account, permissions: %w[conversation_participating_manage]) account_user = AccountUser.find_by(user: test_agent, account: test_account) - account_user.update(role: :agent, custom_role: test_custom_role) + account_user.update!(role: :agent, custom_role: test_custom_role) # Create some conversations other_conversation = create(:conversation, account: test_account, inbox: test_inbox) @@ -131,7 +131,7 @@ RSpec.describe Enterprise::Conversations::PermissionFilterService do test_custom_role = create(:custom_role, account: test_account, permissions: %w[conversation_unassigned_manage]) account_user = AccountUser.find_by(user: test_agent, account: test_account) - account_user.update(role: :agent, custom_role: test_custom_role) + account_user.update!(role: :agent, custom_role: test_custom_role) # Create some conversations assigned_conversation = create(:conversation, account: test_account, inbox: test_inbox, assignee: test_agent) @@ -170,7 +170,7 @@ RSpec.describe Enterprise::Conversations::PermissionFilterService do test_custom_role = create(:custom_role, account: test_account, permissions: permissions) account_user = AccountUser.find_by(user: test_agent, account: test_account) - account_user.update(role: :agent, custom_role: test_custom_role) + account_user.update!(role: :agent, custom_role: test_custom_role) # Create some conversations assigned_to_agent = create(:conversation, account: test_account, inbox: test_inbox, assignee: test_agent) diff --git a/spec/enterprise/services/sla/evaluate_applied_sla_service_spec.rb b/spec/enterprise/services/sla/evaluate_applied_sla_service_spec.rb index 71afd2125..cf8a79cc4 100644 --- a/spec/enterprise/services/sla/evaluate_applied_sla_service_spec.rb +++ b/spec/enterprise/services/sla/evaluate_applied_sla_service_spec.rb @@ -42,8 +42,8 @@ RSpec.describe Sla::EvaluateAppliedSlaService do context 'when next response SLA is missed' do before do - applied_sla.sla_policy.update(next_response_time_threshold: 1.hour) - conversation.update(first_reply_created_at: 5.hours.ago, waiting_since: 5.hours.ago) + applied_sla.sla_policy.update!(next_response_time_threshold: 1.hour) + conversation.update!(first_reply_created_at: 5.hours.ago, waiting_since: 5.hours.ago) end it 'updates the SLA status to missed and logs a warning' do @@ -89,7 +89,7 @@ RSpec.describe Sla::EvaluateAppliedSlaService do context 'when resolved conversation with resolution time SLA is missed' do before do conversation.resolved! - applied_sla.sla_policy.update(resolution_time_threshold: 1.hour) + applied_sla.sla_policy.update!(resolution_time_threshold: 1.hour) end it 'does not update the SLA status to missed' do @@ -100,8 +100,8 @@ RSpec.describe Sla::EvaluateAppliedSlaService do context 'when multiple SLAs are missed' do before do - applied_sla.sla_policy.update(first_response_time_threshold: 1.hour, next_response_time_threshold: 1.hour, resolution_time_threshold: 1.hour) - conversation.update(first_reply_created_at: 5.hours.ago, waiting_since: 5.hours.ago) + applied_sla.sla_policy.update!(first_response_time_threshold: 1.hour, next_response_time_threshold: 1.hour, resolution_time_threshold: 1.hour) + conversation.update!(first_reply_created_at: 5.hours.ago, waiting_since: 5.hours.ago) end it 'updates the SLA status to missed and logs multiple warnings' do @@ -119,8 +119,8 @@ RSpec.describe Sla::EvaluateAppliedSlaService do describe '#perform - SLA hits' do context 'when first response SLA is hit' do before do - applied_sla.sla_policy.update(first_response_time_threshold: 6.hours) - conversation.update(first_reply_created_at: 30.minutes.ago) + applied_sla.sla_policy.update!(first_response_time_threshold: 6.hours) + conversation.update!(first_reply_created_at: 30.minutes.ago) end it 'sla remains active until conversation is resolved' do @@ -142,8 +142,8 @@ RSpec.describe Sla::EvaluateAppliedSlaService do context 'when next response SLA is hit' do before do - applied_sla.sla_policy.update(next_response_time_threshold: 6.hours) - conversation.update(first_reply_created_at: 30.minutes.ago, waiting_since: nil) + applied_sla.sla_policy.update!(next_response_time_threshold: 6.hours) + conversation.update!(first_reply_created_at: 30.minutes.ago, waiting_since: nil) end it 'sla remains active until conversation is resolved' do @@ -164,7 +164,7 @@ RSpec.describe Sla::EvaluateAppliedSlaService do context 'when resolution time SLA is hit' do before do - applied_sla.sla_policy.update(resolution_time_threshold: 8.hours) + applied_sla.sla_policy.update!(resolution_time_threshold: 8.hours) conversation.resolved! end @@ -182,7 +182,7 @@ RSpec.describe Sla::EvaluateAppliedSlaService do describe 'SLA evaluation with frt hit, multiple nrt misses and rt miss' do before do # Setup SLA Policy thresholds - applied_sla.sla_policy.update( + applied_sla.sla_policy.update!( first_response_time_threshold: 2.hours, # Hit frt next_response_time_threshold: 1.hour, # Miss nrt multiple times resolution_time_threshold: 4.hours # Miss rt @@ -204,7 +204,7 @@ RSpec.describe Sla::EvaluateAppliedSlaService do described_class.new(applied_sla: applied_sla).perform # Conversation is resolved missing rt - conversation.update(status: 'resolved') + conversation.update!(status: 'resolved') # this will not create a new notification for rt miss as conversation is resolved # but we would have already created an rt miss notification during previous evaluation diff --git a/spec/finders/email_channel_finder_spec.rb b/spec/finders/email_channel_finder_spec.rb index fe57dec0b..8dc4089a3 100644 --- a/spec/finders/email_channel_finder_spec.rb +++ b/spec/finders/email_channel_finder_spec.rb @@ -9,7 +9,7 @@ describe EmailChannelFinder do let(:reply_cc_mail) { create_inbound_email_from_fixture('reply_cc.eml') } it 'return channel with cc email' do - channel_email.update(email: 'test@example.com') + channel_email.update!(email: 'test@example.com') channel = described_class.new(reply_cc_mail.mail).perform expect(channel).to eq(channel_email) end @@ -19,21 +19,21 @@ describe EmailChannelFinder do let(:reply_mail) { create_inbound_email_from_fixture('reply.eml') } it 'return channel with to email' do - channel_email.update(email: 'test@example.com') + channel_email.update!(email: 'test@example.com') reply_mail.mail['to'] = 'test@example.com' channel = described_class.new(reply_mail.mail).perform expect(channel).to eq(channel_email) end it 'return channel with to+extension email' do - channel_email.update(email: 'test@example.com') + channel_email.update!(email: 'test@example.com') reply_mail.mail['to'] = 'test+123@example.com' channel = described_class.new(reply_mail.mail).perform expect(channel).to eq(channel_email) end it 'return channel with cc email' do - channel_email.update(email: 'test@example.com') + channel_email.update!(email: 'test@example.com') reply_mail.mail['to'] = nil reply_mail.mail['cc'] = 'test@example.com' channel = described_class.new(reply_mail.mail).perform @@ -41,7 +41,7 @@ describe EmailChannelFinder do end it 'return channel with bcc email' do - channel_email.update(email: 'test@example.com') + channel_email.update!(email: 'test@example.com') reply_mail.mail['to'] = nil reply_mail.mail['bcc'] = 'test@example.com' channel = described_class.new(reply_mail.mail).perform @@ -49,7 +49,7 @@ describe EmailChannelFinder do end it 'return channel with X-Original-To email' do - channel_email.update(email: 'test@example.com') + channel_email.update!(email: 'test@example.com') reply_mail.mail['to'] = nil reply_mail.mail['X-Original-To'] = 'test@example.com' channel = described_class.new(reply_mail.mail).perform diff --git a/spec/jobs/account/conversations_resolution_scheduler_job_spec.rb b/spec/jobs/account/conversations_resolution_scheduler_job_spec.rb index 0e4ef3d45..50950726d 100644 --- a/spec/jobs/account/conversations_resolution_scheduler_job_spec.rb +++ b/spec/jobs/account/conversations_resolution_scheduler_job_spec.rb @@ -11,7 +11,7 @@ RSpec.describe Account::ConversationsResolutionSchedulerJob do end it 'enqueues Conversations::ResolutionJob' do - account.update(auto_resolve_duration: 10) + account.update!(auto_resolve_duration: 10) expect(Conversations::ResolutionJob).to receive(:perform_later).with(account: account).once described_class.perform_now end diff --git a/spec/jobs/conversations/resolution_job_spec.rb b/spec/jobs/conversations/resolution_job_spec.rb index 1a812ac86..266156c1f 100644 --- a/spec/jobs/conversations/resolution_job_spec.rb +++ b/spec/jobs/conversations/resolution_job_spec.rb @@ -18,15 +18,15 @@ RSpec.describe Conversations::ResolutionJob do end it 'resolves the issue if time of inactivity is more than the auto resolve duration' do - account.update(auto_resolve_duration: 10) - conversation.update(last_activity_at: 13.days.ago) + account.update!(auto_resolve_duration: 10) + conversation.update!(last_activity_at: 13.days.ago) described_class.perform_now(account: account) expect(conversation.reload.status).to eq('resolved') end it 'resolved only a limited number of conversations in a single execution' do stub_const('Limits::BULK_ACTIONS_LIMIT', 2) - account.update(auto_resolve_duration: 10) + account.update!(auto_resolve_duration: 10) create_list(:conversation, 3, account: account, last_activity_at: 13.days.ago) described_class.perform_now(account: account) expect(account.conversations.resolved.count).to eq(Limits::BULK_ACTIONS_LIMIT) diff --git a/spec/jobs/webhooks/whatsapp_events_job_spec.rb b/spec/jobs/webhooks/whatsapp_events_job_spec.rb index ba8a19413..2fe314d93 100644 --- a/spec/jobs/webhooks/whatsapp_events_job_spec.rb +++ b/spec/jobs/webhooks/whatsapp_events_job_spec.rb @@ -102,7 +102,7 @@ RSpec.describe Webhooks::WhatsappEventsJob do context 'when default provider' do it 'enqueue Whatsapp::IncomingMessageService' do stub_request(:post, 'https://waba.360dialog.io/v1/configs/webhook') - channel.update(provider: 'default') + channel.update!(provider: 'default') allow(Whatsapp::IncomingMessageService).to receive(:new).and_return(process_service) expect(Whatsapp::IncomingMessageService).to receive(:new) job.perform_now(params) diff --git a/spec/lib/integrations/dialogflow/processor_service_spec.rb b/spec/lib/integrations/dialogflow/processor_service_spec.rb index 2b5f36c5a..453191d3b 100644 --- a/spec/lib/integrations/dialogflow/processor_service_spec.rb +++ b/spec/lib/integrations/dialogflow/processor_service_spec.rb @@ -157,7 +157,7 @@ describe Integrations::Dialogflow::ProcessorService do let(:processor) { described_class.new(event_name: event_name, hook: hook, event_data: event_data) } before do - hook.update(settings: { 'project_id' => 'test', 'credentials' => 'creds' }) + hook.update(settings: { 'project_id' => 'test', 'credentials' => 'creds' }) # rubocop:disable Rails/SaveBang allow(google_dialogflow).to receive(:new).and_return(session_client) allow(session_client).to receive(:detect_intent).and_return({ session: session, query_input: query_input }) end diff --git a/spec/lib/integrations/facebook/delivery_status_spec.rb b/spec/lib/integrations/facebook/delivery_status_spec.rb index 28f1fe982..b0a212095 100644 --- a/spec/lib/integrations/facebook/delivery_status_spec.rb +++ b/spec/lib/integrations/facebook/delivery_status_spec.rb @@ -46,7 +46,7 @@ describe Integrations::Facebook::DeliveryStatus do end it 'does not update the message status if the message was created after the watermark' do - message1.update(created_at: 1.day.from_now) + message1.update!(created_at: 1.day.from_now) message_deliveries.delivery['watermark'] = 1.day.ago.to_i described_class.new(params: message_deliveries).perform expect(message1.reload.status).to eq('sent') @@ -73,7 +73,7 @@ describe Integrations::Facebook::DeliveryStatus do end it 'does not update the message status if the message was created after the watermark' do - message1.update(created_at: 1.day.from_now) + message1.update!(created_at: 1.day.from_now) message_reads.read['watermark'] = 1.day.ago.to_i described_class.new(params: message_reads).perform expect(message1.reload.status).to eq('sent') diff --git a/spec/lib/online_status_tracker_spec.rb b/spec/lib/online_status_tracker_spec.rb index d88298485..f0916a211 100644 --- a/spec/lib/online_status_tracker_spec.rb +++ b/spec/lib/online_status_tracker_spec.rb @@ -18,7 +18,7 @@ describe OnlineStatusTracker do end it 'returns agents who have auto offline configured false' do - user2.account_users.first.update(auto_offline: false) + user2.account_users.first.update!(auto_offline: false) expect(described_class.get_available_users(account.id).keys).to contain_exactly(user1.id.to_s, user2.id.to_s) end diff --git a/spec/listeners/action_cable_listener_spec.rb b/spec/listeners/action_cable_listener_spec.rb index 55b74116c..ac590034e 100644 --- a/spec/listeners/action_cable_listener_spec.rb +++ b/spec/listeners/action_cable_listener_spec.rb @@ -38,7 +38,7 @@ describe ActionCableListener do it 'sends message to all hmac verified contact inboxes' do # HACK: to reload conversation inbox members expect(conversation.inbox.reload.inbox_members.count).to eq(1) - conversation.contact_inbox.update(hmac_verified: true) + conversation.contact_inbox.update!(hmac_verified: true) # creating a non verified contact inbox to ensure the events are not sent to it create(:contact_inbox, contact: conversation.contact, inbox: inbox) verified_contact_inbox = create(:contact_inbox, contact: conversation.contact, inbox: inbox, hmac_verified: true) diff --git a/spec/listeners/automation_rule_listener_old_spec.rb b/spec/listeners/automation_rule_listener_old_spec.rb index 5103117cd..91ab09824 100644 --- a/spec/listeners/automation_rule_listener_old_spec.rb +++ b/spec/listeners/automation_rule_listener_old_spec.rb @@ -331,7 +331,7 @@ describe AutomationRuleListener do }.with_indifferent_access ] ) - conversation.update(status: :snoozed) + conversation.update!(status: :snoozed) end let!(:event) do @@ -351,7 +351,7 @@ describe AutomationRuleListener do end it 'triggers automation rule to assign team with OR operator' do - conversation.update(status: :open) + conversation.update!(status: :open) automation_rule.update!( conditions: [ { @@ -380,7 +380,7 @@ describe AutomationRuleListener do context 'when rule doesnt match' do it 'when automation rule is triggered it will not assign team' do - conversation.update(status: :open) + conversation.update!(status: :open) expect(conversation.team_id).not_to eq(team.id) @@ -391,7 +391,7 @@ describe AutomationRuleListener do end it 'when automation rule is triggers, it will not assign team on attribute_changed values' do - conversation.update(status: :snoozed) + conversation.update!(status: :snoozed) event = Events::Base.new('conversation_updated', Time.zone.now, { conversation: conversation, changed_attributes: { company: %w[Marvel DC] } }) diff --git a/spec/listeners/notification_listener_spec.rb b/spec/listeners/notification_listener_spec.rb index 76e458b8e..9661df14f 100644 --- a/spec/listeners/notification_listener_spec.rb +++ b/spec/listeners/notification_listener_spec.rb @@ -126,7 +126,7 @@ describe NotificationListener do it 'will not create duplicate new message notification for the same user for mentions participation & assignment' do create(:inbox_member, user: first_agent, inbox: inbox) - conversation.update(assignee: first_agent) + conversation.update!(assignee: first_agent) message = build( :message, @@ -144,9 +144,9 @@ describe NotificationListener do it 'will not create duplicate new message notifications for assignment & participation' do create(:inbox_member, user: first_agent, inbox: inbox) - conversation.update(assignee: first_agent) + conversation.update!(assignee: first_agent) # participants is created by async job. so creating it directly for testcase - conversation.conversation_participants.first_or_create(user: first_agent) + conversation.conversation_participants.first_or_create!(user: first_agent) message = build( :message, diff --git a/spec/listeners/reporting_event_listener_spec.rb b/spec/listeners/reporting_event_listener_spec.rb index 9a6b8d123..06bc0e921 100644 --- a/spec/listeners/reporting_event_listener_spec.rb +++ b/spec/listeners/reporting_event_listener_spec.rb @@ -50,7 +50,7 @@ describe ReportingEventListener do end it 'does not create a conversation_bot_resolved event if resolved conversation inbox does not have active bot' do - bot_resolved_conversation.update(inbox: inbox) + bot_resolved_conversation.update!(inbox: inbox) event = Events::Base.new('conversation.resolved', Time.zone.now, conversation: bot_resolved_conversation) listener.conversation_resolved(event) expect(account.reporting_events.where(name: 'conversation_bot_resolved').count).to be 0 diff --git a/spec/listeners/webhook_listener_spec.rb b/spec/listeners/webhook_listener_spec.rb index e33f6684d..1466d28a9 100644 --- a/spec/listeners/webhook_listener_spec.rb +++ b/spec/listeners/webhook_listener_spec.rb @@ -166,7 +166,7 @@ describe WebhookListener do it 'triggers webhook' do webhook = create(:webhook, inbox: inbox, account: account) - conversation.update(custom_attributes: { test: 'testing custom attri webhook' }) + conversation.update!(custom_attributes: { test: 'testing custom attri webhook' }) expect(WebhookJob).to receive(:perform_later).with( webhook.url, diff --git a/spec/mailboxes/application_mailbox_spec.rb b/spec/mailboxes/application_mailbox_spec.rb index f4f28d811..cce26370c 100644 --- a/spec/mailboxes/application_mailbox_spec.rb +++ b/spec/mailboxes/application_mailbox_spec.rb @@ -43,7 +43,7 @@ RSpec.describe ApplicationMailbox do it 'routes support emails to Support Mailbox when mail is to channel email' do # this email is hardcoded in the support.eml, that's why we are updating this - channel_email.update(email: 'care@example.com') + channel_email.update!(email: 'care@example.com') dbl = double expect(SupportMailbox).to receive(:new).and_return(dbl) expect(dbl).to receive(:perform_processing).and_return(true) @@ -52,7 +52,7 @@ RSpec.describe ApplicationMailbox do it 'routes support emails to Support Mailbox when mail is to channel forward to email' do # this email is hardcoded in the support.eml, that's why we are updating this - channel_email.update(forward_to_email: 'care@example.com') + channel_email.update!(forward_to_email: 'care@example.com') dbl = double expect(SupportMailbox).to receive(:new).and_return(dbl) expect(dbl).to receive(:perform_processing).and_return(true) @@ -60,7 +60,7 @@ RSpec.describe ApplicationMailbox do end it 'routes support emails to Support Mailbox with cc email' do - channel_email.update(email: 'test@example.com') + channel_email.update!(email: 'test@example.com') dbl = double expect(SupportMailbox).to receive(:new).and_return(dbl) expect(dbl).to receive(:perform_processing).and_return(true) diff --git a/spec/mailers/conversation_reply_mailer_spec.rb b/spec/mailers/conversation_reply_mailer_spec.rb index b8984e2c2..c07bbe284 100644 --- a/spec/mailers/conversation_reply_mailer_spec.rb +++ b/spec/mailers/conversation_reply_mailer_spec.rb @@ -71,7 +71,7 @@ RSpec.describe ConversationReplyMailer do it 'will not send email if conversation is already viewed by contact' do create(:message, message_type: 'outgoing', account: account, conversation: conversation) - conversation.update(contact_last_seen_at: Time.zone.now) + conversation.update!(contact_last_seen_at: Time.zone.now) expect(mail).to be_nil end @@ -132,7 +132,7 @@ RSpec.describe ConversationReplyMailer do it 'will not send email if conversation is already viewed by contact' do create(:message, message_type: 'outgoing', account: account, conversation: conversation) - conversation.update(contact_last_seen_at: Time.zone.now) + conversation.update!(contact_last_seen_at: Time.zone.now) expect(mail).to be_nil end end @@ -176,20 +176,20 @@ RSpec.describe ConversationReplyMailer do end it 'renders sender name even when assignee is not present' do - conversation.update(assignee_id: nil) + conversation.update!(assignee_id: nil) mail = described_class.email_reply(message) expect(mail['from'].value).to eq "#{message.sender.available_name} from #{smtp_email_channel.inbox.name} <#{smtp_email_channel.email}>" end it 'renders assignee name in the from address when sender_name not available' do - message.update(sender_id: nil) + message.update!(sender_id: nil) mail = described_class.email_reply(message) expect(mail['from'].value).to eq "#{conversation.assignee.available_name} from #{smtp_email_channel.inbox.name} <#{smtp_email_channel.email}>" end it 'renders inbox name as sender and assignee or business_name not present' do - message.update(sender_id: nil) - conversation.update(assignee_id: nil) + message.update!(sender_id: nil) + conversation.update!(assignee_id: nil) mail = described_class.email_reply(message) expect(mail['from'].value).to eq "Notifications from #{smtp_email_channel.inbox.name} <#{smtp_email_channel.email}>" @@ -197,14 +197,14 @@ RSpec.describe ConversationReplyMailer do context 'when friendly name enabled' do before do - conversation.inbox.update(sender_name_type: 0) - conversation.inbox.update(business_name: 'Business Name') + conversation.inbox.update!(sender_name_type: 0) + conversation.inbox.update!(business_name: 'Business Name') end it 'renders sender name as sender and assignee and business_name not present' do - message.update(sender_id: nil) - conversation.update(assignee_id: nil) - conversation.inbox.update(business_name: nil) + message.update!(sender_id: nil) + conversation.update!(assignee_id: nil) + conversation.inbox.update!(business_name: nil) mail = described_class.email_reply(message) @@ -212,8 +212,8 @@ RSpec.describe ConversationReplyMailer do end it 'renders sender name as sender and assignee nil and business_name present' do - message.update(sender_id: nil) - conversation.update(assignee_id: nil) + message.update!(sender_id: nil) + conversation.update!(assignee_id: nil) mail = described_class.email_reply(message) @@ -223,8 +223,8 @@ RSpec.describe ConversationReplyMailer do end it 'renders sender name as sender nil and assignee and business_name present' do - message.update(sender_id: nil) - conversation.update(assignee_id: agent.id) + message.update!(sender_id: nil) + conversation.update!(assignee_id: agent.id) mail = described_class.email_reply(message) expect(mail['from'].value).to eq "#{agent.available_name} from #{conversation.inbox.business_name} <#{smtp_email_channel.email}>" @@ -232,8 +232,8 @@ RSpec.describe ConversationReplyMailer do it 'renders sender name as sender and assignee and business_name present' do agent_2 = create(:user, email: 'agent2@example.com', account: account) - message.update(sender_id: agent_2.id) - conversation.update(assignee_id: agent.id) + message.update!(sender_id: agent_2.id) + conversation.update!(assignee_id: agent.id) mail = described_class.email_reply(message) expect(mail['from'].value).to eq "#{agent_2.available_name} from #{conversation.inbox.business_name} <#{smtp_email_channel.email}>" @@ -242,14 +242,14 @@ RSpec.describe ConversationReplyMailer do context 'when friendly name disabled' do before do - conversation.inbox.update(sender_name_type: 1) - conversation.inbox.update(business_name: 'Business Name') + conversation.inbox.update!(sender_name_type: 1) + conversation.inbox.update!(business_name: 'Business Name') end it 'renders sender name as business_name not present' do - message.update(sender_id: nil) - conversation.update(assignee_id: nil) - conversation.inbox.update(business_name: nil) + message.update!(sender_id: nil) + conversation.update!(assignee_id: nil) + conversation.inbox.update!(business_name: nil) mail = described_class.email_reply(message) @@ -257,8 +257,8 @@ RSpec.describe ConversationReplyMailer do end it 'renders sender name as business_name present' do - message.update(sender_id: nil) - conversation.update(assignee_id: nil) + message.update!(sender_id: nil) + conversation.update!(assignee_id: nil) mail = described_class.email_reply(message) diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb index e545f8e4a..54a4a144e 100644 --- a/spec/models/account_spec.rb +++ b/spec/models/account_spec.rb @@ -52,21 +52,21 @@ RSpec.describe Account do let(:account) { create(:account) } it 'returns the domain from inbox if inbox value is present' do - account.update(domain: 'test.com') + account.update!(domain: 'test.com') with_modified_env MAILER_INBOUND_EMAIL_DOMAIN: 'test2.com' do expect(account.inbound_email_domain).to eq('test.com') end end it 'returns the domain from ENV if inbox value is nil' do - account.update(domain: nil) + account.update!(domain: nil) with_modified_env MAILER_INBOUND_EMAIL_DOMAIN: 'test.com' do expect(account.inbound_email_domain).to eq('test.com') end end it 'returns the domain from ENV if inbox value is empty string' do - account.update(domain: '') + account.update!(domain: '') with_modified_env MAILER_INBOUND_EMAIL_DOMAIN: 'test.com' do expect(account.inbound_email_domain).to eq('test.com') end @@ -77,21 +77,21 @@ RSpec.describe Account do let(:account) { create(:account) } it 'returns the support email from inbox if inbox value is present' do - account.update(support_email: 'support@chatwoot.com') + account.update!(support_email: 'support@chatwoot.com') with_modified_env MAILER_SENDER_EMAIL: 'hello@chatwoot.com' do expect(account.support_email).to eq('support@chatwoot.com') end end it 'returns the support email from ENV if inbox value is nil' do - account.update(support_email: nil) + account.update!(support_email: nil) with_modified_env MAILER_SENDER_EMAIL: 'hello@chatwoot.com' do expect(account.support_email).to eq('hello@chatwoot.com') end end it 'returns the support email from ENV if inbox value is empty string' do - account.update(support_email: '') + account.update!(support_email: '') with_modified_env MAILER_SENDER_EMAIL: 'hello@chatwoot.com' do expect(account.support_email).to eq('hello@chatwoot.com') end @@ -104,7 +104,7 @@ RSpec.describe Account do query = "select * from information_schema.sequences where sequence_name in ('camp_dpid_seq_#{account.id}', 'conv_dpid_seq_#{account.id}');" expect(ActiveRecord::Base.connection.execute(query).count).to eq(2) expect(account.locale).to eq('en') - account.destroy + account.destroy! expect(ActiveRecord::Base.connection.execute(query).count).to eq(0) end end diff --git a/spec/models/category_spec.rb b/spec/models/category_spec.rb index efe7fe036..70c7575eb 100644 --- a/spec/models/category_spec.rb +++ b/spec/models/category_spec.rb @@ -23,7 +23,7 @@ RSpec.describe Category do it 'returns erros when locale is not allowed in the portal' do category = create(:category, slug: 'category_1', locale: 'en', portal_id: portal.id) expect(category).to be_valid - category.update(locale: 'es') + expect(category.update(locale: 'es')).to be(false) expect(category.errors.full_messages[0]).to eq("Locale es of category is not part of portal's [\"en\"].") end end diff --git a/spec/models/channel/twilio_sms_spec.rb b/spec/models/channel/twilio_sms_spec.rb index 5f26eb706..3da078708 100644 --- a/spec/models/channel/twilio_sms_spec.rb +++ b/spec/models/channel/twilio_sms_spec.rb @@ -65,7 +65,7 @@ RSpec.describe Channel::TwilioSms do end it 'sends via twilio client' do - expect(twilio_messages).to receive(:create).with( + expect(twilio_messages).to receive(:create!).with( messaging_service_sid: channel.messaging_service_sid, to: '+15555550111', body: 'hello world', @@ -79,7 +79,7 @@ RSpec.describe Channel::TwilioSms do let(:channel) { create(:channel_twilio_sms, :with_phone_number) } it 'sends via twilio client' do - expect(twilio_messages).to receive(:create).with( + expect(twilio_messages).to receive(:create!).with( from: channel.phone_number, to: '+15555550111', body: 'hello world', @@ -92,7 +92,7 @@ RSpec.describe Channel::TwilioSms do context 'with media urls' do it 'supplies a media url' do - expect(twilio_messages).to receive(:create).with( + expect(twilio_messages).to receive(:create!).with( messaging_service_sid: channel.messaging_service_sid, to: '+15555550111', body: 'hello world', diff --git a/spec/models/concerns/assignment_handler_shared.rb b/spec/models/concerns/assignment_handler_shared.rb index 8447b8146..80f1b6f48 100644 --- a/spec/models/concerns/assignment_handler_shared.rb +++ b/spec/models/concerns/assignment_handler_shared.rb @@ -34,7 +34,7 @@ shared_examples_for 'assignment_handler' do it 'changes assignee to nil if they doesnt belong to the team and allow_auto_assign is false' do expect(team.allow_auto_assign).to be false - conversation.update(team: team) + conversation.update!(team: team) expect(conversation.reload.assignee).to be_nil end @@ -42,7 +42,7 @@ shared_examples_for 'assignment_handler' do it 'changes assignee to a team member if allow_auto_assign is enabled' do team.update!(allow_auto_assign: true) - conversation.update(team: team) + conversation.update!(team: team) expect(conversation.reload.assignee).to eq agent expect(Conversations::ActivityMessageJob).to(have_been_enqueued.at_least(:once) @@ -55,9 +55,9 @@ shared_examples_for 'assignment_handler' do assignee = create(:user, account: conversation.account, role: :agent) create(:inbox_member, user: assignee, inbox: conversation.inbox) create(:team_member, team: team, user: assignee) - conversation.update(assignee: assignee) + conversation.update!(assignee: assignee) - conversation.update(team: team) + conversation.update!(team: team) expect(conversation.reload.assignee).to eq assignee end diff --git a/spec/models/concerns/auto_assignment_handler_shared.rb b/spec/models/concerns/auto_assignment_handler_shared.rb index 90c9c9d20..5c93c051b 100644 --- a/spec/models/concerns/auto_assignment_handler_shared.rb +++ b/spec/models/concerns/auto_assignment_handler_shared.rb @@ -27,7 +27,7 @@ shared_examples_for 'auto_assignment_handler' do end it 'will not auto assign agent if enable_auto_assignment is false' do - inbox.update(enable_auto_assignment: false) + inbox.update!(enable_auto_assignment: false) expect(conversation.reload.assignee).to be_nil end diff --git a/spec/models/contact_inbox_spec.rb b/spec/models/contact_inbox_spec.rb index 23d4b7bc7..f4b50a3db 100644 --- a/spec/models/contact_inbox_spec.rb +++ b/spec/models/contact_inbox_spec.rb @@ -14,7 +14,7 @@ RSpec.describe ContactInbox do it 'does not get updated on object update' do obj = contact_inbox old_token = obj.pubsub_token - obj.update(source_id: '234234323') + obj.update!(source_id: '234234323') expect(obj.pubsub_token).to eq(old_token) end @@ -32,7 +32,7 @@ RSpec.describe ContactInbox do expect(results.first['pubsub_token']).to be_nil new_token = obj.pubsub_token - obj.update(source_id: '234234323') + obj.update!(source_id: '234234323') # the generated token shoul be persisted in db expect(obj.pubsub_token).to eq(new_token) end diff --git a/spec/models/conversation_spec.rb b/spec/models/conversation_spec.rb index 1938fb204..77ba4c27c 100644 --- a/spec/models/conversation_spec.rb +++ b/spec/models/conversation_spec.rb @@ -126,7 +126,7 @@ RSpec.describe Conversation do end it 'sends conversation updated event if labels are updated' do - conversation.update(label_list: [label.title]) + conversation.update!(label_list: [label.title]) changed_attributes = conversation.previous_changes expect(Rails.configuration.dispatcher).to have_received(:dispatch) .with( @@ -140,7 +140,7 @@ RSpec.describe Conversation do end it 'runs after_update callbacks' do - conversation.update( + conversation.update!( status: :resolved, contact_last_seen_at: Time.zone.now, assignee: new_assignee @@ -169,7 +169,7 @@ RSpec.describe Conversation do end it 'will not run conversation_updated event for non whitelisted keys' do - conversation.update(updated_at: DateTime.now.utc) + conversation.update!(updated_at: DateTime.now.utc) expect(Rails.configuration.dispatcher).not_to have_received(:dispatch) .with(described_class::CONVERSATION_UPDATED, kind_of(Time), conversation: conversation, notifiable_assignee_change: true) end @@ -191,7 +191,7 @@ RSpec.describe Conversation do end it 'creates conversation activities' do - conversation.update( + conversation.update!( status: :resolved, contact_last_seen_at: Time.zone.now, assignee: new_assignee, @@ -213,7 +213,7 @@ RSpec.describe Conversation do end it 'adds a message for system auto resolution if marked resolved by system' do - account.update(auto_resolve_duration: 40) + account.update!(auto_resolve_duration: 40) conversation2 = create(:conversation, status: 'open', account: account, assignee: old_assignee) Current.user = nil @@ -615,9 +615,9 @@ RSpec.describe Conversation do context 'when instagram channel' do it 'return true with HUMAN_AGENT if it is outside of 24 hour window' do - InstallationConfig.where(name: 'ENABLE_MESSENGER_CHANNEL_HUMAN_AGENT').first_or_create(value: true) + InstallationConfig.where(name: 'ENABLE_MESSENGER_CHANNEL_HUMAN_AGENT').first_or_create!(value: true) - conversation.update(additional_attributes: { type: 'instagram_direct_message' }) + conversation.update!(additional_attributes: { type: 'instagram_direct_message' }) create( :message, account: conversation.account, @@ -630,9 +630,9 @@ RSpec.describe Conversation do end it 'return false without HUMAN_AGENT if it is outside of 24 hour window' do - InstallationConfig.where(name: 'ENABLE_MESSENGER_CHANNEL_HUMAN_AGENT').first_or_create(value: false) + InstallationConfig.where(name: 'ENABLE_MESSENGER_CHANNEL_HUMAN_AGENT').first_or_create!(value: false) - conversation.update(additional_attributes: { type: 'instagram_direct_message' }) + conversation.update!(additional_attributes: { type: 'instagram_direct_message' }) create( :message, account: conversation.account, @@ -878,7 +878,7 @@ RSpec.describe Conversation do let(:conversation) { create(:conversation) } it 'returns the correct list of labels' do - conversation.update(label_list: %w[customer-support enterprise paid-customer]) + conversation.update!(label_list: %w[customer-support enterprise paid-customer]) expect(conversation.cached_label_list_array).to eq %w[customer-support enterprise paid-customer] end diff --git a/spec/models/inbox_spec.rb b/spec/models/inbox_spec.rb index 02d68d77a..73f40e916 100644 --- a/spec/models/inbox_spec.rb +++ b/spec/models/inbox_spec.rb @@ -226,7 +226,7 @@ RSpec.describe Inbox do it 'set portal id in inbox' do inbox.portal_id = portal.id - inbox.save + inbox.save! expect(inbox.portal).to eq(portal) end @@ -234,7 +234,7 @@ RSpec.describe Inbox do it 'sends the inbox_created event if ENABLE_INBOX_EVENTS is true' do with_modified_env ENABLE_INBOX_EVENTS: 'true' do channel = inbox.channel - channel.update(widget_color: '#fff') + channel.update!(widget_color: '#fff') expect(Rails.configuration.dispatcher).to have_received(:dispatch) .with( @@ -248,7 +248,7 @@ RSpec.describe Inbox do it 'sends the inbox_created event if ENABLE_INBOX_EVENTS is false' do channel = inbox.channel - channel.update(widget_color: '#fff') + channel.update!(widget_color: '#fff') expect(Rails.configuration.dispatcher).not_to have_received(:dispatch) .with( @@ -261,7 +261,7 @@ RSpec.describe Inbox do it 'resets cache key if there is an update in the channel' do channel = inbox.channel - channel.update(widget_color: '#fff') + channel.update!(widget_color: '#fff') expect(Rails.configuration.dispatcher).to have_received(:dispatch) .with( @@ -274,7 +274,7 @@ RSpec.describe Inbox do it 'updates the cache key after update' do expect(inbox.account).to receive(:update_cache_key).with('inbox') - inbox.update(name: 'New Name') + inbox.update!(name: 'New Name') end it 'updates the cache key after touch' do diff --git a/spec/models/label_spec.rb b/spec/models/label_spec.rb index ee5e7b108..ebe9a89f2 100644 --- a/spec/models/label_spec.rb +++ b/spec/models/label_spec.rb @@ -46,13 +46,13 @@ RSpec.describe Label do it 'calls update job' do expect(Labels::UpdateJob).to receive(:perform_later).with('new-title', label.title, label.account_id) - label.update(title: 'new-title') + label.update!(title: 'new-title') end it 'does not call update job if title is not updated' do expect(Labels::UpdateJob).not_to receive(:perform_later) - label.update(description: 'new-description') + label.update!(description: 'new-description') end end end diff --git a/spec/models/message_spec.rb b/spec/models/message_spec.rb index 4c66e37ee..fa4aca7fd 100644 --- a/spec/models/message_spec.rb +++ b/spec/models/message_spec.rb @@ -237,7 +237,7 @@ RSpec.describe Message do end it 'sets the waiting_since if there is an incoming message' do - conversation.update(waiting_since: nil) + conversation.update!(waiting_since: nil) message.message_type = :incoming message.save! diff --git a/spec/models/portal_spec.rb b/spec/models/portal_spec.rb index 1a108bbd6..02b675ef2 100644 --- a/spec/models/portal_spec.rb +++ b/spec/models/portal_spec.rb @@ -27,13 +27,13 @@ RSpec.describe Portal do end it 'Does not allow any other config than allowed_locales' do - portal.update(config: { 'some_other_key': 'test_value' }) + expect(portal.update(config: { 'some_other_key': 'test_value' })).to be(false) expect(portal).not_to be_valid - expect(portal.errors.full_messages[0]).to eq('Cofig in portal on some_other_key is not supported.') + expect(portal.errors.full_messages[0]).to eq('Config in portal on some_other_key is not supported.') end it 'converts empty string to nil' do - portal.update(custom_domain: '') + portal.update!(custom_domain: '') expect(portal.custom_domain).to be_nil end end diff --git a/spec/models/working_hour_spec.rb b/spec/models/working_hour_spec.rb index a5018a28e..b15ba71f7 100644 --- a/spec/models/working_hour_spec.rb +++ b/spec/models/working_hour_spec.rb @@ -56,7 +56,7 @@ RSpec.describe WorkingHour do before do Time.zone = 'UTC' - inbox.working_hours.find_by(day_of_week: 5).update(open_all_day: true) + inbox.working_hours.find_by(day_of_week: 5).update!(open_all_day: true) travel_to '18.02.2022 11:00'.to_datetime end @@ -74,7 +74,7 @@ RSpec.describe WorkingHour do before do Time.zone = 'UTC' - inbox.working_hours.find_by(day_of_week: 5).update(open_all_day: true) + inbox.working_hours.find_by(day_of_week: 5).update!(open_all_day: true) travel_to '18.02.2022 11:00'.to_datetime end @@ -94,7 +94,7 @@ RSpec.describe WorkingHour do before do Time.zone = 'Australia/Sydney' - inbox.update(timezone: 'Australia/Sydney') + inbox.update!(timezone: 'Australia/Sydney') travel_to '10.10.2022 9:00 AEDT' end diff --git a/spec/requests/api/v1/accounts/integrations/slack_request_spec.rb b/spec/requests/api/v1/accounts/integrations/slack_request_spec.rb index b3754bd1f..99ad56ab2 100644 --- a/spec/requests/api/v1/accounts/integrations/slack_request_spec.rb +++ b/spec/requests/api/v1/accounts/integrations/slack_request_spec.rb @@ -41,7 +41,7 @@ RSpec.describe 'Api::V1::Accounts::Integrations::Slacks' do context 'when it is an authenticated user' do it 'updates hook if the channel id is correct' do channel_builder = double - expect(channel_builder).to receive(:update).and_return(hook) + expect(channel_builder).to receive(:update_reference_id).and_return(hook) expect(Integrations::Slack::ChannelBuilder).to receive(:new).and_return(channel_builder) put "/api/v1/accounts/#{account.id}/integrations/slack", @@ -55,7 +55,7 @@ RSpec.describe 'Api::V1::Accounts::Integrations::Slacks' do it 'does not update the hook if the channel id is not correct' do channel_builder = double - expect(channel_builder).to receive(:update) + expect(channel_builder).to receive(:update_reference_id) expect(Integrations::Slack::ChannelBuilder).to receive(:new).and_return(channel_builder) put "/api/v1/accounts/#{account.id}/integrations/slack", diff --git a/spec/services/automation_rules/action_service_spec.rb b/spec/services/automation_rules/action_service_spec.rb index bdfa7af0c..5d7d25a2c 100644 --- a/spec/services/automation_rules/action_service_spec.rb +++ b/spec/services/automation_rules/action_service_spec.rb @@ -91,7 +91,7 @@ RSpec.describe AutomationRules::ActionService do describe '#perform with send_email_transcript action' do before do rule.actions << { action_name: 'send_email_transcript', action_params: ['contact@example.com, agent@example.com,agent1@example.com'] } - rule.save + rule.save! end it 'will send email to transcript to action params emails' do @@ -107,7 +107,7 @@ RSpec.describe AutomationRules::ActionService do it 'will send email to transcript to contacts' do rule.actions = [{ action_name: 'send_email_transcript', action_params: ['{{contact.email}}'] }] - rule.save + rule.save! mailer = double allow(ConversationReplyMailer).to receive(:with).and_return(mailer) diff --git a/spec/services/automation_rules/condition_validation_service_spec.rb b/spec/services/automation_rules/condition_validation_service_spec.rb index 36387754a..2fa777ed2 100644 --- a/spec/services/automation_rules/condition_validation_service_spec.rb +++ b/spec/services/automation_rules/condition_validation_service_spec.rb @@ -12,7 +12,7 @@ RSpec.describe AutomationRules::ConditionValidationService do { 'values': ['+918484'], 'attribute_key': 'phone_number', 'query_operator': 'OR', 'filter_operator': 'contains' }, { 'values': ['test'], 'attribute_key': 'email', 'query_operator': nil, 'filter_operator': 'contains' } ] - rule.save + rule.save # rubocop:disable Rails/SaveBang end it 'returns true' do @@ -25,7 +25,7 @@ RSpec.describe AutomationRules::ConditionValidationService do rule.conditions = [ { 'values': ['open'], 'attribute_key': 'not-a-standard-attribute-for-sure', 'query_operator': nil, 'filter_operator': 'equal_to' } ] - rule.save + rule.save # rubocop:disable Rails/SaveBang end it 'returns false' do @@ -38,7 +38,7 @@ RSpec.describe AutomationRules::ConditionValidationService do rule.conditions = [ { 'values': ['open'], 'attribute_key': 'status', 'query_operator': nil, 'filter_operator': 'not-a-filter-operator' } ] - rule.save + rule.save # rubocop:disable Rails/SaveBang end it 'returns false' do @@ -49,7 +49,7 @@ RSpec.describe AutomationRules::ConditionValidationService do context 'with wrong query operator' do before do rule.conditions = [{ 'values': ['open'], 'attribute_key': 'status', 'query_operator': 'invalid', 'filter_operator': 'attribute_changed' }] - rule.save + rule.save # rubocop:disable Rails/SaveBang end it 'returns false' do @@ -62,7 +62,7 @@ RSpec.describe AutomationRules::ConditionValidationService do rule.conditions = [ { 'values': ['open'], 'attribute_key': 'status', 'query_operator': nil, 'filter_operator': 'attribute_changed' } ] - rule.save + rule.save # rubocop:disable Rails/SaveBang end it 'returns true' do @@ -87,7 +87,7 @@ RSpec.describe AutomationRules::ConditionValidationService do 'custom_attribute_type': 'conversation_attribute' } ] - rule.save + rule.save # rubocop:disable Rails/SaveBang end it 'returns true' do @@ -105,7 +105,7 @@ RSpec.describe AutomationRules::ConditionValidationService do 'custom_attribute_type': 'conversation_attribute' } ] - rule.save + rule.save # rubocop:disable Rails/SaveBang end it 'returns false for missing custom attribute' do diff --git a/spec/services/automation_rules/conditions_filter_service_spec.rb b/spec/services/automation_rules/conditions_filter_service_spec.rb index ec9f52062..29434e3ac 100644 --- a/spec/services/automation_rules/conditions_filter_service_spec.rb +++ b/spec/services/automation_rules/conditions_filter_service_spec.rb @@ -12,7 +12,7 @@ RSpec.describe AutomationRules::ConditionsFilterService do before do conversation = create(:conversation, account: account) - conversation.contact.update(phone_number: '+918484828282', email: 'test@test.com') + conversation.contact.update!(phone_number: '+918484828282', email: 'test@test.com') create(:conversation, account: account) create(:conversation, account: account) end @@ -21,7 +21,7 @@ RSpec.describe AutomationRules::ConditionsFilterService do context 'when conditions based on filter_operator equal_to' do before do rule.conditions = [{ 'values': ['open'], 'attribute_key': 'status', 'query_operator': nil, 'filter_operator': 'equal_to' }] - rule.save + rule.save! end context 'when conditions in rule matches with object' do @@ -32,7 +32,7 @@ RSpec.describe AutomationRules::ConditionsFilterService do context 'when conditions in rule does not match with object' do it 'will return false' do - conversation.update(status: 'resolved') + conversation.update!(status: 'resolved') expect(described_class.new(rule, conversation, { changed_attributes: { status: %w[open resolved] } }).perform).to be(false) end end @@ -41,12 +41,12 @@ RSpec.describe AutomationRules::ConditionsFilterService do context 'when conditions based on filter_operator start_with' do before do contact = conversation.contact - contact.update(phone_number: '+918484848484') + contact.update!(phone_number: '+918484848484') rule.conditions = [ { 'values': ['+918484'], 'attribute_key': 'phone_number', 'query_operator': 'OR', 'filter_operator': 'starts_with' }, { 'values': ['test'], 'attribute_key': 'email', 'query_operator': nil, 'filter_operator': 'contains' } ] - rule.save + rule.save! end context 'when conditions in rule matches with object' do @@ -57,7 +57,7 @@ RSpec.describe AutomationRules::ConditionsFilterService do context 'when conditions in rule does not match with object' do it 'will return false' do - conversation.contact.update(phone_number: '+918585858585') + conversation.contact.update!(phone_number: '+918585858585') expect(described_class.new(rule, conversation, { changed_attributes: {} }).perform).to be(false) end end @@ -70,7 +70,7 @@ RSpec.describe AutomationRules::ConditionsFilterService do { 'values': ['test text'], 'attribute_key': 'content', 'query_operator': 'AND', 'filter_operator': 'equal_to' }, { 'values': ['incoming'], 'attribute_key': 'message_type', 'query_operator': nil, 'filter_operator': 'equal_to' } ] - rule.save + rule.save! end it 'will return true when conditions matches' do @@ -89,7 +89,7 @@ RSpec.describe AutomationRules::ConditionsFilterService do { 'values': ['help'], 'attribute_key': 'content', 'query_operator': 'AND', 'filter_operator': 'contains' }, { 'values': ['incoming'], 'attribute_key': 'message_type', 'query_operator': nil, 'filter_operator': 'equal_to' } ] - rule.save + rule.save! end let(:conversation) { create(:conversation, account: account, inbox: email_inbox) } @@ -105,7 +105,7 @@ RSpec.describe AutomationRules::ConditionsFilterService do end it 'will return false when processed_message_content does no match' do - rule.update(conditions: [{ 'values': ['text'], 'attribute_key': 'content', 'query_operator': nil, 'filter_operator': 'contains' }]) + rule.update!(conditions: [{ 'values': ['text'], 'attribute_key': 'content', 'query_operator': nil, 'filter_operator': 'contains' }]) expect(described_class.new(rule, conversation, { message: message, changed_attributes: {} }).perform).to be(false) end diff --git a/spec/services/contacts/filter_service_spec.rb b/spec/services/contacts/filter_service_spec.rb index 22882ae81..67c3d0b85 100644 --- a/spec/services/contacts/filter_service_spec.rb +++ b/spec/services/contacts/filter_service_spec.rb @@ -164,9 +164,9 @@ describe Contacts::FilterService do context 'with standard attributes - last_activity_at' do before do Time.zone = 'UTC' - el_contact.update(last_activity_at: (Time.zone.today - 4.days)) - cs_contact.update(last_activity_at: (Time.zone.today - 5.days)) - en_contact.update(last_activity_at: (Time.zone.today - 2.days)) + el_contact.update!(last_activity_at: (Time.zone.today - 4.days)) + cs_contact.update!(last_activity_at: (Time.zone.today - 5.days)) + en_contact.update!(last_activity_at: (Time.zone.today - 2.days)) end it 'filter by last_activity_at 3_days_before and custom_attributes' do diff --git a/spec/services/contacts/sync_attributes_spec.rb b/spec/services/contacts/sync_attributes_spec.rb index 447bcd740..4589758ec 100644 --- a/spec/services/contacts/sync_attributes_spec.rb +++ b/spec/services/contacts/sync_attributes_spec.rb @@ -16,7 +16,7 @@ RSpec.describe Contacts::SyncAttributes do context 'when contact has email or phone number' do it 'sets contact type to lead' do contact.email = 'test@test.com' - contact.save + contact.save! described_class.new(contact).perform expect(contact.reload.contact_type).to eq('lead') @@ -26,7 +26,7 @@ RSpec.describe Contacts::SyncAttributes do context 'when contact has social details' do it 'sets contact type to lead' do contact.additional_attributes['social_facebook_user_id'] = '123456789' - contact.save + contact.save! described_class.new(contact).perform expect(contact.reload.contact_type).to eq('lead') diff --git a/spec/services/google/refresh_oauth_token_service_spec.rb b/spec/services/google/refresh_oauth_token_service_spec.rb index be36e65a9..0a4487a4b 100644 --- a/spec/services/google/refresh_oauth_token_service_spec.rb +++ b/spec/services/google/refresh_oauth_token_service_spec.rb @@ -73,7 +73,7 @@ RSpec.describe Google::RefreshOauthTokenService do context 'when refresh token is not present in provider config and access token is expired' do it 'throws an error' do with_modified_env GOOGLE_OAUTH_CLIENT_ID: SecureRandom.uuid, GOOGLE_OAUTH_CLIENT_SECRET: SecureRandom.hex do - google_channel.update( + google_channel.update!( provider_config: { access_token: SecureRandom.hex, expires_on: Time.zone.now - 3600 diff --git a/spec/services/message_templates/hook_execution_service_spec.rb b/spec/services/message_templates/hook_execution_service_spec.rb index 9d9d82922..845d2605e 100644 --- a/spec/services/message_templates/hook_execution_service_spec.rb +++ b/spec/services/message_templates/hook_execution_service_spec.rb @@ -6,7 +6,7 @@ describe MessageTemplates::HookExecutionService do contact = create(:contact, email: nil) conversation = create(:conversation, contact: contact) # ensure greeting hook is enabled - conversation.inbox.update(greeting_enabled: true, enable_email_collect: true) + conversation.inbox.update!(greeting_enabled: true, enable_email_collect: true) email_collect_service = double @@ -27,7 +27,7 @@ describe MessageTemplates::HookExecutionService do contact = create(:contact, email: nil) conversation = create(:conversation, contact: contact) # ensure greeting hook is enabled - conversation.inbox.update(greeting_enabled: true, enable_email_collect: true) + conversation.inbox.update!(greeting_enabled: true, enable_email_collect: true) email_collect_service = double @@ -47,7 +47,7 @@ describe MessageTemplates::HookExecutionService do twitter_channel = create(:channel_twitter_profile) twitter_inbox = create(:inbox, channel: twitter_channel) # ensure greeting hook is enabled and greeting_message is present - twitter_inbox.update(greeting_enabled: true, greeting_message: 'Hi, this is a greeting message') + twitter_inbox.update!(greeting_enabled: true, greeting_message: 'Hi, this is a greeting message') conversation = create(:conversation, inbox: twitter_inbox, additional_attributes: { type: 'tweet' }) greeting_service = double @@ -65,7 +65,7 @@ describe MessageTemplates::HookExecutionService do conversation = create(:conversation, contact: contact) # ensure greeting hook is enabled and greeting_message is present - conversation.inbox.update(greeting_enabled: true, enable_email_collect: true, greeting_message: 'Hi, this is a greeting message') + conversation.inbox.update!(greeting_enabled: true, enable_email_collect: true, greeting_message: 'Hi, this is a greeting message') email_collect_service = double greeting_service = double @@ -99,9 +99,9 @@ describe MessageTemplates::HookExecutionService do contact = create(:contact, email: nil) conversation = create(:conversation, contact: contact) - conversation.inbox.update(enable_email_collect: false) + conversation.inbox.update!(enable_email_collect: false) # ensure prechat form is enabled - conversation.inbox.channel.update(pre_chat_form_enabled: true) + conversation.inbox.channel.update!(pre_chat_form_enabled: true) allow(MessageTemplates::Template::EmailCollect).to receive(:new).and_return(true) # described class gets called in message after commit @@ -122,7 +122,7 @@ describe MessageTemplates::HookExecutionService do end it 'calls ::MessageTemplates::Template::CsatSurvey when a conversation is resolved in an inbox with survey enabled' do - conversation.inbox.update(csat_survey_enabled: true) + conversation.inbox.update!(csat_survey_enabled: true) conversation.resolved! Conversations::ActivityMessageJob.perform_now(conversation, @@ -134,7 +134,7 @@ describe MessageTemplates::HookExecutionService do end it 'will not call ::MessageTemplates::Template::CsatSurvey when Csat is not enabled' do - conversation.inbox.update(csat_survey_enabled: false) + conversation.inbox.update!(csat_survey_enabled: false) conversation.resolved! Conversations::ActivityMessageJob.perform_now(conversation, @@ -149,7 +149,7 @@ describe MessageTemplates::HookExecutionService do twitter_channel = create(:channel_twitter_profile) twitter_inbox = create(:inbox, channel: twitter_channel) conversation = create(:conversation, inbox: twitter_inbox, additional_attributes: { type: 'tweet' }) - conversation.inbox.update(csat_survey_enabled: true) + conversation.inbox.update!(csat_survey_enabled: true) conversation.resolved! Conversations::ActivityMessageJob.perform_now(conversation, @@ -161,7 +161,7 @@ describe MessageTemplates::HookExecutionService do end it 'will not call ::MessageTemplates::Template::CsatSurvey if another Csat was already sent' do - conversation.inbox.update(csat_survey_enabled: true) + conversation.inbox.update!(csat_survey_enabled: true) conversation.messages.create!(message_type: 'outgoing', content_type: :input_csat, account: conversation.account, inbox: conversation.inbox) conversation.resolved! @@ -179,7 +179,7 @@ describe MessageTemplates::HookExecutionService do contact = create(:contact) conversation = create(:conversation, contact: contact) - conversation.inbox.update(working_hours_enabled: true, out_of_office_message: 'We are out of office') + conversation.inbox.update!(working_hours_enabled: true, out_of_office_message: 'We are out of office') conversation.inbox.working_hours.today.update!(closed_all_day: true) out_of_office_service = double @@ -198,7 +198,7 @@ describe MessageTemplates::HookExecutionService do contact = create(:contact) conversation = create(:conversation, contact: contact) - conversation.inbox.update(working_hours_enabled: true, out_of_office_message: 'We are out of office') + conversation.inbox.update!(working_hours_enabled: true, out_of_office_message: 'We are out of office') conversation.inbox.working_hours.today.update!(closed_all_day: true) create(:message, conversation: conversation, message_type: :outgoing, created_at: 2.minutes.ago) @@ -217,7 +217,7 @@ describe MessageTemplates::HookExecutionService do contact = create(:contact) conversation = create(:conversation, contact: contact) - conversation.inbox.update(working_hours_enabled: true, out_of_office_message: 'We are out of office') + conversation.inbox.update!(working_hours_enabled: true, out_of_office_message: 'We are out of office') conversation.inbox.working_hours.today.update!(closed_all_day: true) out_of_office_service = double @@ -235,7 +235,7 @@ describe MessageTemplates::HookExecutionService do it 'will not call ::MessageTemplates::Template::OutOfOffice if its a tweet conversation' do twitter_channel = create(:channel_twitter_profile) twitter_inbox = create(:inbox, channel: twitter_channel) - twitter_inbox.update(working_hours_enabled: true, out_of_office_message: 'We are out of office') + twitter_inbox.update!(working_hours_enabled: true, out_of_office_message: 'We are out of office') conversation = create(:conversation, inbox: twitter_inbox, additional_attributes: { type: 'tweet' }) diff --git a/spec/services/microsoft/refresh_oauth_token_service_spec.rb b/spec/services/microsoft/refresh_oauth_token_service_spec.rb index 346db70d8..917224794 100644 --- a/spec/services/microsoft/refresh_oauth_token_service_spec.rb +++ b/spec/services/microsoft/refresh_oauth_token_service_spec.rb @@ -73,7 +73,7 @@ RSpec.describe Microsoft::RefreshOauthTokenService do context 'when refresh token is not present in provider config and access token is expired' do it 'throws an error' do with_modified_env AZURE_APP_ID: SecureRandom.uuid, AZURE_APP_SECRET: SecureRandom.hex do - microsoft_channel.update( + microsoft_channel.update!( provider_config: { access_token: SecureRandom.hex, expires_on: Time.zone.now - 3600 diff --git a/spec/services/sms/incoming_message_service_spec.rb b/spec/services/sms/incoming_message_service_spec.rb index 5da56ff61..79d98c7f5 100644 --- a/spec/services/sms/incoming_message_service_spec.rb +++ b/spec/services/sms/incoming_message_service_spec.rb @@ -41,10 +41,10 @@ describe Sms::IncomingMessageService do end it 'reopen last conversation if last conversation is resolved and lock to single conversation is enabled' do - sms_channel.inbox.update(lock_to_single_conversation: true) + sms_channel.inbox.update!(lock_to_single_conversation: true) contact_inbox = create(:contact_inbox, inbox: sms_channel.inbox, source_id: params[:from]) last_conversation = create(:conversation, inbox: sms_channel.inbox, contact_inbox: contact_inbox) - last_conversation.update(status: 'resolved') + last_conversation.update!(status: 'resolved') described_class.new(inbox: sms_channel.inbox, params: params).perform # no new conversation should be created expect(sms_channel.inbox.conversations.count).to eq(1) @@ -53,10 +53,10 @@ describe Sms::IncomingMessageService do end it 'creates a new conversation if last conversation is resolved and lock to single conversation is disabled' do - sms_channel.inbox.update(lock_to_single_conversation: false) + sms_channel.inbox.update!(lock_to_single_conversation: false) contact_inbox = create(:contact_inbox, inbox: sms_channel.inbox, source_id: params[:from]) last_conversation = create(:conversation, inbox: sms_channel.inbox, contact_inbox: contact_inbox) - last_conversation.update(status: 'resolved') + last_conversation.update!(status: 'resolved') described_class.new(inbox: sms_channel.inbox, params: params).perform # new conversation should be created expect(sms_channel.inbox.conversations.count).to eq(2) @@ -65,10 +65,10 @@ describe Sms::IncomingMessageService do end it 'will not create a new conversation if last conversation is not resolved and lock to single conversation is disabled' do - sms_channel.inbox.update(lock_to_single_conversation: false) + sms_channel.inbox.update!(lock_to_single_conversation: false) contact_inbox = create(:contact_inbox, inbox: sms_channel.inbox, source_id: params[:from]) last_conversation = create(:conversation, inbox: sms_channel.inbox, contact_inbox: contact_inbox) - last_conversation.update(status: Conversation.statuses.except('resolved').keys.sample) + last_conversation.update!(status: Conversation.statuses.except('resolved').keys.sample) described_class.new(inbox: sms_channel.inbox, params: params).perform # new conversation should be created expect(sms_channel.inbox.conversations.count).to eq(1) diff --git a/spec/services/twilio/incoming_message_service_spec.rb b/spec/services/twilio/incoming_message_service_spec.rb index 5f4dcec69..4cc31db1b 100644 --- a/spec/services/twilio/incoming_message_service_spec.rb +++ b/spec/services/twilio/incoming_message_service_spec.rb @@ -104,8 +104,8 @@ describe Twilio::IncomingMessageService do Body: 'testing3' } - twilio_channel.inbox.update(lock_to_single_conversation: true) - conversation.update(status: 'resolved') + twilio_channel.inbox.update!(lock_to_single_conversation: true) + conversation.update!(status: 'resolved') described_class.new(params: params).perform # message appended to the last conversation expect(conversation.reload.messages.last.content).to eq('testing3') @@ -121,8 +121,8 @@ describe Twilio::IncomingMessageService do Body: 'testing3' } - twilio_channel.inbox.update(lock_to_single_conversation: false) - conversation.update(status: 'resolved') + twilio_channel.inbox.update!(lock_to_single_conversation: false) + conversation.update!(status: 'resolved') described_class.new(params: params).perform expect(twilio_channel.inbox.conversations.count).to eq(2) expect(twilio_channel.inbox.conversations.last.messages.last.content).to eq('testing3') @@ -137,8 +137,8 @@ describe Twilio::IncomingMessageService do Body: 'testing3' } - twilio_channel.inbox.update(lock_to_single_conversation: false) - conversation.update(status: Conversation.statuses.except('resolved').keys.sample) + twilio_channel.inbox.update!(lock_to_single_conversation: false) + conversation.update!(status: Conversation.statuses.except('resolved').keys.sample) described_class.new(params: params).perform expect(twilio_channel.inbox.conversations.count).to eq(1) expect(twilio_channel.inbox.conversations.last.messages.last.content).to eq('testing3') diff --git a/spec/services/twilio/oneoff_sms_campaign_service_spec.rb b/spec/services/twilio/oneoff_sms_campaign_service_spec.rb index f8858f174..74c5d1a9d 100644 --- a/spec/services/twilio/oneoff_sms_campaign_service_spec.rb +++ b/spec/services/twilio/oneoff_sms_campaign_service_spec.rb @@ -38,19 +38,19 @@ describe Twilio::OneoffSmsCampaignService do contact_with_label1.update_labels([label1.title]) contact_with_label2.update_labels([label2.title]) contact_with_both_labels.update_labels([label1.title, label2.title]) - expect(twilio_messages).to receive(:create).with( + expect(twilio_messages).to receive(:create!).with( body: campaign.message, messaging_service_sid: twilio_sms.messaging_service_sid, to: contact_with_label1.phone_number, status_callback: 'http://localhost:3000/twilio/delivery_status' ).once - expect(twilio_messages).to receive(:create).with( + expect(twilio_messages).to receive(:create!).with( body: campaign.message, messaging_service_sid: twilio_sms.messaging_service_sid, to: contact_with_label2.phone_number, status_callback: 'http://localhost:3000/twilio/delivery_status' ).once - expect(twilio_messages).to receive(:create).with( + expect(twilio_messages).to receive(:create!).with( body: campaign.message, messaging_service_sid: twilio_sms.messaging_service_sid, to: contact_with_both_labels.phone_number, diff --git a/spec/services/twilio/send_on_twilio_service_spec.rb b/spec/services/twilio/send_on_twilio_service_spec.rb index beae54b57..bbb26c582 100644 --- a/spec/services/twilio/send_on_twilio_service_spec.rb +++ b/spec/services/twilio/send_on_twilio_service_spec.rb @@ -53,7 +53,7 @@ describe Twilio::SendOnTwilioService do context 'with reply' do it 'if message is sent from chatwoot and is outgoing' do - allow(messages_double).to receive(:create).and_return(message_record_double) + allow(messages_double).to receive(:create!).and_return(message_record_double) allow(message_record_double).to receive(:sid).and_return('1234') outgoing_message = create( @@ -67,7 +67,7 @@ describe Twilio::SendOnTwilioService do it 'if outgoing message has attachment and is for whatsapp' do # check for message attachment url - allow(messages_double).to receive(:create).with(hash_including(media_url: [anything])).and_return(message_record_double) + allow(messages_double).to receive(:create!).with(hash_including(media_url: [anything])).and_return(message_record_double) allow(message_record_double).to receive(:sid).and_return('1234') message = build( @@ -78,12 +78,12 @@ describe Twilio::SendOnTwilioService do message.save! described_class.new(message: message).perform - expect(messages_double).to have_received(:create).with(hash_including(media_url: [anything])) + expect(messages_double).to have_received(:create!) end it 'if outgoing message has attachment and is for sms' do # check for message attachment url - allow(messages_double).to receive(:create).with(hash_including(media_url: [anything])).and_return(message_record_double) + allow(messages_double).to receive(:create!).with(hash_including(media_url: [anything])).and_return(message_record_double) allow(message_record_double).to receive(:sid).and_return('1234') message = build( @@ -94,11 +94,11 @@ describe Twilio::SendOnTwilioService do message.save! described_class.new(message: message).perform - expect(messages_double).to have_received(:create).with(hash_including(media_url: [anything])) + expect(messages_double).to have_received(:create!) end it 'if message is sent from chatwoot fails' do - allow(messages_double).to receive(:create).and_raise(Twilio::REST::TwilioError) + allow(messages_double).to receive(:create!).and_raise(Twilio::REST::TwilioError) outgoing_message = create( :message, message_type: 'outgoing', inbox: twilio_inbox, account: account, conversation: conversation diff --git a/spec/services/whatsapp/incoming_message_service_spec.rb b/spec/services/whatsapp/incoming_message_service_spec.rb index 0bcbf2a3e..e08b4b2dd 100644 --- a/spec/services/whatsapp/incoming_message_service_spec.rb +++ b/spec/services/whatsapp/incoming_message_service_spec.rb @@ -36,10 +36,10 @@ describe Whatsapp::IncomingMessageService do end it 'reopen last conversation if last conversation is resolved and lock to single conversation is enabled' do - whatsapp_channel.inbox.update(lock_to_single_conversation: true) + whatsapp_channel.inbox.update!(lock_to_single_conversation: true) contact_inbox = create(:contact_inbox, inbox: whatsapp_channel.inbox, source_id: params[:messages].first[:from]) last_conversation = create(:conversation, inbox: whatsapp_channel.inbox, contact_inbox: contact_inbox) - last_conversation.update(status: 'resolved') + last_conversation.update!(status: 'resolved') described_class.new(inbox: whatsapp_channel.inbox, params: params).perform # no new conversation should be created expect(whatsapp_channel.inbox.conversations.count).to eq(1) @@ -49,10 +49,10 @@ describe Whatsapp::IncomingMessageService do end it 'creates a new conversation if last conversation is resolved and lock to single conversation is disabled' do - whatsapp_channel.inbox.update(lock_to_single_conversation: false) + whatsapp_channel.inbox.update!(lock_to_single_conversation: false) contact_inbox = create(:contact_inbox, inbox: whatsapp_channel.inbox, source_id: params[:messages].first[:from]) last_conversation = create(:conversation, inbox: whatsapp_channel.inbox, contact_inbox: contact_inbox) - last_conversation.update(status: 'resolved') + last_conversation.update!(status: 'resolved') described_class.new(inbox: whatsapp_channel.inbox, params: params).perform # new conversation should be created expect(whatsapp_channel.inbox.conversations.count).to eq(2) @@ -60,10 +60,10 @@ describe Whatsapp::IncomingMessageService do end it 'will not create a new conversation if last conversation is not resolved and lock to single conversation is disabled' do - whatsapp_channel.inbox.update(lock_to_single_conversation: false) + whatsapp_channel.inbox.update!(lock_to_single_conversation: false) contact_inbox = create(:contact_inbox, inbox: whatsapp_channel.inbox, source_id: params[:messages].first[:from]) last_conversation = create(:conversation, inbox: whatsapp_channel.inbox, contact_inbox: contact_inbox) - last_conversation.update(status: Conversation.statuses.except('resolved').keys.sample) + last_conversation.update!(status: Conversation.statuses.except('resolved').keys.sample) described_class.new(inbox: whatsapp_channel.inbox, params: params).perform # new conversation should be created expect(whatsapp_channel.inbox.conversations.count).to eq(1)