chore: Use "create!" and "save!" bang methods when not checking the result (#5358)
* Use "create!" when not checking for errors on the result * Use "save!" when not checking the result
This commit is contained in:
parent
44f498be6d
commit
59b31615ed
30 changed files with 47 additions and 47 deletions
|
@ -25,7 +25,7 @@ class NotificationSubscriptionBuilder
|
|||
end
|
||||
|
||||
def build_identifier_subscription
|
||||
@identifier_subscription = user.notification_subscriptions.create(params.merge(identifier: identifier))
|
||||
@identifier_subscription = user.notification_subscriptions.create!(params.merge(identifier: identifier))
|
||||
end
|
||||
|
||||
def update_identifier_subscription
|
||||
|
|
|
@ -49,7 +49,7 @@ class Api::V1::Accounts::AutomationRulesController < Api::V1::Accounts::BaseCont
|
|||
def clone
|
||||
automation_rule = Current.account.automation_rules.find_by(id: params[:automation_rule_id])
|
||||
new_rule = automation_rule.dup
|
||||
new_rule.save
|
||||
new_rule.save!
|
||||
@automation_rule = new_rule
|
||||
end
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ class Api::V1::Accounts::Channels::TwilioChannelsController < Api::V1::Accounts:
|
|||
phone_number: phone_number,
|
||||
medium: medium
|
||||
)
|
||||
@inbox = Current.account.inboxes.create(
|
||||
@inbox = Current.account.inboxes.create!(
|
||||
name: permitted_params[:name],
|
||||
channel: @twilio_channel
|
||||
)
|
||||
|
|
|
@ -135,7 +135,7 @@ class Api::V1::Accounts::ContactsController < Api::V1::Accounts::BaseController
|
|||
|
||||
inbox = Current.account.inboxes.find(params[:inbox_id])
|
||||
source_id = params[:source_id] || SecureRandom.uuid
|
||||
ContactInbox.create(contact: @contact, inbox: inbox, source_id: source_id)
|
||||
ContactInbox.create!(contact: @contact, inbox: inbox, source_id: source_id)
|
||||
end
|
||||
|
||||
def permitted_params
|
||||
|
|
|
@ -9,7 +9,7 @@ class Api::V1::Widget::ConversationsController < Api::V1::Widget::BaseController
|
|||
ActiveRecord::Base.transaction do
|
||||
process_update_contact
|
||||
@conversation = create_conversation
|
||||
conversation.messages.create(message_params)
|
||||
conversation.messages.create!(message_params)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -59,7 +59,7 @@ class Api::V1::Widget::ConversationsController < Api::V1::Widget::BaseController
|
|||
|
||||
unless conversation.resolved?
|
||||
conversation.status = :resolved
|
||||
conversation.save
|
||||
conversation.save!
|
||||
end
|
||||
head :ok
|
||||
end
|
||||
|
|
|
@ -23,7 +23,7 @@ class DeviseOverrides::SessionsController < ::DeviseTokenAuth::SessionsControlle
|
|||
|
||||
def authenticate_resource_with_sso_token
|
||||
@token = @resource.create_token
|
||||
@resource.save
|
||||
@resource.save!
|
||||
|
||||
sign_in(:user, @resource, store: false, bypass: false)
|
||||
# invalidate the token after the user is signed in
|
||||
|
|
|
@ -44,12 +44,12 @@ class Twitter::CallbacksController < Twitter::BaseController
|
|||
end
|
||||
|
||||
def create_inbox
|
||||
twitter_profile = account.twitter_profiles.create(
|
||||
twitter_profile = account.twitter_profiles.create!(
|
||||
twitter_access_token: parsed_body['oauth_token'],
|
||||
twitter_access_token_secret: parsed_body['oauth_token_secret'],
|
||||
profile_id: parsed_body['user_id']
|
||||
)
|
||||
account.inboxes.create(
|
||||
account.inboxes.create!(
|
||||
name: parsed_body['screen_name'],
|
||||
channel: twitter_profile
|
||||
)
|
||||
|
|
|
@ -2,6 +2,6 @@ class Conversations::ActivityMessageJob < ApplicationJob
|
|||
queue_as :default
|
||||
|
||||
def perform(conversation, message_params)
|
||||
conversation.messages.create(message_params)
|
||||
conversation.messages.create!(message_params)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,7 +10,7 @@ class Conversations::UserMentionJob < ApplicationJob
|
|||
)
|
||||
|
||||
if mention.nil?
|
||||
Mention.create(
|
||||
Mention.create!(
|
||||
user_id: mentioned_user_id,
|
||||
conversation_id: conversation_id,
|
||||
mentioned_at: Time.zone.now,
|
||||
|
|
|
@ -16,7 +16,7 @@ class ReportingEventListener < BaseListener
|
|||
event_start_time: conversation.created_at,
|
||||
event_end_time: conversation.updated_at
|
||||
)
|
||||
reporting_event.save
|
||||
reporting_event.save!
|
||||
end
|
||||
|
||||
def first_reply_created(event)
|
||||
|
@ -39,6 +39,6 @@ class ReportingEventListener < BaseListener
|
|||
# rubocop:disable Rails/SkipsModelValidations
|
||||
conversation.update_columns(first_reply_created_at: message.created_at)
|
||||
# rubocop:enable Rails/SkipsModelValidations
|
||||
reporting_event.save
|
||||
reporting_event.save!
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,7 +4,7 @@ module MailboxHelper
|
|||
def create_message
|
||||
return if @conversation.messages.find_by(source_id: processed_mail.message_id).present?
|
||||
|
||||
@message = @conversation.messages.create(
|
||||
@message = @conversation.messages.create!(
|
||||
account_id: @conversation.account_id,
|
||||
sender: @conversation.contact,
|
||||
content: mail_content&.truncate(150_000),
|
||||
|
|
|
@ -39,7 +39,7 @@ class Channel::FacebookPage < ApplicationRecord
|
|||
def create_contact_inbox(instagram_id, name)
|
||||
ActiveRecord::Base.transaction do
|
||||
contact = inbox.account.contacts.create!(name: name)
|
||||
::ContactInbox.create(
|
||||
::ContactInbox.create!(
|
||||
contact_id: contact.id,
|
||||
inbox_id: inbox.id,
|
||||
source_id: instagram_id
|
||||
|
|
|
@ -30,7 +30,7 @@ class Line::IncomingMessageService
|
|||
def message_created?(event)
|
||||
return unless event_type_message?(event)
|
||||
|
||||
@message = @conversation.messages.create(
|
||||
@message = @conversation.messages.create!(
|
||||
content: event['message']['text'],
|
||||
account_id: @inbox.account_id,
|
||||
inbox_id: @inbox.id,
|
||||
|
|
|
@ -6,7 +6,7 @@ class Sms::IncomingMessageService
|
|||
def perform
|
||||
set_contact
|
||||
set_conversation
|
||||
@message = @conversation.messages.create(
|
||||
@message = @conversation.messages.create!(
|
||||
content: params[:text],
|
||||
account_id: @inbox.account_id,
|
||||
inbox_id: @inbox.id,
|
||||
|
|
|
@ -12,7 +12,7 @@ class Telegram::IncomingMessageService
|
|||
set_contact
|
||||
update_contact_avatar
|
||||
set_conversation
|
||||
@message = @conversation.messages.create(
|
||||
@message = @conversation.messages.create!(
|
||||
content: params[:message][:text].presence || params[:message][:caption],
|
||||
account_id: @inbox.account_id,
|
||||
inbox_id: @inbox.id,
|
||||
|
|
|
@ -8,7 +8,7 @@ class Twilio::IncomingMessageService
|
|||
|
||||
set_contact
|
||||
set_conversation
|
||||
@message = @conversation.messages.create(
|
||||
@message = @conversation.messages.create!(
|
||||
content: params[:Body],
|
||||
account_id: @inbox.account_id,
|
||||
inbox_id: @inbox.id,
|
||||
|
|
|
@ -7,7 +7,7 @@ class Twitter::DirectMessageParserService < Twitter::WebhooksBaseService
|
|||
set_inbox
|
||||
ensure_contacts
|
||||
set_conversation
|
||||
@message = @conversation.messages.create(
|
||||
@message = @conversation.messages.create!(
|
||||
content: message_create_data['message_data']['text'],
|
||||
account_id: @inbox.account_id,
|
||||
inbox_id: @inbox.id,
|
||||
|
@ -30,7 +30,7 @@ class Twitter::DirectMessageParserService < Twitter::WebhooksBaseService
|
|||
def save_media_urls(file)
|
||||
@message.content_attributes[:media_url] = file['media_url']
|
||||
@message.content_attributes[:display_url] = file['display_url']
|
||||
@message.save
|
||||
@message.save!
|
||||
end
|
||||
|
||||
def direct_message_events_params
|
||||
|
@ -121,6 +121,6 @@ class Twitter::DirectMessageParserService < Twitter::WebhooksBaseService
|
|||
content_type: media['type']
|
||||
}
|
||||
)
|
||||
@message.save
|
||||
@message.save!
|
||||
end
|
||||
end
|
||||
|
|
|
@ -80,7 +80,7 @@ class Twitter::TweetParserService < Twitter::WebhooksBaseService
|
|||
def create_message
|
||||
find_or_create_contact(user)
|
||||
set_conversation
|
||||
@conversation.messages.create(
|
||||
@conversation.messages.create!(
|
||||
account_id: @inbox.account_id,
|
||||
sender: @contact,
|
||||
content: tweet_text,
|
||||
|
|
|
@ -7,7 +7,7 @@ class ChatwootHub
|
|||
|
||||
def self.installation_identifier
|
||||
identifier = InstallationConfig.find_by(name: 'INSTALLATION_IDENTIFIER')&.value
|
||||
identifier ||= InstallationConfig.create(name: 'INSTALLATION_IDENTIFIER', value: SecureRandom.uuid).value
|
||||
identifier ||= InstallationConfig.create!(name: 'INSTALLATION_IDENTIFIER', value: SecureRandom.uuid).value
|
||||
identifier
|
||||
end
|
||||
|
||||
|
|
|
@ -84,7 +84,7 @@ class Integrations::Csml::ProcessorService < Integrations::BotProcessorService
|
|||
end
|
||||
|
||||
def process_text_messages(message_payload, conversation)
|
||||
conversation.messages.create(
|
||||
conversation.messages.create!(
|
||||
{
|
||||
message_type: :outgoing,
|
||||
account_id: conversation.account_id,
|
||||
|
@ -99,7 +99,7 @@ class Integrations::Csml::ProcessorService < Integrations::BotProcessorService
|
|||
buttons = message_payload['content']['buttons'].map do |button|
|
||||
{ title: button['content']['title'], value: button['content']['payload'] }
|
||||
end
|
||||
conversation.messages.create(
|
||||
conversation.messages.create!(
|
||||
{
|
||||
message_type: :outgoing,
|
||||
account_id: conversation.account_id,
|
||||
|
|
|
@ -43,10 +43,10 @@ class Integrations::Dialogflow::ProcessorService < Integrations::BotProcessorSer
|
|||
return if content_params.blank?
|
||||
|
||||
conversation = message.conversation
|
||||
conversation.messages.create(content_params.merge({
|
||||
message_type: :outgoing,
|
||||
account_id: conversation.account_id,
|
||||
inbox_id: conversation.inbox_id
|
||||
}))
|
||||
conversation.messages.create!(content_params.merge({
|
||||
message_type: :outgoing,
|
||||
account_id: conversation.account_id,
|
||||
inbox_id: conversation.inbox_id
|
||||
}))
|
||||
end
|
||||
end
|
||||
|
|
|
@ -83,7 +83,7 @@ class Integrations::Slack::IncomingMessageBuilder
|
|||
def create_message
|
||||
return unless conversation
|
||||
|
||||
@message = conversation.messages.create(
|
||||
@message = conversation.messages.create!(
|
||||
message_type: :outgoing,
|
||||
account_id: conversation.account_id,
|
||||
inbox_id: conversation.inbox_id,
|
||||
|
|
|
@ -26,7 +26,7 @@ RSpec.describe '/api/v1/widget/labels', type: :request do
|
|||
|
||||
context 'with correct website token and a defined label' do
|
||||
before do
|
||||
account.labels.create(title: 'customer-support')
|
||||
account.labels.create!(title: 'customer-support')
|
||||
end
|
||||
|
||||
it 'add the label to the conversation' do
|
||||
|
|
|
@ -43,7 +43,7 @@ describe AutomationRuleListener do
|
|||
])
|
||||
file = fixture_file_upload(Rails.root.join('spec/assets/avatar.png'), 'image/png')
|
||||
automation_rule.files.attach(file)
|
||||
automation_rule.save
|
||||
automation_rule.save!
|
||||
end
|
||||
|
||||
describe '#conversation_updated with contacts attributes' do
|
||||
|
|
|
@ -19,7 +19,7 @@ RSpec.describe ReplyMailbox, type: :mailbox do
|
|||
before do
|
||||
# this UUID is hardcoded in the reply.eml, that's why we are updating this
|
||||
conversation.uuid = '6bdc3f4d-0bec-4515-a284-5d916fdde489'
|
||||
conversation.save
|
||||
conversation.save!
|
||||
|
||||
described_subject
|
||||
end
|
||||
|
@ -129,7 +129,7 @@ RSpec.describe ReplyMailbox, type: :mailbox do
|
|||
before do
|
||||
# this UUID is hardcoded in the reply.eml, that's why we are updating this
|
||||
conversation.uuid = '6bdc3f4d-0bec-4515-a284-5d916fdde489'
|
||||
conversation.save
|
||||
conversation.save!
|
||||
end
|
||||
|
||||
it 'add the mail content as new message on the conversation' do
|
||||
|
|
|
@ -32,7 +32,7 @@ RSpec.describe SupportMailbox, type: :mailbox do
|
|||
before do
|
||||
# this email is hardcoded in the support.eml, that's why we are updating this
|
||||
channel_email.email = 'care@example.com'
|
||||
channel_email.save
|
||||
channel_email.save!
|
||||
end
|
||||
|
||||
describe 'covers email address format' do
|
||||
|
@ -121,7 +121,7 @@ RSpec.describe SupportMailbox, type: :mailbox do
|
|||
before do
|
||||
# this email is hardcoded eml fixture file that's why we are updating this
|
||||
channel_email.email = 'support@chatwoot.com'
|
||||
channel_email.save
|
||||
channel_email.save!
|
||||
end
|
||||
|
||||
it 'create new contact with original sender' do
|
||||
|
|
|
@ -54,15 +54,15 @@ RSpec.describe ConversationReplyMailer, type: :mailer do
|
|||
|
||||
it 'renders the subject in conversation as reply' do
|
||||
conversation.additional_attributes = { 'mail_subject': 'Mail Subject' }
|
||||
conversation.save
|
||||
new_message.save
|
||||
conversation.save!
|
||||
new_message.save!
|
||||
expect(mail.subject).to eq('Re: Mail Subject')
|
||||
end
|
||||
|
||||
it 'not have private notes' do
|
||||
# make the message private
|
||||
private_message.private = true
|
||||
private_message.save
|
||||
private_message.save!
|
||||
|
||||
expect(mail.body.decoded).not_to include(private_message.content)
|
||||
expect(mail.body.decoded).to include(message.content)
|
||||
|
@ -104,7 +104,7 @@ RSpec.describe ConversationReplyMailer, type: :mailer do
|
|||
let(:mail) { described_class.reply_without_summary(message_2.conversation, message_2.id).deliver_now }
|
||||
|
||||
before do
|
||||
message_2.save
|
||||
message_2.save!
|
||||
end
|
||||
|
||||
it 'renders the default subject' do
|
||||
|
@ -113,14 +113,14 @@ RSpec.describe ConversationReplyMailer, type: :mailer do
|
|||
|
||||
it 'renders the subject in conversation' do
|
||||
conversation.additional_attributes = { 'mail_subject': 'Mail Subject' }
|
||||
conversation.save
|
||||
conversation.save!
|
||||
expect(mail.subject).to eq('Mail Subject')
|
||||
end
|
||||
|
||||
it 'not have private notes' do
|
||||
# make the message private
|
||||
private_message.private = true
|
||||
private_message.save
|
||||
private_message.save!
|
||||
expect(mail.body.decoded).not_to include(private_message.content)
|
||||
end
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ RSpec.describe Campaign, type: :model do
|
|||
let(:campaign) { build(:campaign, inbox: website_inbox, display_id: nil, trigger_rules: { url: 'https://test.com' }) }
|
||||
|
||||
before do
|
||||
campaign.save
|
||||
campaign.save!
|
||||
campaign.reload
|
||||
end
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ RSpec.describe Conversation, type: :model do
|
|||
let(:conversation) { build(:conversation, display_id: nil) }
|
||||
|
||||
before do
|
||||
conversation.save
|
||||
conversation.save!
|
||||
conversation.reload
|
||||
end
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ RSpec.describe ConversationReplyEmailWorker, type: :worker do
|
|||
end
|
||||
|
||||
it 'calls ConversationSummaryMailer#reply_without_summary when last incoming message was from email' do
|
||||
message.save
|
||||
message.save!
|
||||
described_class.new.perform(1, message.id)
|
||||
expect(mailer).to have_received(:reply_without_summary)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue