diff --git a/.rubocop.yml b/.rubocop.yml index 70c927242..914308551 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -162,41 +162,33 @@ Rails/RenderInline: Performance/CollectionLiteralInLoop: Exclude: - 'db/migrate/20210315101919_enable_email_channel.rb' -RSpec/NamedSubject: - Enabled: false -Style/RedundantConstantBase: - Enabled: false -Rails/RootPathnameMethods: - Enabled: false -RSpec/Rails/MinitestAssertions: - Enabled: false -RSpec/Rails/InferredSpecType: - Enabled: false +Rails/ThreeStateBooleanColumn: + Exclude: + - 'db/migrate/20200509044639_add_hide_input_flag_to_bot_config.rb' + - 'db/migrate/20200605130625_agent_away_message_to_auto_reply.rb' + - 'db/migrate/20200606132552_create_labels.rb' + - 'db/migrate/20201027135006_create_working_hours.rb' + - 'db/migrate/20210112174124_add_hmac_token_to_inbox.rb' + - 'db/migrate/20210114202310_create_teams.rb' + - 'db/migrate/20210212154240_add_request_for_email_on_channel_web_widget.rb' + - 'db/migrate/20210428135041_add_campaigns.rb' + - 'db/migrate/20210602182058_add_hmac_to_api_channel.rb' + - 'db/migrate/20210609133433_add_email_collect_to_inboxes.rb' + - 'db/migrate/20210618095823_add_csat_toggle_for_inbox.rb' + - 'db/migrate/20210927062350_add_trigger_only_during_business_hours_collect_to_campaigns.rb' + - 'db/migrate/20211027073553_add_imap_smtp_config_to_channel_email.rb' + - 'db/migrate/20211109143122_add_tweet_enabled_flag_to_twitter_channel.rb' + - 'db/migrate/20211216110209_add_allow_messages_after_resolved_to_inbox.rb' + - 'db/migrate/20220116103902_add_open_ssl_verify_mode_to_channel_email.rb' + - 'db/migrate/20220216151613_add_open_all_day_to_working_hour.rb' + - 'db/migrate/20220511072655_add_archive_column_to_portal.rb' + - 'db/migrate/20230503101201_create_sla_policies.rb' RSpec/IndexedLet: Enabled: false -RSpec/MatchArray: - Enabled: false -Rails/ResponseParsedBody: - Enabled: false -RSpec/FactoryBot/ConsistentParenthesesStyle: - Enabled: false -Rails/ThreeStateBooleanColumn: - Enabled: false -Rails/Pluck: - Enabled: false -Rails/TopLevelHashWithIndifferentAccess: - Enabled: false -Rails/ActionOrder: - Enabled: false -Style/ArrayIntersect: - Enabled: false -RSpec/NoExpectationExample: - Enabled: false -Style/RedundantReturn: - Enabled: false -Rails/I18nLocaleTexts: +RSpec/NamedSubject: Enabled: false + # we should bring this down RSpec/MultipleMemoizedHelpers: Max: 14 diff --git a/app/controllers/api/v1/accounts/articles_controller.rb b/app/controllers/api/v1/accounts/articles_controller.rb index cc0976375..a1e348723 100644 --- a/app/controllers/api/v1/accounts/articles_controller.rb +++ b/app/controllers/api/v1/accounts/articles_controller.rb @@ -16,6 +16,9 @@ class Api::V1::Accounts::ArticlesController < Api::V1::Accounts::BaseController end end + def show; end + def edit; end + def create @article = @portal.articles.create!(article_params) @article.associate_root_article(article_params[:associated_article_id]) @@ -23,10 +26,6 @@ class Api::V1::Accounts::ArticlesController < Api::V1::Accounts::BaseController render json: { error: @article.errors.messages }, status: :unprocessable_entity and return unless @article.valid? end - def edit; end - - def show; end - def update @article.update!(article_params) if params[:article].present? render json: { error: @article.errors.messages }, status: :unprocessable_entity and return unless @article.valid? diff --git a/app/controllers/api/v1/accounts/automation_rules_controller.rb b/app/controllers/api/v1/accounts/automation_rules_controller.rb index 0bb78d3ea..3431af9c3 100644 --- a/app/controllers/api/v1/accounts/automation_rules_controller.rb +++ b/app/controllers/api/v1/accounts/automation_rules_controller.rb @@ -6,6 +6,8 @@ class Api::V1::Accounts::AutomationRulesController < Api::V1::Accounts::BaseCont @automation_rules = Current.account.automation_rules end + def show; end + def create @automation_rule = Current.account.automation_rules.new(automation_rules_permit) @automation_rule.actions = params[:actions] @@ -28,8 +30,6 @@ class Api::V1::Accounts::AutomationRulesController < Api::V1::Accounts::BaseCont render json: { blob_key: file_blob.key, blob_id: file_blob.id } end - def show; end - def update ActiveRecord::Base.transaction do automation_rule_update diff --git a/app/controllers/api/v1/accounts/campaigns_controller.rb b/app/controllers/api/v1/accounts/campaigns_controller.rb index 6d2fb7729..b1a132246 100644 --- a/app/controllers/api/v1/accounts/campaigns_controller.rb +++ b/app/controllers/api/v1/accounts/campaigns_controller.rb @@ -6,21 +6,21 @@ class Api::V1::Accounts::CampaignsController < Api::V1::Accounts::BaseController @campaigns = Current.account.campaigns end + def show; end + def create @campaign = Current.account.campaigns.create!(campaign_params) end + def update + @campaign.update!(campaign_params) + end + def destroy @campaign.destroy! head :ok end - def show; end - - def update - @campaign.update!(campaign_params) - end - private def campaign diff --git a/app/controllers/api/v1/accounts/categories_controller.rb b/app/controllers/api/v1/accounts/categories_controller.rb index e28e601d5..73fc5d885 100644 --- a/app/controllers/api/v1/accounts/categories_controller.rb +++ b/app/controllers/api/v1/accounts/categories_controller.rb @@ -9,6 +9,8 @@ class Api::V1::Accounts::CategoriesController < Api::V1::Accounts::BaseControlle @categories = @portal.categories.search(params) end + def show; end + def create @category = @portal.categories.create!(category_params) @category.related_categories << related_categories_records @@ -17,8 +19,6 @@ class Api::V1::Accounts::CategoriesController < Api::V1::Accounts::BaseControlle @category.save! end - def show; end - def update @category.update!(category_params) @category.related_categories = related_categories_records if related_categories_records.any? diff --git a/app/controllers/api/v1/accounts/contacts/notes_controller.rb b/app/controllers/api/v1/accounts/contacts/notes_controller.rb index 7bc9dd121..58ba935db 100644 --- a/app/controllers/api/v1/accounts/contacts/notes_controller.rb +++ b/app/controllers/api/v1/accounts/contacts/notes_controller.rb @@ -5,21 +5,21 @@ class Api::V1::Accounts::Contacts::NotesController < Api::V1::Accounts::Contacts @notes = @contact.notes.latest.includes(:user) end + def show; end + def create @note = @contact.notes.create!(note_params) end + def update + @note.update(note_params) + end + def destroy @note.destroy! head :ok end - def show; end - - def update - @note.update(note_params) - end - private def note diff --git a/app/controllers/api/v1/accounts/conversations_controller.rb b/app/controllers/api/v1/accounts/conversations_controller.rb index ebd673d6f..1f3fbae0b 100644 --- a/app/controllers/api/v1/accounts/conversations_controller.rb +++ b/app/controllers/api/v1/accounts/conversations_controller.rb @@ -26,6 +26,8 @@ class Api::V1::Accounts::ConversationsController < Api::V1::Accounts::BaseContro @attachments = @conversation.attachments end + def show; end + def create ActiveRecord::Base.transaction do @conversation = ConversationBuilder.new(params: params, contact_inbox: @contact_inbox).perform @@ -33,8 +35,6 @@ class Api::V1::Accounts::ConversationsController < Api::V1::Accounts::BaseContro end end - def show; end - def filter result = ::Conversations::FilterService.new(params.permit!, current_user).perform @conversations = result[:conversations] diff --git a/app/controllers/api/v1/accounts/inbox_members_controller.rb b/app/controllers/api/v1/accounts/inbox_members_controller.rb index 22726a855..0cb1a0c85 100644 --- a/app/controllers/api/v1/accounts/inbox_members_controller.rb +++ b/app/controllers/api/v1/accounts/inbox_members_controller.rb @@ -2,6 +2,11 @@ class Api::V1::Accounts::InboxMembersController < Api::V1::Accounts::BaseControl before_action :fetch_inbox before_action :current_agents_ids, only: [:create, :update] + def show + authorize @inbox, :show? + fetch_updated_agents + end + def create authorize @inbox, :create? ActiveRecord::Base.transaction do @@ -10,11 +15,6 @@ class Api::V1::Accounts::InboxMembersController < Api::V1::Accounts::BaseControl fetch_updated_agents end - def show - authorize @inbox, :show? - fetch_updated_agents - end - def update authorize @inbox, :update? update_agents_list diff --git a/app/controllers/api/v1/accounts/macros_controller.rb b/app/controllers/api/v1/accounts/macros_controller.rb index a13d74995..604e053f1 100644 --- a/app/controllers/api/v1/accounts/macros_controller.rb +++ b/app/controllers/api/v1/accounts/macros_controller.rb @@ -6,6 +6,10 @@ class Api::V1::Accounts::MacrosController < Api::V1::Accounts::BaseController @macros = Macro.with_visibility(current_user, params) end + def show + head :not_found if @macro.nil? + end + def create @macro = Current.account.macros.new(macros_with_user.merge(created_by_id: current_user.id)) @macro.set_visibility(current_user, permitted_params) @@ -18,8 +22,16 @@ class Api::V1::Accounts::MacrosController < Api::V1::Accounts::BaseController @macro end - def show - head :not_found if @macro.nil? + def update + ActiveRecord::Base.transaction do + @macro.update!(macros_with_user) + @macro.set_visibility(current_user, permitted_params) + process_attachments + @macro.save! + rescue StandardError => e + Rails.logger.error e + render json: { error: @macro.errors.messages }.to_json, status: :unprocessable_entity + end end def destroy @@ -37,18 +49,6 @@ class Api::V1::Accounts::MacrosController < Api::V1::Accounts::BaseController render json: { blob_key: file_blob.key, blob_id: file_blob.id } end - def update - ActiveRecord::Base.transaction do - @macro.update!(macros_with_user) - @macro.set_visibility(current_user, permitted_params) - process_attachments - @macro.save! - rescue StandardError => e - Rails.logger.error e - render json: { error: @macro.errors.messages }.to_json, status: :unprocessable_entity - end - end - def execute ::MacrosExecutionJob.perform_later(@macro, conversation_ids: params[:conversation_ids], user: Current.user) diff --git a/app/controllers/api/v1/accounts_controller.rb b/app/controllers/api/v1/accounts_controller.rb index af48ccdf3..5af8a1fd1 100644 --- a/app/controllers/api/v1/accounts_controller.rb +++ b/app/controllers/api/v1/accounts_controller.rb @@ -14,6 +14,11 @@ class Api::V1::AccountsController < Api::BaseController CustomExceptions::Account::UserErrors, with: :render_error_response + def show + @latest_chatwoot_version = ::Redis::Alfred.get(::Redis::Alfred::LATEST_CHATWOOT_VERSION) + render 'api/v1/accounts/show', format: :json + end + def create @user, @account = AccountBuilder.new( account_name: account_params[:account_name], @@ -35,11 +40,6 @@ class Api::V1::AccountsController < Api::BaseController render json: { cache_keys: get_cache_keys }, status: :ok end - def show - @latest_chatwoot_version = ::Redis::Alfred.get(::Redis::Alfred::LATEST_CHATWOOT_VERSION) - render 'api/v1/accounts/show', format: :json - end - def update @account.update!(account_params.slice(:name, :locale, :domain, :support_email, :auto_resolve_duration)) end diff --git a/app/controllers/devise_overrides/passwords_controller.rb b/app/controllers/devise_overrides/passwords_controller.rb index 06092c5ab..26a9d4555 100644 --- a/app/controllers/devise_overrides/passwords_controller.rb +++ b/app/controllers/devise_overrides/passwords_controller.rb @@ -4,6 +4,16 @@ class DeviseOverrides::PasswordsController < Devise::PasswordsController skip_before_action :require_no_authentication, raise: false skip_before_action :authenticate_user!, raise: false + def create + @user = User.find_by(email: params[:email]) + if @user + @user.send_reset_password_instructions + build_response(I18n.t('messages.reset_password_success'), 200) + else + build_response(I18n.t('messages.reset_password_failure'), 404) + end + end + def update # params: reset_password_token, password, password_confirmation original_token = params[:reset_password_token] @@ -17,16 +27,6 @@ class DeviseOverrides::PasswordsController < Devise::PasswordsController end end - def create - @user = User.find_by(email: params[:email]) - if @user - @user.send_reset_password_instructions - build_response(I18n.t('messages.reset_password_success'), 200) - else - build_response(I18n.t('messages.reset_password_failure'), 404) - end - end - private def reset_password_and_confirmation(recoverable) diff --git a/app/controllers/devise_overrides/sessions_controller.rb b/app/controllers/devise_overrides/sessions_controller.rb index 831c41ddc..ace47a8b5 100644 --- a/app/controllers/devise_overrides/sessions_controller.rb +++ b/app/controllers/devise_overrides/sessions_controller.rb @@ -1,4 +1,4 @@ -class DeviseOverrides::SessionsController < ::DeviseTokenAuth::SessionsController +class DeviseOverrides::SessionsController < DeviseTokenAuth::SessionsController # Prevent session parameter from being passed # Unpermitted parameter: session wrap_parameters format: [] diff --git a/app/controllers/devise_overrides/token_validations_controller.rb b/app/controllers/devise_overrides/token_validations_controller.rb index 64b7949ac..432aa7752 100644 --- a/app/controllers/devise_overrides/token_validations_controller.rb +++ b/app/controllers/devise_overrides/token_validations_controller.rb @@ -1,4 +1,4 @@ -class DeviseOverrides::TokenValidationsController < ::DeviseTokenAuth::TokenValidationsController +class DeviseOverrides::TokenValidationsController < DeviseTokenAuth::TokenValidationsController def validate_token # @resource will have been set by set_user_by_token concern if @resource diff --git a/app/controllers/platform/api/v1/accounts_controller.rb b/app/controllers/platform/api/v1/accounts_controller.rb index 1ea7d4954..9e6d53fef 100644 --- a/app/controllers/platform/api/v1/accounts_controller.rb +++ b/app/controllers/platform/api/v1/accounts_controller.rb @@ -1,12 +1,12 @@ class Platform::Api::V1::AccountsController < PlatformController + def show; end + def create @resource = Account.create!(account_params) update_resource_features @platform_app.platform_app_permissibles.find_or_create_by(permissible: @resource) end - def show; end - def update @resource.assign_attributes(account_params) update_resource_features diff --git a/app/controllers/platform/api/v1/agent_bots_controller.rb b/app/controllers/platform/api/v1/agent_bots_controller.rb index 0c79e118d..138052b77 100644 --- a/app/controllers/platform/api/v1/agent_bots_controller.rb +++ b/app/controllers/platform/api/v1/agent_bots_controller.rb @@ -6,14 +6,14 @@ class Platform::Api::V1::AgentBotsController < PlatformController @resources = @platform_app.platform_app_permissibles.where(permissible_type: 'AgentBot').all end + def show; end + def create @resource = AgentBot.new(agent_bot_params) @resource.save! @platform_app.platform_app_permissibles.find_or_create_by(permissible: @resource) end - def show; end - def update @resource.update!(agent_bot_params) end diff --git a/app/controllers/platform/api/v1/users_controller.rb b/app/controllers/platform/api/v1/users_controller.rb index e0de74da1..03ed55754 100644 --- a/app/controllers/platform/api/v1/users_controller.rb +++ b/app/controllers/platform/api/v1/users_controller.rb @@ -5,6 +5,8 @@ class Platform::Api::V1::UsersController < PlatformController before_action(only: [:login]) { set_resource } before_action(only: [:login]) { validate_platform_app_permissible } + def show; end + def create @resource = (User.find_by(email: user_params[:email]) || User.new(user_params)) @resource.skip_confirmation! @@ -16,8 +18,6 @@ class Platform::Api::V1::UsersController < PlatformController render json: { url: @resource.generate_sso_link } end - def show; end - def update @resource.assign_attributes(user_update_params) diff --git a/app/controllers/public/api/v1/inboxes/contacts_controller.rb b/app/controllers/public/api/v1/inboxes/contacts_controller.rb index b3ebd4ade..835c2596b 100644 --- a/app/controllers/public/api/v1/inboxes/contacts_controller.rb +++ b/app/controllers/public/api/v1/inboxes/contacts_controller.rb @@ -2,6 +2,8 @@ class Public::Api::V1::Inboxes::ContactsController < Public::Api::V1::InboxesCon before_action :contact_inbox, except: [:create] before_action :process_hmac + def show; end + def create source_id = params[:source_id] || SecureRandom.uuid @contact_inbox = ::ContactInboxWithContactBuilder.new( @@ -11,8 +13,6 @@ class Public::Api::V1::Inboxes::ContactsController < Public::Api::V1::InboxesCon ).perform end - def show; end - def update contact_identify_action = ContactIdentifyAction.new( contact: @contact_inbox.contact, diff --git a/app/controllers/super_admin/accounts_controller.rb b/app/controllers/super_admin/accounts_controller.rb index 112357363..6a5fb0fdc 100644 --- a/app/controllers/super_admin/accounts_controller.rb +++ b/app/controllers/super_admin/accounts_controller.rb @@ -45,13 +45,17 @@ class SuperAdmin::AccountsController < SuperAdmin::ApplicationController def seed Internal::SeedAccountJob.perform_later(requested_resource) + # rubocop:disable Rails/I18nLocaleTexts redirect_back(fallback_location: [namespace, requested_resource], notice: 'Account seeding triggered') + # rubocop:enable Rails/I18nLocaleTexts end def destroy account = Account.find(params[:id]) DeleteObjectJob.perform_later(account) if account.present? + # rubocop:disable Rails/I18nLocaleTexts redirect_back(fallback_location: [namespace, requested_resource], notice: 'Account deletion is in progress.') + # rubocop:enable Rails/I18nLocaleTexts end end diff --git a/app/controllers/swagger_controller.rb b/app/controllers/swagger_controller.rb index 697f04ed0..af5a4b039 100644 --- a/app/controllers/swagger_controller.rb +++ b/app/controllers/swagger_controller.rb @@ -1,7 +1,7 @@ class SwaggerController < ApplicationController def respond if Rails.env.development? || Rails.env.test? - render inline: File.read(Rails.root.join('swagger', derived_path)) + render inline: Rails.root.join('swagger', derived_path).read else head :not_found end diff --git a/app/models/concerns/featurable.rb b/app/models/concerns/featurable.rb index 5e6b8b8db..daa0b4bf6 100644 --- a/app/models/concerns/featurable.rb +++ b/app/models/concerns/featurable.rb @@ -6,7 +6,7 @@ module Featurable check_for_column: false }.freeze - FEATURE_LIST = YAML.safe_load(File.read(Rails.root.join('config/features.yml'))).freeze + FEATURE_LIST = YAML.safe_load(Rails.root.join('config/features.yml').read).freeze FEATURES = FEATURE_LIST.each_with_object({}) do |feature, result| result[result.keys.size + 1] = "feature_#{feature['name']}".to_sym @@ -46,7 +46,7 @@ module Featurable end def all_features - FEATURE_LIST.map { |f| f['name'] }.index_with do |feature_name| + FEATURE_LIST.pluck('name').index_with do |feature_name| feature_enabled?(feature_name) end end diff --git a/app/models/conversation.rb b/app/models/conversation.rb index becb0a639..668d96d52 100644 --- a/app/models/conversation.rb +++ b/app/models/conversation.rb @@ -233,8 +233,8 @@ class Conversation < ApplicationRecord def allowed_keys? ( - (previous_changes.keys & %w[team_id assignee_id status snoozed_until custom_attributes label_list first_reply_created_at priority]).present? || - (previous_changes['additional_attributes'].present? && (previous_changes['additional_attributes'][1].keys & %w[conversation_language]).present?) + previous_changes.keys.intersect?(%w[team_id assignee_id status snoozed_until custom_attributes label_list first_reply_created_at priority]) || + (previous_changes['additional_attributes'].present? && previous_changes['additional_attributes'][1].keys.intersect?(%w[conversation_language])) ) end diff --git a/app/models/installation_config.rb b/app/models/installation_config.rb index f0e2ca4f1..f1603e4ca 100644 --- a/app/models/installation_config.rb +++ b/app/models/installation_config.rb @@ -19,7 +19,7 @@ class InstallationConfig < ApplicationRecord # https://discuss.rubyonrails.org/t/cve-2022-32224-possible-rce-escalation-bug-with-serialized-columns-in-active-record/81017 # FIX ME : fixes breakage of installation config. we need to migrate. # Fix configuration in application.rb - serialize :serialized_value, HashWithIndifferentAccess + serialize :serialized_value, ActiveSupport::HashWithIndifferentAccess before_validation :set_lock validates :name, presence: true diff --git a/config/initializers/actioncable.rb b/config/initializers/actioncable.rb index 937ea83b8..3d1c90e75 100644 --- a/config/initializers/actioncable.rb +++ b/config/initializers/actioncable.rb @@ -11,5 +11,5 @@ ActionCable::SubscriptionAdapter::Redis.redis_connector = lambda do |config| # https://gitlab.com/gitlab-org/gitlab/-/merge_requests/75173 # https://github.com/rails/rails/blob/4a23cb3415eac03d76623112576559a722d1f23d/actioncable/lib/action_cable/subscription_adapter/base.rb#L30 config[:id] = nil if ENV['REDIS_DISABLE_CLIENT_COMMAND'].present? - ::Redis.new(config.except(:adapter, :channel_prefix)) + Redis.new(config.except(:adapter, :channel_prefix)) end diff --git a/db/migrate/20230202132107_install_audited.rb b/db/migrate/20230202132107_install_audited.rb index 7c9f1dd54..a59afc0b9 100644 --- a/db/migrate/20230202132107_install_audited.rb +++ b/db/migrate/20230202132107_install_audited.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class InstallAudited < ActiveRecord::Migration[6.1] - # rubocop:disable RMetrics/MethodLength + # rubocop:disable Metrics/MethodLength def self.up create_table :audits, :force => true do |t| t.bigint :auditable_id @@ -19,7 +19,7 @@ class InstallAudited < ActiveRecord::Migration[6.1] t.string :request_uuid t.datetime :created_at end - # rubocop:enable RMetrics/MethodLength + # rubocop:enable Metrics/MethodLength add_index :audits, [:auditable_type, :auditable_id, :version], :name => 'auditable_index' add_index :audits, [:associated_type, :associated_id], :name => 'associated_index' diff --git a/db/seeds.rb b/db/seeds.rb index 1afe3d025..f260f32a7 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -5,7 +5,7 @@ ConfigLoader.new.process ## Seeds productions if Rails.env.production? # Setup Onboarding flow - ::Redis::Alfred.set(::Redis::Alfred::CHATWOOT_INSTALLATION_ONBOARDING, true) + Redis::Alfred.set(Redis::Alfred::CHATWOOT_INSTALLATION_ONBOARDING, true) end ## Seeds for Local Development @@ -46,7 +46,7 @@ unless Rails.env.production? inbox = Inbox.create!(channel: web_widget, account: account, name: 'Acme Support') InboxMember.create!(user: user, inbox: inbox) - contact_inbox = ::ContactInboxWithContactBuilder.new( + contact_inbox = ContactInboxWithContactBuilder.new( source_id: user.id, inbox: inbox, hmac_verified: true, diff --git a/lib/custom_exceptions/base.rb b/lib/custom_exceptions/base.rb index 3076b8847..9032d4bab 100644 --- a/lib/custom_exceptions/base.rb +++ b/lib/custom_exceptions/base.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class CustomExceptions::Base < ::StandardError +class CustomExceptions::Base < StandardError def to_hash { message: message diff --git a/lib/seeders/account_seeder.rb b/lib/seeders/account_seeder.rb index db8d31c37..49e611ab5 100644 --- a/lib/seeders/account_seeder.rb +++ b/lib/seeders/account_seeder.rb @@ -12,7 +12,7 @@ class Seeders::AccountSeeder def initialize(account:) raise 'Account Seeding is not allowed.' unless ENV.fetch('ENABLE_ACCOUNT_SEEDING', !Rails.env.production?) - @account_data = HashWithIndifferentAccess.new(YAML.safe_load(File.read(Rails.root.join('lib/seeders/seed_data.yml')))) + @account_data = ActiveSupport::HashWithIndifferentAccess.new(YAML.safe_load(Rails.root.join('lib/seeders/seed_data.yml').read)) @account = account end diff --git a/spec/actions/contact_identify_action_spec.rb b/spec/actions/contact_identify_action_spec.rb index 64f81ef8f..baf935f61 100644 --- a/spec/actions/contact_identify_action_spec.rb +++ b/spec/actions/contact_identify_action_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe ::ContactIdentifyAction do +describe ContactIdentifyAction do subject(:contact_identify) { described_class.new(contact: contact, params: params).perform } let!(:account) { create(:account) } diff --git a/spec/actions/contact_merge_action_spec.rb b/spec/actions/contact_merge_action_spec.rb index 147dabe41..de207498a 100644 --- a/spec/actions/contact_merge_action_spec.rb +++ b/spec/actions/contact_merge_action_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe ::ContactMergeAction do +describe ContactMergeAction do subject(:contact_merge) { described_class.new(account: account, base_contact: base_contact, mergee_contact: mergee_contact).perform } let!(:account) { create(:account) } diff --git a/spec/builders/campaigns/campaign_conversation_builder_spec.rb b/spec/builders/campaigns/campaign_conversation_builder_spec.rb index 03a392912..8f08cf0c0 100644 --- a/spec/builders/campaigns/campaign_conversation_builder_spec.rb +++ b/spec/builders/campaigns/campaign_conversation_builder_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe ::Campaigns::CampaignConversationBuilder do +describe Campaigns::CampaignConversationBuilder do let(:account) { create(:account) } let(:inbox) { create(:inbox, account: account) } let(:contact) { create(:contact, account: account, identifier: '123') } diff --git a/spec/builders/contact_inbox_builder_spec.rb b/spec/builders/contact_inbox_builder_spec.rb index 46b0d749c..1dda58063 100644 --- a/spec/builders/contact_inbox_builder_spec.rb +++ b/spec/builders/contact_inbox_builder_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe ::ContactInboxBuilder do +describe ContactInboxBuilder do let(:account) { create(:account) } let(:contact) { create(:contact, email: 'xyc@example.com', phone_number: '+23423424123', account: account) } diff --git a/spec/builders/contact_inbox_with_contact_builder_spec.rb b/spec/builders/contact_inbox_with_contact_builder_spec.rb index e76d199d4..8efeae9a5 100644 --- a/spec/builders/contact_inbox_with_contact_builder_spec.rb +++ b/spec/builders/contact_inbox_with_contact_builder_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe ::ContactInboxWithContactBuilder do +describe ContactInboxWithContactBuilder do let(:account) { create(:account) } let(:inbox) { create(:inbox, account: account) } let(:contact) { create(:contact, email: 'xyc@example.com', phone_number: '+23423424123', account: account, identifier: '123') } diff --git a/spec/builders/conversation_builder_spec.rb b/spec/builders/conversation_builder_spec.rb index f0e0ada06..956aec966 100644 --- a/spec/builders/conversation_builder_spec.rb +++ b/spec/builders/conversation_builder_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe ::ConversationBuilder do +describe ConversationBuilder do let(:account) { create(:account) } let!(:sms_channel) { create(:channel_sms, account: account) } let!(:sms_inbox) { create(:inbox, channel: sms_channel, account: account) } diff --git a/spec/builders/csat_surveys/response_builder_spec.rb b/spec/builders/csat_surveys/response_builder_spec.rb index 9356e6369..8ec4e4a23 100644 --- a/spec/builders/csat_surveys/response_builder_spec.rb +++ b/spec/builders/csat_surveys/response_builder_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe ::CsatSurveys::ResponseBuilder do +describe CsatSurveys::ResponseBuilder do let(:message) do create( :message, content_type: :input_csat, diff --git a/spec/builders/messages/facebook/message_builder_spec.rb b/spec/builders/messages/facebook/message_builder_spec.rb index 082510f7b..8219adaa7 100644 --- a/spec/builders/messages/facebook/message_builder_spec.rb +++ b/spec/builders/messages/facebook/message_builder_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe ::Messages::Facebook::MessageBuilder do +describe Messages::Facebook::MessageBuilder do subject(:message_builder) { described_class.new(incoming_fb_text_message, facebook_channel.inbox).perform } before do diff --git a/spec/builders/messages/instagram/message_builder_spec.rb b/spec/builders/messages/instagram/message_builder_spec.rb index 3eaa5c25b..b7dfddc8e 100644 --- a/spec/builders/messages/instagram/message_builder_spec.rb +++ b/spec/builders/messages/instagram/message_builder_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe ::Messages::Instagram::MessageBuilder do +describe Messages::Instagram::MessageBuilder do subject(:instagram_message_builder) { described_class } before do diff --git a/spec/builders/messages/message_builder_spec.rb b/spec/builders/messages/message_builder_spec.rb index be5d60834..728cb8cf1 100644 --- a/spec/builders/messages/message_builder_spec.rb +++ b/spec/builders/messages/message_builder_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe ::Messages::MessageBuilder do +describe Messages::MessageBuilder do subject(:message_builder) { described_class.new(user, conversation, params).perform } let(:account) { create(:account) } diff --git a/spec/builders/notification_builder_spec.rb b/spec/builders/notification_builder_spec.rb index 4db4ea00d..8386dbf9a 100644 --- a/spec/builders/notification_builder_spec.rb +++ b/spec/builders/notification_builder_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe ::NotificationBuilder do +describe NotificationBuilder do include ActiveJob::TestHelper describe '#perform' do diff --git a/spec/builders/v2/report_builder_spec.rb b/spec/builders/v2/report_builder_spec.rb index 7c6c78179..283f18a38 100644 --- a/spec/builders/v2/report_builder_spec.rb +++ b/spec/builders/v2/report_builder_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe ::V2::ReportBuilder do +describe V2::ReportBuilder do include ActiveJob::TestHelper let_it_be(:account) { create(:account) } let_it_be(:label_1) { create(:label, title: 'Label_1', account: account) } @@ -60,7 +60,7 @@ describe ::V2::ReportBuilder do until: Time.zone.today.end_of_day.to_time.to_i.to_s } - builder = V2::ReportBuilder.new(account, params) + builder = described_class.new(account, params) metrics = builder.timeseries expect(metrics[Time.zone.today]).to be 10 @@ -75,7 +75,7 @@ describe ::V2::ReportBuilder do until: Time.zone.today.end_of_day.to_time.to_i.to_s } - builder = V2::ReportBuilder.new(account, params) + builder = described_class.new(account, params) metrics = builder.timeseries expect(metrics[Time.zone.today]).to be 20 @@ -90,7 +90,7 @@ describe ::V2::ReportBuilder do until: Time.zone.today.end_of_day.to_time.to_i.to_s } - builder = V2::ReportBuilder.new(account, params) + builder = described_class.new(account, params) metrics = builder.timeseries expect(metrics[Time.zone.today]).to be 50 @@ -107,7 +107,7 @@ describe ::V2::ReportBuilder do conversations = account.conversations.where('created_at < ?', 1.day.ago) conversations.each(&:resolved!) - builder = V2::ReportBuilder.new(account, params) + builder = described_class.new(account, params) metrics = builder.timeseries expect(metrics[Time.zone.today]).to be 0 @@ -122,7 +122,7 @@ describe ::V2::ReportBuilder do until: Time.zone.today.end_of_day.to_time.to_i.to_s } - builder = V2::ReportBuilder.new(account, params) + builder = described_class.new(account, params) metrics = builder.timeseries expect(metrics[Time.zone.today].to_f).to be 0.48e4 @@ -135,7 +135,7 @@ describe ::V2::ReportBuilder do until: Time.zone.today.end_of_day.to_time.to_i.to_s } - builder = V2::ReportBuilder.new(account, params) + builder = described_class.new(account, params) metrics = builder.summary expect(metrics[:conversations_count]).to be 15 @@ -153,7 +153,7 @@ describe ::V2::ReportBuilder do group_by: 'test'.to_s } - builder = V2::ReportBuilder.new(account, params) + builder = described_class.new(account, params) expect { builder.summary }.to raise_error(ArgumentError) end end @@ -168,7 +168,7 @@ describe ::V2::ReportBuilder do until: Time.zone.today.end_of_day.to_time.to_i.to_s } - builder = V2::ReportBuilder.new(account, params) + builder = described_class.new(account, params) metrics = builder.timeseries expect(metrics[Time.zone.today - 2.days]).to be 5 @@ -183,7 +183,7 @@ describe ::V2::ReportBuilder do until: (Time.zone.today + 1.day).to_time.to_i.to_s } - builder = V2::ReportBuilder.new(account, params) + builder = described_class.new(account, params) metrics = builder.timeseries expect(metrics[Time.zone.today]).to be 20 @@ -199,7 +199,7 @@ describe ::V2::ReportBuilder do until: (Time.zone.today + 1.day).to_time.to_i.to_s } - builder = V2::ReportBuilder.new(account, params) + builder = described_class.new(account, params) metrics = builder.timeseries expect(metrics[Time.zone.today]).to be 50 @@ -217,7 +217,7 @@ describe ::V2::ReportBuilder do conversations = account.conversations.where('created_at < ?', 1.day.ago) conversations.each(&:resolved!) - builder = V2::ReportBuilder.new(account, params) + builder = described_class.new(account, params) metrics = builder.timeseries expect(metrics[Time.zone.today - 2.days]).to be 5 @@ -234,7 +234,7 @@ describe ::V2::ReportBuilder do until: Time.zone.today.end_of_day.to_time.to_i.to_s } - builder = V2::ReportBuilder.new(account, params) + builder = described_class.new(account, params) metrics = builder.timeseries expect(metrics[Time.zone.today].to_f).to be 0.15e1 end @@ -247,7 +247,7 @@ describe ::V2::ReportBuilder do until: Time.zone.today.end_of_day.to_time.to_i.to_s } - builder = V2::ReportBuilder.new(account, params) + builder = described_class.new(account, params) metrics = builder.summary expect(metrics[:conversations_count]).to be 5 @@ -266,7 +266,7 @@ describe ::V2::ReportBuilder do group_by: 'week'.to_s } - builder = V2::ReportBuilder.new(account, params) + builder = described_class.new(account, params) metrics = builder.summary expect(metrics[:conversations_count]).to be 5 @@ -285,7 +285,7 @@ describe ::V2::ReportBuilder do group_by: 'test'.to_s } - builder = V2::ReportBuilder.new(account, params) + builder = described_class.new(account, params) expect { builder.summary }.to raise_error(ArgumentError) end end diff --git a/spec/channels/room_channel_spec.rb b/spec/channels/room_channel_spec.rb index 8db8c0a7c..362a3d405 100644 --- a/spec/channels/room_channel_spec.rb +++ b/spec/channels/room_channel_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe RoomChannel, type: :channel do +RSpec.describe RoomChannel do let!(:contact_inbox) { create(:contact_inbox) } before do diff --git a/spec/configs/schedule_spec.rb b/spec/configs/schedule_spec.rb index 78d0c4e3e..29b4e9399 100644 --- a/spec/configs/schedule_spec.rb +++ b/spec/configs/schedule_spec.rb @@ -19,6 +19,6 @@ RSpec.context 'with valid schedule.yml' do end end # ensure that no duplicates exist - assert_equal schedule_keys.uniq.count, schedule_keys.count + expect(schedule_keys.count).to eq(schedule_keys.uniq.count) end end diff --git a/spec/controllers/api/base_controller_spec.rb b/spec/controllers/api/base_controller_spec.rb index c1dc781e9..f3cb98a92 100644 --- a/spec/controllers/api/base_controller_spec.rb +++ b/spec/controllers/api/base_controller_spec.rb @@ -22,7 +22,7 @@ RSpec.describe 'API Base', type: :request do as: :json expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['id']).to eq(user.id) expect(json_response['email']).to eq(user.email) end diff --git a/spec/controllers/api/v1/accounts/actions/contact_merges_controller_spec.rb b/spec/controllers/api/v1/accounts/actions/contact_merges_controller_spec.rb index 6ec38969c..1390cdd4c 100644 --- a/spec/controllers/api/v1/accounts/actions/contact_merges_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/actions/contact_merges_controller_spec.rb @@ -30,7 +30,7 @@ RSpec.describe 'Contact Merge Action API', type: :request do as: :json expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['id']).to eq(base_contact.id) expected_params = { account: account, base_contact: base_contact, mergee_contact: mergee_contact } expect(ContactMergeAction).to have_received(:new).with(expected_params) diff --git a/spec/controllers/api/v1/accounts/agents_controller_spec.rb b/spec/controllers/api/v1/accounts/agents_controller_spec.rb index b0ce320ff..2b06301d6 100644 --- a/spec/controllers/api/v1/accounts/agents_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/agents_controller_spec.rb @@ -25,7 +25,7 @@ RSpec.describe 'Agents API', type: :request do as: :json expect(response).to have_http_status(:success) - expect(JSON.parse(response.body).size).to eq(account.users.count) + expect(response.parsed_body.size).to eq(account.users.count) end it 'returns custom fields on agents if present' do @@ -36,7 +36,7 @@ RSpec.describe 'Agents API', type: :request do as: :json expect(response).to have_http_status(:success) - data = JSON.parse(response.body) + data = response.parsed_body expect(data.first['custom_attributes']['test']).to eq('test') end end @@ -131,7 +131,7 @@ RSpec.describe 'Agents API', type: :request do as: :json expect(response).to have_http_status(:success) - response_data = JSON.parse(response.body) + response_data = response.parsed_body expect(response_data['role']).to eq('administrator') expect(response_data['availability_status']).to eq('busy') expect(response_data['auto_offline']).to be(false) diff --git a/spec/controllers/api/v1/accounts/articles_controller_spec.rb b/spec/controllers/api/v1/accounts/articles_controller_spec.rb index 703542bb2..60a1da0c2 100644 --- a/spec/controllers/api/v1/accounts/articles_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/articles_controller_spec.rb @@ -35,7 +35,7 @@ RSpec.describe 'Api::V1::Accounts::Articles', type: :request do params: article_params, headers: agent.create_new_auth_token expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['payload']['title']).to eql('MyTitle') expect(json_response['payload']['status']).to eql('draft') expect(json_response['payload']['position']).to be(3) @@ -58,7 +58,7 @@ RSpec.describe 'Api::V1::Accounts::Articles', type: :request do params: article_params, headers: agent.create_new_auth_token expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['payload']['title']).to eql('MyTitle') expect(json_response['payload']['status']).to eql('draft') expect(json_response['payload']['position']).to be(3) @@ -86,7 +86,7 @@ RSpec.describe 'Api::V1::Accounts::Articles', type: :request do params: article_params, headers: agent.create_new_auth_token expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['payload']['title']).to eql('MyTitle') category = Article.find(json_response['payload']['id']) @@ -112,7 +112,7 @@ RSpec.describe 'Api::V1::Accounts::Articles', type: :request do params: article_params, headers: agent.create_new_auth_token expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['payload']['title']).to eql('MyTitle') category = Article.find(json_response['payload']['id']) @@ -146,7 +146,7 @@ RSpec.describe 'Api::V1::Accounts::Articles', type: :request do params: article_params, headers: agent.create_new_auth_token expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['payload']['title']).to eql(article_params[:article][:title]) expect(json_response['payload']['status']).to eql(article_params[:article][:status]) expect(json_response['payload']['position']).to eql(article_params[:article][:position]) @@ -190,7 +190,7 @@ RSpec.describe 'Api::V1::Accounts::Articles', type: :request do headers: agent.create_new_auth_token, params: {} expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['payload'].count).to be 2 end @@ -202,7 +202,7 @@ RSpec.describe 'Api::V1::Accounts::Articles', type: :request do headers: agent.create_new_auth_token, params: { category_slug: category.slug } expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['payload'].count).to be 2 end @@ -219,7 +219,7 @@ RSpec.describe 'Api::V1::Accounts::Articles', type: :request do headers: agent.create_new_auth_token, params: { query: 'funny' } expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['payload'].count).to be 1 expect(json_response['meta']['all_articles_count']).to be 2 expect(json_response['meta']['articles_count']).to be 1 @@ -235,7 +235,7 @@ RSpec.describe 'Api::V1::Accounts::Articles', type: :request do get "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/articles/#{article2.id}", headers: agent.create_new_auth_token expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['payload']['title']).to eq(article2.title) expect(json_response['payload']['id']).to eq(article2.id) @@ -251,11 +251,11 @@ RSpec.describe 'Api::V1::Accounts::Articles', type: :request do get "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/articles/#{root_article.id}", headers: agent.create_new_auth_token expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['payload']['associated_articles'].length).to eq(2) - associated_articles_ids = json_response['payload']['associated_articles'].map { |article| article['id'] } - expect(associated_articles_ids).to match_array([child_article_1.id, child_article_2.id]) + associated_articles_ids = json_response['payload']['associated_articles'].pluck('id') + expect(associated_articles_ids).to contain_exactly(child_article_1.id, child_article_2.id) expect(json_response['payload']['id']).to eq(root_article.id) end end @@ -272,7 +272,7 @@ RSpec.describe 'Api::V1::Accounts::Articles', type: :request do expect(response).to have_http_status(:success) - blob = JSON.parse(response.body) + blob = response.parsed_body expect(blob['file_url']).to be_present end diff --git a/spec/controllers/api/v1/accounts/automation_rules_controller_spec.rb b/spec/controllers/api/v1/accounts/automation_rules_controller_spec.rb index 2c8041ab5..b0da23d0f 100644 --- a/spec/controllers/api/v1/accounts/automation_rules_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/automation_rules_controller_spec.rb @@ -134,7 +134,7 @@ RSpec.describe 'Api::V1::Accounts::AutomationRulesController', type: :request do expect(response).to have_http_status(:success) - blob = JSON.parse(response.body) + blob = response.parsed_body expect(blob['blob_key']).to be_present expect(blob['blob_id']).to be_present @@ -167,13 +167,13 @@ RSpec.describe 'Api::V1::Accounts::AutomationRulesController', type: :request do headers: administrator.create_new_auth_token, params: { attachment: file_1 } - blob_1 = JSON.parse(response.body) + blob_1 = response.parsed_body post "/api/v1/accounts/#{account.id}/automation_rules/attach_file", headers: administrator.create_new_auth_token, params: { attachment: file_2 } - blob_2 = JSON.parse(response.body) + blob_2 = response.parsed_body params[:actions] = [ { diff --git a/spec/controllers/api/v1/accounts/campaigns_controller_spec.rb b/spec/controllers/api/v1/accounts/campaigns_controller_spec.rb index ddf93c3f9..1d9908652 100644 --- a/spec/controllers/api/v1/accounts/campaigns_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/campaigns_controller_spec.rb @@ -222,7 +222,7 @@ RSpec.describe 'Campaigns API', type: :request do as: :json expect(response).to have_http_status(:success) - expect(::Campaign.exists?(campaign.display_id)).to be false + expect(Campaign.exists?(campaign.display_id)).to be false end end end diff --git a/spec/controllers/api/v1/accounts/canned_responses_controller_spec.rb b/spec/controllers/api/v1/accounts/canned_responses_controller_spec.rb index 228da2d56..45c99f15e 100644 --- a/spec/controllers/api/v1/accounts/canned_responses_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/canned_responses_controller_spec.rb @@ -25,7 +25,7 @@ RSpec.describe 'Canned Responses API', type: :request do as: :json expect(response).to have_http_status(:success) - expect(JSON.parse(response.body)).to eq(account.canned_responses.as_json) + expect(response.parsed_body).to eq(account.canned_responses.as_json) end it 'returns all the canned responses the user searched for' do @@ -42,7 +42,7 @@ RSpec.describe 'Canned Responses API', type: :request do as: :json expect(response).to have_http_status(:success) - expect(JSON.parse(response.body)).to eq( + expect(response.parsed_body).to eq( [cr3, cr2, cr1].as_json ) end diff --git a/spec/controllers/api/v1/accounts/categories_controller_spec.rb b/spec/controllers/api/v1/accounts/categories_controller_spec.rb index 783e89d93..03e658aac 100644 --- a/spec/controllers/api/v1/accounts/categories_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/categories_controller_spec.rb @@ -62,7 +62,7 @@ RSpec.describe 'Api::V1::Accounts::Categories', type: :request do headers: agent.create_new_auth_token expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['payload']['related_categories'][0]['id']).to eql(related_category_1.id) expect(json_response['payload']['related_categories'][1]['id']).to eql(related_category_2.id) @@ -107,7 +107,7 @@ RSpec.describe 'Api::V1::Accounts::Categories', type: :request do params: category_params, headers: agent.create_new_auth_token expect(response).to have_http_status(:unprocessable_entity) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['message']).to eql('Locale should be unique in the category and portal') end @@ -125,7 +125,7 @@ RSpec.describe 'Api::V1::Accounts::Categories', type: :request do params: category_params, headers: agent.create_new_auth_token expect(response).to have_http_status(:unprocessable_entity) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['message']).to eql("Slug can't be blank") end @@ -160,7 +160,7 @@ RSpec.describe 'Api::V1::Accounts::Categories', type: :request do params: category_params, headers: agent.create_new_auth_token - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['payload']['name']).to eql(category_params[:category][:name]) expect(json_response['payload']['related_categories'][0]['id']).to eql(related_category_1.id) @@ -185,7 +185,7 @@ RSpec.describe 'Api::V1::Accounts::Categories', type: :request do expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['payload']['name']).to eql(category.name) expect(json_response['payload']['related_categories'][0]['id']).to eql(related_category_1.id) @@ -257,7 +257,7 @@ RSpec.describe 'Api::V1::Accounts::Categories', type: :request do get "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/categories", headers: agent.create_new_auth_token expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['payload'].count).to be(category_count + 1) end end diff --git a/spec/controllers/api/v1/accounts/channels/twilio_channels_controller_spec.rb b/spec/controllers/api/v1/accounts/channels/twilio_channels_controller_spec.rb index 7d8ca4c9c..8e3e45fed 100644 --- a/spec/controllers/api/v1/accounts/channels/twilio_channels_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/channels/twilio_channels_controller_spec.rb @@ -4,13 +4,13 @@ RSpec.describe '/api/v1/accounts/{account.id}/channels/twilio_channel', type: :r let(:account) { create(:account) } let(:admin) { create(:user, account: account, role: :administrator) } let(:agent) { create(:user, account: account, role: :agent) } - let(:twilio_client) { instance_double(::Twilio::REST::Client) } + let(:twilio_client) { instance_double(Twilio::REST::Client) } let(:message_double) { double } - let(:twilio_webhook_setup_service) { instance_double(::Twilio::WebhookSetupService) } + let(:twilio_webhook_setup_service) { instance_double(Twilio::WebhookSetupService) } before do - allow(::Twilio::REST::Client).to receive(:new).and_return(twilio_client) - allow(::Twilio::WebhookSetupService).to receive(:new).and_return(twilio_webhook_setup_service) + allow(Twilio::REST::Client).to receive(:new).and_return(twilio_client) + allow(Twilio::WebhookSetupService).to receive(:new).and_return(twilio_webhook_setup_service) allow(twilio_webhook_setup_service).to receive(:perform) end @@ -46,7 +46,7 @@ RSpec.describe '/api/v1/accounts/{account.id}/channels/twilio_channel', type: :r headers: admin.create_new_auth_token expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['name']).to eq('SMS Channel') expect(json_response['messaging_service_sid']).to eq('MGec8130512b5dd462cfe03095ec1342ed') @@ -71,7 +71,7 @@ RSpec.describe '/api/v1/accounts/{account.id}/channels/twilio_channel', type: :r headers: admin.create_new_auth_token expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['messaging_service_sid']).to eq('MGec8130512b5dd462cfe03095ec1111ed') end @@ -99,7 +99,7 @@ RSpec.describe '/api/v1/accounts/{account.id}/channels/twilio_channel', type: :r headers: admin.create_new_auth_token expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['name']).to eq('SMS Channel') expect(json_response['phone_number']).to eq('+1234567890') @@ -124,7 +124,7 @@ RSpec.describe '/api/v1/accounts/{account.id}/channels/twilio_channel', type: :r headers: admin.create_new_auth_token expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['phone_number']).to eq('whatsapp:+1224466880') end diff --git a/spec/controllers/api/v1/accounts/contacts/conversations_controller_spec.rb b/spec/controllers/api/v1/accounts/contacts/conversations_controller_spec.rb index 489ac60a4..da7764d25 100644 --- a/spec/controllers/api/v1/accounts/contacts/conversations_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/contacts/conversations_controller_spec.rb @@ -33,7 +33,7 @@ RSpec.describe '/api/v1/accounts/{account.id}/contacts/:id/conversations', type: get "/api/v1/accounts/#{account.id}/contacts/#{contact.id}/conversations", headers: admin.create_new_auth_token expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['payload'].length).to eq 4 end @@ -44,7 +44,7 @@ RSpec.describe '/api/v1/accounts/{account.id}/contacts/:id/conversations', type: get "/api/v1/accounts/#{account.id}/contacts/#{contact.id}/conversations", headers: agent.create_new_auth_token expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['payload'].length).to eq 2 end @@ -55,7 +55,7 @@ RSpec.describe '/api/v1/accounts/{account.id}/contacts/:id/conversations', type: get "/api/v1/accounts/#{account.id}/contacts/#{contact.id}/conversations", headers: unknown.create_new_auth_token expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['payload'].length).to eq 0 end diff --git a/spec/controllers/api/v1/accounts/contacts/notes_controller_spec.rb b/spec/controllers/api/v1/accounts/contacts/notes_controller_spec.rb index 9bd26618d..c99e79284 100644 --- a/spec/controllers/api/v1/accounts/contacts/notes_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/contacts/notes_controller_spec.rb @@ -114,7 +114,7 @@ RSpec.describe 'Notes API', type: :request do as: :json expect(response).to have_http_status(:success) - expect(::Note.exists?(note.id)).to be false + expect(Note.exists?(note.id)).to be false end end end diff --git a/spec/controllers/api/v1/accounts/contacts_controller_spec.rb b/spec/controllers/api/v1/accounts/contacts_controller_spec.rb index b3390fe03..f6141000e 100644 --- a/spec/controllers/api/v1/accounts/contacts_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/contacts_controller_spec.rb @@ -35,7 +35,7 @@ RSpec.describe 'Contacts API', type: :request do as: :json expect(response).to have_http_status(:success) - response_body = JSON.parse(response.body) + response_body = response.parsed_body expect(response_body['payload'].first['email']).to eq(contact.email) expect(response_body['payload'].first['contact_inboxes'].first['source_id']).to eq(contact_inbox.source_id) expect(response_body['payload'].first['contact_inboxes'].first['inbox']['name']).to eq(contact_inbox.inbox.name) @@ -47,7 +47,7 @@ RSpec.describe 'Contacts API', type: :request do as: :json expect(response).to have_http_status(:success) - response_body = JSON.parse(response.body) + response_body = response.parsed_body expect(response_body['payload'].first['email']).to eq(contact.email) expect(response_body['payload'].first['contact_inboxes'].blank?).to be(true) end @@ -58,7 +58,7 @@ RSpec.describe 'Contacts API', type: :request do as: :json expect(response).to have_http_status(:success) - response_body = JSON.parse(response.body) + response_body = response.parsed_body expect(response_body['payload'].last['id']).to eq(contact_4.id) expect(response_body['payload'].last['email']).to eq(contact_4.email) end @@ -69,7 +69,7 @@ RSpec.describe 'Contacts API', type: :request do as: :json expect(response).to have_http_status(:success) - response_body = JSON.parse(response.body) + response_body = response.parsed_body expect(response_body['payload'].first['email']).to eq(contact_1.email) expect(response_body['payload'].first['id']).to eq(contact_1.id) expect(response_body['payload'].last['email']).to eq(contact_4.email) @@ -81,7 +81,7 @@ RSpec.describe 'Contacts API', type: :request do as: :json expect(response).to have_http_status(:success) - response_body = JSON.parse(response.body) + response_body = response.parsed_body expect(response_body['payload'].first['email']).to eq(contact.email) expect(response_body['payload'].first['id']).to eq(contact.id) expect(response_body['payload'].last['email']).to eq(contact_4.email) @@ -94,7 +94,7 @@ RSpec.describe 'Contacts API', type: :request do as: :json expect(response).to have_http_status(:success) - response_body = JSON.parse(response.body) + response_body = response.parsed_body expect(response_body['payload'].first['conversations_count']).to eq(contact.conversations.count) expect(response_body['payload'].first['last_seen_at']).present? end @@ -110,7 +110,7 @@ RSpec.describe 'Contacts API', type: :request do as: :json expect(response).to have_http_status(:success) - response_body = JSON.parse(response.body) + response_body = response.parsed_body expect(response_body['meta']['count']).to eq(2) expect(response_body['payload'].pluck('email')).to include(contact_with_label1.email, contact_with_label2.email) end @@ -160,7 +160,7 @@ RSpec.describe 'Contacts API', type: :request do post "/api/v1/accounts/#{account.id}/contacts/import", headers: admin.create_new_auth_token - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(response).to have_http_status(:unprocessable_entity) expect(json_response['error']).to eq('File is blank') @@ -191,7 +191,7 @@ RSpec.describe 'Contacts API', type: :request do end it 'returns all contacts who are online' do - allow(::OnlineStatusTracker).to receive(:get_available_contact_ids).and_return([contact.id]) + allow(OnlineStatusTracker).to receive(:get_available_contact_ids).and_return([contact.id]) get "/api/v1/accounts/#{account.id}/contacts/active", headers: admin.create_new_auth_token, @@ -353,7 +353,7 @@ RSpec.describe 'Contacts API', type: :request do expect(response).to have_http_status(:success) # only the inboxes which agent has access to are shown - expect(JSON.parse(response.body)['payload'].pluck('inbox').pluck('id')).to eq([twilio_whatsapp_inbox.id]) + expect(response.parsed_body['payload'].pluck('inbox').pluck('id')).to eq([twilio_whatsapp_inbox.id]) end end end @@ -383,7 +383,7 @@ RSpec.describe 'Contacts API', type: :request do expect(response).to have_http_status(:success) # custom attributes are updated - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['payload']['contact']['custom_attributes']).to eq({ 'test' => 'test', 'test1' => 'test1' }) end @@ -395,7 +395,7 @@ RSpec.describe 'Contacts API', type: :request do expect(response).to have_http_status(:unprocessable_entity) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['message']).to eq('Name is too long (maximum is 255 characters)') end @@ -460,7 +460,7 @@ RSpec.describe 'Contacts API', type: :request do as: :json expect(response).to have_http_status(:unprocessable_entity) - expect(JSON.parse(response.body)['attributes']).to include('email') + expect(response.parsed_body['attributes']).to include('email') end it 'prevents updating with an existing phone number' do @@ -472,7 +472,7 @@ RSpec.describe 'Contacts API', type: :request do as: :json expect(response).to have_http_status(:unprocessable_entity) - expect(JSON.parse(response.body)['attributes']).to include('phone_number') + expect(response.parsed_body['attributes']).to include('phone_number') end it 'updates avatar' do @@ -517,7 +517,7 @@ RSpec.describe 'Contacts API', type: :request do let(:agent) { create(:user, account: account, role: :agent) } it 'deletes the contact for administrator user' do - allow(::OnlineStatusTracker).to receive(:get_presence).and_return(false) + allow(OnlineStatusTracker).to receive(:get_presence).and_return(false) delete "/api/v1/accounts/#{account.id}/contacts/#{contact.id}", headers: admin.create_new_auth_token @@ -530,7 +530,7 @@ RSpec.describe 'Contacts API', type: :request do end it 'does not delete the contact if online' do - allow(::OnlineStatusTracker).to receive(:get_presence).and_return(true) + allow(OnlineStatusTracker).to receive(:get_presence).and_return(true) delete "/api/v1/accounts/#{account.id}/contacts/#{contact.id}", headers: admin.create_new_auth_token @@ -591,7 +591,7 @@ RSpec.describe 'Contacts API', type: :request do context 'when it is an authenticated user' do before do create(:contact, account: account) - contact.avatar.attach(io: File.open(Rails.root.join('spec/assets/avatar.png')), filename: 'avatar.png', content_type: 'image/png') + contact.avatar.attach(io: Rails.root.join('spec/assets/avatar.png').open, filename: 'avatar.png', content_type: 'image/png') end it 'delete contact avatar' do diff --git a/spec/controllers/api/v1/accounts/conversations/direct_uploads_controller_spec.rb b/spec/controllers/api/v1/accounts/conversations/direct_uploads_controller_spec.rb index c2518c1bd..089b16b59 100644 --- a/spec/controllers/api/v1/accounts/conversations/direct_uploads_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/conversations/direct_uploads_controller_spec.rb @@ -26,7 +26,7 @@ RSpec.describe '/api/v1/accounts/:account_id/conversations/:conversation_id/dire as: :json expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['content_type']).to eq('image/png') end end diff --git a/spec/controllers/api/v1/accounts/conversations/messages_controller_spec.rb b/spec/controllers/api/v1/accounts/conversations/messages_controller_spec.rb index d0072af8a..dc9de8c35 100644 --- a/spec/controllers/api/v1/accounts/conversations/messages_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/conversations/messages_controller_spec.rb @@ -45,7 +45,7 @@ RSpec.describe 'Conversation Messages API', type: :request do expect(response).to have_http_status(:unprocessable_entity) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['error']).to eq('Validation failed: Content is too long (maximum is 150000 characters)') end @@ -61,7 +61,7 @@ RSpec.describe 'Conversation Messages API', type: :request do as: :json expect(response).to have_http_status(:success) - response_data = JSON.parse(response.body) + response_data = response.parsed_body expect(response_data['content_attributes']['external_created_at']).to eq time_stamp expect(conversation.messages.count).to eq(1) expect(conversation.messages.last.sender_id).to eq(agent_bot.id) diff --git a/spec/controllers/api/v1/accounts/conversations_controller_spec.rb b/spec/controllers/api/v1/accounts/conversations_controller_spec.rb index bf73cd0ce..496ce5cdb 100644 --- a/spec/controllers/api/v1/accounts/conversations_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/conversations_controller_spec.rb @@ -765,7 +765,7 @@ RSpec.describe 'Conversations API', type: :request do as: :json expect(response).to have_http_status(:success) - response_body = JSON.parse(response.body) + response_body = response.parsed_body expect(response_body['payload'].first['file_type']).to eq('image') end @@ -775,7 +775,7 @@ RSpec.describe 'Conversations API', type: :request do as: :json expect(response).to have_http_status(:success) - response_body = JSON.parse(response.body) + response_body = response.parsed_body expect(response_body['payload'].length).to eq(1) end end diff --git a/spec/controllers/api/v1/accounts/csat_survey_responses_controller_spec.rb b/spec/controllers/api/v1/accounts/csat_survey_responses_controller_spec.rb index a6c225ab4..10b81986d 100644 --- a/spec/controllers/api/v1/accounts/csat_survey_responses_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/csat_survey_responses_controller_spec.rb @@ -30,7 +30,7 @@ RSpec.describe 'CSAT Survey Responses API', type: :request do as: :json expect(response).to have_http_status(:success) - expect(JSON.parse(response.body).first['feedback_message']).to eq(csat_survey_response.feedback_message) + expect(response.parsed_body.first['feedback_message']).to eq(csat_survey_response.feedback_message) end it 'filters csat responses based on a date range' do @@ -43,7 +43,7 @@ RSpec.describe 'CSAT Survey Responses API', type: :request do as: :json expect(response).to have_http_status(:success) - response_data = JSON.parse(response.body) + response_data = response.parsed_body expect(response_data.pluck('id')).to include(csat_3_days_ago.id) expect(response_data.pluck('id')).not_to include(csat_10_days_ago.id) end @@ -63,7 +63,7 @@ RSpec.describe 'CSAT Survey Responses API', type: :request do as: :json expect(response).to have_http_status(:success) - response_data = JSON.parse(response.body) + response_data = response.parsed_body expect(response_data.size).to eq 2 end @@ -104,7 +104,7 @@ RSpec.describe 'CSAT Survey Responses API', type: :request do as: :json expect(response).to have_http_status(:success) - response_data = JSON.parse(response.body) + response_data = response.parsed_body expect(response_data['total_count']).to eq 1 expect(response_data['total_sent_messages_count']).to eq 0 expect(response_data['ratings_count']).to eq({ '1' => 1 }) @@ -123,7 +123,7 @@ RSpec.describe 'CSAT Survey Responses API', type: :request do as: :json expect(response).to have_http_status(:success) - response_data = JSON.parse(response.body) + response_data = response.parsed_body expect(response_data['total_count']).to eq 1 expect(response_data['total_sent_messages_count']).to eq 0 expect(response_data['ratings_count']).to eq({ '1' => 1 }) @@ -144,7 +144,7 @@ RSpec.describe 'CSAT Survey Responses API', type: :request do as: :json expect(response).to have_http_status(:success) - response_data = JSON.parse(response.body) + response_data = response.parsed_body expect(response_data['total_count']).to eq 2 expect(response_data['total_sent_messages_count']).to eq 0 expect(response_data['ratings_count']).to eq({ '1' => 2 }) diff --git a/spec/controllers/api/v1/accounts/custom_attribute_definitions_controller_spec.rb b/spec/controllers/api/v1/accounts/custom_attribute_definitions_controller_spec.rb index f266aa617..d434381cd 100644 --- a/spec/controllers/api/v1/accounts/custom_attribute_definitions_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/custom_attribute_definitions_controller_spec.rb @@ -23,7 +23,7 @@ RSpec.describe 'Custom Attribute Definitions API', type: :request do as: :json expect(response).to have_http_status(:success) - response_body = JSON.parse(response.body) + response_body = response.parsed_body expect(response_body.count).to eq(2) expect(response_body.first['attribute_key']).to eq(custom_attribute_definition.attribute_key) @@ -86,7 +86,7 @@ RSpec.describe 'Custom Attribute Definitions API', type: :request do end.to change(CustomAttributeDefinition, :count).by(1) expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['attribute_key']).to eq 'developer_id' end end 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 c9a79bdd0..73ba61859 100644 --- a/spec/controllers/api/v1/accounts/custom_filters_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/custom_filters_controller_spec.rb @@ -22,7 +22,7 @@ RSpec.describe 'Custom Filters API', type: :request do as: :json expect(response).to have_http_status(:success) - response_body = JSON.parse(response.body) + response_body = response.parsed_body expect(response_body.first['name']).to eq(custom_filter.name) expect(response_body.first['query']).to eq(custom_filter.query) end @@ -74,7 +74,7 @@ RSpec.describe 'Custom Filters API', type: :request do end.to change(CustomFilter, :count).by(1) expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['name']).to eq 'vip-customers' end end diff --git a/spec/controllers/api/v1/accounts/dashboard_apps_controller_spec.rb b/spec/controllers/api/v1/accounts/dashboard_apps_controller_spec.rb index a557ad788..e545b0e35 100644 --- a/spec/controllers/api/v1/accounts/dashboard_apps_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/dashboard_apps_controller_spec.rb @@ -22,7 +22,7 @@ RSpec.describe 'DashboardAppsController', type: :request do as: :json expect(response).to have_http_status(:success) - response_body = JSON.parse(response.body) + response_body = response.parsed_body expect(response_body.first['title']).to eq(dashboard_app.title) expect(response_body.first['content']).to eq(dashboard_app.content) end @@ -76,7 +76,7 @@ RSpec.describe 'DashboardAppsController', type: :request do end.to change(DashboardApp, :count).by(1) expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['title']).to eq 'CRM Dashboard' expect(json_response['content'][0]['link']).to eq payload[:dashboard_app][:content][0][:link] expect(json_response['content'][0]['type']).to eq payload[:dashboard_app][:content][0][:type] @@ -89,7 +89,7 @@ RSpec.describe 'DashboardAppsController', type: :request do end.not_to change(DashboardApp, :count) expect(response).to have_http_status(:unprocessable_entity) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['message']).to eq 'Content : Invalid data' end @@ -126,7 +126,7 @@ RSpec.describe 'DashboardAppsController', type: :request do as: :json expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(dashboard_app.reload.title).to eq('CRM Dashboard') expect(json_response['content'][0]['link']).to eq payload[:dashboard_app][:content][0][:link] expect(json_response['content'][0]['type']).to eq payload[:dashboard_app][:content][0][:type] diff --git a/spec/controllers/api/v1/accounts/inbox_members_controller_spec.rb b/spec/controllers/api/v1/accounts/inbox_members_controller_spec.rb index b19035e77..34633601e 100644 --- a/spec/controllers/api/v1/accounts/inbox_members_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/inbox_members_controller_spec.rb @@ -38,7 +38,7 @@ RSpec.describe 'Inbox Member API', type: :request do as: :json expect(response).to have_http_status(:success) - expect(JSON.parse(response.body)['payload'].pluck('id')).to eq(inbox.inbox_members.pluck(:user_id)) + expect(response.parsed_body['payload'].pluck('id')).to eq(inbox.inbox_members.pluck(:user_id)) end end end diff --git a/spec/controllers/api/v1/accounts/inboxes_controller_spec.rb b/spec/controllers/api/v1/accounts/inboxes_controller_spec.rb index f19094b0c..b4b6da6fe 100644 --- a/spec/controllers/api/v1/accounts/inboxes_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/inboxes_controller_spec.rb @@ -248,7 +248,7 @@ RSpec.describe 'Inboxes API', type: :request do context 'when it is an authenticated user' do before do create(:inbox_member, user: agent, inbox: inbox) - inbox.avatar.attach(io: File.open(Rails.root.join('spec/assets/avatar.png')), filename: 'avatar.png', content_type: 'image/png') + inbox.avatar.attach(io: Rails.root.join('spec/assets/avatar.png').open, filename: 'avatar.png', content_type: 'image/png') end it 'delete inbox avatar for administrator user' do @@ -293,7 +293,7 @@ RSpec.describe 'Inboxes API', type: :request do as: :json end - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(response).to have_http_status(:success) expect(json_response['message']).to eq('Your inbox deletion request will be processed in some time.') @@ -410,7 +410,7 @@ RSpec.describe 'Inboxes API', type: :request do as: :json expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['allow_messages_after_resolved']).to be true end end @@ -452,7 +452,7 @@ RSpec.describe 'Inboxes API', type: :request do expect(response).to have_http_status(:success) expect(inbox.reload.enable_auto_assignment).to be_falsey expect(inbox.reload.portal_id).to eq(portal.id) - expect(JSON.parse(response.body)['name']).to eq 'new test inbox' + expect(response.parsed_body['name']).to eq 'new test inbox' end it 'updates api inbox when administrator' do diff --git a/spec/controllers/api/v1/accounts/integrations/apps_controller_spec.rb b/spec/controllers/api/v1/accounts/integrations/apps_controller_spec.rb index 4f120df9c..43735046e 100644 --- a/spec/controllers/api/v1/accounts/integrations/apps_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/integrations/apps_controller_spec.rb @@ -22,7 +22,7 @@ RSpec.describe 'Integration Apps API', type: :request do as: :json expect(response).to have_http_status(:success) - apps = JSON.parse(response.body)['payload'].first + apps = response.parsed_body['payload'].first expect(apps['id']).to eql(first_app.id) expect(apps['name']).to eql(first_app.name) expect(apps['action']).to be_nil @@ -36,7 +36,7 @@ RSpec.describe 'Integration Apps API', type: :request do expect(response).to have_http_status(:success) - app = JSON.parse(response.body)['payload'].find { |int_app| int_app['id'] == openai.app.id } + app = response.parsed_body['payload'].find { |int_app| int_app['id'] == openai.app.id } expect(app['hooks'].first['settings']).to be_nil end @@ -47,7 +47,7 @@ RSpec.describe 'Integration Apps API', type: :request do as: :json expect(response).to have_http_status(:success) - apps = JSON.parse(response.body)['payload'].first + apps = response.parsed_body['payload'].first expect(apps['id']).to eql(first_app.id) expect(apps['name']).to eql(first_app.name) expect(apps['action']).to eql(first_app.action) @@ -60,7 +60,7 @@ RSpec.describe 'Integration Apps API', type: :request do as: :json expect(response).to have_http_status(:success) - apps = JSON.parse(response.body)['payload'] + apps = response.parsed_body['payload'] slack_app = apps.find { |app| app['id'] == 'slack' } expect(slack_app['action']).to include('client_id=client_id') end @@ -74,7 +74,7 @@ RSpec.describe 'Integration Apps API', type: :request do expect(response).to have_http_status(:success) - app = JSON.parse(response.body)['payload'].find { |int_app| int_app['id'] == openai.app.id } + app = response.parsed_body['payload'].find { |int_app| int_app['id'] == openai.app.id } expect(app['hooks'].first['settings']).not_to be_nil end end @@ -98,7 +98,7 @@ RSpec.describe 'Integration Apps API', type: :request do as: :json expect(response).to have_http_status(:success) - app = JSON.parse(response.body) + app = response.parsed_body expect(app['id']).to eql('slack') expect(app['name']).to eql('Slack') end @@ -111,7 +111,7 @@ RSpec.describe 'Integration Apps API', type: :request do expect(response).to have_http_status(:success) - app = JSON.parse(response.body) + app = response.parsed_body expect(app['hooks'].first['settings']).to be_nil end @@ -123,7 +123,7 @@ RSpec.describe 'Integration Apps API', type: :request do expect(response).to have_http_status(:success) - app = JSON.parse(response.body) + app = response.parsed_body expect(app['hooks'].first['settings']).not_to be_nil end end diff --git a/spec/controllers/api/v1/accounts/integrations/dyte_controller_spec.rb b/spec/controllers/api/v1/accounts/integrations/dyte_controller_spec.rb index 092e467b8..c70ecc845 100644 --- a/spec/controllers/api/v1/accounts/integrations/dyte_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/integrations/dyte_controller_spec.rb @@ -53,7 +53,7 @@ RSpec.describe 'Dyte Integration API', type: :request do headers: agent.create_new_auth_token, as: :json expect(response).to have_http_status(:success) - response_body = JSON.parse(response.body) + response_body = response.parsed_body last_message = conversation.reload.messages.last expect(conversation.display_id).to eq(response_body['conversation_id']) expect(last_message.id).to eq(response_body['id']) @@ -76,7 +76,7 @@ RSpec.describe 'Dyte Integration API', type: :request do headers: agent.create_new_auth_token, as: :json expect(response).to have_http_status(:unprocessable_entity) - response_body = JSON.parse(response.body) + response_body = response.parsed_body expect(response_body['error']).to eq({ 'data' => { 'message' => 'Title is required' }, 'success' => false }) end end @@ -126,7 +126,7 @@ RSpec.describe 'Dyte Integration API', type: :request do headers: agent.create_new_auth_token, as: :json expect(response).to have_http_status(:success) - response_body = JSON.parse(response.body) + response_body = response.parsed_body expect(response_body['authResponse']).to eq( { 'userAdded' => true, 'id' => 'random_uuid', 'auth_token' => 'json-web-token' diff --git a/spec/controllers/api/v1/accounts/integrations/hooks_controller_spec.rb b/spec/controllers/api/v1/accounts/integrations/hooks_controller_spec.rb index 37378b5a5..562272f14 100644 --- a/spec/controllers/api/v1/accounts/integrations/hooks_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/integrations/hooks_controller_spec.rb @@ -35,7 +35,7 @@ RSpec.describe 'Integration Hooks API', type: :request do as: :json expect(response).to have_http_status(:success) - data = JSON.parse(response.body) + data = response.parsed_body expect(data['app_id']).to eq params[:app_id] end end @@ -71,7 +71,7 @@ RSpec.describe 'Integration Hooks API', type: :request do as: :json expect(response).to have_http_status(:success) - data = JSON.parse(response.body) + data = response.parsed_body expect(data['app_id']).to eq 'slack' end end @@ -131,7 +131,7 @@ RSpec.describe 'Integration Hooks API', type: :request do as: :json expect(response).to have_http_status(:success) - expect(::Integrations::Hook.exists?(hook.id)).to be false + expect(Integrations::Hook.exists?(hook.id)).to be false end end end diff --git a/spec/controllers/api/v1/accounts/macros_controller_spec.rb b/spec/controllers/api/v1/accounts/macros_controller_spec.rb index 7fbe6b54e..8a88caa1c 100644 --- a/spec/controllers/api/v1/accounts/macros_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/macros_controller_spec.rb @@ -26,7 +26,7 @@ RSpec.describe 'Api::V1::Accounts::MacrosController', type: :request do visible_macros = account.macros.global.or(account.macros.personal.where(created_by_id: administrator.id)).order(:id) expect(response).to have_http_status(:success) - body = JSON.parse(response.body) + body = response.parsed_body expect(body['payload'].length).to eq(visible_macros.count) @@ -42,7 +42,7 @@ RSpec.describe 'Api::V1::Accounts::MacrosController', type: :request do expect(response).to have_http_status(:success) - body = JSON.parse(response.body) + body = response.parsed_body visible_macros = account.macros.global.or(account.macros.personal.where(created_by_id: agent.id)).order(:id) expect(body['payload'].length).to eq(visible_macros.count) @@ -105,7 +105,7 @@ RSpec.describe 'Api::V1::Accounts::MacrosController', type: :request do expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['payload']['name']).to eql(params['name']) expect(json_response['payload']['visibility']).to eql(params['visibility']) @@ -119,7 +119,7 @@ RSpec.describe 'Api::V1::Accounts::MacrosController', type: :request do expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['payload']['name']).to eql(params['name']) expect(json_response['payload']['visibility']).to eql('personal') @@ -135,7 +135,7 @@ RSpec.describe 'Api::V1::Accounts::MacrosController', type: :request do expect(response).to have_http_status(:success) - blob = JSON.parse(response.body) + blob = response.parsed_body expect(blob['blob_key']).to be_present expect(blob['blob_id']).to be_present @@ -186,7 +186,7 @@ RSpec.describe 'Api::V1::Accounts::MacrosController', type: :request do headers: administrator.create_new_auth_token expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['name']).to eql(params['name']) end @@ -197,7 +197,7 @@ RSpec.describe 'Api::V1::Accounts::MacrosController', type: :request do params: params, headers: agent_1.create_new_auth_token - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(response).to have_http_status(:unauthorized) expect(json_response['error']).to eq('You are not authorized to do this action') @@ -223,7 +223,7 @@ RSpec.describe 'Api::V1::Accounts::MacrosController', type: :request do expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['payload']['name']).to eql(macro.name) expect(json_response['payload']['created_by']['id']).to eql(administrator.id) @@ -242,7 +242,7 @@ RSpec.describe 'Api::V1::Accounts::MacrosController', type: :request do get "/api/v1/accounts/#{account.id}/macros/#{macro.id}", headers: agent_1.create_new_auth_token - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(response).to have_http_status(:unauthorized) expect(json_response['error']).to eq('You are not authorized to do this action') @@ -452,7 +452,7 @@ RSpec.describe 'Api::V1::Accounts::MacrosController', type: :request do delete "/api/v1/accounts/#{account.id}/macros/#{macro.id}", headers: agent_1.create_new_auth_token - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(response).to have_http_status(:unauthorized) expect(json_response['error']).to eq('You are not authorized to do this action') @@ -464,7 +464,7 @@ RSpec.describe 'Api::V1::Accounts::MacrosController', type: :request do delete "/api/v1/accounts/#{account.id}/macros/#{macro.id}", headers: agent_1.create_new_auth_token - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(response).to have_http_status(:unauthorized) expect(json_response['error']).to eq('You are not authorized to do this action') diff --git a/spec/controllers/api/v1/accounts/microsoft/authorization_controller_spec.rb b/spec/controllers/api/v1/accounts/microsoft/authorization_controller_spec.rb index 60948bce1..853cf2850 100644 --- a/spec/controllers/api/v1/accounts/microsoft/authorization_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/microsoft/authorization_controller_spec.rb @@ -40,8 +40,8 @@ RSpec.describe 'Microsoft Authorization API', type: :request do prompt: 'consent' } ) - expect(JSON.parse(response.body)['url']).to eq response_url - expect(::Redis::Alfred.get(administrator.email)).to eq(account.id.to_s) + expect(response.parsed_body['url']).to eq response_url + expect(Redis::Alfred.get(administrator.email)).to eq(account.id.to_s) end end end diff --git a/spec/controllers/api/v1/accounts/notification_settings_controller_spec.rb b/spec/controllers/api/v1/accounts/notification_settings_controller_spec.rb index 26ea66972..221c5f976 100644 --- a/spec/controllers/api/v1/accounts/notification_settings_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/notification_settings_controller_spec.rb @@ -21,7 +21,7 @@ RSpec.describe 'Notification Settings API', type: :request do as: :json expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['user_id']).to eq(agent.id) expect(json_response['account_id']).to eq(account.id) end @@ -47,7 +47,7 @@ RSpec.describe 'Notification Settings API', type: :request do as: :json expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body agent.reload expect(json_response['user_id']).to eq(agent.id) expect(json_response['account_id']).to eq(account.id) diff --git a/spec/controllers/api/v1/accounts/notifications_controller_spec.rb b/spec/controllers/api/v1/accounts/notifications_controller_spec.rb index 4429e39e7..99baf1b25 100644 --- a/spec/controllers/api/v1/accounts/notifications_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/notifications_controller_spec.rb @@ -22,7 +22,7 @@ RSpec.describe 'Notifications API', type: :request do headers: admin.create_new_auth_token, as: :json - response_json = JSON.parse(response.body) + response_json = response.parsed_body expect(response).to have_http_status(:success) expect(response.body).to include(notification1.notification_type) expect(response_json['data']['meta']['unread_count']).to eq 2 @@ -121,7 +121,7 @@ RSpec.describe 'Notifications API', type: :request do headers: admin.create_new_auth_token, as: :json - response_json = JSON.parse(response.body) + response_json = response.parsed_body expect(response).to have_http_status(:success) expect(response_json).to eq 2 end diff --git a/spec/controllers/api/v1/accounts/portals_controller_spec.rb b/spec/controllers/api/v1/accounts/portals_controller_spec.rb index 2875f1a29..2210a5cd5 100644 --- a/spec/controllers/api/v1/accounts/portals_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/portals_controller_spec.rb @@ -26,7 +26,7 @@ RSpec.describe 'Api::V1::Accounts::Portals', type: :request do headers: agent.create_new_auth_token expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['payload'].length).to be 2 expect(json_response['payload'][0]['id']).to be portal.id end @@ -48,7 +48,7 @@ RSpec.describe 'Api::V1::Accounts::Portals', type: :request do headers: agent.create_new_auth_token expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['name']).to eq portal.name expect(json_response['meta']['all_articles_count']).to eq 0 end @@ -65,7 +65,7 @@ RSpec.describe 'Api::V1::Accounts::Portals', type: :request do headers: agent.create_new_auth_token expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['name']).to eq portal.name expect(json_response['meta']['all_articles_count']).to eq 2 expect(json_response['meta']['mine_articles_count']).to eq 1 @@ -98,7 +98,7 @@ RSpec.describe 'Api::V1::Accounts::Portals', type: :request do headers: admin.create_new_auth_token expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['name']).to eql('test_portal') expect(json_response['custom_domain']).to eql('support.chatwoot.dev') end @@ -130,7 +130,7 @@ RSpec.describe 'Api::V1::Accounts::Portals', type: :request do headers: admin.create_new_auth_token expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['name']).to eql(portal_params[:portal][:name]) expect(json_response['config']).to eql({ 'allowed_locales' => [{ 'articles_count' => 0, 'categories_count' => 0, 'code' => 'en' }, { 'articles_count' => 0, 'categories_count' => 0, 'code' => 'es' }] }) @@ -150,7 +150,7 @@ RSpec.describe 'Api::V1::Accounts::Portals', type: :request do headers: admin.create_new_auth_token expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['archived']).to eql(portal_params[:portal][:archived]) portal.reload @@ -204,7 +204,7 @@ RSpec.describe 'Api::V1::Accounts::Portals', type: :request do headers: admin.create_new_auth_token expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(portal.reload.member_ids).to include(agent_1.id) expect(json_response['portal_members'].length).to be(3) end @@ -221,7 +221,7 @@ RSpec.describe 'Api::V1::Accounts::Portals', type: :request do expect(response).to have_http_status(:success) - blob = JSON.parse(response.body) + blob = response.parsed_body expect(blob['blob_key']).to be_present expect(blob['blob_id']).to be_present diff --git a/spec/controllers/api/v1/accounts/search_controller_spec.rb b/spec/controllers/api/v1/accounts/search_controller_spec.rb index 9081c0d4c..b5644cebf 100644 --- a/spec/controllers/api/v1/accounts/search_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/search_controller_spec.rb @@ -33,7 +33,7 @@ RSpec.describe 'Search', type: :request do response_data = JSON.parse(response.body, symbolize_names: true) expect(response_data[:payload][:messages].first[:content]).to eq 'test2' - expect(response_data[:payload].keys).to match_array [:contacts, :conversations, :messages] + expect(response_data[:payload].keys).to contain_exactly(:contacts, :conversations, :messages) expect(response_data[:payload][:messages].length).to eq 2 expect(response_data[:payload][:conversations].length).to eq 1 expect(response_data[:payload][:contacts].length).to eq 1 @@ -60,7 +60,7 @@ RSpec.describe 'Search', type: :request do expect(response).to have_http_status(:success) response_data = JSON.parse(response.body, symbolize_names: true) - expect(response_data[:payload].keys).to match_array [:contacts] + expect(response_data[:payload].keys).to contain_exactly(:contacts) expect(response_data[:payload][:contacts].length).to eq 1 end end @@ -85,7 +85,7 @@ RSpec.describe 'Search', type: :request do expect(response).to have_http_status(:success) response_data = JSON.parse(response.body, symbolize_names: true) - expect(response_data[:payload].keys).to match_array [:conversations] + expect(response_data[:payload].keys).to contain_exactly(:conversations) expect(response_data[:payload][:conversations].length).to eq 1 end end @@ -110,7 +110,7 @@ RSpec.describe 'Search', type: :request do expect(response).to have_http_status(:success) response_data = JSON.parse(response.body, symbolize_names: true) - expect(response_data[:payload].keys).to match_array [:messages] + expect(response_data[:payload].keys).to contain_exactly(:messages) expect(response_data[:payload][:messages].length).to eq 2 end end diff --git a/spec/controllers/api/v1/accounts/team_members_controller_spec.rb b/spec/controllers/api/v1/accounts/team_members_controller_spec.rb index 6643244c2..ea2ee19c5 100644 --- a/spec/controllers/api/v1/accounts/team_members_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/team_members_controller_spec.rb @@ -24,7 +24,7 @@ RSpec.describe 'Team Members API', type: :request do as: :json expect(response).to have_http_status(:success) - expect(JSON.parse(response.body).first['id']).to eq(agent.id) + expect(response.parsed_body.first['id']).to eq(agent.id) end end end @@ -65,7 +65,7 @@ RSpec.describe 'Team Members API', type: :request do as: :json expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response.count).to eq(user_ids.count - 1) end end @@ -144,7 +144,7 @@ RSpec.describe 'Team Members API', type: :request do as: :json expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response.count).to eq(user_ids.count) end @@ -157,7 +157,7 @@ RSpec.describe 'Team Members API', type: :request do as: :json expect(response).to have_http_status(:unauthorized) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['error']).to eq('Invalid User IDs') end end diff --git a/spec/controllers/api/v1/accounts/teams_controller_spec.rb b/spec/controllers/api/v1/accounts/teams_controller_spec.rb index 5c8588867..347510db6 100644 --- a/spec/controllers/api/v1/accounts/teams_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/teams_controller_spec.rb @@ -22,7 +22,7 @@ RSpec.describe 'Teams API', type: :request do as: :json expect(response).to have_http_status(:success) - expect(JSON.parse(response.body).first['id']).to eq(account.teams.first.id) + expect(response.parsed_body.first['id']).to eq(account.teams.first.id) end end end @@ -45,7 +45,7 @@ RSpec.describe 'Teams API', type: :request do as: :json expect(response).to have_http_status(:success) - expect(JSON.parse(response.body)['id']).to eq(team.id) + expect(response.parsed_body['id']).to eq(team.id) end end end diff --git a/spec/controllers/api/v1/accounts/twitter/authorizations_controller_spec.rb b/spec/controllers/api/v1/accounts/twitter/authorizations_controller_spec.rb index 1a0772243..c6cb41f67 100644 --- a/spec/controllers/api/v1/accounts/twitter/authorizations_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/twitter/authorizations_controller_spec.rb @@ -39,7 +39,7 @@ RSpec.describe 'Twitter Authorization API', type: :request do as: :json expect(response).to have_http_status(:success) - expect(JSON.parse(response.body)['url']).to include('test_token') + expect(response.parsed_body['url']).to include('test_token') end end end diff --git a/spec/controllers/api/v1/accounts/webhook_controller_spec.rb b/spec/controllers/api/v1/accounts/webhook_controller_spec.rb index ae1adfa77..3a68d8921 100644 --- a/spec/controllers/api/v1/accounts/webhook_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/webhook_controller_spec.rb @@ -23,7 +23,7 @@ RSpec.describe 'Webhooks API', type: :request do headers: administrator.create_new_auth_token, as: :json expect(response).to have_http_status(:success) - expect(JSON.parse(response.body)['payload']['webhooks'].count).to eql account.webhooks.count + expect(response.parsed_body['payload']['webhooks'].count).to eql account.webhooks.count end end end @@ -46,7 +46,7 @@ RSpec.describe 'Webhooks API', type: :request do as: :json expect(response).to have_http_status(:success) - expect(JSON.parse(response.body)['payload']['webhook']['url']).to eql 'https://hello.com' + expect(response.parsed_body['payload']['webhook']['url']).to eql 'https://hello.com' end it 'throws error when invalid url provided' do @@ -55,7 +55,7 @@ RSpec.describe 'Webhooks API', type: :request do headers: administrator.create_new_auth_token, as: :json expect(response).to have_http_status(:unprocessable_entity) - expect(JSON.parse(response.body)['message']).to eql 'Url is invalid' + expect(response.parsed_body['message']).to eql 'Url is invalid' end it 'throws error if subscription events are invalid' do @@ -64,7 +64,7 @@ RSpec.describe 'Webhooks API', type: :request do headers: administrator.create_new_auth_token, as: :json expect(response).to have_http_status(:unprocessable_entity) - expect(JSON.parse(response.body)['message']).to eql 'Subscriptions Invalid events' + expect(response.parsed_body['message']).to eql 'Subscriptions Invalid events' end it 'throws error if subscription events are empty' do @@ -73,7 +73,7 @@ RSpec.describe 'Webhooks API', type: :request do headers: administrator.create_new_auth_token, as: :json expect(response).to have_http_status(:unprocessable_entity) - expect(JSON.parse(response.body)['message']).to eql 'Subscriptions Invalid events' + expect(response.parsed_body['message']).to eql 'Subscriptions Invalid events' end it 'use default if subscription events are nil' do @@ -83,7 +83,7 @@ RSpec.describe 'Webhooks API', type: :request do as: :json expect(response).to have_http_status(:ok) expect( - JSON.parse(response.body)['payload']['webhook']['subscriptions'] + response.parsed_body['payload']['webhook']['subscriptions'] ).to eql %w[conversation_status_changed conversation_updated conversation_created contact_created contact_updated message_created message_updated webwidget_triggered] end @@ -107,7 +107,7 @@ RSpec.describe 'Webhooks API', type: :request do headers: administrator.create_new_auth_token, as: :json expect(response).to have_http_status(:success) - expect(JSON.parse(response.body)['payload']['webhook']['url']).to eql 'https://hello.com' + expect(response.parsed_body['payload']['webhook']['url']).to eql 'https://hello.com' end end end diff --git a/spec/controllers/api/v1/accounts_controller_spec.rb b/spec/controllers/api/v1/accounts_controller_spec.rb index 2e402e54e..6b21cfbb2 100644 --- a/spec/controllers/api/v1/accounts_controller_spec.rb +++ b/spec/controllers/api/v1/accounts_controller_spec.rb @@ -149,7 +149,7 @@ RSpec.describe 'Accounts API', type: :request do as: :json expect(response).to have_http_status(:success) - expect(JSON.parse(response.body)['cache_keys'].keys).to match_array(%w[label inbox team]) + expect(response.parsed_body['cache_keys'].keys).to match_array(%w[label inbox team]) end end @@ -206,7 +206,7 @@ RSpec.describe 'Accounts API', type: :request do as: :json expect(response).to have_http_status(:unprocessable_entity) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['message']).to eq('Name is too long (maximum is 255 characters)') end end diff --git a/spec/controllers/api/v1/notification_subscriptions_controller_spec.rb b/spec/controllers/api/v1/notification_subscriptions_controller_spec.rb index 942153dfd..cb4366019 100644 --- a/spec/controllers/api/v1/notification_subscriptions_controller_spec.rb +++ b/spec/controllers/api/v1/notification_subscriptions_controller_spec.rb @@ -31,7 +31,7 @@ RSpec.describe 'Notifications Subscriptions API', type: :request do as: :json expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['subscription_type']).to eq('browser_push') expect(json_response['subscription_attributes']['auth']).to eq('test') end @@ -53,7 +53,7 @@ RSpec.describe 'Notifications Subscriptions API', type: :request do as: :json expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['id']).to eq(subscription.id) end @@ -74,7 +74,7 @@ RSpec.describe 'Notifications Subscriptions API', type: :request do as: :json expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['id']).to eq(subscription.id) expect(json_response['user_id']).to eq(agent.id) end diff --git a/spec/controllers/api/v1/profiles_controller_spec.rb b/spec/controllers/api/v1/profiles_controller_spec.rb index 789e995b8..4feb359c6 100644 --- a/spec/controllers/api/v1/profiles_controller_spec.rb +++ b/spec/controllers/api/v1/profiles_controller_spec.rb @@ -21,7 +21,7 @@ RSpec.describe 'Profile API', type: :request do as: :json expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['id']).to eq(agent.id) expect(json_response['email']).to eq(agent.email) expect(json_response['access_token']).to eq(agent.access_token.token) @@ -50,7 +50,7 @@ RSpec.describe 'Profile API', type: :request do as: :json expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body agent.reload expect(json_response['id']).to eq(agent.id) expect(json_response['name']).to eq(agent.name) @@ -64,7 +64,7 @@ RSpec.describe 'Profile API', type: :request do as: :json expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body agent.reload expect(json_response['id']).to eq(agent.id) expect(json_response['name']).to eq(agent.name) @@ -99,7 +99,7 @@ RSpec.describe 'Profile API', type: :request do as: :json expect(response).to have_http_status(:unprocessable_entity) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['message']).to eq('Name is too long (maximum is 255 characters)') end @@ -123,7 +123,7 @@ RSpec.describe 'Profile API', type: :request do as: :json expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['ui_settings']['is_contact_sidebar_open']).to be(false) end end @@ -159,7 +159,7 @@ RSpec.describe 'Profile API', type: :request do context 'when it is an authenticated user' do before do - agent.avatar.attach(io: File.open(Rails.root.join('spec/assets/avatar.png')), filename: 'avatar.png', content_type: 'image/png') + agent.avatar.attach(io: Rails.root.join('spec/assets/avatar.png').open, filename: 'avatar.png', content_type: 'image/png') end it 'deletes the agent avatar' do @@ -191,7 +191,7 @@ RSpec.describe 'Profile API', type: :request do as: :json expect(response).to have_http_status(:success) - expect(::OnlineStatusTracker.get_status(account.id, agent.id)).to eq('busy') + expect(OnlineStatusTracker.get_status(account.id, agent.id)).to eq('busy') end end end @@ -214,7 +214,7 @@ RSpec.describe 'Profile API', type: :request do as: :json expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['accounts'].first['auto_offline']).to be(false) end end diff --git a/spec/controllers/api/v1/widget/campaigns_controller_spec.rb b/spec/controllers/api/v1/widget/campaigns_controller_spec.rb index 11248769f..602fa96b7 100644 --- a/spec/controllers/api/v1/widget/campaigns_controller_spec.rb +++ b/spec/controllers/api/v1/widget/campaigns_controller_spec.rb @@ -14,7 +14,7 @@ RSpec.describe '/api/v1/widget/campaigns', type: :request do get '/api/v1/widget/campaigns', params: params expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response.length).to eq 1 expect(json_response.pluck('id')).to include(campaign_1.display_id) expect(json_response.pluck('id')).not_to include(campaign_2.display_id) diff --git a/spec/controllers/api/v1/widget/configs_controller_spec.rb b/spec/controllers/api/v1/widget/configs_controller_spec.rb index 4c4cef2c9..6946af3f1 100644 --- a/spec/controllers/api/v1/widget/configs_controller_spec.rb +++ b/spec/controllers/api/v1/widget/configs_controller_spec.rb @@ -6,7 +6,7 @@ RSpec.describe '/api/v1/widget/config', type: :request do let!(:contact) { create(:contact, account: account) } let(:contact_inbox) { create(:contact_inbox, contact: contact, inbox: web_widget.inbox) } let(:payload) { { source_id: contact_inbox.source_id, inbox_id: web_widget.inbox.id } } - let(:token) { ::Widget::TokenService.new(payload: payload).generate_token } + let(:token) { Widget::TokenService.new(payload: payload).generate_token } describe 'POST /api/v1/widget/config' do let(:params) { { website_token: web_widget.website_token } } @@ -28,7 +28,7 @@ RSpec.describe '/api/v1/widget/config', type: :request do end.to change(Contact, :count).by(1) expect(response).to have_http_status(:success) - response_data = JSON.parse(response.body) + response_data = response.parsed_body expect(response_data.keys).to include(*response_keys) end end @@ -43,7 +43,7 @@ RSpec.describe '/api/v1/widget/config', type: :request do end.not_to change(Contact, :count) expect(response).to have_http_status(:success) - response_data = JSON.parse(response.body) + response_data = response.parsed_body expect(response_data.keys).to include(*response_keys) expect(response_data['contact']['pubsub_token']).to eq(contact_inbox.pubsub_token) end @@ -70,7 +70,7 @@ RSpec.describe '/api/v1/widget/config', type: :request do end.to change(Contact, :count).by(1) expect(response).to have_http_status(:success) - response_data = JSON.parse(response.body) + response_data = response.parsed_body expect(response_data.keys).to include(*response_keys) end end diff --git a/spec/controllers/api/v1/widget/contacts_controller_spec.rb b/spec/controllers/api/v1/widget/contacts_controller_spec.rb index bdac8fb24..336d9d9ca 100644 --- a/spec/controllers/api/v1/widget/contacts_controller_spec.rb +++ b/spec/controllers/api/v1/widget/contacts_controller_spec.rb @@ -6,7 +6,7 @@ RSpec.describe '/api/v1/widget/contacts', type: :request do let(:contact) { create(:contact, account: account, email: 'test@test.com', phone_number: '+745623239') } let(:contact_inbox) { create(:contact_inbox, contact: contact, inbox: web_widget.inbox) } let(:payload) { { source_id: contact_inbox.source_id, inbox_id: web_widget.inbox.id } } - let(:token) { ::Widget::TokenService.new(payload: payload).generate_token } + let(:token) { Widget::TokenService.new(payload: payload).generate_token } describe 'PATCH /api/v1/widget/contact' do let(:params) { { website_token: web_widget.website_token, identifier: 'test' } } @@ -47,7 +47,7 @@ RSpec.describe '/api/v1/widget/contacts', type: :request do params: params.merge({ phone_number: '45623239' }), headers: { 'X-Auth-Token' => token }, as: :json - body = JSON.parse(response.body) + body = response.parsed_body expect(body['phone_number']).to eq('+745623239') expect(response).to have_http_status(:success) end @@ -57,7 +57,7 @@ RSpec.describe '/api/v1/widget/contacts', type: :request do params: params.merge({ phone_number: '+245623239' }), headers: { 'X-Auth-Token' => token }, as: :json - body = JSON.parse(response.body) + body = response.parsed_body expect(body['phone_number']).to eq('+245623239') expect(response).to have_http_status(:success) end @@ -67,7 +67,7 @@ RSpec.describe '/api/v1/widget/contacts', type: :request do params: params.merge({ email: 'test@' }), headers: { 'X-Auth-Token' => token }, as: :json - body = JSON.parse(response.body) + body = response.parsed_body expect(body['email']).to eq('test@test.com') expect(response).to have_http_status(:success) end @@ -77,7 +77,7 @@ RSpec.describe '/api/v1/widget/contacts', type: :request do params: params.merge({ email: 'test-1@test.com' }), headers: { 'X-Auth-Token' => token }, as: :json - body = JSON.parse(response.body) + body = response.parsed_body expect(body['email']).to eq('test-1@test.com') expect(response).to have_http_status(:success) end @@ -101,7 +101,7 @@ RSpec.describe '/api/v1/widget/contacts', type: :request do headers: { 'X-Auth-Token' => token }, as: :json - body = JSON.parse(response.body) + body = response.parsed_body expect(body['id']).not_to eq(contact.id) expect(body['widget_auth_token']).not_to be_nil expect(Contact.find(body['id']).contact_inboxes.first.hmac_verified?).to be(true) diff --git a/spec/controllers/api/v1/widget/conversations_controller_spec.rb b/spec/controllers/api/v1/widget/conversations_controller_spec.rb index d76707bbc..40aed4616 100644 --- a/spec/controllers/api/v1/widget/conversations_controller_spec.rb +++ b/spec/controllers/api/v1/widget/conversations_controller_spec.rb @@ -8,9 +8,9 @@ RSpec.describe '/api/v1/widget/conversations/toggle_typing', type: :request do let(:second_session) { create(:contact_inbox, contact: contact, inbox: web_widget.inbox) } let!(:conversation) { create(:conversation, contact: contact, account: account, inbox: web_widget.inbox, contact_inbox: contact_inbox) } let(:payload) { { source_id: contact_inbox.source_id, inbox_id: web_widget.inbox.id } } - let(:token) { ::Widget::TokenService.new(payload: payload).generate_token } + let(:token) { Widget::TokenService.new(payload: payload).generate_token } let(:token_without_conversation) do - ::Widget::TokenService.new(payload: { source_id: second_session.source_id, inbox_id: web_widget.inbox.id }).generate_token + Widget::TokenService.new(payload: { source_id: second_session.source_id, inbox_id: web_widget.inbox.id }).generate_token end describe 'GET /api/v1/widget/conversations' do @@ -23,7 +23,7 @@ RSpec.describe '/api/v1/widget/conversations/toggle_typing', type: :request do as: :json expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['id']).to eq(conversation.display_id) expect(json_response['status']).to eq(conversation.status) @@ -35,7 +35,7 @@ RSpec.describe '/api/v1/widget/conversations/toggle_typing', type: :request do allow(Rails.configuration.dispatcher).to receive(:dispatch) payload = { source_id: 'invalid source id', inbox_id: web_widget.inbox.id } - token = ::Widget::TokenService.new(payload: payload).generate_token + token = Widget::TokenService.new(payload: payload).generate_token get '/api/v1/widget/conversations', headers: { 'X-Auth-Token' => token }, params: { website_token: web_widget.website_token }, @@ -65,7 +65,7 @@ RSpec.describe '/api/v1/widget/conversations/toggle_typing', type: :request do as: :json expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['id']).not_to be_nil expect(json_response['contact']['email']).to eq 'contact-email@chatwoot.com' expect(json_response['contact']['phone_number']).to eq '+919745313456' @@ -89,7 +89,7 @@ RSpec.describe '/api/v1/widget/conversations/toggle_typing', type: :request do as: :json expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['id']).not_to be_nil expect(json_response['contact']['email']).to be_nil expect(json_response['contact']['name']).to eq 'alphy' @@ -116,7 +116,7 @@ RSpec.describe '/api/v1/widget/conversations/toggle_typing', type: :request do as: :json expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['id']).not_to be_nil expect(json_response['contact']['email']).to eq existing_contact.email expect(json_response['contact']['name']).not_to eq 'contact-name' @@ -144,7 +144,7 @@ RSpec.describe '/api/v1/widget/conversations/toggle_typing', type: :request do as: :json expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['contact']['phone_number']).to be_nil end end diff --git a/spec/controllers/api/v1/widget/direct_uploads_controller_spec.rb b/spec/controllers/api/v1/widget/direct_uploads_controller_spec.rb index 0db922370..bf1da7d37 100644 --- a/spec/controllers/api/v1/widget/direct_uploads_controller_spec.rb +++ b/spec/controllers/api/v1/widget/direct_uploads_controller_spec.rb @@ -7,7 +7,7 @@ RSpec.describe '/api/v1/widget/direct_uploads', type: :request do let(:contact_inbox) { create(:contact_inbox, contact: contact, inbox: web_widget.inbox) } let(:conversation) { create(:conversation, contact: contact, account: account, inbox: web_widget.inbox, contact_inbox: contact_inbox) } let(:payload) { { source_id: contact_inbox.source_id, inbox_id: web_widget.inbox.id } } - let(:token) { ::Widget::TokenService.new(payload: payload).generate_token } + let(:token) { Widget::TokenService.new(payload: payload).generate_token } describe 'POST /api/v1/widget/direct_uploads' do context 'when post request is made' do @@ -31,7 +31,7 @@ RSpec.describe '/api/v1/widget/direct_uploads', type: :request do headers: { 'X-Auth-Token' => token } expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['content_type']).to eq('image/png') end end diff --git a/spec/controllers/api/v1/widget/events_controller_spec.rb b/spec/controllers/api/v1/widget/events_controller_spec.rb index da4136680..fdc8cb4fa 100644 --- a/spec/controllers/api/v1/widget/events_controller_spec.rb +++ b/spec/controllers/api/v1/widget/events_controller_spec.rb @@ -6,7 +6,7 @@ RSpec.describe '/api/v1/widget/events', type: :request do let(:contact) { create(:contact, account: account) } let(:contact_inbox) { create(:contact_inbox, contact: contact, inbox: web_widget.inbox) } let(:payload) { { source_id: contact_inbox.source_id, inbox_id: web_widget.inbox.id } } - let(:token) { ::Widget::TokenService.new(payload: payload).generate_token } + let(:token) { Widget::TokenService.new(payload: payload).generate_token } describe 'POST /api/v1/widget/events' do let(:params) { { website_token: web_widget.website_token, name: 'webwidget.triggered', event_info: { test_id: 'test' } } } diff --git a/spec/controllers/api/v1/widget/inbox_members_controller_spec.rb b/spec/controllers/api/v1/widget/inbox_members_controller_spec.rb index dc7bd2ce9..8e2a3897a 100644 --- a/spec/controllers/api/v1/widget/inbox_members_controller_spec.rb +++ b/spec/controllers/api/v1/widget/inbox_members_controller_spec.rb @@ -19,7 +19,7 @@ RSpec.describe '/api/v1/widget/inbox_members', type: :request do get '/api/v1/widget/inbox_members', params: params expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['payload'].length).to eq 2 end end diff --git a/spec/controllers/api/v1/widget/integrations/dyte_controller_spec.rb b/spec/controllers/api/v1/widget/integrations/dyte_controller_spec.rb index 5d5ace90b..8479fcda5 100644 --- a/spec/controllers/api/v1/widget/integrations/dyte_controller_spec.rb +++ b/spec/controllers/api/v1/widget/integrations/dyte_controller_spec.rb @@ -7,7 +7,7 @@ RSpec.describe '/api/v1/widget/integrations/dyte', type: :request do let(:contact_inbox) { create(:contact_inbox, contact: contact, inbox: web_widget.inbox) } let(:conversation) { create(:conversation, contact: contact, account: account, inbox: web_widget.inbox, contact_inbox: contact_inbox) } let(:payload) { { source_id: contact_inbox.source_id, inbox_id: web_widget.inbox.id } } - let(:token) { ::Widget::TokenService.new(payload: payload).generate_token } + let(:token) { Widget::TokenService.new(payload: payload).generate_token } let(:message) { create(:message, conversation: conversation, account: account, inbox: conversation.inbox) } let!(:integration_message) do create(:message, content_type: 'integrations', @@ -39,7 +39,7 @@ RSpec.describe '/api/v1/widget/integrations/dyte', type: :request do as: :json expect(response).to have_http_status(:unprocessable_entity) - response_body = JSON.parse(response.body) + response_body = response.parsed_body expect(response_body['error']).to eq('Invalid message type. Action not permitted') end end @@ -61,7 +61,7 @@ RSpec.describe '/api/v1/widget/integrations/dyte', type: :request do as: :json expect(response).to have_http_status(:success) - response_body = JSON.parse(response.body) + response_body = response.parsed_body expect(response_body['authResponse']).to eq( { 'userAdded' => true, 'id' => 'random_uuid', 'auth_token' => 'json-web-token' diff --git a/spec/controllers/api/v1/widget/labels_controller_spec.rb b/spec/controllers/api/v1/widget/labels_controller_spec.rb index fe242c29b..42572f256 100644 --- a/spec/controllers/api/v1/widget/labels_controller_spec.rb +++ b/spec/controllers/api/v1/widget/labels_controller_spec.rb @@ -7,7 +7,7 @@ RSpec.describe '/api/v1/widget/labels', type: :request do let(:contact_inbox) { create(:contact_inbox, contact: contact, inbox: web_widget.inbox) } let!(:conversation) { create(:conversation, contact: contact, account: account, inbox: web_widget.inbox, contact_inbox: contact_inbox) } let(:payload) { { source_id: contact_inbox.source_id, inbox_id: web_widget.inbox.id } } - let(:token) { ::Widget::TokenService.new(payload: payload).generate_token } + let(:token) { Widget::TokenService.new(payload: payload).generate_token } describe 'POST /api/v1/widget/labels' do let(:params) { { website_token: web_widget.website_token, label: 'customer-support' } } diff --git a/spec/controllers/api/v1/widget/messages_controller_spec.rb b/spec/controllers/api/v1/widget/messages_controller_spec.rb index 06c0b46a9..2525d79dd 100644 --- a/spec/controllers/api/v1/widget/messages_controller_spec.rb +++ b/spec/controllers/api/v1/widget/messages_controller_spec.rb @@ -7,7 +7,7 @@ RSpec.describe '/api/v1/widget/messages', type: :request do let(:contact_inbox) { create(:contact_inbox, contact: contact, inbox: web_widget.inbox) } let(:conversation) { create(:conversation, contact: contact, account: account, inbox: web_widget.inbox, contact_inbox: contact_inbox) } let(:payload) { { source_id: contact_inbox.source_id, inbox_id: web_widget.inbox.id } } - let(:token) { ::Widget::TokenService.new(payload: payload).generate_token } + let(:token) { Widget::TokenService.new(payload: payload).generate_token } before do |example| 2.times.each { create(:message, account: account, inbox: web_widget.inbox, conversation: conversation) } unless example.metadata[:skip_before] @@ -22,7 +22,7 @@ RSpec.describe '/api/v1/widget/messages', type: :request do as: :json expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body # 2 messages created + 2 messages by the email hook expect(json_response['payload'].length).to eq(4) expect(json_response['meta']).not_to be_empty @@ -35,7 +35,7 @@ RSpec.describe '/api/v1/widget/messages', type: :request do as: :json expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['payload'].length).to eq(0) end end @@ -52,7 +52,7 @@ RSpec.describe '/api/v1/widget/messages', type: :request do as: :json expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['content']).to eq(message_params[:content]) end @@ -66,7 +66,7 @@ RSpec.describe '/api/v1/widget/messages', type: :request do expect(response).to have_http_status(:unprocessable_entity) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['message']).to eq('Content is too long (maximum is 150000 characters)') end @@ -79,7 +79,7 @@ RSpec.describe '/api/v1/widget/messages', type: :request do headers: { 'X-Auth-Token' => token } expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['content']).to eq(message_params[:content]) expect(conversation.messages.last.attachments.first.file.present?).to be(true) diff --git a/spec/controllers/api/v2/accounts/report_controller_spec.rb b/spec/controllers/api/v2/accounts/report_controller_spec.rb index 8b2c51450..574330df3 100644 --- a/spec/controllers/api/v2/accounts/report_controller_spec.rb +++ b/spec/controllers/api/v2/accounts/report_controller_spec.rb @@ -53,7 +53,7 @@ RSpec.describe 'Reports API', type: :request do as: :json expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body current_day_metric = json_response.select { |x| x['timestamp'] == start_of_today } expect(current_day_metric.length).to eq(1) @@ -77,7 +77,7 @@ RSpec.describe 'Reports API', type: :request do as: :json expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['open']).to eq(11) expect(json_response['unattended']).to eq(11) @@ -99,7 +99,7 @@ RSpec.describe 'Reports API', type: :request do expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response.blank?).to be false user_metrics = json_response.find { |item| item['name'] == admin[:name] } expect(user_metrics.present?).to be true @@ -140,7 +140,7 @@ RSpec.describe 'Reports API', type: :request do headers: admin.create_new_auth_token, as: :json - json_response = JSON.parse(response.body) + json_response = response.parsed_body user_metrics = json_response.find { |item| item['name'] == agent[:name] } expect(user_metrics.present?).to be true @@ -184,7 +184,7 @@ RSpec.describe 'Reports API', type: :request do as: :json expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['conversations_count']).to eq(10) end @@ -254,7 +254,7 @@ RSpec.describe 'Reports API', type: :request do expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['conversations_count']).to eq(1) end end diff --git a/spec/controllers/installation/onboarding_controller_spec.rb b/spec/controllers/installation/onboarding_controller_spec.rb index 3ab22db18..37a2d8822 100644 --- a/spec/controllers/installation/onboarding_controller_spec.rb +++ b/spec/controllers/installation/onboarding_controller_spec.rb @@ -6,7 +6,7 @@ RSpec.describe 'Installation::Onboarding API', type: :request do describe 'GET /installation/onboarding' do context 'when CHATWOOT_INSTALLATION_ONBOARDING redis key is not set' do it 'redirects back' do - expect(::Redis::Alfred.get(::Redis::Alfred::CHATWOOT_INSTALLATION_ONBOARDING)).to be_nil + expect(Redis::Alfred.get(Redis::Alfred::CHATWOOT_INSTALLATION_ONBOARDING)).to be_nil get '/installation/onboarding' expect(response).to have_http_status(:redirect) end @@ -14,10 +14,10 @@ RSpec.describe 'Installation::Onboarding API', type: :request do context 'when CHATWOOT_INSTALLATION_ONBOARDING redis key is set' do it 'returns onboarding page' do - ::Redis::Alfred.set(::Redis::Alfred::CHATWOOT_INSTALLATION_ONBOARDING, true) + Redis::Alfred.set(Redis::Alfred::CHATWOOT_INSTALLATION_ONBOARDING, true) get '/installation/onboarding' expect(response).to have_http_status(:success) - ::Redis::Alfred.delete(::Redis::Alfred::CHATWOOT_INSTALLATION_ONBOARDING) + Redis::Alfred.delete(Redis::Alfred::CHATWOOT_INSTALLATION_ONBOARDING) end end end @@ -29,17 +29,17 @@ RSpec.describe 'Installation::Onboarding API', type: :request do allow(AccountBuilder).to receive(:new).and_return(account_builder) allow(account_builder).to receive(:perform).and_return(true) allow(ChatwootHub).to receive(:register_instance).and_return(true) - ::Redis::Alfred.set(::Redis::Alfred::CHATWOOT_INSTALLATION_ONBOARDING, true) + Redis::Alfred.set(Redis::Alfred::CHATWOOT_INSTALLATION_ONBOARDING, true) end after do - ::Redis::Alfred.delete(::Redis::Alfred::CHATWOOT_INSTALLATION_ONBOARDING) + Redis::Alfred.delete(Redis::Alfred::CHATWOOT_INSTALLATION_ONBOARDING) end context 'when onboarding successfull' do it 'deletes the redis key' do post '/installation/onboarding', params: { user: {} } - expect(::Redis::Alfred.get(::Redis::Alfred::CHATWOOT_INSTALLATION_ONBOARDING)).to be_nil + expect(Redis::Alfred.get(Redis::Alfred::CHATWOOT_INSTALLATION_ONBOARDING)).to be_nil end it 'will not call register instance when checkboxes are unchecked' do @@ -57,7 +57,7 @@ RSpec.describe 'Installation::Onboarding API', type: :request do it 'does not deletes the redis key' do allow(AccountBuilder).to receive(:new).and_raise('error') post '/installation/onboarding', params: { user: {} } - expect(::Redis::Alfred.get(::Redis::Alfred::CHATWOOT_INSTALLATION_ONBOARDING)).not_to be_nil + expect(Redis::Alfred.get(Redis::Alfred::CHATWOOT_INSTALLATION_ONBOARDING)).not_to be_nil end end end diff --git a/spec/controllers/platform/api/v1/account_users_controller_spec.rb b/spec/controllers/platform/api/v1/account_users_controller_spec.rb index 9ab36b5b2..72563d8fb 100644 --- a/spec/controllers/platform/api/v1/account_users_controller_spec.rb +++ b/spec/controllers/platform/api/v1/account_users_controller_spec.rb @@ -47,7 +47,7 @@ RSpec.describe 'Platform Account Users API', type: :request do headers: { api_access_token: platform_app.access_token.token }, as: :json expect(response).to have_http_status(:success) - data = JSON.parse(response.body) + data = response.parsed_body expect(data['user_id']).to eq(user.id) end @@ -60,7 +60,7 @@ RSpec.describe 'Platform Account Users API', type: :request do headers: { api_access_token: platform_app.access_token.token }, as: :json expect(response).to have_http_status(:success) - data = JSON.parse(response.body) + data = response.parsed_body expect(data['role']).to eq('administrator') end end diff --git a/spec/controllers/platform/api/v1/accounts_controller_spec.rb b/spec/controllers/platform/api/v1/accounts_controller_spec.rb index c41464f1f..db1713bb6 100644 --- a/spec/controllers/platform/api/v1/accounts_controller_spec.rb +++ b/spec/controllers/platform/api/v1/accounts_controller_spec.rb @@ -39,7 +39,7 @@ RSpec.describe 'Platform Accounts API', type: :request do expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['name']).to eq('Test Account') expect(json_response['locale']).to eq('es') expect(json_response['features']['agent_management']).to be(true) @@ -59,7 +59,7 @@ RSpec.describe 'Platform Accounts API', type: :request do disable_branding: false } }, headers: { api_access_token: platform_app.access_token.token }, as: :json - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['name']).to include('Test Account') expect(json_response['features']['inbox_management']).to be(true) expect(json_response['features']['ip_lookup']).to be(true) diff --git a/spec/controllers/platform/api/v1/agent_bots_controller_spec.rb b/spec/controllers/platform/api/v1/agent_bots_controller_spec.rb index d56e1dfb9..030d694ff 100644 --- a/spec/controllers/platform/api/v1/agent_bots_controller_spec.rb +++ b/spec/controllers/platform/api/v1/agent_bots_controller_spec.rb @@ -24,7 +24,7 @@ RSpec.describe 'Platform Agent Bot API', type: :request do it 'returns unauthorized when its not a permissible object' do get '/platform/api/v1/agent_bots', headers: { api_access_token: platform_app.access_token.token }, as: :json expect(response).to have_http_status(:success) - data = JSON.parse(response.body) + data = response.parsed_body expect(data.length).to eq(0) end @@ -35,7 +35,7 @@ RSpec.describe 'Platform Agent Bot API', type: :request do headers: { api_access_token: platform_app.access_token.token }, as: :json expect(response).to have_http_status(:success) - data = JSON.parse(response.body) + data = response.parsed_body expect(data.length).to eq(1) end end @@ -71,7 +71,7 @@ RSpec.describe 'Platform Agent Bot API', type: :request do headers: { api_access_token: platform_app.access_token.token }, as: :json expect(response).to have_http_status(:success) - data = JSON.parse(response.body) + data = response.parsed_body expect(data['name']).to eq(agent_bot.name) end end @@ -100,7 +100,7 @@ RSpec.describe 'Platform Agent Bot API', type: :request do headers: { api_access_token: platform_app.access_token.token }, as: :json expect(response).to have_http_status(:success) - data = JSON.parse(response.body) + data = response.parsed_body expect(data['name']).to eq('test') expect(platform_app.platform_app_permissibles.first.permissible_id).to eq data['id'] end @@ -137,7 +137,7 @@ RSpec.describe 'Platform Agent Bot API', type: :request do headers: { api_access_token: platform_app.access_token.token }, as: :json expect(response).to have_http_status(:success) - data = JSON.parse(response.body) + data = response.parsed_body expect(data['name']).to eq('test123') end end diff --git a/spec/controllers/platform/api/v1/users_controller_spec.rb b/spec/controllers/platform/api/v1/users_controller_spec.rb index edd91f36b..2ebb0d1a4 100644 --- a/spec/controllers/platform/api/v1/users_controller_spec.rb +++ b/spec/controllers/platform/api/v1/users_controller_spec.rb @@ -33,7 +33,7 @@ RSpec.describe 'Platform Users API', type: :request do headers: { api_access_token: platform_app.access_token.token }, as: :json expect(response).to have_http_status(:success) - data = JSON.parse(response.body) + data = response.parsed_body expect(data['email']).to eq(user.email) expect(data['custom_attributes']['test']).to eq('test') end @@ -70,7 +70,7 @@ RSpec.describe 'Platform Users API', type: :request do headers: { api_access_token: platform_app.access_token.token }, as: :json expect(response).to have_http_status(:success) - data = JSON.parse(response.body) + data = response.parsed_body expect(data['url']).to include('email=dev%2Btesting%40chatwoot.com&sso_auth_token=') end end @@ -103,7 +103,7 @@ RSpec.describe 'Platform Users API', type: :request do end.not_to enqueue_mail expect(response).to have_http_status(:success) - data = JSON.parse(response.body) + data = response.parsed_body expect(data).to match( hash_including( 'name' => 'test', @@ -118,7 +118,7 @@ RSpec.describe 'Platform Users API', type: :request do post '/platform/api/v1/users/', params: { name: 'test', email: 'TesT@test.com', password: 'Password1!' }, headers: { api_access_token: platform_app.access_token.token }, as: :json - data = JSON.parse(response.body) + data = response.parsed_body expect(data['message']).to eq('Email has already been taken') end @@ -128,7 +128,7 @@ RSpec.describe 'Platform Users API', type: :request do headers: { api_access_token: platform_app.access_token.token }, as: :json expect(response).to have_http_status(:success) - data = JSON.parse(response.body) + data = response.parsed_body expect(data['name']).to eq('old test') expect(platform_app.platform_app_permissibles.first.permissible_id).to eq data['id'] end @@ -167,7 +167,7 @@ RSpec.describe 'Platform Users API', type: :request do headers: { api_access_token: platform_app.access_token.token }, as: :json expect(response).to have_http_status(:success) - data = JSON.parse(response.body) + data = response.parsed_body expect(data['name']).to eq('test123') expect(data['email']).to eq('newtestemail@test.com') expect(data['custom_attributes']['test']).to eq('test_update') diff --git a/spec/controllers/public/api/v1/csat_survey_controller_spec.rb b/spec/controllers/public/api/v1/csat_survey_controller_spec.rb index 1cc411118..ea2a26e4b 100644 --- a/spec/controllers/public/api/v1/csat_survey_controller_spec.rb +++ b/spec/controllers/public/api/v1/csat_survey_controller_spec.rb @@ -6,7 +6,7 @@ RSpec.describe 'Public Survey Responses API', type: :request do conversation = create(:conversation) create(:message, conversation: conversation, content_type: 'input_csat') get "/public/api/v1/csat_survey/#{conversation.uuid}" - data = JSON.parse(response.body) + data = response.parsed_body expect(response).to have_http_status(:success) expect(data['conversation_id']).to eq conversation.id end @@ -30,7 +30,7 @@ RSpec.describe 'Public Survey Responses API', type: :request do params: params, as: :json expect(response).to have_http_status(:success) - data = JSON.parse(response.body) + data = response.parsed_body expect(data['conversation_id']).to eq conversation.id expect(data['csat_survey_response']['conversation_id']).to eq conversation.id expect(data['csat_survey_response']['feedback_message']).to eq 'amazing experience' diff --git a/spec/controllers/public/api/v1/inbox/conversations_controller_spec.rb b/spec/controllers/public/api/v1/inbox/conversations_controller_spec.rb index c5b7402fc..0911bdfca 100644 --- a/spec/controllers/public/api/v1/inbox/conversations_controller_spec.rb +++ b/spec/controllers/public/api/v1/inbox/conversations_controller_spec.rb @@ -11,7 +11,7 @@ RSpec.describe 'Public Inbox Contact Conversations API', type: :request do get "/public/api/v1/inboxes/#{api_channel.identifier}/contacts/#{contact_inbox.source_id}/conversations" expect(response).to have_http_status(:success) - data = JSON.parse(response.body) + data = response.parsed_body expect(data.length).to eq 1 end @@ -40,7 +40,7 @@ RSpec.describe 'Public Inbox Contact Conversations API', type: :request do post "/public/api/v1/inboxes/#{api_channel.identifier}/contacts/#{contact_inbox.source_id}/conversations" expect(response).to have_http_status(:success) - data = JSON.parse(response.body) + data = response.parsed_body expect(data['id']).not_to be_nil end end diff --git a/spec/controllers/public/api/v1/inbox/messages_controller_spec.rb b/spec/controllers/public/api/v1/inbox/messages_controller_spec.rb index 5916b7fb7..a7e055b19 100644 --- a/spec/controllers/public/api/v1/inbox/messages_controller_spec.rb +++ b/spec/controllers/public/api/v1/inbox/messages_controller_spec.rb @@ -13,7 +13,7 @@ RSpec.describe 'Public Inbox Contact Conversation Messages API', type: :request get "/public/api/v1/inboxes/#{api_channel.identifier}/contacts/#{contact_inbox.source_id}/conversations/#{conversation.display_id}/messages" expect(response).to have_http_status(:success) - data = JSON.parse(response.body) + data = response.parsed_body expect(data.length).to eq 2 end end @@ -24,7 +24,7 @@ RSpec.describe 'Public Inbox Contact Conversation Messages API', type: :request params: { content: 'hello' } expect(response).to have_http_status(:success) - data = JSON.parse(response.body) + data = response.parsed_body expect(data['content']).to eq('hello') end @@ -35,7 +35,7 @@ RSpec.describe 'Public Inbox Contact Conversation Messages API', type: :request expect(response).to have_http_status(:unprocessable_entity) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['message']).to eq('Content is too long (maximum is 150000 characters)') end @@ -46,7 +46,7 @@ RSpec.describe 'Public Inbox Contact Conversation Messages API', type: :request params: { content: 'hello', attachments: [file] } expect(response).to have_http_status(:success) - data = JSON.parse(response.body) + data = response.parsed_body expect(data['content']).to eq('hello') expect(conversation.messages.last.attachments.first.file.present?).to be(true) @@ -62,7 +62,7 @@ RSpec.describe 'Public Inbox Contact Conversation Messages API', type: :request params: { submitted_values: [{ title: 'test' }] } expect(response).to have_http_status(:success) - data = JSON.parse(response.body) + data = response.parsed_body expect(data['content_attributes']['submitted_values'].first['title']).to eq 'test' end @@ -77,7 +77,7 @@ RSpec.describe 'Public Inbox Contact Conversation Messages API', type: :request as: :json expect(response).to have_http_status(:success) - data = JSON.parse(response.body) + data = response.parsed_body expect(data['content_attributes']['submitted_values']['csat_survey_response']['feedback_message']).to eq 'amazing experience' expect(data['content_attributes']['submitted_values']['csat_survey_response']['rating']).to eq 4 end diff --git a/spec/controllers/public/api/v1/portals_controller_spec.rb b/spec/controllers/public/api/v1/portals_controller_spec.rb index 7234c62b5..2541906f1 100644 --- a/spec/controllers/public/api/v1/portals_controller_spec.rb +++ b/spec/controllers/public/api/v1/portals_controller_spec.rb @@ -22,7 +22,7 @@ RSpec.describe 'Public Portals API', type: :request do get "/hc/#{portal.slug}/en" expect(response).to have_http_status(:unauthorized) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['error']).to eql "Domain: www.example.com is not registered with us. \ Please send us an email at support@chatwoot.com with the custom domain name and account API key" diff --git a/spec/controllers/twilio/callbacks_controller_spec.rb b/spec/controllers/twilio/callbacks_controller_spec.rb index 847e9b12a..bf975be6b 100644 --- a/spec/controllers/twilio/callbacks_controller_spec.rb +++ b/spec/controllers/twilio/callbacks_controller_spec.rb @@ -5,7 +5,7 @@ RSpec.describe 'Twilio::CallbacksController', type: :request do let(:twilio_service) { instance_double(Twilio::IncomingMessageService) } before do - allow(::Twilio::IncomingMessageService).to receive(:new).and_return(twilio_service) + allow(Twilio::IncomingMessageService).to receive(:new).and_return(twilio_service) allow(twilio_service).to receive(:perform) end diff --git a/spec/controllers/twitter/callbacks_controller_spec.rb b/spec/controllers/twitter/callbacks_controller_spec.rb index 983b5c681..c2c8791a1 100644 --- a/spec/controllers/twitter/callbacks_controller_spec.rb +++ b/spec/controllers/twitter/callbacks_controller_spec.rb @@ -1,8 +1,8 @@ require 'rails_helper' RSpec.describe 'Twitter::CallbacksController', type: :request do - let(:twitter_client) { instance_double(::Twitty::Facade) } - let(:twitter_response) { instance_double(::Twitty::Response, status: '200', body: { message: 'Valid' }) } + let(:twitter_client) { instance_double(Twitty::Facade) } + let(:twitter_response) { instance_double(Twitty::Response, status: '200', body: { message: 'Valid' }) } let(:raw_response) { double } let(:user_object_rsponse) do OpenStruct.new( @@ -15,15 +15,15 @@ RSpec.describe 'Twitter::CallbacksController', type: :request do let(:webhook_service) { double } before do - allow(::Twitty::Facade).to receive(:new).and_return(twitter_client) - allow(::Redis::Alfred).to receive(:get).and_return(account.id) - allow(::Redis::Alfred).to receive(:delete).and_return('OK') + allow(Twitty::Facade).to receive(:new).and_return(twitter_client) + allow(Redis::Alfred).to receive(:get).and_return(account.id) + allow(Redis::Alfred).to receive(:delete).and_return('OK') allow(twitter_client).to receive(:access_token).and_return(twitter_response) allow(twitter_response).to receive(:raw_response).and_return(raw_response) allow(raw_response).to receive(:body).and_return('oauth_token=1&oauth_token_secret=1&user_id=100&screen_name=chatwoot') allow(twitter_client).to receive(:user_show).and_return(user_object_rsponse) allow(JSON).to receive(:parse).and_return(user_object_rsponse) - allow(::Twitter::WebhookSubscribeService).to receive(:new).and_return(webhook_service) + allow(Twitter::WebhookSubscribeService).to receive(:new).and_return(webhook_service) end describe 'GET /twitter/callback' do diff --git a/spec/controllers/webhooks/instagram_controller_spec.rb b/spec/controllers/webhooks/instagram_controller_spec.rb index 4011489a4..df5a6596d 100644 --- a/spec/controllers/webhooks/instagram_controller_spec.rb +++ b/spec/controllers/webhooks/instagram_controller_spec.rb @@ -26,8 +26,8 @@ RSpec.describe 'Webhooks::InstagramController', type: :request do let!(:dm_params) { build(:instagram_message_create_event).with_indifferent_access } it 'call the instagram events job with the params' do - allow(::Webhooks::InstagramEventsJob).to receive(:perform_later) - expect(::Webhooks::InstagramEventsJob).to receive(:perform_later) + allow(Webhooks::InstagramEventsJob).to receive(:perform_later) + expect(Webhooks::InstagramEventsJob).to receive(:perform_later) instagram_params = dm_params.merge(object: 'instagram') post '/webhooks/instagram', params: instagram_params diff --git a/spec/controllers/widgets_controller_spec.rb b/spec/controllers/widgets_controller_spec.rb index 71aaa084c..7789bb478 100644 --- a/spec/controllers/widgets_controller_spec.rb +++ b/spec/controllers/widgets_controller_spec.rb @@ -6,7 +6,7 @@ describe '/widget', type: :request do let(:contact) { create(:contact, account: account) } let(:contact_inbox) { create(:contact_inbox, contact: contact, inbox: web_widget.inbox) } let(:payload) { { source_id: contact_inbox.source_id, inbox_id: web_widget.inbox.id } } - let(:token) { ::Widget::TokenService.new(payload: payload).generate_token } + let(:token) { Widget::TokenService.new(payload: payload).generate_token } describe 'GET /widget' do it 'renders the page correctly when called with website_token' do diff --git a/spec/cypress/app_commands/activerecord_fixtures.rb b/spec/cypress/app_commands/activerecord_fixtures.rb index a891e182b..b81b7db63 100644 --- a/spec/cypress/app_commands/activerecord_fixtures.rb +++ b/spec/cypress/app_commands/activerecord_fixtures.rb @@ -7,7 +7,7 @@ if defined?(ActiveRecord) require 'active_record/fixtures' fixtures_dir ||= ActiveRecord::Tasks::DatabaseTasks.fixtures_path - fixture_files ||= Dir["#{fixtures_dir}/**/*.yml"].map { |f| f[(fixtures_dir.size + 1)..-5] } + fixture_files ||= Dir["#{fixtures_dir}/**/*.yml"].pluck((fixtures_dir.size + 1)..-5) logger.debug "loading fixtures: { dir: #{fixtures_dir}, files: #{fixture_files} }" ActiveRecord::FixtureSet.reset_cache diff --git a/spec/cypress/app_commands/log_fail.rb b/spec/cypress/app_commands/log_fail.rb index 264d9ea66..2f5ee4b1d 100644 --- a/spec/cypress/app_commands/log_fail.rb +++ b/spec/cypress/app_commands/log_fail.rb @@ -18,6 +18,6 @@ if defined?(ActiveRecord::Base) end filename = command_options.fetch('runnable_full_title', 'no title').gsub(/[^[:print:]]/, '') -File.open(Rails.root.join("log/#{filename}.json"), 'w+') do |file| +Rails.root.join("log/#{filename}.json").open('w+') do |file| file << JSON.pretty_generate(json_result) end diff --git a/spec/drops/contact_drop_spec.rb b/spec/drops/contact_drop_spec.rb index 644d7e3bc..e83ebb377 100644 --- a/spec/drops/contact_drop_spec.rb +++ b/spec/drops/contact_drop_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe ::ContactDrop do +describe ContactDrop do subject(:contact_drop) { described_class.new(contact) } let!(:contact) { create(:contact) } diff --git a/spec/drops/user_drop_spec.rb b/spec/drops/user_drop_spec.rb index 7c0465de5..1093ec4a0 100644 --- a/spec/drops/user_drop_spec.rb +++ b/spec/drops/user_drop_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe ::UserDrop do +describe UserDrop do subject(:user_drop) { described_class.new(user) } let!(:user) { create(:user) } diff --git a/spec/factories/channel/channel_telegram.rb b/spec/factories/channel/channel_telegram.rb index 99f332c4d..755b5c679 100644 --- a/spec/factories/channel/channel_telegram.rb +++ b/spec/factories/channel/channel_telegram.rb @@ -5,8 +5,8 @@ FactoryBot.define do before(:create) do |channel_telegram| # we are skipping some of the validation methods - channel_telegram.define_singleton_method(:ensure_valid_bot_token) { return } - channel_telegram.define_singleton_method(:setup_telegram_webhook) { return } + channel_telegram.define_singleton_method(:ensure_valid_bot_token) { nil } + channel_telegram.define_singleton_method(:setup_telegram_webhook) { nil } end after(:create) do |channel_telegram| diff --git a/spec/factories/channel/channel_whatsapp.rb b/spec/factories/channel/channel_whatsapp.rb index b2d482e1d..ccbbf7172 100644 --- a/spec/factories/channel/channel_whatsapp.rb +++ b/spec/factories/channel/channel_whatsapp.rb @@ -41,8 +41,8 @@ FactoryBot.define do before(:create) do |channel_whatsapp, options| # since factory already has the required message templates, we just need to bypass it getting updated - channel_whatsapp.define_singleton_method(:sync_templates) { return } unless options.sync_templates - channel_whatsapp.define_singleton_method(:validate_provider_config) { return } unless options.validate_provider_config + channel_whatsapp.define_singleton_method(:sync_templates) { nil } unless options.sync_templates + channel_whatsapp.define_singleton_method(:validate_provider_config) { nil } unless options.validate_provider_config if channel_whatsapp.provider == 'whatsapp_cloud' channel_whatsapp.provider_config = channel_whatsapp.provider_config.merge({ 'api_key' => 'test_key', 'phone_number_id' => '123456789', 'business_account_id' => '123456789' }) diff --git a/spec/factories/messages.rb b/spec/factories/messages.rb index 3e51f2b35..b2ae41c5e 100644 --- a/spec/factories/messages.rb +++ b/spec/factories/messages.rb @@ -16,14 +16,14 @@ FactoryBot.define do channel: create(:channel_instagram_fb_page, account: message.account, instagram_id: 'instagram-123')) end attachment = message.attachments.new(account_id: message.account_id, file_type: :image, external_url: 'https://www.example.com/test.jpeg') - 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 end trait :with_attachment do after(:build) do |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') end end diff --git a/spec/finders/conversation_finder_spec.rb b/spec/finders/conversation_finder_spec.rb index 91a257e13..134ab6d7c 100644 --- a/spec/finders/conversation_finder_spec.rb +++ b/spec/finders/conversation_finder_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe ::ConversationFinder do +describe ConversationFinder do subject(:conversation_finder) { described_class.new(user_1, params) } let!(:account) { create(:account) } diff --git a/spec/finders/email_channel_finder_spec.rb b/spec/finders/email_channel_finder_spec.rb index 17e7c0115..fe57dec0b 100644 --- a/spec/finders/email_channel_finder_spec.rb +++ b/spec/finders/email_channel_finder_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe ::EmailChannelFinder do +describe EmailChannelFinder do include ActionMailbox::TestHelper let!(:channel_email) { create(:channel_email) } diff --git a/spec/finders/message_finder_spec.rb b/spec/finders/message_finder_spec.rb index d61a0785b..04d6e2df9 100644 --- a/spec/finders/message_finder_spec.rb +++ b/spec/finders/message_finder_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe ::MessageFinder do +describe MessageFinder do subject(:message_finder) { described_class.new(conversation, params) } let!(:account) { create(:account) } diff --git a/spec/helpers/cache_keys_helper_spec.rb b/spec/helpers/cache_keys_helper_spec.rb index fa13f50ef..de4b71755 100644 --- a/spec/helpers/cache_keys_helper_spec.rb +++ b/spec/helpers/cache_keys_helper_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe CacheKeysHelper, type: :helper do +RSpec.describe CacheKeysHelper do let(:account_id) { 1 } let(:key) { 'example_key' } diff --git a/spec/helpers/email_helper_spec.rb b/spec/helpers/email_helper_spec.rb index 1bc651e91..504154af8 100644 --- a/spec/helpers/email_helper_spec.rb +++ b/spec/helpers/email_helper_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe EmailHelper, type: :helper do +describe EmailHelper do describe '#normalize_email_with_plus_addressing' do context 'when email is passed' do it 'normalise if plus addressing is present' do diff --git a/spec/helpers/frontend_urls_helper_spec.rb b/spec/helpers/frontend_urls_helper_spec.rb index 4f3903f73..c522d0ee9 100644 --- a/spec/helpers/frontend_urls_helper_spec.rb +++ b/spec/helpers/frontend_urls_helper_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe FrontendUrlsHelper, type: :helper do +describe FrontendUrlsHelper do describe '#frontend_url' do context 'without query params' do it 'creates path correctly' do diff --git a/spec/helpers/message_format_helper_spec.rb b/spec/helpers/message_format_helper_spec.rb index a2e0c5f45..c5bafe67d 100644 --- a/spec/helpers/message_format_helper_spec.rb +++ b/spec/helpers/message_format_helper_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe MessageFormatHelper, type: :helper do +describe MessageFormatHelper do describe '#transform_user_mention_content' do context 'when transform_user_mention_content called' do it 'return transormed text correctly' do diff --git a/spec/helpers/url_helper_spec.rb b/spec/helpers/url_helper_spec.rb index 0a845e31a..bb530fcad 100644 --- a/spec/helpers/url_helper_spec.rb +++ b/spec/helpers/url_helper_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe UrlHelper, type: :helper do +describe UrlHelper do describe '#url_valid' do context 'when url valid called' do it 'return if valid url passed' do diff --git a/spec/jobs/account/conversations_resolution_scheduler_job_spec.rb b/spec/jobs/account/conversations_resolution_scheduler_job_spec.rb index 78baae779..0e4ef3d45 100644 --- a/spec/jobs/account/conversations_resolution_scheduler_job_spec.rb +++ b/spec/jobs/account/conversations_resolution_scheduler_job_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe Account::ConversationsResolutionSchedulerJob, type: :job do +RSpec.describe Account::ConversationsResolutionSchedulerJob do subject(:job) { described_class.perform_later } let!(:account) { create(:account) } diff --git a/spec/jobs/agent_bots/csml_job_spec.rb b/spec/jobs/agent_bots/csml_job_spec.rb index bd974a71a..46fa23fba 100644 --- a/spec/jobs/agent_bots/csml_job_spec.rb +++ b/spec/jobs/agent_bots/csml_job_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe AgentBots::CsmlJob, type: :job do +RSpec.describe AgentBots::CsmlJob do it 'runs csml processor service' do event = 'message.created' message = create(:message) diff --git a/spec/jobs/agent_bots/webhook_job_spec.rb b/spec/jobs/agent_bots/webhook_job_spec.rb index c642d88fc..f4c78c953 100644 --- a/spec/jobs/agent_bots/webhook_job_spec.rb +++ b/spec/jobs/agent_bots/webhook_job_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe AgentBots::WebhookJob, type: :job do +RSpec.describe AgentBots::WebhookJob do include ActiveJob::TestHelper subject(:job) { described_class.perform_later(url, payload) } diff --git a/spec/jobs/agents/destroy_job_spec.rb b/spec/jobs/agents/destroy_job_spec.rb index 7d7f6c036..cf6bb2ffa 100644 --- a/spec/jobs/agents/destroy_job_spec.rb +++ b/spec/jobs/agents/destroy_job_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe Agents::DestroyJob, type: :job do +RSpec.describe Agents::DestroyJob do subject(:job) { described_class.perform_later(account, user) } let!(:account) { create(:account) } diff --git a/spec/jobs/avatar/avatar_from_gravatar_job_spec.rb b/spec/jobs/avatar/avatar_from_gravatar_job_spec.rb index c190bf17b..4f73fd4b2 100644 --- a/spec/jobs/avatar/avatar_from_gravatar_job_spec.rb +++ b/spec/jobs/avatar/avatar_from_gravatar_job_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe Avatar::AvatarFromGravatarJob, type: :job do +RSpec.describe Avatar::AvatarFromGravatarJob do let(:avatarable) { create(:contact) } let(:email) { 'test@test.com' } let(:gravatar_url) { "https://www.gravatar.com/avatar/#{Digest::MD5.hexdigest(email)}?d=404" } diff --git a/spec/jobs/avatar/avatar_from_url_job_spec.rb b/spec/jobs/avatar/avatar_from_url_job_spec.rb index 11e43de64..b9886316a 100644 --- a/spec/jobs/avatar/avatar_from_url_job_spec.rb +++ b/spec/jobs/avatar/avatar_from_url_job_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe Avatar::AvatarFromUrlJob, type: :job do +RSpec.describe Avatar::AvatarFromUrlJob do let(:avatarable) { create(:contact) } let(:avatar_url) { 'https://example.com/avatar.png' } diff --git a/spec/jobs/bulk_actions_job_spec.rb b/spec/jobs/bulk_actions_job_spec.rb index 5e8ee8f9e..f227a7f3c 100644 --- a/spec/jobs/bulk_actions_job_spec.rb +++ b/spec/jobs/bulk_actions_job_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe BulkActionsJob, type: :job do +RSpec.describe BulkActionsJob do params = { type: 'Conversation', fields: { status: 'snoozed' }, diff --git a/spec/jobs/campaigns/trigger_oneoff_campaign_job_spec.rb b/spec/jobs/campaigns/trigger_oneoff_campaign_job_spec.rb index 6c56896ac..dc8823efc 100644 --- a/spec/jobs/campaigns/trigger_oneoff_campaign_job_spec.rb +++ b/spec/jobs/campaigns/trigger_oneoff_campaign_job_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe Campaigns::TriggerOneoffCampaignJob, type: :job do +RSpec.describe Campaigns::TriggerOneoffCampaignJob do let(:account) { create(:account) } let!(:twilio_sms) { create(:channel_twilio_sms) } let!(:twilio_inbox) { create(:inbox, channel: twilio_sms) } diff --git a/spec/jobs/channels/whatsapp/templates_sync_job_spec.rb b/spec/jobs/channels/whatsapp/templates_sync_job_spec.rb index 335e4d6f7..caa3b9894 100644 --- a/spec/jobs/channels/whatsapp/templates_sync_job_spec.rb +++ b/spec/jobs/channels/whatsapp/templates_sync_job_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe Channels::Whatsapp::TemplatesSyncJob, type: :job do +RSpec.describe Channels::Whatsapp::TemplatesSyncJob do let(:channel_whatsapp) { create(:channel_whatsapp, sync_templates: false) } it 'enqueues the job' do diff --git a/spec/jobs/channels/whatsapp/templates_sync_scheduler_job_spec.rb b/spec/jobs/channels/whatsapp/templates_sync_scheduler_job_spec.rb index 6d345584d..1b1050b5d 100644 --- a/spec/jobs/channels/whatsapp/templates_sync_scheduler_job_spec.rb +++ b/spec/jobs/channels/whatsapp/templates_sync_scheduler_job_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe Channels::Whatsapp::TemplatesSyncSchedulerJob, type: :job do +RSpec.describe Channels::Whatsapp::TemplatesSyncSchedulerJob do it 'enqueues the job' do expect { described_class.perform_later }.to have_enqueued_job(described_class) .on_queue('low') diff --git a/spec/jobs/conversations/reopen_snoozed_conversations_job_spec.rb b/spec/jobs/conversations/reopen_snoozed_conversations_job_spec.rb index d58b13d52..802bc2194 100644 --- a/spec/jobs/conversations/reopen_snoozed_conversations_job_spec.rb +++ b/spec/jobs/conversations/reopen_snoozed_conversations_job_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe Conversations::ReopenSnoozedConversationsJob, type: :job do +RSpec.describe Conversations::ReopenSnoozedConversationsJob do let!(:snoozed_till_5_minutes_ago) { create(:conversation, status: :snoozed, snoozed_until: 5.minutes.ago) } let!(:snoozed_till_tomorrow) { create(:conversation, status: :snoozed, snoozed_until: 1.day.from_now) } let!(:snoozed_indefinitely) { create(:conversation, status: :snoozed) } diff --git a/spec/jobs/conversations/resolution_job_spec.rb b/spec/jobs/conversations/resolution_job_spec.rb index 4ed26c1d0..ad2dee92b 100644 --- a/spec/jobs/conversations/resolution_job_spec.rb +++ b/spec/jobs/conversations/resolution_job_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe Conversations::ResolutionJob, type: :job do +RSpec.describe Conversations::ResolutionJob do subject(:job) { described_class.perform_later(account) } let!(:account) { create(:account) } diff --git a/spec/jobs/data_import_job_spec.rb b/spec/jobs/data_import_job_spec.rb index d48f2ca3c..2f2783eb8 100644 --- a/spec/jobs/data_import_job_spec.rb +++ b/spec/jobs/data_import_job_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe DataImportJob, type: :job do +RSpec.describe DataImportJob do subject(:job) { described_class.perform_later(data_import) } let!(:data_import) { create(:data_import) } diff --git a/spec/jobs/delete_object_job_spec.rb b/spec/jobs/delete_object_job_spec.rb index 15f19bdb0..854ff1da2 100644 --- a/spec/jobs/delete_object_job_spec.rb +++ b/spec/jobs/delete_object_job_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe DeleteObjectJob, type: :job do +RSpec.describe DeleteObjectJob do subject(:job) { described_class.perform_later(account) } let(:account) { create(:account) } diff --git a/spec/jobs/event_dispatcher_job_spec.rb b/spec/jobs/event_dispatcher_job_spec.rb index a0297785a..c5a99889e 100644 --- a/spec/jobs/event_dispatcher_job_spec.rb +++ b/spec/jobs/event_dispatcher_job_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe EventDispatcherJob, type: :job do +RSpec.describe EventDispatcherJob do subject(:job) { described_class.perform_later(event_name, timestamp, event_data) } let!(:conversation) { create(:conversation) } diff --git a/spec/jobs/hook_job_spec.rb b/spec/jobs/hook_job_spec.rb index 8275bfa31..67dfcaf5f 100644 --- a/spec/jobs/hook_job_spec.rb +++ b/spec/jobs/hook_job_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe HookJob, type: :job do +RSpec.describe HookJob do subject(:job) { described_class.perform_later(hook, event_name, event_data) } let(:account) { create(:account) } diff --git a/spec/jobs/inboxes/fetch_imap_email_inboxes_job_spec.rb b/spec/jobs/inboxes/fetch_imap_email_inboxes_job_spec.rb index 33f516e42..ae4f540d4 100644 --- a/spec/jobs/inboxes/fetch_imap_email_inboxes_job_spec.rb +++ b/spec/jobs/inboxes/fetch_imap_email_inboxes_job_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe Inboxes::FetchImapEmailInboxesJob, type: :job do +RSpec.describe Inboxes::FetchImapEmailInboxesJob do let(:account) { create(:account) } let(:imap_email_channel) do create(:channel_email, imap_enabled: true, imap_address: 'imap.gmail.com', imap_port: 993, imap_login: 'imap@gmail.com', diff --git a/spec/jobs/inboxes/fetch_imap_emails_job_spec.rb b/spec/jobs/inboxes/fetch_imap_emails_job_spec.rb index 20c3880e8..30a77c5ec 100644 --- a/spec/jobs/inboxes/fetch_imap_emails_job_spec.rb +++ b/spec/jobs/inboxes/fetch_imap_emails_job_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe Inboxes::FetchImapEmailsJob, type: :job do +RSpec.describe Inboxes::FetchImapEmailsJob do include ActionMailbox::TestHelper let(:account) { create(:account) } diff --git a/spec/jobs/inboxes/sync_widget_pre_chat_custom_fields_job_spec.rb b/spec/jobs/inboxes/sync_widget_pre_chat_custom_fields_job_spec.rb index 9348754d1..d9258e88a 100644 --- a/spec/jobs/inboxes/sync_widget_pre_chat_custom_fields_job_spec.rb +++ b/spec/jobs/inboxes/sync_widget_pre_chat_custom_fields_job_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe Inboxes::SyncWidgetPreChatCustomFieldsJob, type: :job do +RSpec.describe Inboxes::SyncWidgetPreChatCustomFieldsJob do pre_chat_fields = [{ 'label' => 'Developer Id', 'name' => 'developer_id' diff --git a/spec/jobs/inboxes/update_widget_pre_chat_custom_fields_job_spec.rb b/spec/jobs/inboxes/update_widget_pre_chat_custom_fields_job_spec.rb index 80a32be34..284a0de70 100644 --- a/spec/jobs/inboxes/update_widget_pre_chat_custom_fields_job_spec.rb +++ b/spec/jobs/inboxes/update_widget_pre_chat_custom_fields_job_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe Inboxes::UpdateWidgetPreChatCustomFieldsJob, type: :job do +RSpec.describe Inboxes::UpdateWidgetPreChatCustomFieldsJob do pre_chat_fields = [{ 'label' => 'Developer Id', 'name' => 'developer_id' diff --git a/spec/jobs/internal/check_new_versions_job_spec.rb b/spec/jobs/internal/check_new_versions_job_spec.rb index 853241835..3253ce319 100644 --- a/spec/jobs/internal/check_new_versions_job_spec.rb +++ b/spec/jobs/internal/check_new_versions_job_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe Internal::CheckNewVersionsJob, type: :job do +RSpec.describe Internal::CheckNewVersionsJob do subject(:job) { described_class.perform_now } it 'updates the latest chatwoot version in redis' do @@ -9,6 +9,6 @@ RSpec.describe Internal::CheckNewVersionsJob, type: :job do allow(ChatwootHub).to receive(:latest_version).and_return(version) job expect(ChatwootHub).to have_received(:latest_version) - expect(::Redis::Alfred.get(::Redis::Alfred::LATEST_CHATWOOT_VERSION)).to eq version + expect(Redis::Alfred.get(Redis::Alfred::LATEST_CHATWOOT_VERSION)).to eq version end end diff --git a/spec/jobs/labels/update_job_spec.rb b/spec/jobs/labels/update_job_spec.rb index 16692b2c3..9d9263da6 100644 --- a/spec/jobs/labels/update_job_spec.rb +++ b/spec/jobs/labels/update_job_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe Labels::UpdateJob, type: :job do +RSpec.describe Labels::UpdateJob do subject(:job) { described_class.perform_later(new_label_title, old_label_title, account_id) } let(:new_label_title) { 'new-title' } diff --git a/spec/jobs/migration/conversations_first_reply_scheduler_job_spec.rb b/spec/jobs/migration/conversations_first_reply_scheduler_job_spec.rb index f16b51a3a..52ef7b574 100644 --- a/spec/jobs/migration/conversations_first_reply_scheduler_job_spec.rb +++ b/spec/jobs/migration/conversations_first_reply_scheduler_job_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe Migration::ConversationsFirstReplySchedulerJob, type: :job do +RSpec.describe Migration::ConversationsFirstReplySchedulerJob do subject(:job) { described_class.perform_later } let!(:account) { create(:account) } diff --git a/spec/jobs/send_reply_job_spec.rb b/spec/jobs/send_reply_job_spec.rb index 304653b41..e0e6a121a 100644 --- a/spec/jobs/send_reply_job_spec.rb +++ b/spec/jobs/send_reply_job_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe SendReplyJob, type: :job do +RSpec.describe SendReplyJob do subject(:job) { described_class.perform_later(message) } let(:message) { create(:message) } @@ -33,8 +33,8 @@ RSpec.describe SendReplyJob, type: :job do twitter_channel = create(:channel_twitter_profile) twitter_inbox = create(:inbox, channel: twitter_channel) message = create(:message, conversation: create(:conversation, inbox: twitter_inbox)) - allow(::Twitter::SendOnTwitterService).to receive(:new).with(message: message).and_return(process_service) - expect(::Twitter::SendOnTwitterService).to receive(:new).with(message: message) + allow(Twitter::SendOnTwitterService).to receive(:new).with(message: message).and_return(process_service) + expect(Twitter::SendOnTwitterService).to receive(:new).with(message: message) expect(process_service).to receive(:perform) described_class.perform_now(message.id) end @@ -42,8 +42,8 @@ RSpec.describe SendReplyJob, type: :job do it 'calls ::Twilio::SendOnTwilioService when its twilio message' do twilio_channel = create(:channel_twilio_sms) message = create(:message, conversation: create(:conversation, inbox: twilio_channel.inbox)) - allow(::Twilio::SendOnTwilioService).to receive(:new).with(message: message).and_return(process_service) - expect(::Twilio::SendOnTwilioService).to receive(:new).with(message: message) + allow(Twilio::SendOnTwilioService).to receive(:new).with(message: message).and_return(process_service) + expect(Twilio::SendOnTwilioService).to receive(:new).with(message: message) expect(process_service).to receive(:perform) described_class.perform_now(message.id) end @@ -51,8 +51,8 @@ RSpec.describe SendReplyJob, type: :job do it 'calls ::Telegram::SendOnTelegramService when its telegram message' do telegram_channel = create(:channel_telegram) message = create(:message, conversation: create(:conversation, inbox: telegram_channel.inbox)) - allow(::Telegram::SendOnTelegramService).to receive(:new).with(message: message).and_return(process_service) - expect(::Telegram::SendOnTelegramService).to receive(:new).with(message: message) + allow(Telegram::SendOnTelegramService).to receive(:new).with(message: message).and_return(process_service) + expect(Telegram::SendOnTelegramService).to receive(:new).with(message: message) expect(process_service).to receive(:perform) described_class.perform_now(message.id) end @@ -60,8 +60,8 @@ RSpec.describe SendReplyJob, type: :job do it 'calls ::Line:SendOnLineService when its line message' do line_channel = create(:channel_line) message = create(:message, conversation: create(:conversation, inbox: line_channel.inbox)) - allow(::Line::SendOnLineService).to receive(:new).with(message: message).and_return(process_service) - expect(::Line::SendOnLineService).to receive(:new).with(message: message) + allow(Line::SendOnLineService).to receive(:new).with(message: message).and_return(process_service) + expect(Line::SendOnLineService).to receive(:new).with(message: message) expect(process_service).to receive(:perform) described_class.perform_now(message.id) end @@ -70,8 +70,8 @@ RSpec.describe SendReplyJob, type: :job do stub_request(:post, 'https://waba.360dialog.io/v1/configs/webhook') whatsapp_channel = create(:channel_whatsapp, sync_templates: false) message = create(:message, conversation: create(:conversation, inbox: whatsapp_channel.inbox)) - allow(::Whatsapp::SendOnWhatsappService).to receive(:new).with(message: message).and_return(process_service) - expect(::Whatsapp::SendOnWhatsappService).to receive(:new).with(message: message) + allow(Whatsapp::SendOnWhatsappService).to receive(:new).with(message: message).and_return(process_service) + expect(Whatsapp::SendOnWhatsappService).to receive(:new).with(message: message) expect(process_service).to receive(:perform) described_class.perform_now(message.id) end @@ -79,8 +79,8 @@ RSpec.describe SendReplyJob, type: :job do it 'calls ::Sms::SendOnSmsService when its sms message' do sms_channel = create(:channel_sms) message = create(:message, conversation: create(:conversation, inbox: sms_channel.inbox)) - allow(::Sms::SendOnSmsService).to receive(:new).with(message: message).and_return(process_service) - expect(::Sms::SendOnSmsService).to receive(:new).with(message: message) + allow(Sms::SendOnSmsService).to receive(:new).with(message: message).and_return(process_service) + expect(Sms::SendOnSmsService).to receive(:new).with(message: message) expect(process_service).to receive(:perform) described_class.perform_now(message.id) end diff --git a/spec/jobs/trigger_scheduled_items_job_spec.rb b/spec/jobs/trigger_scheduled_items_job_spec.rb index e7b5fe597..270bd9076 100644 --- a/spec/jobs/trigger_scheduled_items_job_spec.rb +++ b/spec/jobs/trigger_scheduled_items_job_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe TriggerScheduledItemsJob, type: :job do +RSpec.describe TriggerScheduledItemsJob do subject(:job) { described_class.perform_later } let(:account) { create(:account) } diff --git a/spec/jobs/webhook_job_spec.rb b/spec/jobs/webhook_job_spec.rb index f5b8d9dd8..23ddb6cf1 100644 --- a/spec/jobs/webhook_job_spec.rb +++ b/spec/jobs/webhook_job_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe WebhookJob, type: :job do +RSpec.describe WebhookJob do include ActiveJob::TestHelper subject(:job) { described_class.perform_later(url, payload) } diff --git a/spec/jobs/webhooks/facebook_events_job_spec.rb b/spec/jobs/webhooks/facebook_events_job_spec.rb index 8223953ba..14868dc4f 100644 --- a/spec/jobs/webhooks/facebook_events_job_spec.rb +++ b/spec/jobs/webhooks/facebook_events_job_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe Webhooks::FacebookEventsJob, type: :job do +RSpec.describe Webhooks::FacebookEventsJob do subject(:job) { described_class.perform_later(params) } let!(:params) { { test: 'test' } } @@ -15,11 +15,11 @@ RSpec.describe Webhooks::FacebookEventsJob, type: :job do it 'calls MessagePArsed and do message create' do parser = double creator = double - allow(::Integrations::Facebook::MessageParser).to receive(:new).and_return(parser) - allow(::Integrations::Facebook::MessageCreator).to receive(:new).and_return(creator) + allow(Integrations::Facebook::MessageParser).to receive(:new).and_return(parser) + allow(Integrations::Facebook::MessageCreator).to receive(:new).and_return(creator) allow(creator).to receive(:perform).and_return(true) - expect(::Integrations::Facebook::MessageParser).to receive(:new).with(params) - expect(::Integrations::Facebook::MessageCreator).to receive(:new).with(parser) + expect(Integrations::Facebook::MessageParser).to receive(:new).with(params) + expect(Integrations::Facebook::MessageCreator).to receive(:new).with(parser) expect(creator).to receive(:perform) described_class.perform_now(params) end diff --git a/spec/jobs/webhooks/line_events_job_spec.rb b/spec/jobs/webhooks/line_events_job_spec.rb index e8d69939e..ba0068ba0 100644 --- a/spec/jobs/webhooks/line_events_job_spec.rb +++ b/spec/jobs/webhooks/line_events_job_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe Webhooks::LineEventsJob, type: :job do +RSpec.describe Webhooks::LineEventsJob do subject(:job) { described_class.perform_later(params: params) } let!(:line_channel) { create(:channel_line) } diff --git a/spec/jobs/webhooks/sms_events_job_spec.rb b/spec/jobs/webhooks/sms_events_job_spec.rb index 927e8adaa..3874ba24d 100644 --- a/spec/jobs/webhooks/sms_events_job_spec.rb +++ b/spec/jobs/webhooks/sms_events_job_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe Webhooks::SmsEventsJob, type: :job do +RSpec.describe Webhooks::SmsEventsJob do subject(:job) { described_class.perform_later(params) } let!(:sms_channel) { create(:channel_sms) } diff --git a/spec/jobs/webhooks/telegram_events_job_spec.rb b/spec/jobs/webhooks/telegram_events_job_spec.rb index 80153fc0f..992a50b1b 100644 --- a/spec/jobs/webhooks/telegram_events_job_spec.rb +++ b/spec/jobs/webhooks/telegram_events_job_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe Webhooks::TelegramEventsJob, type: :job do +RSpec.describe Webhooks::TelegramEventsJob do subject(:job) { described_class.perform_later(params) } let!(:telegram_channel) { create(:channel_telegram) } diff --git a/spec/jobs/webhooks/whatsapp_events_job_spec.rb b/spec/jobs/webhooks/whatsapp_events_job_spec.rb index 187d4c62c..8a7e783ad 100644 --- a/spec/jobs/webhooks/whatsapp_events_job_spec.rb +++ b/spec/jobs/webhooks/whatsapp_events_job_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe Webhooks::WhatsappEventsJob, type: :job do +RSpec.describe Webhooks::WhatsappEventsJob do subject(:job) { described_class } let(:channel) { create(:channel_whatsapp, provider: 'whatsapp_cloud', sync_templates: false, validate_provider_config: false) } diff --git a/spec/lib/email_templates/db_resolver_service_spec.rb b/spec/lib/email_templates/db_resolver_service_spec.rb index f581c0c29..56c8a648b 100644 --- a/spec/lib/email_templates/db_resolver_service_spec.rb +++ b/spec/lib/email_templates/db_resolver_service_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe ::EmailTemplates::DbResolverService do +describe EmailTemplates::DbResolverService do subject(:resolver) { described_class.using(EmailTemplate, {}) } describe '#find_templates' do diff --git a/spec/lib/integrations/dialogflow/processor_service_spec.rb b/spec/lib/integrations/dialogflow/processor_service_spec.rb index 379339f32..9f7535f5f 100644 --- a/spec/lib/integrations/dialogflow/processor_service_spec.rb +++ b/spec/lib/integrations/dialogflow/processor_service_spec.rb @@ -150,7 +150,7 @@ describe Integrations::Dialogflow::ProcessorService do end describe '#get_response' do - let(:google_dialogflow) { ::Google::Cloud::Dialogflow::V2::Sessions::Client } + let(:google_dialogflow) { Google::Cloud::Dialogflow::V2::Sessions::Client } let(:session_client) { double } let(:session) { double } let(:query_input) { { text: { text: message, language_code: 'en-US' } } } diff --git a/spec/lib/integrations/google_translate/detect_language_service_spec.rb b/spec/lib/integrations/google_translate/detect_language_service_spec.rb index c71ec074f..9a3530707 100644 --- a/spec/lib/integrations/google_translate/detect_language_service_spec.rb +++ b/spec/lib/integrations/google_translate/detect_language_service_spec.rb @@ -8,8 +8,8 @@ describe Integrations::GoogleTranslate::DetectLanguageService do let(:translate_client) { double } before do - allow(::Google::Cloud::Translate::V3::TranslationService::Client).to receive(:new).and_return(translate_client) - allow(translate_client).to receive(:detect_language).and_return(::Google::Cloud::Translate::V3::DetectLanguageResponse + allow(Google::Cloud::Translate::V3::TranslationService::Client).to receive(:new).and_return(translate_client) + allow(translate_client).to receive(:detect_language).and_return(Google::Cloud::Translate::V3::DetectLanguageResponse .new({ languages: [{ language_code: 'es', confidence: 0.71875 }] })) end diff --git a/spec/lib/integrations/slack/send_on_slack_service_spec.rb b/spec/lib/integrations/slack/send_on_slack_service_spec.rb index 46065a074..7fc75b2db 100644 --- a/spec/lib/integrations/slack/send_on_slack_service_spec.rb +++ b/spec/lib/integrations/slack/send_on_slack_service_spec.rb @@ -108,7 +108,7 @@ describe Integrations::Slack::SendOnSlackService do ).and_return(slack_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(slack_client).to receive(:files_upload).with(hash_including( channels: hook.reference_id, diff --git a/spec/lib/online_status_tracker_spec.rb b/spec/lib/online_status_tracker_spec.rb index d4890a6f3..c2f69ffac 100644 --- a/spec/lib/online_status_tracker_spec.rb +++ b/spec/lib/online_status_tracker_spec.rb @@ -29,8 +29,8 @@ describe OnlineStatusTracker do before do described_class.update_presence(account.id, 'Contact', online_contact.id) # creating a stale record for offline contact presence - ::Redis::Alfred.zadd(format(::Redis::Alfred::ONLINE_PRESENCE_CONTACTS, account_id: account.id), - (Time.zone.now - (OnlineStatusTracker::PRESENCE_DURATION + 20)).to_i, offline_contact.id) + Redis::Alfred.zadd(format(Redis::Alfred::ONLINE_PRESENCE_CONTACTS, account_id: account.id), + (Time.zone.now - (OnlineStatusTracker::PRESENCE_DURATION + 20)).to_i, offline_contact.id) end it 'returns only the online contact ids with presence' do @@ -39,7 +39,7 @@ describe OnlineStatusTracker do it 'flushes the stale records from sorted set after the duration' do described_class.get_available_contacts(account.id) - expect(::Redis::Alfred.zscore(format(::Redis::Alfred::ONLINE_PRESENCE_CONTACTS, account_id: account.id), offline_contact.id)).to be_nil + expect(Redis::Alfred.zscore(format(Redis::Alfred::ONLINE_PRESENCE_CONTACTS, account_id: account.id), offline_contact.id)).to be_nil end end end diff --git a/spec/lib/redis/config_spec.rb b/spec/lib/redis/config_spec.rb index cd6d444a6..79dc8b03d 100644 --- a/spec/lib/redis/config_spec.rb +++ b/spec/lib/redis/config_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe ::Redis::Config do +describe Redis::Config do context 'when single redis instance is used' do let(:redis_url) { 'redis://my-redis-instance:6379' } let(:redis_pasword) { 'some-strong-password' } @@ -14,7 +14,7 @@ describe ::Redis::Config do it 'checks for app redis config' do app_config = described_class.app - expect(app_config.keys).to match_array([:url, :password, :timeout, :reconnect_attempts, :ssl_params]) + expect(app_config.keys).to contain_exactly(:url, :password, :timeout, :reconnect_attempts, :ssl_params) expect(app_config[:url]).to eq(redis_url) expect(app_config[:password]).to eq(redis_pasword) end @@ -43,7 +43,7 @@ describe ::Redis::Config do end it 'checks for app redis config' do - expect(described_class.app.keys).to match_array([:url, :password, :sentinels, :timeout, :reconnect_attempts, :ssl_params]) + expect(described_class.app.keys).to contain_exactly(:url, :password, :sentinels, :timeout, :reconnect_attempts, :ssl_params) expect(described_class.app[:url]).to eq("redis://#{redis_master_name}") expect(described_class.app[:sentinels]).to match_array(expected_sentinels) end @@ -60,7 +60,7 @@ describe ::Redis::Config do end it 'checks for app redis config and sentinel passwords will be empty' do - expect(described_class.app.keys).to match_array([:url, :password, :sentinels, :timeout, :reconnect_attempts, :ssl_params]) + expect(described_class.app.keys).to contain_exactly(:url, :password, :sentinels, :timeout, :reconnect_attempts, :ssl_params) expect(described_class.app[:url]).to eq("redis://#{redis_master_name}") expect(described_class.app[:sentinels]).to match_array(expected_sentinels.map { |s| s.except(:password) }) end @@ -78,7 +78,7 @@ describe ::Redis::Config do end it 'checks for app redis config and redis password is replaced in sentinel config' do - expect(described_class.app.keys).to match_array([:url, :password, :sentinels, :timeout, :reconnect_attempts, :ssl_params]) + expect(described_class.app.keys).to contain_exactly(:url, :password, :sentinels, :timeout, :reconnect_attempts, :ssl_params) expect(described_class.app[:url]).to eq("redis://#{redis_master_name}") expect(described_class.app[:sentinels]).to match_array(expected_sentinels.map { |s| s.merge(password: redis_sentinel_password) }) end diff --git a/spec/mailboxes/application_mailbox_spec.rb b/spec/mailboxes/application_mailbox_spec.rb index 3f3e8b97f..d5e15dc46 100644 --- a/spec/mailboxes/application_mailbox_spec.rb +++ b/spec/mailboxes/application_mailbox_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe ApplicationMailbox, type: :mailbox do +RSpec.describe ApplicationMailbox do include ActionMailbox::TestHelper describe 'route the inbound mail to appropriate mailbox' do diff --git a/spec/mailboxes/imap/imap_mailbox_spec.rb b/spec/mailboxes/imap/imap_mailbox_spec.rb index a78c4fcf1..49b51b45f 100644 --- a/spec/mailboxes/imap/imap_mailbox_spec.rb +++ b/spec/mailboxes/imap/imap_mailbox_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe Imap::ImapMailbox, type: :mailbox do +RSpec.describe Imap::ImapMailbox do include ActionMailbox::TestHelper describe 'add mail as a new conversation in the email inbox' do diff --git a/spec/mailboxes/reply_mailbox_spec.rb b/spec/mailboxes/reply_mailbox_spec.rb index a383e3e5c..72fbd317d 100644 --- a/spec/mailboxes/reply_mailbox_spec.rb +++ b/spec/mailboxes/reply_mailbox_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe ReplyMailbox, type: :mailbox do +RSpec.describe ReplyMailbox do include ActionMailbox::TestHelper describe 'add mail as reply in a conversation' do diff --git a/spec/mailboxes/support_mailbox_spec.rb b/spec/mailboxes/support_mailbox_spec.rb index c0501cff4..d2e2c7946 100644 --- a/spec/mailboxes/support_mailbox_spec.rb +++ b/spec/mailboxes/support_mailbox_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe SupportMailbox, type: :mailbox do +RSpec.describe SupportMailbox do include ActionMailbox::TestHelper describe 'when a chatwoot notification email is received' do diff --git a/spec/mailers/administrator_notifications/channel_notifications_mailer_spec.rb b/spec/mailers/administrator_notifications/channel_notifications_mailer_spec.rb index fa90b7970..7190678cc 100644 --- a/spec/mailers/administrator_notifications/channel_notifications_mailer_spec.rb +++ b/spec/mailers/administrator_notifications/channel_notifications_mailer_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe AdministratorNotifications::ChannelNotificationsMailer, type: :mailer do +RSpec.describe AdministratorNotifications::ChannelNotificationsMailer do let(:class_instance) { described_class.new } let!(:account) { create(:account) } let!(:administrator) { create(:user, :administrator, email: 'agent1@example.com', account: account) } diff --git a/spec/mailers/agent_notifications/conversation_notifications_mailer_spec.rb b/spec/mailers/agent_notifications/conversation_notifications_mailer_spec.rb index 6b102d566..9faabc3af 100644 --- a/spec/mailers/agent_notifications/conversation_notifications_mailer_spec.rb +++ b/spec/mailers/agent_notifications/conversation_notifications_mailer_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe AgentNotifications::ConversationNotificationsMailer, type: :mailer do +RSpec.describe AgentNotifications::ConversationNotificationsMailer do let(:class_instance) { described_class.new } let!(:account) { create(:account) } let(:agent) { create(:user, email: 'agent1@example.com', account: account) } @@ -83,7 +83,7 @@ RSpec.describe AgentNotifications::ConversationNotificationsMailer, type: :maile end it 'will not send email if agent is online' do - ::OnlineStatusTracker.update_presence(conversation.account.id, 'User', agent.id) + OnlineStatusTracker.update_presence(conversation.account.id, 'User', agent.id) expect(mail).to be_nil end end @@ -101,7 +101,7 @@ RSpec.describe AgentNotifications::ConversationNotificationsMailer, type: :maile end it 'will not send email if agent is online' do - ::OnlineStatusTracker.update_presence(conversation.account.id, 'User', agent.id) + OnlineStatusTracker.update_presence(conversation.account.id, 'User', agent.id) expect(mail).to be_nil end end diff --git a/spec/mailers/confirmation_instructions_spec.rb b/spec/mailers/confirmation_instructions_spec.rb index 9eeed85d2..8c66c4fea 100644 --- a/spec/mailers/confirmation_instructions_spec.rb +++ b/spec/mailers/confirmation_instructions_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe 'Confirmation Instructions', type: :mailer do +RSpec.describe 'Confirmation Instructions' do describe :notify do let(:account) { create(:account) } let!(:confirmable_user) { create(:user, inviter: inviter_val, account: account) } diff --git a/spec/mailers/conversation_reply_mailer_spec.rb b/spec/mailers/conversation_reply_mailer_spec.rb index 61900fc7e..c10dfe2d5 100644 --- a/spec/mailers/conversation_reply_mailer_spec.rb +++ b/spec/mailers/conversation_reply_mailer_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe ConversationReplyMailer, type: :mailer do +RSpec.describe ConversationReplyMailer do describe 'reply' do let!(:account) { create(:account) } let!(:agent) { create(:user, email: 'agent1@example.com', account: account) } diff --git a/spec/models/agent_bot_inbox_spec.rb b/spec/models/agent_bot_inbox_spec.rb index 2c0ef84e7..ef8f1d723 100644 --- a/spec/models/agent_bot_inbox_spec.rb +++ b/spec/models/agent_bot_inbox_spec.rb @@ -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) } diff --git a/spec/models/agent_bot_spec.rb b/spec/models/agent_bot_spec.rb index 87a3291b3..6e35bd79b 100644 --- a/spec/models/agent_bot_spec.rb +++ b/spec/models/agent_bot_spec.rb @@ -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) } diff --git a/spec/models/article_spec.rb b/spec/models/article_spec.rb index 11837a1d8..ff2734640 100644 --- a/spec/models/article_spec.rb +++ b/spec/models/article_spec.rb @@ -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] }) } diff --git a/spec/models/attachment_spec.rb b/spec/models/attachment_spec.rb index 2f73d1abe..c03bca062 100644 --- a/spec/models/attachment_spec.rb +++ b/spec/models/attachment_spec.rb @@ -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 diff --git a/spec/models/automation_rule_spec.rb b/spec/models/automation_rule_spec.rb index efcae76fd..a20d3d71d 100644 --- a/spec/models/automation_rule_spec.rb +++ b/spec/models/automation_rule_spec.rb @@ -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 diff --git a/spec/models/campaign_spec.rb b/spec/models/campaign_spec.rb index f99f18390..f3154c50a 100644 --- a/spec/models/campaign_spec.rb +++ b/spec/models/campaign_spec.rb @@ -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) } diff --git a/spec/models/category_spec.rb b/spec/models/category_spec.rb index df4392398..efe7fe036 100644 --- a/spec/models/category_spec.rb +++ b/spec/models/category_spec.rb @@ -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) } diff --git a/spec/models/channel/telegram_spec.rb b/spec/models/channel/telegram_spec.rb index 8186a1149..4fe49f844 100644 --- a/spec/models/channel/telegram_spec.rb +++ b/spec/models/channel/telegram_spec.rb @@ -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' } }) diff --git a/spec/models/channel/twilio_sms_spec.rb b/spec/models/channel/twilio_sms_spec.rb index ddaec7025..7ccb26c7a 100644 --- a/spec/models/channel/twilio_sms_spec.rb +++ b/spec/models/channel/twilio_sms_spec.rb @@ -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 diff --git a/spec/models/conversation_participants_spec.rb b/spec/models/conversation_participants_spec.rb index 6e0fe7504..c078f69f6 100644 --- a/spec/models/conversation_participants_spec.rb +++ b/spec/models/conversation_participants_spec.rb @@ -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) } diff --git a/spec/models/conversation_spec.rb b/spec/models/conversation_spec.rb index 514fb80c5..3bbe3c833 100644 --- a/spec/models/conversation_spec.rb +++ b/spec/models/conversation_spec.rb @@ -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) } diff --git a/spec/models/csat_survey_response_spec.rb b/spec/models/csat_survey_response_spec.rb index 9bab7e64a..09659f080 100644 --- a/spec/models/csat_survey_response_spec.rb +++ b/spec/models/csat_survey_response_spec.rb @@ -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) } diff --git a/spec/models/data_import_spec.rb b/spec/models/data_import_spec.rb index 0bfbc3dbf..84805f86d 100644 --- a/spec/models/data_import_spec.rb +++ b/spec/models/data_import_spec.rb @@ -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 diff --git a/spec/models/folder_spec.rb b/spec/models/folder_spec.rb index 47c9adf06..19cfe6a55 100644 --- a/spec/models/folder_spec.rb +++ b/spec/models/folder_spec.rb @@ -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) } diff --git a/spec/models/inbox_member_spec.rb b/spec/models/inbox_member_spec.rb index 389fe75cb..b081c546c 100644 --- a/spec/models/inbox_member_spec.rb +++ b/spec/models/inbox_member_spec.rb @@ -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 diff --git a/spec/models/integrations/hook_spec.rb b/spec/models/integrations/hook_spec.rb index 874fc4346..e8b1b8156 100644 --- a/spec/models/integrations/hook_spec.rb +++ b/spec/models/integrations/hook_spec.rb @@ -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) } diff --git a/spec/models/label_spec.rb b/spec/models/label_spec.rb index 69f1ce771..ee5e7b108 100644 --- a/spec/models/label_spec.rb +++ b/spec/models/label_spec.rb @@ -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 diff --git a/spec/models/macro_spec.rb b/spec/models/macro_spec.rb index ee91b2b93..4df74b7fa 100644 --- a/spec/models/macro_spec.rb +++ b/spec/models/macro_spec.rb @@ -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) } diff --git a/spec/models/mention_spec.rb b/spec/models/mention_spec.rb index fe732ea03..773785c59 100644 --- a/spec/models/mention_spec.rb +++ b/spec/models/mention_spec.rb @@ -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) } diff --git a/spec/models/message_spec.rb b/spec/models/message_spec.rb index e6dddbe4b..e44627666 100644 --- a/spec/models/message_spec.rb +++ b/spec/models/message_spec.rb @@ -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'] }) diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb index 3d36c56ae..203d5ee45 100644 --- a/spec/models/note_spec.rb +++ b/spec/models/note_spec.rb @@ -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) } diff --git a/spec/models/portal_member_spec.rb b/spec/models/portal_member_spec.rb index 67215a3d6..646ff9c27 100644 --- a/spec/models/portal_member_spec.rb +++ b/spec/models/portal_member_spec.rb @@ -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) } diff --git a/spec/models/portal_spec.rb b/spec/models/portal_spec.rb index 070c2ca6c..1b33c8d90 100644 --- a/spec/models/portal_spec.rb +++ b/spec/models/portal_spec.rb @@ -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) } diff --git a/spec/models/related_category_spec.rb b/spec/models/related_category_spec.rb index 5a500d53b..45418095b 100644 --- a/spec/models/related_category_spec.rb +++ b/spec/models/related_category_spec.rb @@ -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) } diff --git a/spec/models/reporting_event_spec.rb b/spec/models/reporting_event_spec.rb index 553a4e360..e9c904a63 100644 --- a/spec/models/reporting_event_spec.rb +++ b/spec/models/reporting_event_spec.rb @@ -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) } diff --git a/spec/models/team_member_spec.rb b/spec/models/team_member_spec.rb index 97171856d..f37f70425 100644 --- a/spec/models/team_member_spec.rb +++ b/spec/models/team_member_spec.rb @@ -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) } diff --git a/spec/models/team_spec.rb b/spec/models/team_spec.rb index c2327ecd6..e9019e211 100644 --- a/spec/models/team_spec.rb +++ b/spec/models/team_spec.rb @@ -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) } diff --git a/spec/models/webhook_spec.rb b/spec/models/webhook_spec.rb index ca3ef213f..81e6d9551 100644 --- a/spec/models/webhook_spec.rb +++ b/spec/models/webhook_spec.rb @@ -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 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 2bc0d813c..1b640aaa3 100644 --- a/spec/requests/api/v1/accounts/integrations/slack_request_spec.rb +++ b/spec/requests/api/v1/accounts/integrations/slack_request_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe 'Api::V1::Accounts::Integrations::Slacks', type: :request do +RSpec.describe 'Api::V1::Accounts::Integrations::Slacks' do let(:account) { create(:account) } let(:agent) { create(:user, account: account, role: :administrator) } let!(:hook) { create(:integrations_hook, account: account) } @@ -28,7 +28,7 @@ RSpec.describe 'Api::V1::Accounts::Integrations::Slacks', type: :request do headers: agent.create_new_auth_token expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['id']).to eql('slack') end end @@ -53,7 +53,7 @@ RSpec.describe 'Api::V1::Accounts::Integrations::Slacks', type: :request do headers: agent.create_new_auth_token expect(response).to have_http_status(:success) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['app_id']).to eql('slack') end end diff --git a/spec/requests/api/v1/integrations/webhooks_request_spec.rb b/spec/requests/api/v1/integrations/webhooks_request_spec.rb index ea870d45c..28922df6a 100644 --- a/spec/requests/api/v1/integrations/webhooks_request_spec.rb +++ b/spec/requests/api/v1/integrations/webhooks_request_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe 'Api::V1::Integrations::Webhooks', type: :request do +RSpec.describe 'Api::V1::Integrations::Webhooks' do describe 'POST /api/v1/integrations/webhooks' do it 'consumes webhook' do builder = Integrations::Slack::IncomingMessageBuilder.new({}) diff --git a/spec/services/action_service_spec.rb b/spec/services/action_service_spec.rb index 8cade58a6..3efcb6555 100644 --- a/spec/services/action_service_spec.rb +++ b/spec/services/action_service_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe ::ActionService do +describe ActionService do describe '#resolve_conversation' do let(:conversation) { create(:conversation) } let(:action_service) { described_class.new(conversation) } diff --git a/spec/services/auto_assignment/agent_assignment_service_spec.rb b/spec/services/auto_assignment/agent_assignment_service_spec.rb index 83790dc28..16337dc04 100644 --- a/spec/services/auto_assignment/agent_assignment_service_spec.rb +++ b/spec/services/auto_assignment/agent_assignment_service_spec.rb @@ -17,7 +17,7 @@ RSpec.describe AutoAssignment::AgentAssignmentService do before do inbox_members.each { |inbox_member| create(:account_user, account: account, user: inbox_member.user) } - allow(::OnlineStatusTracker).to receive(:get_available_users).and_return(online_users) + allow(OnlineStatusTracker).to receive(:get_available_users).and_return(online_users) end describe '#perform' do diff --git a/spec/services/automation_rules/action_service_spec.rb b/spec/services/automation_rules/action_service_spec.rb index 0f0d09943..bdfa7af0c 100644 --- a/spec/services/automation_rules/action_service_spec.rb +++ b/spec/services/automation_rules/action_service_spec.rb @@ -27,7 +27,7 @@ RSpec.describe AutomationRules::ActionService do before do allow(Messages::MessageBuilder).to receive(:new).and_return(message_builder) rule.actions.delete_if { |a| a['action_name'] == 'send_message' } - rule.files.attach(io: File.open(Rails.root.join('spec/assets/avatar.png')), filename: 'avatar.png', content_type: 'image/png') + rule.files.attach(io: Rails.root.join('spec/assets/avatar.png').open, filename: 'avatar.png', content_type: 'image/png') rule.save! rule.actions << { action_name: 'send_attachment', action_params: [rule.files.first.blob_id] } end @@ -47,7 +47,7 @@ RSpec.describe AutomationRules::ActionService do describe '#perform with send_webhook_event action' do it 'will send webhook event' do - expect(rule.actions.map { |r| r['action_name'] }).to include('send_webhook_event') + expect(rule.actions.pluck('action_name')).to include('send_webhook_event') expect(WebhookJob).to receive(:perform_later) described_class.new(rule, account, conversation).perform end @@ -61,13 +61,13 @@ RSpec.describe AutomationRules::ActionService do end it 'will send message' do - expect(rule.actions.map { |r| r['action_name'] }).to include('send_message') + expect(rule.actions.pluck('action_name')).to include('send_message') expect(message_builder).to receive(:perform) described_class.new(rule, account, conversation).perform end it 'will not send message if conversation is a tweet' do - expect(rule.actions.map { |r| r['action_name'] }).to include('send_message') + expect(rule.actions.pluck('action_name')).to include('send_message') twitter_inbox = create(:inbox, channel: create(:channel_twitter_profile, account: account)) conversation = create(:conversation, inbox: twitter_inbox, additional_attributes: { type: 'tweet' }) expect(message_builder).not_to receive(:perform) @@ -102,6 +102,7 @@ RSpec.describe AutomationRules::ActionService do allow(mailer).to receive(:conversation_transcript).with(conversation, 'agent1@example.com') described_class.new(rule, account, conversation).perform + expect(mailer).to have_received(:conversation_transcript).exactly(3).times end it 'will send email to transcript to contacts' do @@ -113,6 +114,7 @@ RSpec.describe AutomationRules::ActionService do allow(mailer).to receive(:conversation_transcript).with(conversation, conversation.contact.email) described_class.new(rule.reload, account, conversation).perform + expect(mailer).to have_received(:conversation_transcript).exactly(1).times end end end diff --git a/spec/services/contacts/filter_service_spec.rb b/spec/services/contacts/filter_service_spec.rb index 7e6661aed..d1b34b4a3 100644 --- a/spec/services/contacts/filter_service_spec.rb +++ b/spec/services/contacts/filter_service_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe ::Contacts::FilterService do +describe Contacts::FilterService do subject(:filter_service) { described_class } let!(:account) { create(:account) } diff --git a/spec/services/conversations/filter_service_spec.rb b/spec/services/conversations/filter_service_spec.rb index a3e6edc27..22defad0e 100644 --- a/spec/services/conversations/filter_service_spec.rb +++ b/spec/services/conversations/filter_service_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe ::Conversations::FilterService do +describe Conversations::FilterService do subject(:filter_service) { described_class } let!(:account) { create(:account) } diff --git a/spec/services/facebook/send_on_facebook_service_spec.rb b/spec/services/facebook/send_on_facebook_service_spec.rb index dc938550b..39a194ca4 100644 --- a/spec/services/facebook/send_on_facebook_service_spec.rb +++ b/spec/services/facebook/send_on_facebook_service_spec.rb @@ -22,25 +22,25 @@ describe Facebook::SendOnFacebookService do context 'without reply' do it 'if message is private' do message = create(:message, message_type: 'outgoing', private: true, inbox: facebook_inbox, account: account) - ::Facebook::SendOnFacebookService.new(message: message).perform + described_class.new(message: message).perform expect(bot).not_to have_received(:deliver) end it 'if inbox channel is not facebook page' do message = create(:message, message_type: 'outgoing', inbox: widget_inbox, account: account) - expect { ::Facebook::SendOnFacebookService.new(message: message).perform }.to raise_error 'Invalid channel service was called' + expect { described_class.new(message: message).perform }.to raise_error 'Invalid channel service was called' expect(bot).not_to have_received(:deliver) end it 'if message is not outgoing' do message = create(:message, message_type: 'incoming', inbox: facebook_inbox, account: account) - ::Facebook::SendOnFacebookService.new(message: message).perform + described_class.new(message: message).perform expect(bot).not_to have_received(:deliver) end it 'if message has an FB ID' do message = create(:message, message_type: 'outgoing', inbox: facebook_inbox, account: account, source_id: SecureRandom.uuid) - ::Facebook::SendOnFacebookService.new(message: message).perform + described_class.new(message: message).perform expect(bot).not_to have_received(:deliver) end end @@ -48,14 +48,14 @@ describe Facebook::SendOnFacebookService do context 'with reply' do it 'if message is sent from chatwoot and is outgoing' do message = create(:message, message_type: 'outgoing', inbox: facebook_inbox, account: account, conversation: conversation) - ::Facebook::SendOnFacebookService.new(message: message).perform + described_class.new(message: message).perform expect(bot).to have_received(:deliver) end it 'raise and exception to validate access token' do message = create(:message, message_type: 'outgoing', inbox: facebook_inbox, account: account, conversation: conversation) allow(bot).to receive(:deliver).and_raise(Facebook::Messenger::FacebookError.new('message' => 'Error validating access token')) - ::Facebook::SendOnFacebookService.new(message: message).perform + described_class.new(message: message).perform expect(facebook_channel.authorization_error_count).to eq(1) end @@ -63,10 +63,10 @@ describe Facebook::SendOnFacebookService do it 'if message with attachment is sent from chatwoot and is outgoing' do message = build(:message, message_type: 'outgoing', inbox: facebook_inbox, account: account, conversation: conversation) 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') message.save! allow(attachment).to receive(:download_url).and_return('url1') - ::Facebook::SendOnFacebookService.new(message: message).perform + described_class.new(message: message).perform expect(bot).to have_received(:deliver).with({ recipient: { id: contact_inbox.source_id }, message: { text: message.content }, diff --git a/spec/services/instagram/send_on_instagram_service_spec.rb b/spec/services/instagram/send_on_instagram_service_spec.rb index f42efa1df..ee553a7d8 100644 --- a/spec/services/instagram/send_on_instagram_service_spec.rb +++ b/spec/services/instagram/send_on_instagram_service_spec.rb @@ -48,7 +48,7 @@ describe Instagram::SendOnInstagramService do } ) - response = ::Instagram::SendOnInstagramService.new(message: message).perform + response = described_class.new(message: message).perform expect(response).to eq({ message_id: 'anyrandommessageid1234567890' }) end @@ -56,9 +56,9 @@ describe Instagram::SendOnInstagramService do it 'if message with attachment is sent from chatwoot and is outgoing' do message = build(:message, message_type: 'outgoing', inbox: instagram_inbox, account: account, conversation: conversation) 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') message.save! - response = ::Instagram::SendOnInstagramService.new(message: message).perform + response = described_class.new(message: message).perform expect(response).to eq({ message_id: 'anyrandommessageid1234567890' }) end @@ -87,7 +87,8 @@ describe Instagram::SendOnInstagramService do } ) - ::Instagram::SendOnInstagramService.new(message: message).perform + described_class.new(message: message).perform + expect(HTTParty).to have_received(:post) end end end diff --git a/spec/services/message_templates/hook_execution_service_spec.rb b/spec/services/message_templates/hook_execution_service_spec.rb index b8255d903..6c9820564 100644 --- a/spec/services/message_templates/hook_execution_service_spec.rb +++ b/spec/services/message_templates/hook_execution_service_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe ::MessageTemplates::HookExecutionService do +describe MessageTemplates::HookExecutionService do context 'when Greeting Message' do it 'doesnot calls ::MessageTemplates::Template::Greeting if greeting_message is empty' do contact = create(:contact, email: nil) @@ -10,15 +10,15 @@ describe ::MessageTemplates::HookExecutionService do email_collect_service = double - allow(::MessageTemplates::Template::EmailCollect).to receive(:new).and_return(email_collect_service) + allow(MessageTemplates::Template::EmailCollect).to receive(:new).and_return(email_collect_service) allow(email_collect_service).to receive(:perform).and_return(true) - allow(::MessageTemplates::Template::Greeting).to receive(:new) + allow(MessageTemplates::Template::Greeting).to receive(:new) # described class gets called in message after commit message = create(:message, conversation: conversation) - expect(::MessageTemplates::Template::Greeting).not_to have_received(:new) - expect(::MessageTemplates::Template::EmailCollect).to have_received(:new).with(conversation: message.conversation) + expect(MessageTemplates::Template::Greeting).not_to have_received(:new) + expect(MessageTemplates::Template::EmailCollect).to have_received(:new).with(conversation: message.conversation) expect(email_collect_service).to have_received(:perform) end @@ -30,11 +30,11 @@ describe ::MessageTemplates::HookExecutionService do conversation = create(:conversation, inbox: twitter_inbox, additional_attributes: { type: 'tweet' }) greeting_service = double - allow(::MessageTemplates::Template::Greeting).to receive(:new).and_return(greeting_service) + allow(MessageTemplates::Template::Greeting).to receive(:new).and_return(greeting_service) allow(greeting_service).to receive(:perform).and_return(true) message = create(:message, conversation: conversation) - expect(::MessageTemplates::Template::Greeting).not_to have_received(:new).with(conversation: message.conversation) + expect(MessageTemplates::Template::Greeting).not_to have_received(:new).with(conversation: message.conversation) end end @@ -48,17 +48,17 @@ describe ::MessageTemplates::HookExecutionService do email_collect_service = double greeting_service = double - allow(::MessageTemplates::Template::EmailCollect).to receive(:new).and_return(email_collect_service) + allow(MessageTemplates::Template::EmailCollect).to receive(:new).and_return(email_collect_service) allow(email_collect_service).to receive(:perform).and_return(true) - allow(::MessageTemplates::Template::Greeting).to receive(:new).and_return(greeting_service) + allow(MessageTemplates::Template::Greeting).to receive(:new).and_return(greeting_service) allow(greeting_service).to receive(:perform).and_return(true) # described class gets called in message after commit message = create(:message, conversation: conversation) - expect(::MessageTemplates::Template::Greeting).to have_received(:new).with(conversation: message.conversation) + expect(MessageTemplates::Template::Greeting).to have_received(:new).with(conversation: message.conversation) expect(greeting_service).to have_received(:perform) - expect(::MessageTemplates::Template::EmailCollect).to have_received(:new).with(conversation: message.conversation) + expect(MessageTemplates::Template::EmailCollect).to have_received(:new).with(conversation: message.conversation) expect(email_collect_service).to have_received(:perform) end @@ -66,12 +66,12 @@ describe ::MessageTemplates::HookExecutionService do contact = create(:contact, email: nil) conversation = create(:conversation, contact: contact, campaign: create(:campaign)) - allow(::MessageTemplates::Template::EmailCollect).to receive(:new).and_return(true) + allow(MessageTemplates::Template::EmailCollect).to receive(:new).and_return(true) # described class gets called in message after commit message = create(:message, conversation: conversation) - expect(::MessageTemplates::Template::EmailCollect).not_to have_received(:new).with(conversation: message.conversation) + expect(MessageTemplates::Template::EmailCollect).not_to have_received(:new).with(conversation: message.conversation) end it 'doesnot calls ::MessageTemplates::Template::EmailCollect when enable_email_collect form is disabled' do @@ -81,12 +81,12 @@ describe ::MessageTemplates::HookExecutionService do conversation.inbox.update(enable_email_collect: false) # ensure prechat form is enabled conversation.inbox.channel.update(pre_chat_form_enabled: true) - allow(::MessageTemplates::Template::EmailCollect).to receive(:new).and_return(true) + allow(MessageTemplates::Template::EmailCollect).to receive(:new).and_return(true) # described class gets called in message after commit message = create(:message, conversation: conversation) - expect(::MessageTemplates::Template::EmailCollect).not_to have_received(:new).with(conversation: message.conversation) + expect(MessageTemplates::Template::EmailCollect).not_to have_received(:new).with(conversation: message.conversation) end end @@ -95,7 +95,7 @@ describe ::MessageTemplates::HookExecutionService do let(:conversation) { create(:conversation) } before do - allow(::MessageTemplates::Template::CsatSurvey).to receive(:new).and_return(csat_survey) + allow(MessageTemplates::Template::CsatSurvey).to receive(:new).and_return(csat_survey) allow(csat_survey).to receive(:perform).and_return(true) end @@ -107,7 +107,7 @@ describe ::MessageTemplates::HookExecutionService do { account_id: conversation.account_id, inbox_id: conversation.inbox_id, message_type: :activity, content: 'Conversation marked resolved!!' }) - expect(::MessageTemplates::Template::CsatSurvey).to have_received(:new).with(conversation: conversation) + expect(MessageTemplates::Template::CsatSurvey).to have_received(:new).with(conversation: conversation) expect(csat_survey).to have_received(:perform) end @@ -119,7 +119,7 @@ describe ::MessageTemplates::HookExecutionService do { account_id: conversation.account_id, inbox_id: conversation.inbox_id, message_type: :activity, content: 'Conversation marked resolved!!' }) - expect(::MessageTemplates::Template::CsatSurvey).not_to have_received(:new).with(conversation: conversation) + expect(MessageTemplates::Template::CsatSurvey).not_to have_received(:new).with(conversation: conversation) expect(csat_survey).not_to have_received(:perform) end @@ -134,7 +134,7 @@ describe ::MessageTemplates::HookExecutionService do { account_id: conversation.account_id, inbox_id: conversation.inbox_id, message_type: :activity, content: 'Conversation marked resolved!!' }) - expect(::MessageTemplates::Template::CsatSurvey).not_to have_received(:new).with(conversation: conversation) + expect(MessageTemplates::Template::CsatSurvey).not_to have_received(:new).with(conversation: conversation) expect(csat_survey).not_to have_received(:perform) end @@ -147,47 +147,47 @@ describe ::MessageTemplates::HookExecutionService do { account_id: conversation.account_id, inbox_id: conversation.inbox_id, message_type: :activity, content: 'Conversation marked resolved!!' }) - expect(::MessageTemplates::Template::CsatSurvey).not_to have_received(:new).with(conversation: conversation) + expect(MessageTemplates::Template::CsatSurvey).not_to have_received(:new).with(conversation: conversation) expect(csat_survey).not_to have_received(:perform) end end context 'when it is after working hours' do it 'calls ::MessageTemplates::Template::OutOfOffice' do - contact = create :contact - conversation = create :conversation, contact: contact + 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.working_hours.today.update!(closed_all_day: true) out_of_office_service = double - allow(::MessageTemplates::Template::OutOfOffice).to receive(:new).and_return(out_of_office_service) + allow(MessageTemplates::Template::OutOfOffice).to receive(:new).and_return(out_of_office_service) allow(out_of_office_service).to receive(:perform).and_return(true) # described class gets called in message after commit message = create(:message, conversation: conversation) - expect(::MessageTemplates::Template::OutOfOffice).to have_received(:new).with(conversation: message.conversation) + expect(MessageTemplates::Template::OutOfOffice).to have_received(:new).with(conversation: message.conversation) expect(out_of_office_service).to have_received(:perform) end it 'will not calls ::MessageTemplates::Template::OutOfOffice when outgoing message' do - contact = create :contact - conversation = create :conversation, contact: contact + 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.working_hours.today.update!(closed_all_day: true) out_of_office_service = double - allow(::MessageTemplates::Template::OutOfOffice).to receive(:new).and_return(out_of_office_service) + allow(MessageTemplates::Template::OutOfOffice).to receive(:new).and_return(out_of_office_service) allow(out_of_office_service).to receive(:perform).and_return(true) # described class gets called in message after commit message = create(:message, conversation: conversation, message_type: 'outgoing') - expect(::MessageTemplates::Template::OutOfOffice).not_to have_received(:new).with(conversation: message.conversation) + expect(MessageTemplates::Template::OutOfOffice).not_to have_received(:new).with(conversation: message.conversation) expect(out_of_office_service).not_to have_received(:perform) end @@ -200,11 +200,11 @@ describe ::MessageTemplates::HookExecutionService do out_of_office_service = double - allow(::MessageTemplates::Template::OutOfOffice).to receive(:new).and_return(out_of_office_service) + allow(MessageTemplates::Template::OutOfOffice).to receive(:new).and_return(out_of_office_service) allow(out_of_office_service).to receive(:perform).and_return(false) message = create(:message, conversation: conversation) - expect(::MessageTemplates::Template::OutOfOffice).not_to have_received(:new).with(conversation: message.conversation) + expect(MessageTemplates::Template::OutOfOffice).not_to have_received(:new).with(conversation: message.conversation) expect(out_of_office_service).not_to receive(:perform) end end diff --git a/spec/services/message_templates/template/csat_survey_spec.rb b/spec/services/message_templates/template/csat_survey_spec.rb index e02c93520..dae44ca3e 100644 --- a/spec/services/message_templates/template/csat_survey_spec.rb +++ b/spec/services/message_templates/template/csat_survey_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe ::MessageTemplates::Template::CsatSurvey do +describe MessageTemplates::Template::CsatSurvey do context 'when this hook is called' do let(:conversation) { create(:conversation) } diff --git a/spec/services/message_templates/template/email_collect_spec.rb b/spec/services/message_templates/template/email_collect_spec.rb index 4fe5256c7..402ca8278 100644 --- a/spec/services/message_templates/template/email_collect_spec.rb +++ b/spec/services/message_templates/template/email_collect_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe ::MessageTemplates::Template::EmailCollect do +describe MessageTemplates::Template::EmailCollect do context 'when this hook is called' do let(:conversation) { create(:conversation) } diff --git a/spec/services/message_templates/template/greeting_spec.rb b/spec/services/message_templates/template/greeting_spec.rb index 3d7645e3a..d7fc7690f 100644 --- a/spec/services/message_templates/template/greeting_spec.rb +++ b/spec/services/message_templates/template/greeting_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe ::MessageTemplates::Template::Greeting do +describe MessageTemplates::Template::Greeting do context 'when this hook is called' do let(:conversation) { create(:conversation) } diff --git a/spec/services/message_templates/template/out_of_office_spec.rb b/spec/services/message_templates/template/out_of_office_spec.rb index 5fb0dbf79..e9e987192 100644 --- a/spec/services/message_templates/template/out_of_office_spec.rb +++ b/spec/services/message_templates/template/out_of_office_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe ::MessageTemplates::Template::OutOfOffice do +describe MessageTemplates::Template::OutOfOffice do context 'when this hook is called' do let(:conversation) { create(:conversation) } diff --git a/spec/services/messages/mention_service_spec.rb b/spec/services/messages/mention_service_spec.rb index 21484ab13..6090a013c 100644 --- a/spec/services/messages/mention_service_spec.rb +++ b/spec/services/messages/mention_service_spec.rb @@ -64,7 +64,7 @@ describe Messages::MentionService do it 'add the users to the participants list' do described_class.new(message: message).perform - expect(conversation.conversation_participants.map(&:user_id)).to match_array([first_agent.id, second_agent.id]) + expect(conversation.conversation_participants.map(&:user_id)).to contain_exactly(first_agent.id, second_agent.id) end end end diff --git a/spec/services/search_service_spec.rb b/spec/services/search_service_spec.rb index 3bc45e9ae..5242d893e 100644 --- a/spec/services/search_service_spec.rb +++ b/spec/services/search_service_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe ::SearchService do +describe SearchService do subject(:search) { described_class.new(current_user: user, current_account: account, params: params, search_type: search_type) } let(:search_type) { 'all' } diff --git a/spec/services/sms/send_on_sms_service_spec.rb b/spec/services/sms/send_on_sms_service_spec.rb index 422861e06..d2dc1f24a 100644 --- a/spec/services/sms/send_on_sms_service_spec.rb +++ b/spec/services/sms/send_on_sms_service_spec.rb @@ -28,9 +28,9 @@ describe Sms::SendOnSmsService do message = build(:message, message_type: :outgoing, content: 'test', conversation: conversation) 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') attachment2 = message.attachments.new(account_id: message.account_id, file_type: :image) - attachment2.file.attach(io: File.open(Rails.root.join('spec/assets/avatar.png')), filename: 'avatar.png', content_type: 'image/png') + attachment2.file.attach(io: Rails.root.join('spec/assets/avatar.png').open, filename: 'avatar.png', content_type: 'image/png') message.save! allow(HTTParty).to receive(:post).and_return(sms_request) diff --git a/spec/services/twilio/oneoff_sms_campaign_service_spec.rb b/spec/services/twilio/oneoff_sms_campaign_service_spec.rb index 37338f889..da5d871d9 100644 --- a/spec/services/twilio/oneoff_sms_campaign_service_spec.rb +++ b/spec/services/twilio/oneoff_sms_campaign_service_spec.rb @@ -17,7 +17,7 @@ describe Twilio::OneoffSmsCampaignService do describe 'perform' do 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 diff --git a/spec/services/twilio/send_on_twilio_service_spec.rb b/spec/services/twilio/send_on_twilio_service_spec.rb index cc0ead00e..9579dd840 100644 --- a/spec/services/twilio/send_on_twilio_service_spec.rb +++ b/spec/services/twilio/send_on_twilio_service_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' describe Twilio::SendOnTwilioService do subject(:outgoing_message_service) { described_class.new(message: message) } - let(:twilio_client) { instance_double(::Twilio::REST::Client) } + let(:twilio_client) { instance_double(Twilio::REST::Client) } let(:messages_double) { double } let(:message_record_double) { double } @@ -18,7 +18,7 @@ describe Twilio::SendOnTwilioService do let(:conversation) { create(:conversation, contact: contact, inbox: twilio_inbox, contact_inbox: contact_inbox) } 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(messages_double) end @@ -26,27 +26,27 @@ describe Twilio::SendOnTwilioService do context 'without reply' do it 'if message is private' do message = create(:message, message_type: 'outgoing', private: true, inbox: twilio_inbox, account: account) - ::Twilio::SendOnTwilioService.new(message: message).perform + described_class.new(message: message).perform expect(twilio_client).not_to have_received(:messages) expect(message.reload.source_id).to be_nil end it 'if inbox channel is not twilio' do message = create(:message, message_type: 'outgoing', inbox: widget_inbox, account: account) - expect { ::Twilio::SendOnTwilioService.new(message: message).perform }.to raise_error 'Invalid channel service was called' + expect { described_class.new(message: message).perform }.to raise_error 'Invalid channel service was called' expect(twilio_client).not_to have_received(:messages) end it 'if message is not outgoing' do message = create(:message, message_type: 'incoming', inbox: twilio_inbox, account: account) - ::Twilio::SendOnTwilioService.new(message: message).perform + described_class.new(message: message).perform expect(twilio_client).not_to have_received(:messages) expect(message.reload.source_id).to be_nil end it 'if message has an source id' do message = create(:message, message_type: 'outgoing', inbox: twilio_inbox, account: account, source_id: SecureRandom.uuid) - ::Twilio::SendOnTwilioService.new(message: message).perform + described_class.new(message: message).perform expect(twilio_client).not_to have_received(:messages) end end @@ -59,7 +59,7 @@ describe Twilio::SendOnTwilioService do outgoing_message = create( :message, message_type: 'outgoing', inbox: twilio_inbox, account: account, conversation: conversation ) - ::Twilio::SendOnTwilioService.new(message: outgoing_message).perform + described_class.new(message: outgoing_message).perform expect(outgoing_message.reload.source_id).to eq('1234') end @@ -74,10 +74,11 @@ describe Twilio::SendOnTwilioService do :message, message_type: 'outgoing', inbox: twilio_whatsapp_inbox, account: account, conversation: conversation ) 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') message.save! - ::Twilio::SendOnTwilioService.new(message: message).perform + described_class.new(message: message).perform + expect(messages_double).to have_received(:create).with(hash_including(media_url: [anything])) end it 'if outgoing message has attachment and is for sms' do @@ -89,10 +90,11 @@ describe Twilio::SendOnTwilioService do :message, message_type: 'outgoing', inbox: twilio_inbox, account: account, conversation: conversation ) 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') message.save! - ::Twilio::SendOnTwilioService.new(message: message).perform + described_class.new(message: message).perform + expect(messages_double).to have_received(:create).with(hash_including(media_url: [anything])) end end end diff --git a/spec/services/twilio/webhook_setup_service_spec.rb b/spec/services/twilio/webhook_setup_service_spec.rb index 1fb64b4a1..b45a8a895 100644 --- a/spec/services/twilio/webhook_setup_service_spec.rb +++ b/spec/services/twilio/webhook_setup_service_spec.rb @@ -3,10 +3,10 @@ require 'rails_helper' describe Twilio::WebhookSetupService do include Rails.application.routes.url_helpers - let(:twilio_client) { instance_double(::Twilio::REST::Client) } + let(:twilio_client) { instance_double(Twilio::REST::Client) } before do - allow(::Twilio::REST::Client).to receive(:new).and_return(twilio_client) + allow(Twilio::REST::Client).to receive(:new).and_return(twilio_client) end describe '#perform' do diff --git a/spec/services/twitter/send_on_twitter_service_spec.rb b/spec/services/twitter/send_on_twitter_service_spec.rb index 19b21fc49..93b58253b 100644 --- a/spec/services/twitter/send_on_twitter_service_spec.rb +++ b/spec/services/twitter/send_on_twitter_service_spec.rb @@ -3,8 +3,8 @@ require 'rails_helper' describe Twitter::SendOnTwitterService do subject(:send_reply_service) { described_class.new(message: message) } - let(:twitter_client) { instance_double(::Twitty::Facade) } - let(:twitter_response) { instance_double(::Twitty::Response) } + let(:twitter_client) { instance_double(Twitty::Facade) } + let(:twitter_response) { instance_double(Twitty::Response) } let(:account) { create(:account) } let(:widget_inbox) { create(:inbox, account: account) } let(:twitter_channel) { create(:channel_twitter_profile, account: account) } @@ -31,7 +31,7 @@ describe Twitter::SendOnTwitterService do end before do - allow(::Twitty::Facade).to receive(:new).and_return(twitter_client) + allow(Twitty::Facade).to receive(:new).and_return(twitter_client) allow(twitter_client).to receive(:send_direct_message).and_return(true) allow(twitter_client).to receive(:send_tweet_reply).and_return(twitter_response) allow(twitter_response).to receive(:status).and_return('200') @@ -42,25 +42,25 @@ describe Twitter::SendOnTwitterService do context 'without reply' do it 'if inbox channel is not twitter profile' do message = create(:message, message_type: 'outgoing', inbox: widget_inbox, account: account) - expect { ::Twitter::SendOnTwitterService.new(message: message).perform }.to raise_error 'Invalid channel service was called' + expect { described_class.new(message: message).perform }.to raise_error 'Invalid channel service was called' expect(twitter_client).not_to have_received(:send_direct_message) end it 'if message is private' do message = create(:message, message_type: 'outgoing', private: true, inbox: twitter_inbox, account: account) - ::Twitter::SendOnTwitterService.new(message: message).perform + described_class.new(message: message).perform expect(twitter_client).not_to have_received(:send_direct_message) end it 'if message has source_id' do message = create(:message, message_type: 'outgoing', source_id: '123', inbox: twitter_inbox, account: account) - ::Twitter::SendOnTwitterService.new(message: message).perform + described_class.new(message: message).perform expect(twitter_client).not_to have_received(:send_direct_message) end it 'if message is not outgoing' do message = create(:message, message_type: 'incoming', inbox: twitter_inbox, account: account) - ::Twitter::SendOnTwitterService.new(message: message).perform + described_class.new(message: message).perform expect(twitter_client).not_to have_received(:send_direct_message) end end @@ -69,7 +69,7 @@ describe Twitter::SendOnTwitterService do it 'if conversation is a direct message' do create(:message, message_type: :incoming, inbox: twitter_inbox, account: account, conversation: dm_conversation) message = create(:message, message_type: :outgoing, inbox: twitter_inbox, account: account, conversation: dm_conversation) - ::Twitter::SendOnTwitterService.new(message: message).perform + described_class.new(message: message).perform expect(twitter_client).to have_received(:send_direct_message) end @@ -85,7 +85,7 @@ describe Twitter::SendOnTwitterService do conversation: tweet_conversation ) message = create(:message, message_type: :outgoing, inbox: twitter_inbox, account: account, conversation: tweet_conversation) - ::Twitter::SendOnTwitterService.new(message: message).perform + described_class.new(message: message).perform expect(twitter_client).to have_received(:send_tweet_reply).with( reply_to_tweet_id: 'test-source-id-1', tweet: "@test_user #{message.content}" @@ -110,7 +110,7 @@ describe Twitter::SendOnTwitterService do conversation: tweet_conversation, in_reply_to: outgoing_message.id ) - ::Twitter::SendOnTwitterService.new(message: reply_message).perform + described_class.new(message: reply_message).perform expect(twitter_client).to have_received(:send_tweet_reply).with( reply_to_tweet_id: 'test-source-id-1', tweet: "@#{twitter_inbox.name} #{reply_message.content}" diff --git a/spec/services/twitter/webhook_subscribe_service_spec.rb b/spec/services/twitter/webhook_subscribe_service_spec.rb index c94314836..67cc3b372 100644 --- a/spec/services/twitter/webhook_subscribe_service_spec.rb +++ b/spec/services/twitter/webhook_subscribe_service_spec.rb @@ -1,28 +1,28 @@ require 'rails_helper' -describe ::Twitter::WebhookSubscribeService do +describe Twitter::WebhookSubscribeService do subject(:webhook_subscribe_service) { described_class.new(inbox_id: twitter_inbox.id) } - let(:twitter_client) { instance_double(::Twitty::Facade) } - let(:twitter_success_response) { instance_double(::Twitty::Response, status: '200', body: { message: 'Valid' }) } - let(:twitter_error_response) { instance_double(::Twitty::Response, status: '422', body: { message: 'Invalid request' }) } + let(:twitter_client) { instance_double(Twitty::Facade) } + let(:twitter_success_response) { instance_double(Twitty::Response, status: '200', body: { message: 'Valid' }) } + let(:twitter_error_response) { instance_double(Twitty::Response, status: '422', body: { message: 'Invalid request' }) } let(:account) { create(:account) } let(:twitter_channel) { create(:channel_twitter_profile, account: account) } let(:twitter_inbox) { create(:inbox, channel: twitter_channel, account: account) } before do - allow(::Twitty::Facade).to receive(:new).and_return(twitter_client) + allow(Twitty::Facade).to receive(:new).and_return(twitter_client) allow(twitter_client).to receive(:register_webhook).and_return(twitter_success_response) allow(twitter_client).to receive(:unregister_webhook).and_return(twitter_success_response) - allow(twitter_client).to receive(:fetch_subscriptions).and_return(instance_double(::Twitty::Response, status: '204', body: { message: 'Valid' })) - allow(twitter_client).to receive(:create_subscription).and_return(instance_double(::Twitty::Response, status: '204', body: { message: 'Valid' })) + allow(twitter_client).to receive(:fetch_subscriptions).and_return(instance_double(Twitty::Response, status: '204', body: { message: 'Valid' })) + allow(twitter_client).to receive(:create_subscription).and_return(instance_double(Twitty::Response, status: '204', body: { message: 'Valid' })) end describe '#perform' do context 'when webhook is not registered' do it 'calls register_webhook' do allow(twitter_client).to receive(:fetch_webhooks).and_return( - instance_double(::Twitty::Response, status: '200', body: {}) + instance_double(Twitty::Response, status: '200', body: {}) ) webhook_subscribe_service.perform expect(twitter_client).not_to have_received(:unregister_webhook) @@ -33,8 +33,8 @@ describe ::Twitter::WebhookSubscribeService do context 'when valid webhook is registered' do it 'calls unregister_webhook and then register webhook' do allow(twitter_client).to receive(:fetch_webhooks).and_return( - instance_double(::Twitty::Response, status: '200', - body: [{ 'url' => webhook_subscribe_service.send(:twitter_url) }]) + instance_double(Twitty::Response, status: '200', + body: [{ 'url' => webhook_subscribe_service.send(:twitter_url) }]) ) webhook_subscribe_service.perform expect(twitter_client).not_to have_received(:unregister_webhook) @@ -45,8 +45,8 @@ describe ::Twitter::WebhookSubscribeService do context 'when invalid webhook is registered' do it 'calls unregister_webhook and then register webhook' do allow(twitter_client).to receive(:fetch_webhooks).and_return( - instance_double(::Twitty::Response, status: '200', - body: [{ 'url' => 'invalid_url' }]) + instance_double(Twitty::Response, status: '200', + body: [{ 'url' => 'invalid_url' }]) ) webhook_subscribe_service.perform expect(twitter_client).to have_received(:unregister_webhook) @@ -57,18 +57,18 @@ describe ::Twitter::WebhookSubscribeService do context 'when correct webhook is present' do it 'calls create subscription if subscription is not present' do allow(twitter_client).to receive(:fetch_webhooks).and_return( - instance_double(::Twitty::Response, status: '200', - body: [{ 'url' => webhook_subscribe_service.send(:twitter_url) }]) + instance_double(Twitty::Response, status: '200', + body: [{ 'url' => webhook_subscribe_service.send(:twitter_url) }]) ) - allow(twitter_client).to receive(:fetch_subscriptions).and_return(instance_double(::Twitty::Response, status: '500')) + allow(twitter_client).to receive(:fetch_subscriptions).and_return(instance_double(Twitty::Response, status: '500')) webhook_subscribe_service.perform expect(twitter_client).to have_received(:create_subscription) end it 'does not call create subscription if subscription is already present' do allow(twitter_client).to receive(:fetch_webhooks).and_return( - instance_double(::Twitty::Response, status: '200', - body: [{ 'url' => webhook_subscribe_service.send(:twitter_url) }]) + instance_double(Twitty::Response, status: '200', + body: [{ 'url' => webhook_subscribe_service.send(:twitter_url) }]) ) webhook_subscribe_service.perform expect(twitter_client).not_to have_received(:create_subscription) diff --git a/spec/services/whatsapp/incoming_message_service_spec.rb b/spec/services/whatsapp/incoming_message_service_spec.rb index c141f869e..07f503162 100644 --- a/spec/services/whatsapp/incoming_message_service_spec.rb +++ b/spec/services/whatsapp/incoming_message_service_spec.rb @@ -328,15 +328,15 @@ describe Whatsapp::IncomingMessageService do expect(Message.find_by(source_id: 'wamid.SDFADSf23sfasdafasdfa')).not_to be_present key = format(Redis::RedisKeys::MESSAGE_SOURCE_KEY, id: 'wamid.SDFADSf23sfasdafasdfa') - ::Redis::Alfred.setex(key, true) - expect(::Redis::Alfred.get(key)).to be_truthy + Redis::Alfred.setex(key, true) + expect(Redis::Alfred.get(key)).to be_truthy described_class.new(inbox: whatsapp_channel.inbox, params: params).perform expect(whatsapp_channel.inbox.messages.count).to eq(0) expect(Message.find_by(source_id: 'wamid.SDFADSf23sfasdafasdfa')).not_to be_present - expect(::Redis::Alfred.get(key)).to be_truthy - ::Redis::Alfred.delete(key) + expect(Redis::Alfred.get(key)).to be_truthy + Redis::Alfred.delete(key) end end end diff --git a/spec/services/whatsapp/providers/whatsapp_cloud_service_spec.rb b/spec/services/whatsapp/providers/whatsapp_cloud_service_spec.rb index 8946dfc9f..3fbea97e9 100644 --- a/spec/services/whatsapp/providers/whatsapp_cloud_service_spec.rb +++ b/spec/services/whatsapp/providers/whatsapp_cloud_service_spec.rb @@ -30,7 +30,7 @@ describe Whatsapp::Providers::WhatsappCloudService do it 'calls message endpoints for image attachment message messages' 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') stub_request(:post, 'https://graph.facebook.com/v13.0/123456789/messages') .with( @@ -47,7 +47,7 @@ describe Whatsapp::Providers::WhatsappCloudService do it 'calls message endpoints for document attachment message messages' do attachment = message.attachments.new(account_id: message.account_id, file_type: :file) - attachment.file.attach(io: File.open(Rails.root.join('spec/assets/sample.pdf')), filename: 'sample.pdf', content_type: 'application/pdf') + attachment.file.attach(io: Rails.root.join('spec/assets/sample.pdf').open, filename: 'sample.pdf', content_type: 'application/pdf') # ref: https://github.com/bblimke/webmock/issues/900 # reason for Webmock::API.hash_including diff --git a/spec/workers/conversation_reply_email_worker_spec.rb b/spec/workers/conversation_reply_email_worker_spec.rb index 3483c04a5..7b28eedde 100644 --- a/spec/workers/conversation_reply_email_worker_spec.rb +++ b/spec/workers/conversation_reply_email_worker_spec.rb @@ -20,7 +20,7 @@ RSpec.describe ConversationReplyEmailWorker, type: :worker do it 'worker jobs are enqueued in the mailers queue' do described_class.perform_async - assert_equal :mailers, described_class.queue + expect(described_class.queue).to eq(:mailers) end it 'goes into the jobs array for testing environment' do