diff --git a/app/services/twilio/send_on_twilio_service.rb b/app/services/twilio/send_on_twilio_service.rb index d2fe5719b..e4d787ef5 100644 --- a/app/services/twilio/send_on_twilio_service.rb +++ b/app/services/twilio/send_on_twilio_service.rb @@ -37,7 +37,7 @@ class Twilio::SendOnTwilioService < Base::SendOnChannelService # Add messaging service or from number send_params = send_params.merge(channel.send(:send_message_from)) - channel.send(:client).messages.create(**send_params) + channel.send(:client).messages.create!(**send_params) end def template_params diff --git a/enterprise/app/builders/saml_user_builder.rb b/enterprise/app/builders/saml_user_builder.rb index 97a287462..b4f7a439a 100644 --- a/enterprise/app/builders/saml_user_builder.rb +++ b/enterprise/app/builders/saml_user_builder.rb @@ -42,7 +42,7 @@ class SamlUserBuilder full_name = [auth_attribute('first_name'), auth_attribute('last_name')].compact.join(' ') fallback_name = auth_attribute('name') || auth_attribute('email').split('@').first - User.create( + User.create!( email: auth_attribute('email'), name: (full_name.presence || fallback_name), display_name: auth_attribute('first_name'), @@ -58,13 +58,13 @@ class SamlUserBuilder return unless account # Create account_user if not exists - account_user = AccountUser.find_or_create_by( + account_user = AccountUser.find_or_create_by!( user: @user, account: account ) # Set default role as agent if not set - account_user.update(role: 'agent') if account_user.role.blank? + account_user.update!(role: 'agent') if account_user.role.blank? # Handle role mappings if configured apply_role_mappings(account_user, account) @@ -75,9 +75,9 @@ class SamlUserBuilder return unless matching_mapping if matching_mapping['role'] - account_user.update(role: matching_mapping['role']) + account_user.update!(role: matching_mapping['role']) elsif matching_mapping['custom_role_id'] - account_user.update(custom_role_id: matching_mapping['custom_role_id']) + account_user.update!(custom_role_id: matching_mapping['custom_role_id']) end end diff --git a/enterprise/app/services/twilio/voice_webhook_setup_service.rb b/enterprise/app/services/twilio/voice_webhook_setup_service.rb index c1da2f24a..88e91274f 100644 --- a/enterprise/app/services/twilio/voice_webhook_setup_service.rb +++ b/enterprise/app/services/twilio/voice_webhook_setup_service.rb @@ -26,7 +26,7 @@ class Twilio::VoiceWebhookSetupService def create_twiml_app! friendly_name = "Chatwoot Voice #{channel.phone_number}" - app = api_key_client.applications.create( + app = api_key_client.applications.create!( friendly_name: friendly_name, voice_url: channel.voice_call_webhook_url, voice_method: HTTP_METHOD @@ -46,7 +46,7 @@ class Twilio::VoiceWebhookSetupService api_key_client .incoming_phone_numbers(numbers.first.sid) - .update( + .update!( voice_url: channel.voice_call_webhook_url, voice_method: HTTP_METHOD, status_callback: channel.voice_status_webhook_url, diff --git a/spec/enterprise/models/account_saml_settings_spec.rb b/spec/enterprise/models/account_saml_settings_spec.rb index ac35eb486..49456a521 100644 --- a/spec/enterprise/models/account_saml_settings_spec.rb +++ b/spec/enterprise/models/account_saml_settings_spec.rb @@ -127,7 +127,7 @@ RSpec.describe AccountSamlSettings, type: :model do it 'queues job to reset account users provider' do settings = create(:account_saml_settings, account: account) expect(Saml::UpdateAccountUsersProviderJob).to receive(:perform_later).with(account.id, 'email') - settings.destroy + settings.destroy! end end end diff --git a/spec/enterprise/models/agent_capacity_policy_spec.rb b/spec/enterprise/models/agent_capacity_policy_spec.rb index 231e85423..f97e15184 100644 --- a/spec/enterprise/models/agent_capacity_policy_spec.rb +++ b/spec/enterprise/models/agent_capacity_policy_spec.rb @@ -22,7 +22,7 @@ RSpec.describe AgentCapacityPolicy, type: :model do account_user = user.account_users.first account_user.update!(agent_capacity_policy: policy) - policy.destroy + policy.destroy! expect(account_user.reload.agent_capacity_policy).to be_nil end end diff --git a/spec/jobs/avatar/avatar_from_url_job_spec.rb b/spec/jobs/avatar/avatar_from_url_job_spec.rb index 8db3769ad..bf00654b3 100644 --- a/spec/jobs/avatar/avatar_from_url_job_spec.rb +++ b/spec/jobs/avatar/avatar_from_url_job_spec.rb @@ -24,7 +24,7 @@ RSpec.describe Avatar::AvatarFromUrlJob do it 'returns early when rate limited' do ts = 30.seconds.ago.iso8601 - avatarable.update(additional_attributes: { 'last_avatar_sync_at' => ts }) + avatarable.update!(additional_attributes: { 'last_avatar_sync_at' => ts }) expect(Down).not_to receive(:download) described_class.perform_now(avatarable, valid_url) avatarable.reload @@ -36,7 +36,7 @@ RSpec.describe Avatar::AvatarFromUrlJob do end it 'returns early when hash unchanged' do - avatarable.update(additional_attributes: { 'avatar_url_hash' => Digest::SHA256.hexdigest(valid_url) }) + avatarable.update!(additional_attributes: { 'avatar_url_hash' => Digest::SHA256.hexdigest(valid_url) }) expect(Down).not_to receive(:download) described_class.perform_now(avatarable, valid_url) expect(avatarable.avatar).not_to be_attached diff --git a/spec/jobs/inboxes/bulk_auto_assignment_job_spec.rb b/spec/jobs/inboxes/bulk_auto_assignment_job_spec.rb index 5e7e3d7cc..3ad12d488 100644 --- a/spec/jobs/inboxes/bulk_auto_assignment_job_spec.rb +++ b/spec/jobs/inboxes/bulk_auto_assignment_job_spec.rb @@ -47,7 +47,7 @@ RSpec.describe Inboxes::BulkAutoAssignmentJob do context 'when account is on default plan in chatwoot cloud' do before do account.update!(custom_attributes: {}) - InstallationConfig.create(name: 'CHATWOOT_CLOUD_PLANS', value: [{ 'name' => 'default' }]) + InstallationConfig.create!(name: 'CHATWOOT_CLOUD_PLANS', value: [{ 'name' => 'default' }]) allow(ChatwootApp).to receive(:chatwoot_cloud?).and_return(true) end diff --git a/spec/services/automation_rules/action_service_spec.rb b/spec/services/automation_rules/action_service_spec.rb index 85678ca66..294ad3ced 100644 --- a/spec/services/automation_rules/action_service_spec.rb +++ b/spec/services/automation_rules/action_service_spec.rb @@ -121,7 +121,7 @@ RSpec.describe AutomationRules::ActionService do describe '#perform with add_label action' do before do rule.actions << { action_name: 'add_label', action_params: %w[bug feature] } - rule.save + rule.save! end it 'will add labels to conversation' do @@ -141,7 +141,7 @@ RSpec.describe AutomationRules::ActionService do before do conversation.add_labels(%w[bug feature support]) rule.actions << { action_name: 'remove_label', action_params: %w[bug feature] } - rule.save + rule.save! end it 'will remove specified labels from conversation' do diff --git a/spec/services/automation_rules/conditions_filter_service_spec.rb b/spec/services/automation_rules/conditions_filter_service_spec.rb index 71b8212aa..ea3394960 100644 --- a/spec/services/automation_rules/conditions_filter_service_spec.rb +++ b/spec/services/automation_rules/conditions_filter_service_spec.rb @@ -145,7 +145,7 @@ RSpec.describe AutomationRules::ConditionsFilterService do rule.conditions = [ { 'values': ['bug'], 'attribute_key': 'labels', 'query_operator': nil, 'filter_operator': 'equal_to' } ] - rule.save + rule.save! end it 'will return true when conversation has the label' do @@ -156,7 +156,7 @@ RSpec.describe AutomationRules::ConditionsFilterService do rule.conditions = [ { 'values': ['feature'], 'attribute_key': 'labels', 'query_operator': nil, 'filter_operator': 'equal_to' } ] - rule.save + rule.save! expect(described_class.new(rule, conversation, { changed_attributes: {} }).perform).to be(false) end end @@ -166,7 +166,7 @@ RSpec.describe AutomationRules::ConditionsFilterService do rule.conditions = [ { 'values': ['feature'], 'attribute_key': 'labels', 'query_operator': nil, 'filter_operator': 'not_equal_to' } ] - rule.save + rule.save! end it 'will return true when conversation does not have the label' do @@ -184,7 +184,7 @@ RSpec.describe AutomationRules::ConditionsFilterService do rule.conditions = [ { 'values': [], 'attribute_key': 'labels', 'query_operator': nil, 'filter_operator': 'is_present' } ] - rule.save + rule.save! end it 'will return true when conversation has any labels' do @@ -202,7 +202,7 @@ RSpec.describe AutomationRules::ConditionsFilterService do rule.conditions = [ { 'values': [], 'attribute_key': 'labels', 'query_operator': nil, 'filter_operator': 'is_not_present' } ] - rule.save + rule.save! end it 'will return false when conversation has any labels' do