diff --git a/Gemfile b/Gemfile index f79855eaa6..497480d7d3 100644 --- a/Gemfile +++ b/Gemfile @@ -113,7 +113,7 @@ group :development do gem "haml_lint", require: false gem "letter_opener" gem "rack-mini-profiler", "~> 4.0" - gem "rubocop", "1.84.1", require: false + gem "rubocop", "1.85.1", require: false gem "rubocop-performance" gem "rubocop-rails" gem "rubocop-rspec" diff --git a/Gemfile.lock b/Gemfile.lock index 450102c34b..db1a31978a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -385,6 +385,9 @@ GEM jsbundling-rails (1.3.1) railties (>= 6.0.0) json (2.18.1) + json-schema (6.1.0) + addressable (~> 2.8) + bigdecimal (>= 3.1, < 5) jwt (3.1.2) base64 kgio (2.11.4) @@ -420,6 +423,8 @@ GEM zeitwerk marcel (1.0.4) matrix (0.4.3) + mcp (0.8.0) + json-schema (>= 4.1) method_source (1.1.0) mime-types (3.7.0) logger @@ -607,10 +612,11 @@ GEM rspec-support (3.13.6) rspec_junit_formatter (0.6.0) rspec-core (>= 2, < 4, != 2.12.0) - rubocop (1.84.1) + rubocop (1.85.1) json (~> 2.3) language_server-protocol (~> 3.17.0.2) lint_roller (~> 1.1.0) + mcp (~> 0.6) parallel (~> 1.10) parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) @@ -831,7 +837,7 @@ DEPENDENCIES rspec-collection_matchers rspec-rails rspec_junit_formatter - rubocop (= 1.84.1) + rubocop (= 1.85.1) rubocop-performance rubocop-rails rubocop-rspec diff --git a/app/lib/nucore.rb b/app/lib/nucore.rb index cef590937a..b47167d225 100644 --- a/app/lib/nucore.rb +++ b/app/lib/nucore.rb @@ -19,4 +19,7 @@ class NotPermittedWhileActingAs < NUCore::Error class PurchaseException < NUCore::Error; end + class OrderDetailUpdateException < NUCore::Error + end + end diff --git a/app/models/email_event.rb b/app/models/email_event.rb index 107ceec1ed..3e8a4fd991 100644 --- a/app/models/email_event.rb +++ b/app/models/email_event.rb @@ -29,7 +29,7 @@ def self.notify(user, keys, wait: 24.hours) end def self.key_for(keys) - Array(keys).map(&:to_s).join("/") + Array(keys).join("/") end end diff --git a/app/models/product_display_group.rb b/app/models/product_display_group.rb index f7bfb3c4e0..5200bb080f 100644 --- a/app/models/product_display_group.rb +++ b/app/models/product_display_group.rb @@ -14,7 +14,7 @@ def to_s name end - Fake = Struct.new(:name, :products, keyword_init: true) do + Fake = Struct.new(:name, :products) do def to_s name end diff --git a/app/services/order_detail_updater.rb b/app/services/order_detail_updater.rb index 481970cc7a..f81b6fe167 100644 --- a/app/services/order_detail_updater.rb +++ b/app/services/order_detail_updater.rb @@ -1,12 +1,5 @@ # frozen_string_literal: true -module NUCore - - class OrderDetailUpdateException < StandardError - end - -end - class OrderDetailUpdater attr_reader :order, :params, :quantities_changed diff --git a/app/services/order_row_importer.rb b/app/services/order_row_importer.rb index 752643cb68..03fe81ecb4 100644 --- a/app/services/order_row_importer.rb +++ b/app/services/order_row_importer.rb @@ -102,7 +102,7 @@ def order_key def row_with_errors # Start with a hash of HEADERS keys with nil values to ensure optional columns # are included in the report even if they are not in the uploaded CSV. - new_row = HEADERS.each_with_object({}) { |header, hash| hash[header] = nil } + new_row = HEADERS.to_h { |header| [header, nil] } new_row.merge!(@row) new_row[header(:errors)] = errors.join(", ") diff --git a/app/services/projects_search/searcher.rb b/app/services/projects_search/searcher.rb index 17eff9cabd..0147cec944 100644 --- a/app/services/projects_search/searcher.rb +++ b/app/services/projects_search/searcher.rb @@ -61,8 +61,8 @@ def options end def to_options_by_searcher - @to_h ||= options.each_with_object({}) do |searcher, hash| - hash[searcher.key] = searcher.options + @to_h ||= options.to_h do |searcher| + [searcher.key, searcher.options] end end diff --git a/app/services/research_safety_certification_lookup.rb b/app/services/research_safety_certification_lookup.rb index ee33c321f5..aa8e1b6a3e 100644 --- a/app/services/research_safety_certification_lookup.rb +++ b/app/services/research_safety_certification_lookup.rb @@ -34,8 +34,8 @@ def missing_from(certificates) end def certificates_with_status - ResearchSafetyCertificate.ordered.each_with_object({}) do |certificate, hash| - hash[certificate] = adapter.certified?(certificate) + ResearchSafetyCertificate.ordered.to_h do |certificate| + [certificate, adapter.certified?(certificate)] end end diff --git a/app/services/transaction_search/searcher.rb b/app/services/transaction_search/searcher.rb index 5da2c95c76..cfcbe0a19a 100644 --- a/app/services/transaction_search/searcher.rb +++ b/app/services/transaction_search/searcher.rb @@ -114,8 +114,8 @@ def options end def to_options_by_searcher - @to_h ||= options.each_with_object({}) do |searcher, hash| - hash[searcher.key] = searcher.options + @to_h ||= options.to_h do |searcher| + [searcher.key, searcher.options] end end diff --git a/db/migrate/20231212185627_update_duration_rate_rate_for_internal_price_groups.rb b/db/migrate/20231212185627_update_duration_rate_rate_for_internal_price_groups.rb index 0b4e7e5640..c796faaffd 100644 --- a/db/migrate/20231212185627_update_duration_rate_rate_for_internal_price_groups.rb +++ b/db/migrate/20231212185627_update_duration_rate_rate_for_internal_price_groups.rb @@ -1,8 +1,7 @@ # frozen_string_literal: true -class DurationRate < ApplicationRecord; end - class UpdateDurationRateRateForInternalPriceGroups < ActiveRecord::Migration[7.0] + class DurationRate < ApplicationRecord; end def up DurationRate.all.each(&:set_rate_from_base) diff --git a/db/migrate/20240410203410_update_cross_core_ordering_available_in_products.rb b/db/migrate/20240410203410_update_cross_core_ordering_available_in_products.rb index 473e336963..11c4f57bf1 100644 --- a/db/migrate/20240410203410_update_cross_core_ordering_available_in_products.rb +++ b/db/migrate/20240410203410_update_cross_core_ordering_available_in_products.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true -class Product < ApplicationRecord; end - class UpdateCrossCoreOrderingAvailableInProducts < ActiveRecord::Migration[7.0] + class Product < ApplicationRecord; end + def up change_column :products, :cross_core_ordering_available, :boolean, default: false, null: false diff --git a/lib/tasks/order_details.rake b/lib/tasks/order_details.rake index 85dca8fb55..e0d64ca148 100644 --- a/lib/tasks/order_details.rake +++ b/lib/tasks/order_details.rake @@ -56,12 +56,14 @@ namespace :order_details do task :uncancel, [:filename] => :environment do |_t, args| Rails.logger = Logger.new(STDOUT) uncanceler = OrderUncanceler.new - File.open(args[:filename]).each_line do |line| - order_detail = OrderDetail.find_by(id: line.chomp) - if order_detail - uncanceler.uncancel_to_complete(order_detail) - else - puts "Could not find order detail #{line}" + File.open(args[:filename]) do |file| + file.each_line do |line| + order_detail = OrderDetail.find_by(id: line.chomp) + if order_detail + uncanceler.uncancel_to_complete(order_detail) + else + puts "Could not find order detail #{line}" + end end end end @@ -122,10 +124,12 @@ namespace :order_details do def self.remove_orders(file) OrderDetail.transaction do - File.open(file, "r").each_line do |line| - next unless /([0-9]+)-([0-9]+)/ =~ line + File.open(file, "r") do |file| + file.each_line do |line| + next unless /([0-9]+)-([0-9]+)/ =~ line - remove_order(OrderDetail.find(Regexp.last_match(2))) + remove_order(OrderDetail.find(Regexp.last_match(2))) + end end end puts "Done" diff --git a/spec/app_support/reservations/date_support_spec.rb b/spec/app_support/reservations/date_support_spec.rb index 57f38e0ba4..2af42717e4 100644 --- a/spec/app_support/reservations/date_support_spec.rb +++ b/spec/app_support/reservations/date_support_spec.rb @@ -78,13 +78,13 @@ ["2015-01-01T01:00:59", 60], ] .each do |timestring, expected_minutes| - context "and the actual_end_at is #{timestring}" do - let(:actual_end_at) { Time.zone.parse(timestring) } + context "and the actual_end_at is #{timestring}" do + let(:actual_end_at) { Time.zone.parse(timestring) } - it "returns #{expected_minutes}" do - expect(reservation.actual_duration_mins).to eq(expected_minutes) - end + it "returns #{expected_minutes}" do + expect(reservation.actual_duration_mins).to eq(expected_minutes) end + end end context "and actual_end_at is unset" do @@ -97,11 +97,11 @@ ["2015-01-01T01:00:59", 60], ] .each do |timestring, expected_minutes| - context "and the base_time is #{timestring}" do - it "returns #{expected_minutes}" do - expect(reservation.actual_duration_mins).to be_blank - end + context "and the base_time is #{timestring}" do + it "returns #{expected_minutes}" do + expect(reservation.actual_duration_mins).to be_blank end + end end end end @@ -211,13 +211,13 @@ ["2015-01-01T01:00:59", 60], ] .each do |timestring, expected_minutes| - context "and reserve_end_at is #{timestring}" do - let(:reserve_end_at) { Time.zone.parse(timestring) } + context "and reserve_end_at is #{timestring}" do + let(:reserve_end_at) { Time.zone.parse(timestring) } - it "returns #{expected_minutes}" do - expect(reservation.duration_mins).to eq(expected_minutes) - end + it "returns #{expected_minutes}" do + expect(reservation.duration_mins).to eq(expected_minutes) end + end end context "and reserve_end_at is unset" do diff --git a/spec/services/order_details/reconciler_spec.rb b/spec/services/order_details/reconciler_spec.rb index 6c18c7d5d8..260d2ca863 100644 --- a/spec/services/order_details/reconciler_spec.rb +++ b/spec/services/order_details/reconciler_spec.rb @@ -11,7 +11,7 @@ OrderDetail.create!(product: product, quantity: 1, actual_cost: 1, actual_subsidy: 0, state: "complete", statement:, order_id: order.id, created_by_user: user) end end - let(:params) { order_details.each_with_object({}) { |od, h| h[od.id.to_s] = ActionController::Parameters.new(selected: "1", reconciled: "1") } } + let(:params) { order_details.to_h { |od| [od.id.to_s, ActionController::Parameters.new(selected: "1", reconciled: "1")] } } let(:reconciler) { described_class.new(OrderDetail.all, params, Time.current, "reconciled") } let(:account) { create(:account, :with_account_owner, type: Account.config.statement_account_types.first) } let(:statement) { create(:statement, facility: product.facility, account:, created_by_user: user) } @@ -71,7 +71,7 @@ context "with NO bulk note" do context "with reconciled note set" do let(:reconciler) { described_class.new(OrderDetail.all, params, Time.current, "reconciled") } - let(:params) { order_details.each_with_object({}) { |od, h| h[od.id.to_s] = ActionController::Parameters.new(selected: "1", reconciled: "1", reconciled_note: "note #{od.id}") } } + let(:params) { order_details.to_h { |od| [od.id.to_s, ActionController::Parameters.new(selected: "1", reconciled: "1", reconciled_note: "note #{od.id}")] } } it "adds the note to the appropriate order details" do reconciler.reconcile_all diff --git a/vendor/engines/bulk_email/app/controllers/bulk_email/bulk_email_controller.rb b/vendor/engines/bulk_email/app/controllers/bulk_email/bulk_email_controller.rb index 34dc9fb0c8..2823658447 100644 --- a/vendor/engines/bulk_email/app/controllers/bulk_email/bulk_email_controller.rb +++ b/vendor/engines/bulk_email/app/controllers/bulk_email/bulk_email_controller.rb @@ -119,8 +119,8 @@ def datepicker_field_input(form, key) end def user_types - RecipientSearcher.user_types.each_with_object({}) do |user_type, hash| - hash[user_type] = I18n.t("bulk_email.user_type.#{user_type}") + RecipientSearcher.user_types.to_h do |user_type| + [user_type, I18n.t("bulk_email.user_type.#{user_type}")] end end diff --git a/vendor/engines/saml_authentication/lib/saml_authentication/saml_attributes.rb b/vendor/engines/saml_authentication/lib/saml_authentication/saml_attributes.rb index 9d8ff7d42a..c655abdf13 100644 --- a/vendor/engines/saml_authentication/lib/saml_authentication/saml_attributes.rb +++ b/vendor/engines/saml_authentication/lib/saml_authentication/saml_attributes.rb @@ -11,8 +11,8 @@ def initialize(saml_response) end def to_h - @saml_response.attributes.resource_keys.each_with_object({}) do |key, memo| - memo[key] = @saml_response.attribute_value_by_resource_key(key) + @saml_response.attributes.resource_keys.to_h do |key| + [key, @saml_response.attribute_value_by_resource_key(key)] end.with_indifferent_access end diff --git a/vendor/engines/secure_rooms/app/services/secure_rooms/order_details/param_updater_extension.rb b/vendor/engines/secure_rooms/app/services/secure_rooms/order_details/param_updater_extension.rb index 375564de72..3b1ad69921 100644 --- a/vendor/engines/secure_rooms/app/services/secure_rooms/order_details/param_updater_extension.rb +++ b/vendor/engines/secure_rooms/app/services/secure_rooms/order_details/param_updater_extension.rb @@ -11,8 +11,10 @@ module ParamUpdaterExtension included do permitted_attributes.append( occupancy_attributes: [ - entry_at: [:date, :hour, :minute, :ampm], - exit_at: [:date, :hour, :minute, :ampm], + { + entry_at: [:date, :hour, :minute, :ampm], + exit_at: [:date, :hour, :minute, :ampm] + }, ], ) end