From a1b286e0134f6962e46a2db1078afeef070e6218 Mon Sep 17 00:00:00 2001 From: Gabriel Majeri Date: Sun, 24 Nov 2024 19:04:28 +0200 Subject: [PATCH] Fix autocorrectable offenses using Rubocop --- app/controllers/commitments_controller.rb | 57 +++++++++++-------- app/controllers/concerns/filtrable.rb | 7 ++- .../expenditure_articles_controller.rb | 15 ++--- app/controllers/expenditures_controller.rb | 25 ++++---- .../financing_sources_controller.rb | 7 +-- app/controllers/payment_types_controller.rb | 11 ++-- .../project_categories_controller.rb | 9 +-- app/controllers/sessions_controller.rb | 2 +- app/controllers/users_controller.rb | 4 +- app/models/concerns/import_matchable.rb | 1 - app/models/setting.rb | 2 +- config/puma.rb | 4 +- db/seeds.rb | 4 +- test/models/user_test.rb | 2 +- 14 files changed, 77 insertions(+), 73 deletions(-) diff --git a/app/controllers/commitments_controller.rb b/app/controllers/commitments_controller.rb index c470e01..738e6ed 100644 --- a/app/controllers/commitments_controller.rb +++ b/app/controllers/commitments_controller.rb @@ -30,17 +30,17 @@ def new @commitment.registration_date = Time.zone.today @commitment.created_by_user = current_user - if params[:source_expenditure_id].present? - @source_expenditure = Expenditure.find(params[:source_expenditure_id]) - - @commitment.financing_sources << @source_expenditure.financing_source - @commitment.expenditure_article = @source_expenditure.expenditure_article - @commitment.procurement_type = @source_expenditure.procurement_type - @commitment.project_details = @source_expenditure.details - @commitment.partner = @source_expenditure.beneficiary - @commitment.value = @source_expenditure.value - @commitment.remarks = @source_expenditure.remarks - end + return unless params[:source_expenditure_id].present? + + @source_expenditure = Expenditure.find(params[:source_expenditure_id]) + + @commitment.financing_sources << @source_expenditure.financing_source + @commitment.expenditure_article = @source_expenditure.expenditure_article + @commitment.procurement_type = @source_expenditure.procurement_type + @commitment.project_details = @source_expenditure.details + @commitment.partner = @source_expenditure.beneficiary + @commitment.value = @source_expenditure.value + @commitment.remarks = @source_expenditure.remarks end def edit @@ -79,13 +79,14 @@ def create user: current_user, action: :insert, target_table: :commitments, - target_object_id: "#{@commitment.registration_number}/#{@commitment.year}", + target_object_id: "#{@commitment.registration_number}/#{@commitment.year}" ) end end if successfully_saved - flash[:notice] = "A fost salvat cu succes angajamentul cu numărul de înregistrare #{@commitment.registration_number}/#{@commitment.year}" + flash[:notice] = + "A fost salvat cu succes angajamentul cu numărul de înregistrare #{@commitment.registration_number}/#{@commitment.year}" redirect_to commitments_path else flash[:alert] = 'Nu s-a putut salva noul angajament. Verificați erorile și încercați din nou.' @@ -105,10 +106,11 @@ def update user: current_user, action: :update, target_table: :commitments, - target_object_id: "#{@commitment.registration_number}/#{@commitment.year}", + target_object_id: "#{@commitment.registration_number}/#{@commitment.year}" ) - flash[:notice] = "A fost modificat cu succes angajamentul cu numărul de înregistrare #{@commitment.registration_number}/#{@commitment.year}" + flash[:notice] = + "A fost modificat cu succes angajamentul cu numărul de înregistrare #{@commitment.registration_number}/#{@commitment.year}" redirect_to commitments_path else flash[:alert] = 'Nu s-au putut salva modificările la angajament. Verificați erorile și încercați din nou.' @@ -215,13 +217,13 @@ def apply_filters if params[:start_date].present? start_date = Date.strptime(params[:start_date], '%d.%m.%Y') - @commitments = @commitments.where('registration_date >= ?', start_date) + @commitments = @commitments.where(registration_date: start_date..) @any_filters_applied = true end if params[:end_date].present? end_date = Date.strptime(params[:end_date], '%d.%m.%Y') - @commitments = @commitments.where('registration_date <= ?', end_date) + @commitments = @commitments.where(registration_date: ..end_date) @any_filters_applied = true end @@ -283,7 +285,10 @@ def parse_commitment(row_index, row) financing_sources_column = row[4]&.strip&.downcase - raise ImportError.new(row_index, 'lipsește reprezentantul UB / sursa de finanțare') if financing_sources_column.blank? + if financing_sources_column.blank? + raise ImportError.new(row_index, + 'lipsește reprezentantul UB / sursa de finanțare') + end financing_sources = [] project_details = '' @@ -315,9 +320,9 @@ def parse_commitment(row_index, row) 'pr cu tva', 'pr nationale', 'pr internationale', 'proiecte internationale', 'proiecte in valuta', 'pr in valuta', /^ctr\./, - /^pfe /, /^pfe\//, /^fcs /, /^fcs\//, - /^fss\//, /^fss /, /^proiecte fss/, - /^cpi\//, + /^pfe /, %r{^pfe/}, /^fcs /, %r{^fcs/}, + %r{^fss/}, /^fss /, /^proiecte fss/, + %r{^cpi/}, /^lifewatch/, /^timss/, /^proiect caipe/, /^pr growing/, /^pr employer/, /^pr ev potential/, /^pr siec/, /^proiect addendum/, @@ -377,7 +382,7 @@ def parse_commitment(row_index, row) when /^trace/ project_details = financing_sources_column.strip financing_sources << FinancingSource.find_by(name: 'Erasmus') - when /^erasmus\// + when %r{^erasmus/} project_details = financing_sources_column.delete_prefix('erasmus').delete_prefix('/') .strip financing_sources << FinancingSource.find_by(name: 'Erasmus') @@ -498,7 +503,7 @@ def parse_commitment(row_index, row) financing_sources << FinancingSource.find_by(name: 'Serviciul Spații de Învățământ') when 'achizitii' financing_sources << FinancingSource.find_by(name: 'Serviciul Achiziții Publice') - when /^achizitii\// + when %r{^achizitii/} project_details = financing_sources_column.strip financing_sources << FinancingSource.find_by(name: 'Serviciul Achiziții Publice') when 'ru' @@ -563,7 +568,8 @@ def parse_commitment(row_index, row) # Remove entries which weren't found financing_sources.filter!(&:present?) if financing_sources.empty? - raise ImportError.new(row_index, "nu a putut fi găsită o sursă de finanțare denumită '#{financing_sources_column}'") + raise ImportError.new(row_index, + "nu a putut fi găsită o sursă de finanțare denumită '#{financing_sources_column}'") end commitment.financing_sources = financing_sources @@ -586,7 +592,8 @@ def parse_commitment(row_index, row) expenditure_article = ExpenditureArticle.find_by(code: expenditure_article_code) if expenditure_article.nil? - raise ImportError.new(row_index, "nu a putut fi găsit un articol de cheltuială cu codul '#{expenditure_article_code}'") + raise ImportError.new(row_index, + "nu a putut fi găsit un articol de cheltuială cu codul '#{expenditure_article_code}'") end commitment.expenditure_article = expenditure_article diff --git a/app/controllers/concerns/filtrable.rb b/app/controllers/concerns/filtrable.rb index ab01a2a..d2b609d 100644 --- a/app/controllers/concerns/filtrable.rb +++ b/app/controllers/concerns/filtrable.rb @@ -41,12 +41,12 @@ def apply_string_field_filter(collection, field_name, param_key = nil) def apply_value_range_filter(collection) if params[:min_value].present? - collection = collection.where('value >= ?', params[:min_value]) + collection = collection.where(value: params[:min_value]..) @any_filters_applied = true end if params[:max_value].present? - collection = collection.where('value <= ?', params[:max_value]) + collection = collection.where(value: ..params[:max_value]) @any_filters_applied = true end @@ -76,7 +76,8 @@ def apply_exclude_cash_receipts_filter(collection) collection = collection.where.not(expenditure_article: receipts_expenditure_article) @any_filters_applied = true else - flash[:alert] = 'Nu s-a putut aplica filtrul deoarece nu este definit articolul de cheltuială cu codul 12, "Încasări"' + flash[:alert] = + 'Nu s-a putut aplica filtrul deoarece nu este definit articolul de cheltuială cu codul 12, "Încasări"' end end end diff --git a/app/controllers/expenditure_articles_controller.rb b/app/controllers/expenditure_articles_controller.rb index ea065d1..a1b9d47 100644 --- a/app/controllers/expenditure_articles_controller.rb +++ b/app/controllers/expenditure_articles_controller.rb @@ -29,7 +29,7 @@ def create user: current_user, action: :insert, target_table: :expenditure_articles, - target_object_id: @expenditure_article.id, + target_object_id: @expenditure_article.id ) end end @@ -59,7 +59,7 @@ def update user: current_user, action: :update, target_table: :expenditure_articles, - target_object_id: @expenditure_article.id, + target_object_id: @expenditure_article.id ) end end @@ -68,7 +68,8 @@ def update flash[:notice] = "A fost actualizat cu succes articolul de cheltuială cu codul #{@expenditure_article.code}" redirect_to expenditure_articles_path else - flash[:alert] = 'Nu s-au putut salva modificările la articolul de cheltuială. Verificați erorile și încercați din nou.' + flash[:alert] = + 'Nu s-au putut salva modificările la articolul de cheltuială. Verificați erorile și încercați din nou.' render :edit, status: :unprocessable_entity end end @@ -87,7 +88,7 @@ def destroy user: current_user, action: :delete, target_table: :expenditure_articles, - target_object_id: @expenditure_article.id, + target_object_id: @expenditure_article.id ) end end @@ -95,7 +96,8 @@ def destroy if successfully_deleted flash[:notice] = "A fost șters cu succes articolul de cheltuială cu codul #{@expenditure_article.code}" else - flash[:alert] = "Nu s-a putut șterge articolul de cheltuială: #{@expenditure_article.errors.full_messages.join(', ')}." + flash[:alert] = + "Nu s-a putut șterge articolul de cheltuială: #{@expenditure_article.errors.full_messages.join(', ')}." end redirect_to expenditure_articles_path @@ -137,10 +139,9 @@ def import_upload flash[:notice] = "S-au importat/actualizat cu succes #{total_count} articole de cheltuială!" redirect_to expenditure_articles_path - rescue ImportError => e flash.now[:alert] = e.to_s - return render :import + render :import end private diff --git a/app/controllers/expenditures_controller.rb b/app/controllers/expenditures_controller.rb index 02ca394..aee33e1 100644 --- a/app/controllers/expenditures_controller.rb +++ b/app/controllers/expenditures_controller.rb @@ -63,18 +63,18 @@ def create user: current_user, action: :insert, target_table: :expenditures, - target_object_id: "#{@expenditure.registration_number}/#{@expenditure.year}", + target_object_id: "#{@expenditure.registration_number}/#{@expenditure.year}" ) end end if successfully_saved - flash[:notice] = t('expenditures.create.success_message', + flash[:notice] = t('.success_message', registration_number: @expenditure.registration_number, year: @expenditure.year) redirect_to expenditures_path else - flash[:alert] = t 'expenditures.create.error_message' + flash[:alert] = t '.error_message' render :new, status: :unprocessable_entity end end @@ -91,15 +91,15 @@ def update user: current_user, action: :update, target_table: :expenditures, - target_object_id: "#{@expenditure.registration_number}/#{@expenditure.year}", + target_object_id: "#{@expenditure.registration_number}/#{@expenditure.year}" ) - flash[:notice] = t('expenditures.update.success_message', + flash[:notice] = t('.success_message', registration_number: @expenditure.registration_number, year: @expenditure.year) redirect_to expenditures_path else - flash[:alert] = t 'expenditures.update.error_message' + flash[:alert] = t '.error_message' render :edit, status: :unprocessable_entity end end @@ -218,13 +218,13 @@ def apply_filters if params[:start_date].present? start_date = Date.strptime(params[:start_date], '%d.%m.%Y') - @expenditures = @expenditures.where('registration_date >= ?', start_date) + @expenditures = @expenditures.where(registration_date: start_date..) @any_filters_applied = true end if params[:end_date].present? end_date = Date.strptime(params[:end_date], '%d.%m.%Y') - @expenditures = @expenditures.where('registration_date <= ?', end_date) + @expenditures = @expenditures.where(registration_date: ..end_date) @any_filters_applied = true end @@ -276,7 +276,6 @@ def apply_filters @expenditures = apply_created_by_user_ids_filter @expenditures @expenditures = apply_updated_by_user_ids_filter @expenditures - end # noinspection SpellCheckingInspection @@ -439,7 +438,8 @@ def parse_expenditure(row_index, row) end if financing_source.nil? - raise ImportError.new(row_index, "nu a putut fi găsită o sursă de finanțare cunoscută asociată cu denumirea '#{financing_source_name}'") + raise ImportError.new(row_index, + "nu a putut fi găsită o sursă de finanțare cunoscută asociată cu denumirea '#{financing_source_name}'") end expenditure_article_code = row[3].to_s.strip @@ -453,7 +453,8 @@ def parse_expenditure(row_index, row) expenditure_article = ExpenditureArticle.find_by(code: expenditure_article_code) if expenditure_article.nil? - raise ImportError.new(row_index, "nu a putut fi găsit un articol de cheltuială cu codul '#{expenditure_article_code}'") + raise ImportError.new(row_index, + "nu a putut fi găsit un articol de cheltuială cu codul '#{expenditure_article_code}'") end expenditure.expenditure_article = expenditure_article @@ -705,8 +706,6 @@ def parse_expenditure(row_index, row) PaymentType.find_by(name: 'Avans numerar') when 'avans virament' PaymentType.find_by(name: 'Avans virament') - else - nil end if payment_type.nil? diff --git a/app/controllers/financing_sources_controller.rb b/app/controllers/financing_sources_controller.rb index ff3fcd7..4ff51e2 100644 --- a/app/controllers/financing_sources_controller.rb +++ b/app/controllers/financing_sources_controller.rb @@ -29,7 +29,7 @@ def create user: current_user, action: :insert, target_table: :financing_sources, - target_object_id: @financing_source.id, + target_object_id: @financing_source.id ) end end @@ -59,7 +59,7 @@ def update user: current_user, action: :update, target_table: :financing_sources, - target_object_id: @financing_source.id, + target_object_id: @financing_source.id ) end end @@ -87,7 +87,7 @@ def destroy user: current_user, action: :delete, target_table: :financing_sources, - target_object_id: @financing_source.id, + target_object_id: @financing_source.id ) end end @@ -132,7 +132,6 @@ def import_upload flash[:notice] = "S-au importat/actualizat cu succes #{total_count} surse de finanțare!" redirect_to financing_sources_path - rescue ImportError => e flash.now[:alert] = e.to_s render :import diff --git a/app/controllers/payment_types_controller.rb b/app/controllers/payment_types_controller.rb index 2071787..bc8dd68 100644 --- a/app/controllers/payment_types_controller.rb +++ b/app/controllers/payment_types_controller.rb @@ -59,7 +59,7 @@ def update user: current_user, action: :update, target_table: :payment_types, - target_object_id: @payment_type.id, + target_object_id: @payment_type.id ) end end @@ -87,7 +87,7 @@ def destroy user: current_user, action: :delete, target_table: :payment_types, - target_object_id: @payment_type.id, + target_object_id: @payment_type.id ) end end @@ -123,9 +123,7 @@ def import_upload payment_type = PaymentType.find_or_initialize_by(name:) - unless payment_type.save - raise ImportError.new(row_index, payment_type.errors.full_messages.join(', ')) - end + raise ImportError.new(row_index, payment_type.errors.full_messages.join(', ')) unless payment_type.save total_count += 1 end @@ -133,10 +131,9 @@ def import_upload flash[:notice] = "S-au importat/actualizat cu succes #{total_count} tipuri de plăți!" redirect_to payment_types_path - rescue ImportError => e flash.now[:alert] = e.to_s - return render :import + render :import end private diff --git a/app/controllers/project_categories_controller.rb b/app/controllers/project_categories_controller.rb index 2e3048c..4149f38 100644 --- a/app/controllers/project_categories_controller.rb +++ b/app/controllers/project_categories_controller.rb @@ -29,7 +29,7 @@ def create user: current_user, action: :insert, target_table: :project_categories, - target_object_id: @project_category.id, + target_object_id: @project_category.id ) end end @@ -59,7 +59,7 @@ def update user: current_user, action: :update, target_table: :project_categories, - target_object_id: @project_category.id, + target_object_id: @project_category.id ) end end @@ -68,7 +68,8 @@ def update flash[:notice] = "A fost actualizată cu succes categoria de proiect cu denumirea '#{@project_category.name}'" redirect_to project_categories_path else - flash[:alert] = 'Nu s-au putut salva modificările la categoria de proiect. Verificați erorile și încercați din nou.' + flash[:alert] = + 'Nu s-au putut salva modificările la categoria de proiect. Verificați erorile și încercați din nou.' render :edit, status: :unprocessable_entity end end @@ -87,7 +88,7 @@ def destroy user: current_user, action: :delete, target_table: :project_categories, - target_object_id: @project_category.id, + target_object_id: @project_category.id ) end end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 9924033..db77627 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -12,7 +12,7 @@ def create if user.nil? flash[:alert] = 'Nu vă puteți conecta deoarece contul dvs. nu are drept de acces în aplicație. ' \ - 'Rugați un administrator să vă adauge contul.' + 'Rugați un administrator să vă adauge contul.' else session[:current_user_id] = user.id session[:current_user_role] = user.role diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 2d412fe..a62e155 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -46,7 +46,7 @@ def create user: current_user, action: :insert, target_table: :users, - target_object_id: @user.id, + target_object_id: @user.id ) end end @@ -82,7 +82,7 @@ def update user: current_user, action: :update, target_table: :users, - target_object_id: @user.id, + target_object_id: @user.id ) end end diff --git a/app/models/concerns/import_matchable.rb b/app/models/concerns/import_matchable.rb index ac93a45..2f655a9 100644 --- a/app/models/concerns/import_matchable.rb +++ b/app/models/concerns/import_matchable.rb @@ -13,4 +13,3 @@ def import_regexp @import_regexp ||= Regexp.new import_code end end - diff --git a/app/models/setting.rb b/app/models/setting.rb index 19b2712..3c386fc 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -5,7 +5,7 @@ class Setting < ApplicationRecord validates :key, uniqueness: true - validates :key, inclusion: { in: %w(current_year) } + validates :key, inclusion: { in: %w[current_year] } def self.current_year find_by!(key: :current_year).value diff --git a/config/puma.rb b/config/puma.rb index 3d4412a..c6fbd82 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -30,8 +30,8 @@ # Bind to TLS if requested to. if ENV['ENABLE_TLS'] ssl_bind '0.0.0.0', 3001, { - cert: ENV['TLS_CERTIFICATE_PATH'], - key: ENV['TLS_KEY_PATH'], + cert: ENV.fetch('TLS_CERTIFICATE_PATH', nil), + key: ENV.fetch('TLS_KEY_PATH', nil), no_tlsv1: true, no_tlsv1_1: true } diff --git a/db/seeds.rb b/db/seeds.rb index 2fbb8b4..48f5088 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -15,7 +15,7 @@ context = MicrosoftKiotaAuthenticationOAuth::ClientCredentialContext.new( identity_platform_credentials[:tenant_id], identity_platform_credentials[:client_id], - identity_platform_credentials[:client_secret], + identity_platform_credentials[:client_secret] ) authentication_provider = MicrosoftGraphCore::Authentication::OAuthAuthenticationProvider.new( @@ -48,7 +48,7 @@ csv_reader_options = { headers: true, - converters: -> (f) { f&.strip } + converters: ->(f) { f&.strip } } puts 'Seeding financing sources...' diff --git a/test/models/user_test.rb b/test/models/user_test.rb index fb6308c..c7b2e29 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -9,7 +9,7 @@ class UserTest < ActiveSupport::TestCase email: 'test.user@example.com', first_name: 'Test', last_name: 'User', - role: :supervisor, + role: :supervisor ) assert user.save