diff --git a/Gemfile b/Gemfile index 7b809cb7f..c8f829f2f 100644 --- a/Gemfile +++ b/Gemfile @@ -42,11 +42,11 @@ group :development do end group :development, :test do - gem 'rubocop', require: false - gem 'rubocop-performance', require: false - gem 'rubocop-rails', require: false - gem 'rubocop-rspec', require: false - gem 'rubocop-thread_safety', require: false + gem 'rubocop', '~> 1.89.0', require: false + gem 'rubocop-performance', '~> 1.26.1', require: false + gem 'rubocop-rails', '~> 2.36.0', require: false + gem 'rubocop-rspec', '~> 3.10.2', require: false + gem 'rubocop-thread_safety', '~> 0.7.3', require: false end # gem 'killbill-assets-ui', github: 'killbill/killbill-assets-ui', ref: 'main' diff --git a/app/controllers/kaui/bundles_controller.rb b/app/controllers/kaui/bundles_controller.rb index 585daafbd..cc990c081 100644 --- a/app/controllers/kaui/bundles_controller.rb +++ b/app/controllers/kaui/bundles_controller.rb @@ -2,7 +2,6 @@ module Kaui class BundlesController < Kaui::EngineController - # rubocop:disable Lint/HashCompareByIdentity def index cached_options_for_klient = options_for_klient @search_query = params[:q].presence @@ -12,27 +11,19 @@ def index fetch_bundle_tags = promise do all_bundle_tags = @account.all_tags(:BUNDLE, false, 'NONE', cached_options_for_klient) - all_bundle_tags.each_with_object({}) do |entry, hsh| - (hsh[entry.object_id] ||= []) << entry - end + all_bundle_tags.group_by(&:object_id) end fetch_subscription_tags = promise do all_subscription_tags = @account.all_tags(:SUBSCRIPTION, false, 'NONE', cached_options_for_klient) - all_subscription_tags.each_with_object({}) do |entry, hsh| - (hsh[entry.object_id] ||= []) << entry - end + all_subscription_tags.group_by(&:object_id) end fetch_bundle_fields = promise do all_bundle_fields = @account.all_custom_fields(:BUNDLE, 'NONE', cached_options_for_klient) - all_bundle_fields.each_with_object({}) do |entry, hsh| - (hsh[entry.object_id] ||= []) << entry - end + all_bundle_fields.group_by(&:object_id) end fetch_subscription_fields = promise do all_subscription_fields = @account.all_custom_fields(:SUBSCRIPTION, 'NONE', cached_options_for_klient) - all_subscription_fields.each_with_object({}) do |entry, hsh| - (hsh[entry.object_id] ||= []) << entry - end + all_subscription_fields.group_by(&:object_id) end fetch_available_tags = promise { Kaui::TagDefinition.all_for_bundle(cached_options_for_klient) } fetch_available_subscription_tags = promise { Kaui::TagDefinition.all_for_subscription(cached_options_for_klient) } @@ -74,7 +65,6 @@ def index end end end - # rubocop:enable Lint/HashCompareByIdentity def transfer @bundle_id = params.require(:id) diff --git a/app/controllers/kaui/custom_fields_controller.rb b/app/controllers/kaui/custom_fields_controller.rb index 01f0ba609..f1c111507 100644 --- a/app/controllers/kaui/custom_fields_controller.rb +++ b/app/controllers/kaui/custom_fields_controller.rb @@ -137,7 +137,7 @@ def _check_object_exist(uuid, object_type) test_uuid = nil msg = nil case param_object_type - when 'INVOICE_ITEM' + when 'INVOICE_ITEM' begin test_uuid = Kaui::Invoice.find_by_invoice_item_id(param_uuid, false, 'NONE', options_for_klient) rescue StandardError @@ -145,7 +145,7 @@ def _check_object_exist(uuid, object_type) ensure msg = { status: '200', message: I18n.t('custom_field_uuid_exist_in_invoice_item_db') } if test_uuid.present? end - when 'ACCOUNT' + when 'ACCOUNT' begin test_uuid = Kaui::Account.find_by_id_or_key(param_uuid, false, false, options_for_klient) rescue StandardError @@ -153,7 +153,7 @@ def _check_object_exist(uuid, object_type) ensure msg = { status: '200', message: I18n.t('custom_field_uuid_exist_in_account_db') } if test_uuid.present? && (test_uuid.account_id == param_uuid) end - when 'BUNDLE' + when 'BUNDLE' begin test_uuid = Kaui::Bundle.find_by_id_or_key(param_uuid, options_for_klient) rescue StandardError @@ -161,7 +161,7 @@ def _check_object_exist(uuid, object_type) ensure msg = { status: '200', message: I18n.t('custom_field_uuid_exist_in_bundle_db') } if test_uuid.present? && (test_uuid.bundle_id == param_uuid) end - when 'SUBSCRIPTION' + when 'SUBSCRIPTION' begin test_uuid = Kaui::Subscription.find_by_id(param_uuid, 'NONE', options_for_klient) rescue StandardError @@ -169,7 +169,7 @@ def _check_object_exist(uuid, object_type) ensure msg = { status: '200', message: I18n.t('custom_field_uuid_exist_in_subscription_db') } if test_uuid.present? && (test_uuid.subscription_id == param_uuid) end - when 'INVOICE' + when 'INVOICE' begin cached_options_for_klient = options_for_klient test_uuid = Kaui::Invoice.find_by_id(param_uuid, false, 'FULL', cached_options_for_klient) @@ -178,7 +178,7 @@ def _check_object_exist(uuid, object_type) ensure msg = { status: '200', message: I18n.t('custom_field_uuid_exist_in_invoice_db') } if test_uuid.present? && (test_uuid.invoice_id == param_uuid) end - when 'PAYMENT' + when 'PAYMENT' begin test_uuid = Kaui::InvoicePayment.find_by_id(param_uuid, false, true, options_for_klient) rescue StandardError diff --git a/app/controllers/kaui/engine_controller.rb b/app/controllers/kaui/engine_controller.rb index 01e2fccee..70c4b5b09 100644 --- a/app/controllers/kaui/engine_controller.rb +++ b/app/controllers/kaui/engine_controller.rb @@ -7,7 +7,7 @@ class Kaui::EngineController < ApplicationController before_action :authenticate_user!, :check_for_redirect_to_tenant_screen, :populate_account_details - layout :get_layout + layout :current_layout # Common options for the Kill Bill client def options_for_klient(options = {}) diff --git a/app/controllers/kaui/engine_controller_util.rb b/app/controllers/kaui/engine_controller_util.rb index 17d51c54d..81cda83e1 100644 --- a/app/controllers/kaui/engine_controller_util.rb +++ b/app/controllers/kaui/engine_controller_util.rb @@ -8,11 +8,9 @@ module EngineControllerUtil protected - # rubocop:disable Lint/UselessAssignment, Naming/AccessorMethodName - def get_layout - layout ||= Kaui.config[:layout] + def current_layout + Kaui.config[:layout] end - # rubocop:enable Lint/UselessAssignment, Naming/AccessorMethodName # Remove this when we support balance search alongside the other search def handle_balance_search(query_string) diff --git a/app/controllers/kaui/invoices_controller.rb b/app/controllers/kaui/invoices_controller.rb index 6503b3897..5fa418524 100644 --- a/app/controllers/kaui/invoices_controller.rb +++ b/app/controllers/kaui/invoices_controller.rb @@ -84,7 +84,6 @@ def pagination paginate searcher, data_extractor, formatter end - # rubocop:disable Lint/HashCompareByIdentity def show # Go to the database once cached_options_for_klient = options_for_klient @@ -116,24 +115,18 @@ def show fetch_invoice_fields = promise { @invoice.custom_fields('NONE', cached_options_for_klient).sort { |cf_a, cf_b| cf_a.name.downcase <=> cf_b.name.downcase } } fetch_payment_fields = promise do all_payment_fields = @account.all_custom_fields(:PAYMENT, 'NONE', cached_options_for_klient) - all_payment_fields.each_with_object({}) do |entry, hsh| - (hsh[entry.object_id] ||= []) << entry - end + all_payment_fields.group_by(&:object_id) end fetch_available_invoice_item_tags = promise { Kaui::TagDefinition.all_for_invoice_item(cached_options_for_klient) } fetch_tags_per_invoice_item = promise do tags_per_invoice_item = @account.all_tags(:INVOICE_ITEM, false, 'NONE', cached_options_for_klient) - tags_per_invoice_item.each_with_object({}) do |entry, hsh| - (hsh[entry.object_id] ||= []) << entry - end + tags_per_invoice_item.group_by(&:object_id) end fetch_custom_fields_per_invoice_item = promise do custom_fields_per_invoice_item = @account.all_custom_fields(:INVOICE_ITEM, 'NONE', cached_options_for_klient) - custom_fields_per_invoice_item.each_with_object({}) do |entry, hsh| - (hsh[entry.object_id] ||= []) << entry - end + custom_fields_per_invoice_item.group_by(&:object_id) end fetch_invoice_tags = promise { @invoice.tags(false, 'NONE', cached_options_for_klient).sort } @@ -150,7 +143,6 @@ def show @available_invoice_tags = wait(fetch_available_invoice_tags) @available_invoice_tags.reject! { |td| td.name == 'WRITTEN_OFF' } if @invoice.status == 'VOID' end - # rubocop:enable Lint/HashCompareByIdentity def void_invoice cached_options_for_klient = options_for_klient @@ -175,9 +167,7 @@ def restful_show_by_number end def show_html - # rubocop:disable Rails/OutputSafety -- Invoice HTML from Kill Bill backend is trusted - render html: Kaui::Invoice.as_html(params.require(:id), options_for_klient).html_safe - # rubocop:enable Rails/OutputSafety + render html: Kaui::Invoice.as_html(params.require(:id), options_for_klient).html_safe # rubocop:disable Rails/OutputSafety -- Invoice HTML from Kill Bill backend is trusted end def commit_invoice diff --git a/app/controllers/kaui/queues_controller.rb b/app/controllers/kaui/queues_controller.rb index c7b110715..1db5ddb3f 100644 --- a/app/controllers/kaui/queues_controller.rb +++ b/app/controllers/kaui/queues_controller.rb @@ -2,7 +2,6 @@ module Kaui class QueuesController < Kaui::EngineController - # rubocop:disable Lint/SuppressedException,Lint/EnsureReturn def index @account_id = params[:account_id] @@ -10,11 +9,11 @@ def index begin max_date_test = Time.parse(params[:max_date]).iso8601 rescue StandardError - ensure - if max_date_test.nil? - flash[:error] = I18n.t('errors.messages.invalid_max_date') - redirect_to account_queues_path(@account.account_id) and return - end + max_date_test = nil + end + if max_date_test.nil? + flash[:error] = I18n.t('errors.messages.invalid_max_date') + redirect_to account_queues_path(@account.account_id) and return end end @@ -22,11 +21,11 @@ def index begin min_date_test = Time.parse(params[:min_date]).iso8601 rescue StandardError - ensure - if min_date_test.nil? - flash[:error] = I18n.t('errors.messages.invalid_min_date') - redirect_to account_queues_path(@account.account_id) and return - end + min_date_test = nil + end + if min_date_test.nil? + flash[:error] = I18n.t('errors.messages.invalid_min_date') + redirect_to account_queues_path(@account.account_id) and return end end @@ -47,6 +46,5 @@ def index params.permit! end - # rubocop:enable Lint/SuppressedException,Lint/EnsureReturn end end diff --git a/app/controllers/kaui/refunds_controller.rb b/app/controllers/kaui/refunds_controller.rb index 3b324bb94..820927f21 100644 --- a/app/controllers/kaui/refunds_controller.rb +++ b/app/controllers/kaui/refunds_controller.rb @@ -17,7 +17,6 @@ def new @refund = KillBillClient::Model::InvoiceItem.new(invoice_id: @invoice.invoice_id) end - # rubocop:disable Lint/FloatComparison def create invoice = Kaui::Invoice.find_by_id(params.require(:invoice_id), false, 'NONE', options_for_klient) @@ -29,9 +28,7 @@ def create item = KillBillClient::Model::InvoiceItem.new item.invoice_item_id = ii[0] item.description = params.dig(:descriptions, ii[0]) - # If we tried to do a partial item adjustment, we pass the value, if not we don't send any value and let the system - # decide what is the maximum amount we can have on that item - item.amount = ii[1].to_f == original_item.amount ? nil : ii[1] + item.amount = ii[1].to_d == original_item.amount.to_d ? nil : ii[1] items << item end @@ -40,7 +37,6 @@ def create KillBillClient::Model::InvoicePayment.refund(params.require(:payment_id), params[:amount], items, current_user.kb_username, params[:reason], params[:comment], options_for_klient) redirect_to kaui_engine.account_invoice_path(invoice.account_id, invoice.invoice_id), notice: 'Refund created' end - # rubocop:enable Lint/FloatComparison private diff --git a/app/models/kaui/refund.rb b/app/models/kaui/refund.rb index 24bc035e0..a2986f896 100644 --- a/app/models/kaui/refund.rb +++ b/app/models/kaui/refund.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true module Kaui - # rubocop:disable Lint/EmptyClass - class Refund + class Refund # rubocop:disable Lint/EmptyClass end - # rubocop:enable Lint/EmptyClass end diff --git a/test/functional/kaui/admin_allowed_users_controller_test.rb b/test/functional/kaui/admin_allowed_users_controller_test.rb index 395ac2f6e..5b570e7e7 100644 --- a/test/functional/kaui/admin_allowed_users_controller_test.rb +++ b/test/functional/kaui/admin_allowed_users_controller_test.rb @@ -140,7 +140,6 @@ class AdminAllowedUsersControllerTest < Kaui::FunctionalTestHelper assert response_path.include?('/kaui/home'), "#{response_path} is expected to contain '/kaui/home'" end - # rubocop:disable Naming/VariableNumber test 'should add tenant' do allowed_user = { kb_username: SecureRandom.uuid.to_s, description: SecureRandom.uuid.to_s } @@ -151,13 +150,12 @@ class AdminAllowedUsersControllerTest < Kaui::FunctionalTestHelper allowed_user[:id] = au.id - put :add_tenant, params: { allowed_user:, tenant_1: nil } + put :add_tenant, params: { allowed_user:, tenant_1: nil } # rubocop:disable Naming/VariableNumber assert_equal 'Successfully set tenants for user', flash[:notice] assert_response :redirect # validate redirect path assert response_path.include?(expected_response_path(au.id)), "#{response_path} is expected to contain #{expected_response_path(au.id)}" end - # rubocop:enable Naming/VariableNumber test 'should detect if a user is managed externally' do allowed_user = { kb_username: SecureRandom.uuid.to_s, description: SecureRandom.uuid.to_s } diff --git a/test/killbill_test_helper.rb b/test/killbill_test_helper.rb index 4088e0eba..7583a66db 100644 --- a/test/killbill_test_helper.rb +++ b/test/killbill_test_helper.rb @@ -131,18 +131,15 @@ def create_bundle(account = nil, tenant = nil, username = USERNAME, password = P end # Return a new test payment method - # rubocop:disable Style/OptionalBooleanParameter - def create_payment_method(set_default = false, account = nil, tenant = nil, username = USERNAME, password = PASSWORD, user = 'Kaui test', reason = nil, comment = nil) + def create_payment_method(set_default = false, account = nil, tenant = nil, username = USERNAME, password = PASSWORD, user = 'Kaui test', reason = nil, comment = nil) # rubocop:disable Style/OptionalBooleanParameter account = create_account(tenant, username, password, user, reason, comment) if account.nil? payment_method = Kaui::PaymentMethod.new(account_id: account.account_id, plugin_name: '__EXTERNAL_PAYMENT__', is_default: set_default) payment_method.create(true, user, reason, comment, build_options(tenant, username, password)) end - # rubocop:enable Style/OptionalBooleanParameter # Return the created external charge - # rubocop:disable Style/OptionalBooleanParameter - def create_charge(account = nil, tenant = nil, auto_commit = false, username = USERNAME, password = PASSWORD, user = 'Kaui test', reason = nil, comment = nil) + def create_charge(account = nil, tenant = nil, auto_commit = false, username = USERNAME, password = PASSWORD, user = 'Kaui test', reason = nil, comment = nil) # rubocop:disable Style/OptionalBooleanParameter tenant = create_tenant(user, reason, comment) if tenant.nil? account = create_account(tenant, username, password, user, reason, comment) if account.nil? @@ -155,11 +152,9 @@ def create_charge(account = nil, tenant = nil, auto_commit = false, username = U rescue StandardError nil end - # rubocop:enable Style/OptionalBooleanParameter # Return the created credit - # rubocop:disable Style/OptionalBooleanParameter - def create_cba(invoice_id = nil, account = nil, tenant = nil, _auto_commit = false, username = USERNAME, password = PASSWORD, user = 'Kaui test', reason = nil, comment = nil) + def create_cba(invoice_id = nil, account = nil, tenant = nil, _auto_commit = false, username = USERNAME, password = PASSWORD, user = 'Kaui test', reason = nil, comment = nil) # rubocop:disable Style/OptionalBooleanParameter tenant = create_tenant(user, reason, comment) if tenant.nil? account = create_account(tenant, username, password, user, reason, comment) if account.nil? @@ -169,7 +164,6 @@ def create_cba(invoice_id = nil, account = nil, tenant = nil, _auto_commit = fal invoice = KillBillClient::Model::Invoice.find_by_id(credit.invoice_id, false, 'NONE', build_options(tenant, username, password)) invoice.items.find { |ii| ii.amount == -credit.amount } end - # rubocop:enable Style/OptionalBooleanParameter def commit_invoice(invoice_id, tenant, username = USERNAME, password = PASSWORD, user = 'Kaui test', reason = nil, comment = nil) invoice = KillBillClient::Model::Invoice.find_by_id(invoice_id, false, 'NONE', build_options(tenant, username, password)) diff --git a/test/unit/kaui/account_email_test.rb b/test/unit/kaui/account_email_test.rb index 83682fd1a..9daec82bb 100644 --- a/test/unit/kaui/account_email_test.rb +++ b/test/unit/kaui/account_email_test.rb @@ -4,7 +4,6 @@ module Kaui class AccountEmailTest < ActiveSupport::TestCase - # rubocop:disable Lint/BinaryOperatorWithIdenticalOperands test 'can compare emails' do email1 = Kaui::AccountEmail.new(account_id: SecureRandom.uuid, email: 'abc@bar.com') email2 = Kaui::AccountEmail.new(account_id: SecureRandom.uuid, email: 'bcd@bar.com') @@ -12,13 +11,12 @@ class AccountEmailTest < ActiveSupport::TestCase assert_equal(-1, email1 <=> email2) assert_equal 1, email2 <=> email1 - assert_equal 0, email1 <=> email1 - assert_equal 0, email2 <=> email2 - assert_equal 0, email3 <=> email3 + assert_equal 0, email1 <=> email1.dup + assert_equal 0, email2 <=> email2.dup + assert_equal 0, email3 <=> email3.dup assert_equal 1, email1 <=> email3 assert_equal(-1, email3 <=> email1) assert_equal(-1, email1 <=> nil) end - # rubocop:enable Lint/BinaryOperatorWithIdenticalOperands end end