From 19d5786cf4c9bea2ec459fccf4918553d523c3e8 Mon Sep 17 00:00:00 2001 From: Sojan Date: Thu, 6 Mar 2025 20:35:01 -0800 Subject: [PATCH] chore: fixes --- .rubocop.yml | 47 ++++++++++++++++++- Gemfile | 3 +- Gemfile.lock | 4 ++ app/models/account.rb | 4 +- app/models/email_template.rb | 4 +- app/models/user.rb | 10 ++-- ...0230515051424_update_article_image_keys.rb | 7 ++- 7 files changed, 66 insertions(+), 13 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index d69304dec..8cb06f810 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -7,51 +7,69 @@ plugins: require: - ./rubocop/use_from_email.rb - ./rubocop/custom_cop_location.rb + - rubocop-rspec_rails + Layout/LineLength: Max: 150 + Metrics/ClassLength: Max: 175 Exclude: - 'app/models/message.rb' - 'app/models/conversation.rb' + Metrics/MethodLength: Max: 19 + RSpec/ExampleLength: Max: 25 + Style/Documentation: Enabled: false + Style/ExponentialNotation: Enabled: false + Style/FrozenStringLiteralComment: Enabled: false + Style/SymbolArray: Enabled: false + Style/OpenStructUse: Enabled: false + Style/OptionalBooleanParameter: Exclude: - 'app/services/email_templates/db_resolver_service.rb' - 'app/dispatchers/dispatcher.rb' + Style/GlobalVars: Exclude: - 'config/initializers/01_redis.rb' - 'config/initializers/rack_attack.rb' - 'lib/redis/alfred.rb' - 'lib/global_config.rb' + Style/ClassVars: Exclude: - 'app/services/email_templates/db_resolver_service.rb' + Lint/MissingSuper: Exclude: - 'app/drops/base_drop.rb' + Lint/SymbolConversion: Enabled: false + Lint/EmptyBlock: Exclude: - 'app/views/api/v1/accounts/conversations/toggle_status.json.jbuilder' + Lint/OrAssignmentToConstant: Exclude: - 'lib/redis/config.rb' + Metrics/BlockLength: Max: 30 Exclude: @@ -59,10 +77,12 @@ Metrics/BlockLength: - '**/routes.rb' - 'config/environments/*' - db/schema.rb + Metrics/ModuleLength: Exclude: - lib/seeders/message_seeder.rb - spec/support/slack_stubs.rb + Rails/ApplicationController: Exclude: - 'app/controllers/api/v1/widget/messages_controller.rb' @@ -72,51 +92,66 @@ Rails/ApplicationController: - 'app/controllers/platform_controller.rb' - 'app/controllers/public_controller.rb' - 'app/controllers/survey/responses_controller.rb' + Rails/FindEach: Enabled: true Include: - 'app/**/*.rb' + Rails/CompactBlank: Enabled: false + Rails/EnvironmentVariableAccess: Enabled: false + Rails/TimeZoneAssignment: Enabled: false + Rails/RedundantPresenceValidationOnBelongsTo: Enabled: false + Style/ClassAndModuleChildren: EnforcedStyle: compact Exclude: - 'config/application.rb' - 'config/initializers/monkey_patches/*' + Style/MapToHash: Enabled: false + Style/HashSyntax: Enabled: true EnforcedStyle: no_mixed_keys EnforcedShorthandSyntax: never + RSpec/NestedGroups: Enabled: true Max: 4 + RSpec/MessageSpies: Enabled: false + RSpec/StubbedMock: Enabled: false - Enabled: false + Naming/VariableNumber: Enabled: false + Naming/MemoizedInstanceVariableName: Exclude: - 'app/models/message.rb' + Style/GuardClause: Exclude: - 'app/builders/account_builder.rb' - 'app/models/attachment.rb' - 'app/models/message.rb' + Metrics/AbcSize: Max: 26 Exclude: - 'app/controllers/concerns/auth_helper.rb' + Rails/UniqueValidationWithoutIndex: Exclude: - 'app/models/channel/twitter_profile.rb' @@ -125,29 +160,38 @@ Rails/UniqueValidationWithoutIndex: - 'app/models/integrations/hook.rb' - 'app/models/canned_response.rb' - 'app/models/telegram_bot.rb' + Rails/RenderInline: Exclude: - 'app/controllers/swagger_controller.rb' + Rails/ThreeStateBooleanColumn: Exclude: - 'db/migrate/20230503101201_create_sla_policies.rb' + RSpec/IndexedLet: Enabled: false + RSpec/NamedSubject: Enabled: false + # we should bring this down RSpec/MultipleExpectations: Max: 7 + RSpec/MultipleMemoizedHelpers: Max: 14 + # custom rules UseFromEmail: Enabled: true Exclude: - 'app/models/user.rb' - 'app/models/contact.rb' + CustomCopLocation: Enabled: true + AllCops: NewCops: enable Exclude: @@ -162,5 +206,6 @@ AllCops: - 'tmp/**/*' - 'storage/**/*' - 'db/migrate/20230426130150_init_schema.rb' + FactoryBot/SyntaxMethods: Enabled: false diff --git a/Gemfile b/Gemfile index e7a164559..59bcc150a 100644 --- a/Gemfile +++ b/Gemfile @@ -234,10 +234,11 @@ group :development, :test do gem 'rubocop-performance', require: false gem 'rubocop-rails', require: false gem 'rubocop-rspec', require: false + gem 'rubocop-rspec_rails', require: false gem 'rubocop-factory_bot', require: false gem 'seed_dump' gem 'shoulda-matchers' gem 'simplecov', '0.17.1', require: false gem 'spring' gem 'spring-watcher-listen' -end +end \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index 6d165b56e..66b7665f9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -745,6 +745,9 @@ GEM rubocop-rspec (3.5.0) lint_roller (~> 1.1) rubocop (~> 1.72, >= 1.72.1) + rubocop-rspec_rails (2.30.0) + rubocop (~> 1.61) + rubocop-rspec (~> 3, >= 3.0.1) ruby-openai (7.4.0) event_stream_parser (>= 0.3.0, < 2.0.0) faraday (>= 1) @@ -1017,6 +1020,7 @@ DEPENDENCIES rubocop-performance rubocop-rails rubocop-rspec + rubocop-rspec_rails ruby-openai scout_apm scss_lint diff --git a/app/models/account.rb b/app/models/account.rb index a35affb3e..a5412e34e 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -80,8 +80,8 @@ class Account < ApplicationRecord has_one_attached :contacts_export - enum locale: LANGUAGES_CONFIG.map { |key, val| [val[:iso_639_1_code], key] }.to_h - enum status: { active: 0, suspended: 1 } + enum :locale, LANGUAGES_CONFIG.map { |key, val| [val[:iso_639_1_code], key] }.to_h, prefix: true + enum :status, { active: 0, suspended: 1 } before_validation :validate_limit_keys after_create_commit :notify_creation diff --git a/app/models/email_template.rb b/app/models/email_template.rb index 5891626a4..57db7a94c 100644 --- a/app/models/email_template.rb +++ b/app/models/email_template.rb @@ -16,8 +16,8 @@ # index_email_templates_on_name_and_account_id (name,account_id) UNIQUE # class EmailTemplate < ApplicationRecord - enum locale: LANGUAGES_CONFIG.map { |key, val| [val[:iso_639_1_code], key] }.to_h - enum template_type: { layout: 0, content: 1 } + enum :locale, LANGUAGES_CONFIG.map { |key, val| [val[:iso_639_1_code], key] }.to_h, prefix: true + enum :template_type, { layout: 0, content: 1 } belongs_to :account, optional: true validates :name, uniqueness: { scope: :account } diff --git a/app/models/user.rb b/app/models/user.rb index faadb3271..006444663 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -62,7 +62,7 @@ class User < ApplicationRecord # TODO: remove in a future version once online status is moved to account users # remove the column availability from users - enum availability: { online: 0, offline: 1, busy: 2 } + enum :availability, { online: 0, offline: 1, busy: 2 } # The validation below has been commented out as it does not # work because :validatable in devise overrides this. @@ -75,7 +75,7 @@ class User < ApplicationRecord accepts_nested_attributes_for :account_users has_many :assigned_conversations, foreign_key: 'assignee_id', class_name: 'Conversation', dependent: :nullify, inverse_of: :assignee - alias_attribute :conversations, :assigned_conversations + alias conversations assigned_conversations has_many :csat_survey_responses, foreign_key: 'assigned_agent_id', dependent: :nullify, inverse_of: :assigned_agent has_many :conversation_participants, dependent: :destroy_async has_many :participating_conversations, through: :conversation_participants, source: :conversation @@ -113,8 +113,8 @@ class User < ApplicationRecord self.email = email.try(:downcase) end - def send_devise_notification(notification, *args) - devise_mailer.with(account: Current.account).send(notification, self, *args).deliver_later + def send_devise_notification(notification, *) + devise_mailer.with(account: Current.account).send(notification, self, *).deliver_later end def set_password_and_uid @@ -126,7 +126,7 @@ class User < ApplicationRecord end def serializable_hash(options = nil) - super(options).merge(confirmed: confirmed?) + super.merge(confirmed: confirmed?) end def push_event_data diff --git a/db/migrate/20230515051424_update_article_image_keys.rb b/db/migrate/20230515051424_update_article_image_keys.rb index db208470f..572c00ce5 100644 --- a/db/migrate/20230515051424_update_article_image_keys.rb +++ b/db/migrate/20230515051424_update_article_image_keys.rb @@ -12,8 +12,11 @@ class ArticleKeyConverter def convert_key(id) verifier_name = 'ActiveStorage' - key_generator = ActiveSupport::KeyGenerator.new(Rails.application.secrets.secret_key_base, iterations: 1000, - hash_digest_class: OpenSSL::Digest::SHA1) + secret_key_base = Rails.application.credentials.secret_key_base || + Rails.application.secrets.secret_key_base + key_generator = ActiveSupport::KeyGenerator.new(secret_key_base, + iterations: 1000, + hash_digest_class: OpenSSL::Digest::SHA1) key_generator = ActiveSupport::CachingKeyGenerator.new(key_generator) secret = key_generator.generate_key(verifier_name.to_s) verifier = ActiveSupport::MessageVerifier.new(secret)