From 4187428729be31879c8d10e6b10c4114ad2bc478 Mon Sep 17 00:00:00 2001 From: Sojan Jose Date: Fri, 15 Jul 2022 04:51:59 +0200 Subject: [PATCH] chore: Update dependencies to the latest versions (#5033) --- .circleci/config.yml | 11 +- Gemfile | 9 +- Gemfile.lock | 405 ++++++++++-------- .../campaign_conversation_builder.rb | 5 +- .../platform/api/v1/users_controller.rb | 2 +- app/jobs/contact_ip_lookup_job.rb | 2 +- .../channel_notifications_mailer.rb | 6 +- app/models/account.rb | 2 +- app/models/category.rb | 2 +- app/models/channel/telegram.rb | 2 +- app/models/contact.rb | 4 +- app/models/data_import.rb | 2 +- app/models/inbox.rb | 8 +- app/models/installation_config.rb | 4 + app/models/integrations/app.rb | 4 +- app/models/label.rb | 2 +- app/models/message.rb | 2 +- app/models/team.rb | 2 +- .../notification/push_notification_service.rb | 2 +- .../providers/whatsapp_360_dialog_service.rb | 2 +- config/application.rb | 5 + config/initializers/datadog.rb | 4 +- config/initializers/geocoder.rb | 2 +- config/initializers/mailer.rb | 4 +- config/locales/en.yml | 12 + docker/entrypoints/helpers/pg_database_url.rb | 2 +- lib/chatwoot_hub.rb | 2 +- lib/global_config_service.rb | 4 +- .../slack/send_on_slack_service.rb | 2 +- lib/tasks/db_enhancements.rake | 2 +- lib/vapid_service.rb | 4 +- spec/actions/contact_identify_action_spec.rb | 8 +- spec/actions/contact_merge_action_spec.rb | 2 +- .../campaign_conversation_builder_spec.rb | 2 +- spec/builders/contact_inbox_builder_spec.rb | 8 +- .../csat_surveys/response_builder_spec.rb | 2 +- .../v1/accounts/agent_bots_controller_spec.rb | 4 +- .../api/v1/accounts/agents_controller_spec.rb | 2 +- .../v1/accounts/articles_controller_spec.rb | 10 +- .../automation_rules_controller_spec.rb | 6 +- .../accounts/bulk_actions_controller_spec.rb | 10 +- .../v1/accounts/campaigns_controller_spec.rb | 4 +- .../v1/accounts/categories_controller_spec.rb | 4 +- .../twilio_channels_controller_spec.rb | 2 +- .../contact_inboxes_controller_spec.rb | 2 +- .../contacts/notes_controller_spec.rb | 2 +- .../v1/accounts/contacts_controller_spec.rb | 10 +- .../assignments_controller_spec.rb | 4 +- .../conversations/messages_controller_spec.rb | 8 +- .../accounts/conversations_controller_spec.rb | 14 +- ...m_attribute_definitions_controller_spec.rb | 2 +- .../custom_filters_controller_spec.rb | 2 +- .../dashboard_apps_controller_spec.rb | 6 +- .../v1/accounts/inboxes_controller_spec.rb | 8 +- .../integrations/hooks_controller_spec.rb | 2 +- .../api/v1/accounts/labels_controller_spec.rb | 2 +- .../accounts/notifications_controller_spec.rb | 2 +- .../v1/accounts/portals_controller_spec.rb | 4 +- .../api/v1/accounts_controller_spec.rb | 4 +- .../api/v1/profiles_controller_spec.rb | 8 +- .../api/v1/widget/configs_controller_spec.rb | 2 +- .../api/v1/widget/contacts_controller_spec.rb | 4 +- .../widget/conversations_controller_spec.rb | 8 +- .../api/v1/widget/messages_controller_spec.rb | 6 +- .../devise/confirmations_controller_spec.rb | 6 +- .../onboarding_controller_spec.rb | 8 +- .../platform/api/v1/users_controller_spec.rb | 4 +- .../api/v1/inbox/contacts_controller_spec.rb | 4 +- .../v1/inbox/conversations_controller_spec.rb | 2 +- .../api/v1/inbox/messages_controller_spec.rb | 2 +- .../v1/portals/articles_controller_spec.rb | 2 +- .../service/responses_controller_spec.rb | 2 +- .../super_admin/app_config_controller_spec.rb | 2 +- .../twitter/callbacks_controller_spec.rb | 5 +- spec/controllers/widgets_controller_spec.rb | 2 +- spec/helpers/url_helper_spec.rb | 4 +- spec/jobs/bulk_actions_job_spec.rb | 2 +- .../webhooks/instagram_events_job_spec.rb | 9 +- spec/lib/chatwoot_captcha_spec.rb | 6 +- spec/lib/chatwoot_hub_spec.rb | 4 +- spec/lib/global_config_service_spec.rb | 2 +- .../csml/processor_service_spec.rb | 8 +- .../dialogflow/processor_service_spec.rb | 4 +- .../slack/incoming_message_builder_spec.rb | 6 +- spec/listeners/notification_listener_spec.rb | 2 +- spec/mailboxes/reply_mailbox_spec.rb | 4 +- spec/mailboxes/support_mailbox_spec.rb | 10 +- .../conversation_notifications_mailer_spec.rb | 2 +- .../mailers/conversation_reply_mailer_spec.rb | 4 +- spec/models/account_user_spec.rb | 6 +- spec/models/attachment_spec.rb | 2 +- spec/models/automation_rule_spec.rb | 2 +- spec/models/campaign_spec.rb | 12 +- spec/models/channel/twilio_sms_spec.rb | 4 +- spec/models/channel/whatsapp_spec.rb | 4 +- .../concerns/access_tokenable_shared.rb | 2 +- .../concerns/assignment_handler_shared.rb | 14 +- spec/models/concerns/reauthorizable_shared.rb | 12 +- .../concerns/round_robin_handler_shared.rb | 4 +- spec/models/contact_inbox_spec.rb | 4 +- spec/models/contact_spec.rb | 4 +- spec/models/conversation_spec.rb | 44 +- spec/models/csat_survey_response_spec.rb | 4 +- spec/models/data_import_spec.rb | 2 +- spec/models/inbox_spec.rb | 12 +- spec/models/integrations/hook_spec.rb | 4 +- spec/models/label_spec.rb | 12 +- spec/models/message_spec.rb | 6 +- spec/models/user_spec.rb | 10 +- spec/presenters/mail_presenter_spec.rb | 4 +- .../integrations/slack_request_spec.rb | 2 +- .../facebook/send_on_facebook_service_spec.rb | 2 +- .../line/incoming_message_service_spec.rb | 4 +- .../round_robin/manage_service_spec.rb | 2 +- .../sms/incoming_message_service_spec.rb | 2 +- .../sms/oneoff_sms_campaign_service_spec.rb | 2 +- .../telegram/incoming_message_service_spec.rb | 79 +--- .../oneoff_sms_campaign_service_spec.rb | 2 +- .../twilio/send_on_twilio_service_spec.rb | 4 +- .../twilio/webhook_setup_service_spec.rb | 4 +- .../whatsapp/incoming_message_service_spec.rb | 2 +- .../providers/whatsapp_cloud_service_spec.rb | 8 +- 122 files changed, 546 insertions(+), 526 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 2939c327d..27918bfd6 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -93,14 +93,17 @@ jobs: - run: bundle exec rake db:create - run: bundle exec rake db:schema:load - # disable till fixed - # - run: - # name: Bundle audit - # command: bundle exec bundle audit update && bundle exec bundle audit check -v + - run: + name: Bundle audit + command: bundle exec bundle audit update && bundle exec bundle audit check -v - run: name: Rubocop command: bundle exec rubocop + + # - run: + # name: Brakeman + # command: bundle exec brakeman - run: name: eslint diff --git a/Gemfile b/Gemfile index 937f0bd60..270e6527c 100644 --- a/Gemfile +++ b/Gemfile @@ -4,7 +4,7 @@ ruby '3.0.4' ##-- base gems for rails --## gem 'rack-cors', require: 'rack/cors' -gem 'rails' +gem 'rails', '~>6.1' # Reduces boot times through caching; required in config/boot.rb gem 'bootsnap', require: false @@ -89,10 +89,6 @@ gem 'slack-ruby-client' # for dialogflow integrations gem 'google-cloud-dialogflow' -##--- gems for debugging and error reporting ---## -# static analysis -gem 'brakeman' - ##-- apm and error monitoring ---# gem 'ddtrace' gem 'newrelic_rpm' @@ -160,6 +156,9 @@ end group :development, :test do gem 'active_record_query_trace' + ##--- gems for debugging and error reporting ---## + # static analysis + gem 'brakeman' gem 'bundle-audit', require: false gem 'byebug', platform: :mri gem 'climate_control' diff --git a/Gemfile.lock b/Gemfile.lock index fa8f9d9f0..7e0583757 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -9,63 +9,63 @@ GIT GEM remote: https://rubygems.org/ specs: - actioncable (6.1.5.1) - actionpack (= 6.1.5.1) - activesupport (= 6.1.5.1) + actioncable (6.1.6.1) + actionpack (= 6.1.6.1) + activesupport (= 6.1.6.1) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (6.1.5.1) - actionpack (= 6.1.5.1) - activejob (= 6.1.5.1) - activerecord (= 6.1.5.1) - activestorage (= 6.1.5.1) - activesupport (= 6.1.5.1) + actionmailbox (6.1.6.1) + actionpack (= 6.1.6.1) + activejob (= 6.1.6.1) + activerecord (= 6.1.6.1) + activestorage (= 6.1.6.1) + activesupport (= 6.1.6.1) mail (>= 2.7.1) - actionmailer (6.1.5.1) - actionpack (= 6.1.5.1) - actionview (= 6.1.5.1) - activejob (= 6.1.5.1) - activesupport (= 6.1.5.1) + actionmailer (6.1.6.1) + actionpack (= 6.1.6.1) + actionview (= 6.1.6.1) + activejob (= 6.1.6.1) + activesupport (= 6.1.6.1) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (6.1.5.1) - actionview (= 6.1.5.1) - activesupport (= 6.1.5.1) + actionpack (6.1.6.1) + actionview (= 6.1.6.1) + activesupport (= 6.1.6.1) rack (~> 2.0, >= 2.0.9) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (6.1.5.1) - actionpack (= 6.1.5.1) - activerecord (= 6.1.5.1) - activestorage (= 6.1.5.1) - activesupport (= 6.1.5.1) + actiontext (6.1.6.1) + actionpack (= 6.1.6.1) + activerecord (= 6.1.6.1) + activestorage (= 6.1.6.1) + activesupport (= 6.1.6.1) nokogiri (>= 1.8.5) - actionview (6.1.5.1) - activesupport (= 6.1.5.1) + actionview (6.1.6.1) + activesupport (= 6.1.6.1) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0) active_record_query_trace (1.8) - activejob (6.1.5.1) - activesupport (= 6.1.5.1) + activejob (6.1.6.1) + activesupport (= 6.1.6.1) globalid (>= 0.3.6) - activemodel (6.1.5.1) - activesupport (= 6.1.5.1) - activerecord (6.1.5.1) - activemodel (= 6.1.5.1) - activesupport (= 6.1.5.1) - activerecord-import (1.3.0) + activemodel (6.1.6.1) + activesupport (= 6.1.6.1) + activerecord (6.1.6.1) + activemodel (= 6.1.6.1) + activesupport (= 6.1.6.1) + activerecord-import (1.4.0) activerecord (>= 4.2) - activestorage (6.1.5.1) - actionpack (= 6.1.5.1) - activejob (= 6.1.5.1) - activerecord (= 6.1.5.1) - activesupport (= 6.1.5.1) + activestorage (6.1.6.1) + actionpack (= 6.1.6.1) + activejob (= 6.1.6.1) + activerecord (= 6.1.6.1) + activesupport (= 6.1.6.1) marcel (~> 1.0) mini_mime (>= 1.1.0) - activesupport (6.1.5.1) + activesupport (6.1.6.1) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) @@ -91,20 +91,20 @@ GEM ast (2.4.2) attr_extras (6.2.5) aws-eventstream (1.2.0) - aws-partitions (1.556.0) - aws-sdk-core (3.126.2) + aws-partitions (1.605.0) + aws-sdk-core (3.131.2) aws-eventstream (~> 1, >= 1.0.2) aws-partitions (~> 1, >= 1.525.0) aws-sigv4 (~> 1.1) - jmespath (~> 1.0) - aws-sdk-kms (1.54.0) - aws-sdk-core (~> 3, >= 3.126.0) + jmespath (~> 1, >= 1.6.1) + aws-sdk-kms (1.57.0) + aws-sdk-core (~> 3, >= 3.127.0) aws-sigv4 (~> 1.1) - aws-sdk-s3 (1.112.0) - aws-sdk-core (~> 3, >= 3.126.0) + aws-sdk-s3 (1.114.0) + aws-sdk-core (~> 3, >= 3.127.0) aws-sdk-kms (~> 1) aws-sigv4 (~> 1.4) - aws-sigv4 (1.4.0) + aws-sigv4 (1.5.0) aws-eventstream (~> 1, >= 1.0.2) azure-storage-blob (2.0.3) azure-storage-common (~> 2.0) @@ -117,31 +117,31 @@ GEM barnes (0.0.9) multi_json (~> 1) statsd-ruby (~> 1.1) - bcrypt (3.1.16) + bcrypt (3.1.18) bindex (0.8.1) - bootsnap (1.10.3) + bootsnap (1.12.0) msgpack (~> 1.2) - brakeman (5.2.1) + brakeman (5.2.3) browser (5.3.1) builder (3.2.4) - bullet (7.0.1) + bullet (7.0.2) activesupport (>= 3.0.0) uniform_notifier (~> 1.11) bundle-audit (0.1.0) bundler-audit - bundler-audit (0.9.0.1) + bundler-audit (0.9.1) bundler (>= 1.2.0, < 3) thor (~> 1.0) byebug (11.1.3) - climate_control (1.0.1) + climate_control (1.1.1) coderay (1.1.3) - commonmarker (0.23.4) + commonmarker (0.23.5) concurrent-ruby (1.1.10) connection_pool (2.2.5) crack (0.4.5) rexml crass (1.0.6) - cypress-on-rails (1.12.1) + cypress-on-rails (1.13.1) rack database_cleaner (2.0.1) database_cleaner-active_record (~> 2.0.0) @@ -151,10 +151,12 @@ GEM database_cleaner-core (2.0.1) datetime_picker_rails (0.0.7) momentjs-rails (>= 2.8.1) - ddtrace (0.54.2) - debase-ruby_core_source (<= 0.10.14) + ddtrace (1.2.0) + debase-ruby_core_source (= 0.10.16) + libddprof (~> 0.6.0.1.0) + libddwaf (~> 1.3.0.2.0) msgpack - debase-ruby_core_source (0.10.14) + debase-ruby_core_source (0.10.16) declarative (0.0.20) devise (4.8.1) bcrypt (~> 3.0) @@ -176,7 +178,7 @@ GEM dotenv-rails (2.7.6) dotenv (= 2.7.6) railties (>= 3.2) - down (5.3.0) + down (5.3.1) addressable (~> 2.8) ecma-re-validator (0.4.0) regexp_parser (~> 2.2) @@ -188,36 +190,60 @@ GEM facebook-messenger (2.0.1) httparty (~> 0.13, >= 0.13.7) rack (>= 1.4.5) - factory_bot (6.2.0) + factory_bot (6.2.1) activesupport (>= 5.0.0) factory_bot_rails (6.2.0) factory_bot (~> 6.2.0) railties (>= 5.0.0) - faker (2.19.0) - i18n (>= 1.6, < 2) - faraday (1.0.1) - multipart-post (>= 1.2, < 3) + faker (2.21.0) + i18n (>= 1.8.11, < 2) + faraday (1.10.0) + faraday-em_http (~> 1.0) + faraday-em_synchrony (~> 1.0) + faraday-excon (~> 1.1) + faraday-httpclient (~> 1.0) + faraday-multipart (~> 1.0) + faraday-net_http (~> 1.0) + faraday-net_http_persistent (~> 1.0) + faraday-patron (~> 1.0) + faraday-rack (~> 1.0) + faraday-retry (~> 1.0) + ruby2_keywords (>= 0.0.4) + faraday-em_http (1.0.0) + faraday-em_synchrony (1.0.0) + faraday-excon (1.1.0) + faraday-httpclient (1.0.1) + faraday-multipart (1.0.4) + multipart-post (~> 2) + faraday-net_http (1.0.1) + faraday-net_http_persistent (1.2.0) + faraday-patron (1.0.0) + faraday-rack (1.0.0) + faraday-retry (1.0.3) faraday_middleware (1.2.0) faraday (~> 1.0) - fcm (1.0.5) - faraday (~> 1) + fcm (1.0.8) + faraday (>= 1.0.0, < 3.0) + googleauth (~> 1) ffi (1.15.5) flag_shih_tzu (0.3.23) foreman (0.87.2) fugit (1.5.3) et-orbi (~> 1, >= 1.2.7) raabro (~> 1.4) - gapic-common (0.3.4) - google-protobuf (~> 3.12, >= 3.12.2) - googleapis-common-protos (>= 1.3.9, < 2.0) - googleapis-common-protos-types (>= 1.0.4, < 2.0) - googleauth (~> 0.9) - grpc (~> 1.25) - geocoder (1.7.3) + gapic-common (0.10.0) + faraday (>= 1.9, < 3.a) + faraday-retry (>= 1.0, < 3.a) + google-protobuf (~> 3.14) + googleapis-common-protos (>= 1.3.12, < 2.a) + googleapis-common-protos-types (>= 1.3.1, < 2.a) + googleauth (~> 1.0) + grpc (~> 1.36) + geocoder (1.8.0) gli (2.21.0) globalid (1.0.0) activesupport (>= 5.0) - google-apis-core (0.4.2) + google-apis-core (0.7.0) addressable (~> 2.5, >= 2.5.1) googleauth (>= 0.16.2, < 2.a) httpclient (>= 2.8.1, < 3.a) @@ -226,23 +252,27 @@ GEM retriable (>= 2.0, < 4.a) rexml webrick - google-apis-iamcredentials_v1 (0.10.0) - google-apis-core (>= 0.4, < 2.a) - google-apis-storage_v1 (0.11.0) - google-apis-core (>= 0.4, < 2.a) + google-apis-iamcredentials_v1 (0.13.0) + google-apis-core (>= 0.7, < 2.a) + google-apis-storage_v1 (0.18.0) + google-apis-core (>= 0.7, < 2.a) google-cloud-core (1.6.0) google-cloud-env (~> 1.0) google-cloud-errors (~> 1.0) - google-cloud-dialogflow (1.2.0) - google-cloud-core (~> 1.5) - google-cloud-dialogflow-v2 (~> 0.1) - google-cloud-dialogflow-v2 (0.6.4) - gapic-common (~> 0.3) + google-cloud-dialogflow (1.5.0) + google-cloud-core (~> 1.6) + google-cloud-dialogflow-v2 (>= 0.15, < 2.a) + google-cloud-dialogflow-v2 (0.17.0) + gapic-common (>= 0.10, < 2.a) google-cloud-errors (~> 1.0) - google-cloud-env (1.5.0) - faraday (>= 0.17.3, < 2.0) + google-cloud-location (>= 0.0, < 2.a) + google-cloud-env (1.6.0) + faraday (>= 0.17.3, < 3.0) google-cloud-errors (1.2.0) - google-cloud-storage (1.36.1) + google-cloud-location (0.2.0) + gapic-common (>= 0.10, < 2.a) + google-cloud-errors (~> 1.0) + google-cloud-storage (1.37.0) addressable (~> 2.8) digest-crc (~> 0.4) google-apis-iamcredentials_v1 (~> 0.1) @@ -250,32 +280,32 @@ GEM google-cloud-core (~> 1.6) googleauth (>= 0.16.2, < 2.a) mini_mime (~> 1.0) - google-protobuf (3.19.4) - google-protobuf (3.19.4-x86_64-darwin) - google-protobuf (3.19.4-x86_64-linux) + google-protobuf (3.21.2) + google-protobuf (3.21.2-x86_64-darwin) + google-protobuf (3.21.2-x86_64-linux) googleapis-common-protos (1.3.12) google-protobuf (~> 3.14) googleapis-common-protos-types (~> 1.2) grpc (~> 1.27) - googleapis-common-protos-types (1.3.0) + googleapis-common-protos-types (1.3.2) google-protobuf (~> 3.14) - googleauth (0.17.1) - faraday (>= 0.17.3, < 2.0) + googleauth (1.2.0) + faraday (>= 0.17.3, < 3.a) jwt (>= 1.4, < 3.0) memoist (~> 0.16) multi_json (~> 1.11) os (>= 0.9, < 2.0) - signet (~> 0.15) - groupdate (6.0.1) + signet (>= 0.16, < 2.a) + groupdate (6.1.0) activesupport (>= 5.2) - grpc (1.43.1) - google-protobuf (~> 3.18) + grpc (1.47.0) + google-protobuf (~> 3.19) googleapis-common-protos-types (~> 1.0) - grpc (1.43.1-universal-darwin) - google-protobuf (~> 3.18) + grpc (1.47.0-x86_64-darwin) + google-protobuf (~> 3.19) googleapis-common-protos-types (~> 1.0) - grpc (1.43.1-x86_64-linux) - google-protobuf (~> 3.18) + grpc (1.47.0-x86_64-linux) + google-protobuf (~> 3.19) googleapis-common-protos-types (~> 1.0) haikunator (1.1.1) hairtrigger (0.2.25) @@ -289,13 +319,13 @@ GEM html2text (0.2.1) nokogiri (~> 1.6) http-accept (1.7.0) - http-cookie (1.0.4) + http-cookie (1.0.5) domain_name (~> 0.5) httparty (0.20.0) mime-types (~> 3.0) multi_xml (>= 0.5.2) httpclient (2.8.3) - i18n (1.10.0) + i18n (1.11.0) concurrent-ruby (~> 1.0) image_processing (1.12.2) mini_magick (>= 4.9.5, < 5) @@ -304,19 +334,19 @@ GEM actionview (>= 5.0.0) activesupport (>= 5.0.0) jmespath (1.6.1) - jquery-rails (4.4.0) + jquery-rails (4.5.0) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) - json (2.6.1) + json (2.6.2) json_refs (0.1.7) hana - json_schemer (0.2.19) + json_schemer (0.2.21) ecma-re-validator (~> 0.3) hana (~> 1.3) regexp_parser (~> 2.0) uri_template (~> 0.7) - jwt (2.3.0) + jwt (2.4.1) kaminari (1.2.2) activesupport (>= 4.1.0) kaminari-actionview (= 1.2.2) @@ -329,17 +359,27 @@ GEM activerecord kaminari-core (= 1.2.2) kaminari-core (1.2.2) - koala (3.1.0) + koala (3.2.0) addressable faraday (< 2) json (>= 1.8) rexml launchy (2.5.0) addressable (~> 2.7) - letter_opener (1.7.0) - launchy (~> 2.2) - line-bot-api (1.23.0) - liquid (5.1.0) + letter_opener (1.8.1) + launchy (>= 2.2, < 3) + libddprof (0.6.0.1.0) + libddprof (0.6.0.1.0-x86_64-linux) + libddwaf (1.3.0.2.0) + ffi (~> 1.0) + libddwaf (1.3.0.2.0-arm64-darwin) + ffi (~> 1.0) + libddwaf (1.3.0.2.0-x86_64-darwin) + ffi (~> 1.0) + libddwaf (1.3.0.2.0-x86_64-linux) + ffi (~> 1.0) + line-bot-api (1.25.0) + liquid (5.3.0) listen (3.7.1) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) @@ -358,36 +398,36 @@ GEM mini_magick (4.11.0) mini_mime (1.1.2) mini_portile2 (2.8.0) - minitest (5.15.0) - mock_redis (0.30.0) + minitest (5.16.2) + mock_redis (0.32.0) ruby2_keywords momentjs-rails (2.29.1.1) railties (>= 3.1) - msgpack (1.4.5) + msgpack (1.5.3) multi_json (1.15.0) multi_xml (0.6.0) - multipart-post (2.1.1) + multipart-post (2.2.3) net-http-persistent (4.0.1) connection_pool (~> 2.2) netrc (0.11.0) - newrelic_rpm (8.7.0) + newrelic_rpm (8.9.0) nio4r (2.5.8) - nokogiri (1.13.6) + nokogiri (1.13.7) mini_portile2 (~> 2.8.0) racc (~> 1.4) - nokogiri (1.13.6-arm64-darwin) + nokogiri (1.13.7-arm64-darwin) racc (~> 1.4) - nokogiri (1.13.6-x86_64-darwin) + nokogiri (1.13.7-x86_64-darwin) racc (~> 1.4) - nokogiri (1.13.6-x86_64-linux) + nokogiri (1.13.7-x86_64-linux) racc (~> 1.4) - oauth (0.5.8) + oauth (0.5.10) orm_adapter (0.5.0) os (1.1.4) - parallel (1.21.0) - parser (3.1.1.0) + parallel (1.22.1) + parser (3.1.2.0) ast (~> 2.4.1) - pg (1.3.2) + pg (1.4.1) pg_search (2.3.6) activerecord (>= 5.2) activesupport (>= 5.2) @@ -398,46 +438,46 @@ GEM method_source (~> 1.0) pry-rails (0.3.9) pry (>= 0.10.4) - public_suffix (4.0.6) + public_suffix (4.0.7) puma (5.6.4) nio4r (~> 2.0) pundit (2.2.0) activesupport (>= 3.0.0) raabro (1.4.0) racc (1.6.0) - rack (2.2.3.1) - rack-attack (6.6.0) + rack (2.2.4) + rack-attack (6.6.1) rack (>= 1.0, < 3) rack-cors (1.1.1) rack (>= 2.0.0) rack-proxy (0.7.2) rack - rack-test (1.1.0) - rack (>= 1.0, < 3) - rack-timeout (0.6.0) - rails (6.1.5.1) - actioncable (= 6.1.5.1) - actionmailbox (= 6.1.5.1) - actionmailer (= 6.1.5.1) - actionpack (= 6.1.5.1) - actiontext (= 6.1.5.1) - actionview (= 6.1.5.1) - activejob (= 6.1.5.1) - activemodel (= 6.1.5.1) - activerecord (= 6.1.5.1) - activestorage (= 6.1.5.1) - activesupport (= 6.1.5.1) + rack-test (2.0.2) + rack (>= 1.3) + rack-timeout (0.6.3) + rails (6.1.6.1) + actioncable (= 6.1.6.1) + actionmailbox (= 6.1.6.1) + actionmailer (= 6.1.6.1) + actionpack (= 6.1.6.1) + actiontext (= 6.1.6.1) + actionview (= 6.1.6.1) + activejob (= 6.1.6.1) + activemodel (= 6.1.6.1) + activerecord (= 6.1.6.1) + activestorage (= 6.1.6.1) + activesupport (= 6.1.6.1) bundler (>= 1.15.0) - railties (= 6.1.5.1) + railties (= 6.1.6.1) sprockets-rails (>= 2.0.0) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) rails-html-sanitizer (1.4.3) loofah (~> 2.3) - railties (6.1.5.1) - actionpack (= 6.1.5.1) - activesupport (= 6.1.5.1) + railties (6.1.6.1) + actionpack (= 6.1.6.1) + activesupport (= 6.1.6.1) method_source rake (>= 12.2) thor (~> 1.0) @@ -446,11 +486,11 @@ GEM rb-fsevent (0.11.1) rb-inotify (0.10.1) ffi (~> 1.0) - redis (4.6.0) - redis-namespace (1.8.1) + redis (4.7.1) + redis-namespace (1.8.2) redis (>= 3.0.4) - regexp_parser (2.2.1) - representable (3.1.1) + regexp_parser (2.5.0) + representable (3.2.0) declarative (< 0.1.0) trailblazer-option (>= 0.1.1, < 0.2.0) uber (< 0.2.0) @@ -469,7 +509,7 @@ GEM rspec-expectations (3.11.0) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.11.0) - rspec-mocks (3.11.0) + rspec-mocks (3.11.1) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.11.0) rspec-rails (5.0.3) @@ -481,26 +521,27 @@ GEM rspec-mocks (~> 3.10) rspec-support (~> 3.10) rspec-support (3.11.0) - rubocop (1.25.1) + rubocop (1.31.2) + json (~> 2.3) parallel (~> 1.10) parser (>= 3.1.0.0) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) - rexml - rubocop-ast (>= 1.15.1, < 2.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.18.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.16.0) + rubocop-ast (1.19.1) parser (>= 3.1.1.0) - rubocop-performance (1.13.2) + rubocop-performance (1.14.2) rubocop (>= 1.7.0, < 2.0) rubocop-ast (>= 0.4.0) - rubocop-rails (2.13.2) + rubocop-rails (2.15.2) activesupport (>= 4.2.0) rack (>= 1.1) rubocop (>= 1.7.0, < 2.0) - rubocop-rspec (2.8.0) - rubocop (~> 1.19) + rubocop-rspec (2.12.1) + rubocop (~> 1.31) ruby-progressbar (1.11.0) ruby-vips (2.1.4) ffi (~> 1.12) @@ -508,7 +549,7 @@ GEM ruby2ruby (2.4.4) ruby_parser (~> 3.1) sexp_processor (~> 4.6) - ruby_parser (3.18.1) + ruby_parser (3.19.1) sexp_processor (~> 4.16) sassc (2.4.0) ffi (~> 1.9) @@ -518,37 +559,37 @@ GEM sprockets (> 3.0) sprockets-rails tilt - scout_apm (5.1.1) + scout_apm (5.2.0) parser seed_dump (3.3.1) activerecord (>= 4) activesupport (>= 4) selectize-rails (0.12.6) semantic_range (3.0.0) - sentry-rails (5.3.0) + sentry-rails (5.3.1) railties (>= 5.0) - sentry-ruby-core (~> 5.3.0) - sentry-ruby (5.3.0) + sentry-ruby-core (~> 5.3.1) + sentry-ruby (5.3.1) concurrent-ruby (~> 1.0, >= 1.0.2) - sentry-ruby-core (= 5.3.0) - sentry-ruby-core (5.3.0) + sentry-ruby-core (= 5.3.1) + sentry-ruby-core (5.3.1) concurrent-ruby - sentry-sidekiq (5.3.0) - sentry-ruby-core (~> 5.3.0) + sentry-sidekiq (5.3.1) + sentry-ruby-core (~> 5.3.1) sidekiq (>= 3.0) - sexp_processor (4.16.0) + sexp_processor (4.16.1) shoulda-matchers (5.1.0) activesupport (>= 5.2.0) - sidekiq (6.4.1) + sidekiq (6.4.2) connection_pool (>= 2.2.2) rack (~> 2.0) redis (>= 4.2.0) - sidekiq-cron (1.4.0) + sidekiq-cron (1.6.0) fugit (~> 1) sidekiq (>= 4.2.1) - signet (0.16.0) + signet (0.17.0) addressable (~> 2.8) - faraday (>= 0.17.3, < 2.0) + faraday (>= 0.17.5, < 3.a) jwt (>= 1.5, < 3.0) multi_json (~> 1.10) simplecov (0.17.1) @@ -566,7 +607,7 @@ GEM spring-watcher-listen (2.0.1) listen (>= 2.7, < 4.0) spring (>= 1.2, < 3.0) - sprockets (4.0.3) + sprockets (4.1.1) concurrent-ruby (~> 1.0) rack (> 1, < 3) sprockets-rails (3.4.2) @@ -575,31 +616,31 @@ GEM sprockets (>= 3.0.0) squasher (0.6.2) statsd-ruby (1.5.0) - telephone_number (1.4.13) + telephone_number (1.4.16) thor (1.2.1) tilt (2.0.10) time_diff (0.3.0) activesupport i18n trailblazer-option (0.1.2) - twilio-ruby (5.66.0) - faraday (>= 0.9, < 2.0) + twilio-ruby (5.68.0) + faraday (>= 0.9, < 3.0) jwt (>= 1.5, <= 2.5) nokogiri (>= 1.6, < 2.0) twitty (0.1.4) oauth tzinfo (2.0.4) concurrent-ruby (~> 1.0) - tzinfo-data (1.2021.5) + tzinfo-data (1.2022.1) tzinfo (>= 1.0.0) uber (0.1.0) uglifier (4.2.0) execjs (>= 0.3.0, < 3) unf (0.1.4) unf_ext - unf_ext (0.0.8) - unicode-display_width (2.1.0) - uniform_notifier (1.14.2) + unf_ext (0.0.8.2) + unicode-display_width (2.2.0) + uniform_notifier (1.16.0) uri_template (0.7.0) valid_email2 (4.0.3) activemodel (>= 3.2) @@ -631,7 +672,7 @@ GEM working_hours (1.4.1) activesupport (>= 3.2) tzinfo - zeitwerk (2.5.4) + zeitwerk (2.6.0) PLATFORMS arm64-darwin-20 @@ -705,7 +746,7 @@ DEPENDENCIES rack-attack rack-cors rack-timeout - rails + rails (~> 6.1) redis redis-namespace responders diff --git a/app/builders/campaigns/campaign_conversation_builder.rb b/app/builders/campaigns/campaign_conversation_builder.rb index b04c6d077..3b3f262c9 100644 --- a/app/builders/campaigns/campaign_conversation_builder.rb +++ b/app/builders/campaigns/campaign_conversation_builder.rb @@ -9,12 +9,15 @@ class Campaigns::CampaignConversationBuilder @contact_inbox.lock! # We won't send campaigns if a conversation is already present - return if @contact_inbox.reload.conversations.present? + raise 'Conversation alread present' if @contact_inbox.reload.conversations.present? @conversation = ::Conversation.create!(conversation_params) Messages::MessageBuilder.new(@campaign.sender, @conversation, message_params).perform end @conversation + rescue StandardError => e + Rails.logger.info(e.message) + nil end private diff --git a/app/controllers/platform/api/v1/users_controller.rb b/app/controllers/platform/api/v1/users_controller.rb index 4a7eafc9c..12c87deb5 100644 --- a/app/controllers/platform/api/v1/users_controller.rb +++ b/app/controllers/platform/api/v1/users_controller.rb @@ -14,7 +14,7 @@ class Platform::Api::V1::UsersController < PlatformController def login encoded_email = ERB::Util.url_encode(@resource.email) - render json: { url: "#{ENV['FRONTEND_URL']}/app/login?email=#{encoded_email}&sso_auth_token=#{@resource.generate_sso_auth_token}" } + render json: { url: "#{ENV.fetch('FRONTEND_URL', nil)}/app/login?email=#{encoded_email}&sso_auth_token=#{@resource.generate_sso_auth_token}" } end def show; end diff --git a/app/jobs/contact_ip_lookup_job.rb b/app/jobs/contact_ip_lookup_job.rb index 0403df537..cf46d4ea3 100644 --- a/app/jobs/contact_ip_lookup_job.rb +++ b/app/jobs/contact_ip_lookup_job.rb @@ -47,7 +47,7 @@ class ContactIpLookupJob < ApplicationJob def setup_vendor_db base_url = 'https://download.maxmind.com/app/geoip_download' source_file = Down.download( - "#{base_url}?edition_id=GeoLite2-City&suffix=tar.gz&license_key=#{ENV['IP_LOOKUP_API_KEY']}" + "#{base_url}?edition_id=GeoLite2-City&suffix=tar.gz&license_key=#{ENV.fetch('IP_LOOKUP_API_KEY', nil)}" ) tar_extract = Gem::Package::TarReader.new(Zlib::GzipReader.open(source_file)) tar_extract.rewind diff --git a/app/mailers/administrator_notifications/channel_notifications_mailer.rb b/app/mailers/administrator_notifications/channel_notifications_mailer.rb index e8cd450b6..e7c0318c4 100644 --- a/app/mailers/administrator_notifications/channel_notifications_mailer.rb +++ b/app/mailers/administrator_notifications/channel_notifications_mailer.rb @@ -3,7 +3,7 @@ class AdministratorNotifications::ChannelNotificationsMailer < ApplicationMailer return unless smtp_config_set_or_development? subject = 'Your Slack integration has expired' - @action_url = "#{ENV['FRONTEND_URL']}/app/accounts/#{Current.account.id}/settings/integrations/slack" + @action_url = "#{ENV.fetch('FRONTEND_URL', nil)}/app/accounts/#{Current.account.id}/settings/integrations/slack" send_mail_with_liquid(to: admin_emails, subject: subject) and return end @@ -11,7 +11,7 @@ class AdministratorNotifications::ChannelNotificationsMailer < ApplicationMailer return unless smtp_config_set_or_development? subject = 'Your Facebook page connection has expired' - @action_url = "#{ENV['FRONTEND_URL']}/app/accounts/#{Current.account.id}/settings/inboxes/#{inbox.id}" + @action_url = "#{ENV.fetch('FRONTEND_URL', nil)}/app/accounts/#{Current.account.id}/settings/inboxes/#{inbox.id}" send_mail_with_liquid(to: admin_emails, subject: subject) and return end @@ -19,7 +19,7 @@ class AdministratorNotifications::ChannelNotificationsMailer < ApplicationMailer return unless smtp_config_set_or_development? subject = 'Your email inbox has been disconnected. Please update the credentials for SMTP/IMAP' - @action_url = "#{ENV['FRONTEND_URL']}/app/accounts/#{Current.account.id}/settings/inboxes/#{inbox.id}" + @action_url = "#{ENV.fetch('FRONTEND_URL', nil)}/app/accounts/#{Current.account.id}/settings/inboxes/#{inbox.id}" send_mail_with_liquid(to: admin_emails, subject: subject) and return end diff --git a/app/models/account.rb b/app/models/account.rb index 62af85e86..5ece265bb 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -112,7 +112,7 @@ class Account < ApplicationRecord end def support_email - super || ENV['MAILER_SENDER_EMAIL'] || GlobalConfig.get('MAILER_SUPPORT_EMAIL')['MAILER_SUPPORT_EMAIL'] + super || ENV.fetch('MAILER_SENDER_EMAIL') { GlobalConfig.get('MAILER_SUPPORT_EMAIL')['MAILER_SUPPORT_EMAIL'] } end def usage_limits diff --git a/app/models/category.rb b/app/models/category.rb index beecebd71..14c455e29 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -63,7 +63,7 @@ class Category < ApplicationRecord validates :name, presence: true validate :allowed_locales validates :locale, uniqueness: { scope: %i[slug portal_id], - message: 'should be unique in the category and portal' } + message: I18n.t('errors.categories.locale.unique') } accepts_nested_attributes_for :related_categories scope :search_by_locale, ->(locale) { where(locale: locale) if locale.present? } diff --git a/app/models/channel/telegram.rb b/app/models/channel/telegram.rb index 2b9db5679..26d70c854 100644 --- a/app/models/channel/telegram.rb +++ b/app/models/channel/telegram.rb @@ -72,7 +72,7 @@ class Channel::Telegram < ApplicationRecord HTTParty.post("#{telegram_api_url}/deleteWebhook") response = HTTParty.post("#{telegram_api_url}/setWebhook", body: { - url: "#{ENV['FRONTEND_URL']}/webhooks/telegram/#{bot_token}" + url: "#{ENV.fetch('FRONTEND_URL', nil)}/webhooks/telegram/#{bot_token}" }) errors.add(:bot_token, 'error setting up the webook') unless response.success? end diff --git a/app/models/contact.rb b/app/models/contact.rb index 157878654..2cfcbc3c0 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -29,11 +29,11 @@ class Contact < ApplicationRecord validates :account_id, presence: true validates :email, allow_blank: true, uniqueness: { scope: [:account_id], case_sensitive: false }, - format: { with: Devise.email_regexp, message: 'Invalid email' } + format: { with: Devise.email_regexp, message: I18n.t('errors.contacts.email.invalid') } validates :identifier, allow_blank: true, uniqueness: { scope: [:account_id] } validates :phone_number, allow_blank: true, uniqueness: { scope: [:account_id] }, - format: { with: /\+[1-9]\d{1,14}\z/, message: 'Should be in e164 format' } + format: { with: /\+[1-9]\d{1,14}\z/, message: I18n.t('errors.contacts.phone_number.invalid') } validates :name, length: { maximum: 255 } belongs_to :account diff --git a/app/models/data_import.rb b/app/models/data_import.rb index 85386b3d1..b83cf596a 100644 --- a/app/models/data_import.rb +++ b/app/models/data_import.rb @@ -22,7 +22,7 @@ # class DataImport < ApplicationRecord belongs_to :account - validates :data_type, inclusion: { in: ['contacts'], message: '%s is an invalid data type' } + validates :data_type, inclusion: { in: ['contacts'], message: I18n.t('errors.data_import.data_type.invalid') } enum status: { pending: 0, processing: 1, completed: 2, failed: 3 } has_one_attached :import_file diff --git a/app/models/inbox.rb b/app/models/inbox.rb index d3127b3cf..4ae240d7b 100644 --- a/app/models/inbox.rb +++ b/app/models/inbox.rb @@ -115,13 +115,13 @@ class Inbox < ApplicationRecord def callback_webhook_url case channel_type when 'Channel::TwilioSms' - "#{ENV['FRONTEND_URL']}/twilio/callback" + "#{ENV.fetch('FRONTEND_URL', nil)}/twilio/callback" when 'Channel::Sms' - "#{ENV['FRONTEND_URL']}/webhooks/sms/#{channel.phone_number.delete_prefix('+')}" + "#{ENV.fetch('FRONTEND_URL', nil)}/webhooks/sms/#{channel.phone_number.delete_prefix('+')}" when 'Channel::Line' - "#{ENV['FRONTEND_URL']}/webhooks/line/#{channel.line_channel_id}" + "#{ENV.fetch('FRONTEND_URL', nil)}/webhooks/line/#{channel.line_channel_id}" when 'Channel::Whatsapp' - "#{ENV['FRONTEND_URL']}/webhooks/whatsapp/#{channel.phone_number}" + "#{ENV.fetch('FRONTEND_URL', nil)}/webhooks/whatsapp/#{channel.phone_number}" end end diff --git a/app/models/installation_config.rb b/app/models/installation_config.rb index 20ee1f5ff..03e0b246a 100644 --- a/app/models/installation_config.rb +++ b/app/models/installation_config.rb @@ -15,6 +15,10 @@ # index_installation_configs_on_name_and_created_at (name,created_at) UNIQUE # class InstallationConfig < ApplicationRecord + # https://stackoverflow.com/questions/72970170/upgrading-to-rails-6-1-6-1-causes-psychdisallowedclass-tried-to-load-unspecif + # 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 before_validation :set_lock diff --git a/app/models/integrations/app.rb b/app/models/integrations/app.rb index 7861cc5c8..b746bd92b 100644 --- a/app/models/integrations/app.rb +++ b/app/models/integrations/app.rb @@ -28,7 +28,7 @@ class Integrations::App def action case params[:id] when 'slack' - "#{params[:action]}&client_id=#{ENV['SLACK_CLIENT_ID']}&redirect_uri=#{self.class.slack_integration_url}" + "#{params[:action]}&client_id=#{ENV.fetch('SLACK_CLIENT_ID', nil)}&redirect_uri=#{self.class.slack_integration_url}" else params[:action] end @@ -57,7 +57,7 @@ class Integrations::App end def self.slack_integration_url - "#{ENV['FRONTEND_URL']}/app/accounts/#{Current.account.id}/settings/integrations/slack" + "#{ENV.fetch('FRONTEND_URL', nil)}/app/accounts/#{Current.account.id}/settings/integrations/slack" end class << self diff --git a/app/models/label.rb b/app/models/label.rb index 650ea6f8e..6f0bd9d07 100644 --- a/app/models/label.rb +++ b/app/models/label.rb @@ -21,7 +21,7 @@ class Label < ApplicationRecord belongs_to :account validates :title, - presence: { message: 'must not be blank' }, + presence: { message: I18n.t('errors.validations.presence') }, format: { with: UNICODE_CHARACTER_NUMBER_HYPHEN_UNDERSCORE }, uniqueness: { scope: :account_id } diff --git a/app/models/message.rb b/app/models/message.rb index 4e119aa6b..4b8a62e3b 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -136,7 +136,7 @@ class Message < ApplicationRecord # move this to a presenter return self[:content] if !input_csat? || inbox.web_widget? - I18n.t('conversations.survey.response', link: "#{ENV['FRONTEND_URL']}/survey/responses/#{conversation.uuid}") + I18n.t('conversations.survey.response', link: "#{ENV.fetch('FRONTEND_URL', nil)}/survey/responses/#{conversation.uuid}") end def email_notifiable_message? diff --git a/app/models/team.rb b/app/models/team.rb index 7c8a7f205..28e37f0cf 100644 --- a/app/models/team.rb +++ b/app/models/team.rb @@ -26,7 +26,7 @@ class Team < ApplicationRecord has_many :conversations, dependent: :nullify validates :name, - presence: { message: 'must not be blank' }, + presence: { message: I18n.t('errors.validations.presence') }, uniqueness: { scope: :account_id } before_validation do diff --git a/app/services/notification/push_notification_service.rb b/app/services/notification/push_notification_service.rb index a083eb48c..285ad1bc8 100644 --- a/app/services/notification/push_notification_service.rb +++ b/app/services/notification/push_notification_service.rb @@ -73,7 +73,7 @@ class Notification::PushNotificationService return unless ENV['FCM_SERVER_KEY'] return unless subscription.fcm? - fcm = FCM.new(ENV['FCM_SERVER_KEY']) + fcm = FCM.new(ENV.fetch('FCM_SERVER_KEY', nil)) response = fcm.send([subscription.subscription_attributes['push_token']], fcm_options) remove_subscription_if_error(subscription, response) end diff --git a/app/services/whatsapp/providers/whatsapp_360_dialog_service.rb b/app/services/whatsapp/providers/whatsapp_360_dialog_service.rb index 04f4e8f7f..a9ffb35a0 100644 --- a/app/services/whatsapp/providers/whatsapp_360_dialog_service.rb +++ b/app/services/whatsapp/providers/whatsapp_360_dialog_service.rb @@ -31,7 +31,7 @@ class Whatsapp::Providers::Whatsapp360DialogService < Whatsapp::Providers::BaseS "#{api_base_path}/configs/webhook", headers: { 'D360-API-KEY': whatsapp_channel.provider_config['api_key'], 'Content-Type': 'application/json' }, body: { - url: "#{ENV['FRONTEND_URL']}/webhooks/whatsapp/#{whatsapp_channel.phone_number}" + url: "#{ENV.fetch('FRONTEND_URL', nil)}/webhooks/whatsapp/#{whatsapp_channel.phone_number}" }.to_json ) response.success? diff --git a/config/application.rb b/config/application.rb index 4a114e0d7..dc4d42ca9 100644 --- a/config/application.rb +++ b/config/application.rb @@ -28,6 +28,11 @@ module Chatwoot # Custom chatwoot configurations config.x = config_for(:app).with_indifferent_access + + # https://stackoverflow.com/questions/72970170/upgrading-to-rails-6-1-6-1-causes-psychdisallowedclass-tried-to-load-unspecif + # 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. + config.active_record.yaml_column_permitted_classes = [HashWithIndifferentAccess] end def self.config diff --git a/config/initializers/datadog.rb b/config/initializers/datadog.rb index 1749552da..4072a4c3b 100644 --- a/config/initializers/datadog.rb +++ b/config/initializers/datadog.rb @@ -1,6 +1,6 @@ if ENV['DD_TRACE_AGENT_URL'] Datadog.configure do |c| - # This will activate auto-instrumentation for Rails - c.use :rails + # Instrumentation + c.tracing.instrument :rails end end diff --git a/config/initializers/geocoder.rb b/config/initializers/geocoder.rb index aa34b8030..0b4dced86 100644 --- a/config/initializers/geocoder.rb +++ b/config/initializers/geocoder.rb @@ -27,6 +27,6 @@ if ENV['IP_LOOKUP_SERVICE'].present? if ENV['IP_LOOKUP_SERVICE'] == 'geoip2' Geocoder.configure(ip_lookup: :geoip2, geoip2: { file: GeocoderConfiguration::LOOK_UP_DB }) else - Geocoder.configure(ip_lookup: ENV['IP_LOOKUP_SERVICE'].to_sym, api_key: ENV['IP_LOOKUP_API_KEY']) + Geocoder.configure(ip_lookup: ENV['IP_LOOKUP_SERVICE'].to_sym, api_key: ENV.fetch('IP_LOOKUP_API_KEY', nil)) end end diff --git a/config/initializers/mailer.rb b/config/initializers/mailer.rb index 5c317d62f..bc28e9198 100644 --- a/config/initializers/mailer.rb +++ b/config/initializers/mailer.rb @@ -18,8 +18,8 @@ Rails.application.configure do smtp_settings[:authentication] = ENV.fetch('SMTP_AUTHENTICATION', 'login').to_sym if ENV['SMTP_AUTHENTICATION'].present? smtp_settings[:domain] = ENV['SMTP_DOMAIN'] if ENV['SMTP_DOMAIN'].present? - smtp_settings[:user_name] = ENV['SMTP_USERNAME'] - smtp_settings[:password] = ENV['SMTP_PASSWORD'] + smtp_settings[:user_name] = ENV.fetch('SMTP_USERNAME', nil) + smtp_settings[:password] = ENV.fetch('SMTP_PASSWORD', nil) smtp_settings[:enable_starttls_auto] = ActiveModel::Type::Boolean.new.cast(ENV.fetch('SMTP_ENABLE_STARTTLS_AUTO', true)) smtp_settings[:openssl_verify_mode] = ENV['SMTP_OPENSSL_VERIFY_MODE'] if ENV['SMTP_OPENSSL_VERIFY_MODE'].present? smtp_settings[:ssl] = ActiveModel::Type::Boolean.new.cast(ENV.fetch('SMTP_SSL', true)) if ENV['SMTP_SSL'] diff --git a/config/locales/en.yml b/config/locales/en.yml index c8315c08c..fcad0e47b 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -36,6 +36,8 @@ en: reset_password_failure: Uh ho! We could not find any user with the specified email. errors: + validations: + presence: must not be blank webhook: invalid: Invalid events signup: @@ -43,9 +45,19 @@ en: invalid_email: You have entered an invalid email email_already_exists: "You have already signed up for an account with %{email}" failed: Signup failed + data_import: + data_type: + invalid: Invalid data type contacts: import: failed: File is blank + email: + invalid: Invalid email + phone_number: + invalid: should be in e164 format + categories: + locale: + unique: should be unique in the category and portal inboxes: imap: socket_error: Please check the network connection, IMAP address and try again. diff --git a/docker/entrypoints/helpers/pg_database_url.rb b/docker/entrypoints/helpers/pg_database_url.rb index 759ef2f9a..2aec699c9 100755 --- a/docker/entrypoints/helpers/pg_database_url.rb +++ b/docker/entrypoints/helpers/pg_database_url.rb @@ -3,7 +3,7 @@ require 'uri' # Let DATABASE_URL env take presedence over individual connection params. if !ENV['DATABASE_URL'].nil? && ENV['DATABASE_URL'] != '' - uri = URI(ENV['DATABASE_URL']) + uri = URI(ENV.fetch('DATABASE_URL', nil)) puts "export POSTGRES_HOST=#{uri.host} POSTGRES_PORT=#{uri.port} POSTGRES_USERNAME=#{uri.user}" elsif ENV['POSTGRES_PORT'].nil? || ENV['POSTGRES_PORT'] == '' puts 'export POSTGRES_PORT=5432' diff --git a/lib/chatwoot_hub.rb b/lib/chatwoot_hub.rb index 273a399d9..f909527fc 100644 --- a/lib/chatwoot_hub.rb +++ b/lib/chatwoot_hub.rb @@ -1,5 +1,5 @@ class ChatwootHub - BASE_URL = ENV['CHATWOOT_HUB_URL'] || 'https://hub.2.chatwoot.com' + BASE_URL = ENV.fetch('CHATWOOT_HUB_URL', 'https://hub.2.chatwoot.com') PING_URL = "#{BASE_URL}/ping".freeze REGISTRATION_URL = "#{BASE_URL}/instances".freeze PUSH_NOTIFICATION_URL = "#{BASE_URL}/send_push".freeze diff --git a/lib/global_config_service.rb b/lib/global_config_service.rb index 4190bf770..8de1c50c9 100644 --- a/lib/global_config_service.rb +++ b/lib/global_config_service.rb @@ -1,11 +1,11 @@ class GlobalConfigService def self.load(config_key, default_value) - config = ENV[config_key] || GlobalConfig.get(config_key)[config_key] + config = ENV.fetch(config_key) { GlobalConfig.get(config_key)[config_key] } return config if config.present? # To support migrating existing instance relying on env variables # TODO: deprecate this later down the line - config_value = ENV[config_key] || default_value + config_value = ENV.fetch(config_key) { default_value } return if config_value.blank? diff --git a/lib/integrations/slack/send_on_slack_service.rb b/lib/integrations/slack/send_on_slack_service.rb index 40fab95ea..1ded0547f 100644 --- a/lib/integrations/slack/send_on_slack_service.rb +++ b/lib/integrations/slack/send_on_slack_service.rb @@ -41,7 +41,7 @@ class Integrations::Slack::SendOnSlackService < Base::SendOnChannelService end def avatar_url(sender) - sender.try(:avatar_url) || "#{ENV['FRONTEND_URL']}/admin/avatar_square.png" + sender.try(:avatar_url) || "#{ENV.fetch('FRONTEND_URL', nil)}/admin/avatar_square.png" end def send_message diff --git a/lib/tasks/db_enhancements.rake b/lib/tasks/db_enhancements.rake index 32b7b2ce8..656d1ef0b 100644 --- a/lib/tasks/db_enhancements.rake +++ b/lib/tasks/db_enhancements.rake @@ -20,7 +20,7 @@ db_namespace = namespace :db do # handling case where database was created by the provider, with out running db:setup unless ActiveRecord::Base.connection.table_exists? 'ar_internal_metadata' db_namespace['load_config'].invoke if ActiveRecord::Base.schema_format == :ruby - ActiveRecord::Tasks::DatabaseTasks.load_schema_current(:ruby, ENV['SCHEMA']) + ActiveRecord::Tasks::DatabaseTasks.load_schema_current(:ruby, ENV.fetch('SCHEMA', nil)) db_namespace['seed'].invoke end diff --git a/lib/vapid_service.rb b/lib/vapid_service.rb index 52c8cea7e..2e8b581ea 100644 --- a/lib/vapid_service.rb +++ b/lib/vapid_service.rb @@ -14,8 +14,8 @@ class VapidService # keys don't exist in the database. so let's generate and save them keys = Webpush.generate_key # TODO: remove the logic on environment variables when we completely deprecate - public_key = ENV['VAPID_PUBLIC_KEY'] || keys.public_key - private_key = ENV['VAPID_PRIVATE_KEY'] || keys.private_key + public_key = ENV.fetch('VAPID_PUBLIC_KEY') { keys.public_key } + private_key = ENV.fetch('VAPID_PRIVATE_KEY') { keys.private_key } i = InstallationConfig.where(name: 'VAPID_KEYS').first_or_create(value: { public_key: public_key, private_key: private_key }) i.value diff --git a/spec/actions/contact_identify_action_spec.rb b/spec/actions/contact_identify_action_spec.rb index d64731c3e..db1c84e6c 100644 --- a/spec/actions/contact_identify_action_spec.rb +++ b/spec/actions/contact_identify_action_spec.rb @@ -62,7 +62,7 @@ describe ::ContactIdentifyAction do result = described_class.new(contact: contact, params: params).perform expect(result.id).not_to eq existing_email_contact.id expect(result.identifier).to eq params[:identifier] - expect(result.email).to eq nil + expect(result.email).to be_nil end end @@ -82,7 +82,7 @@ describe ::ContactIdentifyAction do result = described_class.new(contact: contact, params: params).perform expect(result.id).not_to eq existing_phone_number_contact.id expect(result.identifier).to eq params[:identifier] - expect(result.email).to eq nil + expect(result.email).to be_nil end it 'will not overide the phone contacts email when params contains different email' do @@ -91,7 +91,7 @@ describe ::ContactIdentifyAction do result = described_class.new(contact: contact, params: params).perform expect(result.id).not_to eq existing_phone_number_contact.id expect(result.email).to eq params[:email] - expect(result.phone_number).to eq nil + expect(result.phone_number).to be_nil end end @@ -130,7 +130,7 @@ describe ::ContactIdentifyAction do params = { phone_number: 'blahblah blah', name: 'new name' } described_class.new(contact: contact, params: params, discard_invalid_attrs: true).perform expect(contact.reload.name).to eq 'new name' - expect(contact.phone_number).to eq nil + expect(contact.phone_number).to be_nil end end end diff --git a/spec/actions/contact_merge_action_spec.rb b/spec/actions/contact_merge_action_spec.rb index a00f908fa..147dabe41 100644 --- a/spec/actions/contact_merge_action_spec.rb +++ b/spec/actions/contact_merge_action_spec.rb @@ -43,7 +43,7 @@ describe ::ContactMergeAction do it 'does not delete contact' do mergee_contact = base_contact contact_merge - expect(mergee_contact.reload).not_to eq nil + expect(mergee_contact.reload).not_to be_nil end end diff --git a/spec/builders/campaigns/campaign_conversation_builder_spec.rb b/spec/builders/campaigns/campaign_conversation_builder_spec.rb index c461337cd..03a392912 100644 --- a/spec/builders/campaigns/campaign_conversation_builder_spec.rb +++ b/spec/builders/campaigns/campaign_conversation_builder_spec.rb @@ -26,7 +26,7 @@ describe ::Campaigns::CampaignConversationBuilder do campaign_display_id: campaign.display_id ).perform - expect(campaign_conversation).to eq(nil) + expect(campaign_conversation).to be_nil end end end diff --git a/spec/builders/contact_inbox_builder_spec.rb b/spec/builders/contact_inbox_builder_spec.rb index 80658b5ac..2de5b6b60 100644 --- a/spec/builders/contact_inbox_builder_spec.rb +++ b/spec/builders/contact_inbox_builder_spec.rb @@ -226,7 +226,7 @@ describe ::ContactInboxBuilder do inbox_id: api_inbox.id ).perform - expect(contact_inbox.source_id).not_to be(nil) + expect(contact_inbox.source_id).not_to be_nil end end @@ -241,7 +241,7 @@ describe ::ContactInboxBuilder do source_id: 'test' ).perform - expect(contact_inbox).to be(nil) + expect(contact_inbox).to be_nil end end @@ -260,7 +260,7 @@ describe ::ContactInboxBuilder do source_id: 'test' ).perform - expect(contact_inbox).to be(nil) + expect(contact_inbox).to be_nil end end @@ -275,7 +275,7 @@ describe ::ContactInboxBuilder do source_id: 'test' ).perform - expect(contact_inbox).to be(nil) + expect(contact_inbox).to be_nil end end end diff --git a/spec/builders/csat_surveys/response_builder_spec.rb b/spec/builders/csat_surveys/response_builder_spec.rb index 5400e9bfd..9356e6369 100644 --- a/spec/builders/csat_surveys/response_builder_spec.rb +++ b/spec/builders/csat_surveys/response_builder_spec.rb @@ -14,7 +14,7 @@ describe ::CsatSurveys::ResponseBuilder do message: message ).perform - expect(csat_survey_response.valid?).to eq(true) + expect(csat_survey_response.valid?).to be(true) end it 'updates the value of csat survey response if response already exists' do diff --git a/spec/controllers/api/v1/accounts/agent_bots_controller_spec.rb b/spec/controllers/api/v1/accounts/agent_bots_controller_spec.rb index ab3b578fc..70fcf9f42 100644 --- a/spec/controllers/api/v1/accounts/agent_bots_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/agent_bots_controller_spec.rb @@ -69,7 +69,7 @@ RSpec.describe 'Agent Bot API', type: :request do context 'when it is an unauthenticated user' do it 'returns unauthorized' do - expect { post "/api/v1/accounts/#{account.id}/agent_bots", params: valid_params }.to change(Label, :count).by(0) + expect { post "/api/v1/accounts/#{account.id}/agent_bots", params: valid_params }.not_to change(Label, :count) expect(response).to have_http_status(:unauthorized) end @@ -89,7 +89,7 @@ RSpec.describe 'Agent Bot API', type: :request do expect do post "/api/v1/accounts/#{account.id}/agent_bots", headers: agent.create_new_auth_token, params: valid_params - end.to change(AgentBot, :count).by(0) + end.not_to change(AgentBot, :count) expect(response).to have_http_status(:unauthorized) end diff --git a/spec/controllers/api/v1/accounts/agents_controller_spec.rb b/spec/controllers/api/v1/accounts/agents_controller_spec.rb index 4d8aa4d65..ffbae10c9 100644 --- a/spec/controllers/api/v1/accounts/agents_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/agents_controller_spec.rb @@ -114,7 +114,7 @@ RSpec.describe 'Agents API', type: :request do response_data = JSON.parse(response.body) expect(response_data['role']).to eq('administrator') expect(response_data['availability_status']).to eq('busy') - expect(response_data['auto_offline']).to eq(false) + expect(response_data['auto_offline']).to be(false) expect(other_agent.account_users.first.role).to eq('administrator') end end diff --git a/spec/controllers/api/v1/accounts/articles_controller_spec.rb b/spec/controllers/api/v1/accounts/articles_controller_spec.rb index 976cebc0d..ce4aab778 100644 --- a/spec/controllers/api/v1/accounts/articles_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/articles_controller_spec.rb @@ -137,7 +137,7 @@ RSpec.describe 'Api::V1::Accounts::Articles', type: :request do headers: agent.create_new_auth_token expect(response).to have_http_status(:success) deleted_article = Article.find_by(id: article.id) - expect(deleted_article).to be nil + expect(deleted_article).to be_nil end end end @@ -153,7 +153,7 @@ RSpec.describe 'Api::V1::Accounts::Articles', type: :request do context 'when it is an authenticated user' do it 'get all articles' do article2 = create(:article, account_id: account.id, portal: portal, category: category, author_id: agent.id) - expect(article2.id).not_to be nil + expect(article2.id).not_to be_nil get "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/articles", headers: agent.create_new_auth_token, @@ -165,7 +165,7 @@ RSpec.describe 'Api::V1::Accounts::Articles', type: :request do it 'get all articles with searched params' do article2 = create(:article, account_id: account.id, portal: portal, category: category, author_id: agent.id) - expect(article2.id).not_to be nil + expect(article2.id).not_to be_nil get "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/articles", headers: agent.create_new_auth_token, @@ -182,7 +182,7 @@ RSpec.describe 'Api::V1::Accounts::Articles', type: :request do category: category, author_id: agent.id, content: 'this is some test and funny content') - expect(article2.id).not_to be nil + expect(article2.id).not_to be_nil get "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/articles", headers: agent.create_new_auth_token, @@ -196,7 +196,7 @@ RSpec.describe 'Api::V1::Accounts::Articles', type: :request do describe 'GET /api/v1/accounts/{account.id}/portals/{portal.slug}/articles/{article.id}' do it 'get article' do article2 = create(:article, account_id: account.id, portal: portal, category: category, author_id: agent.id) - expect(article2.id).not_to be nil + expect(article2.id).not_to be_nil get "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/articles/#{article2.id}", headers: agent.create_new_auth_token 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 7701e044c..d905bf771 100644 --- a/spec/controllers/api/v1/accounts/automation_rules_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/automation_rules_controller_spec.rb @@ -307,7 +307,7 @@ RSpec.describe 'Api::V1::Accounts::AutomationRulesController', type: :request do end it 'returns for updated active flag for automation_rule' do - expect(automation_rule.active).to eq(true) + expect(automation_rule.active).to be(true) params = { active: false } patch "/api/v1/accounts/#{account.id}/automation_rules/#{automation_rule.id}", @@ -316,8 +316,8 @@ RSpec.describe 'Api::V1::Accounts::AutomationRulesController', type: :request do expect(response).to have_http_status(:success) body = JSON.parse(response.body, symbolize_names: true) - expect(body[:payload][:active]).to eq(false) - expect(automation_rule.reload.active).to eq(false) + expect(body[:payload][:active]).to be(false) + expect(automation_rule.reload.active).to be(false) end end end diff --git a/spec/controllers/api/v1/accounts/bulk_actions_controller_spec.rb b/spec/controllers/api/v1/accounts/bulk_actions_controller_spec.rb index 27376b84f..cbc6661aa 100644 --- a/spec/controllers/api/v1/accounts/bulk_actions_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/bulk_actions_controller_spec.rb @@ -40,7 +40,7 @@ RSpec.describe 'Api::V1::Accounts::BulkActionsController', type: :request do it 'Bulk update conversation status' do expect(Conversation.first.status).to eq('open') expect(Conversation.last.status).to eq('open') - expect(Conversation.first.assignee_id).to eq(nil) + expect(Conversation.first.assignee_id).to be_nil perform_enqueued_jobs do post "/api/v1/accounts/#{account.id}/bulk_actions", @@ -52,15 +52,15 @@ RSpec.describe 'Api::V1::Accounts::BulkActionsController', type: :request do expect(Conversation.first.status).to eq('snoozed') expect(Conversation.last.status).to eq('open') - expect(Conversation.first.assignee_id).to eq(nil) + expect(Conversation.first.assignee_id).to be_nil end it 'Bulk update conversation assignee id' do params = { type: 'Conversation', fields: { assignee_id: agent_1.id }, ids: Conversation.first(3).pluck(:display_id) } expect(Conversation.first.status).to eq('open') - expect(Conversation.first.assignee_id).to eq(nil) - expect(Conversation.second.assignee_id).to eq(nil) + expect(Conversation.first.assignee_id).to be_nil + expect(Conversation.second.assignee_id).to be_nil perform_enqueued_jobs do post "/api/v1/accounts/#{account.id}/bulk_actions", @@ -79,7 +79,7 @@ RSpec.describe 'Api::V1::Accounts::BulkActionsController', type: :request do params = { type: 'Conversation', fields: { assignee_id: agent_1.id, status: 'snoozed' }, ids: Conversation.first(3).pluck(:display_id) } expect(Conversation.first.status).to eq('open') - expect(Conversation.second.assignee_id).to eq(nil) + expect(Conversation.second.assignee_id).to be_nil perform_enqueued_jobs do post "/api/v1/accounts/#{account.id}/bulk_actions", diff --git a/spec/controllers/api/v1/accounts/campaigns_controller_spec.rb b/spec/controllers/api/v1/accounts/campaigns_controller_spec.rb index 219e8f0b9..ddf93c3f9 100644 --- a/spec/controllers/api/v1/accounts/campaigns_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/campaigns_controller_spec.rb @@ -145,7 +145,7 @@ RSpec.describe 'Campaigns API', type: :request do expect(response).to have_http_status(:success) response_data = JSON.parse(response.body, symbolize_names: true) expect(response_data[:campaign_type]).to eq('one_off') - expect(response_data[:scheduled_at].present?).to eq true + expect(response_data[:scheduled_at].present?).to be true expect(response_data[:scheduled_at]).to eq(scheduled_at.to_i) expect(response_data[:audience].pluck(:id)).to include(label1.id, label2.id) end @@ -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 eq false + expect(::Campaign.exists?(campaign.display_id)).to be false end end end diff --git a/spec/controllers/api/v1/accounts/categories_controller_spec.rb b/spec/controllers/api/v1/accounts/categories_controller_spec.rb index 05b980674..03898a3a7 100644 --- a/spec/controllers/api/v1/accounts/categories_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/categories_controller_spec.rb @@ -228,7 +228,7 @@ RSpec.describe 'Api::V1::Accounts::Categories', type: :request do headers: agent.create_new_auth_token expect(response).to have_http_status(:success) deleted_category = Category.find_by(id: category.id) - expect(deleted_category).to be nil + expect(deleted_category).to be_nil end end end @@ -247,7 +247,7 @@ RSpec.describe 'Api::V1::Accounts::Categories', type: :request do category2 = create(:category, name: 'test_category_2', portal: portal, locale: 'es', slug: 'category_slug_2') - expect(category2.id).not_to be nil + expect(category2.id).not_to be_nil get "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/categories", headers: agent.create_new_auth_token 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 68b23de33..b8e41b9d1 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 @@ -5,7 +5,7 @@ RSpec.describe '/api/v1/accounts/{account.id}/channels/twilio_channel', type: :r 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(:message_double) { instance_double('message') } + let(:message_double) { double } let(:twilio_webhook_setup_service) { instance_double(::Twilio::WebhookSetupService) } before do diff --git a/spec/controllers/api/v1/accounts/contacts/contact_inboxes_controller_spec.rb b/spec/controllers/api/v1/accounts/contacts/contact_inboxes_controller_spec.rb index 80de09c40..1414c00e7 100644 --- a/spec/controllers/api/v1/accounts/contacts/contact_inboxes_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/contacts/contact_inboxes_controller_spec.rb @@ -36,7 +36,7 @@ RSpec.describe '/api/v1/accounts/{account.id}/contacts/:id/contact_inboxes', typ params: { inbox_id: channel_twilio_sms.inbox.id }, headers: agent.create_new_auth_token, as: :json - end.to change(ContactInbox, :count).by(0) + end.not_to change(ContactInbox, :count) expect(response).to have_http_status(:unprocessable_entity) 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 a40184508..9bd26618d 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 eq 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 800d36e14..0c9b77443 100644 --- a/spec/controllers/api/v1/accounts/contacts_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/contacts_controller_spec.rb @@ -49,7 +49,7 @@ RSpec.describe 'Contacts API', type: :request do expect(response).to have_http_status(:success) response_body = JSON.parse(response.body) expect(response_body['payload'].first['email']).to eq(contact.email) - expect(response_body['payload'].first['contact_inboxes'].blank?).to eq(true) + expect(response_body['payload'].first['contact_inboxes'].blank?).to be(true) end it 'returns all contacts with company name desc order' do @@ -149,7 +149,7 @@ RSpec.describe 'Contacts API', type: :request do expect(response).to have_http_status(:success) expect(account.data_imports.count).to eq(1) - expect(account.data_imports.first.import_file.attached?).to eq(true) + expect(account.data_imports.first.import_file.attached?).to be(true) end end @@ -364,7 +364,7 @@ RSpec.describe 'Contacts API', type: :request do context 'when it is an unauthenticated user' do it 'returns unauthorized' do - expect { post "/api/v1/accounts/#{account.id}/contacts", params: valid_params }.to change(Contact, :count).by(0) + expect { post "/api/v1/accounts/#{account.id}/contacts", params: valid_params }.not_to change(Contact, :count) expect(response).to have_http_status(:unauthorized) end @@ -477,7 +477,7 @@ RSpec.describe 'Contacts API', type: :request do it 'updates avatar' do # no avatar before upload - expect(contact.avatar.attached?).to eq(false) + expect(contact.avatar.attached?).to be(false) file = fixture_file_upload(Rails.root.join('spec/assets/avatar.png'), 'image/png') patch "/api/v1/accounts/#{account.id}/contacts/#{contact.id}", params: valid_params.merge(avatar: file), @@ -485,7 +485,7 @@ RSpec.describe 'Contacts API', type: :request do expect(response).to have_http_status(:success) contact.reload - expect(contact.avatar.attached?).to eq(true) + expect(contact.avatar.attached?).to be(true) end end end diff --git a/spec/controllers/api/v1/accounts/conversations/assignments_controller_spec.rb b/spec/controllers/api/v1/accounts/conversations/assignments_controller_spec.rb index 6583eaf0e..368849b5f 100644 --- a/spec/controllers/api/v1/accounts/conversations/assignments_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/conversations/assignments_controller_spec.rb @@ -68,7 +68,7 @@ RSpec.describe 'Conversation Assignment API', type: :request do as: :json expect(response).to have_http_status(:success) - expect(conversation.reload.assignee).to eq(nil) + expect(conversation.reload.assignee).to be_nil expect(Conversations::ActivityMessageJob) .to(have_been_enqueued.at_least(:once) .with(conversation, { account_id: conversation.account_id, inbox_id: conversation.inbox_id, message_type: :activity, @@ -93,7 +93,7 @@ RSpec.describe 'Conversation Assignment API', type: :request do as: :json expect(response).to have_http_status(:success) - expect(conversation.reload.team).to eq(nil) + expect(conversation.reload.team).to be_nil end 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 d97645416..e518ab185 100644 --- a/spec/controllers/api/v1/accounts/conversations/messages_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/conversations/messages_controller_spec.rb @@ -77,7 +77,7 @@ RSpec.describe 'Conversation Messages API', type: :request do headers: agent.create_new_auth_token expect(response).to have_http_status(:success) - expect(conversation.messages.last.attachments.first.file.present?).to eq(true) + expect(conversation.messages.last.attachments.first.file.present?).to be(true) expect(conversation.messages.last.attachments.first.file_type).to eq('image') end end @@ -113,7 +113,7 @@ RSpec.describe 'Conversation Messages API', type: :request do expect(response).to have_http_status(:success) expect(conversation.messages.count).to eq(1) expect(conversation.messages.first.content_type).to eq(params[:content_type]) - expect(conversation.messages.first.content).to eq nil + expect(conversation.messages.first.content).to be_nil end it 'creates a new outgoing cards message' do @@ -187,8 +187,8 @@ RSpec.describe 'Conversation Messages API', type: :request do expect(response).to have_http_status(:success) expect(message.reload.content).to eq 'This message was deleted' - expect(message.reload.deleted).to eq true - expect(message.reload.content_attributes['bcc_emails']).to eq nil + expect(message.reload.deleted).to be true + expect(message.reload.content_attributes['bcc_emails']).to be_nil end end diff --git a/spec/controllers/api/v1/accounts/conversations_controller_spec.rb b/spec/controllers/api/v1/accounts/conversations_controller_spec.rb index 102e12477..f63e33d0f 100644 --- a/spec/controllers/api/v1/accounts/conversations_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/conversations_controller_spec.rb @@ -490,20 +490,20 @@ RSpec.describe 'Conversations API', type: :request do as: :json expect(response).to have_http_status(:success) - expect(conversation.reload.agent_last_seen_at).not_to eq nil + expect(conversation.reload.agent_last_seen_at).not_to be_nil end it 'updates assignee last seen' do conversation.update!(assignee_id: agent.id) - expect(conversation.reload.assignee_last_seen_at).to eq nil + expect(conversation.reload.assignee_last_seen_at).to be_nil post "/api/v1/accounts/#{account.id}/conversations/#{conversation.display_id}/update_last_seen", headers: agent.create_new_auth_token, as: :json expect(response).to have_http_status(:success) - expect(conversation.reload.assignee_last_seen_at).not_to eq nil + expect(conversation.reload.assignee_last_seen_at).not_to be_nil end end end @@ -532,8 +532,8 @@ RSpec.describe 'Conversations API', type: :request do as: :json expect(response).to have_http_status(:success) - expect(conversation.reload.resolved?).to eq(true) - expect(conversation.reload.muted?).to eq(true) + expect(conversation.reload.resolved?).to be(true) + expect(conversation.reload.muted?).to be(true) end end end @@ -562,7 +562,7 @@ RSpec.describe 'Conversations API', type: :request do as: :json expect(response).to have_http_status(:success) - expect(conversation.reload.muted?).to eq(false) + expect(conversation.reload.muted?).to be(false) end end end @@ -636,7 +636,7 @@ RSpec.describe 'Conversations API', type: :request do as: :json expect(response).to have_http_status(:success) - expect(conversation.reload.custom_attributes).not_to eq nil + expect(conversation.reload.custom_attributes).not_to be_nil expect(conversation.reload.custom_attributes.count).to eq 3 end end 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 8dc7a7e3d..f266aa617 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 @@ -72,7 +72,7 @@ RSpec.describe 'Custom Attribute Definitions API', type: :request do expect do post "/api/v1/accounts/#{account.id}/custom_attribute_definitions", params: payload - end.to change(CustomAttributeDefinition, :count).by(0) + end.not_to change(CustomAttributeDefinition, :count) expect(response).to have_http_status(:unauthorized) 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 76798898f..c9a79bdd0 100644 --- a/spec/controllers/api/v1/accounts/custom_filters_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/custom_filters_controller_spec.rb @@ -58,7 +58,7 @@ RSpec.describe 'Custom Filters API', type: :request do context 'when it is an unauthenticated user' do it 'returns unauthorized' do - expect { post "/api/v1/accounts/#{account.id}/custom_filters", params: payload }.to change(CustomFilter, :count).by(0) + expect { post "/api/v1/accounts/#{account.id}/custom_filters", params: payload }.not_to change(CustomFilter, :count) expect(response).to have_http_status(:unauthorized) 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 9a6b0fa67..a557ad788 100644 --- a/spec/controllers/api/v1/accounts/dashboard_apps_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/dashboard_apps_controller_spec.rb @@ -60,7 +60,7 @@ RSpec.describe 'DashboardAppsController', type: :request do context 'when it is an unauthenticated user' do it 'returns unauthorized' do - expect { post "/api/v1/accounts/#{account.id}/dashboard_apps", params: payload }.to change(CustomFilter, :count).by(0) + expect { post "/api/v1/accounts/#{account.id}/dashboard_apps", params: payload }.not_to change(CustomFilter, :count) expect(response).to have_http_status(:unauthorized) end @@ -86,7 +86,7 @@ RSpec.describe 'DashboardAppsController', type: :request do expect do post "/api/v1/accounts/#{account.id}/dashboard_apps", headers: user.create_new_auth_token, params: invalid_url_payload - end.to change(DashboardApp, :count).by(0) + end.not_to change(DashboardApp, :count) expect(response).to have_http_status(:unprocessable_entity) json_response = JSON.parse(response.body) @@ -97,7 +97,7 @@ RSpec.describe 'DashboardAppsController', type: :request do expect do post "/api/v1/accounts/#{account.id}/dashboard_apps", headers: user.create_new_auth_token, params: invalid_type_payload - end.to change(DashboardApp, :count).by(0) + end.not_to change(DashboardApp, :count) expect(response).to have_http_status(:unprocessable_entity) end diff --git a/spec/controllers/api/v1/accounts/inboxes_controller_spec.rb b/spec/controllers/api/v1/accounts/inboxes_controller_spec.rb index 3867aa1fc..83a84952c 100644 --- a/spec/controllers/api/v1/accounts/inboxes_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/inboxes_controller_spec.rb @@ -414,7 +414,7 @@ RSpec.describe 'Inboxes API', type: :request do as: :json expect(response).to have_http_status(:success) - expect(api_channel.reload.tweets_enabled).to eq(false) + expect(api_channel.reload.tweets_enabled).to be(false) end it 'updates email inbox when administrator' do @@ -458,7 +458,7 @@ RSpec.describe 'Inboxes API', type: :request do it 'updates avatar when administrator' do # no avatar before upload - expect(inbox.avatar.attached?).to eq(false) + expect(inbox.avatar.attached?).to be(false) file = fixture_file_upload(Rails.root.join('spec/assets/avatar.png'), 'image/png') patch "/api/v1/accounts/#{account.id}/inboxes/#{inbox.id}", params: valid_params.merge(avatar: file), @@ -466,7 +466,7 @@ RSpec.describe 'Inboxes API', type: :request do expect(response).to have_http_status(:success) inbox.reload - expect(inbox.avatar.attached?).to eq(true) + expect(inbox.avatar.attached?).to be(true) end it 'updates working hours when administrator' do @@ -613,7 +613,7 @@ RSpec.describe 'Inboxes API', type: :request do expect(response).to have_http_status(:success) inbox_data = JSON.parse(response.body, symbolize_names: true) - expect(inbox_data[:agent_bot].blank?).to eq(true) + expect(inbox_data[:agent_bot].blank?).to be(true) end it 'returns the agent bot attached to the inbox' do 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 63c31d98a..bb87d8837 100644 --- a/spec/controllers/api/v1/accounts/integrations/hooks_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/integrations/hooks_controller_spec.rb @@ -104,7 +104,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 eq false + expect(::Integrations::Hook.exists?(hook.id)).to be false end end end diff --git a/spec/controllers/api/v1/accounts/labels_controller_spec.rb b/spec/controllers/api/v1/accounts/labels_controller_spec.rb index 083d1ec86..61751ad68 100644 --- a/spec/controllers/api/v1/accounts/labels_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/labels_controller_spec.rb @@ -55,7 +55,7 @@ RSpec.describe 'Label API', type: :request do context 'when it is an unauthenticated user' do it 'returns unauthorized' do - expect { post "/api/v1/accounts/#{account.id}/labels", params: valid_params }.to change(Label, :count).by(0) + expect { post "/api/v1/accounts/#{account.id}/labels", params: valid_params }.not_to change(Label, :count) expect(response).to have_http_status(:unauthorized) end diff --git a/spec/controllers/api/v1/accounts/notifications_controller_spec.rb b/spec/controllers/api/v1/accounts/notifications_controller_spec.rb index 3d824b841..4429e39e7 100644 --- a/spec/controllers/api/v1/accounts/notifications_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/notifications_controller_spec.rb @@ -70,7 +70,7 @@ RSpec.describe 'Notifications API', type: :request do expect(response).to have_http_status(:success) expect(notification1.reload.read_at).not_to eq('') - expect(notification2.reload.read_at).to eq nil + expect(notification2.reload.read_at).to be_nil end end end diff --git a/spec/controllers/api/v1/accounts/portals_controller_spec.rb b/spec/controllers/api/v1/accounts/portals_controller_spec.rb index bdca10a68..e756edb30 100644 --- a/spec/controllers/api/v1/accounts/portals_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/portals_controller_spec.rb @@ -21,7 +21,7 @@ RSpec.describe 'Api::V1::Accounts::Portals', type: :request do context 'when it is an authenticated user' do it 'get all portals' do portal2 = create(:portal, name: 'test_portal_2', account_id: account.id, slug: 'portal-2') - expect(portal2.id).not_to be nil + expect(portal2.id).not_to be_nil get "/api/v1/accounts/#{account.id}/portals", headers: agent.create_new_auth_token @@ -155,7 +155,7 @@ RSpec.describe 'Api::V1::Accounts::Portals', type: :request do headers: admin.create_new_auth_token expect(response).to have_http_status(:success) deleted_portal = Portal.find_by(id: portal.slug) - expect(deleted_portal).to be nil + expect(deleted_portal).to be_nil end end end diff --git a/spec/controllers/api/v1/accounts_controller_spec.rb b/spec/controllers/api/v1/accounts_controller_spec.rb index a82bd515d..d7e66fa56 100644 --- a/spec/controllers/api/v1/accounts_controller_spec.rb +++ b/spec/controllers/api/v1/accounts_controller_spec.rb @@ -206,14 +206,14 @@ RSpec.describe 'Accounts API', type: :request do context 'when it is an authenticated user' do it 'modifies an account' do - expect(agent.account_users.first.active_at).to eq(nil) + expect(agent.account_users.first.active_at).to be_nil post "/api/v1/accounts/#{account.id}/update_active_at", params: {}, headers: agent.create_new_auth_token, as: :json expect(response).to have_http_status(:success) - expect(agent.account_users.first.active_at).not_to eq(nil) + expect(agent.account_users.first.active_at).not_to be_nil end end end diff --git a/spec/controllers/api/v1/profiles_controller_spec.rb b/spec/controllers/api/v1/profiles_controller_spec.rb index 4f6cfaeb0..0e386752f 100644 --- a/spec/controllers/api/v1/profiles_controller_spec.rb +++ b/spec/controllers/api/v1/profiles_controller_spec.rb @@ -79,7 +79,7 @@ RSpec.describe 'Profile API', type: :request do as: :json expect(response).to have_http_status(:success) - expect(agent.reload.valid_password?('Test1234!')).to eq true + expect(agent.reload.valid_password?('Test1234!')).to be true end it 'throws error when current password provided is invalid' do @@ -105,7 +105,7 @@ RSpec.describe 'Profile API', type: :request do it 'updates avatar' do # no avatar before upload - expect(agent.avatar.attached?).to eq(false) + expect(agent.avatar.attached?).to be(false) file = fixture_file_upload(Rails.root.join('spec/assets/avatar.png'), 'image/png') put '/api/v1/profile', params: { profile: { avatar: file } }, @@ -113,7 +113,7 @@ RSpec.describe 'Profile API', type: :request do expect(response).to have_http_status(:success) agent.reload - expect(agent.avatar.attached?).to eq(true) + expect(agent.avatar.attached?).to be(true) end it 'updates the ui settings' do @@ -124,7 +124,7 @@ RSpec.describe 'Profile API', type: :request do expect(response).to have_http_status(:success) json_response = JSON.parse(response.body) - expect(json_response['ui_settings']['is_contact_sidebar_open']).to eq(false) + expect(json_response['ui_settings']['is_contact_sidebar_open']).to be(false) end end diff --git a/spec/controllers/api/v1/widget/configs_controller_spec.rb b/spec/controllers/api/v1/widget/configs_controller_spec.rb index 773e83102..8101885bd 100644 --- a/spec/controllers/api/v1/widget/configs_controller_spec.rb +++ b/spec/controllers/api/v1/widget/configs_controller_spec.rb @@ -40,7 +40,7 @@ RSpec.describe '/api/v1/widget/config', type: :request do params: params, headers: { 'X-Auth-Token' => token }, as: :json - end.to change(Contact, :count).by(0) + end.not_to change(Contact, :count) expect(response).to have_http_status(:success) response_data = JSON.parse(response.body) diff --git a/spec/controllers/api/v1/widget/contacts_controller_spec.rb b/spec/controllers/api/v1/widget/contacts_controller_spec.rb index 0b69c0859..bdac8fb24 100644 --- a/spec/controllers/api/v1/widget/contacts_controller_spec.rb +++ b/spec/controllers/api/v1/widget/contacts_controller_spec.rb @@ -103,8 +103,8 @@ RSpec.describe '/api/v1/widget/contacts', type: :request do body = JSON.parse(response.body) expect(body['id']).not_to eq(contact.id) - expect(body['widget_auth_token']).not_to eq(nil) - expect(Contact.find(body['id']).contact_inboxes.first.hmac_verified?).to eq(true) + expect(body['widget_auth_token']).not_to be_nil + expect(Contact.find(body['id']).contact_inboxes.first.hmac_verified?).to be(true) end end diff --git a/spec/controllers/api/v1/widget/conversations_controller_spec.rb b/spec/controllers/api/v1/widget/conversations_controller_spec.rb index 307862374..6f6f30e8e 100644 --- a/spec/controllers/api/v1/widget/conversations_controller_spec.rb +++ b/spec/controllers/api/v1/widget/conversations_controller_spec.rb @@ -66,7 +66,7 @@ RSpec.describe '/api/v1/widget/conversations/toggle_typing', type: :request do expect(response).to have_http_status(:success) json_response = JSON.parse(response.body) - expect(json_response['id']).not_to eq nil + 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' expect(json_response['contact']['name']).to eq 'contact-name' @@ -95,7 +95,7 @@ RSpec.describe '/api/v1/widget/conversations/toggle_typing', type: :request do expect(response).to have_http_status(:success) json_response = JSON.parse(response.body) - expect(json_response['id']).not_to eq nil + 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' expect(json_response['contact']['phone_number']).to eq '+919745313456' @@ -124,7 +124,7 @@ RSpec.describe '/api/v1/widget/conversations/toggle_typing', type: :request do context 'with a conversation' do it 'returns the correct conversation params' do allow(Rails.configuration.dispatcher).to receive(:dispatch) - expect(conversation.contact_last_seen_at).to eq(nil) + expect(conversation.contact_last_seen_at).to be_nil post '/api/v1/widget/conversations/update_last_seen', headers: { 'X-Auth-Token' => token }, @@ -133,7 +133,7 @@ RSpec.describe '/api/v1/widget/conversations/toggle_typing', type: :request do expect(response).to have_http_status(:success) - expect(conversation.reload.contact_last_seen_at).not_to eq(nil) + expect(conversation.reload.contact_last_seen_at).not_to be_nil end end end diff --git a/spec/controllers/api/v1/widget/messages_controller_spec.rb b/spec/controllers/api/v1/widget/messages_controller_spec.rb index fe6dd19e4..56485f9fc 100644 --- a/spec/controllers/api/v1/widget/messages_controller_spec.rb +++ b/spec/controllers/api/v1/widget/messages_controller_spec.rb @@ -82,7 +82,7 @@ RSpec.describe '/api/v1/widget/messages', type: :request do json_response = JSON.parse(response.body) expect(json_response['content']).to eq(message_params[:content]) - expect(conversation.messages.last.attachments.first.file.present?).to eq(true) + expect(conversation.messages.last.attachments.first.file.present?).to be(true) expect(conversation.messages.last.attachments.first.file_type).to eq('image') end @@ -96,7 +96,7 @@ RSpec.describe '/api/v1/widget/messages', type: :request do as: :json expect(response).to have_http_status(:success) - expect(conversation.reload.resolved?).to eq(true) + expect(conversation.reload.resolved?).to be(true) end it 'does not create resolved activity messages when snoozed conversation is opened' do @@ -118,7 +118,7 @@ RSpec.describe '/api/v1/widget/messages', type: :request do } ) expect(response).to have_http_status(:success) - expect(conversation.reload.open?).to eq(true) + expect(conversation.reload.open?).to be(true) end end end diff --git a/spec/controllers/devise/confirmations_controller_spec.rb b/spec/controllers/devise/confirmations_controller_spec.rb index d01ecb196..7c322fe16 100644 --- a/spec/controllers/devise/confirmations_controller_spec.rb +++ b/spec/controllers/devise/confirmations_controller_spec.rb @@ -15,7 +15,7 @@ RSpec.describe 'Token Confirmation', type: :request do let(:confirmation_token) { '12345' } it 'has status 200' do - expect(response.status).to eq 200 + expect(response).to have_http_status :ok end it 'returns "auth data"' do @@ -28,7 +28,7 @@ RSpec.describe 'Token Confirmation', type: :request do let(:confirmation_token) { '' } it 'has status 422' do - expect(response.status).to eq 422 + expect(response).to have_http_status :unprocessable_entity end it 'returns message "Invalid token"' do @@ -41,7 +41,7 @@ RSpec.describe 'Token Confirmation', type: :request do let(:confirmation_token) { '12345' } it 'has status 422' do - expect(response.status).to eq 422 + expect(response).to have_http_status :unprocessable_entity end it 'returns message "Already confirmed"' do diff --git a/spec/controllers/installation/onboarding_controller_spec.rb b/spec/controllers/installation/onboarding_controller_spec.rb index aeeb667a4..3ab22db18 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 eq nil + expect(::Redis::Alfred.get(::Redis::Alfred::CHATWOOT_INSTALLATION_ONBOARDING)).to be_nil get '/installation/onboarding' expect(response).to have_http_status(:redirect) end @@ -23,7 +23,7 @@ RSpec.describe 'Installation::Onboarding API', type: :request do end describe 'POST /installation/onboarding' do - let(:account_builder) { instance_double('account_builder') } + let(:account_builder) { double } before do allow(AccountBuilder).to receive(:new).and_return(account_builder) @@ -39,7 +39,7 @@ RSpec.describe 'Installation::Onboarding API', type: :request do 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 eq 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 eq 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/users_controller_spec.rb b/spec/controllers/platform/api/v1/users_controller_spec.rb index 6ed3cbb7d..57fa81bd4 100644 --- a/spec/controllers/platform/api/v1/users_controller_spec.rb +++ b/spec/controllers/platform/api/v1/users_controller_spec.rb @@ -148,8 +148,8 @@ RSpec.describe 'Platform Users API', type: :request do it 'updates the user attributes' do create(:platform_app_permissible, platform_app: platform_app, permissible: user) patch "/platform/api/v1/users/#{user.id}", params: { - name: 'test123', email: 'newtestemail@test.com', custom_attributes: { test: 'test_update' } - }, + name: 'test123', email: 'newtestemail@test.com', custom_attributes: { test: 'test_update' } + }, headers: { api_access_token: platform_app.access_token.token }, as: :json expect(response).to have_http_status(:success) diff --git a/spec/controllers/public/api/v1/inbox/contacts_controller_spec.rb b/spec/controllers/public/api/v1/inbox/contacts_controller_spec.rb index 5e412a65d..7bd707883 100644 --- a/spec/controllers/public/api/v1/inbox/contacts_controller_spec.rb +++ b/spec/controllers/public/api/v1/inbox/contacts_controller_spec.rb @@ -12,8 +12,8 @@ RSpec.describe 'Public Inbox Contacts API', type: :request do expect(response).to have_http_status(:success) data = response.parsed_body expect(data.keys).to include('email', 'id', 'name', 'phone_number', 'pubsub_token', 'source_id') - expect(data['source_id']).not_to eq nil - expect(data['pubsub_token']).not_to eq nil + expect(data['source_id']).not_to be_nil + expect(data['pubsub_token']).not_to be_nil end end 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 1250ba526..a4a711b04 100644 --- a/spec/controllers/public/api/v1/inbox/conversations_controller_spec.rb +++ b/spec/controllers/public/api/v1/inbox/conversations_controller_spec.rb @@ -22,7 +22,7 @@ RSpec.describe 'Public Inbox Contact Conversations API', type: :request do expect(response).to have_http_status(:success) data = JSON.parse(response.body) - expect(data['id']).not_to eq nil + expect(data['id']).not_to be_nil end 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 54c1cc2cd..5ad9e91ef 100644 --- a/spec/controllers/public/api/v1/inbox/messages_controller_spec.rb +++ b/spec/controllers/public/api/v1/inbox/messages_controller_spec.rb @@ -49,7 +49,7 @@ RSpec.describe 'Public Inbox Contact Conversation Messages API', type: :request data = JSON.parse(response.body) expect(data['content']).to eq('hello') - expect(conversation.messages.last.attachments.first.file.present?).to eq(true) + expect(conversation.messages.last.attachments.first.file.present?).to be(true) expect(conversation.messages.last.attachments.first.file_type).to eq('image') end end diff --git a/spec/controllers/public/api/v1/portals/articles_controller_spec.rb b/spec/controllers/public/api/v1/portals/articles_controller_spec.rb index f5509cf28..0e074da68 100644 --- a/spec/controllers/public/api/v1/portals/articles_controller_spec.rb +++ b/spec/controllers/public/api/v1/portals/articles_controller_spec.rb @@ -32,7 +32,7 @@ RSpec.describe 'Public Articles API', type: :request do category: category, author_id: agent.id, content: 'this is some test and funny content') - expect(article2.id).not_to be nil + expect(article2.id).not_to be_nil get "/public/api/v1/portals/#{portal.slug}/articles", headers: agent.create_new_auth_token, diff --git a/spec/controllers/service/responses_controller_spec.rb b/spec/controllers/service/responses_controller_spec.rb index a576a1c19..9f2aede70 100644 --- a/spec/controllers/service/responses_controller_spec.rb +++ b/spec/controllers/service/responses_controller_spec.rb @@ -10,7 +10,7 @@ describe '/survey/response', type: :request do it 'returns 404 when called with invalid conversation uuid' do get survey_response_url(id: '') - expect(response.status).to eq(404) + expect(response).to have_http_status(:not_found) end end end diff --git a/spec/controllers/super_admin/app_config_controller_spec.rb b/spec/controllers/super_admin/app_config_controller_spec.rb index 9cf7b9075..3d6df46a8 100644 --- a/spec/controllers/super_admin/app_config_controller_spec.rb +++ b/spec/controllers/super_admin/app_config_controller_spec.rb @@ -36,7 +36,7 @@ RSpec.describe 'Super Admin Application Config API', type: :request do sign_in(super_admin, scope: :super_admin) post '/super_admin/app_config', params: { app_config: { TESTKEY: 'TESTVALUE' } } - expect(response.status).to eq(302) + expect(response).to have_http_status(:found) expect(response).to redirect_to(super_admin_app_config_path) config = GlobalConfig.get('TESTKEY') diff --git a/spec/controllers/twitter/callbacks_controller_spec.rb b/spec/controllers/twitter/callbacks_controller_spec.rb index 213f4704d..12a73953b 100644 --- a/spec/controllers/twitter/callbacks_controller_spec.rb +++ b/spec/controllers/twitter/callbacks_controller_spec.rb @@ -3,9 +3,7 @@ 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(:raw_response) do - object_double('raw_response', body: 'oauth_token=1&oauth_token_secret=1&user_id=100&screen_name=chatwoot') - end + let(:raw_response) { double } let(:account) { create(:account) } let(:webhook_service) { double } @@ -15,6 +13,7 @@ RSpec.describe 'Twitter::CallbacksController', type: :request do 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::WebhookSubscribeService).to receive(:new).and_return(webhook_service) end diff --git a/spec/controllers/widgets_controller_spec.rb b/spec/controllers/widgets_controller_spec.rb index efeec5723..07624e03e 100644 --- a/spec/controllers/widgets_controller_spec.rb +++ b/spec/controllers/widgets_controller_spec.rb @@ -23,7 +23,7 @@ describe '/widget', type: :request do it 'returns 404 when called with out website_token' do get widget_url - expect(response.status).to eq(404) + expect(response).to have_http_status(:not_found) end end end diff --git a/spec/helpers/url_helper_spec.rb b/spec/helpers/url_helper_spec.rb index 14defbf17..0a845e31a 100644 --- a/spec/helpers/url_helper_spec.rb +++ b/spec/helpers/url_helper_spec.rb @@ -4,11 +4,11 @@ describe UrlHelper, type: :helper do describe '#url_valid' do context 'when url valid called' do it 'return if valid url passed' do - expect(helper.url_valid?('https://app.chatwoot.com/')).to eq true + expect(helper.url_valid?('https://app.chatwoot.com/')).to be true end it 'return false if invalid url passed' do - expect(helper.url_valid?('javascript:alert(document.cookie)')).to eq false + expect(helper.url_valid?('javascript:alert(document.cookie)')).to be false end end end diff --git a/spec/jobs/bulk_actions_job_spec.rb b/spec/jobs/bulk_actions_job_spec.rb index 028f5ff3d..80784a6db 100644 --- a/spec/jobs/bulk_actions_job_spec.rb +++ b/spec/jobs/bulk_actions_job_spec.rb @@ -51,7 +51,7 @@ RSpec.describe BulkActionsJob, type: :job do ids: Conversation.first(3).pluck(:display_id) } - expect(Conversation.first.assignee_id).to eq(nil) + expect(Conversation.first.assignee_id).to be_nil described_class.perform_now(account: account, params: params, user: agent) diff --git a/spec/jobs/webhooks/instagram_events_job_spec.rb b/spec/jobs/webhooks/instagram_events_job_spec.rb index 850c3730b..e358576e4 100644 --- a/spec/jobs/webhooks/instagram_events_job_spec.rb +++ b/spec/jobs/webhooks/instagram_events_job_spec.rb @@ -7,13 +7,6 @@ describe Webhooks::InstagramEventsJob do before do stub_request(:post, /graph.facebook.com/) stub_request(:get, 'https://www.example.com/test.jpeg') - .with( - headers: { - 'Accept' => '*/*', - 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'User-Agent' => 'Down/5.3.0' - } - ) .to_return(status: 200, body: '', headers: {}) end @@ -78,7 +71,7 @@ describe Webhooks::InstagramEventsJob do instagram_webhook.perform_now(unsend_event[:entry]) expect(instagram_inbox.messages.last.content).to eq 'This message was deleted' - expect(instagram_inbox.messages.last.reload.deleted).to eq true + expect(instagram_inbox.messages.last.reload.deleted).to be true end it 'creates incoming message with attachments in the instagram inbox' do diff --git a/spec/lib/chatwoot_captcha_spec.rb b/spec/lib/chatwoot_captcha_spec.rb index 3b35c872e..db0329971 100644 --- a/spec/lib/chatwoot_captcha_spec.rb +++ b/spec/lib/chatwoot_captcha_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' describe ChatwootCaptcha do it 'returns true if HCAPTCHA SERVER KEY is absent' do - expect(described_class.new('random_key').valid?).to eq(true) + expect(described_class.new('random_key').valid?).to be(true) end context 'when HCAPTCHA SERVER KEY is present' do @@ -11,7 +11,7 @@ describe ChatwootCaptcha do end it 'returns false if client response is blank' do - expect(described_class.new('').valid?).to eq false + expect(described_class.new('').valid?).to be false end it 'returns true if client response is valid' do @@ -19,7 +19,7 @@ describe ChatwootCaptcha do allow(HTTParty).to receive(:post).and_return(captcha_request) allow(captcha_request).to receive(:success?).and_return(true) allow(captcha_request).to receive(:parsed_response).and_return({ 'success' => true }) - expect(described_class.new('valid_response').valid?).to eq true + expect(described_class.new('valid_response').valid?).to be true end end end diff --git a/spec/lib/chatwoot_hub_spec.rb b/spec/lib/chatwoot_hub_spec.rb index 32925492e..99eaf19da 100644 --- a/spec/lib/chatwoot_hub_spec.rb +++ b/spec/lib/chatwoot_hub_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' describe ChatwootHub do it 'generates installation identifier' do installation_identifier = described_class.installation_identifier - expect(installation_identifier).not_to eq nil + expect(installation_identifier).not_to be_nil expect(described_class.installation_identifier).to eq installation_identifier end @@ -28,7 +28,7 @@ describe ChatwootHub do it 'returns nil when chatwoot hub is down' do allow(RestClient).to receive(:post).and_raise(ExceptionList::REST_CLIENT_EXCEPTIONS.sample) - expect(described_class.latest_version).to eq nil + expect(described_class.latest_version).to be_nil end end diff --git a/spec/lib/global_config_service_spec.rb b/spec/lib/global_config_service_spec.rb index 4b27a8c38..9de13fb5f 100644 --- a/spec/lib/global_config_service_spec.rb +++ b/spec/lib/global_config_service_spec.rb @@ -23,7 +23,7 @@ describe GlobalConfigService do it 'get value from env variable even if present on DB' do with_modified_env ENABLE_ACCOUNT_SIGNUP: 'false' do - expect(InstallationConfig.find_by(name: 'ENABLE_ACCOUNT_SIGNUP')&.value).to eq nil + expect(InstallationConfig.find_by(name: 'ENABLE_ACCOUNT_SIGNUP')&.value).to be_nil value = described_class.load('ENABLE_ACCOUNT_SIGNUP', 'true') expect(value).to eq 'false' end diff --git a/spec/lib/integrations/csml/processor_service_spec.rb b/spec/lib/integrations/csml/processor_service_spec.rb index 2578881bb..a6d213114 100644 --- a/spec/lib/integrations/csml/processor_service_spec.rb +++ b/spec/lib/integrations/csml/processor_service_spec.rb @@ -61,7 +61,7 @@ describe Integrations::Csml::ProcessorService do let(:conversation) { create(:conversation, account: account, status: :open) } it 'returns nil' do - expect(processor.perform).to be(nil) + expect(processor.perform).to be_nil end end @@ -69,7 +69,7 @@ describe Integrations::Csml::ProcessorService do let(:message) { create(:message, account: account, conversation: conversation, private: true) } it 'returns nil' do - expect(processor.perform).to be(nil) + expect(processor.perform).to be_nil end end @@ -77,7 +77,7 @@ describe Integrations::Csml::ProcessorService do let(:message) { create(:message, account: account, conversation: conversation, message_type: :template) } it 'returns nil' do - expect(processor.perform).to be(nil) + expect(processor.perform).to be_nil end end @@ -100,7 +100,7 @@ describe Integrations::Csml::ProcessorService do let(:event_name) { 'message.updated' } it 'returns nil' do - expect(processor.perform).to be(nil) + expect(processor.perform).to be_nil end end end diff --git a/spec/lib/integrations/dialogflow/processor_service_spec.rb b/spec/lib/integrations/dialogflow/processor_service_spec.rb index 87f1e2cc4..003fd7c57 100644 --- a/spec/lib/integrations/dialogflow/processor_service_spec.rb +++ b/spec/lib/integrations/dialogflow/processor_service_spec.rb @@ -93,7 +93,7 @@ describe Integrations::Dialogflow::ProcessorService do let(:conversation) { create(:conversation, account: account, status: :open) } it 'returns nil' do - expect(processor.perform).to be(nil) + expect(processor.perform).to be_nil end end @@ -101,7 +101,7 @@ describe Integrations::Dialogflow::ProcessorService do let(:message) { create(:message, account: account, conversation: conversation, private: true) } it 'returns nil' do - expect(processor.perform).to be(nil) + expect(processor.perform).to be_nil end end diff --git a/spec/lib/integrations/slack/incoming_message_builder_spec.rb b/spec/lib/integrations/slack/incoming_message_builder_spec.rb index 0eede30cf..5e2730081 100644 --- a/spec/lib/integrations/slack/incoming_message_builder_spec.rb +++ b/spec/lib/integrations/slack/incoming_message_builder_spec.rb @@ -36,7 +36,7 @@ describe Integrations::Slack::IncomingMessageBuilder do end it 'creates message' do - expect(hook).not_to eq nil + expect(hook).not_to be_nil messages_count = conversation.messages.count builder = described_class.new(message_params) allow(builder).to receive(:sender).and_return(nil) @@ -71,7 +71,7 @@ describe Integrations::Slack::IncomingMessageBuilder do end it 'saves attachment if params files present' do - expect(hook).not_to eq nil + expect(hook).not_to be_nil messages_count = conversation.messages.count builder = described_class.new(message_with_attachments) allow(builder).to receive(:sender).and_return(nil) @@ -82,7 +82,7 @@ describe Integrations::Slack::IncomingMessageBuilder do end it 'ignore message if it is postback of CW attachment message' do - expect(hook).not_to eq nil + expect(hook).not_to be_nil messages_count = conversation.messages.count message_with_attachments[:event][:text] = 'Attached File!' builder = described_class.new(message_with_attachments) diff --git a/spec/listeners/notification_listener_spec.rb b/spec/listeners/notification_listener_spec.rb index e1b3a6a56..e581e9ac6 100644 --- a/spec/listeners/notification_listener_spec.rb +++ b/spec/listeners/notification_listener_spec.rb @@ -134,7 +134,7 @@ describe NotificationListener do event = Events::Base.new(event_name, Time.zone.now, message: message) # want to validate message_created doesnt throw an error - expect(listener.message_created(event)).to eq nil + expect(listener.message_created(event)).to be_nil end end end diff --git a/spec/mailboxes/reply_mailbox_spec.rb b/spec/mailboxes/reply_mailbox_spec.rb index f5d8f80c2..c73de877c 100644 --- a/spec/mailboxes/reply_mailbox_spec.rb +++ b/spec/mailboxes/reply_mailbox_spec.rb @@ -136,7 +136,7 @@ RSpec.describe ReplyMailbox, type: :mailbox do described_subject current_message = conversation.messages.last expect(current_message.content).to eq( - <<-BODY.strip_heredoc.chomp + <<~BODY.chomp Yes, I am providing you step how to reproduce this issue On Thu, Aug 19, 2021 at 2:07 PM Tejaswini from Email sender test < tejaswini@chatwoot.com> wrote: @@ -157,7 +157,7 @@ RSpec.describe ReplyMailbox, type: :mailbox do described_subject current_message = conversation.messages.last expect(current_message.reload.content_attributes[:email][:text_content][:reply]).to eq( - <<-BODY.strip_heredoc.chomp + <<~BODY.chomp Yes, I am providing you step how to reproduce this issue On Thu, Aug 19, 2021 at 2:07 PM Tejaswini from Email sender test < tejaswini@chatwoot.com> wrote: diff --git a/spec/mailboxes/support_mailbox_spec.rb b/spec/mailboxes/support_mailbox_spec.rb index 8c32ee80e..88ded0831 100644 --- a/spec/mailboxes/support_mailbox_spec.rb +++ b/spec/mailboxes/support_mailbox_spec.rb @@ -12,7 +12,7 @@ RSpec.describe SupportMailbox, type: :mailbox do it 'shouldnt create a conversation in the channel' do described_subject - expect(conversation.present?).to eq(false) + expect(conversation.present?).to be(false) end end @@ -202,7 +202,7 @@ RSpec.describe SupportMailbox, type: :mailbox do expect(conversation.inbox.id).to eq(channel_email.inbox.id) expect(conversation.messages.last.content_attributes['email']['html_content']['reply']).to include( - <<-BODY.strip_heredoc.chomp + <<~BODY.chomp Hi, We are providing you platform from here you can sell paid posts on your website. @@ -231,8 +231,8 @@ RSpec.describe SupportMailbox, type: :mailbox do expect(conversation.inbox.id).to eq(channel_email.inbox.id) expect(conversation.messages.last.content).to eq( - <<-BODY.strip_heredoc.chomp - This is html only mail + <<~BODY.chomp + This is html only mail BODY ) expect(conversation.messages.last.content_attributes['email']['subject']).to eq('test html only mail') @@ -243,7 +243,7 @@ RSpec.describe SupportMailbox, type: :mailbox do expect(conversation.inbox.id).to eq(channel_email.inbox.id) - expect(conversation.messages.last.content).to eq(nil) + expect(conversation.messages.last.content).to be_nil expect(conversation.messages.last.attachments.count).to eq(1) expect(conversation.messages.last.content_attributes['email']['subject']).to eq('only attachments') end diff --git a/spec/mailers/agent_notifications/conversation_notifications_mailer_spec.rb b/spec/mailers/agent_notifications/conversation_notifications_mailer_spec.rb index 4263b6796..1186d7cc9 100644 --- a/spec/mailers/agent_notifications/conversation_notifications_mailer_spec.rb +++ b/spec/mailers/agent_notifications/conversation_notifications_mailer_spec.rb @@ -70,7 +70,7 @@ RSpec.describe AgentNotifications::ConversationNotificationsMailer, type: :maile it 'will not send email if agent is online' do ::OnlineStatusTracker.update_presence(conversation.account.id, 'User', agent.id) - expect(mail).to eq nil + expect(mail).to be_nil end end end diff --git a/spec/mailers/conversation_reply_mailer_spec.rb b/spec/mailers/conversation_reply_mailer_spec.rb index c64b2a28a..cb3c4a9f9 100644 --- a/spec/mailers/conversation_reply_mailer_spec.rb +++ b/spec/mailers/conversation_reply_mailer_spec.rb @@ -71,7 +71,7 @@ RSpec.describe ConversationReplyMailer, type: :mailer do it 'will not send email if conversation is already viewed by contact' do create(:message, message_type: 'outgoing', account: account, conversation: conversation) conversation.update(contact_last_seen_at: Time.zone.now) - expect(mail).to eq nil + expect(mail).to be_nil end it 'will send email to cc and bcc email addresses' do @@ -132,7 +132,7 @@ RSpec.describe ConversationReplyMailer, type: :mailer do it 'will not send email if conversation is already viewed by contact' do create(:message, message_type: 'outgoing', account: account, conversation: conversation) conversation.update(contact_last_seen_at: Time.zone.now) - expect(mail).to eq nil + expect(mail).to be_nil end end diff --git a/spec/models/account_user_spec.rb b/spec/models/account_user_spec.rb index b4207d577..00b66dc77 100644 --- a/spec/models/account_user_spec.rb +++ b/spec/models/account_user_spec.rb @@ -13,10 +13,10 @@ RSpec.describe User do describe 'notification_settings' do it 'gets created with the right default settings' do - expect(account_user.user.notification_settings).not_to eq(nil) + expect(account_user.user.notification_settings).not_to be_nil - expect(account_user.user.notification_settings.first.email_conversation_creation?).to eq(false) - expect(account_user.user.notification_settings.first.email_conversation_assignment?).to eq(true) + expect(account_user.user.notification_settings.first.email_conversation_creation?).to be(false) + expect(account_user.user.notification_settings.first.email_conversation_assignment?).to be(true) end end diff --git a/spec/models/attachment_spec.rb b/spec/models/attachment_spec.rb index 55cf01a0b..14e35fea9 100644 --- a/spec/models/attachment_spec.rb +++ b/spec/models/attachment_spec.rb @@ -6,7 +6,7 @@ RSpec.describe Attachment, type: :model 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') - expect(attachment.download_url).not_to eq nil + expect(attachment.download_url).not_to be_nil end end end diff --git a/spec/models/automation_rule_spec.rb b/spec/models/automation_rule_spec.rb index fe5fe46c7..501e19637 100644 --- a/spec/models/automation_rule_spec.rb +++ b/spec/models/automation_rule_spec.rb @@ -50,7 +50,7 @@ RSpec.describe AutomationRule, type: :model do it 'returns valid record' do rule = FactoryBot.build(:automation_rule, params) - expect(rule.valid?).to eq true + expect(rule.valid?).to be true end end end diff --git a/spec/models/campaign_spec.rb b/spec/models/campaign_spec.rb index 95cac1caf..53890458e 100644 --- a/spec/models/campaign_spec.rb +++ b/spec/models/campaign_spec.rb @@ -34,7 +34,7 @@ RSpec.describe Campaign, type: :model do let(:campaign) { build(:campaign, inbox: facebook_inbox) } it 'would not save the campaigns' do - expect(campaign.save).to eq false + expect(campaign.save).to be false expect(campaign.errors.full_messages.first).to eq 'Inbox Unsupported Inbox type' end end @@ -46,18 +46,18 @@ RSpec.describe Campaign, type: :model do it 'would prevent further updates' do campaign.title = 'new name' - expect(campaign.save).to eq false + expect(campaign.save).to be false expect(campaign.errors.full_messages.first).to eq 'Status The campaign is already completed' end it 'can be deleted' do campaign.destroy! - expect(described_class.exists?(campaign.id)).to eq false + expect(described_class.exists?(campaign.id)).to be false end it 'cant be triggered' do expect(Twilio::OneoffSmsCampaignService).not_to receive(:new).with(campaign: campaign) - expect(campaign.trigger!).to eq nil + expect(campaign.trigger!).to be_nil end end @@ -71,7 +71,7 @@ RSpec.describe Campaign, type: :model do campaign.campaign_type = 'ongoing' campaign.save! expect(campaign.reload.campaign_type).to eq 'one_off' - expect(campaign.scheduled_at.present?).to eq true + expect(campaign.scheduled_at.present?).to be true end it 'calls twilio service on trigger!' do @@ -92,7 +92,7 @@ RSpec.describe Campaign, type: :model do campaign.campaign_type = 'ongoing' campaign.save! expect(campaign.reload.campaign_type).to eq 'one_off' - expect(campaign.scheduled_at.present?).to eq true + expect(campaign.scheduled_at.present?).to be true end it 'calls sms service on trigger!' do diff --git a/spec/models/channel/twilio_sms_spec.rb b/spec/models/channel/twilio_sms_spec.rb index d38bf3145..e77584935 100644 --- a/spec/models/channel/twilio_sms_spec.rb +++ b/spec/models/channel/twilio_sms_spec.rb @@ -8,7 +8,7 @@ RSpec.describe Channel::TwilioSms do let!(:whatsapp_channel) { create(:channel_twilio_sms, medium: :whatsapp) } it 'returns true' do - expect(whatsapp_channel.messaging_window_enabled?).to eq true + expect(whatsapp_channel.messaging_window_enabled?).to be true expect(whatsapp_channel.name).to eq 'Whatsapp' expect(whatsapp_channel.medium).to eq 'whatsapp' end @@ -18,7 +18,7 @@ RSpec.describe Channel::TwilioSms do let!(:sms_channel) { create(:channel_twilio_sms, medium: :sms) } it 'returns false' do - expect(sms_channel.messaging_window_enabled?).to eq false + expect(sms_channel.messaging_window_enabled?).to be false expect(sms_channel.name).to eq 'Twilio SMS' expect(sms_channel.medium).to eq 'sms' end diff --git a/spec/models/channel/whatsapp_spec.rb b/spec/models/channel/whatsapp_spec.rb index d38f14d11..d96ffdc85 100644 --- a/spec/models/channel/whatsapp_spec.rb +++ b/spec/models/channel/whatsapp_spec.rb @@ -8,7 +8,7 @@ RSpec.describe Channel::Whatsapp do it 'validates false when provider config is wrong' do stub_request(:get, 'https://graph.facebook.com/v14.0//message_templates?access_token=test_key').to_return(status: 401) - expect(channel.save).to eq(false) + expect(channel.save).to be(false) end it 'validates true when provider config is right' do @@ -17,7 +17,7 @@ RSpec.describe Channel::Whatsapp do body: { data: [{ id: '123456789', name: 'test_template' }] }.to_json) - expect(channel.save).to eq(true) + expect(channel.save).to be(true) end end end diff --git a/spec/models/concerns/access_tokenable_shared.rb b/spec/models/concerns/access_tokenable_shared.rb index c2b504dbf..d84d22938 100644 --- a/spec/models/concerns/access_tokenable_shared.rb +++ b/spec/models/concerns/access_tokenable_shared.rb @@ -4,6 +4,6 @@ shared_examples_for 'access_tokenable' do let(:obj) { create(described_class.to_s.underscore) } it 'creates access token on create' do - expect(obj.access_token).not_to eq(nil) + expect(obj.access_token).not_to be_nil end end diff --git a/spec/models/concerns/assignment_handler_shared.rb b/spec/models/concerns/assignment_handler_shared.rb index 7546228c1..0194da76c 100644 --- a/spec/models/concerns/assignment_handler_shared.rb +++ b/spec/models/concerns/assignment_handler_shared.rb @@ -21,8 +21,8 @@ shared_examples_for 'assignment_handler' do end it 'creates team assigned and unassigned message activity' do - expect(conversation.update(team: team)).to eq true - expect(conversation.update(team: nil)).to eq true + expect(conversation.update(team: team)).to be true + expect(conversation.update(team: nil)).to be true expect(Conversations::ActivityMessageJob).to(have_been_enqueued.at_least(:once) .with(conversation, { account_id: conversation.account_id, inbox_id: conversation.inbox_id, message_type: :activity, content: "Assigned to #{team.name} by #{agent.name}" })) @@ -32,11 +32,11 @@ shared_examples_for 'assignment_handler' do end it 'changes assignee to nil if they doesnt belong to the team and allow_auto_assign is false' do - expect(team.allow_auto_assign).to eq false + expect(team.allow_auto_assign).to be false conversation.update(team: team) - expect(conversation.reload.assignee).to eq nil + expect(conversation.reload.assignee).to be_nil end it 'changes assignee to a team member if allow_auto_assign is enabled' do @@ -74,7 +74,7 @@ shared_examples_for 'assignment_handler' do let(:assignment_mailer) { instance_double(AgentNotifications::ConversationNotificationsMailer, deliver: true) } it 'assigns the agent to conversation' do - expect(update_assignee).to eq(true) + expect(update_assignee).to be(true) expect(conversation.reload.assignee).to eq(agent) end @@ -82,7 +82,7 @@ shared_examples_for 'assignment_handler' do # TODO: FIX me # expect(EventDispatcherJob).to(have_been_enqueued.at_least(:once).with('assignee.changed', anything, anything, anything, anything)) expect(EventDispatcherJob).to(have_been_enqueued.at_least(:once)) - expect(update_assignee).to eq(true) + expect(update_assignee).to be(true) end context 'when agent is current user' do @@ -91,7 +91,7 @@ shared_examples_for 'assignment_handler' do end it 'creates self-assigned message activity' do - expect(update_assignee).to eq(true) + expect(update_assignee).to be(true) expect(Conversations::ActivityMessageJob).to(have_been_enqueued.at_least(:once) .with(conversation, { account_id: conversation.account_id, inbox_id: conversation.inbox_id, message_type: :activity, content: "#{agent.name} self-assigned this conversation" })) diff --git a/spec/models/concerns/reauthorizable_shared.rb b/spec/models/concerns/reauthorizable_shared.rb index 212afd4af..0bfa112c4 100644 --- a/spec/models/concerns/reauthorizable_shared.rb +++ b/spec/models/concerns/reauthorizable_shared.rb @@ -14,21 +14,21 @@ shared_examples_for 'reauthorizable' do it 'prompts reauthorization when error threshold is passed' do obj = FactoryBot.create(model.to_s.underscore.tr('/', '_').to_sym) - expect(obj.reauthorization_required?).to eq false + expect(obj.reauthorization_required?).to be false obj.class::AUTHORIZATION_ERROR_THRESHOLD.times do obj.authorization_error! end - expect(obj.reauthorization_required?).to eq true + expect(obj.reauthorization_required?).to be true end it 'prompt_reauthorization!' do obj = FactoryBot.create(model.to_s.underscore.tr('/', '_').to_sym) - expect(obj.reauthorization_required?).to eq false + expect(obj.reauthorization_required?).to be false obj.prompt_reauthorization! - expect(obj.reauthorization_required?).to eq true + expect(obj.reauthorization_required?).to be true end it 'reauthorized!' do @@ -36,13 +36,13 @@ shared_examples_for 'reauthorizable' do # setting up the object with the errors to validate its cleared on action obj.authorization_error! obj.prompt_reauthorization! - expect(obj.reauthorization_required?).to eq true + expect(obj.reauthorization_required?).to be true expect(obj.authorization_error_count).not_to eq 0 obj.reauthorized! # authorization errors are reset expect(obj.authorization_error_count).to eq 0 - expect(obj.reauthorization_required?).to eq false + expect(obj.reauthorization_required?).to be false end end diff --git a/spec/models/concerns/round_robin_handler_shared.rb b/spec/models/concerns/round_robin_handler_shared.rb index 9ec499ed2..1bd7b9ca1 100644 --- a/spec/models/concerns/round_robin_handler_shared.rb +++ b/spec/models/concerns/round_robin_handler_shared.rb @@ -31,7 +31,7 @@ shared_examples_for 'round_robin_handler' do inbox.update(enable_auto_assignment: false) # run_round_robin - expect(conversation.reload.assignee).to eq(nil) + expect(conversation.reload.assignee).to be_nil end it 'will not auto assign agent if its a bot conversation' do @@ -45,7 +45,7 @@ shared_examples_for 'round_robin_handler' do ) # run_round_robin - expect(conversation.reload.assignee).to eq(nil) + expect(conversation.reload.assignee).to be_nil end it 'gets triggered on update only when status changes to open' do diff --git a/spec/models/contact_inbox_spec.rb b/spec/models/contact_inbox_spec.rb index a162d6e7b..1c575f105 100644 --- a/spec/models/contact_inbox_spec.rb +++ b/spec/models/contact_inbox_spec.rb @@ -8,7 +8,7 @@ RSpec.describe ContactInbox do it 'gets created on object create' do obj = contact_inbox - expect(obj.pubsub_token).not_to eq(nil) + expect(obj.pubsub_token).not_to be_nil end it 'does not get updated on object update' do @@ -29,7 +29,7 @@ RSpec.describe ContactInbox do # ensure the column is nil in database results = ActiveRecord::Base.connection.execute('Select * from contact_inboxes;') - expect(results.first['pubsub_token']).to eq(nil) + expect(results.first['pubsub_token']).to be_nil new_token = obj.pubsub_token obj.update(source_id: '234234323') diff --git a/spec/models/contact_spec.rb b/spec/models/contact_spec.rb index a6893ae76..900d96c2f 100644 --- a/spec/models/contact_spec.rb +++ b/spec/models/contact_spec.rb @@ -52,7 +52,7 @@ RSpec.describe Contact do it 'updates phone number when adding valid phone number' do contact = create(:contact) - expect(contact.update!(phone_number: '+12312312321')).to eq true + expect(contact.update!(phone_number: '+12312312321')).to be true expect(contact.phone_number).to eq '+12312312321' end end @@ -65,7 +65,7 @@ RSpec.describe Contact do it 'updates email when adding valid email' do contact = create(:contact) - expect(contact.update!(email: 'test@test.com')).to eq true + expect(contact.update!(email: 'test@test.com')).to be true expect(contact.email).to eq 'test@test.com' end end diff --git a/spec/models/conversation_spec.rb b/spec/models/conversation_spec.rb index 1a80a55fb..1d172ca8d 100644 --- a/spec/models/conversation_spec.rb +++ b/spec/models/conversation_spec.rb @@ -221,7 +221,7 @@ RSpec.describe Conversation, type: :model do expect(conversation.label_list).to match_array(labels) updated_labels = [second_label, third_label].map(&:title) - expect(conversation.update_labels(updated_labels)).to eq(true) + expect(conversation.update_labels(updated_labels)).to be(true) expect(conversation.label_list).to match_array(updated_labels) expect(Conversations::ActivityMessageJob) @@ -238,25 +238,25 @@ RSpec.describe Conversation, type: :model do describe '#toggle_status' do it 'toggles conversation status to resolved when open' do conversation = create(:conversation, status: 'open') - expect(conversation.toggle_status).to eq(true) + expect(conversation.toggle_status).to be(true) expect(conversation.reload.status).to eq('resolved') end it 'toggles conversation status to open when resolved' do conversation = create(:conversation, status: 'resolved') - expect(conversation.toggle_status).to eq(true) + expect(conversation.toggle_status).to be(true) expect(conversation.reload.status).to eq('open') end it 'toggles conversation status to open when pending' do conversation = create(:conversation, status: 'pending') - expect(conversation.toggle_status).to eq(true) + expect(conversation.toggle_status).to be(true) expect(conversation.reload.status).to eq('open') end it 'toggles conversation status to open when snoozed' do conversation = create(:conversation, status: 'snoozed') - expect(conversation.toggle_status).to eq(true) + expect(conversation.toggle_status).to be(true) expect(conversation.reload.status).to eq('open') end end @@ -264,9 +264,9 @@ RSpec.describe Conversation, type: :model do describe '#ensure_snooze_until_reset' do it 'resets the snoozed_until when status is toggled' do conversation = create(:conversation, status: 'snoozed', snoozed_until: 2.days.from_now) - expect(conversation.snoozed_until).not_to eq nil - expect(conversation.toggle_status).to eq(true) - expect(conversation.reload.snoozed_until).to eq(nil) + expect(conversation.snoozed_until).not_to be_nil + expect(conversation.toggle_status).to be(true) + expect(conversation.reload.snoozed_until).to be_nil end end @@ -283,12 +283,12 @@ RSpec.describe Conversation, type: :model do it 'marks conversation as resolved' do mute! - expect(conversation.reload.resolved?).to eq(true) + expect(conversation.reload.resolved?).to be(true) end it 'marks conversation as muted in redis' do mute! - expect(Redis::Alfred.get(conversation.send(:mute_key))).not_to eq(nil) + expect(Redis::Alfred.get(conversation.send(:mute_key))).not_to be_nil end it 'creates mute message' do @@ -335,11 +335,11 @@ RSpec.describe Conversation, type: :model do it 'return true if conversation is muted' do conversation.mute! - expect(muted?).to eq(true) + expect(muted?).to be(true) end it 'returns false if conversation is not muted' do - expect(muted?).to eq(false) + expect(muted?).to be(false) end end @@ -475,7 +475,7 @@ RSpec.describe Conversation, type: :model do let(:conversation) { create(:conversation) } it 'returns true' do - expect(conversation.can_reply?).to eq true + expect(conversation.can_reply?).to be true end it 'return true for facebook channels' do @@ -484,8 +484,8 @@ RSpec.describe Conversation, type: :model do facebook_inbox = create(:inbox, channel: facebook_channel, account: facebook_channel.account) fb_conversation = create(:conversation, inbox: facebook_inbox, account: facebook_channel.account) - expect(fb_conversation.can_reply?).to eq true - expect(facebook_channel.messaging_window_enabled?).to eq false + expect(fb_conversation.can_reply?).to be true + expect(facebook_channel.messaging_window_enabled?).to be false end end @@ -511,7 +511,7 @@ RSpec.describe Conversation, type: :model do created_at: Time.now - 48.hours ) - expect(conversation.can_reply?).to eq true + expect(conversation.can_reply?).to be true end it 'return false without HUMAN_AGENT if it is outside of 24 hour window' do @@ -526,7 +526,7 @@ RSpec.describe Conversation, type: :model do created_at: Time.now - 48.hours ) - expect(conversation.can_reply?).to eq false + expect(conversation.can_reply?).to be false end end end @@ -546,8 +546,8 @@ RSpec.describe Conversation, type: :model do created_at: Time.now - 13.hours ) - expect(api_channel.additional_attributes['agent_reply_time_window']).to eq nil - expect(conversation.can_reply?).to eq true + expect(api_channel.additional_attributes['agent_reply_time_window']).to be_nil + expect(conversation.can_reply?).to be true end end @@ -563,7 +563,7 @@ RSpec.describe Conversation, type: :model do ) expect(api_channel_with_limit.additional_attributes['agent_reply_time_window']).to eq '12' - expect(conversation.can_reply?).to eq false + expect(conversation.can_reply?).to be false end it 'return true if it is inside of agent_reply_time_window' do @@ -574,7 +574,7 @@ RSpec.describe Conversation, type: :model do inbox: api_channel_with_limit.inbox, conversation: conversation ) - expect(conversation.can_reply?).to eq true + expect(conversation.can_reply?).to be true end end end @@ -595,7 +595,7 @@ RSpec.describe Conversation, type: :model do let(:conversation) { create(:conversation, additional_attributes: { referer: 'javascript' }) } it 'returns nil' do - expect(conversation['additional_attributes']['referer']).to eq(nil) + expect(conversation['additional_attributes']['referer']).to be_nil end end diff --git a/spec/models/csat_survey_response_spec.rb b/spec/models/csat_survey_response_spec.rb index 931ea15e2..9bab7e64a 100644 --- a/spec/models/csat_survey_response_spec.rb +++ b/spec/models/csat_survey_response_spec.rb @@ -9,7 +9,7 @@ RSpec.describe CsatSurveyResponse, type: :model do it 'validates that the rating can only be in range 1-5' do csat_survey_response = build(:csat_survey_response, rating: 6) - expect(csat_survey_response.valid?).to eq false + expect(csat_survey_response.valid?).to be false end end @@ -22,7 +22,7 @@ RSpec.describe CsatSurveyResponse, type: :model do describe 'validates_factory' do it 'creates valid csat_survey_response object' do csat_survey_response = create(:csat_survey_response) - expect(csat_survey_response.valid?).to eq true + expect(csat_survey_response.valid?).to be true end end end diff --git a/spec/models/data_import_spec.rb b/spec/models/data_import_spec.rb index df37c9211..0bfbc3dbf 100644 --- a/spec/models/data_import_spec.rb +++ b/spec/models/data_import_spec.rb @@ -7,7 +7,7 @@ RSpec.describe DataImport, type: :model do describe 'validations' do it 'returns false for invalid data type' do - expect(build(:data_import, data_type: 'Xyc').valid?).to eq false + expect(build(:data_import, data_type: 'Xyc').valid?).to be false end end end diff --git a/spec/models/inbox_spec.rb b/spec/models/inbox_spec.rb index 743704a1b..f1aeca2e5 100644 --- a/spec/models/inbox_spec.rb +++ b/spec/models/inbox_spec.rb @@ -74,7 +74,7 @@ RSpec.describe Inbox do let(:channel_val) { Channel::FacebookPage.new } it do - expect(inbox.facebook?).to eq(true) + expect(inbox.facebook?).to be(true) expect(inbox.inbox_type).to eq('Facebook') end end @@ -83,7 +83,7 @@ RSpec.describe Inbox do let(:channel_val) { Channel::WebWidget.new } it do - expect(inbox.facebook?).to eq(false) + expect(inbox.facebook?).to be(false) expect(inbox.inbox_type).to eq('Website') end end @@ -98,7 +98,7 @@ RSpec.describe Inbox do let(:channel_val) { Channel::WebWidget.new } it do - expect(inbox.web_widget?).to eq(true) + expect(inbox.web_widget?).to be(true) expect(inbox.inbox_type).to eq('Website') end end @@ -107,7 +107,7 @@ RSpec.describe Inbox do let(:channel_val) { Channel::Api.new } it do - expect(inbox.web_widget?).to eq(false) + expect(inbox.web_widget?).to be(false) expect(inbox.inbox_type).to eq('API') end end @@ -122,7 +122,7 @@ RSpec.describe Inbox do let(:channel_val) { Channel::Api.new } it do - expect(inbox.api?).to eq(true) + expect(inbox.api?).to be(true) expect(inbox.inbox_type).to eq('API') end end @@ -131,7 +131,7 @@ RSpec.describe Inbox do let(:channel_val) { Channel::FacebookPage.new } it do - expect(inbox.api?).to eq(false) + expect(inbox.api?).to be(false) expect(inbox.inbox_type).to eq('Facebook') end end diff --git a/spec/models/integrations/hook_spec.rb b/spec/models/integrations/hook_spec.rb index 87822a0dc..08a08cc4e 100644 --- a/spec/models/integrations/hook_spec.rb +++ b/spec/models/integrations/hook_spec.rb @@ -16,14 +16,14 @@ RSpec.describe Integrations::Hook, type: :model do context 'when app allows multiple hooks' do it 'allows to create succesfully' do create(:integrations_hook, account: account, app_id: 'webhook') - expect(build(:integrations_hook, account: account, app_id: 'webhook').valid?).to eq true + expect(build(:integrations_hook, account: account, app_id: 'webhook').valid?).to be true end end context 'when app doesnot allow multiple hooks' do it 'throws invalid error' do create(:integrations_hook, account: account, app_id: 'slack') - expect(build(:integrations_hook, account: account, app_id: 'slack').valid?).to eq false + expect(build(:integrations_hook, account: account, app_id: 'slack').valid?).to be false end end end diff --git a/spec/models/label_spec.rb b/spec/models/label_spec.rb index bd8b6ad19..69f1ce771 100644 --- a/spec/models/label_spec.rb +++ b/spec/models/label_spec.rb @@ -8,27 +8,27 @@ RSpec.describe Label, type: :model do describe 'title validations' do it 'would not let you start title without numbers or letters' do label = FactoryBot.build(:label, title: '_12') - expect(label.valid?).to eq false + expect(label.valid?).to be false end it 'would not let you use special characters' do label = FactoryBot.build(:label, title: 'jell;;2_12') - expect(label.valid?).to eq false + expect(label.valid?).to be false end it 'would not allow space' do label = FactoryBot.build(:label, title: 'heeloo _12') - expect(label.valid?).to eq false + expect(label.valid?).to be false end it 'allows foreign charactes' do label = FactoryBot.build(:label, title: 'ε­¦δΈ­ζ–‡_12') - expect(label.valid?).to eq true + expect(label.valid?).to be true end it 'converts uppercase letters to lowercase' do label = FactoryBot.build(:label, title: 'Hello_World') - expect(label.valid?).to eq true + expect(label.valid?).to be true expect(label.title).to eq 'hello_world' end @@ -36,7 +36,7 @@ RSpec.describe Label, type: :model do account = create(:account) label = FactoryBot.create(:label, account: account) duplicate_label = FactoryBot.build(:label, title: label.title, account: account) - expect(duplicate_label.valid?).to eq false + expect(duplicate_label.valid?).to be false end end diff --git a/spec/models/message_spec.rb b/spec/models/message_spec.rb index fea6cd5b5..e74a1129d 100644 --- a/spec/models/message_spec.rb +++ b/spec/models/message_spec.rb @@ -16,20 +16,20 @@ RSpec.describe Message, type: :model do it 'reopens resolved conversation when the message is from a contact' do conversation.resolved! message.save! - expect(message.conversation.open?).to eq true + expect(message.conversation.open?).to be true end it 'reopens snoozed conversation when the message is from a contact' do conversation.snoozed! message.save! - expect(message.conversation.open?).to eq true + expect(message.conversation.open?).to be true end it 'will not reopen if the conversation is muted' do conversation.resolved! conversation.mute! message.save! - expect(message.conversation.open?).to eq false + expect(message.conversation.open?).to be false end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 92015edcc..3c8c26cd4 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -30,7 +30,7 @@ RSpec.describe User do describe 'pubsub_token' do before { user.update(name: Faker::Name.name) } - it { expect(user.pubsub_token).not_to eq(nil) } + it { expect(user.pubsub_token).not_to be_nil } it { expect(user.saved_changes.keys).not_to eq('pubsub_token') } end @@ -58,18 +58,18 @@ RSpec.describe User do sso_auth_token2 = user.generate_sso_auth_token expect(sso_auth_token1).present? expect(sso_auth_token2).present? - expect(user.valid_sso_auth_token?(sso_auth_token1)).to eq true - expect(user.valid_sso_auth_token?(sso_auth_token2)).to eq true + expect(user.valid_sso_auth_token?(sso_auth_token1)).to be true + expect(user.valid_sso_auth_token?(sso_auth_token2)).to be true end it 'wont validate an invalid token' do - expect(user.valid_sso_auth_token?(SecureRandom.hex(32))).to eq false + expect(user.valid_sso_auth_token?(SecureRandom.hex(32))).to be false end it 'wont validate an invalidated token' do sso_auth_token = user.generate_sso_auth_token user.invalidate_sso_auth_token(sso_auth_token) - expect(user.valid_sso_auth_token?(sso_auth_token)).to eq false + expect(user.valid_sso_auth_token?(sso_auth_token)).to be false end end diff --git a/spec/presenters/mail_presenter_spec.rb b/spec/presenters/mail_presenter_spec.rb index a39559cc4..a783c92a3 100644 --- a/spec/presenters/mail_presenter_spec.rb +++ b/spec/presenters/mail_presenter_spec.rb @@ -51,12 +51,12 @@ RSpec.describe MailPresenter do expect(data[:content_type]).to include('multipart/alternative') expect(data[:date].to_s).to eq('2020-04-20T04:20:20-04:00') expect(data[:message_id]).to eq(mail.message_id) - expect(data[:multipart]).to eq(true) + expect(data[:multipart]).to be(true) expect(data[:subject]).to eq(decorated_mail.subject) end it 'give email from in downcased format' do - expect(decorated_mail.from.first.eql?(mail.from.first.downcase)).to eq true + expect(decorated_mail.from.first.eql?(mail.from.first.downcase)).to be true end it 'parse html content in the mail' do 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 0815c6eba..2bc0d813c 100644 --- a/spec/requests/api/v1/accounts/integrations/slack_request_spec.rb +++ b/spec/requests/api/v1/accounts/integrations/slack_request_spec.rb @@ -72,7 +72,7 @@ RSpec.describe 'Api::V1::Accounts::Integrations::Slacks', type: :request do delete "/api/v1/accounts/#{account.id}/integrations/slack", headers: agent.create_new_auth_token expect(response).to have_http_status(:success) - expect(Integrations::Hook.find_by(id: hook.id)).to be nil + expect(Integrations::Hook.find_by(id: hook.id)).to be_nil end end end diff --git a/spec/services/facebook/send_on_facebook_service_spec.rb b/spec/services/facebook/send_on_facebook_service_spec.rb index 5063159ad..674700c4d 100644 --- a/spec/services/facebook/send_on_facebook_service_spec.rb +++ b/spec/services/facebook/send_on_facebook_service_spec.rb @@ -10,7 +10,7 @@ describe Facebook::SendOnFacebookService do end let!(:account) { create(:account) } - let(:bot) { class_double('Facebook::Messenger::Bot').as_stubbed_const } + let(:bot) { class_double(Facebook::Messenger::Bot).as_stubbed_const } let!(:widget_inbox) { create(:inbox, account: account) } let!(:facebook_channel) { create(:channel_facebook_page, account: account) } let!(:facebook_inbox) { create(:inbox, channel: facebook_channel, account: account) } diff --git a/spec/services/line/incoming_message_service_spec.rb b/spec/services/line/incoming_message_service_spec.rb index 4b03fc8f2..ee53421b5 100644 --- a/spec/services/line/incoming_message_service_spec.rb +++ b/spec/services/line/incoming_message_service_spec.rb @@ -149,7 +149,7 @@ describe Line::IncomingMessageService do described_class.new(inbox: line_channel.inbox, params: image_params).perform expect(line_channel.inbox.conversations).not_to eq(0) expect(Contact.all.first.name).to eq('LINE Test') - expect(line_channel.inbox.messages.first.content).to eq(nil) + expect(line_channel.inbox.messages.first.content).to be_nil expect(line_channel.inbox.messages.first.attachments.first.file_type).to eq('image') expect(line_channel.inbox.messages.first.attachments.first.file.blob.filename.to_s).to eq('media-354718.png') end @@ -178,7 +178,7 @@ describe Line::IncomingMessageService do described_class.new(inbox: line_channel.inbox, params: video_params).perform expect(line_channel.inbox.conversations).not_to eq(0) expect(Contact.all.first.name).to eq('LINE Test') - expect(line_channel.inbox.messages.first.content).to eq(nil) + expect(line_channel.inbox.messages.first.content).to be_nil expect(line_channel.inbox.messages.first.attachments.first.file_type).to eq('video') expect(line_channel.inbox.messages.first.attachments.first.file.blob.filename.to_s).to eq('media-354718.mp4') end diff --git a/spec/services/round_robin/manage_service_spec.rb b/spec/services/round_robin/manage_service_spec.rb index 84cca45d1..fafbfb6d4 100644 --- a/spec/services/round_robin/manage_service_spec.rb +++ b/spec/services/round_robin/manage_service_spec.rb @@ -9,7 +9,7 @@ describe RoundRobin::ManageService do describe '#available_agent' do it 'returns nil if allowed_member_ids is empty' do - expect(described_class.new(inbox: inbox, allowed_member_ids: []).available_agent).to eq nil + expect(described_class.new(inbox: inbox, allowed_member_ids: []).available_agent).to be_nil end it 'gets the first available agent in allowed_member_ids and move agent to end of the list' do diff --git a/spec/services/sms/incoming_message_service_spec.rb b/spec/services/sms/incoming_message_service_spec.rb index 6dd8c56d5..0269cde95 100644 --- a/spec/services/sms/incoming_message_service_spec.rb +++ b/spec/services/sms/incoming_message_service_spec.rb @@ -54,7 +54,7 @@ describe Sms::IncomingMessageService do expect(sms_channel.inbox.conversations.count).not_to eq(0) expect(Contact.all.first.name).to eq('+1 423-423-4234') expect(sms_channel.inbox.messages.first.content).to eq('test message') - expect(sms_channel.inbox.messages.first.attachments.present?).to eq true + expect(sms_channel.inbox.messages.first.attachments.present?).to be true end end end diff --git a/spec/services/sms/oneoff_sms_campaign_service_spec.rb b/spec/services/sms/oneoff_sms_campaign_service_spec.rb index 9049175d8..27492f83b 100644 --- a/spec/services/sms/oneoff_sms_campaign_service_spec.rb +++ b/spec/services/sms/oneoff_sms_campaign_service_spec.rb @@ -41,7 +41,7 @@ describe Sms::OneoffSmsCampaignService do contact_with_both_labels.update_labels([label1.title, label2.title]) sms_campaign_service.perform assert_requested(:post, 'https://messaging.bandwidth.com/api/v2/users/1/messages', times: 3) - expect(campaign.reload.completed?).to eq true + expect(campaign.reload.completed?).to be true end end end diff --git a/spec/services/telegram/incoming_message_service_spec.rb b/spec/services/telegram/incoming_message_service_spec.rb index a9147e1f2..766330605 100644 --- a/spec/services/telegram/incoming_message_service_spec.rb +++ b/spec/services/telegram/incoming_message_service_spec.rb @@ -31,20 +31,23 @@ describe Telegram::IncomingMessageService do end let!(:telegram_channel) { create(:channel_telegram) } + let!(:message_params) do + { + 'message_id' => 1, + 'from' => { + 'id' => 23, 'is_bot' => false, 'first_name' => 'Sojan', 'last_name' => 'Jose', 'username' => 'sojan', 'language_code' => 'en' + }, + 'chat' => { 'id' => 23, 'first_name' => 'Sojan', 'last_name' => 'Jose', 'username' => 'sojan', 'type' => 'private' }, + 'date' => 1_631_132_077 + } + end describe '#perform' do context 'when valid text message params' do it 'creates appropriate conversations, message and contacts' do params = { 'update_id' => 2_342_342_343_242, - 'message' => { - 'message_id' => 1, - 'from' => { - 'id' => 23, 'is_bot' => false, 'first_name' => 'Sojan', 'last_name' => 'Jose', 'username' => 'sojan', 'language_code' => 'en' - }, - 'chat' => { 'id' => 23, 'first_name' => 'Sojan', 'last_name' => 'Jose', 'username' => 'sojan', 'type' => 'private' }, - 'date' => 1_631_132_077, 'text' => 'test' - } + 'message' => { 'text' => 'test' }.merge(message_params) }.with_indifferent_access described_class.new(inbox: telegram_channel.inbox, params: params).perform expect(telegram_channel.inbox.conversations.count).not_to eq(0) @@ -57,14 +60,7 @@ describe Telegram::IncomingMessageService do it 'creates appropriate conversations, message and contacts' do params = { 'update_id' => 2_342_342_343_242, - 'message' => { - 'message_id' => 1, - 'from' => { - 'id' => 23, 'is_bot' => false, 'first_name' => 'Sojan', 'last_name' => 'Jose', 'username' => 'sojan', 'language_code' => 'en' - }, - 'chat' => { 'id' => 23, 'first_name' => 'Sojan', 'last_name' => 'Jose', 'username' => 'sojan', 'type' => 'private' }, - 'date' => 1_631_132_077, 'caption' => 'test' - } + 'message' => { 'caption' => 'test' }.merge(message_params) }.with_indifferent_access described_class.new(inbox: telegram_channel.inbox, params: params).perform expect(telegram_channel.inbox.conversations.count).not_to eq(0) @@ -97,12 +93,6 @@ describe Telegram::IncomingMessageService do params = { 'update_id' => 2_342_342_343_242, 'message' => { - 'message_id' => 1, - 'from' => { - 'id' => 23, 'is_bot' => false, 'first_name' => 'Sojan', 'last_name' => 'Jose', 'username' => 'sojan', 'language_code' => 'en' - }, - 'chat' => { 'id' => 23, 'first_name' => 'Sojan', 'last_name' => 'Jose', 'username' => 'sojan', 'type' => 'private' }, - 'date' => 1_631_132_077, 'audio' => { 'file_id' => 'AwADBAADbXXXXXXXXXXXGBdhD2l6_XX', 'duration' => 243, @@ -110,7 +100,7 @@ describe Telegram::IncomingMessageService do 'file_size' => 3_897_500, 'title' => 'Test music file' } - } + }.merge(message_params) }.with_indifferent_access described_class.new(inbox: telegram_channel.inbox, params: params).perform expect(telegram_channel.inbox.conversations.count).not_to eq(0) @@ -125,17 +115,11 @@ describe Telegram::IncomingMessageService do params = { 'update_id' => 2_342_342_343_242, 'message' => { - 'message_id' => 1, - 'from' => { - 'id' => 23, 'is_bot' => false, 'first_name' => 'Sojan', 'last_name' => 'Jose', 'username' => 'sojan', 'language_code' => 'en' - }, - 'chat' => { 'id' => 23, 'first_name' => 'Sojan', 'last_name' => 'Jose', 'username' => 'sojan', 'type' => 'private' }, - 'date' => 1_631_132_077, 'photo' => [{ 'file_id' => 'AgACAgUAAxkBAAODYV3aGZlD6vhzKsE2WNmblsr6zKwAAi-tMRvCoeBWNQ1ENVBzJdwBAAMCAANzAAMhBA', 'file_unique_id' => 'AQADL60xG8Kh4FZ4', 'file_size' => 1883, 'width' => 90, 'height' => 67 }] - } + }.merge(message_params) }.with_indifferent_access described_class.new(inbox: telegram_channel.inbox, params: params).perform expect(telegram_channel.inbox.conversations.count).not_to eq(0) @@ -150,14 +134,9 @@ describe Telegram::IncomingMessageService do params = { 'update_id' => 2_342_342_343_242, 'message' => { - 'message_id' => 1, - 'from' => { - 'id' => 23, 'is_bot' => false, 'first_name' => 'Sojan', 'last_name' => 'Jose', 'username' => 'sojan', 'language_code' => 'en' - }, - 'chat' => { 'id' => 23, 'first_name' => 'Sojan', 'last_name' => 'Jose', 'username' => 'sojan', 'type' => 'private' }, - 'date' => 1_631_132_077, 'sticker' => { - 'emoji' => 'πŸ‘', 'width' => 512, 'height' => 512, 'set_name' => 'a834556273_by_HopSins_1_anim', 'is_animated' => 1, 'thumb' => { + 'emoji' => 'πŸ‘', 'width' => 512, 'height' => 512, 'set_name' => 'a834556273_by_HopSins_1_anim', 'is_animated' => 1, + 'thumb' => { 'file_id' => 'AAMCAQADGQEAA0dhXpKorj9CiRpNX3QOn7YPZ6XS4AAC4wADcVG-MexptyOf8SbfAQAHbQADIQQ', 'file_unique_id' => 'AQAD4wADcVG-MXI', 'file_size' => 4690, 'width' => 128, 'height' => 128 }, @@ -165,7 +144,7 @@ describe Telegram::IncomingMessageService do 'file_unique_id' => 'AgAD4wADcVG-MQ', 'file_size' => 7340 } - } + }.merge(message_params) }.with_indifferent_access described_class.new(inbox: telegram_channel.inbox, params: params).perform expect(telegram_channel.inbox.conversations.count).not_to eq(0) @@ -180,12 +159,6 @@ describe Telegram::IncomingMessageService do params = { 'update_id' => 2_342_342_343_242, 'message' => { - 'message_id' => 1, - 'from' => { - 'id' => 23, 'is_bot' => false, 'first_name' => 'Sojan', 'last_name' => 'Jose', 'username' => 'sojan', 'language_code' => 'en' - }, - 'chat' => { 'id' => 23, 'first_name' => 'Sojan', 'last_name' => 'Jose', 'username' => 'sojan', 'type' => 'private' }, - 'date' => 1_631_132_077, 'video' => { 'duration' => 1, 'width' => 720, 'height' => 1280, 'file_name' => 'IMG_2170.MOV', 'mime_type' => 'video/mp4', 'thumb' => { 'file_id' => 'AAMCBQADGQEAA4ZhXd78Xz6_c6gCzbdIkgGiXJcwwwACqwMAAp3x8Fbhf3EWamgCWAEAB20AAyEE', 'file_unique_id' => 'AQADqwMAAp3x8FZy', @@ -193,7 +166,7 @@ describe Telegram::IncomingMessageService do }, 'file_id' => 'BAACAgUAAxkBAAOGYV3e_F8-v3OoAs23SJIBolyXMMMAAqsDAAKd8fBW4X9xFmpoAlghBA', 'file_unique_id' => 'AgADqwMAAp3x8FY', 'file_size' => 291_286 } - } + }.merge(message_params) }.with_indifferent_access described_class.new(inbox: telegram_channel.inbox, params: params).perform expect(telegram_channel.inbox.conversations.count).not_to eq(0) @@ -208,17 +181,11 @@ describe Telegram::IncomingMessageService do params = { 'update_id' => 2_342_342_343_242, 'message' => { - 'message_id' => 1, - 'from' => { - 'id' => 23, 'is_bot' => false, 'first_name' => 'Sojan', 'last_name' => 'Jose', 'username' => 'sojan', 'language_code' => 'en' - }, - 'chat' => { 'id' => 23, 'first_name' => 'Sojan', 'last_name' => 'Jose', 'username' => 'sojan', 'type' => 'private' }, - 'date' => 1_631_132_077, 'voice' => { 'duration' => 2, 'mime_type' => 'audio/ogg', 'file_id' => 'AwACAgUAAxkBAANjYVwnWF_w8LYTchqVdK9dY7mbwYEAAskDAALCoeBWFvS2u4zS6HAhBA', 'file_unique_id' => 'AgADyQMAAsKh4FY', 'file_size' => 11_833 } - } + }.merge(message_params) }.with_indifferent_access described_class.new(inbox: telegram_channel.inbox, params: params).perform expect(telegram_channel.inbox.conversations.count).not_to eq(0) @@ -233,19 +200,13 @@ describe Telegram::IncomingMessageService do params = { 'update_id' => 2_342_342_343_242, 'message' => { - 'message_id' => 1, - 'from' => { - 'id' => 23, 'is_bot' => false, 'first_name' => 'Sojan', 'last_name' => 'Jose', 'username' => 'sojan', 'language_code' => 'en' - }, - 'chat' => { 'id' => 23, 'first_name' => 'Sojan', 'last_name' => 'Jose', 'username' => 'sojan', 'type' => 'private' }, - 'date' => 1_631_132_077, 'document' => { 'file_id' => 'AwADBAADbXXXXXXXXXXXGBdhD2l6_XX', 'file_name' => 'Screenshot 2021-09-27 at 2.01.14 PM.png', 'mime_type' => 'application/png', 'file_size' => 536_392 } - } + }.merge(message_params) }.with_indifferent_access described_class.new(inbox: telegram_channel.inbox, params: params).perform expect(telegram_channel.inbox.conversations.count).not_to eq(0) diff --git a/spec/services/twilio/oneoff_sms_campaign_service_spec.rb b/spec/services/twilio/oneoff_sms_campaign_service_spec.rb index 46d135222..37338f889 100644 --- a/spec/services/twilio/oneoff_sms_campaign_service_spec.rb +++ b/spec/services/twilio/oneoff_sms_campaign_service_spec.rb @@ -55,7 +55,7 @@ describe Twilio::OneoffSmsCampaignService do ).once sms_campaign_service.perform - expect(campaign.reload.completed?).to eq true + expect(campaign.reload.completed?).to be true end end end diff --git a/spec/services/twilio/send_on_twilio_service_spec.rb b/spec/services/twilio/send_on_twilio_service_spec.rb index d4fc16048..cc0ead00e 100644 --- a/spec/services/twilio/send_on_twilio_service_spec.rb +++ b/spec/services/twilio/send_on_twilio_service_spec.rb @@ -4,8 +4,8 @@ describe Twilio::SendOnTwilioService do subject(:outgoing_message_service) { described_class.new(message: message) } let(:twilio_client) { instance_double(::Twilio::REST::Client) } - let(:messages_double) { instance_double('messages') } - let(:message_record_double) { instance_double('message_record_double') } + let(:messages_double) { double } + let(:message_record_double) { double } let!(:account) { create(:account) } let!(:widget_inbox) { create(:inbox, account: account) } diff --git a/spec/services/twilio/webhook_setup_service_spec.rb b/spec/services/twilio/webhook_setup_service_spec.rb index 4a8b92317..1fb64b4a1 100644 --- a/spec/services/twilio/webhook_setup_service_spec.rb +++ b/spec/services/twilio/webhook_setup_service_spec.rb @@ -40,8 +40,8 @@ describe Twilio::WebhookSetupService do context 'with a phone number' do let(:channel_twilio_sms) { create(:channel_twilio_sms, :with_phone_number) } - let(:phone_double) { instance_double('phone_double') } - let(:phone_record_double) { instance_double('phone_record_double') } + let(:phone_double) { double } + let(:phone_record_double) { double } before do allow(phone_double).to receive(:update) diff --git a/spec/services/whatsapp/incoming_message_service_spec.rb b/spec/services/whatsapp/incoming_message_service_spec.rb index e59dc2a95..22340f1b5 100644 --- a/spec/services/whatsapp/incoming_message_service_spec.rb +++ b/spec/services/whatsapp/incoming_message_service_spec.rb @@ -98,7 +98,7 @@ describe Whatsapp::IncomingMessageService do expect(whatsapp_channel.inbox.conversations.count).not_to eq(0) expect(Contact.all.first.name).to eq('Sojan Jose') expect(whatsapp_channel.inbox.messages.first.content).to eq('Check out my product!') - expect(whatsapp_channel.inbox.messages.first.attachments.present?).to eq true + expect(whatsapp_channel.inbox.messages.first.attachments.present?).to be true 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 cba8176b6..678d03b84 100644 --- a/spec/services/whatsapp/providers/whatsapp_cloud_service_spec.rb +++ b/spec/services/whatsapp/providers/whatsapp_cloud_service_spec.rb @@ -93,7 +93,7 @@ describe Whatsapp::Providers::WhatsappCloudService do it 'updated the message templates' do stub_request(:get, 'https://graph.facebook.com/v14.0/123456789/message_templates?access_token=test_key') .to_return(status: 200, headers: response_headers, body: { data: [{ id: '123456789', name: 'test_template' }] }.to_json) - expect(subject.sync_templates).to eq(true) + expect(subject.sync_templates).to be(true) expect(whatsapp_channel.reload.message_templates).to eq([{ id: '123456789', name: 'test_template' }.stringify_keys]) end end @@ -103,13 +103,13 @@ describe Whatsapp::Providers::WhatsappCloudService do context 'when called' do it 'returns true if valid' do stub_request(:get, 'https://graph.facebook.com/v14.0/123456789/message_templates?access_token=test_key') - expect(subject.validate_provider_config?).to eq(true) - expect(whatsapp_channel.errors.present?).to eq(false) + expect(subject.validate_provider_config?).to be(true) + expect(whatsapp_channel.errors.present?).to be(false) end it 'returns false if invalid' do stub_request(:get, 'https://graph.facebook.com/v14.0/123456789/message_templates?access_token=test_key').to_return(status: 401) - expect(subject.validate_provider_config?).to eq(false) + expect(subject.validate_provider_config?).to be(false) end end end