chore: Enable the new Rubocop rules (#7122)

fixes: https://linear.app/chatwoot/issue/CW-1574/renable-the-disabled-rubocop-rules
This commit is contained in:
Sojan Jose
2023-05-19 14:37:10 +05:30
committed by GitHub
parent b988a01df3
commit 7ab7bac6bf
215 changed files with 609 additions and 608 deletions

View File

@@ -1,6 +1,6 @@
require 'rails_helper'
RSpec.describe AgentBotInbox, type: :model do
RSpec.describe AgentBotInbox do
describe 'validations' do
it { is_expected.to validate_presence_of(:inbox_id) }
it { is_expected.to validate_presence_of(:agent_bot_id) }

View File

@@ -2,7 +2,7 @@ require 'rails_helper'
require Rails.root.join 'spec/models/concerns/access_tokenable_shared.rb'
require Rails.root.join 'spec/models/concerns/avatarable_shared.rb'
RSpec.describe AgentBot, type: :model do
RSpec.describe AgentBot do
describe 'associations' do
it { is_expected.to have_many(:agent_bot_inboxes) }
it { is_expected.to have_many(:inboxes) }

View File

@@ -1,6 +1,6 @@
require 'rails_helper'
RSpec.describe Article, type: :model do
RSpec.describe Article do
let!(:account) { create(:account) }
let(:user) { create(:user, account_ids: [account.id], role: :agent) }
let!(:portal_1) { create(:portal, account_id: account.id, config: { allowed_locales: %w[en es] }) }

View File

@@ -1,12 +1,12 @@
require 'rails_helper'
RSpec.describe Attachment, type: :model do
RSpec.describe Attachment do
describe 'external url validations' do
let(:message) { create(:message) }
let(:attachment) { message.attachments.new(account_id: message.account_id, file_type: :image) }
before do
attachment.file.attach(io: File.open(Rails.root.join('spec/assets/avatar.png')), filename: 'avatar.png', content_type: 'image/png')
attachment.file.attach(io: Rails.root.join('spec/assets/avatar.png').open, filename: 'avatar.png', content_type: 'image/png')
end
context 'when it validates external url length' do
@@ -27,7 +27,7 @@ RSpec.describe Attachment, type: :model do
it 'returns valid download url' do
message = create(:message)
attachment = message.attachments.new(account_id: message.account_id, file_type: :image)
attachment.file.attach(io: File.open(Rails.root.join('spec/assets/avatar.png')), filename: 'avatar.png', content_type: 'image/png')
attachment.file.attach(io: Rails.root.join('spec/assets/avatar.png').open, filename: 'avatar.png', content_type: 'image/png')
expect(attachment.download_url).not_to be_nil
end
end

View File

@@ -1,6 +1,6 @@
require 'rails_helper'
RSpec.describe AutomationRule, type: :model do
RSpec.describe AutomationRule do
describe 'associations' do
let(:account) { create(:account) }
let(:params) do

View File

@@ -2,7 +2,7 @@
require 'rails_helper'
RSpec.describe Campaign, type: :model do
RSpec.describe Campaign do
describe 'associations' do
it { is_expected.to belong_to(:account) }
it { is_expected.to belong_to(:inbox) }

View File

@@ -1,6 +1,6 @@
require 'rails_helper'
RSpec.describe Category, type: :model do
RSpec.describe Category do
context 'with validations' do
it { is_expected.to validate_presence_of(:account_id) }
it { is_expected.to validate_presence_of(:name) }

View File

@@ -53,7 +53,7 @@ RSpec.describe Channel::Telegram do
it 'send image' do
telegram_attachment_response = double
attachment = message.attachments.new(account_id: message.account_id, file_type: :image)
attachment.file.attach(io: File.open(Rails.root.join('spec/assets/avatar.png')), filename: 'avatar.png', content_type: 'image/png')
attachment.file.attach(io: Rails.root.join('spec/assets/avatar.png').open, filename: 'avatar.png', content_type: 'image/png')
allow(telegram_attachment_response).to receive(:success?).and_return(true)
allow(telegram_attachment_response).to receive(:parsed_response).and_return({ 'result' => [{ 'message_id' => 'telegram_456' }] })
@@ -64,7 +64,7 @@ RSpec.describe Channel::Telegram do
it 'send document' do
telegram_attachment_response = double
attachment = message.attachments.new(account_id: message.account_id, file_type: :file)
attachment.file.attach(io: File.open(Rails.root.join('spec/assets/attachment.pdf')), filename: 'attachment.pdf',
attachment.file.attach(io: Rails.root.join('spec/assets/attachment.pdf').open, filename: 'attachment.pdf',
content_type: 'application/pdf')
allow(telegram_attachment_response).to receive(:success?).and_return(true)
@@ -82,7 +82,7 @@ RSpec.describe Channel::Telegram do
telegram_message_response = double
telegram_attachment_response = double
attachment = message.attachments.new(account_id: message.account_id, file_type: :image)
attachment.file.attach(io: File.open(Rails.root.join('spec/assets/avatar.png')), filename: 'avatar.png', content_type: 'image/png')
attachment.file.attach(io: Rails.root.join('spec/assets/avatar.png').open, filename: 'avatar.png', content_type: 'image/png')
allow(telegram_message_response).to receive(:success?).and_return(true)
allow(telegram_message_response).to receive(:parsed_response).and_return({ 'result' => { 'message_id' => 'telegram_456' } })

View File

@@ -60,7 +60,7 @@ RSpec.describe Channel::TwilioSms do
let(:twilio_messages) { double }
before do
allow(::Twilio::REST::Client).to receive(:new).and_return(twilio_client)
allow(Twilio::REST::Client).to receive(:new).and_return(twilio_client)
allow(twilio_client).to receive(:messages).and_return(twilio_messages)
end

View File

@@ -1,6 +1,6 @@
require 'rails_helper'
RSpec.describe ConversationParticipant, type: :model do
RSpec.describe ConversationParticipant do
context 'with validations' do
it { is_expected.to validate_presence_of(:account_id) }
it { is_expected.to validate_presence_of(:conversation_id) }

View File

@@ -4,7 +4,7 @@ require 'rails_helper'
require Rails.root.join 'spec/models/concerns/assignment_handler_shared.rb'
require Rails.root.join 'spec/models/concerns/auto_assignment_handler_shared.rb'
RSpec.describe Conversation, type: :model do
RSpec.describe Conversation do
describe 'associations' do
it { is_expected.to belong_to(:account) }
it { is_expected.to belong_to(:inbox) }

View File

@@ -1,6 +1,6 @@
require 'rails_helper'
RSpec.describe CsatSurveyResponse, type: :model do
RSpec.describe CsatSurveyResponse do
describe 'validations' do
it { is_expected.to validate_presence_of(:rating) }
it { is_expected.to validate_presence_of(:account_id) }

View File

@@ -1,6 +1,6 @@
require 'rails_helper'
RSpec.describe DataImport, type: :model do
RSpec.describe DataImport do
describe 'associations' do
it { is_expected.to belong_to(:account) }
end

View File

@@ -1,6 +1,6 @@
require 'rails_helper'
RSpec.describe Folder, type: :model do
RSpec.describe Folder do
context 'with validations' do
it { is_expected.to validate_presence_of(:account_id) }
it { is_expected.to validate_presence_of(:category_id) }

View File

@@ -14,6 +14,7 @@ RSpec.describe InboxMember do
perform_enqueued_jobs do
inbox_member.inbox.destroy!
end
expect { inbox_member.reload }.to raise_error(ActiveRecord::RecordNotFound)
end
end
end

View File

@@ -1,6 +1,6 @@
require 'rails_helper'
RSpec.describe Integrations::Hook, type: :model do
RSpec.describe Integrations::Hook do
context 'with validations' do
it { is_expected.to validate_presence_of(:app_id) }
it { is_expected.to validate_presence_of(:account_id) }

View File

@@ -1,6 +1,6 @@
require 'rails_helper'
RSpec.describe Label, type: :model do
RSpec.describe Label do
describe 'associations' do
it { is_expected.to belong_to(:account) }
end

View File

@@ -1,6 +1,6 @@
require 'rails_helper'
RSpec.describe Macro, type: :model do
RSpec.describe Macro do
let(:account) { create(:account) }
let(:admin) { create(:user, account: account, role: :administrator) }

View File

@@ -2,7 +2,7 @@
require 'rails_helper'
RSpec.describe Mention, type: :model do
RSpec.describe Mention do
describe 'associations' do
it { is_expected.to belong_to(:account) }
it { is_expected.to belong_to(:user) }

View File

@@ -3,7 +3,7 @@
require 'rails_helper'
require Rails.root.join 'spec/models/concerns/liquidable_shared.rb'
RSpec.describe Message, type: :model do
RSpec.describe Message do
context 'with validations' do
it { is_expected.to validate_presence_of(:inbox_id) }
it { is_expected.to validate_presence_of(:conversation_id) }
@@ -123,7 +123,7 @@ RSpec.describe Message, type: :model do
it 'contains the message attachment when attachment is present' do
message = create(:message)
attachment = message.attachments.new(account_id: message.account_id, file_type: :image)
attachment.file.attach(io: File.open(Rails.root.join('spec/assets/avatar.png')), filename: 'avatar.png', content_type: 'image/png')
attachment.file.attach(io: Rails.root.join('spec/assets/avatar.png').open, filename: 'avatar.png', content_type: 'image/png')
attachment.save!
expect(message.webhook_data.key?(:attachments)).to be true
end
@@ -148,12 +148,12 @@ RSpec.describe Message, type: :model do
it 'triggers ::MessageTemplates::HookExecutionService' do
hook_execution_service = double
allow(::MessageTemplates::HookExecutionService).to receive(:new).and_return(hook_execution_service)
allow(MessageTemplates::HookExecutionService).to receive(:new).and_return(hook_execution_service)
allow(hook_execution_service).to receive(:perform).and_return(true)
message.save!
expect(::MessageTemplates::HookExecutionService).to have_received(:new).with(message: message)
expect(MessageTemplates::HookExecutionService).to have_received(:new).with(message: message)
expect(hook_execution_service).to have_received(:perform)
end
@@ -213,7 +213,7 @@ RSpec.describe Message, type: :model do
it 'add errors to message for attachment size is more than allowed limit' do
16.times.each do
attachment = message.attachments.new(account_id: message.account_id, file_type: :image)
attachment.file.attach(io: File.open(Rails.root.join('spec/assets/avatar.png')), filename: 'avatar.png', content_type: 'image/png')
attachment.file.attach(io: Rails.root.join('spec/assets/avatar.png').open, filename: 'avatar.png', content_type: 'image/png')
end
expect(message.errors.messages).to eq({ attachments: ['exceeded maximum allowed'] })

View File

@@ -1,6 +1,6 @@
require 'rails_helper'
RSpec.describe Note, type: :model do
RSpec.describe Note do
describe 'validations' do
it { is_expected.to validate_presence_of(:content) }
it { is_expected.to validate_presence_of(:account_id) }

View File

@@ -1,6 +1,6 @@
require 'rails_helper'
RSpec.describe PortalMember, type: :model do
RSpec.describe PortalMember do
describe 'associations' do
it { is_expected.to belong_to(:portal) }
it { is_expected.to belong_to(:user) }

View File

@@ -1,6 +1,6 @@
require 'rails_helper'
RSpec.describe Portal, type: :model do
RSpec.describe Portal do
context 'with validations' do
it { is_expected.to validate_presence_of(:account_id) }
it { is_expected.to validate_presence_of(:slug) }

View File

@@ -1,6 +1,6 @@
require 'rails_helper'
RSpec.describe RelatedCategory, type: :model do
RSpec.describe RelatedCategory do
describe 'associations' do
it { is_expected.to belong_to(:category) }
it { is_expected.to belong_to(:related_category) }

View File

@@ -1,6 +1,6 @@
require 'rails_helper'
RSpec.describe ReportingEvent, type: :model do
RSpec.describe ReportingEvent do
describe 'validations' do
it { is_expected.to validate_presence_of(:account_id) }
it { is_expected.to validate_presence_of(:name) }

View File

@@ -1,6 +1,6 @@
require 'rails_helper'
RSpec.describe TeamMember, type: :model do
RSpec.describe TeamMember do
describe 'associations' do
it { is_expected.to belong_to(:team) }
it { is_expected.to belong_to(:user) }

View File

@@ -1,6 +1,6 @@
require 'rails_helper'
RSpec.describe Team, type: :model do
RSpec.describe Team do
describe 'associations' do
it { is_expected.to belong_to(:account) }
it { is_expected.to have_many(:conversations) }

View File

@@ -1,6 +1,6 @@
require 'rails_helper'
RSpec.describe Webhook, type: :model do
RSpec.describe Webhook do
describe 'validations' do
it { is_expected.to validate_presence_of(:account_id) }
end