From a5d89de4c9ea2b6018205976d2096ecee3045d83 Mon Sep 17 00:00:00 2001 From: Joshua Flark Date: Sat, 30 Sep 2023 14:03:38 -0700 Subject: [PATCH 1/2] Install rubocop with Rails 7.0 defaults --- .rubocop.yml | 302 +++++++++++++++++++++++++++++++++++++++++++++++++++ Gemfile | 47 ++++---- Gemfile.lock | 9 ++ 3 files changed, 337 insertions(+), 21 deletions(-) create mode 100644 .rubocop.yml diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 000000000..b9e765b0e --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,302 @@ +require: + - rubocop-minitest + - rubocop-performance + - rubocop-rails + +AllCops: + TargetRubyVersion: 3.1 + # RuboCop has a bunch of cops enabled by default. This setting tells RuboCop + # to ignore them, so only the ones explicitly set in this file are enabled. + DisabledByDefault: true + SuggestExtensions: false + Exclude: + - "**/tmp/**/*" + - "**/templates/**/*" + - "**/vendor/**/*" + - "actionpack/lib/action_dispatch/journey/parser.rb" + - "actionmailbox/test/dummy/**/*" + - "actiontext/test/dummy/**/*" + - "**/node_modules/**/*" + +Performance: + Exclude: + - "**/test/**/*" + +# Prefer assert_not over assert ! +Rails/AssertNot: + Include: + - "**/test/**/*" + +# Prefer assert_not_x over refute_x +Rails/RefuteMethods: + Include: + - "**/test/**/*" + +Rails/IndexBy: + Enabled: true + +Rails/IndexWith: + Enabled: true + +# Prefer &&/|| over and/or. +Style/AndOr: + Enabled: true + +# Align `when` with `case`. +Layout/CaseIndentation: + Enabled: true + +Layout/ClosingHeredocIndentation: + Enabled: true + +Layout/ClosingParenthesisIndentation: + Enabled: true + +# Align comments with method definitions. +Layout/CommentIndentation: + Enabled: true + +Layout/ElseAlignment: + Enabled: true + +# Align `end` with the matching keyword or starting expression except for +# assignments, where it should be aligned with the LHS. +Layout/EndAlignment: + Enabled: true + EnforcedStyleAlignWith: variable + AutoCorrect: true + +Layout/EndOfLine: + Enabled: true + +Layout/EmptyLineAfterMagicComment: + Enabled: true + +Layout/EmptyLinesAroundAccessModifier: + Enabled: true + EnforcedStyle: only_before + +Layout/EmptyLinesAroundBlockBody: + Enabled: true + +# In a regular class definition, no empty lines around the body. +Layout/EmptyLinesAroundClassBody: + Enabled: true + +# In a regular method definition, no empty lines around the body. +Layout/EmptyLinesAroundMethodBody: + Enabled: true + +# In a regular module definition, no empty lines around the body. +Layout/EmptyLinesAroundModuleBody: + Enabled: true + +# Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }. +Style/HashSyntax: + Enabled: true + +# Method definitions after `private` or `protected` isolated calls need one +# extra level of indentation. +Layout/IndentationConsistency: + Enabled: true + EnforcedStyle: indented_internal_methods + +# Two spaces, no tabs (for indentation). +Layout/IndentationWidth: + Enabled: true + +Layout/LeadingCommentSpace: + Enabled: true + +Layout/SpaceAfterColon: + Enabled: true + +Layout/SpaceAfterComma: + Enabled: true + +Layout/SpaceAfterSemicolon: + Enabled: true + +Layout/SpaceAroundEqualsInParameterDefault: + Enabled: true + +Layout/SpaceAroundKeyword: + Enabled: true + +Layout/SpaceAroundOperators: + Enabled: true + +Layout/SpaceBeforeComma: + Enabled: true + +Layout/SpaceBeforeComment: + Enabled: true + +Layout/SpaceBeforeFirstArg: + Enabled: true + +Style/DefWithParentheses: + Enabled: true + +# Defining a method with parameters needs parentheses. +Style/MethodDefParentheses: + Enabled: true + +Style/ExplicitBlockArgument: + Enabled: true + +Style/FrozenStringLiteralComment: + Enabled: true + EnforcedStyle: always + Exclude: + - "actionview/test/**/*.builder" + - "actionview/test/**/*.ruby" + - "actionpack/test/**/*.builder" + - "actionpack/test/**/*.ruby" + - "activestorage/db/migrate/**/*.rb" + - "activestorage/db/update_migrate/**/*.rb" + - "actionmailbox/db/migrate/**/*.rb" + - "actiontext/db/migrate/**/*.rb" + +Style/RedundantFreeze: + Enabled: true + +# Use `foo {}` not `foo{}`. +Layout/SpaceBeforeBlockBraces: + Enabled: true + +# Use `foo { bar }` not `foo {bar}`. +Layout/SpaceInsideBlockBraces: + Enabled: true + EnforcedStyleForEmptyBraces: space + +# Use `{ a: 1 }` not `{a:1}`. +Layout/SpaceInsideHashLiteralBraces: + Enabled: true + +Layout/SpaceInsideParens: + Enabled: true + +# Check quotes usage according to lint rule below. +Style/StringLiterals: + Enabled: true + EnforcedStyle: double_quotes + +# Detect hard tabs, no hard tabs. +Layout/IndentationStyle: + Enabled: true + +# Empty lines should not have any spaces. +Layout/TrailingEmptyLines: + Enabled: true + +# No trailing whitespace. +Layout/TrailingWhitespace: + Enabled: true + +# Use quotes for string literals when they are enough. +Style/RedundantPercentQ: + Enabled: true + +Lint/AmbiguousOperator: + Enabled: true + +Lint/AmbiguousRegexpLiteral: + Enabled: true + +Lint/DuplicateRequire: + Enabled: true + +Lint/DuplicateMethods: + Enabled: true + +Lint/ErbNewArguments: + Enabled: true + +# Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg. +Lint/RequireParentheses: + Enabled: true + +Lint/RedundantStringCoercion: + Enabled: true + +Lint/UriEscapeUnescape: + Enabled: true + +Lint/UselessAssignment: + Enabled: true + +Lint/DeprecatedClassMethods: + Enabled: true + +Style/ParenthesesAroundCondition: + Enabled: true + +Style/HashTransformKeys: + Enabled: true + +Style/HashTransformValues: + Enabled: true + +Style/RedundantBegin: + Enabled: true + +Style/RedundantReturn: + Enabled: true + AllowMultipleReturnValues: true + +Style/RedundantRegexpEscape: + Enabled: true + +Style/Semicolon: + Enabled: true + AllowAsExpressionSeparator: true + +# Prefer Foo.method over Foo::method +Style/ColonMethodCall: + Enabled: true + +Style/TrivialAccessors: + Enabled: true + +Performance/BindCall: + Enabled: true + +Performance/FlatMap: + Enabled: true + +Performance/MapCompact: + Enabled: true + +Performance/SelectMap: + Enabled: true + +Performance/RedundantMerge: + Enabled: true + +Performance/StartWith: + Enabled: true + +Performance/EndWith: + Enabled: true + +Performance/RegexpMatch: + Enabled: true + +Performance/ReverseEach: + Enabled: true + +Performance/StringReplacement: + Enabled: true + +Performance/UnfreezeString: + Enabled: true + +Performance/DeletePrefix: + Enabled: true + +Performance/DeleteSuffix: + Enabled: true + +Minitest/UnreachableAssertion: + Enabled: true diff --git a/Gemfile b/Gemfile index dada2c035..d675a67ef 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source "https://rubygems.org" git_source(:github) { |repo| "https://github.com/#{repo}.git" } @@ -24,35 +26,35 @@ gem "jbuilder", "~> 2.11" # The latest release doesn't include the test helpers. Using this branch includes those. # See: https://github.com/ErwinM/acts_as_tenant/issues/215#issuecomment-552076674 +gem "activerecord-postgres_enum" gem "acts_as_tenant" -gem "devise" -gem "pundit" gem "audited", github: "simmerz/audited" -gem "turbolinks_render" -gem "money-rails" +gem "devise" +gem "http" gem "mjml-rails" # , github: "jim/mjml-rails", branch: "webpacker" +gem "money-rails" gem "pagy" gem "pg_search" -gem "activerecord-postgres_enum" -gem "scenic" +gem "pundit" gem "reverse_markdown" -gem "http" -gem "translation" +gem "scenic" gem "store_model" +gem "translation" +gem "turbolinks_render" -gem "square.rb" gem "aws-sdk-s3", require: false -gem "sentry-raven" gem "omniauth-google-oauth2" gem "omniauth-rails_csrf_protection" +gem "sentry-raven" +gem "square.rb" gem "image_processing", "~> 1.12" gem "mini_magick" +gem "appsignal" gem "barnes" -gem "sucker_punch" gem "dotenv-rails" -gem "appsignal" +gem "sucker_punch" gem "chronic" @@ -61,30 +63,33 @@ gem "bootsnap", ">= 1.4.1", require: false group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console - gem "byebug", platforms: [:mri, :mingw, :x64_mingw] - gem "standard" + gem "byebug", platforms: %i[mri mingw x64_mingw] gem "factory_bot_rails" - gem "spy" gem "letter_opener" + gem "rubocop", ">= 1.25.1", require: false + gem "rubocop-minitest", require: false + gem "rubocop-rails", require: false + gem "spy" + gem "standard" end group :development do # Access an interactive console on exception pages or by calling 'console' anywhere in the code. - gem "web-console", ">= 3.3.0" - gem "listen" - gem "solargraph" gem "active_storage_log_suppressor", path: "gems/active_storage_log_suppressor" - gem "lefthook" gem "erb_lint", "~> 0.1.1" + gem "lefthook" + gem "listen" + gem "solargraph" + gem "web-console", ">= 3.3.0" end group :test do # Adds support for Capybara system testing and selenium driver - gem "minitest", "5.15.0" gem "capybara", ">= 2.15" - gem "selenium-webdriver" + gem "minitest", "5.15.0" gem "minitest-ci" gem "rails-controller-testing" + gem "selenium-webdriver" end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem diff --git a/Gemfile.lock b/Gemfile.lock index 7d44caeae..788533f7c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -390,9 +390,15 @@ GEM unicode-display_width (>= 1.4.0, < 3.0) rubocop-ast (1.17.0) parser (>= 3.1.1.0) + rubocop-minitest (0.27.0) + rubocop (>= 0.90, < 2.0) rubocop-performance (1.13.3) rubocop (>= 1.7.0, < 2.0) rubocop-ast (>= 0.4.0) + rubocop-rails (2.15.2) + activesupport (>= 4.2.0) + rack (>= 1.1) + rubocop (>= 1.7.0, < 2.0) ruby-progressbar (1.11.0) ruby-vips (2.1.4) ffi (~> 1.12) @@ -526,6 +532,9 @@ DEPENDENCIES rails (~> 6.1.4) rails-controller-testing reverse_markdown + rubocop (>= 1.25.1) + rubocop-minitest + rubocop-rails scenic selenium-webdriver sentry-raven From 98c3f5495934546c2cae1f249d7633f1783fe691 Mon Sep 17 00:00:00 2001 From: Joshua Flark Date: Sat, 30 Sep 2023 14:05:12 -0700 Subject: [PATCH 2/2] =?UTF-8?q?Rubocop=20autofixes=20=F0=9F=A4=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Rakefile | 2 + .../account/appointments_controller.rb | 55 +++--- app/controllers/account/base_controller.rb | 2 + app/controllers/account/holds_controller.rb | 2 + app/controllers/account/home_controller.rb | 2 + app/controllers/account/loans_controller.rb | 2 + app/controllers/account/members_controller.rb | 33 ++-- .../account/passwords_controller.rb | 9 +- .../account/renewal_requests_controller.rb | 6 +- .../account/renewals_controller.rb | 2 + .../admin/appointment_checkins_controller.rb | 2 + .../admin/appointment_checkouts_controller.rb | 39 ++-- .../appointment_completions_controller.rb | 6 +- .../admin/appointment_holds_controller.rb | 75 ++++---- .../admin/appointment_loans_controller.rb | 63 +++---- .../admin/appointments_controller.rb | 113 ++++++------ app/controllers/admin/base_controller.rb | 33 ++-- .../admin/borrow_policies_controller.rb | 15 +- .../admin/bulk_renewals_controller.rb | 9 +- .../admin/categories_controller.rb | 15 +- app/controllers/admin/dashboard_controller.rb | 2 + app/controllers/admin/documents_controller.rb | 19 +- .../admin/gift_memberships_controller.rb | 15 +- app/controllers/admin/holds_controller.rb | 4 +- app/controllers/admin/images_controller.rb | 21 +-- .../admin/item_histories_controller.rb | 2 + .../admin/item_holds_controller.rb | 2 + .../admin/items/attachments_controller.rb | 9 +- .../admin/items/base_controller.rb | 9 +- .../tickets/ticket_updates_controller.rb | 27 +-- .../admin/items/tickets_controller.rb | 15 +- app/controllers/admin/items_controller.rb | 51 +++--- .../admin/loan_histories_controller.rb | 2 + .../admin/loan_summaries_controller.rb | 13 +- app/controllers/admin/loans_controller.rb | 15 +- app/controllers/admin/lookups_controller.rb | 4 +- .../admin/manage_features_controller.rb | 19 +- .../admin/manual_imports_controller.rb | 9 +- app/controllers/admin/maps_controller.rb | 2 + .../admin/members/adjustments_controller.rb | 2 + .../admin/members/appointments_controller.rb | 17 +- .../admin/members/base_controller.rb | 9 +- .../admin/members/hold_loans_controller.rb | 2 + .../admin/members/holds_controller.rb | 9 +- .../members/loan_summaries_controller.rb | 2 + .../admin/members/lookups_controller.rb | 4 +- .../admin/members/memberships_controller.rb | 9 +- .../admin/members/notifications_controller.rb | 2 + .../admin/members/payments_controller.rb | 15 +- .../admin/members/verifications_controller.rb | 19 +- app/controllers/admin/members_controller.rb | 23 +-- app/controllers/admin/notes_controller.rb | 35 ++-- .../admin/renewal_requests_controller.rb | 25 +-- app/controllers/admin/renewals_controller.rb | 2 + .../items_in_maintenance_controller.rb | 2 + .../reports/items_without_image_controller.rb | 2 + .../reports/member_requests_controller.rb | 2 + .../admin/reports/memberships_controller.rb | 4 +- .../admin/reports/money_controller.rb | 2 + .../reports/monthly_activities_controller.rb | 2 + .../admin/reports/notifications_controller.rb | 2 + .../potential_volunteers_controller.rb | 4 +- .../admin/reports/shifts_controller.rb | 2 + .../admin/reports/zipcodes_controller.rb | 4 +- app/controllers/admin/searches_controller.rb | 4 +- .../admin/settings/closing_controller.rb | 9 +- .../settings/email_settings_controller.rb | 9 +- .../admin/settings/exports_controller.rb | 25 +-- .../settings/library_updates_controller.rb | 15 +- app/controllers/admin/ui_controller.rb | 2 + app/controllers/admin/users_controller.rb | 21 +-- app/controllers/application_controller.rb | 82 +++++---- app/controllers/concerns/appointment_slots.rb | 17 +- app/controllers/concerns/calendaring.rb | 2 + app/controllers/concerns/lending.rb | 169 +++++++++--------- app/controllers/concerns/member_ordering.rb | 2 + app/controllers/concerns/page_attributes.rb | 27 +-- app/controllers/concerns/portal_rendering.rb | 2 + app/controllers/dev_controller.rb | 2 + app/controllers/documents_controller.rb | 2 + app/controllers/errors_controller.rb | 59 +++--- app/controllers/home_controller.rb | 2 + app/controllers/homepage_controller.rb | 9 +- app/controllers/items_controller.rb | 95 +++++----- .../renewal/acceptances_controller.rb | 9 +- app/controllers/renewal/base_controller.rb | 65 +++---- .../renewal/confirmations_controller.rb | 2 + .../renewal/documents_controller.rb | 2 + app/controllers/renewal/home_controller.rb | 2 + app/controllers/renewal/members_controller.rb | 17 +- .../renewal/payments_controller.rb | 41 ++--- .../renewal/redemptions_controller.rb | 9 +- app/controllers/short_links_controller.rb | 2 + .../signup/acceptances_controller.rb | 9 +- app/controllers/signup/base_controller.rb | 75 ++++---- .../signup/confirmations_controller.rb | 2 + .../signup/documents_controller.rb | 2 + app/controllers/signup/home_controller.rb | 2 + app/controllers/signup/members_controller.rb | 17 +- app/controllers/signup/payments_controller.rb | 41 ++--- .../signup/redemptions_controller.rb | 9 +- .../super_admin/libraries_controller.rb | 17 +- app/controllers/test_controller.rb | 2 + app/controllers/users/sessions_controller.rb | 2 + .../volunteer/attendees_controller.rb | 17 +- app/controllers/volunteer/base_controller.rb | 17 +- .../volunteer/sessions_controller.rb | 15 +- .../volunteer/shifts_controller.rb | 9 +- app/forms/extend_holds_form.rb | 11 +- app/forms/gift_membership_redemption_form.rb | 2 + app/forms/member_signup_form.rb | 2 + app/forms/membership_form.rb | 15 +- app/forms/membership_payment_form.rb | 2 + app/forms/ticket_update_form.rb | 2 + app/helpers/adjustments_helper.rb | 2 + .../admin/items/items_attachments_helper.rb | 2 + app/helpers/admin_helper.rb | 16 +- app/helpers/application_helper.rb | 2 + app/helpers/appointments_helper.rb | 2 + app/helpers/date_helper.rb | 2 + app/helpers/holds_helper.rb | 15 +- app/helpers/icons_helper.rb | 10 +- app/helpers/items_helper.rb | 8 +- app/helpers/layout_helper.rb | 2 + app/helpers/loans_helper.rb | 17 +- app/helpers/member_profiles_helper.rb | 2 + app/helpers/members_helper.rb | 4 +- app/helpers/shifts_helper.rb | 10 +- app/helpers/ticket_updates_helper.rb | 2 + app/helpers/tickets_helper.rb | 2 + app/jobs/application_job.rb | 2 + app/jobs/neon_member_job.rb | 2 + app/lib/activity_notifier.rb | 29 +-- app/lib/admin/check_out.rb | 2 + app/lib/admin/lookup.rb | 2 + app/lib/admin/payment.rb | 2 + app/lib/admin/verification.rb | 2 + app/lib/certificate/generator.rb | 2 + app/lib/fine_calculator.rb | 2 + app/lib/google/calendar.rb | 87 ++++----- app/lib/google/calendar_event.rb | 2 + app/lib/google/test_calendar.rb | 27 +-- app/lib/html_to_markdown.rb | 2 + app/lib/item_exporter.rb | 2 + app/lib/manual_import.rb | 4 +- app/lib/map/chicago.rb | 33 ++-- app/lib/member_exporter.rb | 35 ++-- app/lib/neon.rb | 14 +- app/lib/open_days.rb | 4 +- app/lib/result.rb | 2 + app/lib/spectre_form_builder.rb | 133 +++++++------- app/lib/square_checkout.rb | 15 +- app/lib/step.rb | 2 + app/lib/validation_inspector.rb | 2 + app/lib/volunteer/day.rb | 2 + app/lib/volunteer/month_calendar.rb | 2 + app/lib/volunteer/shift.rb | 2 + app/mailers/application_mailer.rb | 2 + app/mailers/gift_purchaser_mailer.rb | 29 +-- app/mailers/homepage_mailer.rb | 2 + app/mailers/member_mailer.rb | 51 +++--- app/mailers/member_mailer_observer.rb | 4 +- app/mailers/user_mailer.rb | 2 + app/models/adjustment.rb | 6 +- app/models/agreement_acceptance.rb | 2 + app/models/application_record.rb | 2 + app/models/appointment.rb | 43 ++--- app/models/appointment_hold.rb | 2 + app/models/appointment_loan.rb | 2 + app/models/attendee.rb | 2 + app/models/borrow_policy.rb | 23 +-- app/models/categorization.rb | 11 +- app/models/category.rb | 6 +- app/models/category_node.rb | 2 + app/models/document.rb | 4 +- app/models/event.rb | 2 + app/models/gift_membership.rb | 25 +-- app/models/gift_membership_code.rb | 2 + app/models/hold.rb | 19 +- app/models/item.rb | 93 +++++----- app/models/item_attachment.rb | 11 +- app/models/library.rb | 27 +-- app/models/library_update.rb | 2 + app/models/loan.rb | 6 +- app/models/loan_summary.rb | 4 +- app/models/member.rb | 63 +++---- app/models/membership.rb | 31 ++-- app/models/monthly_adjustment.rb | 2 + app/models/monthly_appointment.rb | 2 + app/models/monthly_loan.rb | 2 + app/models/monthly_member.rb | 2 + app/models/note.rb | 2 + app/models/notification.rb | 4 +- app/models/renewal_request.rb | 4 +- app/models/short_link.rb | 45 ++--- app/models/ticket.rb | 4 +- app/models/ticket_update.rb | 4 +- app/models/user.rb | 2 + app/nulls/null_association_proxy.rb | 2 + app/nulls/null_attachment.rb | 2 + app/nulls/null_borrow_policy.rb | 2 + app/nulls/null_item.rb | 2 + app/policies/application_policy.rb | 2 + app/policies/loan_policy.rb | 2 + .../admin/documents/_agreement.json.jbuilder | 2 + app/views/admin/documents/index.json.jbuilder | 2 + app/views/admin/documents/show.json.jbuilder | 2 + .../_gift_membership.json.jbuilder | 2 + .../gift_memberships/index.json.jbuilder | 2 + .../admin/gift_memberships/show.json.jbuilder | 2 + app/views/admin/loans/_loan.json.jbuilder | 2 + app/views/admin/loans/index.json.jbuilder | 2 + bin/bundle | 6 +- bin/rails | 12 +- bin/rake | 10 +- bin/reset | 22 +-- bin/setup | 22 +-- bin/spring | 9 +- bin/update | 18 +- bin/yarn | 16 +- config.ru | 2 + config/application.rb | 2 + config/boot.rb | 2 + config/environment.rb | 2 + config/environments/development.rb | 4 +- config/environments/production.rb | 4 +- config/environments/staging.rb | 4 +- config/environments/test.rb | 4 +- .../application_controller_renderer.rb | 1 + config/initializers/backtrace_silencers.rb | 1 + .../initializers/content_security_policy.rb | 1 + config/initializers/cookies_serializer.rb | 2 + config/initializers/custom_time_formats.rb | 2 + config/initializers/date_format.rb | 2 + config/initializers/dotenv.rb | 2 + config/initializers/email_observers.rb | 2 + .../initializers/filter_parameter_logging.rb | 2 + config/initializers/inflections.rb | 2 + config/initializers/logging.rb | 4 +- config/initializers/mime_types.rb | 2 + config/initializers/money.rb | 2 + config/initializers/omniauth.rb | 2 + config/initializers/pagy.rb | 2 + config/initializers/staging_access.rb | 2 + config/initializers/translation.rb | 2 + config/initializers/wrap_parameters.rb | 2 + config/puma.rb | 2 + config/routes.rb | 6 +- config/spring.rb | 2 + db/migrate/20190314033712_create_items.rb | 2 + ...te_active_storage_tables.active_storage.rb | 2 + ...0_create_action_text_tables.action_text.rb | 2 + .../20190317013855_add_number_to_items.rb | 2 + .../20190317031248_create_categories.rb | 2 + .../20190317032441_create_categorizations.rb | 2 + ...niqueness_constraint_to_categorizations.rb | 2 + ...190317035504_add_ancestry_to_categories.rb | 2 + ...317203043_add_counter_cache_to_category.rb | 2 + db/migrate/20190319024125_create_members.rb | 2 + db/migrate/20190322030007_create_loans.rb | 2 + db/migrate/20190427201337_install_audited.rb | 2 + .../20190509041314_add_status_to_items.rb | 2 + .../20190509042525_add_status_to_members.rb | 2 + .../20190526205528_create_borrow_policies.rb | 2 + ...190601021224_add_borrow_policy_to_items.rb | 2 + .../20190604001152_create_adjustments.rb | 2 + .../20190610021238_create_agreements.rb | 2 + ...0614011321_create_agreement_acceptances.rb | 2 + .../20190616014227_update_member_fields.rb | 2 + .../20190624133416_add_strength_to_items.rb | 2 + ...dd_uniquely_numbered_to_borrow_policies.rb | 2 + ...description_and_code_to_borrow_policies.rb | 2 + ...28171313_add_uniquely_numbered_to_loans.rb | 2 + ...30003353_add_default_to_borrow_policies.rb | 2 + ...0190710215125_remove_category_hierarchy.rb | 2 + .../20190711233155_add_quantity_to_items.rb | 2 + .../20190715143604_create_memberships.rb | 2 + ...16012142_rename_agreements_to_documents.rb | 2 + ...0716013130_update_agreement_acceptances.rb | 2 + .../20190716013252_add_default_documents.rb | 2 + ...0716014635_remove_active_from_documents.rb | 2 + ...3026_add_communication_fields_to_member.rb | 2 + ...7020247_add_payment_info_to_adjustments.rb | 2 + ...20190816152137_add_support_for_renewals.rb | 4 +- .../20190817190131_create_loan_summaries.rb | 2 + .../20190911020605_add_kind_to_adjustments.rb | 2 + ...16011430_add_forgiveness_to_adjustments.rb | 2 + ...3208_update_loan_summaries_to_version_2.rb | 2 + ...190921013902_create_monthly_adjustments.rb | 2 + ...0512_update_loan_summaries_to_version_3.rb | 2 + ...0191021005121_create_monthly_activities.rb | 2 + ...91028022023_add_index_to_loans_ended_at.rb | 2 + .../20191102002601_create_notifications.rb | 2 + .../20191103015209_add_notice_to_items.rb | 2 + .../20191210022433_create_gift_memberships.rb | 2 + ...055236_relax_member_id_on_notifications.rb | 2 + ...00437_add_recipient_to_gift_memberships.rb | 2 + ...121020026_add_address_fields_to_members.rb | 2 + ...0929_add_renewal_limit_to_borrow_policy.rb | 2 + .../20200208203157_create_short_links.rb | 2 + ...00422023206_add_parent_id_to_categories.rb | 4 +- .../20200425192757_create_category_nodes.rb | 2 + .../20200503203437_add_member_number.rb | 2 + .../20200504134052_assign_member_numbers.rb | 2 + db/migrate/20200512184900_create_holds.rb | 4 +- ...14003135_add_hold_counter_cache_to_item.rb | 2 + .../20200517211425_add_ended_at_to_holds.rb | 2 + .../20200518032950_add_loan_id_to_hold.rb | 2 + db/migrate/20200605013050_create_notes.rb | 4 +- ...2240_add_uniqueness_constraint_to_loans.rb | 2 + ...20200618031047_add_other_names_to_items.rb | 2 + .../20200621211015_add_roles_to_users.rb | 2 + .../20200710004507_create_hold_requests.rb | 2 + ...0200714041707_create_hold_request_items.rb | 2 + ...718180844_add_event_id_to_hold_requests.rb | 2 + db/migrate/20200722175156_create_events.rb | 2 + .../20200905185238_add_member_to_user.rb | 2 + .../20200906142639_add_member_to_role_enum.rb | 2 + ...00906142955_change_default_role_on_user.rb | 2 + .../20200906182546_add_pronouns_to_members.rb | 2 + ...add_member_renewable_to_borrow_policies.rb | 2 + db/migrate/20200921232145_create_libraries.rb | 4 +- .../20200922173203_scope_models_to_tenants.rb | 2 + ...0922204207_add_super_admin_to_role_enum.rb | 2 + .../20200923151427_create_appointments.rb | 2 + ...20200923152956_create_appointment_holds.rb | 2 + ...20200924184016_create_appointment_loans.rb | 2 + ...2839_update_category_nodes_to_version_2.rb | 2 + ...3209_update_loan_summaries_to_version_4.rb | 2 + .../20200925134546_establish_tenant_zero.rb | 63 +++---- ...0201002020141_add_power_source_to_items.rb | 2 + .../20201017185636_drop_hold_requests.rb | 2 + .../20201024195024_remove_user_uniqueness.rb | 2 + ...201024225228_rename_member_notes_to_bio.rb | 2 + db/migrate/20201107024718_downcase_emails.rb | 2 + .../20201112012007_create_item_attachments.rb | 4 +- ...18221831_migrate_manuals_to_attachments.rb | 2 + ...20201129191804_make_memberships_pending.rb | 2 + .../20201228190740_add_started_at_to_holds.rb | 2 + ...name_membership_started_on_and_ended_on.rb | 2 + ...move_pronoun_and_custom_pronoun_columns.rb | 2 + .../20210204025839_create_renewal_requests.rb | 2 + ..._to_active_storage_blobs.active_storage.rb | 2 + ..._storage_variant_records.active_storage.rb | 2 + ...update_monthly_adjustments_to_version_2.rb | 2 + ...212401_add_completed_at_to_appointments.rb | 2 + ...20210722214912_add_item_location_fields.rb | 2 + ...3205105_change_event_attendees_to_jsonb.rb | 2 + ...0911202001_add_pronunciation_to_members.rb | 2 + ...1216_add_plain_text_description_to_item.rb | 2 + ...3946_add_library_id_to_renewal_requests.rb | 2 + ...12153401_add_allow_members_to_libraries.rb | 2 + ...3172726_add_allow_payments_to_libraries.rb | 2 + ...75030_add_allow_volunteers_to_libraries.rb | 2 + ...745_add_allow_appointments_to_libraries.rb | 2 + .../20211120222110_add_expires_at_to_holds.rb | 2 + .../20211203200042_create_library_updates.rb | 2 + ...20202191706_create_enum_for_item_status.rb | 2 + ...220202214711_create_maintenance_reports.rb | 4 +- .../20220212072927_create_monthly_loans.rb | 2 + .../20220212073119_create_monthly_members.rb | 2 + ...20212073628_create_monthly_appointments.rb | 2 + ...0212081100_drop_monthly_activities_view.rb | 2 + ...0215035541_add_additional_item_statuses.rb | 2 + .../20220225180000_add_ticket_status.rb | 2 + db/migrate/20220225184325_create_tickets.rb | 4 +- ...20220225192017_drop_maintenance_reports.rb | 2 + .../20220227204052_create_ticket_updates.rb | 4 +- ...3060319_add_consumable_to_borrow_policy.rb | 2 + ..._remove_maintenance_statuses_from_items.rb | 4 +- ...d_library_to_tickets_and_ticket_updates.rb | 2 + db/migrate/20220327010549_add_url_to_items.rb | 2 + ...20330165641_add_item_counts_to_category.rb | 2 + ...5925_update_category_nodes_to_version_3.rb | 2 + ...4122_add_unique_index_to_category_nodes.rb | 2 + ...4258_update_category_nodes_to_version_4.rb | 2 + ...2531_remove_item_counts_from_categories.rb | 2 + ...urchase_price_and_purchase_link_to_item.rb | 2 + ...30174955_add_my_turn_item_type_to_items.rb | 2 + db/schema.rb | 4 +- db/seeds.rb | 4 +- gems/active_storage_log_suppressor/Gemfile | 2 + .../active_storage_log_suppressor.gemspec | 2 + .../active_storage_log_suppressor/filters.rb | 9 +- .../active_storage_log_suppressor_tasks.rake | 1 + lib/rails_solargraph.rb | 1 + lib/tasks/categories.rake | 2 + lib/tasks/db.rake | 2 + lib/tasks/devdata.rake | 24 +-- lib/tasks/email.rake | 4 +- lib/tasks/export.rake | 2 + lib/tasks/holds.rake | 4 +- lib/tasks/import.rake | 4 +- lib/tasks/members.rake | 6 +- lib/tasks/neon.rake | 2 + lib/tasks/production.rake | 4 +- lib/tasks/s3.rake | 2 + lib/tasks/stats.rake | 2 + lib/tasks/sync.rake | 4 +- test/application_system_test_case.rb | 79 ++++---- .../application_cable/connection_test.rb | 2 + .../account/appointments_controller_test.rb | 8 +- .../account/holds_controller_test.rb | 8 +- .../account/home_controller_test.rb | 4 +- .../account/loans_controller_test.rb | 8 +- .../account/members_controller_test.rb | 6 +- .../account/password_controller_test.rb | 10 +- .../renewal_requests_controller_test.rb | 6 +- .../account/renewals_controller_test.rb | 6 +- .../appointment_checkins_controller_test.rb | 4 +- ...appointment_completions_controller_test.rb | 2 + .../admin/appointments_controller_test.rb | 6 +- .../admin/borrow_policies_controller_test.rb | 6 +- .../admin/bulk_renewals_controller_test.rb | 2 + .../admin/categories_controller_test.rb | 6 +- .../admin/dashboard_controller_test.rb | 2 + .../admin/documents_controller_test.rb | 4 +- .../admin/gift_memberships_controller_test.rb | 2 + .../admin/hold_loans_controller_test.rb | 2 + .../admin/hold_requests_controller_test.rb | 2 + .../admin/items/tickets_controller_test.rb | 6 +- .../admin/items_controller_test.rb | 6 +- .../items_in_maintenance_controller_test.rb | 2 + .../admin/loan_summaries_controller_test.rb | 2 + .../admin/loans_controller_test.rb | 16 +- .../members/appointments_controller_test.rb | 4 +- .../admin/members/holds_controller_test.rb | 18 +- .../admin/members_controller_test.rb | 4 +- .../admin/memberships_controller_test.rb | 10 +- .../admin/notes_controller_test.rb | 10 +- .../admin/renewal_requests_controller_test.rb | 14 +- .../admin/renewals_controller_test.rb | 6 +- .../items_without_image_controller_test.rb | 2 + .../member_requests_controller_test.rb | 2 + .../reports/memberships_controller_test.rb | 2 + .../monthly_activities_controller_test.rb | 2 + .../monthly_adjustments_controller_test.rb | 2 + .../potential_volunteers_controller_test.rb | 2 + .../admin/reports/requests_controller_test.rb | 2 + .../admin/reports/shifts_controller_test.rb | 2 + .../admin/searches_controller_test.rb | 2 + test/controllers/admin/ui_controller_test.rb | 6 +- .../admin/users_controller_test.rb | 10 +- .../admin/verifications_controller_test.rb | 2 + .../application_controller_test.rb | 16 +- test/controllers/concerns/lending_test.rb | 64 +++---- .../concerns/page_attributes_test.rb | 4 +- test/controllers/documents_controller_test.rb | 2 + test/controllers/errors_controller_test.rb | 2 + test/controllers/items_controller_test.rb | 14 +- .../short_links_controller_test.rb | 2 + .../signup/payments_controller_test.rb | 26 +-- .../super_admin/libraries_controller_test.rb | 10 +- test/factories/adjustments.rb | 2 + test/factories/appointment_holds.rb | 2 + test/factories/appointment_loans.rb | 2 + test/factories/appointments.rb | 2 + test/factories/borrow_policies.rb | 2 + test/factories/categories.rb | 2 + test/factories/documents.rb | 2 + test/factories/events.rb | 2 + test/factories/gift_memberships.rb | 2 + test/factories/holds.rb | 2 + test/factories/item_attachments.rb | 2 + test/factories/items.rb | 2 + test/factories/libraries.rb | 2 + test/factories/library_updates.rb | 2 + test/factories/loans.rb | 2 + test/factories/maintenance_reports.rb | 2 + test/factories/members.rb | 4 +- test/factories/memberships.rb | 2 + test/factories/notes.rb | 2 + test/factories/notifications.rb | 2 + test/factories/renewal_requests.rb | 2 + test/factories/short_links.rb | 2 + test/factories/tickets.rb | 2 + test/factories/users.rb | 2 + test/forms/extend_holds_form_test.rb | 10 +- .../gift_membership_redemption_form_test.rb | 10 +- test/helpers/ensure_request_tenant.rb | 2 + test/helpers/holds_helper_test.rb | 2 + test/helpers/items_helper_test.rb | 18 +- test/helpers/loans_helper_test.rb | 2 + test/helpers/return_values.rb | 2 + test/helpers/shifts_helper_test.rb | 2 + test/lib/activity_notifier_test.rb | 28 +-- test/lib/certificate/generator_test.rb | 2 + test/lib/item_exporter_test.rb | 2 + test/lib/manual_import_test.rb | 6 +- test/lib/map/chicago_test.rb | 4 +- test/lib/member_exporter_test.rb | 2 + test/lib/neon_test.rb | 2 + test/lib/open_days_test.rb | 2 + test/lib/result_test.rb | 6 +- test/lib/square_checkout_test.rb | 14 +- test/mailers/member_mailer_test.rb | 14 +- .../previews/gift_purchaser_mailer_preview.rb | 4 +- .../previews/homepage_mailer_preview.rb | 4 +- .../mailers/previews/member_mailer_preview.rb | 34 ++-- test/models/adjustment_test.rb | 2 + test/models/agreement_acceptance_test.rb | 2 + test/models/agreement_test.rb | 2 + test/models/appointment_hold_test.rb | 4 +- test/models/appointment_loan_test.rb | 2 + test/models/appointment_test.rb | 28 +-- test/models/borrow_policy_test.rb | 6 +- test/models/category_node_test.rb | 2 + test/models/category_test.rb | 4 +- test/models/event_test.rb | 4 +- test/models/fine_calculator_test.rb | 2 + test/models/gift_membership_test.rb | 2 + test/models/hold_test.rb | 86 ++++----- test/models/item_attachment_test.rb | 2 + test/models/item_test.rb | 44 ++--- test/models/library_test.rb | 6 +- test/models/library_update_test.rb | 2 + test/models/loan_summary_test.rb | 2 + test/models/loan_test.rb | 74 ++++---- test/models/member_test.rb | 28 +-- test/models/membership_test.rb | 28 +-- test/models/monthly_adjustment_test.rb | 2 + test/models/note_test.rb | 2 + test/models/notification_test.rb | 2 + test/models/renewal_request_test.rb | 2 + test/models/reservation_test.rb | 2 + test/models/short_link_test.rb | 10 +- test/models/ticket_test.rb | 2 + test/models/user_test.rb | 2 + test/nulls/null_borrow_policy_test.rb | 2 + test/nulls/null_item_test.rb | 2 + test/system/admin/appointments_test.rb | 2 + test/system/admin/borrow_policies_test.rb | 2 + test/system/admin/categories_test.rb | 2 + test/system/admin/check_in_check_out_test.rb | 4 +- test/system/admin/consumables_test.rb | 2 + test/system/admin/gift_memberships_test.rb | 2 + test/system/admin/holds_test.rb | 2 + test/system/admin/item_attachments_test.rb | 2 + test/system/admin/items_test.rb | 2 + test/system/admin/manage_features_test.rb | 2 + test/system/admin/member_payment_test.rb | 2 + test/system/admin/member_verification_test.rb | 2 + test/system/admin/members_test.rb | 2 + test/system/admin/memberships_test.rb | 6 +- test/system/admin/notes_test.rb | 2 + test/system/admin/renewal_requests_test.rb | 2 + .../admin/reports/monthly_activities_test.rb | 2 + test/system/admin/users_test.rb | 2 + test/system/appointments_test.rb | 4 +- test/system/holds_test.rb | 4 +- test/system/item_filtering_test.rb | 2 + test/system/member_checked_out_items_test.rb | 2 + test/system/member_profile_test.rb | 2 + test/system/membership_renewal_test.rb | 6 +- test/system/multitenancy_test.rb | 4 +- test/system/pronoun_selection_test.rb | 2 + test/system/user_signup_test.rb | 6 +- test/system/volunteer/shifts_test.rb | 2 + test/test_helper.rb | 2 + 559 files changed, 2859 insertions(+), 1854 deletions(-) diff --git a/Rakefile b/Rakefile index 9a5ea7383..d2a78aa25 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. diff --git a/app/controllers/account/appointments_controller.rb b/app/controllers/account/appointments_controller.rb index a85694413..86da0309b 100644 --- a/app/controllers/account/appointments_controller.rb +++ b/app/controllers/account/appointments_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Account class AppointmentsController < BaseController include AppointmentSlots @@ -62,39 +64,38 @@ def update def destroy @appointment.destroy - redirect_to account_appointments_path, flash: {success: "Appointment cancelled."} + redirect_to account_appointments_path, flash: { success: "Appointment cancelled." } end private + def appointment_params + form_params = params.require(:appointment).permit(:comment, :time_range_string, hold_ids: [], loan_ids: []) + + { + holds: @member.holds.where(id: form_params[:hold_ids]), + loans: @member.loans.where(id: form_params[:loan_ids]), + comment: form_params[:comment], + time_range_string: form_params[:time_range_string], + member_updating: true + } + end - def appointment_params - form_params = params.require(:appointment).permit(:comment, :time_range_string, hold_ids: [], loan_ids: []) - - { - holds: @member.holds.where(id: form_params[:hold_ids]), - loans: @member.loans.where(id: form_params[:loan_ids]), - comment: form_params[:comment], - time_range_string: form_params[:time_range_string], - member_updating: true - } - end - - def load_holds_and_loans - @holds = Hold.active.includes(member: {appointments: :holds}).where(member: @member) - @loans = @member.loans.includes(:item, member: {appointments: :loans}).checked_out - end + def load_holds_and_loans + @holds = Hold.active.includes(member: { appointments: :holds }).where(member: @member) + @loans = @member.loans.includes(:item, member: { appointments: :loans }).checked_out + end - def merge_simultaneous_appointments - simultaneous_appointment = @member.appointments.simultaneous(@appointment).first - if simultaneous_appointment - simultaneous_appointment.merge!(@appointment) - true + def merge_simultaneous_appointments + simultaneous_appointment = @member.appointments.simultaneous(@appointment).first + if simultaneous_appointment + simultaneous_appointment.merge!(@appointment) + true + end end - end - def load_appointment_for_editing - @appointment = current_member.appointments.find(params[:id]) - redirect_to account_appointments_path, alert: "Completed appointments can't be changed" if @appointment.completed? - end + def load_appointment_for_editing + @appointment = current_member.appointments.find(params[:id]) + redirect_to account_appointments_path, alert: "Completed appointments can't be changed" if @appointment.completed? + end end end diff --git a/app/controllers/account/base_controller.rb b/app/controllers/account/base_controller.rb index f6c136754..3041989d3 100644 --- a/app/controllers/account/base_controller.rb +++ b/app/controllers/account/base_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Account class BaseController < ApplicationController before_action :authenticate_user! diff --git a/app/controllers/account/holds_controller.rb b/app/controllers/account/holds_controller.rb index 6e9a9d813..23ef8a86a 100644 --- a/app/controllers/account/holds_controller.rb +++ b/app/controllers/account/holds_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Account class HoldsController < BaseController def index diff --git a/app/controllers/account/home_controller.rb b/app/controllers/account/home_controller.rb index c998f9907..747a6d937 100644 --- a/app/controllers/account/home_controller.rb +++ b/app/controllers/account/home_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Account class HomeController < BaseController def index diff --git a/app/controllers/account/loans_controller.rb b/app/controllers/account/loans_controller.rb index 9b0ecf85b..48548c56c 100644 --- a/app/controllers/account/loans_controller.rb +++ b/app/controllers/account/loans_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Account class LoansController < BaseController def index diff --git a/app/controllers/account/members_controller.rb b/app/controllers/account/members_controller.rb index 3d4b9671e..af1b53a70 100644 --- a/app/controllers/account/members_controller.rb +++ b/app/controllers/account/members_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Account class MembersController < ApplicationController def show @@ -20,21 +22,20 @@ def update end private - - def member_params - params.require(:member).permit(:full_name, - :preferred_name, - :email, - :phone_number, - :address1, - :address2, - :postal_code, - :desires, - :reminders_via_email, - :reminders_via_text, - :receive_newsletter, - :volunteer_interest, - pronouns: []) - end + def member_params + params.require(:member).permit(:full_name, + :preferred_name, + :email, + :phone_number, + :address1, + :address2, + :postal_code, + :desires, + :reminders_via_email, + :reminders_via_text, + :receive_newsletter, + :volunteer_interest, + pronouns: []) + end end end diff --git a/app/controllers/account/passwords_controller.rb b/app/controllers/account/passwords_controller.rb index df2dd38e0..1ab35f914 100644 --- a/app/controllers/account/passwords_controller.rb +++ b/app/controllers/account/passwords_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Account class PasswordsController < BaseController def edit @@ -15,9 +17,8 @@ def update end private - - def user_params - params.require(:user).permit(:current_password, :password, :password_confirmation) - end + def user_params + params.require(:user).permit(:current_password, :password, :password_confirmation) + end end end diff --git a/app/controllers/account/renewal_requests_controller.rb b/app/controllers/account/renewal_requests_controller.rb index c6fbbc297..e0f525a7b 100644 --- a/app/controllers/account/renewal_requests_controller.rb +++ b/app/controllers/account/renewal_requests_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Account class RenewalRequestsController < BaseController def create @@ -10,9 +12,9 @@ def create @renewal_request = RenewalRequest.new(loan: @loan) flash_message = if @renewal_request.save - {success: "Renewal requested. We'll e-mail you an update."} + { success: "Renewal requested. We'll e-mail you an update." } else - {error: "Something went wrong!"} + { error: "Something went wrong!" } end redirect_to account_loans_path, flash: flash_message diff --git a/app/controllers/account/renewals_controller.rb b/app/controllers/account/renewals_controller.rb index 34c82c045..9c0e79234 100644 --- a/app/controllers/account/renewals_controller.rb +++ b/app/controllers/account/renewals_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Account class RenewalsController < BaseController include Lending diff --git a/app/controllers/admin/appointment_checkins_controller.rb b/app/controllers/admin/appointment_checkins_controller.rb index 4cd327743..5fc4296ca 100644 --- a/app/controllers/admin/appointment_checkins_controller.rb +++ b/app/controllers/admin/appointment_checkins_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin class AppointmentCheckinsController < BaseController before_action :are_appointments_enabled? diff --git a/app/controllers/admin/appointment_checkouts_controller.rb b/app/controllers/admin/appointment_checkouts_controller.rb index 9aaa8e5af..837867490 100644 --- a/app/controllers/admin/appointment_checkouts_controller.rb +++ b/app/controllers/admin/appointment_checkouts_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin class AppointmentCheckoutsController < BaseController include Lending @@ -6,34 +8,33 @@ class AppointmentCheckoutsController < BaseController def create create_loans_for_holds - redirect_to admin_appointment_path(appointment), flash: {success: "#{pluralize(checked_out_item_count, "Item")} checked-out."} + redirect_to admin_appointment_path(appointment), flash: { success: "#{pluralize(checked_out_item_count, "Item")} checked-out." } end private + attr_accessor :new_loans - attr_accessor :new_loans - - delegate :pluralize, to: "ActionController::Base.helpers", private: true - delegate :member, to: :appointment + delegate :pluralize, to: "ActionController::Base.helpers", private: true + delegate :member, to: :appointment - def checked_out_item_count - new_loans&.count&.to_i - end + def checked_out_item_count + new_loans&.count&.to_i + end - def holds - @holds ||= appointment.holds.active.where(id: params[:hold_ids]) - end + def holds + @holds ||= appointment.holds.active.where(id: params[:hold_ids]) + end - def appointment - @appointment ||= Appointment.find(params[:appointment_id]) - end + def appointment + @appointment ||= Appointment.find(params[:appointment_id]) + end - def create_loans_for_holds - self.new_loans = member.transaction do - holds.map do |hold| - create_loan_from_hold(hold) + def create_loans_for_holds + self.new_loans = member.transaction do + holds.map do |hold| + create_loan_from_hold(hold) + end end end - end end end diff --git a/app/controllers/admin/appointment_completions_controller.rb b/app/controllers/admin/appointment_completions_controller.rb index 20e2f2487..cd3647db6 100644 --- a/app/controllers/admin/appointment_completions_controller.rb +++ b/app/controllers/admin/appointment_completions_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin class AppointmentCompletionsController < BaseController before_action :are_appointments_enabled? @@ -7,13 +9,13 @@ class AppointmentCompletionsController < BaseController def create @appointment = Appointment.find(params[:appointment_id]) @appointment.update!(completed_at: Time.current, staff_updating: true) - render_to_portal("admin/appointments/appointment", table_row: true, locals: {appointment: @appointment}) + render_to_portal("admin/appointments/appointment", table_row: true, locals: { appointment: @appointment }) end def destroy @appointment = Appointment.find(params[:appointment_id]) @appointment.update!(completed_at: nil, staff_updating: true) - render_to_portal("admin/appointments/appointment", table_row: true, locals: {appointment: @appointment}) + render_to_portal("admin/appointments/appointment", table_row: true, locals: { appointment: @appointment }) end end end diff --git a/app/controllers/admin/appointment_holds_controller.rb b/app/controllers/admin/appointment_holds_controller.rb index 7fd4e1955..e6035613a 100644 --- a/app/controllers/admin/appointment_holds_controller.rb +++ b/app/controllers/admin/appointment_holds_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin class AppointmentHoldsController < ApplicationController before_action :are_appointments_enabled? @@ -9,57 +11,56 @@ def create def destroy remove_appointment_hold - redirect_to admin_appointment_path(appointment), flash: {success: "Item removed from appointment."} + redirect_to admin_appointment_path(appointment), flash: { success: "Item removed from appointment." } end private + def remove_appointment_hold + @remove_appointment_hold ||= appointment.appointment_holds.find_by(hold_id: params[:id]).destroy - def remove_appointment_hold - @remove_appointment_hold ||= appointment.appointment_holds.find_by(hold_id: params[:id]).destroy - - if params[:cancel_hold] - Hold.find(params[:id]).destroy + if params[:cancel_hold] + Hold.find(params[:id]).destroy + end end - end - def add_new_appointment_hold - return if item_to_add.blank? || - item_to_add.allow_one_holds_per_member? && - appointment.appointment_holds.joins(:hold).exists?(holds: {item: item_to_add}) + def add_new_appointment_hold + return if item_to_add.blank? || + item_to_add.allow_one_holds_per_member? && + appointment.appointment_holds.joins(:hold).exists?(holds: { item: item_to_add }) - new_appointment_hold.save - end + new_appointment_hold.save + end - def create_flash_message - if new_appointment_hold&.persisted? - {success: "Item added to appointment check-outs."} - else - {error: "Unable to add item to appointment check-outs."} + def create_flash_message + if new_appointment_hold&.persisted? + { success: "Item added to appointment check-outs." } + else + { error: "Unable to add item to appointment check-outs." } + end end - end - def new_appointment_hold - return if item_to_add.blank? + def new_appointment_hold + return if item_to_add.blank? - @new_appointment_hold ||= appointment.appointment_holds.new( - hold: hold_for_item_to_add - ) - end + @new_appointment_hold ||= appointment.appointment_holds.new( + hold: hold_for_item_to_add + ) + end - def hold_for_item_to_add - @item_to_add_hold ||= if item_to_add.allow_multiple_holds_per_member? - appointment.member.holds.new(item: item_to_add, creator: current_user) - elsif item_to_add.available? - appointment.member.active_holds.find_or_initialize_by(item: item_to_add, creator: current_user) + def hold_for_item_to_add + @item_to_add_hold ||= if item_to_add.allow_multiple_holds_per_member? + appointment.member.holds.new(item: item_to_add, creator: current_user) + elsif item_to_add.available? + appointment.member.active_holds.find_or_initialize_by(item: item_to_add, creator: current_user) + end end - end - def item_to_add - Item.find_by_complete_number(params.require(:appointment_hold)[:item_id].to_s) - end + def item_to_add + Item.find_by_complete_number(params.require(:appointment_hold)[:item_id].to_s) + end - def appointment - @appointment ||= Appointment.find(params[:appointment_id]) - end + def appointment + @appointment ||= Appointment.find(params[:appointment_id]) + end end end diff --git a/app/controllers/admin/appointment_loans_controller.rb b/app/controllers/admin/appointment_loans_controller.rb index 39f25cbbe..af36dcd22 100644 --- a/app/controllers/admin/appointment_loans_controller.rb +++ b/app/controllers/admin/appointment_loans_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin class AppointmentLoansController < ApplicationController before_action :are_appointments_enabled? @@ -9,48 +11,47 @@ def create def destroy remove_appointment_loan - redirect_to admin_appointment_path(appointment), flash: {success: "Item removed from appointment."} + redirect_to admin_appointment_path(appointment), flash: { success: "Item removed from appointment." } end private + def remove_appointment_loan + @remove_appointment_loan ||= appointment.appointment_loans.find_by(loan_id: params[:id]).destroy + end - def remove_appointment_loan - @remove_appointment_loan ||= appointment.appointment_loans.find_by(loan_id: params[:id]).destroy - end - - def add_new_appointment_loan - return if item_to_add.blank? || - appointment.appointment_loans.joins(:loan).exists?(loans: {item: item_to_add}) + def add_new_appointment_loan + return if item_to_add.blank? || + appointment.appointment_loans.joins(:loan).exists?(loans: { item: item_to_add }) - new_appointment_loan.save - end + new_appointment_loan.save + end - def create_flash_message - if new_appointment_loan&.persisted? - {success: "Item added to appointment check-ins."} - else - {error: "Unable to add item to appointment check-ins."} + def create_flash_message + if new_appointment_loan&.persisted? + { success: "Item added to appointment check-ins." } + else + { error: "Unable to add item to appointment check-ins." } + end end - end - def new_appointment_loan - return if item_to_add.blank? + def new_appointment_loan + return if item_to_add.blank? - @new_appointment_loan ||= appointment.appointment_loans.new( - loan: loan_for_item_to_add - ) - end + @new_appointment_loan ||= appointment.appointment_loans.new( + loan: loan_for_item_to_add + ) + end - def loan_for_item_to_add - @item_to_add_loan = appointment.member.loans.find_or_initialize_by(item: item_to_add) - end + def loan_for_item_to_add + @item_to_add_loan = appointment.member.loans.find_or_initialize_by(item: item_to_add) + end - def item_to_add - Item.find(params.require(:appointment_loan)[:item_id]) - end + def item_to_add + Item.find(params.require(:appointment_loan)[:item_id]) + end - def appointment - @appointment ||= Appointment.find(params[:appointment_id]) - end + def appointment + @appointment ||= Appointment.find(params[:appointment_id]) + end end end diff --git a/app/controllers/admin/appointments_controller.rb b/app/controllers/admin/appointments_controller.rb index 08844695a..ef95c0ccc 100644 --- a/app/controllers/admin/appointments_controller.rb +++ b/app/controllers/admin/appointments_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin class AppointmentsController < BaseController before_action :load_appointment, except: :index @@ -8,7 +10,7 @@ def index @appointments = Appointment .where(starts_at: @current_day.beginning_of_day..@current_day.end_of_day) .chronologically - .includes(:member, loans: {item: :borrow_policy}, holds: {item: :borrow_policy}) + .includes(:member, loans: { item: :borrow_policy }, holds: { item: :borrow_policy }) @pending_appointments = [] @completed_appointments = [] @@ -30,7 +32,7 @@ def edit def update if @appointment.update(appointment_params) - redirect_to admin_appointments_path, flash: {success: "Appointment updated."} + redirect_to admin_appointments_path, flash: { success: "Appointment updated." } else load_appointment_slots render :edit @@ -39,75 +41,74 @@ def update def destroy @appointment.destroy - redirect_to admin_appointments_path, flash: {success: "Appointment cancelled."} + redirect_to admin_appointments_path, flash: { success: "Appointment cancelled." } end private + def sort_by_member_and_time(appointments) + appointments + .group_by { |a| a.member } + .map { |member, appointments| [appointments.map(&:starts_at).min, appointments] } + .sort_by { |first_time, appointments| [first_time, helpers.preferred_or_default_name(appointments.first.member)] } + .flat_map { |_, appointments| appointments.sort_by(&:created_at) } + end - def sort_by_member_and_time(appointments) - appointments - .group_by { |a| a.member } - .map { |member, appointments| [appointments.map(&:starts_at).min, appointments] } - .sort_by { |first_time, appointments| [first_time, helpers.preferred_or_default_name(appointments.first.member)] } - .flat_map { |_, appointments| appointments.sort_by(&:created_at) } - end - - def load_appointment - @appointment = Appointment.find(params[:id]) - end + def load_appointment + @appointment = Appointment.find(params[:id]) + end - helper_method def previous_day - @current_day - 1.day - end + helper_method def previous_day + @current_day - 1.day + end - helper_method def next_day - @current_day + 1.day - end + helper_method def next_day + @current_day + 1.day + end - helper_method def current_day_label - if @current_day == Date.today - "Today" - elsif @current_day == Date.tomorrow - "Tomorrow" - else - l @current_day, format: :with_weekday + helper_method def current_day_label + if @current_day == Date.today + "Today" + elsif @current_day == Date.tomorrow + "Tomorrow" + else + l @current_day, format: :with_weekday + end end - end - helper_method def items_available_to_add_to_pickup - Item.available.eager_load(:borrow_policy) - end + helper_method def items_available_to_add_to_pickup + Item.available.eager_load(:borrow_policy) + end - helper_method def items_available_to_add_to_dropoff - (@appointment.member.loans.checked_out - appointment_return_items).map(&:item) - end + helper_method def items_available_to_add_to_dropoff + (@appointment.member.loans.checked_out - appointment_return_items).map(&:item) + end - helper_method def appointment_pickup_items - @appointment.holds - end + helper_method def appointment_pickup_items + @appointment.holds + end - helper_method def appointment_return_items - @appointment.loans - end + helper_method def appointment_return_items + @appointment.loans + end - helper_method def checkout_items_quantity_for_appointment - appointment_pickup_items.active.length - end + helper_method def checkout_items_quantity_for_appointment + appointment_pickup_items.active.length + end - helper_method def checkin_items_quantity_for_appointment - appointment_return_items.length - end + helper_method def checkin_items_quantity_for_appointment + appointment_return_items.length + end - def appointment_params - params.require(:appointment).permit(:time_range_string) - end + def appointment_params + params.require(:appointment).permit(:time_range_string) + end - def load_appointment_slots - events = Event.appointment_slots.upcoming - @appointment_slots = events.group_by { |event| event.start.to_date }.map { |date, events| - times = events.map { |event| [helpers.format_appointment_times(event.start, event.finish), event.start..event.finish] } - [date.strftime("%A, %B %-d, %Y"), times] - } - end + def load_appointment_slots + events = Event.appointment_slots.upcoming + @appointment_slots = events.group_by { |event| event.start.to_date }.map { |date, events| + times = events.map { |event| [helpers.format_appointment_times(event.start, event.finish), event.start..event.finish] } + [date.strftime("%A, %B %-d, %Y"), times] + } + end end end diff --git a/app/controllers/admin/base_controller.rb b/app/controllers/admin/base_controller.rb index 781649d38..a2056f762 100644 --- a/app/controllers/admin/base_controller.rb +++ b/app/controllers/admin/base_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin class BaseController < ApplicationController before_action :authenticate_user! @@ -7,27 +9,26 @@ class BaseController < ApplicationController layout "admin" private - - def require_staff - unless current_user.roles.include?(:staff) - redirect_to root_url, warning: "You do not have access to that page." + def require_staff + unless current_user.roles.include?(:staff) + redirect_to root_url, warning: "You do not have access to that page." + end end - end - def require_admin - unless current_user.roles.include?(:admin) - redirect_to root_url, warning: "You do not have access to that page." + def require_admin + unless current_user.roles.include?(:admin) + redirect_to root_url, warning: "You do not have access to that page." + end end - end - def load_requested_renewal_request_count - @requested_renewal_request_count = RenewalRequest.requested.count - end + def load_requested_renewal_request_count + @requested_renewal_request_count = RenewalRequest.requested.count + end - def are_appointments_enabled? - if !@current_library.allow_appointments? - render_not_found + def are_appointments_enabled? + if !@current_library.allow_appointments? + render_not_found + end end - end end end diff --git a/app/controllers/admin/borrow_policies_controller.rb b/app/controllers/admin/borrow_policies_controller.rb index 9242ee77d..d52c1b193 100644 --- a/app/controllers/admin/borrow_policies_controller.rb +++ b/app/controllers/admin/borrow_policies_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin class BorrowPoliciesController < BaseController before_action :set_borrow_policy, only: [:edit, :update, :destroy] @@ -18,13 +20,12 @@ def update end private + def set_borrow_policy + @borrow_policy = BorrowPolicy.find(params[:id]) + end - def set_borrow_policy - @borrow_policy = BorrowPolicy.find(params[:id]) - end - - def borrow_policy_params - params.require(:borrow_policy).permit(:name, :duration, :fine, :fine_period, :uniquely_numbered, :code, :description, :default, :renewal_limit, :member_renewable, :consumable, :rules) - end + def borrow_policy_params + params.require(:borrow_policy).permit(:name, :duration, :fine, :fine_period, :uniquely_numbered, :code, :description, :default, :renewal_limit, :member_renewable, :consumable, :rules) + end end end diff --git a/app/controllers/admin/bulk_renewals_controller.rb b/app/controllers/admin/bulk_renewals_controller.rb index fc42f521f..981e70d3d 100644 --- a/app/controllers/admin/bulk_renewals_controller.rb +++ b/app/controllers/admin/bulk_renewals_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin class BulkRenewalsController < BaseController include ActionView::RecordIdentifier @@ -14,9 +16,8 @@ def update end private - - def set_member - @member = Member.find(params[:id]) - end + def set_member + @member = Member.find(params[:id]) + end end end diff --git a/app/controllers/admin/categories_controller.rb b/app/controllers/admin/categories_controller.rb index 0ef99f290..8a7abbed8 100644 --- a/app/controllers/admin/categories_controller.rb +++ b/app/controllers/admin/categories_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin class CategoriesController < BaseController include ActionView::RecordIdentifier @@ -39,13 +41,12 @@ def destroy end private + def set_category + @category = Category.find(params[:id]) + end - def set_category - @category = Category.find(params[:id]) - end - - def category_params - params.require(:category).permit(:name, :slug, :parent_id) - end + def category_params + params.require(:category).permit(:name, :slug, :parent_id) + end end end diff --git a/app/controllers/admin/dashboard_controller.rb b/app/controllers/admin/dashboard_controller.rb index 56d2eeb33..af3e56fbd 100644 --- a/app/controllers/admin/dashboard_controller.rb +++ b/app/controllers/admin/dashboard_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin class DashboardController < BaseController def index diff --git a/app/controllers/admin/documents_controller.rb b/app/controllers/admin/documents_controller.rb index da887a93c..2c12bac4d 100644 --- a/app/controllers/admin/documents_controller.rb +++ b/app/controllers/admin/documents_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin class DocumentsController < BaseController before_action :set_document, only: [:show, :edit, :update] @@ -32,15 +34,14 @@ def update end private + # Use callbacks to share common setup or constraints between actions. + def set_document + @document = Document.coded(params[:id]).first! + end - # Use callbacks to share common setup or constraints between actions. - def set_document - @document = Document.coded(params[:id]).first! - end - - # Never trust parameters from the scary internet, only allow the white list through. - def document_params - params.require(:document).permit(:name, :summary, :body) - end + # Never trust parameters from the scary internet, only allow the white list through. + def document_params + params.require(:document).permit(:name, :summary, :body) + end end end diff --git a/app/controllers/admin/gift_memberships_controller.rb b/app/controllers/admin/gift_memberships_controller.rb index 83a9e3b3b..4e784b25f 100644 --- a/app/controllers/admin/gift_memberships_controller.rb +++ b/app/controllers/admin/gift_memberships_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin class GiftMembershipsController < BaseController include Pagy::Backend @@ -55,13 +57,12 @@ def destroy end private + def set_gift_membership + @gift_membership = GiftMembership.find(params[:id]) + end - def set_gift_membership - @gift_membership = GiftMembership.find(params[:id]) - end - - def gift_membership_params - params.require(:gift_membership).permit(:purchaser_email, :purchaser_name, :amount, :recipient_name) - end + def gift_membership_params + params.require(:gift_membership).permit(:purchaser_email, :purchaser_name, :amount, :recipient_name) + end end end diff --git a/app/controllers/admin/holds_controller.rb b/app/controllers/admin/holds_controller.rb index ebf7e6e4a..937e00541 100644 --- a/app/controllers/admin/holds_controller.rb +++ b/app/controllers/admin/holds_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin class HoldsController < BaseController include Pagy::Backend @@ -6,7 +8,5 @@ def index holds_scope = Hold.active.includes(:member, item: :borrow_policy).order("expires_at ASC NULLS LAST, created_at ASC") @pagy, @holds = pagy(holds_scope, items: 100) end - - private end end diff --git a/app/controllers/admin/images_controller.rb b/app/controllers/admin/images_controller.rb index 4f515cc14..ab34cc97c 100644 --- a/app/controllers/admin/images_controller.rb +++ b/app/controllers/admin/images_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin class ImagesController < BaseController before_action :load_image @@ -13,17 +15,16 @@ def update end private + def image_params + params.require(:image).permit(:rotation) + end - def image_params - params.require(:image).permit(:rotation) - end - - def load_image - @item = Item.find(params[:item_id]) - unless @item.image.attached? - redirect_to admin_item_path(@item), error: "Image not found" + def load_image + @item = Item.find(params[:item_id]) + unless @item.image.attached? + redirect_to admin_item_path(@item), error: "Image not found" + end + @image = @item.image end - @image = @item.image - end end end diff --git a/app/controllers/admin/item_histories_controller.rb b/app/controllers/admin/item_histories_controller.rb index ce8c5e22a..853379cf5 100644 --- a/app/controllers/admin/item_histories_controller.rb +++ b/app/controllers/admin/item_histories_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin class ItemHistoriesController < BaseController def show diff --git a/app/controllers/admin/item_holds_controller.rb b/app/controllers/admin/item_holds_controller.rb index d17fb3f8c..89501ff94 100644 --- a/app/controllers/admin/item_holds_controller.rb +++ b/app/controllers/admin/item_holds_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin class ItemHoldsController < BaseController def index diff --git a/app/controllers/admin/items/attachments_controller.rb b/app/controllers/admin/items/attachments_controller.rb index af9d89205..8eea4b2cd 100644 --- a/app/controllers/admin/items/attachments_controller.rb +++ b/app/controllers/admin/items/attachments_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin module Items class AttachmentsController < BaseController @@ -48,10 +50,9 @@ def show end private - - def attachment_params - params.require(:item_attachment).permit(:file, :kind, :other_kind, :notes) - end + def attachment_params + params.require(:item_attachment).permit(:file, :kind, :other_kind, :notes) + end end end end diff --git a/app/controllers/admin/items/base_controller.rb b/app/controllers/admin/items/base_controller.rb index 1bb0f5bae..df818ec5d 100644 --- a/app/controllers/admin/items/base_controller.rb +++ b/app/controllers/admin/items/base_controller.rb @@ -1,13 +1,14 @@ +# frozen_string_literal: true + module Admin module Items class BaseController < Admin::BaseController before_action :load_item private - - def load_item - @item = Item.find(params[:item_id]) - end + def load_item + @item = Item.find(params[:item_id]) + end end end end diff --git a/app/controllers/admin/items/tickets/ticket_updates_controller.rb b/app/controllers/admin/items/tickets/ticket_updates_controller.rb index c4994dee6..1797a67ca 100644 --- a/app/controllers/admin/items/tickets/ticket_updates_controller.rb +++ b/app/controllers/admin/items/tickets/ticket_updates_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin module Items module Tickets @@ -42,22 +44,21 @@ def destroy end private + def set_ticket + @ticket = @item.tickets.find(params[:ticket_id]) + end - def set_ticket - @ticket = @item.tickets.find(params[:ticket_id]) - end - - def set_ticket_update - @ticket_update = @ticket.ticket_updates.find(params[:id]) - end + def set_ticket_update + @ticket_update = @ticket.ticket_updates.find(params[:id]) + end - def ticket_update_create_params - params.require(:ticket_update_form).permit(:title, :time_spent, :body, :status).merge(creator: current_user) - end + def ticket_update_create_params + params.require(:ticket_update_form).permit(:title, :time_spent, :body, :status).merge(creator: current_user) + end - def ticket_update_update_params - params.require(:ticket_update).permit(:title, :time_spent, :body) - end + def ticket_update_update_params + params.require(:ticket_update).permit(:title, :time_spent, :body) + end end end end diff --git a/app/controllers/admin/items/tickets_controller.rb b/app/controllers/admin/items/tickets_controller.rb index 708cb6911..3d0305ed9 100644 --- a/app/controllers/admin/items/tickets_controller.rb +++ b/app/controllers/admin/items/tickets_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin module Items class TicketsController < BaseController @@ -44,14 +46,13 @@ def destroy end private + def set_ticket + @ticket = Ticket.find(params[:id]) + end - def set_ticket - @ticket = Ticket.find(params[:id]) - end - - def ticket_params - params.require(:ticket).permit(:title, :body, :status).merge(creator_id: current_user.id) - end + def ticket_params + params.require(:ticket).permit(:title, :body, :status).merge(creator_id: current_user.id) + end end end end diff --git a/app/controllers/admin/items_controller.rb b/app/controllers/admin/items_controller.rb index b0548d1ca..e8eb85c5d 100644 --- a/app/controllers/admin/items_controller.rb +++ b/app/controllers/admin/items_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin class ItemsController < BaseController include Pagy::Backend @@ -70,34 +72,33 @@ def destroy end private + def set_item + @item = Item.find(params[:id]) + end - def set_item - @item = Item.find(params[:id]) - end - - def set_categories - @categories = CategoryNode.all - end + def set_categories + @categories = CategoryNode.all + end - def item_params - all_item_params.except(:delete_image) - end + def item_params + all_item_params.except(:delete_image) + end - def all_item_params - params.require(:item).permit( - :name, :other_names, :description, :size, :brand, :model, :serial, :number, :image, :status, :strength, - :power_source, :borrow_policy_id, :quantity, :checkout_notice, :delete_image, :location_shelf, :location_area, :url, - :purchase_price, :purchase_link, :myturn_item_type, category_ids: [] - ) - end + def all_item_params + params.require(:item).permit( + :name, :other_names, :description, :size, :brand, :model, :serial, :number, :image, :status, :strength, + :power_source, :borrow_policy_id, :quantity, :checkout_notice, :delete_image, :location_shelf, :location_area, :url, + :purchase_price, :purchase_link, :myturn_item_type, category_ids: [] + ) + end - def index_order - options = { - "name" => "items.name ASC", - "number" => "items.number ASC", - "added" => "items.created_at DESC" - } - options.fetch(params[:sort]) { options["name"] } - end + def index_order + options = { + "name" => "items.name ASC", + "number" => "items.number ASC", + "added" => "items.created_at DESC" + } + options.fetch(params[:sort]) { options["name"] } + end end end diff --git a/app/controllers/admin/loan_histories_controller.rb b/app/controllers/admin/loan_histories_controller.rb index 325b544c3..12dd4b52e 100644 --- a/app/controllers/admin/loan_histories_controller.rb +++ b/app/controllers/admin/loan_histories_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin class LoanHistoriesController < BaseController def show diff --git a/app/controllers/admin/loan_summaries_controller.rb b/app/controllers/admin/loan_summaries_controller.rb index 0c7d2211f..092560d64 100644 --- a/app/controllers/admin/loan_summaries_controller.rb +++ b/app/controllers/admin/loan_summaries_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin class LoanSummariesController < BaseController include Pagy::Backend @@ -12,11 +14,10 @@ def index end private - - def index_filter - allowed = %w[checked_out overdue returned] - return params[:filter] if allowed.include? params[:filter] - "checked_out" - end + def index_filter + allowed = %w[checked_out overdue returned] + return params[:filter] if allowed.include? params[:filter] + "checked_out" + end end end diff --git a/app/controllers/admin/loans_controller.rb b/app/controllers/admin/loans_controller.rb index eceb892be..e37dc3f5c 100644 --- a/app/controllers/admin/loans_controller.rb +++ b/app/controllers/admin/loans_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin class LoansController < BaseController include ActionView::RecordIdentifier @@ -54,13 +56,12 @@ def destroy end private + def new_loan_params + params.require(:loan).permit(:item_id, :member_id) + end - def new_loan_params - params.require(:loan).permit(:item_id, :member_id) - end - - def update_loan_params - params.require(:loan).permit(:ended) - end + def update_loan_params + params.require(:loan).permit(:ended) + end end end diff --git a/app/controllers/admin/lookups_controller.rb b/app/controllers/admin/lookups_controller.rb index 93d785ddf..3c26b4fce 100644 --- a/app/controllers/admin/lookups_controller.rb +++ b/app/controllers/admin/lookups_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin class LookupsController < BaseController include PortalRendering @@ -11,7 +13,7 @@ def create @item = @lookup.item render_to_portal "admin/lookups/create" else - render_to_portal "admin/lookups/form", status: 422, locals: {lookup: @lookup} + render_to_portal "admin/lookups/form", status: 422, locals: { lookup: @lookup } end end diff --git a/app/controllers/admin/manage_features_controller.rb b/app/controllers/admin/manage_features_controller.rb index dbaa11fbd..917a2c768 100644 --- a/app/controllers/admin/manage_features_controller.rb +++ b/app/controllers/admin/manage_features_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin class ManageFeaturesController < BaseController def index @@ -14,17 +16,16 @@ def update end private + def check_for_edit + checked_value = { "0": false, "1": true } - def check_for_edit - checked_value = {"0": false, "1": true} - - library_feature_params.keys.each do |feature| - return true if checked_value[library_feature_params[feature].to_sym] != @current_library[feature] + library_feature_params.keys.each do |feature| + return true if checked_value[library_feature_params[feature].to_sym] != @current_library[feature] + end end - end - def library_feature_params - params.require(:library).permit(:allow_members, :allow_appointments, :allow_payments, :allow_volunteers) - end + def library_feature_params + params.require(:library).permit(:allow_members, :allow_appointments, :allow_payments, :allow_volunteers) + end end end diff --git a/app/controllers/admin/manual_imports_controller.rb b/app/controllers/admin/manual_imports_controller.rb index 47b4238fd..54774a15f 100644 --- a/app/controllers/admin/manual_imports_controller.rb +++ b/app/controllers/admin/manual_imports_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin class ManualImportsController < BaseController def edit @@ -17,9 +19,8 @@ def update end private - - def manual_import_params - params.require(:manual_import).permit(:url) - end + def manual_import_params + params.require(:manual_import).permit(:url) + end end end diff --git a/app/controllers/admin/maps_controller.rb b/app/controllers/admin/maps_controller.rb index bbe5dfe20..4c94ae7bb 100644 --- a/app/controllers/admin/maps_controller.rb +++ b/app/controllers/admin/maps_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin class MapsController < BaseController def show diff --git a/app/controllers/admin/members/adjustments_controller.rb b/app/controllers/admin/members/adjustments_controller.rb index 764c132d4..71d715349 100644 --- a/app/controllers/admin/members/adjustments_controller.rb +++ b/app/controllers/admin/members/adjustments_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin module Members class AdjustmentsController < BaseController diff --git a/app/controllers/admin/members/appointments_controller.rb b/app/controllers/admin/members/appointments_controller.rb index 84a37f3b3..da3050cc3 100644 --- a/app/controllers/admin/members/appointments_controller.rb +++ b/app/controllers/admin/members/appointments_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin module Members class AppointmentsController < BaseController @@ -14,7 +16,7 @@ def create @appointment = Appointment.new if update_appointment - redirect_to admin_appointment_path(@appointment), flash: {success: "Appointment created"} + redirect_to admin_appointment_path(@appointment), flash: { success: "Appointment created" } else flash[:alert] = @appointment.errors.full_messages redirect_to admin_member_appointments_path(@member) @@ -22,14 +24,13 @@ def create end private + def appointment_params + params.require(:appointment).permit(:time_range_string) + end - def appointment_params - params.require(:appointment).permit(:time_range_string) - end - - def update_appointment - @appointment.update(member: @member, time_range_string: appointment_params[:time_range_string], staff_updating: true) - end + def update_appointment + @appointment.update(member: @member, time_range_string: appointment_params[:time_range_string], staff_updating: true) + end end end end diff --git a/app/controllers/admin/members/base_controller.rb b/app/controllers/admin/members/base_controller.rb index 2cfed6ede..c26aef112 100644 --- a/app/controllers/admin/members/base_controller.rb +++ b/app/controllers/admin/members/base_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin module Members class BaseController < Admin::BaseController @@ -10,10 +12,9 @@ def are_appointments_enabled? end private - - def load_member - @member = Member.find(params[:member_id]) - end + def load_member + @member = Member.find(params[:member_id]) + end end end end diff --git a/app/controllers/admin/members/hold_loans_controller.rb b/app/controllers/admin/members/hold_loans_controller.rb index 4cc85d4a1..20f9e295f 100644 --- a/app/controllers/admin/members/hold_loans_controller.rb +++ b/app/controllers/admin/members/hold_loans_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin module Members class HoldLoansController < BaseController diff --git a/app/controllers/admin/members/holds_controller.rb b/app/controllers/admin/members/holds_controller.rb index 7d8117e6c..94e5df066 100644 --- a/app/controllers/admin/members/holds_controller.rb +++ b/app/controllers/admin/members/holds_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin module Members class HoldsController < BaseController @@ -46,10 +48,9 @@ def history end private - - def new_hold_params - params.require(:hold).permit(:item_id) - end + def new_hold_params + params.require(:hold).permit(:item_id) + end end end end diff --git a/app/controllers/admin/members/loan_summaries_controller.rb b/app/controllers/admin/members/loan_summaries_controller.rb index 30af2de9a..908239caf 100644 --- a/app/controllers/admin/members/loan_summaries_controller.rb +++ b/app/controllers/admin/members/loan_summaries_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin module Members class LoanSummariesController < BaseController diff --git a/app/controllers/admin/members/lookups_controller.rb b/app/controllers/admin/members/lookups_controller.rb index c2a31cdb2..91e5ca80f 100644 --- a/app/controllers/admin/members/lookups_controller.rb +++ b/app/controllers/admin/members/lookups_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin module Members class LookupsController < BaseController @@ -12,7 +14,7 @@ def create @item = @lookup.item render_to_portal "admin/members/lookups/create" else - render_to_portal "admin/members/lookups/form", status: 422, locals: {lookup: @lookup} + render_to_portal "admin/members/lookups/form", status: 422, locals: { lookup: @lookup } end end diff --git a/app/controllers/admin/members/memberships_controller.rb b/app/controllers/admin/members/memberships_controller.rb index 03ddef6ad..18749bed2 100644 --- a/app/controllers/admin/members/memberships_controller.rb +++ b/app/controllers/admin/members/memberships_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin module Members class MembershipsController < BaseController @@ -32,10 +34,9 @@ def update end private - - def membership_form_params - params.require(:membership_form).permit(:amount_dollars, :payment_source, :with_payment, :start_membership) - end + def membership_form_params + params.require(:membership_form).permit(:amount_dollars, :payment_source, :with_payment, :start_membership) + end end end end diff --git a/app/controllers/admin/members/notifications_controller.rb b/app/controllers/admin/members/notifications_controller.rb index 765d3e51f..7d9f3e54a 100644 --- a/app/controllers/admin/members/notifications_controller.rb +++ b/app/controllers/admin/members/notifications_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin module Members class NotificationsController < BaseController diff --git a/app/controllers/admin/members/payments_controller.rb b/app/controllers/admin/members/payments_controller.rb index 9589b7699..973190b44 100644 --- a/app/controllers/admin/members/payments_controller.rb +++ b/app/controllers/admin/members/payments_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin module Members class PaymentsController < BaseController @@ -19,14 +21,13 @@ def create end private + def default_payment_value + Money.new([-@member.account_balance, 0].max) + end - def default_payment_value - Money.new([-@member.account_balance, 0].max) - end - - def payment_params - params.require(:admin_payment).permit(:amount_dollars, :payment_source) - end + def payment_params + params.require(:admin_payment).permit(:amount_dollars, :payment_source) + end end end end diff --git a/app/controllers/admin/members/verifications_controller.rb b/app/controllers/admin/members/verifications_controller.rb index 274c267d7..6beb4b862 100644 --- a/app/controllers/admin/members/verifications_controller.rb +++ b/app/controllers/admin/members/verifications_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin module Members class VerificationsController < BaseController @@ -26,17 +28,16 @@ def update end private - - def load_member - super - if @member.status_verified? - redirect_to admin_members_path, warning: "Member is already verified." + def load_member + super + if @member.status_verified? + redirect_to admin_members_path, warning: "Member is already verified." + end end - end - def verification_params - params.require(:admin_verification).permit(:id_kind, :other_id_kind, :address_verified) - end + def verification_params + params.require(:admin_verification).permit(:id_kind, :other_id_kind, :address_verified) + end end end end diff --git a/app/controllers/admin/members_controller.rb b/app/controllers/admin/members_controller.rb index 0c4081d99..1626539ec 100644 --- a/app/controllers/admin/members_controller.rb +++ b/app/controllers/admin/members_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin class MembersController < BaseController include Pagy::Backend @@ -58,17 +60,16 @@ def destroy end private + def set_member + @member = Member.find(params[:id]) + end - def set_member - @member = Member.find(params[:id]) - end - - def member_params - params.require(:member).permit( - :full_name, :pronunciation, :preferred_name, :email, :phone_number, :postal_code, - :desires, :reminders_via_email, :reminders_via_text, :receive_newsletter, :volunteer_interest, :bio, - :status, :address1, :address2, pronouns: [] - ) - end + def member_params + params.require(:member).permit( + :full_name, :pronunciation, :preferred_name, :email, :phone_number, :postal_code, + :desires, :reminders_via_email, :reminders_via_text, :receive_newsletter, :volunteer_interest, :bio, + :status, :address1, :address2, pronouns: [] + ) + end end end diff --git a/app/controllers/admin/notes_controller.rb b/app/controllers/admin/notes_controller.rb index 33334c468..9b4a3acf5 100644 --- a/app/controllers/admin/notes_controller.rb +++ b/app/controllers/admin/notes_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin class NotesController < BaseController include ActionView::RecordIdentifier @@ -11,7 +13,7 @@ def create if @note.save redirect_to [:admin, @parent, anchor: dom_id(@note)] else - render_to_portal "form", locals: {parent: @parent, note: @note}, status: 422 + render_to_portal "form", locals: { parent: @parent, note: @note }, status: 422 end end @@ -21,7 +23,7 @@ def update if @note.update(note_params) redirect_to [:admin, @parent, anchor: dom_id(@note)] else - render_to_portal "form", locals: {parent: @parent, note: @note}, status: 422 + render_to_portal "form", locals: { parent: @parent, note: @note }, status: 422 end end @@ -33,35 +35,34 @@ def edit @note = @parent.notes.find(params[:id]) if @parent.is_a?(Member) - render "_form", locals: {parent: @parent, note: @note} + render "_form", locals: { parent: @parent, note: @note } else - render_to_portal "form", locals: {parent: @parent, note: @note} + render_to_portal "form", locals: { parent: @parent, note: @note } end end def show @note = @parent.notes.find(params[:id]) - render_to_portal "show", locals: {parent: @parent, note: @note} + render_to_portal "show", locals: { parent: @parent, note: @note } end def destroy @parent.notes.find(params[:id]).destroy! - redirect_to [:admin, @parent], flash: {success: "Note has been deleted."} + redirect_to [:admin, @parent], flash: { success: "Note has been deleted." } end private + def note_params + params.require(:note).permit(:body) + end - def note_params - params.require(:note).permit(:body) - end - - def load_parent - if params[:item_id] - @parent = Item.find(params[:item_id]) - elsif params[:member_id] - @parent = Member.find(params[:member_id]) + def load_parent + if params[:item_id] + @parent = Item.find(params[:item_id]) + elsif params[:member_id] + @parent = Member.find(params[:member_id]) + end + raise ActiveRecord::RecordNotFound unless @parent end - raise ActiveRecord::RecordNotFound unless @parent - end end end diff --git a/app/controllers/admin/renewal_requests_controller.rb b/app/controllers/admin/renewal_requests_controller.rb index 970516ade..f86e0fe04 100644 --- a/app/controllers/admin/renewal_requests_controller.rb +++ b/app/controllers/admin/renewal_requests_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin class RenewalRequestsController < BaseController include Pagy::Backend @@ -6,7 +8,7 @@ class RenewalRequestsController < BaseController def index renewal_requests_scope = RenewalRequest.send(index_filter) .order(created_at: :desc) - .includes(loan: [{item: :borrow_policy}, :member, :renewals]) + .includes(loan: [{ item: :borrow_policy }, :member, :renewals]) @pagy, @renewal_requests = pagy(renewal_requests_scope, items: 50) end @@ -23,24 +25,23 @@ def update flash_message = if @renewal_request.update(renewal_request_params) renew_loan(@renewal_request.loan) if @renewal_request.approved? MemberMailer.with(renewal_request: @renewal_request).renewal_request_updated.deliver_later - {success: "Renewal request updated."} + { success: "Renewal request updated." } else - {error: "Something went wrong!"} + { error: "Something went wrong!" } end redirect_to admin_renewal_requests_url, flash: flash_message end private + def index_filter + allowed = %w[all requested rejected] + return params[:filter] if allowed.include? params[:filter] + "all" + end - def index_filter - allowed = %w[all requested rejected] - return params[:filter] if allowed.include? params[:filter] - "all" - end - - def renewal_request_params - params.require(:renewal_request).permit(:status) - end + def renewal_request_params + params.require(:renewal_request).permit(:status) + end end end diff --git a/app/controllers/admin/renewals_controller.rb b/app/controllers/admin/renewals_controller.rb index f5d502e14..b281ce454 100644 --- a/app/controllers/admin/renewals_controller.rb +++ b/app/controllers/admin/renewals_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin class RenewalsController < BaseController include ActionView::RecordIdentifier diff --git a/app/controllers/admin/reports/items_in_maintenance_controller.rb b/app/controllers/admin/reports/items_in_maintenance_controller.rb index 727c8d37e..6b9ef7a65 100644 --- a/app/controllers/admin/reports/items_in_maintenance_controller.rb +++ b/app/controllers/admin/reports/items_in_maintenance_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin module Reports class ItemsInMaintenanceController < BaseController diff --git a/app/controllers/admin/reports/items_without_image_controller.rb b/app/controllers/admin/reports/items_without_image_controller.rb index 494985d5f..0ed5a809d 100644 --- a/app/controllers/admin/reports/items_without_image_controller.rb +++ b/app/controllers/admin/reports/items_without_image_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin module Reports class ItemsWithoutImageController < BaseController diff --git a/app/controllers/admin/reports/member_requests_controller.rb b/app/controllers/admin/reports/member_requests_controller.rb index 5f600a79b..b76c6c082 100644 --- a/app/controllers/admin/reports/member_requests_controller.rb +++ b/app/controllers/admin/reports/member_requests_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin module Reports class MemberRequestsController < BaseController diff --git a/app/controllers/admin/reports/memberships_controller.rb b/app/controllers/admin/reports/memberships_controller.rb index 111fd91cc..9fc44e678 100644 --- a/app/controllers/admin/reports/memberships_controller.rb +++ b/app/controllers/admin/reports/memberships_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "csv" module Admin @@ -44,7 +46,7 @@ def index } filename = Time.current.strftime("memberships_%-m/%-d/%Y.csv") - send_data text, filename: filename + send_data text, filename: end end end diff --git a/app/controllers/admin/reports/money_controller.rb b/app/controllers/admin/reports/money_controller.rb index 289fba1e8..95abc4f56 100644 --- a/app/controllers/admin/reports/money_controller.rb +++ b/app/controllers/admin/reports/money_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin module Reports class MoneyController < BaseController diff --git a/app/controllers/admin/reports/monthly_activities_controller.rb b/app/controllers/admin/reports/monthly_activities_controller.rb index 995a96260..0b3416c47 100644 --- a/app/controllers/admin/reports/monthly_activities_controller.rb +++ b/app/controllers/admin/reports/monthly_activities_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin module Reports class MonthlyActivitiesController < BaseController diff --git a/app/controllers/admin/reports/notifications_controller.rb b/app/controllers/admin/reports/notifications_controller.rb index 92bdefab3..5cf104e3c 100644 --- a/app/controllers/admin/reports/notifications_controller.rb +++ b/app/controllers/admin/reports/notifications_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin module Reports class NotificationsController < BaseController diff --git a/app/controllers/admin/reports/potential_volunteers_controller.rb b/app/controllers/admin/reports/potential_volunteers_controller.rb index 5d28bbde9..3202a7a0d 100644 --- a/app/controllers/admin/reports/potential_volunteers_controller.rb +++ b/app/controllers/admin/reports/potential_volunteers_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "csv" module Admin @@ -20,7 +22,7 @@ def index } filename = Time.current.strftime("potential_volunteers_%-m/%-d/%Y.csv") - send_data text, filename: filename + send_data text, filename: end end end diff --git a/app/controllers/admin/reports/shifts_controller.rb b/app/controllers/admin/reports/shifts_controller.rb index dda3d48cf..ec7c45368 100644 --- a/app/controllers/admin/reports/shifts_controller.rb +++ b/app/controllers/admin/reports/shifts_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin module Reports class ShiftsController < BaseController diff --git a/app/controllers/admin/reports/zipcodes_controller.rb b/app/controllers/admin/reports/zipcodes_controller.rb index 4c9b879d8..2ec3c76e0 100644 --- a/app/controllers/admin/reports/zipcodes_controller.rb +++ b/app/controllers/admin/reports/zipcodes_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "csv" module Admin @@ -18,7 +20,7 @@ def index } filename = Time.current.strftime("zipcodes_%-m/%-d/%Y.csv") - send_data text, filename: filename + send_data text, filename: end end end diff --git a/app/controllers/admin/searches_controller.rb b/app/controllers/admin/searches_controller.rb index f8eab44da..455e64b2b 100644 --- a/app/controllers/admin/searches_controller.rb +++ b/app/controllers/admin/searches_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin class SearchesController < BaseController def create @@ -9,7 +11,7 @@ def create # member = Member.matching(query).first # redirect_to(admin_member_path(member)) && return if member - redirect_to admin_search_path(query: query) + redirect_to admin_search_path(query:) end def show diff --git a/app/controllers/admin/settings/closing_controller.rb b/app/controllers/admin/settings/closing_controller.rb index 487a70958..5a5ebe88c 100644 --- a/app/controllers/admin/settings/closing_controller.rb +++ b/app/controllers/admin/settings/closing_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Admin::Settings::ClosingController < Admin::BaseController before_action :require_admin @@ -21,8 +23,7 @@ def extend_holds end private - - def form_params - params.require(:extend_holds_form).permit(:date) - end + def form_params + params.require(:extend_holds_form).permit(:date) + end end diff --git a/app/controllers/admin/settings/email_settings_controller.rb b/app/controllers/admin/settings/email_settings_controller.rb index 2a5245117..a9e04f434 100644 --- a/app/controllers/admin/settings/email_settings_controller.rb +++ b/app/controllers/admin/settings/email_settings_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin module Settings class EmailSettingsController < BaseController @@ -20,10 +22,9 @@ def preview end private - - def email_settings_params - params.require(:library).permit(:email_banner1, :email_banner2) - end + def email_settings_params + params.require(:library).permit(:email_banner1, :email_banner2) + end end end end diff --git a/app/controllers/admin/settings/exports_controller.rb b/app/controllers/admin/settings/exports_controller.rb index 3bf33b7b2..c506bd10d 100644 --- a/app/controllers/admin/settings/exports_controller.rb +++ b/app/controllers/admin/settings/exports_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Admin::Settings::ExportsController < Admin::BaseController include ActionController::Live @@ -19,16 +21,15 @@ def members end private - - def export(filename, exporter) - send_file_headers!( - type: "text/csv", - disposition: "attachment", - filename: filename - ) - response.headers["Last-Modified"] = Time.now.httpdate - exporter.export(response.stream) - ensure - response.stream.close - end + def export(filename, exporter) + send_file_headers!( + type: "text/csv", + disposition: "attachment", + filename: + ) + response.headers["Last-Modified"] = Time.now.httpdate + exporter.export(response.stream) + ensure + response.stream.close + end end diff --git a/app/controllers/admin/settings/library_updates_controller.rb b/app/controllers/admin/settings/library_updates_controller.rb index 0b8bd3a83..240dc54c1 100644 --- a/app/controllers/admin/settings/library_updates_controller.rb +++ b/app/controllers/admin/settings/library_updates_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Admin::Settings::LibraryUpdatesController < Admin::BaseController before_action :require_admin include ActionView::RecordIdentifier @@ -39,12 +41,11 @@ def destroy end private + def set_library_update + @library_update = LibraryUpdate.find(params[:id]) + end - def set_library_update - @library_update = LibraryUpdate.find(params[:id]) - end - - def library_update_params - params.require(:library_update).permit(:title, :body, :published) - end + def library_update_params + params.require(:library_update).permit(:title, :body, :published) + end end diff --git a/app/controllers/admin/ui_controller.rb b/app/controllers/admin/ui_controller.rb index c31dd1f75..ce26b3c8c 100644 --- a/app/controllers/admin/ui_controller.rb +++ b/app/controllers/admin/ui_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin class UIController < BaseController def names diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index d7fc1bdc8..bd54939c3 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin class UsersController < BaseController before_action :set_user, only: [:show, :edit, :update, :destroy] @@ -19,7 +21,7 @@ def edit def create password = Devise.friendly_token.first(16) - @user = User.new(user_params.merge(password: password)) + @user = User.new(user_params.merge(password:)) if @user.save redirect_to admin_users_url, success: "User was successfully created." @@ -42,15 +44,14 @@ def destroy end private + def set_user + @user = User.find(params[:id]) + end - def set_user - @user = User.find(params[:id]) - end - - def user_params - parameters = params.require(:user).permit(:email, :role) - parameters.delete("role") unless current_user.has_role?(params.dig("user", "role")) - parameters - end + def user_params + parameters = params.require(:user).permit(:email, :role) + parameters.delete("role") unless current_user.has_role?(params.dig("user", "role")) + parameters + end end end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 4ee6f4167..4098fc453 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "active_support/testing/time_helpers" class ApplicationController < ActionController::Base @@ -23,62 +25,58 @@ def are_appointments_enabled? end private - - def override_time_in_development(&block) - if session[:time_override] - travel_to session[:time_override] do + def override_time_in_development(&block) + if session[:time_override] + travel_to session[:time_override], &block + else yield end - else - yield end - end - def current_member - current_user.member - end + def current_member + current_user.member + end - def current_library - @current_library ||= Library.find_by(hostname: request.host.downcase) || Library.first - end + def current_library + @current_library ||= Library.find_by(hostname: request.host.downcase) || Library.first + end private - - def set_tenant - if current_library - set_current_tenant current_library - else - Rails.logger.debug "No Library found for the provided hostname" - render_not_found + def set_tenant + if current_library + set_current_tenant current_library + else + Rails.logger.debug "No Library found for the provided hostname" + render_not_found + end end - end - def set_time_zone(&block) - Time.use_zone "America/Chicago" do - Chronic.time_class = Time.zone - block.call + def set_time_zone(&block) + Time.use_zone "America/Chicago" do + Chronic.time_class = Time.zone + block.call + end end - end - def set_raven_context - if user_signed_in? - Raven.user_context(id: current_user.id, member_id: current_member.try(:id)) + def set_raven_context + if user_signed_in? + Raven.user_context(id: current_user.id, member_id: current_member.try(:id)) + end end - end - def render_not_found - render "errors/show", status: :not_found - end + def render_not_found + render "errors/show", status: :not_found + end - def after_sign_in_path_for(user) - return super_admin_libraries_path if user.super_admin? + def after_sign_in_path_for(user) + return super_admin_libraries_path if user.super_admin? - referer = stored_location_for(user) - default_path = user.admin? || user.staff? ? admin_dashboard_path : account_home_path - if referer.eql? root_path - default_path - else - referer || default_path + referer = stored_location_for(user) + default_path = user.admin? || user.staff? ? admin_dashboard_path : account_home_path + if referer.eql? root_path + default_path + else + referer || default_path + end end - end end diff --git a/app/controllers/concerns/appointment_slots.rb b/app/controllers/concerns/appointment_slots.rb index 68d30807d..dd8a61683 100644 --- a/app/controllers/concerns/appointment_slots.rb +++ b/app/controllers/concerns/appointment_slots.rb @@ -1,11 +1,12 @@ +# frozen_string_literal: true + module AppointmentSlots private - - def load_appointment_slots - events = Event.appointment_slots - @appointment_slots = events.group_by { |event| event.start.to_date }.map { |date, events| - times = events.map { |event| [helpers.format_appointment_times(event.start, event.finish), event.start..event.finish] } - [date.strftime("%A, %B %-d, %Y"), times] - } - end + def load_appointment_slots + events = Event.appointment_slots + @appointment_slots = events.group_by { |event| event.start.to_date }.map { |date, events| + times = events.map { |event| [helpers.format_appointment_times(event.start, event.finish), event.start..event.finish] } + [date.strftime("%A, %B %-d, %Y"), times] + } + end end diff --git a/app/controllers/concerns/calendaring.rb b/app/controllers/concerns/calendaring.rb index 9fb96b115..fcca4c0c7 100644 --- a/app/controllers/concerns/calendaring.rb +++ b/app/controllers/concerns/calendaring.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Calendaring extend ActiveSupport::Concern diff --git a/app/controllers/concerns/lending.rb b/app/controllers/concerns/lending.rb index 6f8289766..263cec048 100644 --- a/app/controllers/concerns/lending.rb +++ b/app/controllers/concerns/lending.rb @@ -1,111 +1,112 @@ +# frozen_string_literal: true + module Lending private - - def create_loan(item, member, now: Time.current) - loan = Loan.lend(item, to: member, now: now) - loan.transaction do - if loan.save - if item.borrow_policy.consumable? && return_loan(loan, now: now) - item.decrement_quantity + def create_loan(item, member, now: Time.current) + loan = Loan.lend(item, to: member, now:) + loan.transaction do + if loan.save + if item.borrow_policy.consumable? && return_loan(loan, now:) + item.decrement_quantity + end + loan + else + false end - loan - else - false end end - end - def create_loan_from_hold(hold, now: Time.current) - hold.transaction do - create_loan(hold.item, hold.member, now: now).tap do |loan| - hold.update!(loan: loan, ended_at: now) + def create_loan_from_hold(hold, now: Time.current) + hold.transaction do + create_loan(hold.item, hold.member, now:).tap do |loan| + hold.update!(loan:, ended_at: now) + end end end - end - def return_loan(loan, now: Time.current) - success = false - policy = loan.item.borrow_policy + def return_loan(loan, now: Time.current) + success = false + policy = loan.item.borrow_policy - loan.transaction do - next unless loan.update(ended_at: now) + loan.transaction do + next unless loan.update(ended_at: now) - amount = FineCalculator.new.amount(fine: policy.fine, period: policy.fine_period, due_at: loan.due_at, returned_at: loan.ended_at) - if amount > 0 - Adjustment.create!(member_id: loan.member_id, adjustable: loan, amount: amount * -1, kind: "fine") - end + amount = FineCalculator.new.amount(fine: policy.fine, period: policy.fine_period, due_at: loan.due_at, returned_at: loan.ended_at) + if amount > 0 + Adjustment.create!(member_id: loan.member_id, adjustable: loan, amount: amount * -1, kind: "fine") + end - # reject any renewal requests to avoid confusion - loan.renewal_requests.requested.each do |renewal_request| - renewal_request.update!(status: "rejected") + # reject any renewal requests to avoid confusion + loan.renewal_requests.requested.each do |renewal_request| + renewal_request.update!(status: "rejected") + end + + success = true end - success = true + success ? loan : false end - success ? loan : false - end - - def undo_loan(loan) - return false if loan.renewal? - loan.transaction do - loan.destroy - if loan.item.borrow_policy.consumable? - loan.item.increment_quantity + def undo_loan(loan) + return false if loan.renewal? + loan.transaction do + loan.destroy + if loan.item.borrow_policy.consumable? + loan.item.increment_quantity + end end end - end - - def restore_loan(loan) - loan.update(ended_at: nil) - end - - def renew_loan(loan, now: Time.current) - success = false - period_start_date = [loan.due_at, now.end_of_day].max - new_loan = Loan.new( - member_id: loan.member_id, - item_id: loan.item_id, - initial_loan_id: loan.initial_loan_id || loan.id, - renewal_count: loan.renewal_count + 1, - due_at: Loan.next_open_day(period_start_date + loan.item.borrow_policy.duration.days), - uniquely_numbered: loan.uniquely_numbered, - created_at: now - ) - - loan.transaction do - next unless return_loan(loan, now: now) - new_loan.save! - - # update any appointments connected with the old loan - AppointmentLoan.where(loan_id: loan).update_all(loan_id: new_loan.id) - - success = true + + def restore_loan(loan) + loan.update(ended_at: nil) end - success ? new_loan : false - end + def renew_loan(loan, now: Time.current) + success = false + period_start_date = [loan.due_at, now.end_of_day].max + new_loan = Loan.new( + member_id: loan.member_id, + item_id: loan.item_id, + initial_loan_id: loan.initial_loan_id || loan.id, + renewal_count: loan.renewal_count + 1, + due_at: Loan.next_open_day(period_start_date + loan.item.borrow_policy.duration.days), + uniquely_numbered: loan.uniquely_numbered, + created_at: now + ) + + loan.transaction do + next unless return_loan(loan, now:) + new_loan.save! + + # update any appointments connected with the old loan + AppointmentLoan.where(loan_id: loan).update_all(loan_id: new_loan.id) + + success = true + end - def undo_loan_renewal(loan) - success = false - target = nil + success ? new_loan : false + end - loan.transaction do - next unless loan.destroy + def undo_loan_renewal(loan) + success = false + target = nil - target = if loan.renewal_count > 1 - loan.initial_loan.renewals.order(created_at: :desc).where.not(id: loan.id).first - else - loan.initial_loan - end - target.update!(ended_at: nil) + loan.transaction do + next unless loan.destroy - # update any appointments connected with the reverted loan - AppointmentLoan.where(loan_id: loan).update_all(loan_id: target.id) + target = if loan.renewal_count > 1 + loan.initial_loan.renewals.order(created_at: :desc).where.not(id: loan.id).first + else + loan.initial_loan + end + target.update!(ended_at: nil) - success = true - end + # update any appointments connected with the reverted loan + AppointmentLoan.where(loan_id: loan).update_all(loan_id: target.id) + + success = true + end - success ? target : false - end + success ? target : false + end end diff --git a/app/controllers/concerns/member_ordering.rb b/app/controllers/concerns/member_ordering.rb index 64b0e778f..218caf5e1 100644 --- a/app/controllers/concerns/member_ordering.rb +++ b/app/controllers/concerns/member_ordering.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module MemberOrdering def index_order options = { diff --git a/app/controllers/concerns/page_attributes.rb b/app/controllers/concerns/page_attributes.rb index caf9983f8..d4bdc605f 100644 --- a/app/controllers/concerns/page_attributes.rb +++ b/app/controllers/concerns/page_attributes.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # PageAttributes provides a consise API for declaring bits of page metadata # within controller methods, stored as a Hash on the controller instance. # @@ -9,19 +11,18 @@ def self.included(base) end private + def set_page_attr(key, value) + @page_attributes ||= {} + @page_attributes[key] = value + value + end - def set_page_attr(key, value) - @page_attributes ||= {} - @page_attributes[key] = value - value - end + def page_attr(key) + @page_attributes ||= {} + @page_attributes[key] + end - def page_attr(key) - @page_attributes ||= {} - @page_attributes[key] - end - - def page_attr?(key) - @page_attributes&.has_key?(key) - end + def page_attr?(key) + @page_attributes&.has_key?(key) + end end diff --git a/app/controllers/concerns/portal_rendering.rb b/app/controllers/concerns/portal_rendering.rb index b443725a7..75d7f1744 100644 --- a/app/controllers/concerns/portal_rendering.rb +++ b/app/controllers/concerns/portal_rendering.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module PortalRendering def render_to_portal(partial, options = {}) table_row = options.delete(:table_row) diff --git a/app/controllers/dev_controller.rb b/app/controllers/dev_controller.rb index ac9249307..25c5b3183 100644 --- a/app/controllers/dev_controller.rb +++ b/app/controllers/dev_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class DevController < ApplicationController def set_time new_time = Time.zone.parse params[:new_time] diff --git a/app/controllers/documents_controller.rb b/app/controllers/documents_controller.rb index d91c705d0..a2e8b97ee 100644 --- a/app/controllers/documents_controller.rb +++ b/app/controllers/documents_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class DocumentsController < ApplicationController def show @document = Document.find_by!(code: params[:id]) diff --git a/app/controllers/errors_controller.rb b/app/controllers/errors_controller.rb index 5d7158062..1efc37634 100644 --- a/app/controllers/errors_controller.rb +++ b/app/controllers/errors_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ErrorsController < ApplicationController def show @status_code = params[:code]&.to_i || 500 @@ -8,34 +10,33 @@ def show end private - - def error_content - case @status_code - when 404 - { - title: "Page not found", - message: "The page you were looking for could not be found." - } - when 422 - { - title: "Unprocessable entity", - message: "The page you were looking for could not be processed." - } - when 500 - { - title: "Internal server error", - message: "Something went wrong." - } - when 503 - { - title: "Service unavailable", - message: "The service you were looking for is unavailable." - } - else - { - title: "Error", - message: "Something went wrong." - } + def error_content + case @status_code + when 404 + { + title: "Page not found", + message: "The page you were looking for could not be found." + } + when 422 + { + title: "Unprocessable entity", + message: "The page you were looking for could not be processed." + } + when 500 + { + title: "Internal server error", + message: "Something went wrong." + } + when 503 + { + title: "Service unavailable", + message: "The service you were looking for is unavailable." + } + else + { + title: "Error", + message: "Something went wrong." + } + end end - end end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 49955061f..2e4941018 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class HomeController < ApplicationController before_action :index do redirect_to account_home_url if user_signed_in? diff --git a/app/controllers/homepage_controller.rb b/app/controllers/homepage_controller.rb index c3ea72ec4..8b74b2dae 100644 --- a/app/controllers/homepage_controller.rb +++ b/app/controllers/homepage_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class HomepageController < ApplicationController layout "homepage" @@ -12,8 +14,7 @@ def create end private - - def homepage_params - params.permit(homepage: %i[name email city state country description inventory]) - end + def homepage_params + params.permit(homepage: %i[name email city state country description inventory]) + end end diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb index 76bc60551..40c46569c 100644 --- a/app/controllers/items_controller.rb +++ b/app/controllers/items_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ItemsController < ApplicationController include Pagy::Backend @@ -30,70 +32,69 @@ def show end private + def filter_params + @filter_params ||= params.permit(:sort, :category, :query).to_h.each_with_object({}) do |(k, v), filtered| + value = v&.to_s&.strip&.presence - def filter_params - @filter_params ||= params.permit(:sort, :category, :query).to_h.each_with_object({}) do |(k, v), filtered| - value = v&.to_s&.strip&.presence - - next unless value + next unless value - filtered[k.to_sym] = value + filtered[k.to_sym] = value + end end - end - def set_index_page_title - return unless @query || @category + def set_index_page_title + return unless @query || @category - if @query - title = "Search results for #{@query}" - title << "in #{@category.name}" if @category - else - title = @category.name + if @query + title = "Search results for #{@query}" + title << "in #{@category.name}" if @category + else + title = @category.name + end + + set_page_attr(:title, title) end - set_page_attr(:title, title) - end + def filter_by_category(item_scope) + @category = CategoryNode.find_by(id: params[:category]) - def filter_by_category(item_scope) - @category = CategoryNode.find_by(id: params[:category]) + return filter_failed(:category, "Category not found") unless @category - return filter_failed(:category, "Category not found") unless @category + item_scope.for_category(@category) + end - item_scope.for_category(@category) - end + def filter_by_query(item_scope) + @query = filter_params[:query].to_s.strip.presence - def filter_by_query(item_scope) - @query = filter_params[:query].to_s.strip.presence + return item_scope unless @query - return item_scope unless @query + if @query.size < 3 + flash.now[:warning] = "You must provide at least three numbers or letters to search by." + filter_params.delete(:query) + return item_scope + end - if @query.size < 3 - flash.now[:warning] = "You must provide at least three numbers or letters to search by." - filter_params.delete(:query) - return item_scope + scope = item_scope.search_by_anything(@query) + scope.select("#{scope.pg_search_rank_table_alias}.rank", "items.*") end - scope = item_scope.search_by_anything(@query) - scope.select("#{scope.pg_search_rank_table_alias}.rank", "items.*") - end + def filter_failed(failed_param, error_message) + filter_params = %i[sort category query].each_with_object({}) do |filter_param, accepted_params| + next if filter_param == failed_param + next if params[:filter_param].blank? - def filter_failed(failed_param, error_message) - filter_params = %i[sort category query].each_with_object({}) do |filter_param, accepted_params| - next if filter_param == failed_param - next if params[:filter_param].blank? + accepted_params[filter_param] = params[filter_param] + end - accepted_params[filter_param] = params[filter_param] + redirect_to(items_path(filter_params), error: error_message) end - redirect_to(items_path(filter_params), error: error_message) - end - - def index_order - options = { - "name" => "items.name ASC", - "number" => "items.number ASC", - "added" => "items.created_at DESC" - } - options.fetch(params[:sort]) { options["added"] } - end + def index_order + options = { + "name" => "items.name ASC", + "number" => "items.number ASC", + "added" => "items.created_at DESC" + } + options.fetch(params[:sort]) { options["added"] } + end end diff --git a/app/controllers/renewal/acceptances_controller.rb b/app/controllers/renewal/acceptances_controller.rb index c49008e54..26ae9c440 100644 --- a/app/controllers/renewal/acceptances_controller.rb +++ b/app/controllers/renewal/acceptances_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Renewal class AcceptancesController < BaseController before_action :load_member @@ -19,9 +21,8 @@ def destroy end private - - def acceptance_params - params.require(:agreement_acceptance).permit(:terms) - end + def acceptance_params + params.require(:agreement_acceptance).permit(:terms) + end end end diff --git a/app/controllers/renewal/base_controller.rb b/app/controllers/renewal/base_controller.rb index 6bcc2245c..24d337d8a 100644 --- a/app/controllers/renewal/base_controller.rb +++ b/app/controllers/renewal/base_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Renewal class BaseController < ApplicationController before_action :authenticate_user! @@ -8,43 +10,42 @@ class BaseController < ApplicationController layout "steps" private - - def load_steps - agreement = Document.agreement - @steps = if @current_library.allow_payments? - [ - Step.new(:rules, name: "Rules"), - Step.new(:profile, name: "Profile"), - Step.new(:agreement, name: agreement.name), - Step.new(:payment, name: "Payment"), - Step.new(:complete, name: "Complete") - ] - else - [ - Step.new(:rules, name: "Rules"), - Step.new(:profile, name: "Profile"), - Step.new(:agreement, name: agreement.name), - Step.new(:complete, name: "Complete") - ] + def load_steps + agreement = Document.agreement + @steps = if @current_library.allow_payments? + [ + Step.new(:rules, name: "Rules"), + Step.new(:profile, name: "Profile"), + Step.new(:agreement, name: agreement.name), + Step.new(:payment, name: "Payment"), + Step.new(:complete, name: "Complete") + ] + else + [ + Step.new(:rules, name: "Rules"), + Step.new(:profile, name: "Profile"), + Step.new(:agreement, name: agreement.name), + Step.new(:complete, name: "Complete") + ] + end end - end - def load_member - @member = current_member - end + def load_member + @member = current_member + end - def set_page_title - @page_title = "Membership Renewal" - end + def set_page_title + @page_title = "Membership Renewal" + end - def activate_step(step_id) - @steps.each do |step| - if step.id == step_id - step.active = true - @active_step = step - break + def activate_step(step_id) + @steps.each do |step| + if step.id == step_id + step.active = true + @active_step = step + break + end end end - end end end diff --git a/app/controllers/renewal/confirmations_controller.rb b/app/controllers/renewal/confirmations_controller.rb index 701006f20..1e3ebedf0 100644 --- a/app/controllers/renewal/confirmations_controller.rb +++ b/app/controllers/renewal/confirmations_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Renewal class ConfirmationsController < BaseController def show diff --git a/app/controllers/renewal/documents_controller.rb b/app/controllers/renewal/documents_controller.rb index 302701e04..6c2be0591 100644 --- a/app/controllers/renewal/documents_controller.rb +++ b/app/controllers/renewal/documents_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Renewal class DocumentsController < BaseController def rules diff --git a/app/controllers/renewal/home_controller.rb b/app/controllers/renewal/home_controller.rb index 01f69f7a9..214927fd0 100644 --- a/app/controllers/renewal/home_controller.rb +++ b/app/controllers/renewal/home_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Renewal class HomeController < BaseController def index diff --git a/app/controllers/renewal/members_controller.rb b/app/controllers/renewal/members_controller.rb index 94b4250b4..fbf4b65ff 100644 --- a/app/controllers/renewal/members_controller.rb +++ b/app/controllers/renewal/members_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Renewal class MembersController < BaseController before_action :load_member @@ -16,13 +18,12 @@ def update end private - - def member_params - params.require(:member).permit( - :full_name, :preferred_name, :email, :phone_number, :postal_code, - :address1, :address2, :desires, :reminders_via_email, :reminders_via_text, :receive_newsletter, - :volunteer_interest, :password, :password_confirmation, pronouns: [] - ) - end + def member_params + params.require(:member).permit( + :full_name, :preferred_name, :email, :phone_number, :postal_code, + :address1, :address2, :desires, :reminders_via_email, :reminders_via_text, :receive_newsletter, + :volunteer_interest, :password, :password_confirmation, pronouns: [] + ) + end end end diff --git a/app/controllers/renewal/payments_controller.rb b/app/controllers/renewal/payments_controller.rb index 563840536..a84f468da 100644 --- a/app/controllers/renewal/payments_controller.rb +++ b/app/controllers/renewal/payments_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Renewal class PaymentsController < BaseController before_action :load_member @@ -38,12 +40,12 @@ def skip def callback transaction_id = params[:transactionId] - result = checkout.fetch_transaction(member: @member, transaction_id: transaction_id) + result = checkout.fetch_transaction(member: @member, transaction_id:) session[:attempts] ||= 0 if result.success? amount = result.value - Membership.create_for_member(@member, amount: amount, start_membership: true, square_transaction_id: transaction_id, source: "square") + Membership.create_for_member(@member, amount:, start_membership: true, square_transaction_id: transaction_id, source: "square") MemberMailer.with(member: @member, amount: amount.cents).renewal_message.deliver_later session[:amount] = amount.cents @@ -71,27 +73,26 @@ def callback end private + def form_params + params.require(:membership_payment_form).permit(:amount_dollars) + end - def form_params - params.require(:membership_payment_form).permit(:amount_dollars) - end - - def checkout - SquareCheckout.new( - access_token: ENV.fetch("SQUARE_ACCESS_TOKEN"), - location_id: ENV.fetch("SQUARE_LOCATION_ID"), - environment: ENV.fetch("SQUARE_ENVIRONMENT") - ) - end + def checkout + SquareCheckout.new( + access_token: ENV.fetch("SQUARE_ACCESS_TOKEN"), + location_id: ENV.fetch("SQUARE_LOCATION_ID"), + environment: ENV.fetch("SQUARE_ENVIRONMENT") + ) + end - def set_raven_context - Raven.extra_context(session) - end + def set_raven_context + Raven.extra_context(session) + end - def are_payments_enabled? - if !@current_library.allow_payments? - render_not_found + def are_payments_enabled? + if !@current_library.allow_payments? + render_not_found + end end - end end end diff --git a/app/controllers/renewal/redemptions_controller.rb b/app/controllers/renewal/redemptions_controller.rb index 910e1339b..d2d886908 100644 --- a/app/controllers/renewal/redemptions_controller.rb +++ b/app/controllers/renewal/redemptions_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Renewal class RedemptionsController < BaseController before_action :load_member @@ -26,9 +28,8 @@ def create end private - - def form_params - params.require(:gift_membership_redemption_form).permit(:code) - end + def form_params + params.require(:gift_membership_redemption_form).permit(:code) + end end end diff --git a/app/controllers/short_links_controller.rb b/app/controllers/short_links_controller.rb index 54d530cb6..c9a05089d 100644 --- a/app/controllers/short_links_controller.rb +++ b/app/controllers/short_links_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ShortLinksController < ApplicationController def show @short_link = ShortLink.where(slug: params[:id]).first diff --git a/app/controllers/signup/acceptances_controller.rb b/app/controllers/signup/acceptances_controller.rb index ab227c2e5..5ead3f0a8 100644 --- a/app/controllers/signup/acceptances_controller.rb +++ b/app/controllers/signup/acceptances_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Signup class AcceptancesController < BaseController before_action :load_member @@ -19,9 +21,8 @@ def destroy end private - - def acceptance_params - params.require(:agreement_acceptance).permit(:terms) - end + def acceptance_params + params.require(:agreement_acceptance).permit(:terms) + end end end diff --git a/app/controllers/signup/base_controller.rb b/app/controllers/signup/base_controller.rb index 5f076bb02..bbf2dd022 100644 --- a/app/controllers/signup/base_controller.rb +++ b/app/controllers/signup/base_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Signup class BaseController < ApplicationController before_action :load_steps @@ -12,49 +14,48 @@ def is_membership_enabled? end private - - def load_member - if session[:member_id] && session[:timeout] && session[:timeout] > Time.current - 15.minutes - @member = Member.find(session[:member_id]) - else - reset_session - flash[:error] = "Your session expired. Please come into the library to complete signup." - redirect_to signup_url + def load_member + if session[:member_id] && session[:timeout] && session[:timeout] > Time.current - 15.minutes + @member = Member.find(session[:member_id]) + else + reset_session + flash[:error] = "Your session expired. Please come into the library to complete signup." + redirect_to signup_url + end end - end - def load_steps - agreement = Document.agreement - @steps = if @current_library.allow_payments? - [ - Step.new(:rules, name: "Rules"), - Step.new(:profile, name: "Profile"), - Step.new(:agreement, name: agreement.name), - Step.new(:payment, name: "Payment"), - Step.new(:complete, name: "Complete") - ] - else - [ - Step.new(:rules, name: "Rules"), - Step.new(:profile, name: "Profile"), - Step.new(:agreement, name: agreement.name), - Step.new(:complete, name: "Complete") - ] + def load_steps + agreement = Document.agreement + @steps = if @current_library.allow_payments? + [ + Step.new(:rules, name: "Rules"), + Step.new(:profile, name: "Profile"), + Step.new(:agreement, name: agreement.name), + Step.new(:payment, name: "Payment"), + Step.new(:complete, name: "Complete") + ] + else + [ + Step.new(:rules, name: "Rules"), + Step.new(:profile, name: "Profile"), + Step.new(:agreement, name: agreement.name), + Step.new(:complete, name: "Complete") + ] + end end - end - def activate_step(step_id) - @steps.each do |step| - if step.id == step_id - step.active = true - @active_step = step - break + def activate_step(step_id) + @steps.each do |step| + if step.id == step_id + step.active = true + @active_step = step + break + end end end - end - def set_page_title - @page_title = "New Member Signup" - end + def set_page_title + @page_title = "New Member Signup" + end end end diff --git a/app/controllers/signup/confirmations_controller.rb b/app/controllers/signup/confirmations_controller.rb index 5377cc938..454983084 100644 --- a/app/controllers/signup/confirmations_controller.rb +++ b/app/controllers/signup/confirmations_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Signup class ConfirmationsController < BaseController def show diff --git a/app/controllers/signup/documents_controller.rb b/app/controllers/signup/documents_controller.rb index a6a4055b7..0a5b87ed3 100644 --- a/app/controllers/signup/documents_controller.rb +++ b/app/controllers/signup/documents_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Signup class DocumentsController < BaseController before_action :load_member, only: :agreement diff --git a/app/controllers/signup/home_controller.rb b/app/controllers/signup/home_controller.rb index 1066c5fc8..a24abac5e 100644 --- a/app/controllers/signup/home_controller.rb +++ b/app/controllers/signup/home_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Signup class HomeController < BaseController before_action :is_membership_enabled? diff --git a/app/controllers/signup/members_controller.rb b/app/controllers/signup/members_controller.rb index f0a8a37da..caa1bad72 100644 --- a/app/controllers/signup/members_controller.rb +++ b/app/controllers/signup/members_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Signup class MembersController < BaseController before_action :is_membership_enabled? @@ -30,13 +32,12 @@ def create end private - - def member_signup_form_params - params.require(:member_signup_form).permit( - :full_name, :preferred_name, :email, :phone_number, :postal_code, - :address1, :address2, :desires, :reminders_via_email, :reminders_via_text, :receive_newsletter, - :volunteer_interest, :password, :password_confirmation, pronouns: [] - ) - end + def member_signup_form_params + params.require(:member_signup_form).permit( + :full_name, :preferred_name, :email, :phone_number, :postal_code, + :address1, :address2, :desires, :reminders_via_email, :reminders_via_text, :receive_newsletter, + :volunteer_interest, :password, :password_confirmation, pronouns: [] + ) + end end end diff --git a/app/controllers/signup/payments_controller.rb b/app/controllers/signup/payments_controller.rb index f47756c39..95fb63cad 100644 --- a/app/controllers/signup/payments_controller.rb +++ b/app/controllers/signup/payments_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Signup class PaymentsController < BaseController before_action :load_member @@ -38,12 +40,12 @@ def skip def callback transaction_id = params[:transactionId] - result = checkout.fetch_transaction(member: @member, transaction_id: transaction_id) + result = checkout.fetch_transaction(member: @member, transaction_id:) session[:attempts] ||= 0 if result.success? amount = result.value - Membership.create_for_member(@member, amount: amount, square_transaction_id: transaction_id, source: "square") + Membership.create_for_member(@member, amount:, square_transaction_id: transaction_id, source: "square") MemberMailer.with(member: @member, amount: amount.cents).welcome_message.deliver_later reset_session @@ -72,27 +74,26 @@ def callback end private + def form_params + params.require(:membership_payment_form).permit(:amount_dollars) + end - def form_params - params.require(:membership_payment_form).permit(:amount_dollars) - end - - def checkout - SquareCheckout.new( - access_token: ENV.fetch("SQUARE_ACCESS_TOKEN"), - location_id: ENV.fetch("SQUARE_LOCATION_ID"), - environment: ENV.fetch("SQUARE_ENVIRONMENT") - ) - end + def checkout + SquareCheckout.new( + access_token: ENV.fetch("SQUARE_ACCESS_TOKEN"), + location_id: ENV.fetch("SQUARE_LOCATION_ID"), + environment: ENV.fetch("SQUARE_ENVIRONMENT") + ) + end - def set_raven_context - Raven.extra_context(session) - end + def set_raven_context + Raven.extra_context(session) + end - def are_payments_enabled? - if !@current_library.allow_payments? - render_not_found + def are_payments_enabled? + if !@current_library.allow_payments? + render_not_found + end end - end end end diff --git a/app/controllers/signup/redemptions_controller.rb b/app/controllers/signup/redemptions_controller.rb index 54d8a2ddd..3bcd3bd89 100644 --- a/app/controllers/signup/redemptions_controller.rb +++ b/app/controllers/signup/redemptions_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Signup class RedemptionsController < BaseController before_action :load_member @@ -27,9 +29,8 @@ def create end private - - def form_params - params.require(:gift_membership_redemption_form).permit(:code) - end + def form_params + params.require(:gift_membership_redemption_form).permit(:code) + end end end diff --git a/app/controllers/super_admin/libraries_controller.rb b/app/controllers/super_admin/libraries_controller.rb index a0c5e2937..3b2566587 100644 --- a/app/controllers/super_admin/libraries_controller.rb +++ b/app/controllers/super_admin/libraries_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module SuperAdmin class LibrariesController < ApplicationController skip_before_action :set_tenant @@ -52,15 +54,14 @@ def destroy end private - - def require_super_admin - unless current_user.super_admin? - redirect_to items_path, warning: "You do not have access to that page." + def require_super_admin + unless current_user.super_admin? + redirect_to items_path, warning: "You do not have access to that page." + end end - end - def library_params - params.require(:library).permit(:name, :hostname, :city, :email, :address, :member_postal_code_pattern, :image) - end + def library_params + params.require(:library).permit(:name, :hostname, :city, :email, :address, :member_postal_code_pattern, :image) + end end end diff --git a/app/controllers/test_controller.rb b/app/controllers/test_controller.rb index 399e9759c..bbe378577 100644 --- a/app/controllers/test_controller.rb +++ b/app/controllers/test_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class TestController < ApplicationController def google_auth session[:email] = params[:email] diff --git a/app/controllers/users/sessions_controller.rb b/app/controllers/users/sessions_controller.rb index 93f2303dc..1ad9884f7 100644 --- a/app/controllers/users/sessions_controller.rb +++ b/app/controllers/users/sessions_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Users class SessionsController < Devise::SessionsController def new diff --git a/app/controllers/volunteer/attendees_controller.rb b/app/controllers/volunteer/attendees_controller.rb index 357af4598..5d02a89d0 100644 --- a/app/controllers/volunteer/attendees_controller.rb +++ b/app/controllers/volunteer/attendees_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Volunteer class AttendeesController < BaseController include ShiftsHelper @@ -24,20 +26,19 @@ def destroy end private - - def post_redirect(path) - <<~HTML.html_safe + def post_redirect(path) + <<~HTML.html_safe
- HTML - end + HTML + end - def google_calendar_id - ::Event.volunteer_shift_calendar_id - end + def google_calendar_id + ::Event.volunteer_shift_calendar_id + end end end diff --git a/app/controllers/volunteer/base_controller.rb b/app/controllers/volunteer/base_controller.rb index 939a1c2a9..649db1f51 100644 --- a/app/controllers/volunteer/base_controller.rb +++ b/app/controllers/volunteer/base_controller.rb @@ -1,17 +1,18 @@ +# frozen_string_literal: true + module Volunteer class BaseController < ApplicationController before_action :redirect_to_teamup helper_method :signed_in_via_google? private + def signed_in_via_google? + session[:email].present? + end - def signed_in_via_google? - session[:email].present? - end - - def redirect_to_teamup - redirect_to "https://teamup.com/ksnp8rrsst1ow8nvwn" - false - end + def redirect_to_teamup + redirect_to "https://teamup.com/ksnp8rrsst1ow8nvwn" + false + end end end diff --git a/app/controllers/volunteer/sessions_controller.rb b/app/controllers/volunteer/sessions_controller.rb index 66950feed..67d62b42a 100644 --- a/app/controllers/volunteer/sessions_controller.rb +++ b/app/controllers/volunteer/sessions_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Volunteer class SessionsController < BaseController include Calendaring @@ -28,13 +30,12 @@ def failure end private + def auth_hash + request.env["omniauth.auth"] + end - def auth_hash - request.env["omniauth.auth"] - end - - def google_calendar_id - ::Event.volunteer_shift_calendar_id - end + def google_calendar_id + ::Event.volunteer_shift_calendar_id + end end end diff --git a/app/controllers/volunteer/shifts_controller.rb b/app/controllers/volunteer/shifts_controller.rb index 27397de5d..a0563487e 100644 --- a/app/controllers/volunteer/shifts_controller.rb +++ b/app/controllers/volunteer/shifts_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Volunteer class ShiftsController < BaseController include ShiftsHelper @@ -32,9 +34,8 @@ def event end private - - def google_calendar_id - ::Event.volunteer_shift_calendar_id - end + def google_calendar_id + ::Event.volunteer_shift_calendar_id + end end end diff --git a/app/forms/extend_holds_form.rb b/app/forms/extend_holds_form.rb index 5f8b832b0..bc349039a 100644 --- a/app/forms/extend_holds_form.rb +++ b/app/forms/extend_holds_form.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ExtendHoldsForm include ActiveModel::Model include ActiveModel::Attributes @@ -18,10 +20,9 @@ def latest_valid_date end private - - def date_in_near_future - unless (earliest_valid_date..latest_valid_date).cover?(date) - errors.add(:date, "must be a date within the next month") + def date_in_near_future + unless (earliest_valid_date..latest_valid_date).cover?(date) + errors.add(:date, "must be a date within the next month") + end end - end end diff --git a/app/forms/gift_membership_redemption_form.rb b/app/forms/gift_membership_redemption_form.rb index 702ed349b..2111b7546 100644 --- a/app/forms/gift_membership_redemption_form.rb +++ b/app/forms/gift_membership_redemption_form.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class GiftMembershipRedemptionForm include ActiveModel::Model diff --git a/app/forms/member_signup_form.rb b/app/forms/member_signup_form.rb index 7d9b63109..dd8de1d19 100644 --- a/app/forms/member_signup_form.rb +++ b/app/forms/member_signup_form.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This class encapsulates creating both a Member and User record from a single form, # as is done by the new member signup flow. class MemberSignupForm diff --git a/app/forms/membership_form.rb b/app/forms/membership_form.rb index 2a8bee993..ff3774a77 100644 --- a/app/forms/membership_form.rb +++ b/app/forms/membership_form.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class MembershipForm include ActiveModel::Model @@ -29,12 +31,11 @@ def save end private + def save_with_payment + @payment.valid? && Membership.create_for_member(@member, amount: @payment.amount, source: @payment.payment_source, start_membership:) + end - def save_with_payment - @payment.valid? && Membership.create_for_member(@member, amount: @payment.amount, source: @payment.payment_source, start_membership: start_membership) - end - - def save_without_payment - Membership.create_for_member(@member, start_membership: start_membership) - end + def save_without_payment + Membership.create_for_member(@member, start_membership:) + end end diff --git a/app/forms/membership_payment_form.rb b/app/forms/membership_payment_form.rb index 9059d47bf..cb34c7526 100644 --- a/app/forms/membership_payment_form.rb +++ b/app/forms/membership_payment_form.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class MembershipPaymentForm include ActiveModel::Model diff --git a/app/forms/ticket_update_form.rb b/app/forms/ticket_update_form.rb index a55676f65..be2324080 100644 --- a/app/forms/ticket_update_form.rb +++ b/app/forms/ticket_update_form.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class TicketUpdateForm include ActiveModel::Model diff --git a/app/helpers/adjustments_helper.rb b/app/helpers/adjustments_helper.rb index 1b312e300..b0de41bf5 100644 --- a/app/helpers/adjustments_helper.rb +++ b/app/helpers/adjustments_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module AdjustmentsHelper def adjustment_payment_source_options Adjustment.payment_sources diff --git a/app/helpers/admin/items/items_attachments_helper.rb b/app/helpers/admin/items/items_attachments_helper.rb index 275c889b5..c8134b0b1 100644 --- a/app/helpers/admin/items/items_attachments_helper.rb +++ b/app/helpers/admin/items/items_attachments_helper.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + module Admin::Items::ItemsAttachmentsHelper end diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb index 660a6716b..47748f101 100644 --- a/app/helpers/admin_helper.rb +++ b/app/helpers/admin_helper.rb @@ -1,18 +1,20 @@ +# frozen_string_literal: true + module AdminHelper def index_header(title, icon: nil, &block) - render "shared/index_header", title: title, icon: icon, &block + render "shared/index_header", title:, icon:, &block end def flash_message(key, classname = key) if flash.key?(key) - tag.div(class: "toast toast-#{classname}", data: {controller: "alert"}) do - tag.button(class: "btn btn-clear float-right", data: {action: "alert#remove"}) + flash[key] + tag.div(class: "toast toast-#{classname}", data: { controller: "alert" }) do + tag.button(class: "btn btn-clear float-right", data: { action: "alert#remove" }) + flash[key] end end end def empty_state(title, subtitle: nil, icon: nil, &block) - render "shared/empty_state", title: title, subtitle: subtitle, icon: icon, &block + render "shared/empty_state", title:, subtitle:, icon:, &block end def preferred_or_default_name(member) @@ -34,7 +36,7 @@ def item_attachment_kind_options end def tab_link(label, path, badge: nil) - opts = badge.present? && badge != 0 ? {class: "badge", data: {badge: badge}} : {} + opts = badge.present? && badge != 0 ? { class: "badge", data: { badge: } } : {} tag.li(class: "tab-item #{"active" if current_page?(path)}") do link_to label, path, **opts end @@ -51,7 +53,7 @@ def renewal_tooltop(renewable, renewal_limit, &block) end tag.span( class: "tooltip tooltip-bottom", - data: {tooltip: message}, + data: { tooltip: message }, &block ) end @@ -101,7 +103,7 @@ def audit_description(audit, key, values) end def modal(title:, body:, &block) - render "shared/modal", title: title, body: body, &block + render "shared/modal", title:, body:, &block end def appointment_in_schedule_path(appointment) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 352a6edf7..b0fcfc6c8 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ApplicationHelper # Assume that any request with an action of new or edit is displaying a form def form_request? diff --git a/app/helpers/appointments_helper.rb b/app/helpers/appointments_helper.rb index e559170eb..80a49c205 100644 --- a/app/helpers/appointments_helper.rb +++ b/app/helpers/appointments_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module AppointmentsHelper def format_appointment_times(start, stop) date_format = "%l:%M%P" diff --git a/app/helpers/date_helper.rb b/app/helpers/date_helper.rb index 8567039cc..d3424c9e8 100644 --- a/app/helpers/date_helper.rb +++ b/app/helpers/date_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DateHelper def date_with_time_title(time) tag.span(time.to_s(:short_date), title: time.to_s(:short_datetime)) diff --git a/app/helpers/holds_helper.rb b/app/helpers/holds_helper.rb index 7f58cdb25..97c6388b4 100644 --- a/app/helpers/holds_helper.rb +++ b/app/helpers/holds_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module HoldsHelper def hold_date(event) event.date.strftime("%A, %B %-d, between ") + event.times.sub("-", "&") @@ -11,8 +13,8 @@ def hold_slot_options(slots) end def render_hold_items(items, &block) - block ||= proc {} - render layout: "holds/items", locals: {items: items}, &block + block ||= proc { } + render layout: "holds/items", locals: { items: }, &block end def render_hold_status(hold) @@ -37,7 +39,7 @@ def render_hold_status(hold) def render_remove_link(hold) unless hold.appointments.present? - link_to("Remove Hold", account_hold_path(hold), class: "btn", method: :delete, data: {confirm: "Are you sure you want to remove this hold?"}) + link_to("Remove Hold", account_hold_path(hold), class: "btn", method: :delete, data: { confirm: "Are you sure you want to remove this hold?" }) end end @@ -46,8 +48,7 @@ def place_in_line_for(hold) end private - - def format_date(date) - date.strftime("%a, %-m/%-d") - end + def format_date(date) + date.strftime("%a, %-m/%-d") + end end diff --git a/app/helpers/icons_helper.rb b/app/helpers/icons_helper.rb index 5466a956a..d41422c44 100644 --- a/app/helpers/icons_helper.rb +++ b/app/helpers/icons_helper.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + module IconsHelper def feather_icon(icon_name, **options) - opts = options.deep_merge({data: {feather: icon_name}}) + opts = options.deep_merge({ data: { feather: icon_name } }) tag.i(**opts) end @@ -8,11 +10,11 @@ def icon_stat(icon_name, content = nil, css_class: nil, title: nil, placeholder: content = capture(&block) if block return if content.blank? && placeholder.nil? - tag.li(title: title, class: css_class, placeholder: placeholder) do + tag.li(title:, class: css_class, placeholder:) do if content.blank? - tag.i(data: {feather: icon_name}) + tag.span(placeholder, class: "placeholder-text") + tag.i(data: { feather: icon_name }) + tag.span(placeholder, class: "placeholder-text") else - tag.i(data: {feather: icon_name}) + content.to_s + tag.i(data: { feather: icon_name }) + content.to_s end end end diff --git a/app/helpers/items_helper.rb b/app/helpers/items_helper.rb index 260f28838..25ec81ad2 100644 --- a/app/helpers/items_helper.rb +++ b/app/helpers/items_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ItemsHelper include Pagy::Frontend @@ -73,7 +75,7 @@ def category_tree_nav(categories, current_category = nil) parent[category.id] = TreeNode.new(category) end - tag.nav(class: "tree-nav", data: {controller: "tree-nav"}) do + tag.nav(class: "tree-nav", data: { controller: "tree-nav" }) do concat(tag.ul do root.children.values.sort_by { |node| node.value.name.downcase }.map do |node| concat(render_tree_node(node, current_category)) @@ -84,13 +86,13 @@ def category_tree_nav(categories, current_category = nil) def render_tree_node(node, current_value) has_children = node.children.size > 0 - tag.li(class: "tree-node", data: {id: node.value.id}) do + tag.li(class: "tree-node", data: { id: node.value.id }) do if has_children concat( tag.button( 'Toggle subcategories'.html_safe, class: "tree-node-toggle", - data: {action: "tree-nav#toggle"}, + data: { action: "tree-nav#toggle" }, "aria-expanded": false ) ) diff --git a/app/helpers/layout_helper.rb b/app/helpers/layout_helper.rb index 7294155ce..e0e0eb93b 100644 --- a/app/helpers/layout_helper.rb +++ b/app/helpers/layout_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module LayoutHelper def section_header(title, level: "h1", &block) right_content = block ? capture(&block) : "" diff --git a/app/helpers/loans_helper.rb b/app/helpers/loans_helper.rb index 359106ae4..4e7f72e09 100644 --- a/app/helpers/loans_helper.rb +++ b/app/helpers/loans_helper.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + module LoansHelper def undo_button(loan) name, method, path, params = if loan.ended? if loan.item.borrow_policy.consumable? ["loan", :delete, admin_loan_path(loan)] else - ["return", :patch, admin_loan_path(loan), {loan: {ended_at: nil}}] + ["return", :patch, admin_loan_path(loan), { loan: { ended_at: nil } }] end elsif loan.renewal? ["renewal", :delete, admin_renewal_path(loan)] @@ -55,12 +57,11 @@ def next_due_date(loans) end private + def format_date(date) + date.strftime("%a, %-m/%-d") + end - def format_date(date) - date.strftime("%a, %-m/%-d") - end - - def format_time_range(starts_at, ends_at) - "#{starts_at.strftime("%l%P")}–#{ends_at.strftime("%l%P")}" - end + def format_time_range(starts_at, ends_at) + "#{starts_at.strftime("%l%P")}–#{ends_at.strftime("%l%P")}" + end end diff --git a/app/helpers/member_profiles_helper.rb b/app/helpers/member_profiles_helper.rb index 1662949d0..13e8cb96d 100644 --- a/app/helpers/member_profiles_helper.rb +++ b/app/helpers/member_profiles_helper.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + module MemberProfilesHelper end diff --git a/app/helpers/members_helper.rb b/app/helpers/members_helper.rb index 1de67cfc3..541dd2700 100644 --- a/app/helpers/members_helper.rb +++ b/app/helpers/members_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module MembersHelper def member_id_kind_options Member.id_kinds.map do |key, value| @@ -16,7 +18,7 @@ def member_status_options end def format_phone_number(number, delimiter = " ") - number_to_phone(number, pattern: /^(\d{0,3})(\d{0,3})(\d{0,4})/, delimiter: delimiter)&.strip + number_to_phone(number, pattern: /^(\d{0,3})(\d{0,3})(\d{0,4})/, delimiter:)&.strip end def member_status(member) diff --git a/app/helpers/shifts_helper.rb b/app/helpers/shifts_helper.rb index 0c975ec88..b38400125 100644 --- a/app/helpers/shifts_helper.rb +++ b/app/helpers/shifts_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ShiftsHelper def each_shift(events, &block) last_date = nil @@ -24,9 +26,7 @@ def calendar_day(day, &block) data = {} data["test-date"] = day.date.to_s unless day.previous_month? || day.next_month? - tag.div(class: "calendar-date #{calendar_day_class(day)}", data: data) do - yield - end + tag.div(class: "calendar-date #{calendar_day_class(day)}", data:, &block) end def calendar_date_item_class(day) @@ -38,8 +38,8 @@ def event_attendees(attendees) attendees .select { |a| a.accepted? } - .map { |a| + .filter_map { |a| Member.find_by(email: a.email)&.preferred_name || a.email.split("@").first - }.compact.sort.join(", ") + }.sort.join(", ") end end diff --git a/app/helpers/ticket_updates_helper.rb b/app/helpers/ticket_updates_helper.rb index 72029b855..f9dfa3a82 100644 --- a/app/helpers/ticket_updates_helper.rb +++ b/app/helpers/ticket_updates_helper.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + module TicketUpdatesHelper end diff --git a/app/helpers/tickets_helper.rb b/app/helpers/tickets_helper.rb index 2bb95e344..3d089413d 100644 --- a/app/helpers/tickets_helper.rb +++ b/app/helpers/tickets_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module TicketsHelper def ticket_status_options Ticket.statuses.map do |key, value| diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb index d394c3d10..bef395997 100644 --- a/app/jobs/application_job.rb +++ b/app/jobs/application_job.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ApplicationJob < ActiveJob::Base # Automatically retry jobs that encountered a deadlock # retry_on ActiveRecord::Deadlocked diff --git a/app/jobs/neon_member_job.rb b/app/jobs/neon_member_job.rb index 9f6d6e588..14e131588 100644 --- a/app/jobs/neon_member_job.rb +++ b/app/jobs/neon_member_job.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class NeonMemberJob < ApplicationJob include SuckerPunch::Job diff --git a/app/lib/activity_notifier.rb b/app/lib/activity_notifier.rb index b0c485991..fe6cb3b9a 100644 --- a/app/lib/activity_notifier.rb +++ b/app/lib/activity_notifier.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ActivityNotifier def initialize(now = Time.current) @now = now @@ -7,7 +9,7 @@ def send_daily_loan_summaries members_active_today = Member.active_on(@now).pluck(:id) each_member(members_active_today) do |member, summaries| - MemberMailer.with(member: member, summaries: summaries, now: @now).loan_summaries.deliver + MemberMailer.with(member:, summaries:, now: @now).loan_summaries.deliver end end @@ -15,7 +17,7 @@ def send_overdue_notices members_with_overdue_items = Member.verified.joins(:loans).merge(Loan.checked_out.due_whole_weeks_ago).pluck(:id) each_member(members_with_overdue_items) do |member, summaries| - MemberMailer.with(member: member, summaries: summaries.overdue_as_of(@now.tomorrow.beginning_of_day), now: @now).overdue_notice.deliver + MemberMailer.with(member:, summaries: summaries.overdue_as_of(@now.tomorrow.beginning_of_day), now: @now).overdue_notice.deliver end end @@ -24,14 +26,14 @@ def send_return_reminders members_with_items_due_tomorrow = Member.verified.joins(:loans).merge(Loan.checked_out.due_on(tomorrow)).pluck(:id) each_member(members_with_items_due_tomorrow) do |member, summaries| - MemberMailer.with(member: member, summaries: summaries, now: @now).return_reminder.deliver + MemberMailer.with(member:, summaries:, now: @now).return_reminder.deliver end end # TODO activate this one def remind_pending_members Member.status_pending.where("created_at < ?", @now).each do |member| - MemberMailer.with(member: member).membership_reminder.deliver + MemberMailer.with(member:).membership_reminder.deliver end end @@ -42,20 +44,19 @@ def send_staff_daily_renewal_requests return end - Member.joins(:user).where(users: {role: :admin}).each do |staff| + Member.joins(:user).where(users: { role: :admin }).each do |staff| MemberMailer.with(member: staff, renewal_requests: daily_renewal_requests).staff_daily_renewal_requests.deliver end end private - - def each_member(ids, &block) - Member.find(ids).each do |member| - summaries = member.loan_summaries - .active_on(@now) - .or(member.loan_summaries.includes(:renewal_requests).checked_out) - .includes(item: :borrow_policy) - yield member, summaries + def each_member(ids, &block) + Member.find(ids).each do |member| + summaries = member.loan_summaries + .active_on(@now) + .or(member.loan_summaries.includes(:renewal_requests).checked_out) + .includes(item: :borrow_policy) + yield member, summaries + end end - end end diff --git a/app/lib/admin/check_out.rb b/app/lib/admin/check_out.rb index 8b86c74fb..84c3c77aa 100644 --- a/app/lib/admin/check_out.rb +++ b/app/lib/admin/check_out.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin class CheckOut include ActiveModel::Model diff --git a/app/lib/admin/lookup.rb b/app/lib/admin/lookup.rb index 79b8ad9ed..cbca2d867 100644 --- a/app/lib/admin/lookup.rb +++ b/app/lib/admin/lookup.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin class Lookup include ActiveModel::Model diff --git a/app/lib/admin/payment.rb b/app/lib/admin/payment.rb index c8c7719c7..1fc0cdf78 100644 --- a/app/lib/admin/payment.rb +++ b/app/lib/admin/payment.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin class Payment include ActiveModel::Model diff --git a/app/lib/admin/verification.rb b/app/lib/admin/verification.rb index 6e03fdcbe..e4582dd32 100644 --- a/app/lib/admin/verification.rb +++ b/app/lib/admin/verification.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Admin class Verification include ActiveModel::Model diff --git a/app/lib/certificate/generator.rb b/app/lib/certificate/generator.rb index 8e6d3faf2..c0dac7466 100644 --- a/app/lib/certificate/generator.rb +++ b/app/lib/certificate/generator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Certificate class Generator def initialize(code:) diff --git a/app/lib/fine_calculator.rb b/app/lib/fine_calculator.rb index d6087b0b4..995b61dca 100644 --- a/app/lib/fine_calculator.rb +++ b/app/lib/fine_calculator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class FineCalculator def self.for_overdue_loan(loan, now) borrow_policy = loan.item.borrow_policy diff --git a/app/lib/google/calendar.rb b/app/lib/google/calendar.rb index becf4a4e2..066f8bfdb 100644 --- a/app/lib/google/calendar.rb +++ b/app/lib/google/calendar.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Google class Calendar TOKEN_ENDPOINT = "https://www.googleapis.com/oauth2/v4/token" @@ -17,7 +19,7 @@ def upcoming_events(start_time, end_time) }) if events_response.status == 200 - events = events_response.parse.fetch("items", []).map { |event| gcal_event_to_event(event) }.compact + events = events_response.parse.fetch("items", []).filter_map { |event| gcal_event_to_event(event) } Result.success(events) else Result.failure(events_response.body) @@ -61,7 +63,7 @@ def add_attendee_to_event(attendee, event_id) # update event patch_response = client.patch(event_url, json: { - attendees: attendees + attendees: }) if patch_response.status == 200 event = gcal_event_to_event(patch_response.parse) @@ -97,51 +99,50 @@ def remove_attendee_from_event(attendee, event_id) end private + def events_endpoint + "https://www.googleapis.com/calendar/v3/calendars/#{@calendar_id}/events" + end - def events_endpoint - "https://www.googleapis.com/calendar/v3/calendars/#{@calendar_id}/events" - end - - def client - @client ||= new_client - end + def client + @client ||= new_client + end - def new_client - http = HTTP.use(instrumentation: {instrumenter: ActiveSupport::Notifications.instrumenter}) - token_response = http.post(TOKEN_ENDPOINT, params: { - client_id: ENV.fetch("GOOGLE_CLIENT_ID"), - client_secret: ENV.fetch("GOOGLE_CLIENT_SECRET"), - grant_type: "refresh_token", - refresh_token: ENV.fetch("GOOGLE_REFRESH_TOKEN") - }) - token = token_response.parse["access_token"] - http.auth("Bearer #{token}") - end + def new_client + http = HTTP.use(instrumentation: { instrumenter: ActiveSupport::Notifications.instrumenter }) + token_response = http.post(TOKEN_ENDPOINT, params: { + client_id: ENV.fetch("GOOGLE_CLIENT_ID"), + client_secret: ENV.fetch("GOOGLE_CLIENT_SECRET"), + grant_type: "refresh_token", + refresh_token: ENV.fetch("GOOGLE_REFRESH_TOKEN") + }) + token = token_response.parse["access_token"] + http.auth("Bearer #{token}") + end - def parse_gcal_time(time) - zone_name = time["timeZone"] - datetime = time["dateTime"] - ActiveSupport::TimeZone[zone_name].iso8601(datetime) - end + def parse_gcal_time(time) + zone_name = time["timeZone"] + datetime = time["dateTime"] + ActiveSupport::TimeZone[zone_name].iso8601(datetime) + end - def gcal_event_to_event(gcal_event) - # skip all day events - unless gcal_event["start"]["dateTime"] && gcal_event["end"]["dateTime"] - Rails.logger.info "skipping all-day event #{gcal_event["id"]} in calendar #{@calendar_id}" - return nil + def gcal_event_to_event(gcal_event) + # skip all day events + unless gcal_event["start"]["dateTime"] && gcal_event["end"]["dateTime"] + Rails.logger.info "skipping all-day event #{gcal_event["id"]} in calendar #{@calendar_id}" + return nil + end + CalendarEvent.new( + id: gcal_event["id"], + calendar_id: @calendar_id, + summary: gcal_event["summary"], + description: gcal_event["description"], + start: parse_gcal_time(gcal_event["start"]), + finish: parse_gcal_time(gcal_event["end"]), + status: gcal_event["status"], + attendees: gcal_event.fetch("attendees", []).map { |attendee| + Attendee.new(email: attendee["email"], name: attendee["displayName"], status: attendee["responseStatus"]) + } + ) end - CalendarEvent.new( - id: gcal_event["id"], - calendar_id: @calendar_id, - summary: gcal_event["summary"], - description: gcal_event["description"], - start: parse_gcal_time(gcal_event["start"]), - finish: parse_gcal_time(gcal_event["end"]), - status: gcal_event["status"], - attendees: gcal_event.fetch("attendees", []).map { |attendee| - Attendee.new(email: attendee["email"], name: attendee["displayName"], status: attendee["responseStatus"]) - } - ) - end end end diff --git a/app/lib/google/calendar_event.rb b/app/lib/google/calendar_event.rb index 28e170180..20aa0e678 100644 --- a/app/lib/google/calendar_event.rb +++ b/app/lib/google/calendar_event.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Google class CalendarEvent attr_reader :id, :summary, :description, :start, :finish, :attendees, :calendar_id diff --git a/app/lib/google/test_calendar.rb b/app/lib/google/test_calendar.rb index f66371d55..6d7710ec4 100644 --- a/app/lib/google/test_calendar.rb +++ b/app/lib/google/test_calendar.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Google # This object is only used during tests to circumvent connections to the Google Calendar API. class TestCalendar @@ -40,18 +42,17 @@ def remove_attendee_from_event(attendee, event_id) end private - - def event_to_gcal_event(event) - CalendarEvent.new( - id: event.calendar_event_id, - calendar_id: event.calendar_id, - summary: event.summary, - attendees: event.attendees, - start: event.start, - finish: event.finish, - status: "confirmed", - description: event.description - ) - end + def event_to_gcal_event(event) + CalendarEvent.new( + id: event.calendar_event_id, + calendar_id: event.calendar_id, + summary: event.summary, + attendees: event.attendees, + start: event.start, + finish: event.finish, + status: "confirmed", + description: event.description + ) + end end end diff --git a/app/lib/html_to_markdown.rb b/app/lib/html_to_markdown.rb index 7d835c967..e1e168a82 100644 --- a/app/lib/html_to_markdown.rb +++ b/app/lib/html_to_markdown.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + ReverseMarkdown::Converters.unregister :strong class HTMLToMarkdown diff --git a/app/lib/item_exporter.rb b/app/lib/item_exporter.rb index 5a4145cb1..4f27f1037 100644 --- a/app/lib/item_exporter.rb +++ b/app/lib/item_exporter.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "csv" class ItemExporter diff --git a/app/lib/manual_import.rb b/app/lib/manual_import.rb index d446139c6..7786dbd0d 100644 --- a/app/lib/manual_import.rb +++ b/app/lib/manual_import.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "uri" class ManualImport @@ -30,7 +32,7 @@ def update_item!(item) filename = File.basename(URI.parse(url).path) item.manual.attach( - filename: filename, + filename:, io: tempfile, content_type: response.mime_type ) diff --git a/app/lib/map/chicago.rb b/app/lib/map/chicago.rb index 13578de8c..17a2d838a 100644 --- a/app/lib/map/chicago.rb +++ b/app/lib/map/chicago.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Map class Chicago SVG_FILE = File.join(Rails.root, "app/lib/map/chicago.svg") @@ -20,25 +22,24 @@ def self.generate_style(value, max, fill) end private - - def load_svg - @doc = if @svg - Nokogiri::XML(@svg) - else - File.open(SVG_FILE) { |f| Nokogiri::XML(f) } + def load_svg + @doc = if @svg + Nokogiri::XML(@svg) + else + File.open(SVG_FILE) { |f| Nokogiri::XML(f) } + end end - end - def add_fills_to_zipcodes - max = @values.values.max - @values.each do |key, value| - node = @doc.at_css("##{key.to_s.strip}") - node["style"] = self.class.generate_style(value, max, @fill) if node + def add_fills_to_zipcodes + max = @values.values.max + @values.each do |key, value| + node = @doc.at_css("##{key.to_s.strip}") + node["style"] = self.class.generate_style(value, max, @fill) if node + end end - end - def serialize - @doc.to_xml - end + def serialize + @doc.to_xml + end end end diff --git a/app/lib/member_exporter.rb b/app/lib/member_exporter.rb index f39524199..b827fb7b6 100644 --- a/app/lib/member_exporter.rb +++ b/app/lib/member_exporter.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "csv" class MemberExporter @@ -51,22 +53,21 @@ def export(stream) end private + def year_headers + @year_range.flat_map { |year| ["#{year}_amount", "#{year}_started_at"] } + end - def year_headers - @year_range.flat_map { |year| ["#{year}_amount", "#{year}_started_at"] } - end - - def year_values(member) - @year_range.flat_map { |year| - started_at = member["#{year}_started_at"] - amount = member["#{year}_amount"].to_i - if started_at - [amount / 100, started_at.to_s(:short_date)] - elsif amount > 0 - [amount / 100, nil] - else - [nil, nil] - end - } - end + def year_values(member) + @year_range.flat_map { |year| + started_at = member["#{year}_started_at"] + amount = member["#{year}_amount"].to_i + if started_at + [amount / 100, started_at.to_s(:short_date)] + elsif amount > 0 + [amount / 100, nil] + else + [nil, nil] + end + } + end end diff --git a/app/lib/neon.rb b/app/lib/neon.rb index 9bbc9efcf..38b822136 100644 --- a/app/lib/neon.rb +++ b/app/lib/neon.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Neon # Until we are storing per-library credentials somewhere other than environment variables, # we will prefix the variable names with the library ID to scope credentials to @@ -26,16 +28,16 @@ def self.member_to_account(member) "email1" => member.email }, "accountCustomFields" => [ - {"id" => "77", "name" => "Member number", "value" => member.number.to_s}, - {"id" => "76", "name" => "Pronouns", "value" => member.display_pronouns}, - {"id" => "75", "name" => "Volunteer Interest", "value" => boolean_to_yes_no(member.volunteer_interest)} + { "id" => "77", "name" => "Member number", "value" => member.number.to_s }, + { "id" => "76", "name" => "Pronouns", "value" => member.display_pronouns }, + { "id" => "75", "name" => "Volunteer Interest", "value" => boolean_to_yes_no(member.volunteer_interest) } ] } } end def self.member_to_address(member) - {"addressLine1" => member.address1, + { "addressLine1" => member.address1, "addressLine2" => member.address2, "city" => member.city, "stateProvince" => { @@ -45,7 +47,7 @@ def self.member_to_address(member) "type" => { "id" => "0", "name" => "Home" - }} + } } end def self.boolean_to_yes_no(value) @@ -63,7 +65,7 @@ def initialize(organization_id, api_key) @api_key = api_key logger = Logger.new($stdout) - @http = HTTP.use(logging: {logger: logger}) + @http = HTTP.use(logging: { logger: }) end def new_request diff --git a/app/lib/open_days.rb b/app/lib/open_days.rb index 963c7545f..ad8f8e66c 100644 --- a/app/lib/open_days.rb +++ b/app/lib/open_days.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class OpenDays TIME_SLOTS = [ OpenStruct.new(day: "Thursday", from: 18, to: 20), @@ -21,7 +23,7 @@ def self.next_slots(weeks: 2, time_slots: TIME_SLOTS) end def self.next_slots_for_select(weeks: 2, time_slots: TIME_SLOTS) - next_slots(weeks: weeks, time_slots: time_slots).each_with_object({}) do |date, memo| + next_slots(weeks:, time_slots:).each_with_object({}) do |date, memo| key = date.strftime("%A, %B %-d, %Y") memo[key] ||= [] memo[key] << [ diff --git a/app/lib/result.rb b/app/lib/result.rb index c93a5e619..f01dfd418 100644 --- a/app/lib/result.rb +++ b/app/lib/result.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Result attr_reader :error attr_reader :value diff --git a/app/lib/spectre_form_builder.rb b/app/lib/spectre_form_builder.rb index 29632fa53..4336f3981 100644 --- a/app/lib/spectre_form_builder.rb +++ b/app/lib/spectre_form_builder.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class SpectreFormBuilder < ActionView::Helpers::FormBuilder include ERB::Util @@ -38,21 +40,21 @@ def collection_select(method, collection, value_method, text_method, options = { def tag_select(method, tags) namer = ->(c) { c.path_names.map { |n| h(n) }.join(" ⤏ ").html_safe } - @template.tag.div(data: {controller: "tag-editor"}) do + @template.tag.div(data: { controller: "tag-editor" }) do sequence_layout(method, options) do - parent_collection_select method, tags, :id, namer, {}, data: {target: "tag-editor.input"}, multiple: true + parent_collection_select method, tags, :id, namer, {}, data: { target: "tag-editor.input" }, multiple: true end end end def summarized_collection_select(method, collection, value_method, text_method, options = {}, html_options = {}) - options[:wrapper_options] = {data: {controller: "multi-select"}} - html_options[:data] = {target: "multi-select.control", action: "multi-select#change"} + options[:wrapper_options] = { data: { controller: "multi-select" } } + html_options[:data] = { target: "multi-select.control", action: "multi-select#change" } html_options[:class] = "form-sele5" sequence_layout(method, options) do parent_collection_select(method, collection, value_method, text_method, options, html_options) + - @template.tag.div(data: {target: "multi-select.summary"}, class: "multi-select-summary") + @template.tag.div(data: { target: "multi-select.summary" }, class: "multi-select-summary") end end @@ -124,9 +126,9 @@ def password_field(method, options = {}) def autocomplete_text_field(method, options = {}) text_field(method, options.merge( wrapper_options: { - data: {controller: "autocomplete", action: "input->autocomplete#input", autocomplete_path: options.delete(:path)} + data: { controller: "autocomplete", action: "input->autocomplete#input", autocomplete_path: options.delete(:path) } }, - data: {target: "autocomplete.input"} + data: { target: "autocomplete.input" } )) end @@ -138,9 +140,7 @@ def date_field(method, options = {}) end def actions(&block) - @template.content_tag :div, class: "form-buttons" do - yield - end + @template.content_tag :div, class: "form-buttons", &block end def button(label = nil, options = {}) @@ -148,7 +148,7 @@ def button(label = nil, options = {}) end def submit(label = nil, options = {}, &block) - parent_button(label, options.deep_merge(type: "submit", class: "btn btn-primary btn-lg btn-block", data: {disable: true}), &block) + parent_button(label, options.deep_merge(type: "submit", class: "btn btn-primary btn-lg btn-block", data: { disable: true }), &block) end def errors @@ -158,72 +158,71 @@ def errors end private + # Use this method for inputs where the label has to preceed the input as a sibling + def sequence_layout(method, options = {}) + label_text = label_or_default(options[:label], method) + has_error = @object.errors.include?(method) + display_required = options.delete(:required) + messages = has_error ? @object.errors.messages[method].join(", ") : options.delete(:hint) - # Use this method for inputs where the label has to preceed the input as a sibling - def sequence_layout(method, options = {}) - label_text = label_or_default(options[:label], method) - has_error = @object.errors.include?(method) - display_required = options.delete(:required) - messages = has_error ? @object.errors.messages[method].join(", ") : options.delete(:hint) + hint_content = messages.present? ? @template.tag.div(messages, class: "form-input-hint") : "" - hint_content = messages.present? ? @template.tag.div(messages, class: "form-input-hint") : "" + wrapper_options = options.delete(:wrapper_options) || {} + wrapper_options[:class] ||= "" << " form-group #{"has-error" if has_error}" + wrapper_options[:class].strip! - wrapper_options = options.delete(:wrapper_options) || {} - wrapper_options[:class] ||= "" << " form-group #{"has-error" if has_error}" - wrapper_options[:class].strip! + content_label = options[:label] == false ? "" : label(method, (h(label_text).html_safe + required_label(method, display_required)), { class: "form-label #{options[:label_class]}" }) - content_label = options[:label] == false ? "" : label(method, (h(label_text).html_safe + required_label(method, display_required)), {class: "form-label #{options[:label_class]}"}) - - @template.content_tag :div, wrapper_options do - content_label.html_safe + - yield + - hint_content + @template.content_tag :div, wrapper_options do + content_label.html_safe + + yield + + hint_content + end end - end - def required_label(method, show_label) - if validation_inspector.attribute_required?(method) && show_label.nil? - @template.tag.span("required", class: "label label-warning label-required-field").html_safe - elsif show_label - @template.tag.span("required", class: "label label-warning label-required-field").html_safe - else - "" + def required_label(method, show_label) + if validation_inspector.attribute_required?(method) && show_label.nil? + @template.tag.span("required", class: "label label-warning label-required-field").html_safe + elsif show_label + @template.tag.span("required", class: "label label-warning label-required-field").html_safe + else + "" + end end - end - # Use this method for inputs where the label has to wrap the input - def wrapped_layout(method, options = {}) - label_text = label_or_default(options.delete(:label), method) - has_error = @object.errors.include?(method) - display_required = options.fetch(:required, true) - messages = has_error ? @object.errors.messages[method].join(", ") : options.delete(:hint) - - hint_content = messages.present? ? @template.tag.div(messages, class: "form-input-hint") : "" - - wrapper_options = options.delete(:wrapper_options) || {} - wrapper_options[:class] ||= "" << " form-group #{"has-error" if has_error}" - wrapper_options[:class].strip! - - @template.content_tag :div, wrapper_options do - label_options = {class: "form-label #{options.delete(:label_class)}"} - label_options[:for] = options.delete(:label_for) if options.key?(:label_for) - label(method, **label_options) { - yield + - label_text + - required_label(method, display_required) - } + - hint_content + # Use this method for inputs where the label has to wrap the input + def wrapped_layout(method, options = {}) + label_text = label_or_default(options.delete(:label), method) + has_error = @object.errors.include?(method) + display_required = options.fetch(:required, true) + messages = has_error ? @object.errors.messages[method].join(", ") : options.delete(:hint) + + hint_content = messages.present? ? @template.tag.div(messages, class: "form-input-hint") : "" + + wrapper_options = options.delete(:wrapper_options) || {} + wrapper_options[:class] ||= "" << " form-group #{"has-error" if has_error}" + wrapper_options[:class].strip! + + @template.content_tag :div, wrapper_options do + label_options = { class: "form-label #{options.delete(:label_class)}" } + label_options[:for] = options.delete(:label_for) if options.key?(:label_for) + label(method, **label_options) { + yield + + label_text + + required_label(method, display_required) + } + + hint_content + end end - end - def label_or_default(label, method) - return label if label + def label_or_default(label, method) + return label if label - method_string = method.to_s - if method_string.ends_with?("_ids") - method_string.sub("_ids", "").pluralize.titleize - else - method_string.humanize + method_string = method.to_s + if method_string.ends_with?("_ids") + method_string.sub("_ids", "").pluralize.titleize + else + method_string.humanize + end end - end end diff --git a/app/lib/square_checkout.rb b/app/lib/square_checkout.rb index 0468f7d7a..91ac9ae28 100644 --- a/app/lib/square_checkout.rb +++ b/app/lib/square_checkout.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + class SquareCheckout def initialize(access_token:, location_id:, environment: "production", now: Time.current) - @client = Square::Client.new(access_token: access_token, environment: environment) + @client = Square::Client.new(access_token:, environment:) @location_id = location_id @now = now end @@ -9,7 +11,7 @@ def checkout_url(amount:, email:, date:, member_id:, return_to:, idempotency_key checkout_response = @client.checkout.create_checkout( location_id: @location_id, body: { - idempotency_key: idempotency_key, + idempotency_key:, redirect_url: return_to, pre_populate_buyer_email: email, order: { @@ -39,7 +41,7 @@ def checkout_url(amount:, email:, date:, member_id:, return_to:, idempotency_key def fetch_transaction(member:, transaction_id:) transaction_response = @client.transactions.retrieve_transaction( location_id: @location_id, - transaction_id: transaction_id + transaction_id: ) if transaction_response.success? @@ -56,8 +58,7 @@ def fetch_transaction(member:, transaction_id:) end private - - def random_idempotency_key - rand(1_000_000_000).to_s - end + def random_idempotency_key + rand(1_000_000_000).to_s + end end diff --git a/app/lib/step.rb b/app/lib/step.rb index 127892913..550b21e91 100644 --- a/app/lib/step.rb +++ b/app/lib/step.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Step attr_accessor :id attr_accessor :name diff --git a/app/lib/validation_inspector.rb b/app/lib/validation_inspector.rb index 22f0aff3e..bf15c6b31 100644 --- a/app/lib/validation_inspector.rb +++ b/app/lib/validation_inspector.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Provides convenience methods for introspecting the validations defined on a model class ValidationInspector def initialize(klass) diff --git a/app/lib/volunteer/day.rb b/app/lib/volunteer/day.rb index d905da212..f7fe830da 100644 --- a/app/lib/volunteer/day.rb +++ b/app/lib/volunteer/day.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Volunteer class Day def initialize(date, today, events, state = nil) diff --git a/app/lib/volunteer/month_calendar.rb b/app/lib/volunteer/month_calendar.rb index c55697fcb..11bbadad2 100644 --- a/app/lib/volunteer/month_calendar.rb +++ b/app/lib/volunteer/month_calendar.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Volunteer class MonthCalendar attr_reader :first_date diff --git a/app/lib/volunteer/shift.rb b/app/lib/volunteer/shift.rb index 15fb7a7c0..8a87b52c2 100644 --- a/app/lib/volunteer/shift.rb +++ b/app/lib/volunteer/shift.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Volunteer class Shift FULLY_STAFFED_COUNT = 2 diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 20e381507..731de3014 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ApplicationMailer < ActionMailer::Base default from: "Chicago Tool Library " layout "mailer" diff --git a/app/mailers/gift_purchaser_mailer.rb b/app/mailers/gift_purchaser_mailer.rb index 582c9fe21..dcc6dcb1b 100644 --- a/app/mailers/gift_purchaser_mailer.rb +++ b/app/mailers/gift_purchaser_mailer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class GiftPurchaserMailer < ApplicationMailer before_action :generate_uuid after_action :set_uuid_header @@ -16,20 +18,19 @@ def confirmation end private + def generate_uuid + @uuid = SecureRandom.uuid + end - def generate_uuid - @uuid = SecureRandom.uuid - end + def set_uuid_header + headers["X-SMTPAPI"] = { + unique_args: { + uuid: @uuid + } + }.to_json + end - def set_uuid_header - headers["X-SMTPAPI"] = { - unique_args: { - uuid: @uuid - } - }.to_json - end - - def store_notification - Notification.create!(uuid: @uuid, action: action_name, address: @gift_membership.purchaser_email, subject: @subject, library: @library) - end + def store_notification + Notification.create!(uuid: @uuid, action: action_name, address: @gift_membership.purchaser_email, subject: @subject, library: @library) + end end diff --git a/app/mailers/homepage_mailer.rb b/app/mailers/homepage_mailer.rb index 02b183efb..7b7b781cc 100644 --- a/app/mailers/homepage_mailer.rb +++ b/app/mailers/homepage_mailer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class HomepageMailer < ApplicationMailer def inquiry @homepage_inquiry = params[:homepage_params] diff --git a/app/mailers/member_mailer.rb b/app/mailers/member_mailer.rb index a1ad3a654..fbe4b8d97 100644 --- a/app/mailers/member_mailer.rb +++ b/app/mailers/member_mailer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class MemberMailer < ApplicationMailer include DateHelper @@ -95,29 +97,28 @@ def appointment_confirmation end private - - def summary_mail(template_name: "summary") - @member = params[:member] - @library = @member.library - @summaries = params[:summaries] - @now = params[:now] || Time.current - - mail(to: @member.email, subject: @subject, template_name: template_name) - end - - def generate_uuid - @uuid = SecureRandom.uuid - end - - def set_uuid_header - headers["X-SMTPAPI"] = { - unique_args: { - uuid: @uuid - } - }.to_json - end - - def store_notification - Notification.create!(member: @member, uuid: @uuid, action: action_name, address: @member.email, subject: @subject, library: @library) - end + def summary_mail(template_name: "summary") + @member = params[:member] + @library = @member.library + @summaries = params[:summaries] + @now = params[:now] || Time.current + + mail(to: @member.email, subject: @subject, template_name:) + end + + def generate_uuid + @uuid = SecureRandom.uuid + end + + def set_uuid_header + headers["X-SMTPAPI"] = { + unique_args: { + uuid: @uuid + } + }.to_json + end + + def store_notification + Notification.create!(member: @member, uuid: @uuid, action: action_name, address: @member.email, subject: @subject, library: @library) + end end diff --git a/app/mailers/member_mailer_observer.rb b/app/mailers/member_mailer_observer.rb index acf521920..846e4f58b 100644 --- a/app/mailers/member_mailer_observer.rb +++ b/app/mailers/member_mailer_observer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class MemberMailerObserver def self.delivered_email(message) return unless message["X-SMTPAPI"] @@ -5,6 +7,6 @@ def self.delivered_email(message) smtpapi_json = message["X-SMTPAPI"].value smtpapi_args = JSON.parse(smtpapi_json) uuid = smtpapi_args.dig("unique_args", "uuid") - Notification.where(uuid: uuid).update(status: "sent") + Notification.where(uuid:).update(status: "sent") end end diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index f7f7b6fce..737aad244 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class UserMailer < Devise::Mailer default from: "Chicago Tool Library " after_action :store_notification, only: [:reset_password_instructions] diff --git a/app/models/adjustment.rb b/app/models/adjustment.rb index aa7767f28..3f7a561cb 100644 --- a/app/models/adjustment.rb +++ b/app/models/adjustment.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Adjustment < ApplicationRecord monetize :amount_cents @@ -34,9 +36,9 @@ def self.record_member_payment(member, amount, source, square_transaction_id = n end adjustments << member.adjustments.create!( payment_source: source, - amount: amount, + amount:, kind: "payment", - square_transaction_id: square_transaction_id + square_transaction_id: ) adjustments end diff --git a/app/models/agreement_acceptance.rb b/app/models/agreement_acceptance.rb index 7cfebc046..89d2fad1b 100644 --- a/app/models/agreement_acceptance.rb +++ b/app/models/agreement_acceptance.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AgreementAcceptance < ApplicationRecord belongs_to :member diff --git a/app/models/application_record.rb b/app/models/application_record.rb index 10a4cba84..71fbba5b3 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ApplicationRecord < ActiveRecord::Base self.abstract_class = true end diff --git a/app/models/appointment.rb b/app/models/appointment.rb index 9001ac221..9260649cc 100644 --- a/app/models/appointment.rb +++ b/app/models/appointment.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Appointment < ApplicationRecord has_many :appointment_holds, dependent: :destroy has_many :appointment_loans, dependent: :destroy @@ -45,34 +47,33 @@ def merge!(other_appointment) end private - - def item_present - if holds.empty? && loans.empty? - errors.add(:base, "Please select an item to pick-up or return for your appointment") + def item_present + if holds.empty? && loans.empty? + errors.add(:base, "Please select an item to pick-up or return for your appointment") + end end - end - def date_present - if starts_at.nil? || ends_at.nil? - errors.add(:base, "Please select a date and time for this appointment.") + def date_present + if starts_at.nil? || ends_at.nil? + errors.add(:base, "Please select a date and time for this appointment.") + end end - end - def ends_at_later_than_starts_at - return if ends_at.blank? || starts_at.blank? + def ends_at_later_than_starts_at + return if ends_at.blank? || starts_at.blank? - if ends_at < starts_at - errors.add(:ends_at, "must be after the starts_at date") + if ends_at < starts_at + errors.add(:ends_at, "must be after the starts_at date") + end end - end - def starts_before_holds_expire - holds_first_expire = holds.filter_map(&:expires_at).min - return unless starts_at + def starts_before_holds_expire + holds_first_expire = holds.filter_map(&:expires_at).min + return unless starts_at - before_holds_expire = holds_first_expire.nil? || starts_at <= holds_first_expire - unless before_holds_expire - errors.add(:base, "Please pick an appointment on or before hold expires on #{holds_first_expire.strftime("%a, %-m/%-d")}.") + before_holds_expire = holds_first_expire.nil? || starts_at <= holds_first_expire + unless before_holds_expire + errors.add(:base, "Please pick an appointment on or before hold expires on #{holds_first_expire.strftime("%a, %-m/%-d")}.") + end end - end end diff --git a/app/models/appointment_hold.rb b/app/models/appointment_hold.rb index 941b13392..a228b66d9 100644 --- a/app/models/appointment_hold.rb +++ b/app/models/appointment_hold.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AppointmentHold < ApplicationRecord belongs_to :appointment belongs_to :hold diff --git a/app/models/appointment_loan.rb b/app/models/appointment_loan.rb index 60e0e756e..e9d78c628 100644 --- a/app/models/appointment_loan.rb +++ b/app/models/appointment_loan.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AppointmentLoan < ApplicationRecord belongs_to :appointment belongs_to :loan diff --git a/app/models/attendee.rb b/app/models/attendee.rb index 1898555c8..f1895658e 100644 --- a/app/models/attendee.rb +++ b/app/models/attendee.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Attendee include StoreModel::Model diff --git a/app/models/borrow_policy.rb b/app/models/borrow_policy.rb index 4acf2e564..4c248edb7 100644 --- a/app/models/borrow_policy.rb +++ b/app/models/borrow_policy.rb @@ -1,17 +1,19 @@ +# frozen_string_literal: true + class BorrowPolicy < ApplicationRecord monetize :fine_cents, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 10 } validates :name, - presence: true, uniqueness: {scope: :library_id, case_sensitive: false} + presence: true, uniqueness: { scope: :library_id, case_sensitive: false } validates_numericality_of :duration, only_integer: true, greater_than_or_equal_to: 1, less_than: 365 validates_numericality_of :fine_period, only_integer: true, greater_than_or_equal_to: 1, less_than_or_equal_to: 100 validates_numericality_of :renewal_limit, only_integer: true, greater_than_or_equal_to: 0, less_than_or_equal_to: 52 - validates :code, inclusion: {in: "A".."ZZ", message: "must be 1 or 2 letters from A to ZZ"}, uniqueness: {scope: :library_id} + validates :code, inclusion: { in: "A".."ZZ", message: "must be 1 or 2 letters from A to ZZ" }, uniqueness: { scope: :library_id } validate :require_consumables_to_not_be_uniquely_numbered @@ -45,16 +47,15 @@ def allow_one_holds_per_member? after_save :make_only_default private - - def make_only_default - if default - self.class.where("id != ?", id).update_all(default: false) + def make_only_default + if default + self.class.where("id != ?", id).update_all(default: false) + end end - end - def require_consumables_to_not_be_uniquely_numbered - if consumable? && uniquely_numbered - errors.add(:uniquely_numbered, "must not be enabled for consumables") + def require_consumables_to_not_be_uniquely_numbered + if consumable? && uniquely_numbered + errors.add(:uniquely_numbered, "must not be enabled for consumables") + end end - end end diff --git a/app/models/categorization.rb b/app/models/categorization.rb index 8b8318eb2..5323c5be1 100644 --- a/app/models/categorization.rb +++ b/app/models/categorization.rb @@ -1,15 +1,16 @@ +# frozen_string_literal: true + class Categorization < ApplicationRecord belongs_to :item belongs_to :category, counter_cache: true belongs_to :category_node, foreign_key: "category_id" - validates :category_id, uniqueness: {scope: :item_id} + validates :category_id, uniqueness: { scope: :item_id } after_save :refresh_category_nodes after_destroy :refresh_category_nodes private - - def refresh_category_nodes - CategoryNode.refresh - end + def refresh_category_nodes + CategoryNode.refresh + end end diff --git a/app/models/category.rb b/app/models/category.rb index 9a3886f0a..82bdfbdc5 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Category < ApplicationRecord has_many :categorizations, dependent: :destroy has_many :items, through: :categorizations @@ -5,8 +7,8 @@ class Category < ApplicationRecord belongs_to :parent, class_name: "Category", required: false has_many :children, class_name: "Category", foreign_key: "parent_id", dependent: :destroy - validates :name, presence: true, uniqueness: {scope: :library_id} - validates :slug, presence: true, uniqueness: {scope: :library_id} + validates :name, presence: true, uniqueness: { scope: :library_id } + validates :slug, presence: true, uniqueness: { scope: :library_id } before_validation :assign_slug after_commit :refresh_category_nodes diff --git a/app/models/category_node.rb b/app/models/category_node.rb index 30acea47f..348e066a0 100644 --- a/app/models/category_node.rb +++ b/app/models/category_node.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CategoryNode < ApplicationRecord self.primary_key = :id diff --git a/app/models/document.rb b/app/models/document.rb index c71eb8d1e..a5369c01b 100644 --- a/app/models/document.rb +++ b/app/models/document.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + class Document < ApplicationRecord has_rich_text :body validates_presence_of :name, :summary - scope :coded, ->(code) { where(code: code) } + scope :coded, ->(code) { where(code:) } acts_as_tenant :library diff --git a/app/models/event.rb b/app/models/event.rb index bcf1e7877..66fd76e35 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Event < ApplicationRecord attribute :attendees, Attendee.to_array_type, default: [] diff --git a/app/models/gift_membership.rb b/app/models/gift_membership.rb index 61a6650e4..426675044 100644 --- a/app/models/gift_membership.rb +++ b/app/models/gift_membership.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class GiftMembership < ApplicationRecord monetize :amount_cents, numericality: { greater_than_or_equal_to: 0 @@ -6,9 +8,9 @@ class GiftMembership < ApplicationRecord composed_of :code, class_name: "GiftMembershipCode", mapping: %w[code value], allow_nil: true belongs_to :membership, required: false - validates :purchaser_email, format: {with: URI::MailTo::EMAIL_REGEXP, message: "must be a valid email"} + validates :purchaser_email, format: { with: URI::MailTo::EMAIL_REGEXP, message: "must be a valid email" } validates :purchaser_name, presence: true - validates :code, presence: true, uniqueness: {scope: :library_id} + validates :code, presence: true, uniqueness: { scope: :library_id } before_validation :set_code, if: ->(gm) { gm.code.blank? } @@ -33,16 +35,15 @@ def read_attribute_for_validation(attr) end private + def set_code + self.code = find_random_unique_code + end - def set_code - self.code = find_random_unique_code - end - - def find_random_unique_code - 5.times do |n| - code = GiftMembershipCode.random - return code if self.class.unique_code?(code) + def find_random_unique_code + 5.times do |n| + code = GiftMembershipCode.random + return code if self.class.unique_code?(code) + end + raise "could not find a unique code" end - raise "could not find a unique code" - end end diff --git a/app/models/gift_membership_code.rb b/app/models/gift_membership_code.rb index 5f48bf0e9..fd6ed0f1f 100644 --- a/app/models/gift_membership_code.rb +++ b/app/models/gift_membership_code.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class GiftMembershipCode CODE_CHARACTERS = %w[3 6 7 C D F G H J K M N P R T W X] CODE_SIZE = 8 diff --git a/app/models/hold.rb b/app/models/hold.rb index 27d8232d9..7eceacd0c 100644 --- a/app/models/hold.rb +++ b/app/models/hold.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Hold < ApplicationRecord HOLD_LENGTH = 7.days @@ -28,7 +30,7 @@ class Hold < ApplicationRecord acts_as_tenant :library def self.active_hold_count_for_item(item) - active.where(item: item).count + active.where(item:).count end # active and inactive are mutually exclusive @@ -68,7 +70,7 @@ def started? end def previous_active_holds(now = Time.current) - Hold.active(now).where("created_at < ?", created_at).where(item: item).where.not(member: member).order(:ended_at).to_a + Hold.active(now).where("created_at < ?", created_at).where(item:).where.not(member:).order(:ended_at).to_a end def ready_for_pickup?(now = Time.current) @@ -131,12 +133,11 @@ def self.start_waiting_holds(now = Time.current, &block) end private - - def ensure_items_are_holdable - return unless item - item.reload - unless item.holdable? - errors.add(:item, "can not be placed on hold") + def ensure_items_are_holdable + return unless item + item.reload + unless item.holdable? + errors.add(:item, "can not be placed on hold") + end end - end end diff --git a/app/models/item.rb b/app/models/item.rb index 75807b279..1563c58bb 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Item < ApplicationRecord STATUS_NAMES = { "pending" => "Pending", @@ -24,7 +26,7 @@ class Item < ApplicationRecord size: "D", strength: "D" }, - using: {tsearch: {prefix: true, dictionary: "english"}} + using: { tsearch: { prefix: true, dictionary: "english" } } has_many :categorizations, dependent: :destroy has_many :categories, through: :categorizations, @@ -81,20 +83,20 @@ def next_hold scope :strength_contains, ->(query) { where("strength ILIKE ?", "#{"%" if query.size > 1}#{query}%").limit(10).distinct } scope :listed_publicly, -> { where("status = ? OR status = ?", Item.statuses[:active], Item.statuses[:maintenance]) } scope :with_category, ->(category) { joins(:categories).merge(category.items) } - scope :for_category, ->(category) { joins(:categorizations).where(categorizations: {category_id: CategoryNode.find(category.id).tree_ids}).distinct } - scope :available, -> { left_outer_joins(:checked_out_exclusive_loan).where(loans: {id: nil}) } - scope :without_attached_image, -> { left_joins(:image_attachment).where(active_storage_attachments: {record_id: nil}) } + scope :for_category, ->(category) { joins(:categorizations).where(categorizations: { category_id: CategoryNode.find(category.id).tree_ids }).distinct } + scope :available, -> { left_outer_joins(:checked_out_exclusive_loan).where(loans: { id: nil }) } + scope :without_attached_image, -> { left_joins(:image_attachment).where(active_storage_attachments: { record_id: nil }) } scope :in_maintenance, -> { where(status: Item.statuses.values_at(:maintenance)) } scope :by_name, -> { order(name: :asc) } validates :name, presence: true - validates :number, numericality: {only_integer: true}, uniqueness: {scope: :library} - validates :status, inclusion: {in: Item.statuses.keys} - validates :power_source, inclusion: {in: Item.power_sources.keys}, allow_blank: true - validates :borrow_policy_id, inclusion: {in: ->(item) { BorrowPolicy.pluck(:id) }} - validates :quantity, numericality: {only_integer: true, greater_than_or_equal_to: 0}, if: ->(item) { item.borrow_policy && item.borrow_policy.consumable? } - validates :url, format: {with: URI::DEFAULT_PARSER.make_regexp, message: "must be a valid URL", allow_blank: true} + validates :number, numericality: { only_integer: true }, uniqueness: { scope: :library } + validates :status, inclusion: { in: Item.statuses.keys } + validates :power_source, inclusion: { in: Item.power_sources.keys }, allow_blank: true + validates :borrow_policy_id, inclusion: { in: ->(item) { BorrowPolicy.pluck(:id) } } + validates :quantity, numericality: { only_integer: true, greater_than_or_equal_to: 0 }, if: ->(item) { item.borrow_policy && item.borrow_policy.consumable? } + validates :url, format: { with: URI::DEFAULT_PARSER.make_regexp, message: "must be a valid URL", allow_blank: true } before_validation :assign_number, on: :create before_validation :strip_whitespace @@ -114,7 +116,7 @@ def self.next_number(limit = nil) def self.find_by_complete_number(complete_number) code, number = complete_number.split("-") - joins(:borrow_policy).find_by(borrow_policies: {code: code}, number: number.to_i) + joins(:borrow_policy).find_by(borrow_policies: { code: }, number: number.to_i) end def assign_number @@ -183,49 +185,48 @@ def increment_quantity end private - - def cache_description_as_plain_text - self.plain_text_description = description.to_plain_text - end - - def strip_whitespace - %w[name brand size model serial strength].each do |attr_name| - value = attributes[attr_name] - next unless value.present? - write_attribute attr_name, value.strip + def cache_description_as_plain_text + self.plain_text_description = description.to_plain_text end - end - def clear_holds_if_inactive - if saved_change_to_status? && status == Item.statuses[:retired] - active_holds.update_all(ended_at: Time.current) + def strip_whitespace + %w[name brand size model serial strength].each do |attr_name| + value = attributes[attr_name] + next unless value.present? + write_attribute attr_name, value.strip + end end - end - def pause_next_hold_if_maintenance - if saved_change_to_status? && status == Item.statuses[:maintenance] - next_hold&.update_columns(started_at: nil, expires_at: nil) + def clear_holds_if_inactive + if saved_change_to_status? && status == Item.statuses[:retired] + active_holds.update_all(ended_at: Time.current) + end end - end - def cache_category_ids(category) - @current_category_ids ||= Categorization.where(item_id: id).pluck(:category_id).sort - end + def pause_next_hold_if_maintenance + if saved_change_to_status? && status == Item.statuses[:maintenance] + next_hold&.update_columns(started_at: nil, expires_at: nil) + end + end - # called when item is created - def audited_attributes - super.merge("category_ids" => category_ids.sort) - end + def cache_category_ids(category) + @current_category_ids ||= Categorization.where(item_id: id).pluck(:category_id).sort + end - # called when item is updated - def audited_changes - unless @current_category_ids.present? - cache_category_ids(nil) + # called when item is created + def audited_attributes + super.merge("category_ids" => category_ids.sort) end - if (@current_category_ids.present? || category_ids.present?) && @current_category_ids != category_ids.sort - super.merge("category_ids" => [@current_category_ids, category_ids.sort]) - else - super + + # called when item is updated + def audited_changes + unless @current_category_ids.present? + cache_category_ids(nil) + end + if (@current_category_ids.present? || category_ids.present?) && @current_category_ids != category_ids.sort + super.merge("category_ids" => [@current_category_ids, category_ids.sort]) + else + super + end end - end end diff --git a/app/models/item_attachment.rb b/app/models/item_attachment.rb index bc244cae7..c0f4a8db0 100644 --- a/app/models/item_attachment.rb +++ b/app/models/item_attachment.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ItemAttachment < ApplicationRecord belongs_to :item belongs_to :creator, class_name: "User" @@ -10,12 +12,11 @@ class ItemAttachment < ApplicationRecord "other" => "other" } - validates :kind, inclusion: {in: ItemAttachment.kinds.keys} + validates :kind, inclusion: { in: ItemAttachment.kinds.keys } validate :file_is_attached private - - def file_is_attached - errors.add(:file, "is required") unless file.attached? - end + def file_is_attached + errors.add(:file, "is required") unless file.attached? + end end diff --git a/app/models/library.rb b/app/models/library.rb index 49ec8c667..4d4aecf00 100644 --- a/app/models/library.rb +++ b/app/models/library.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Library < ApplicationRecord validates :name, presence: true validates :hostname, presence: true, uniqueness: true @@ -30,20 +32,19 @@ def admissible_postal_codes end private + def create_docs + documents.create!(name: "Borrow Policy", code: "borrow_policy", summary: "Covers the rules of borrowing. Shown on the first page of member signup.") + documents.create!(name: "Agreement", code: "agreement", summary: "Member Waiver of Indemnification") + end - def create_docs - documents.create!(name: "Borrow Policy", code: "borrow_policy", summary: "Covers the rules of borrowing. Shown on the first page of member signup.") - documents.create!(name: "Agreement", code: "agreement", summary: "Member Waiver of Indemnification") - end - - def member_postal_code_regexp - return if member_postal_code_pattern.blank? + def member_postal_code_regexp + return if member_postal_code_pattern.blank? - begin - Regexp.new(member_postal_code_pattern) - rescue => e - logger.debug "Error parsing `member_postal_code_pattern` `#{member_postal_code_pattern}': #{e}" - errors.add(:member_postal_code_pattern, :invalid) + begin + Regexp.new(member_postal_code_pattern) + rescue => e + logger.debug "Error parsing `member_postal_code_pattern` `#{member_postal_code_pattern}': #{e}" + errors.add(:member_postal_code_pattern, :invalid) + end end - end end diff --git a/app/models/library_update.rb b/app/models/library_update.rb index b184659d7..a4e5e2ac3 100644 --- a/app/models/library_update.rb +++ b/app/models/library_update.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class LibraryUpdate < ApplicationRecord acts_as_tenant :library diff --git a/app/models/loan.rb b/app/models/loan.rb index 5be912d3a..1ed6018be 100644 --- a/app/models/loan.rb +++ b/app/models/loan.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Loan < ApplicationRecord belongs_to :item, optional: true belongs_to :member @@ -9,7 +11,7 @@ class Loan < ApplicationRecord validates :due_at, presence: true validates_numericality_of :ended_at, allow_nil: true, greater_than_or_equal_to: ->(loan) { loan.created_at } - validates :initial_loan_id, uniqueness: {scope: :renewal_count}, if: ->(l) { l.initial_loan_id.present? } + validates :initial_loan_id, uniqueness: { scope: :renewal_count }, if: ->(l) { l.initial_loan_id.present? } validates_each :item_id do |record, attr, value| if value @@ -81,7 +83,7 @@ def self.next_open_day(time) def self.lend(item, to:, now: Time.current) due_at = next_open_day(now.end_of_day + item.borrow_policy.duration.days) - Loan.new(member: to, item: item, due_at: due_at, uniquely_numbered: item&.borrow_policy&.uniquely_numbered, created_at: now) + Loan.new(member: to, item:, due_at:, uniquely_numbered: item&.borrow_policy&.uniquely_numbered, created_at: now) end # Will another renewal exceed the maximum number of renewals? diff --git a/app/models/loan_summary.rb b/app/models/loan_summary.rb index f2c1c864e..a265f9a82 100644 --- a/app/models/loan_summary.rb +++ b/app/models/loan_summary.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class LoanSummary < ApplicationRecord self.primary_key = :initial_loan_id @@ -10,7 +12,7 @@ class LoanSummary < ApplicationRecord scope :active_on, ->(date) { morning = date.beginning_of_day.utc night = date.end_of_day.utc - where("loan_summaries.created_at BETWEEN :morning AND :night OR loan_summaries.ended_at BETWEEN :morning AND :night OR renewal_requests.updated_at BETWEEN :morning AND :night", morning: morning, night: night).includes(:renewal_requests).references(:renewal_requests) + where("loan_summaries.created_at BETWEEN :morning AND :night OR loan_summaries.ended_at BETWEEN :morning AND :night OR renewal_requests.updated_at BETWEEN :morning AND :night", morning:, night:).includes(:renewal_requests).references(:renewal_requests) } scope :checked_out, -> { where(ended_at: nil) } diff --git a/app/models/member.rb b/app/models/member.rb index 0c0e098f8..ad9d1bbb0 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Member < ApplicationRecord has_many :acceptances, class_name: "AgreementAcceptance", dependent: :destroy has_many :adjustments, dependent: :destroy @@ -25,14 +27,14 @@ class Member < ApplicationRecord enum status: [:pending, :verified, :suspended, :deactivated], _prefix: true validates :email, - format: {with: URI::MailTo::EMAIL_REGEXP, message: "must be a valid email"}, - uniqueness: {conditions: -> { where.not(status: "deactivated") }} + format: { with: URI::MailTo::EMAIL_REGEXP, message: "must be a valid email" }, + uniqueness: { conditions: -> { where.not(status: "deactivated") } } validates :full_name, presence: true - validates :phone_number, length: {is: 10, blank: false, message: "must be 10 digits"} + validates :phone_number, length: { is: 10, blank: false, message: "must be 10 digits" } validates :address1, presence: true validates :city, presence: true validates :region, presence: true - validates :postal_code, length: {is: 5, blank: false, message: "must be 5 digits"} + validates :postal_code, length: { is: 5, blank: false, message: "must be 5 digits" } validate :postal_code_must_be_in_library_service_area scope :matching, ->(query) { @@ -112,44 +114,43 @@ def display_pronouns def upcoming_appointment_of(schedulable) if schedulable.is_a? Hold - appointments.upcoming.joins(:holds).where(holds: {id: schedulable.id}).first + appointments.upcoming.joins(:holds).where(holds: { id: schedulable.id }).first elsif schedulable.is_a? Loan - appointments.upcoming.joins(:loans).where(loans: {id: schedulable.id}).first + appointments.upcoming.joins(:loans).where(loans: { id: schedulable.id }).first end end private + def update_user_email + user.update_column(:email, email) if user && !user.new_record? # Skip validations + end - def update_user_email - user.update_column(:email, email) if user && !user.new_record? # Skip validations - end - - def update_neon_crm - NeonMemberJob.perform_async(id) - end + def update_neon_crm + NeonMemberJob.perform_async(id) + end - def can_update_neon_crm? - Rails.env.production? && Neon.credentials_for_library(library) - end + def can_update_neon_crm? + Rails.env.production? && Neon.credentials_for_library(library) + end - def strip_phone_number - self.phone_number = phone_number.gsub(/\D/, "") - end + def strip_phone_number + self.phone_number = phone_number.gsub(/\D/, "") + end - def set_default_address_fields - self.city ||= library.city - self.region ||= "IL" - end + def set_default_address_fields + self.city ||= library.city + self.region ||= "IL" + end - def downcase_email - self.email = email.try(:downcase) - end + def downcase_email + self.email = email.try(:downcase) + end - def postal_code_must_be_in_library_service_area - return unless library && postal_code.present? + def postal_code_must_be_in_library_service_area + return unless library && postal_code.present? - unless library.allows_postal_code?(postal_code) - errors.add :postal_code, "must be one of: #{library.admissible_postal_codes.join(", ")}" + unless library.allows_postal_code?(postal_code) + errors.add :postal_code, "must be one of: #{library.admissible_postal_codes.join(", ")}" + end end - end end diff --git a/app/models/membership.rb b/app/models/membership.rb index c5cb1c009..7ad581b8b 100644 --- a/app/models/membership.rb +++ b/app/models/membership.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Membership < ApplicationRecord class PendingMembership < StandardError; end @@ -74,7 +76,7 @@ def self.next_start_date_for_member(member, now: Time.current) def self.create_for_member(member, amount: 0, source: nil, start_membership: false, now: Time.current, square_transaction_id: nil) if start_membership - start_date = next_start_date_for_member(member, now: now) + start_date = next_start_date_for_member(member, now:) raise PendingMembership.new("member with pending membership can't start a new membership") unless start_date membership = member.memberships.create!(started_at: start_date, ended_at: start_date + 365.days, library: member.library) @@ -90,22 +92,21 @@ def self.create_for_member(member, amount: 0, source: nil, start_membership: fal end private + def no_overlapping_dates + overlapping = member.memberships.where( + "started_at BETWEEN ? AND ? OR ended_at BETWEEN ? AND ?", + started_at, ended_at, started_at, ended_at + ).count - def no_overlapping_dates - overlapping = member.memberships.where( - "started_at BETWEEN ? AND ? OR ended_at BETWEEN ? AND ?", - started_at, ended_at, started_at, ended_at - ).count - - errors.add(:base, "can't overlap with another membership") if overlapping > 0 - end + errors.add(:base, "can't overlap with another membership") if overlapping > 0 + end - def start_after_end - return true unless started_at && ended_at + def start_after_end + return true unless started_at && ended_at - if started_at > ended_at - errors.add(:started_at, "must start before end") - errors.add(:ended_at, "must end after start") + if started_at > ended_at + errors.add(:started_at, "must start before end") + errors.add(:ended_at, "must end after start") + end end - end end diff --git a/app/models/monthly_adjustment.rb b/app/models/monthly_adjustment.rb index 2cf434343..96eb08dee 100644 --- a/app/models/monthly_adjustment.rb +++ b/app/models/monthly_adjustment.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class MonthlyAdjustment < ApplicationRecord self.primary_key = :year # to handle cases where the primary key is added to order clauses diff --git a/app/models/monthly_appointment.rb b/app/models/monthly_appointment.rb index 3aeefaae5..1ab0fff82 100644 --- a/app/models/monthly_appointment.rb +++ b/app/models/monthly_appointment.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + class MonthlyAppointment < ApplicationRecord end diff --git a/app/models/monthly_loan.rb b/app/models/monthly_loan.rb index 5ee9094c5..2947dcca2 100644 --- a/app/models/monthly_loan.rb +++ b/app/models/monthly_loan.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + class MonthlyLoan < ApplicationRecord end diff --git a/app/models/monthly_member.rb b/app/models/monthly_member.rb index d8fa479b4..1da92ca4b 100644 --- a/app/models/monthly_member.rb +++ b/app/models/monthly_member.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + class MonthlyMember < ApplicationRecord end diff --git a/app/models/note.rb b/app/models/note.rb index 784feb756..79907ddc7 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Note < ApplicationRecord belongs_to :creator, class_name: "User" belongs_to :notable, polymorphic: true diff --git a/app/models/notification.rb b/app/models/notification.rb index 08855d59f..2898bab44 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Notification < ApplicationRecord enum status: { pending: "pending", @@ -11,7 +13,7 @@ class Notification < ApplicationRecord validates :address, presence: true validates :action, presence: true validates :uuid, presence: true - validates :status, inclusion: {in: Notification.statuses.keys} + validates :status, inclusion: { in: Notification.statuses.keys } acts_as_tenant :library end diff --git a/app/models/renewal_request.rb b/app/models/renewal_request.rb index 93e33373b..965a8aae9 100644 --- a/app/models/renewal_request.rb +++ b/app/models/renewal_request.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class RenewalRequest < ApplicationRecord belongs_to :loan @@ -7,7 +9,7 @@ class RenewalRequest < ApplicationRecord rejected: "rejected" } - validates :status, inclusion: {in: RenewalRequest.statuses.keys} + validates :status, inclusion: { in: RenewalRequest.statuses.keys } acts_as_tenant :library end diff --git a/app/models/short_link.rb b/app/models/short_link.rb index 33f1b5d43..325df1ef8 100644 --- a/app/models/short_link.rb +++ b/app/models/short_link.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "uri" class ShortLink < ApplicationRecord @@ -5,8 +7,8 @@ class ShortLink < ApplicationRecord MAX_ITERATIONS = 10 VALID_CHARS = ["a".."z", "A".."Z", "0".."9"].inject([]) { |a, r| a.concat(r.to_a) } - validates :slug, presence: true, uniqueness: {scope: :library_id} - validates :url, format: {with: URI::DEFAULT_PARSER.make_regexp, message: "must be a valid URL"}, uniqueness: {scope: :library_id} + validates :slug, presence: true, uniqueness: { scope: :library_id } + validates :url, format: { with: URI::DEFAULT_PARSER.make_regexp, message: "must be a valid URL" }, uniqueness: { scope: :library_id } before_validation :generate_slug @@ -17,7 +19,7 @@ def views end def self.for_url(url) - link = find_or_initialize_by(url: url) + link = find_or_initialize_by(url:) link.save! link end @@ -28,27 +30,26 @@ def record_view end private + def generate_slug + self.slug = find_random_unique_slug + end - def generate_slug - self.slug = find_random_unique_slug - end - - def find_random_unique_slug - slug = nil - MAX_ITERATIONS.times do |n| - slug = random_slug(SLUG_LENGTH) - break if unique_slug?(slug) - raise "could not find a unique slug" if n == (MAX_ITERATIONS - 1) + def find_random_unique_slug + slug = nil + MAX_ITERATIONS.times do |n| + slug = random_slug(SLUG_LENGTH) + break if unique_slug?(slug) + raise "could not find a unique slug" if n == (MAX_ITERATIONS - 1) + end + slug end - slug - end - def unique_slug?(slug) - self.class.where(slug: slug).count == 0 - end + def unique_slug?(slug) + self.class.where(slug:).count == 0 + end - def random_slug(length) - chars = VALID_CHARS - length.times.inject("") { |s| s << chars[rand(chars.size)] } - end + def random_slug(length) + chars = VALID_CHARS + length.times.inject("") { |s| s << chars[rand(chars.size)] } + end end diff --git a/app/models/ticket.rb b/app/models/ticket.rb index 09ff16911..17c8864d2 100644 --- a/app/models/ticket.rb +++ b/app/models/ticket.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Ticket < ApplicationRecord STATUS_NAMES = { "assess" => "Assess", @@ -28,7 +30,7 @@ class Ticket < ApplicationRecord has_rich_text :body validates :title, presence: true - validates :status, inclusion: {in: Ticket.statuses.keys} + validates :status, inclusion: { in: Ticket.statuses.keys } audited acts_as_tenant :library diff --git a/app/models/ticket_update.rb b/app/models/ticket_update.rb index 72c01941c..c62e33b35 100644 --- a/app/models/ticket_update.rb +++ b/app/models/ticket_update.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class TicketUpdate < ApplicationRecord belongs_to :ticket, touch: true belongs_to :creator, class_name: "User" @@ -5,7 +7,7 @@ class TicketUpdate < ApplicationRecord has_rich_text :body validates :body, presence: true - validates :time_spent, numericality: {allow_blank: true} + validates :time_spent, numericality: { allow_blank: true } acts_as_tenant :library diff --git a/app/models/user.rb b/app/models/user.rb index 690d6df6f..30ffc9438 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class User < ApplicationRecord devise :database_authenticatable, :recoverable, :rememberable, :lockable, :timeoutable, :trackable, :validatable diff --git a/app/nulls/null_association_proxy.rb b/app/nulls/null_association_proxy.rb index 0f4529c57..c425a1a5c 100644 --- a/app/nulls/null_association_proxy.rb +++ b/app/nulls/null_association_proxy.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class NullAssociationProxy def count 0 diff --git a/app/nulls/null_attachment.rb b/app/nulls/null_attachment.rb index e9a2feef4..d5376b984 100644 --- a/app/nulls/null_attachment.rb +++ b/app/nulls/null_attachment.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class NullAttachment def attached? false diff --git a/app/nulls/null_borrow_policy.rb b/app/nulls/null_borrow_policy.rb index 7f45ded6b..374128a53 100644 --- a/app/nulls/null_borrow_policy.rb +++ b/app/nulls/null_borrow_policy.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class NullBorrowPolicy def renewal_limit 0 diff --git a/app/nulls/null_item.rb b/app/nulls/null_item.rb index 97a1592a4..8042c2d6e 100644 --- a/app/nulls/null_item.rb +++ b/app/nulls/null_item.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class NullItem include ActiveModel::Model diff --git a/app/policies/application_policy.rb b/app/policies/application_policy.rb index eefe976c6..50f2d7c61 100644 --- a/app/policies/application_policy.rb +++ b/app/policies/application_policy.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ApplicationPolicy attr_reader :user, :record diff --git a/app/policies/loan_policy.rb b/app/policies/loan_policy.rb index 31171b476..0cbe7318c 100644 --- a/app/policies/loan_policy.rb +++ b/app/policies/loan_policy.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class LoanPolicy attr_reader :user, :loan diff --git a/app/views/admin/documents/_agreement.json.jbuilder b/app/views/admin/documents/_agreement.json.jbuilder index 9f27773fd..75dc6645f 100644 --- a/app/views/admin/documents/_agreement.json.jbuilder +++ b/app/views/admin/documents/_agreement.json.jbuilder @@ -1,2 +1,4 @@ +# frozen_string_literal: true + json.extract! agreement, :code, :name, :summary, :body, :updated_at json.url admin_agreement_url(agreement, format: :json) diff --git a/app/views/admin/documents/index.json.jbuilder b/app/views/admin/documents/index.json.jbuilder index 826f87b8d..6cd3f5aa2 100644 --- a/app/views/admin/documents/index.json.jbuilder +++ b/app/views/admin/documents/index.json.jbuilder @@ -1 +1,3 @@ +# frozen_string_literal: true + json.array! @agreements, partial: "admin/agreements/agreement", as: :agreement diff --git a/app/views/admin/documents/show.json.jbuilder b/app/views/admin/documents/show.json.jbuilder index 4550255cf..8a2f305e7 100644 --- a/app/views/admin/documents/show.json.jbuilder +++ b/app/views/admin/documents/show.json.jbuilder @@ -1 +1,3 @@ +# frozen_string_literal: true + json.partial! "admin/agreements/agreement", agreement: @agreement diff --git a/app/views/admin/gift_memberships/_gift_membership.json.jbuilder b/app/views/admin/gift_memberships/_gift_membership.json.jbuilder index 676dfb157..13908a97f 100644 --- a/app/views/admin/gift_memberships/_gift_membership.json.jbuilder +++ b/app/views/admin/gift_memberships/_gift_membership.json.jbuilder @@ -1,2 +1,4 @@ +# frozen_string_literal: true + json.extract! gift_membership, :id, :purchaser_email, :purchaser_name, :amount_cents, :code, :membership_id, :created_at, :updated_at json.url gift_membership_url(gift_membership, format: :json) diff --git a/app/views/admin/gift_memberships/index.json.jbuilder b/app/views/admin/gift_memberships/index.json.jbuilder index 520bdc237..fb0cc9793 100644 --- a/app/views/admin/gift_memberships/index.json.jbuilder +++ b/app/views/admin/gift_memberships/index.json.jbuilder @@ -1 +1,3 @@ +# frozen_string_literal: true + json.array! @gift_memberships, partial: "gift_memberships/gift_membership", as: :gift_membership diff --git a/app/views/admin/gift_memberships/show.json.jbuilder b/app/views/admin/gift_memberships/show.json.jbuilder index 59150b8d5..a088c238a 100644 --- a/app/views/admin/gift_memberships/show.json.jbuilder +++ b/app/views/admin/gift_memberships/show.json.jbuilder @@ -1 +1,3 @@ +# frozen_string_literal: true + json.partial! "gift_memberships/gift_membership", gift_membership: @gift_membership diff --git a/app/views/admin/loans/_loan.json.jbuilder b/app/views/admin/loans/_loan.json.jbuilder index 173417eb8..bfaa6c8a2 100644 --- a/app/views/admin/loans/_loan.json.jbuilder +++ b/app/views/admin/loans/_loan.json.jbuilder @@ -1,2 +1,4 @@ +# frozen_string_literal: true + json.extract! loan, :id, :item_id, :member_id, :due_at, :ended_at, :created_at, :updated_at json.url admin_loan_url(loan, format: :json) diff --git a/app/views/admin/loans/index.json.jbuilder b/app/views/admin/loans/index.json.jbuilder index 49e509744..92f35e129 100644 --- a/app/views/admin/loans/index.json.jbuilder +++ b/app/views/admin/loans/index.json.jbuilder @@ -1 +1,3 @@ +# frozen_string_literal: true + json.array! @loans, partial: "admin/loans/loan", as: :loan diff --git a/bin/bundle b/bin/bundle index 3917ce9a1..0817fb64d 100755 --- a/bin/bundle +++ b/bin/bundle @@ -11,7 +11,7 @@ require "rubygems" m = Module.new do - module_function + module_function def invoked_as_script? File.expand_path($0) == File.expand_path(__FILE__) @@ -61,10 +61,8 @@ m = Module.new do end def bundler_version - @bundler_version ||= begin - env_var_version || cli_arg_version || + @bundler_version ||= env_var_version || cli_arg_version || lockfile_version || "#{Gem::Requirement.default}.a" - end end def load_bundler! diff --git a/bin/rails b/bin/rails index 5badb2fde..b0427c7c1 100755 --- a/bin/rails +++ b/bin/rails @@ -1,9 +1,11 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + begin - load File.expand_path('../spring', __FILE__) + load File.expand_path("../spring", __FILE__) rescue LoadError => e - raise unless e.message.include?('spring') + raise unless e.message.include?("spring") end -APP_PATH = File.expand_path('../config/application', __dir__) -require_relative '../config/boot' -require 'rails/commands' +APP_PATH = File.expand_path("../config/application", __dir__) +require_relative "../config/boot" +require "rails/commands" diff --git a/bin/rake b/bin/rake index d87d5f578..de33f8860 100755 --- a/bin/rake +++ b/bin/rake @@ -1,9 +1,11 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + begin - load File.expand_path('../spring', __FILE__) + load File.expand_path("../spring", __FILE__) rescue LoadError => e - raise unless e.message.include?('spring') + raise unless e.message.include?("spring") end -require_relative '../config/boot' -require 'rake' +require_relative "../config/boot" +require "rake" Rake.application.run diff --git a/bin/reset b/bin/reset index f49b2ca9a..bbce0e380 100755 --- a/bin/reset +++ b/bin/reset @@ -1,8 +1,10 @@ #!/usr/bin/env ruby -require 'fileutils' +# frozen_string_literal: true + +require "fileutils" # path to your application root. -APP_ROOT = File.expand_path('..', __dir__) +APP_ROOT = File.expand_path("..", __dir__) def system!(*args) system(*args) || abort("\n== Command #{args} failed ==") @@ -11,21 +13,21 @@ end FileUtils.chdir APP_ROOT do # This script resets the application to a stable state for development - puts '== Drop db connections ==' - system! 'bin/rails db:close_connections' + puts "== Drop db connections ==" + system! "bin/rails db:close_connections" - puts '== Database reset ==' - system! 'bin/rails db:reset' + puts "== Database reset ==" + system! "bin/rails db:reset" puts "\n== Loading dev data ==" - system! 'bin/rails devdata:load' + system! "bin/rails devdata:load" puts "\n== Creating loans and holds ==" - system! 'bin/rails devdata:create_loans_and_holds' + system! "bin/rails devdata:create_loans_and_holds" puts "\n== Removing old logs and tempfiles ==" - system! 'bin/rails log:clear tmp:clear' + system! "bin/rails log:clear tmp:clear" puts "\n== Restarting application server ==" - system! 'bin/rails restart' + system! "bin/rails restart" end diff --git a/bin/setup b/bin/setup index c1f8eb9db..a0eec5388 100755 --- a/bin/setup +++ b/bin/setup @@ -1,8 +1,10 @@ #!/usr/bin/env ruby -require 'fileutils' +# frozen_string_literal: true + +require "fileutils" # path to your application root. -APP_ROOT = File.expand_path('..', __dir__) +APP_ROOT = File.expand_path("..", __dir__) def system!(*args) system(*args) || abort("\n== Command #{args} failed ==") @@ -12,12 +14,12 @@ FileUtils.chdir APP_ROOT do # This script is a starting point to setup your application. # Add necessary setup steps to this file. - puts '== Installing dependencies ==' - system! 'gem install bundler --conservative' - system('bundle check') || system!('bundle install') + puts "== Installing dependencies ==" + system! "gem install bundler --conservative" + system("bundle check") || system!("bundle install") # Install JavaScript dependencies - system('bin/yarn') + system("bin/yarn") # puts "\n== Copying sample files ==" # unless File.exist?('config/database.yml') @@ -25,14 +27,14 @@ FileUtils.chdir APP_ROOT do # end puts "\n== Preparing database ==" - system! 'bin/rails db:setup' + system! "bin/rails db:setup" puts "\n== Loading dev data ==" - system! 'bin/rails devdata:load' + system! "bin/rails devdata:load" puts "\n== Removing old logs and tempfiles ==" - system! 'bin/rails log:clear tmp:clear' + system! "bin/rails log:clear tmp:clear" puts "\n== Restarting application server ==" - system! 'bin/rails restart' + system! "bin/rails restart" end diff --git a/bin/spring b/bin/spring index fb2ec2ebb..3ad0d069d 100755 --- a/bin/spring +++ b/bin/spring @@ -1,17 +1,18 @@ #!/usr/bin/env ruby +# frozen_string_literal: true # This file loads spring without using Bundler, in order to be fast. # It gets overwritten when you run the `spring binstub` command. unless defined?(Spring) - require 'rubygems' - require 'bundler' + require "rubygems" + require "bundler" lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read) spring = lockfile.specs.detect { |spec| spec.name == "spring" } if spring Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path - gem 'spring', spring.version - require 'spring/binstub' + gem "spring", spring.version + require "spring/binstub" end end diff --git a/bin/update b/bin/update index fe9271118..b331994ad 100755 --- a/bin/update +++ b/bin/update @@ -1,8 +1,10 @@ #!/usr/bin/env ruby -require 'fileutils' +# frozen_string_literal: true + +require "fileutils" # path to your application root. -APP_ROOT = File.expand_path('..', __dir__) +APP_ROOT = File.expand_path("..", __dir__) def system!(*args) system(*args) || abort("\n== Command #{args} failed ==") @@ -12,19 +14,19 @@ FileUtils.chdir APP_ROOT do # This script is a way to update your development environment automatically. # Add necessary update steps to this file. - puts '== Installing dependencies ==' - system! 'gem install bundler --conservative' - system('bundle check') || system!('bundle install') + puts "== Installing dependencies ==" + system! "gem install bundler --conservative" + system("bundle check") || system!("bundle install") # Install JavaScript dependencies # system('bin/yarn') puts "\n== Updating database ==" - system! 'rails db:migrate' + system! "rails db:migrate" puts "\n== Removing old logs and tempfiles ==" - system! 'rails log:clear tmp:clear' + system! "rails log:clear tmp:clear" puts "\n== Restarting application server ==" - system! 'rails restart' + system! "rails restart" end diff --git a/bin/yarn b/bin/yarn index 460dd565b..9d7bac762 100755 --- a/bin/yarn +++ b/bin/yarn @@ -1,11 +1,11 @@ #!/usr/bin/env ruby -APP_ROOT = File.expand_path('..', __dir__) +# frozen_string_literal: true + +APP_ROOT = File.expand_path("..", __dir__) Dir.chdir(APP_ROOT) do - begin - exec "yarnpkg", *ARGV - rescue Errno::ENOENT - $stderr.puts "Yarn executable was not detected in the system." - $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install" - exit 1 - end + exec "yarnpkg", *ARGV +rescue Errno::ENOENT + $stderr.puts "Yarn executable was not detected in the system." + $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install" + exit 1 end diff --git a/config.ru b/config.ru index 441e6ff0c..bff88d608 100644 --- a/config.ru +++ b/config.ru @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file is used by Rack-based servers to start the application. require_relative "config/environment" diff --git a/config/application.rb b/config/application.rb index cab646486..de1c66c07 100644 --- a/config/application.rb +++ b/config/application.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative "boot" require "rails" diff --git a/config/boot.rb b/config/boot.rb index 988a5ddc4..aef6d031e 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) require "bundler/setup" # Set up gems listed in the Gemfile. diff --git a/config/environment.rb b/config/environment.rb index cac531577..7df99e89c 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Load the Rails application. require_relative "application" diff --git a/config/environments/development.rb b/config/environments/development.rb index 795ca5db8..7bad5a7bd 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. @@ -77,7 +79,7 @@ end end - config.action_mailer.default_url_options = {host: "localhost", port: 3000} + config.action_mailer.default_url_options = { host: "localhost", port: 3000 } config.action_mailer.asset_host = "http://localhost:3000" config.action_mailer.delivery_method = :letter_opener config.action_mailer.perform_deliveries = true diff --git a/config/environments/production.rb b/config/environments/production.rb index 1017e55a2..2bac8f121 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. @@ -31,7 +33,7 @@ # Enable serving of images, stylesheets, and JavaScripts from an asset server. # config.action_controller.asset_host = 'http://assets.example.com' - config.action_mailer.default_url_options = {host: "app.chicagotoollibrary.org"} + config.action_mailer.default_url_options = { host: "app.chicagotoollibrary.org" } config.action_mailer.asset_host = "https://app.chicagotoollibrary.org" # Specifies the header that your server uses for sending files. diff --git a/config/environments/staging.rb b/config/environments/staging.rb index 1d5de42ef..017479ff0 100644 --- a/config/environments/staging.rb +++ b/config/environments/staging.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. @@ -77,7 +79,7 @@ end end - config.action_mailer.default_url_options = {host: "localhost", port: 3000} + config.action_mailer.default_url_options = { host: "localhost", port: 3000 } config.action_mailer.asset_host = "http://localhost:3000" config.action_mailer.delivery_method = :letter_opener config.action_mailer.perform_deliveries = true diff --git a/config/environments/test.rb b/config/environments/test.rb index a3ec4d561..18114514a 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_dependency "acts_as_tenant/test_tenant_middleware" Rails.application.configure do @@ -40,7 +42,7 @@ # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test - config.action_mailer.default_url_options = {host: "example.com"} + config.action_mailer.default_url_options = { host: "example.com" } # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr diff --git a/config/initializers/application_controller_renderer.rb b/config/initializers/application_controller_renderer.rb index 89d2efab2..f4556db39 100644 --- a/config/initializers/application_controller_renderer.rb +++ b/config/initializers/application_controller_renderer.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. # ActiveSupport::Reloader.to_prepare do diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb index 59385cdf3..d0f0d3b5d 100644 --- a/config/initializers/backtrace_silencers.rb +++ b/config/initializers/backtrace_silencers.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. diff --git a/config/initializers/content_security_policy.rb b/config/initializers/content_security_policy.rb index 1b79e310e..d7efc5d67 100644 --- a/config/initializers/content_security_policy.rb +++ b/config/initializers/content_security_policy.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. # Define an application-wide content security policy diff --git a/config/initializers/cookies_serializer.rb b/config/initializers/cookies_serializer.rb index 5a6a32d37..ee8dff9c9 100644 --- a/config/initializers/cookies_serializer.rb +++ b/config/initializers/cookies_serializer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Specify a serializer for the signed and encrypted cookie jars. diff --git a/config/initializers/custom_time_formats.rb b/config/initializers/custom_time_formats.rb index a79f830f5..fd729fa74 100644 --- a/config/initializers/custom_time_formats.rb +++ b/config/initializers/custom_time_formats.rb @@ -1 +1,3 @@ +# frozen_string_literal: true + Time::DATE_FORMATS[:long_date] = "%B %-d, %Y" diff --git a/config/initializers/date_format.rb b/config/initializers/date_format.rb index 5b0d5d1fb..0b2ab962b 100644 --- a/config/initializers/date_format.rb +++ b/config/initializers/date_format.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Date::DATE_FORMATS[:short_date] = "%-m/%-d/%Y" Time::DATE_FORMATS[:short_date] = "%-m/%-d/%Y" diff --git a/config/initializers/dotenv.rb b/config/initializers/dotenv.rb index 3a40225af..1fea8e696 100644 --- a/config/initializers/dotenv.rb +++ b/config/initializers/dotenv.rb @@ -1 +1,3 @@ +# frozen_string_literal: true + Dotenv.require_keys("SQUARE_ACCESS_TOKEN", "SQUARE_LOCATION_ID") diff --git a/config/initializers/email_observers.rb b/config/initializers/email_observers.rb index 516bb3d92..64c702d64 100644 --- a/config/initializers/email_observers.rb +++ b/config/initializers/email_observers.rb @@ -1 +1,3 @@ +# frozen_string_literal: true + Rails.application.config.action_mailer.observers = [:member_mailer_observer] diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb index 4a994e1e7..7a4f47b4c 100644 --- a/config/initializers/filter_parameter_logging.rb +++ b/config/initializers/filter_parameter_logging.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Configure sensitive parameters which will be filtered from the log file. diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index 48d7b512d..ec9b00914 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Add new inflection rules using the following format. Inflections diff --git a/config/initializers/logging.rb b/config/initializers/logging.rb index b737c65bd..8e9dbffd5 100644 --- a/config/initializers/logging.rb +++ b/config/initializers/logging.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # when requests are sent from http.rb gem ActiveSupport::Notifications.subscribe("start_request.http") do |name, start, finish, id, payload| filtered = payload[:request].uri.to_s.gsub(/((?:client_secret|refresh_token)=)[^&]+/, '\1[FILTERED]') @@ -7,6 +9,6 @@ # when requests are completed from http.rb gem ActiveSupport::Notifications.subscribe("request.http") do |name, start, finish, id, payload| Rails.logger.info( - name: name, start: start.to_f, finish: finish.to_f, id: id, payload: payload + name:, start: start.to_f, finish: finish.to_f, id:, payload: ) end diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb index f15bab4b2..f4285fffd 100644 --- a/config/initializers/mime_types.rb +++ b/config/initializers/mime_types.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Add new mime types for use in respond_to blocks: diff --git a/config/initializers/money.rb b/config/initializers/money.rb index 0a9e6d509..985ff60b7 100644 --- a/config/initializers/money.rb +++ b/config/initializers/money.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + MoneyRails.configure do |config| config.locale_backend = :currency # To set the default currency diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb index 20c157259..8d24558c2 100644 --- a/config/initializers/omniauth.rb +++ b/config/initializers/omniauth.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.config.middleware.use OmniAuth::Builder do provider :google_oauth2, ENV["GOOGLE_CLIENT_ID"], ENV["GOOGLE_CLIENT_SECRET"] end diff --git a/config/initializers/pagy.rb b/config/initializers/pagy.rb index 5b2101615..68406f760 100644 --- a/config/initializers/pagy.rb +++ b/config/initializers/pagy.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "pagy/extras/bootstrap" require "pagy/extras/arel" require "pagy/extras/overflow" diff --git a/config/initializers/staging_access.rb b/config/initializers/staging_access.rb index acb99f6aa..521bff8ad 100644 --- a/config/initializers/staging_access.rb +++ b/config/initializers/staging_access.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + unless ENV["HTTP_BASIC_USERS"].blank? Rails.application.config.middleware.use ::Rack::Auth::Basic do |username, password| ENV["HTTP_BASIC_USERS"].split(";").any? do |pair| diff --git a/config/initializers/translation.rb b/config/initializers/translation.rb index 7c2aa2e62..9571d84a1 100644 --- a/config/initializers/translation.rb +++ b/config/initializers/translation.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + TranslationIO.configure do |config| config.api_key = ENV.fetch("TRANSLATION_IO_API_KEY", "not a real key") config.source_locale = "en" diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb index bbfc3961b..2f3c0db47 100644 --- a/config/initializers/wrap_parameters.rb +++ b/config/initializers/wrap_parameters.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # This file contains settings for ActionController::ParamsWrapper which diff --git a/config/puma.rb b/config/puma.rb index a4e630516..1ec595e7c 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "barnes" # Puma can serve each request in a thread from an internal thread pool. diff --git a/config/routes.rb b/config/routes.rb index effb45b6b..d2bf1d31a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + Rails.application.routes.draw do - devise_for :users, controllers: {sessions: "users/sessions"} + devise_for :users, controllers: { sessions: "users/sessions" } namespace :signup do resources :members, only: [:new, :create] @@ -186,6 +188,6 @@ end %w[404 422 500 503].each do |code| - match code, to: "errors#show", via: :all, code: code, as: "error_#{code}" + match code, to: "errors#show", via: :all, code:, as: "error_#{code}" end end diff --git a/config/spring.rb b/config/spring.rb index db5bf1307..37a354342 100644 --- a/config/spring.rb +++ b/config/spring.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Spring.watch( ".ruby-version", ".rbenv-vars", diff --git a/db/migrate/20190314033712_create_items.rb b/db/migrate/20190314033712_create_items.rb index f5aa3eea6..7882f0c57 100644 --- a/db/migrate/20190314033712_create_items.rb +++ b/db/migrate/20190314033712_create_items.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateItems < ActiveRecord::Migration[6.0] def change create_table :items do |t| diff --git a/db/migrate/20190314034749_create_active_storage_tables.active_storage.rb b/db/migrate/20190314034749_create_active_storage_tables.active_storage.rb index fd86aef01..344c574bf 100644 --- a/db/migrate/20190314034749_create_active_storage_tables.active_storage.rb +++ b/db/migrate/20190314034749_create_active_storage_tables.active_storage.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This migration comes from active_storage (originally 20170806125915) class CreateActiveStorageTables < ActiveRecord::Migration[5.2] def change diff --git a/db/migrate/20190314034750_create_action_text_tables.action_text.rb b/db/migrate/20190314034750_create_action_text_tables.action_text.rb index 191a034ed..86c61bc19 100644 --- a/db/migrate/20190314034750_create_action_text_tables.action_text.rb +++ b/db/migrate/20190314034750_create_action_text_tables.action_text.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This migration comes from action_text (originally 20180528164100) class CreateActionTextTables < ActiveRecord::Migration[6.0] def change diff --git a/db/migrate/20190317013855_add_number_to_items.rb b/db/migrate/20190317013855_add_number_to_items.rb index 55550cd7f..7681573ac 100644 --- a/db/migrate/20190317013855_add_number_to_items.rb +++ b/db/migrate/20190317013855_add_number_to_items.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddNumberToItems < ActiveRecord::Migration[6.0] def change add_column :items, :number, :integer, null: false, unique: true diff --git a/db/migrate/20190317031248_create_categories.rb b/db/migrate/20190317031248_create_categories.rb index 6e1171e1a..1d33028c6 100644 --- a/db/migrate/20190317031248_create_categories.rb +++ b/db/migrate/20190317031248_create_categories.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateCategories < ActiveRecord::Migration[6.0] def change create_table :categories do |t| diff --git a/db/migrate/20190317032441_create_categorizations.rb b/db/migrate/20190317032441_create_categorizations.rb index 10c7cebda..5c46bd7f1 100644 --- a/db/migrate/20190317032441_create_categorizations.rb +++ b/db/migrate/20190317032441_create_categorizations.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateCategorizations < ActiveRecord::Migration[6.0] def change create_table :categorizations do |t| diff --git a/db/migrate/20190317034933_add_uniqueness_constraint_to_categorizations.rb b/db/migrate/20190317034933_add_uniqueness_constraint_to_categorizations.rb index 45c56d560..4eb57c7b4 100644 --- a/db/migrate/20190317034933_add_uniqueness_constraint_to_categorizations.rb +++ b/db/migrate/20190317034933_add_uniqueness_constraint_to_categorizations.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddUniquenessConstraintToCategorizations < ActiveRecord::Migration[6.0] def change add_index :categorizations, [:item_id, :category_id] diff --git a/db/migrate/20190317035504_add_ancestry_to_categories.rb b/db/migrate/20190317035504_add_ancestry_to_categories.rb index 0f36e9198..c066c3f7e 100644 --- a/db/migrate/20190317035504_add_ancestry_to_categories.rb +++ b/db/migrate/20190317035504_add_ancestry_to_categories.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddAncestryToCategories < ActiveRecord::Migration[6.0] def change add_column :categories, :ancestry, :string diff --git a/db/migrate/20190317203043_add_counter_cache_to_category.rb b/db/migrate/20190317203043_add_counter_cache_to_category.rb index 0189fd089..2d0a132e2 100644 --- a/db/migrate/20190317203043_add_counter_cache_to_category.rb +++ b/db/migrate/20190317203043_add_counter_cache_to_category.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddCounterCacheToCategory < ActiveRecord::Migration[6.0] def change add_column :categories, :categorizations_count, :integer, default: 0, null: false diff --git a/db/migrate/20190319024125_create_members.rb b/db/migrate/20190319024125_create_members.rb index 1173161b8..895b5c467 100644 --- a/db/migrate/20190319024125_create_members.rb +++ b/db/migrate/20190319024125_create_members.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateMembers < ActiveRecord::Migration[6.0] def change create_table :members do |t| diff --git a/db/migrate/20190322030007_create_loans.rb b/db/migrate/20190322030007_create_loans.rb index f78db3a2e..a542cd606 100644 --- a/db/migrate/20190322030007_create_loans.rb +++ b/db/migrate/20190322030007_create_loans.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateLoans < ActiveRecord::Migration[6.0] def change create_table :loans do |t| diff --git a/db/migrate/20190427201337_install_audited.rb b/db/migrate/20190427201337_install_audited.rb index 15162ece7..9280498e2 100644 --- a/db/migrate/20190427201337_install_audited.rb +++ b/db/migrate/20190427201337_install_audited.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class InstallAudited < ActiveRecord::Migration[6.0] def self.up create_table :audits, force: true do |t| diff --git a/db/migrate/20190509041314_add_status_to_items.rb b/db/migrate/20190509041314_add_status_to_items.rb index be3aeca81..093f9a262 100644 --- a/db/migrate/20190509041314_add_status_to_items.rb +++ b/db/migrate/20190509041314_add_status_to_items.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddStatusToItems < ActiveRecord::Migration[6.0] def change add_column :items, :status, :integer, default: Item.statuses[:active], null: false diff --git a/db/migrate/20190509042525_add_status_to_members.rb b/db/migrate/20190509042525_add_status_to_members.rb index 765b045f5..754122054 100644 --- a/db/migrate/20190509042525_add_status_to_members.rb +++ b/db/migrate/20190509042525_add_status_to_members.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddStatusToMembers < ActiveRecord::Migration[6.0] def change add_column :members, :status, :integer, default: Member.statuses[:pending], null: false diff --git a/db/migrate/20190526205528_create_borrow_policies.rb b/db/migrate/20190526205528_create_borrow_policies.rb index b9036aec1..55f6bf38a 100644 --- a/db/migrate/20190526205528_create_borrow_policies.rb +++ b/db/migrate/20190526205528_create_borrow_policies.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateBorrowPolicies < ActiveRecord::Migration[6.0] def change create_table :borrow_policies do |t| diff --git a/db/migrate/20190601021224_add_borrow_policy_to_items.rb b/db/migrate/20190601021224_add_borrow_policy_to_items.rb index 68a5ac658..36602b334 100644 --- a/db/migrate/20190601021224_add_borrow_policy_to_items.rb +++ b/db/migrate/20190601021224_add_borrow_policy_to_items.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddBorrowPolicyToItems < ActiveRecord::Migration[6.0] def change add_reference :items, :borrow_policy, null: false diff --git a/db/migrate/20190604001152_create_adjustments.rb b/db/migrate/20190604001152_create_adjustments.rb index c5be16684..2df1a09c3 100644 --- a/db/migrate/20190604001152_create_adjustments.rb +++ b/db/migrate/20190604001152_create_adjustments.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateAdjustments < ActiveRecord::Migration[6.0] def change create_table :adjustments do |t| diff --git a/db/migrate/20190610021238_create_agreements.rb b/db/migrate/20190610021238_create_agreements.rb index 09a7bc934..6755d3b66 100644 --- a/db/migrate/20190610021238_create_agreements.rb +++ b/db/migrate/20190610021238_create_agreements.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateAgreements < ActiveRecord::Migration[6.0] def change create_table :agreements do |t| diff --git a/db/migrate/20190614011321_create_agreement_acceptances.rb b/db/migrate/20190614011321_create_agreement_acceptances.rb index d8efae9f5..a43bda6d2 100644 --- a/db/migrate/20190614011321_create_agreement_acceptances.rb +++ b/db/migrate/20190614011321_create_agreement_acceptances.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateAgreementAcceptances < ActiveRecord::Migration[6.0] def change create_table :agreement_acceptances do |t| diff --git a/db/migrate/20190616014227_update_member_fields.rb b/db/migrate/20190616014227_update_member_fields.rb index dcd78cb5a..49e1a852c 100644 --- a/db/migrate/20190616014227_update_member_fields.rb +++ b/db/migrate/20190616014227_update_member_fields.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class UpdateMemberFields < ActiveRecord::Migration[6.0] def change remove_column :members, :id_number, :string diff --git a/db/migrate/20190624133416_add_strength_to_items.rb b/db/migrate/20190624133416_add_strength_to_items.rb index 0dbcdf480..a070b192f 100644 --- a/db/migrate/20190624133416_add_strength_to_items.rb +++ b/db/migrate/20190624133416_add_strength_to_items.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddStrengthToItems < ActiveRecord::Migration[6.0] def change add_column :items, :strength, :string diff --git a/db/migrate/20190627024415_add_uniquely_numbered_to_borrow_policies.rb b/db/migrate/20190627024415_add_uniquely_numbered_to_borrow_policies.rb index 1450855e6..4e2041f83 100644 --- a/db/migrate/20190627024415_add_uniquely_numbered_to_borrow_policies.rb +++ b/db/migrate/20190627024415_add_uniquely_numbered_to_borrow_policies.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddUniquelyNumberedToBorrowPolicies < ActiveRecord::Migration[6.0] def change add_column :borrow_policies, :uniquely_numbered, :boolean, default: true, null: false diff --git a/db/migrate/20190628042057_add_description_and_code_to_borrow_policies.rb b/db/migrate/20190628042057_add_description_and_code_to_borrow_policies.rb index 98cb5c08a..ec030dca7 100644 --- a/db/migrate/20190628042057_add_description_and_code_to_borrow_policies.rb +++ b/db/migrate/20190628042057_add_description_and_code_to_borrow_policies.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddDescriptionAndCodeToBorrowPolicies < ActiveRecord::Migration[6.0] def change add_column :borrow_policies, :code, :string, unique: true diff --git a/db/migrate/20190628171313_add_uniquely_numbered_to_loans.rb b/db/migrate/20190628171313_add_uniquely_numbered_to_loans.rb index 18d48f209..756c4f70c 100644 --- a/db/migrate/20190628171313_add_uniquely_numbered_to_loans.rb +++ b/db/migrate/20190628171313_add_uniquely_numbered_to_loans.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddUniquelyNumberedToLoans < ActiveRecord::Migration[6.0] def change add_column :loans, :uniquely_numbered, :boolean, default: true, null: false diff --git a/db/migrate/20190630003353_add_default_to_borrow_policies.rb b/db/migrate/20190630003353_add_default_to_borrow_policies.rb index 32a46c52a..57bdbf621 100644 --- a/db/migrate/20190630003353_add_default_to_borrow_policies.rb +++ b/db/migrate/20190630003353_add_default_to_borrow_policies.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddDefaultToBorrowPolicies < ActiveRecord::Migration[6.0] def change add_column :borrow_policies, :default, :boolean, default: false, null: false diff --git a/db/migrate/20190710215125_remove_category_hierarchy.rb b/db/migrate/20190710215125_remove_category_hierarchy.rb index 4257f75f0..1f22f99ef 100644 --- a/db/migrate/20190710215125_remove_category_hierarchy.rb +++ b/db/migrate/20190710215125_remove_category_hierarchy.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class RemoveCategoryHierarchy < ActiveRecord::Migration[6.0] def change remove_column :categories, :ancestry diff --git a/db/migrate/20190711233155_add_quantity_to_items.rb b/db/migrate/20190711233155_add_quantity_to_items.rb index 3ac11a86a..19879c348 100644 --- a/db/migrate/20190711233155_add_quantity_to_items.rb +++ b/db/migrate/20190711233155_add_quantity_to_items.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddQuantityToItems < ActiveRecord::Migration[6.0] def change add_column :items, :quantity, :integer diff --git a/db/migrate/20190715143604_create_memberships.rb b/db/migrate/20190715143604_create_memberships.rb index 99ab4be92..09bc8fa0d 100644 --- a/db/migrate/20190715143604_create_memberships.rb +++ b/db/migrate/20190715143604_create_memberships.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateMemberships < ActiveRecord::Migration[6.0] def change create_table :memberships do |t| diff --git a/db/migrate/20190716012142_rename_agreements_to_documents.rb b/db/migrate/20190716012142_rename_agreements_to_documents.rb index 1dca42dee..463ee1cd8 100644 --- a/db/migrate/20190716012142_rename_agreements_to_documents.rb +++ b/db/migrate/20190716012142_rename_agreements_to_documents.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class RenameAgreementsToDocuments < ActiveRecord::Migration[6.0] def change rename_table :agreements, :documents diff --git a/db/migrate/20190716013130_update_agreement_acceptances.rb b/db/migrate/20190716013130_update_agreement_acceptances.rb index dd18f94dc..46e046cf3 100644 --- a/db/migrate/20190716013130_update_agreement_acceptances.rb +++ b/db/migrate/20190716013130_update_agreement_acceptances.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class UpdateAgreementAcceptances < ActiveRecord::Migration[6.0] def change remove_column :agreement_acceptances, :agreement_id diff --git a/db/migrate/20190716013252_add_default_documents.rb b/db/migrate/20190716013252_add_default_documents.rb index 33b664285..b27e90b2c 100644 --- a/db/migrate/20190716013252_add_default_documents.rb +++ b/db/migrate/20190716013252_add_default_documents.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddDefaultDocuments < ActiveRecord::Migration[6.0] class MigrationDocument < ActiveRecord::Base self.table_name = :documents diff --git a/db/migrate/20190716014635_remove_active_from_documents.rb b/db/migrate/20190716014635_remove_active_from_documents.rb index e2c5f4fd9..0f25a1051 100644 --- a/db/migrate/20190716014635_remove_active_from_documents.rb +++ b/db/migrate/20190716014635_remove_active_from_documents.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class RemoveActiveFromDocuments < ActiveRecord::Migration[6.0] def change remove_column :documents, :active diff --git a/db/migrate/20190719033026_add_communication_fields_to_member.rb b/db/migrate/20190719033026_add_communication_fields_to_member.rb index 89513c6a5..fc41f4dfa 100644 --- a/db/migrate/20190719033026_add_communication_fields_to_member.rb +++ b/db/migrate/20190719033026_add_communication_fields_to_member.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddCommunicationFieldsToMember < ActiveRecord::Migration[6.0] def change add_column :members, :reminders_via_email, :boolean, default: false, null: false diff --git a/db/migrate/20190807020247_add_payment_info_to_adjustments.rb b/db/migrate/20190807020247_add_payment_info_to_adjustments.rb index 4e93ba630..6873a7d21 100644 --- a/db/migrate/20190807020247_add_payment_info_to_adjustments.rb +++ b/db/migrate/20190807020247_add_payment_info_to_adjustments.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddPaymentInfoToAdjustments < ActiveRecord::Migration[6.0] def change create_enum :adjustment_source, ["cash", "square"] diff --git a/db/migrate/20190816152137_add_support_for_renewals.rb b/db/migrate/20190816152137_add_support_for_renewals.rb index eed8175c4..6df519bd1 100644 --- a/db/migrate/20190816152137_add_support_for_renewals.rb +++ b/db/migrate/20190816152137_add_support_for_renewals.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + class AddSupportForRenewals < ActiveRecord::Migration[6.0] def change add_column :loans, :renewal_count, :integer, default: 0, null: false - add_reference :loans, :initial_loan, foreign_key: {to_table: :loans} + add_reference :loans, :initial_loan, foreign_key: { to_table: :loans } end end diff --git a/db/migrate/20190817190131_create_loan_summaries.rb b/db/migrate/20190817190131_create_loan_summaries.rb index 6d6560973..91b5eefa5 100644 --- a/db/migrate/20190817190131_create_loan_summaries.rb +++ b/db/migrate/20190817190131_create_loan_summaries.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateLoanSummaries < ActiveRecord::Migration[6.0] def change create_view :loan_summaries diff --git a/db/migrate/20190911020605_add_kind_to_adjustments.rb b/db/migrate/20190911020605_add_kind_to_adjustments.rb index 18d667b21..719f8a157 100644 --- a/db/migrate/20190911020605_add_kind_to_adjustments.rb +++ b/db/migrate/20190911020605_add_kind_to_adjustments.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddKindToAdjustments < ActiveRecord::Migration[6.0] def change create_enum :adjustment_kind, ["fine", "membership", "donation", "payment"] diff --git a/db/migrate/20190916011430_add_forgiveness_to_adjustments.rb b/db/migrate/20190916011430_add_forgiveness_to_adjustments.rb index 1847b311e..4704ee12b 100644 --- a/db/migrate/20190916011430_add_forgiveness_to_adjustments.rb +++ b/db/migrate/20190916011430_add_forgiveness_to_adjustments.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddForgivenessToAdjustments < ActiveRecord::Migration[6.0] disable_ddl_transaction! def change diff --git a/db/migrate/20190916013208_update_loan_summaries_to_version_2.rb b/db/migrate/20190916013208_update_loan_summaries_to_version_2.rb index f17fbf933..74bb4cc2f 100644 --- a/db/migrate/20190916013208_update_loan_summaries_to_version_2.rb +++ b/db/migrate/20190916013208_update_loan_summaries_to_version_2.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class UpdateLoanSummariesToVersion2 < ActiveRecord::Migration[6.0] def change update_view :loan_summaries, version: 2, revert_to_version: 1 diff --git a/db/migrate/20190921013902_create_monthly_adjustments.rb b/db/migrate/20190921013902_create_monthly_adjustments.rb index 97793bb7b..e9c219b7c 100644 --- a/db/migrate/20190921013902_create_monthly_adjustments.rb +++ b/db/migrate/20190921013902_create_monthly_adjustments.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateMonthlyAdjustments < ActiveRecord::Migration[6.0] def change create_view :monthly_adjustments diff --git a/db/migrate/20190925030512_update_loan_summaries_to_version_3.rb b/db/migrate/20190925030512_update_loan_summaries_to_version_3.rb index 4322203b1..ecc4099bc 100644 --- a/db/migrate/20190925030512_update_loan_summaries_to_version_3.rb +++ b/db/migrate/20190925030512_update_loan_summaries_to_version_3.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class UpdateLoanSummariesToVersion3 < ActiveRecord::Migration[6.0] def change update_view :loan_summaries, version: 3, revert_to_version: 2 diff --git a/db/migrate/20191021005121_create_monthly_activities.rb b/db/migrate/20191021005121_create_monthly_activities.rb index deaa739c8..e1c3188f2 100644 --- a/db/migrate/20191021005121_create_monthly_activities.rb +++ b/db/migrate/20191021005121_create_monthly_activities.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateMonthlyActivities < ActiveRecord::Migration[6.0] def change create_view :monthly_activities diff --git a/db/migrate/20191028022023_add_index_to_loans_ended_at.rb b/db/migrate/20191028022023_add_index_to_loans_ended_at.rb index 0c6f10607..83eb22a14 100644 --- a/db/migrate/20191028022023_add_index_to_loans_ended_at.rb +++ b/db/migrate/20191028022023_add_index_to_loans_ended_at.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddIndexToLoansEndedAt < ActiveRecord::Migration[6.0] def change add_index :loans, :ended_at diff --git a/db/migrate/20191102002601_create_notifications.rb b/db/migrate/20191102002601_create_notifications.rb index 6d003af12..3e9d2046b 100644 --- a/db/migrate/20191102002601_create_notifications.rb +++ b/db/migrate/20191102002601_create_notifications.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateNotifications < ActiveRecord::Migration[6.0] def change create_enum :notification_status, ["pending", "sent", "bounced", "error"] diff --git a/db/migrate/20191103015209_add_notice_to_items.rb b/db/migrate/20191103015209_add_notice_to_items.rb index 61d0baff9..43c467896 100644 --- a/db/migrate/20191103015209_add_notice_to_items.rb +++ b/db/migrate/20191103015209_add_notice_to_items.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddNoticeToItems < ActiveRecord::Migration[6.0] def change add_column :items, :checkout_notice, :string diff --git a/db/migrate/20191210022433_create_gift_memberships.rb b/db/migrate/20191210022433_create_gift_memberships.rb index 980c8ca19..0c0943dec 100644 --- a/db/migrate/20191210022433_create_gift_memberships.rb +++ b/db/migrate/20191210022433_create_gift_memberships.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateGiftMemberships < ActiveRecord::Migration[6.0] def change create_table :gift_memberships do |t| diff --git a/db/migrate/20191212055236_relax_member_id_on_notifications.rb b/db/migrate/20191212055236_relax_member_id_on_notifications.rb index eb14b30a6..d087611a9 100644 --- a/db/migrate/20191212055236_relax_member_id_on_notifications.rb +++ b/db/migrate/20191212055236_relax_member_id_on_notifications.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class RelaxMemberIdOnNotifications < ActiveRecord::Migration[6.0] def change change_column_null :notifications, :member_id, true diff --git a/db/migrate/20191215100437_add_recipient_to_gift_memberships.rb b/db/migrate/20191215100437_add_recipient_to_gift_memberships.rb index 0e46ec2dc..e9a198d16 100644 --- a/db/migrate/20191215100437_add_recipient_to_gift_memberships.rb +++ b/db/migrate/20191215100437_add_recipient_to_gift_memberships.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddRecipientToGiftMemberships < ActiveRecord::Migration[6.0] def change add_column :gift_memberships, :recipient_name, :string diff --git a/db/migrate/20200121020026_add_address_fields_to_members.rb b/db/migrate/20200121020026_add_address_fields_to_members.rb index 46261ec9e..71dc5d2b8 100644 --- a/db/migrate/20200121020026_add_address_fields_to_members.rb +++ b/db/migrate/20200121020026_add_address_fields_to_members.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddAddressFieldsToMembers < ActiveRecord::Migration[6.0] def change add_column :members, :address1, :string diff --git a/db/migrate/20200126220929_add_renewal_limit_to_borrow_policy.rb b/db/migrate/20200126220929_add_renewal_limit_to_borrow_policy.rb index 2eacc6462..149d1edc3 100644 --- a/db/migrate/20200126220929_add_renewal_limit_to_borrow_policy.rb +++ b/db/migrate/20200126220929_add_renewal_limit_to_borrow_policy.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddRenewalLimitToBorrowPolicy < ActiveRecord::Migration[6.0] def change add_column :borrow_policies, :renewal_limit, :integer, default: 0, null: false diff --git a/db/migrate/20200208203157_create_short_links.rb b/db/migrate/20200208203157_create_short_links.rb index 842bd5d40..b7bb6a1df 100644 --- a/db/migrate/20200208203157_create_short_links.rb +++ b/db/migrate/20200208203157_create_short_links.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateShortLinks < ActiveRecord::Migration[6.0] def change create_table :short_links do |t| diff --git a/db/migrate/20200422023206_add_parent_id_to_categories.rb b/db/migrate/20200422023206_add_parent_id_to_categories.rb index 95f4a723c..8f063b510 100644 --- a/db/migrate/20200422023206_add_parent_id_to_categories.rb +++ b/db/migrate/20200422023206_add_parent_id_to_categories.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + class AddParentIdToCategories < ActiveRecord::Migration[6.0] def change - add_reference :categories, :parent, foreign_key: {to_table: :categories} + add_reference :categories, :parent, foreign_key: { to_table: :categories } end end diff --git a/db/migrate/20200425192757_create_category_nodes.rb b/db/migrate/20200425192757_create_category_nodes.rb index 76b73edb4..68035462f 100644 --- a/db/migrate/20200425192757_create_category_nodes.rb +++ b/db/migrate/20200425192757_create_category_nodes.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateCategoryNodes < ActiveRecord::Migration[6.0] def change create_view :category_nodes, materialized: true diff --git a/db/migrate/20200503203437_add_member_number.rb b/db/migrate/20200503203437_add_member_number.rb index 6b2bc7514..b092b4457 100644 --- a/db/migrate/20200503203437_add_member_number.rb +++ b/db/migrate/20200503203437_add_member_number.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddMemberNumber < ActiveRecord::Migration[6.0] def change add_column :members, :number, :integer diff --git a/db/migrate/20200504134052_assign_member_numbers.rb b/db/migrate/20200504134052_assign_member_numbers.rb index c4f232783..ead8cda6e 100644 --- a/db/migrate/20200504134052_assign_member_numbers.rb +++ b/db/migrate/20200504134052_assign_member_numbers.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AssignMemberNumbers < ActiveRecord::Migration[6.0] class Member < ActiveRecord::Base enum status: [:pending, :verified, :suspended, :deactivated], _prefix: true diff --git a/db/migrate/20200512184900_create_holds.rb b/db/migrate/20200512184900_create_holds.rb index 8d8ebd88e..30bf29508 100644 --- a/db/migrate/20200512184900_create_holds.rb +++ b/db/migrate/20200512184900_create_holds.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + class CreateHolds < ActiveRecord::Migration[6.0] def change create_table :holds do |t| t.references :member, null: false, foreign_key: true t.references :item, null: false, foreign_key: true - t.references :creator, null: false, foreign_key: {to_table: :users} + t.references :creator, null: false, foreign_key: { to_table: :users } t.timestamps end diff --git a/db/migrate/20200514003135_add_hold_counter_cache_to_item.rb b/db/migrate/20200514003135_add_hold_counter_cache_to_item.rb index 59fb8c7a6..82f784d36 100644 --- a/db/migrate/20200514003135_add_hold_counter_cache_to_item.rb +++ b/db/migrate/20200514003135_add_hold_counter_cache_to_item.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddHoldCounterCacheToItem < ActiveRecord::Migration[6.0] def change add_column :items, :holds_count, :integer, default: 0, null: false diff --git a/db/migrate/20200517211425_add_ended_at_to_holds.rb b/db/migrate/20200517211425_add_ended_at_to_holds.rb index 9fafe4e33..f6d094abb 100644 --- a/db/migrate/20200517211425_add_ended_at_to_holds.rb +++ b/db/migrate/20200517211425_add_ended_at_to_holds.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddEndedAtToHolds < ActiveRecord::Migration[6.0] def change add_column :holds, :ended_at, :datetime diff --git a/db/migrate/20200518032950_add_loan_id_to_hold.rb b/db/migrate/20200518032950_add_loan_id_to_hold.rb index 72ea81d9a..4a0499b0d 100644 --- a/db/migrate/20200518032950_add_loan_id_to_hold.rb +++ b/db/migrate/20200518032950_add_loan_id_to_hold.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddLoanIdToHold < ActiveRecord::Migration[6.0] def change add_reference :holds, :loan, foreign_key: true diff --git a/db/migrate/20200605013050_create_notes.rb b/db/migrate/20200605013050_create_notes.rb index d9dcf4858..85593fd78 100644 --- a/db/migrate/20200605013050_create_notes.rb +++ b/db/migrate/20200605013050_create_notes.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + class CreateNotes < ActiveRecord::Migration[6.0] def change create_table :notes do |t| t.references :notable, null: false, polymorphic: true - t.references :creator, null: false, foreign_key: {to_table: :users} + t.references :creator, null: false, foreign_key: { to_table: :users } t.timestamps end diff --git a/db/migrate/20200606002240_add_uniqueness_constraint_to_loans.rb b/db/migrate/20200606002240_add_uniqueness_constraint_to_loans.rb index 768c23f54..94d30917c 100644 --- a/db/migrate/20200606002240_add_uniqueness_constraint_to_loans.rb +++ b/db/migrate/20200606002240_add_uniqueness_constraint_to_loans.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddUniquenessConstraintToLoans < ActiveRecord::Migration[6.0] def change add_index :loans, [:initial_loan_id, :renewal_count], unique: true diff --git a/db/migrate/20200618031047_add_other_names_to_items.rb b/db/migrate/20200618031047_add_other_names_to_items.rb index b7bb6145e..4d187f4a6 100644 --- a/db/migrate/20200618031047_add_other_names_to_items.rb +++ b/db/migrate/20200618031047_add_other_names_to_items.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddOtherNamesToItems < ActiveRecord::Migration[6.0] def change add_column :items, :other_names, :string diff --git a/db/migrate/20200621211015_add_roles_to_users.rb b/db/migrate/20200621211015_add_roles_to_users.rb index ca1b88897..09bf6447b 100644 --- a/db/migrate/20200621211015_add_roles_to_users.rb +++ b/db/migrate/20200621211015_add_roles_to_users.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddRolesToUsers < ActiveRecord::Migration[6.0] def change create_enum :user_role, ["staff", "admin"] diff --git a/db/migrate/20200710004507_create_hold_requests.rb b/db/migrate/20200710004507_create_hold_requests.rb index 088d42b67..2f365b8e8 100644 --- a/db/migrate/20200710004507_create_hold_requests.rb +++ b/db/migrate/20200710004507_create_hold_requests.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateHoldRequests < ActiveRecord::Migration[6.0] def change create_enum :hold_request_status, [ diff --git a/db/migrate/20200714041707_create_hold_request_items.rb b/db/migrate/20200714041707_create_hold_request_items.rb index dcd9e84fb..5db3512a8 100644 --- a/db/migrate/20200714041707_create_hold_request_items.rb +++ b/db/migrate/20200714041707_create_hold_request_items.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateHoldRequestItems < ActiveRecord::Migration[6.0] def change create_table :hold_request_items do |t| diff --git a/db/migrate/20200718180844_add_event_id_to_hold_requests.rb b/db/migrate/20200718180844_add_event_id_to_hold_requests.rb index eeda3efd4..c33864f91 100644 --- a/db/migrate/20200718180844_add_event_id_to_hold_requests.rb +++ b/db/migrate/20200718180844_add_event_id_to_hold_requests.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddEventIdToHoldRequests < ActiveRecord::Migration[6.0] def change add_column :hold_requests, :event_id, :string diff --git a/db/migrate/20200722175156_create_events.rb b/db/migrate/20200722175156_create_events.rb index ce28934b9..f6dd26f62 100644 --- a/db/migrate/20200722175156_create_events.rb +++ b/db/migrate/20200722175156_create_events.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateEvents < ActiveRecord::Migration[6.0] def change create_table :events do |t| diff --git a/db/migrate/20200905185238_add_member_to_user.rb b/db/migrate/20200905185238_add_member_to_user.rb index b48b50e8e..67b4baf96 100644 --- a/db/migrate/20200905185238_add_member_to_user.rb +++ b/db/migrate/20200905185238_add_member_to_user.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddMemberToUser < ActiveRecord::Migration[6.0] def change # foreign_key to users table allowed to be null to support existing diff --git a/db/migrate/20200906142639_add_member_to_role_enum.rb b/db/migrate/20200906142639_add_member_to_role_enum.rb index 49dc3e9f8..1cfb92a5d 100644 --- a/db/migrate/20200906142639_add_member_to_role_enum.rb +++ b/db/migrate/20200906142639_add_member_to_role_enum.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddMemberToRoleEnum < ActiveRecord::Migration[6.0] disable_ddl_transaction! def change diff --git a/db/migrate/20200906142955_change_default_role_on_user.rb b/db/migrate/20200906142955_change_default_role_on_user.rb index a6911c217..2735a3cec 100644 --- a/db/migrate/20200906142955_change_default_role_on_user.rb +++ b/db/migrate/20200906142955_change_default_role_on_user.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ChangeDefaultRoleOnUser < ActiveRecord::Migration[6.0] def change change_column_default :users, :role, from: "staff", to: "member" diff --git a/db/migrate/20200906182546_add_pronouns_to_members.rb b/db/migrate/20200906182546_add_pronouns_to_members.rb index 454558c52..c38d38fd3 100644 --- a/db/migrate/20200906182546_add_pronouns_to_members.rb +++ b/db/migrate/20200906182546_add_pronouns_to_members.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddPronounsToMembers < ActiveRecord::Migration[6.0] class TemporaryMember < ActiveRecord::Base self.table_name = "members" diff --git a/db/migrate/20200913143441_add_member_renewable_to_borrow_policies.rb b/db/migrate/20200913143441_add_member_renewable_to_borrow_policies.rb index 349fb68f8..98b2b06e2 100644 --- a/db/migrate/20200913143441_add_member_renewable_to_borrow_policies.rb +++ b/db/migrate/20200913143441_add_member_renewable_to_borrow_policies.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddMemberRenewableToBorrowPolicies < ActiveRecord::Migration[6.0] def change add_column :borrow_policies, :member_renewable, :boolean, null: false, default: false diff --git a/db/migrate/20200921232145_create_libraries.rb b/db/migrate/20200921232145_create_libraries.rb index 47e41c5e6..faefe87c5 100644 --- a/db/migrate/20200921232145_create_libraries.rb +++ b/db/migrate/20200921232145_create_libraries.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + class CreateLibraries < ActiveRecord::Migration[6.0] def change create_table :libraries do |t| t.string :name, null: false - t.string :hostname, null: false, index: {unique: true} + t.string :hostname, null: false, index: { unique: true } t.string :member_postal_code_pattern, limit: 100, null: true, default: nil t.string :city, null: false t.string :email, null: false diff --git a/db/migrate/20200922173203_scope_models_to_tenants.rb b/db/migrate/20200922173203_scope_models_to_tenants.rb index 0967cd754..6d428f601 100644 --- a/db/migrate/20200922173203_scope_models_to_tenants.rb +++ b/db/migrate/20200922173203_scope_models_to_tenants.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ScopeModelsToTenants < ActiveRecord::Migration[6.0] def change add_column :users, :library_id, :integer diff --git a/db/migrate/20200922204207_add_super_admin_to_role_enum.rb b/db/migrate/20200922204207_add_super_admin_to_role_enum.rb index 8a9c8d841..e905688ab 100644 --- a/db/migrate/20200922204207_add_super_admin_to_role_enum.rb +++ b/db/migrate/20200922204207_add_super_admin_to_role_enum.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddSuperAdminToRoleEnum < ActiveRecord::Migration[6.0] disable_ddl_transaction! def change diff --git a/db/migrate/20200923151427_create_appointments.rb b/db/migrate/20200923151427_create_appointments.rb index c7f2c6816..932816485 100644 --- a/db/migrate/20200923151427_create_appointments.rb +++ b/db/migrate/20200923151427_create_appointments.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateAppointments < ActiveRecord::Migration[6.0] def change create_table :appointments do |t| diff --git a/db/migrate/20200923152956_create_appointment_holds.rb b/db/migrate/20200923152956_create_appointment_holds.rb index 49dcf2398..be8c885ca 100644 --- a/db/migrate/20200923152956_create_appointment_holds.rb +++ b/db/migrate/20200923152956_create_appointment_holds.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateAppointmentHolds < ActiveRecord::Migration[6.0] def change create_table :appointment_holds do |t| diff --git a/db/migrate/20200924184016_create_appointment_loans.rb b/db/migrate/20200924184016_create_appointment_loans.rb index fe47459ee..e9827ad83 100644 --- a/db/migrate/20200924184016_create_appointment_loans.rb +++ b/db/migrate/20200924184016_create_appointment_loans.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateAppointmentLoans < ActiveRecord::Migration[6.0] def change create_table :appointment_loans do |t| diff --git a/db/migrate/20200925122839_update_category_nodes_to_version_2.rb b/db/migrate/20200925122839_update_category_nodes_to_version_2.rb index 7599c207c..f21690e26 100644 --- a/db/migrate/20200925122839_update_category_nodes_to_version_2.rb +++ b/db/migrate/20200925122839_update_category_nodes_to_version_2.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class UpdateCategoryNodesToVersion2 < ActiveRecord::Migration[6.0] def change update_view :category_nodes, diff --git a/db/migrate/20200925123209_update_loan_summaries_to_version_4.rb b/db/migrate/20200925123209_update_loan_summaries_to_version_4.rb index 2766f2a47..a19965226 100644 --- a/db/migrate/20200925123209_update_loan_summaries_to_version_4.rb +++ b/db/migrate/20200925123209_update_loan_summaries_to_version_4.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class UpdateLoanSummariesToVersion4 < ActiveRecord::Migration[6.0] def change update_view :loan_summaries, version: 4, revert_to_version: 3 diff --git a/db/migrate/20200925134546_establish_tenant_zero.rb b/db/migrate/20200925134546_establish_tenant_zero.rb index 8f668cacb..50aa98e03 100644 --- a/db/migrate/20200925134546_establish_tenant_zero.rb +++ b/db/migrate/20200925134546_establish_tenant_zero.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class EstablishTenantZero < ActiveRecord::Migration[6.0] def up execute "INSERT INTO libraries (#{LIBRARY.keys.join(", ")}, created_at, updated_at)"\ @@ -17,41 +19,40 @@ def down end private + def library_id + @library_id ||= select_value("SELECT id FROM libraries WHERE hostname = #{connection.quote(LIBRARY[:hostname])}").presence || + (raise "Error updating #{LIBRARY[:name]} record") + end - def library_id - @library_id ||= select_value("SELECT id FROM libraries WHERE hostname = #{connection.quote(LIBRARY[:hostname])}").presence || - (raise "Error updating #{LIBRARY[:name]} record") - end - - ADDRESS = <<~ADDRESS.strip + ADDRESS = <<~ADDRESS.strip The Chicago Tool Library 1048 W 37th Street Suite 102 Chicago, IL 60609 chicagotoollibrary.org - ADDRESS - LIBRARY = { - name: "Chicago Tool Library", - hostname: "chicagotoollibrary.herokuapp.com", - city: "Chicago", - email: "team@chicagotoollibrary.org", - address: ADDRESS, - member_postal_code_pattern: "60707|60827|^606" - }.freeze - TABLES = %w[ - users - members - memberships - items - loans - documents - borrow_policies - gift_memberships - notifications - holds - categories - events - short_links - ].freeze + ADDRESS + LIBRARY = { + name: "Chicago Tool Library", + hostname: "chicagotoollibrary.herokuapp.com", + city: "Chicago", + email: "team@chicagotoollibrary.org", + address: ADDRESS, + member_postal_code_pattern: "60707|60827|^606" + }.freeze + TABLES = %w[ + users + members + memberships + items + loans + documents + borrow_policies + gift_memberships + notifications + holds + categories + events + short_links + ].freeze - private_constant :LIBRARY, :TABLES + private_constant :LIBRARY, :TABLES end diff --git a/db/migrate/20201002020141_add_power_source_to_items.rb b/db/migrate/20201002020141_add_power_source_to_items.rb index 68818208a..718d521a8 100644 --- a/db/migrate/20201002020141_add_power_source_to_items.rb +++ b/db/migrate/20201002020141_add_power_source_to_items.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddPowerSourceToItems < ActiveRecord::Migration[6.0] def change create_enum :power_source, ["solar", "gas", "air", "electric (corded)", "electric (battery)"] diff --git a/db/migrate/20201017185636_drop_hold_requests.rb b/db/migrate/20201017185636_drop_hold_requests.rb index d246cce78..c9c6786d1 100644 --- a/db/migrate/20201017185636_drop_hold_requests.rb +++ b/db/migrate/20201017185636_drop_hold_requests.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class DropHoldRequests < ActiveRecord::Migration[6.0] def change drop_table :hold_request_items diff --git a/db/migrate/20201024195024_remove_user_uniqueness.rb b/db/migrate/20201024195024_remove_user_uniqueness.rb index 8d64385b7..9f7072fdf 100644 --- a/db/migrate/20201024195024_remove_user_uniqueness.rb +++ b/db/migrate/20201024195024_remove_user_uniqueness.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class RemoveUserUniqueness < ActiveRecord::Migration[6.0] def change remove_index :users, column: :email, name: "index_users_on_email", unique: true diff --git a/db/migrate/20201024225228_rename_member_notes_to_bio.rb b/db/migrate/20201024225228_rename_member_notes_to_bio.rb index 18fb153e6..569c7d2ce 100644 --- a/db/migrate/20201024225228_rename_member_notes_to_bio.rb +++ b/db/migrate/20201024225228_rename_member_notes_to_bio.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class RenameMemberNotesToBio < ActiveRecord::Migration[6.0] def change rename_column :members, :notes, :bio diff --git a/db/migrate/20201107024718_downcase_emails.rb b/db/migrate/20201107024718_downcase_emails.rb index d674421f9..45e0db51e 100644 --- a/db/migrate/20201107024718_downcase_emails.rb +++ b/db/migrate/20201107024718_downcase_emails.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class DowncaseEmails < ActiveRecord::Migration[6.0] def change execute "UPDATE members SET email = LOWER(email)" diff --git a/db/migrate/20201112012007_create_item_attachments.rb b/db/migrate/20201112012007_create_item_attachments.rb index 0b9698406..4d54551f6 100644 --- a/db/migrate/20201112012007_create_item_attachments.rb +++ b/db/migrate/20201112012007_create_item_attachments.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + class CreateItemAttachments < ActiveRecord::Migration[6.0] def change create_enum :item_attachment_kind, ["manual", "parts_list", "other"] create_table :item_attachments do |t| t.belongs_to :item, null: false, foreign_key: true - t.belongs_to :creator, null: false, foreign_key: {to_table: :users} + t.belongs_to :creator, null: false, foreign_key: { to_table: :users } t.enum :kind, enum_type: :item_attachment_kind t.string :other_kind t.string :notes diff --git a/db/migrate/20201118221831_migrate_manuals_to_attachments.rb b/db/migrate/20201118221831_migrate_manuals_to_attachments.rb index 84ee51833..5b9f40dca 100644 --- a/db/migrate/20201118221831_migrate_manuals_to_attachments.rb +++ b/db/migrate/20201118221831_migrate_manuals_to_attachments.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class MigrateManualsToAttachments < ActiveRecord::Migration[6.0] class TemporaryItem < ActiveRecord::Base self.table_name = "items" diff --git a/db/migrate/20201129191804_make_memberships_pending.rb b/db/migrate/20201129191804_make_memberships_pending.rb index 7ed918130..4b5d27b86 100644 --- a/db/migrate/20201129191804_make_memberships_pending.rb +++ b/db/migrate/20201129191804_make_memberships_pending.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class MakeMembershipsPending < ActiveRecord::Migration[6.0] def change change_column_null :memberships, :started_on, true diff --git a/db/migrate/20201228190740_add_started_at_to_holds.rb b/db/migrate/20201228190740_add_started_at_to_holds.rb index a3b1295f7..1d06ab0d3 100644 --- a/db/migrate/20201228190740_add_started_at_to_holds.rb +++ b/db/migrate/20201228190740_add_started_at_to_holds.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddStartedAtToHolds < ActiveRecord::Migration[6.0] def change add_column :holds, :started_at, :timestamp diff --git a/db/migrate/20201231181600_rename_membership_started_on_and_ended_on.rb b/db/migrate/20201231181600_rename_membership_started_on_and_ended_on.rb index 41cf32519..582c846bb 100644 --- a/db/migrate/20201231181600_rename_membership_started_on_and_ended_on.rb +++ b/db/migrate/20201231181600_rename_membership_started_on_and_ended_on.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class RenameMembershipStartedOnAndEndedOn < ActiveRecord::Migration[6.0] def change rename_column(:memberships, :started_on, :started_at) diff --git a/db/migrate/20210129221240_remove_pronoun_and_custom_pronoun_columns.rb b/db/migrate/20210129221240_remove_pronoun_and_custom_pronoun_columns.rb index c847d4e85..fded55047 100644 --- a/db/migrate/20210129221240_remove_pronoun_and_custom_pronoun_columns.rb +++ b/db/migrate/20210129221240_remove_pronoun_and_custom_pronoun_columns.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class RemovePronounAndCustomPronounColumns < ActiveRecord::Migration[6.0] def change remove_column :members, :pronoun diff --git a/db/migrate/20210204025839_create_renewal_requests.rb b/db/migrate/20210204025839_create_renewal_requests.rb index c1fd06979..5beed3b70 100644 --- a/db/migrate/20210204025839_create_renewal_requests.rb +++ b/db/migrate/20210204025839_create_renewal_requests.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateRenewalRequests < ActiveRecord::Migration[6.0] def change create_enum :renewal_request_status, ["requested", "approved", "rejected"] diff --git a/db/migrate/20210216165139_add_service_name_to_active_storage_blobs.active_storage.rb b/db/migrate/20210216165139_add_service_name_to_active_storage_blobs.active_storage.rb index 95a21bbbe..4bed0651a 100644 --- a/db/migrate/20210216165139_add_service_name_to_active_storage_blobs.active_storage.rb +++ b/db/migrate/20210216165139_add_service_name_to_active_storage_blobs.active_storage.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This migration comes from active_storage (originally 20190112182829) class AddServiceNameToActiveStorageBlobs < ActiveRecord::Migration[6.0] def up diff --git a/db/migrate/20210216165140_create_active_storage_variant_records.active_storage.rb b/db/migrate/20210216165140_create_active_storage_variant_records.active_storage.rb index fb6e2b017..11d8daeec 100644 --- a/db/migrate/20210216165140_create_active_storage_variant_records.active_storage.rb +++ b/db/migrate/20210216165140_create_active_storage_variant_records.active_storage.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This migration comes from active_storage (originally 20191206030411) class CreateActiveStorageVariantRecords < ActiveRecord::Migration[6.0] def change diff --git a/db/migrate/20210314163055_update_monthly_adjustments_to_version_2.rb b/db/migrate/20210314163055_update_monthly_adjustments_to_version_2.rb index d5a351083..d5ae1fd36 100644 --- a/db/migrate/20210314163055_update_monthly_adjustments_to_version_2.rb +++ b/db/migrate/20210314163055_update_monthly_adjustments_to_version_2.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class UpdateMonthlyAdjustmentsToVersion2 < ActiveRecord::Migration[6.1] def change update_view :monthly_adjustments, version: 2, revert_to_version: 1 diff --git a/db/migrate/20210519212401_add_completed_at_to_appointments.rb b/db/migrate/20210519212401_add_completed_at_to_appointments.rb index 3f3b8470b..93c441d04 100644 --- a/db/migrate/20210519212401_add_completed_at_to_appointments.rb +++ b/db/migrate/20210519212401_add_completed_at_to_appointments.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddCompletedAtToAppointments < ActiveRecord::Migration[6.1] def change add_column :appointments, :completed_at, :timestamp diff --git a/db/migrate/20210722214912_add_item_location_fields.rb b/db/migrate/20210722214912_add_item_location_fields.rb index 2910411c3..dbd56e5de 100644 --- a/db/migrate/20210722214912_add_item_location_fields.rb +++ b/db/migrate/20210722214912_add_item_location_fields.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddItemLocationFields < ActiveRecord::Migration[6.1] def change add_column :items, :location_area, :text diff --git a/db/migrate/20210903205105_change_event_attendees_to_jsonb.rb b/db/migrate/20210903205105_change_event_attendees_to_jsonb.rb index 1b5a5fbfa..3b10a3749 100644 --- a/db/migrate/20210903205105_change_event_attendees_to_jsonb.rb +++ b/db/migrate/20210903205105_change_event_attendees_to_jsonb.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ChangeEventAttendeesToJsonb < ActiveRecord::Migration[6.1] def change remove_column :events, :attendees diff --git a/db/migrate/20210911202001_add_pronunciation_to_members.rb b/db/migrate/20210911202001_add_pronunciation_to_members.rb index f7c9a5487..f2c5457cb 100644 --- a/db/migrate/20210911202001_add_pronunciation_to_members.rb +++ b/db/migrate/20210911202001_add_pronunciation_to_members.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddPronunciationToMembers < ActiveRecord::Migration[6.1] def change add_column :members, :pronunciation, :string diff --git a/db/migrate/20210925151216_add_plain_text_description_to_item.rb b/db/migrate/20210925151216_add_plain_text_description_to_item.rb index d4e9ef585..efe71d792 100644 --- a/db/migrate/20210925151216_add_plain_text_description_to_item.rb +++ b/db/migrate/20210925151216_add_plain_text_description_to_item.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddPlainTextDescriptionToItem < ActiveRecord::Migration[6.1] def change add_column :items, :plain_text_description, :text diff --git a/db/migrate/20211006183946_add_library_id_to_renewal_requests.rb b/db/migrate/20211006183946_add_library_id_to_renewal_requests.rb index 4bf33f447..4c93cb16f 100644 --- a/db/migrate/20211006183946_add_library_id_to_renewal_requests.rb +++ b/db/migrate/20211006183946_add_library_id_to_renewal_requests.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddLibraryIdToRenewalRequests < ActiveRecord::Migration[6.1] def change add_column :renewal_requests, :library_id, :integer diff --git a/db/migrate/20211012153401_add_allow_members_to_libraries.rb b/db/migrate/20211012153401_add_allow_members_to_libraries.rb index 7df916e75..a464b2b48 100644 --- a/db/migrate/20211012153401_add_allow_members_to_libraries.rb +++ b/db/migrate/20211012153401_add_allow_members_to_libraries.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddAllowMembersToLibraries < ActiveRecord::Migration[6.0] def change add_column :libraries, :allow_members, :boolean, default: true, after: :address, null: false diff --git a/db/migrate/20211013172726_add_allow_payments_to_libraries.rb b/db/migrate/20211013172726_add_allow_payments_to_libraries.rb index 030c5e8a5..7e6e18507 100644 --- a/db/migrate/20211013172726_add_allow_payments_to_libraries.rb +++ b/db/migrate/20211013172726_add_allow_payments_to_libraries.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddAllowPaymentsToLibraries < ActiveRecord::Migration[6.0] def change add_column :libraries, :allow_payments, :boolean, default: true, after: :allow_payments, null: false diff --git a/db/migrate/20211013175030_add_allow_volunteers_to_libraries.rb b/db/migrate/20211013175030_add_allow_volunteers_to_libraries.rb index c6fd23852..e35e6583e 100644 --- a/db/migrate/20211013175030_add_allow_volunteers_to_libraries.rb +++ b/db/migrate/20211013175030_add_allow_volunteers_to_libraries.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddAllowVolunteersToLibraries < ActiveRecord::Migration[6.1] def change add_column :libraries, :allow_volunteers, :boolean, default: true, after: :address, null: false diff --git a/db/migrate/20211014184745_add_allow_appointments_to_libraries.rb b/db/migrate/20211014184745_add_allow_appointments_to_libraries.rb index 275d53364..6a69cd2de 100644 --- a/db/migrate/20211014184745_add_allow_appointments_to_libraries.rb +++ b/db/migrate/20211014184745_add_allow_appointments_to_libraries.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddAllowAppointmentsToLibraries < ActiveRecord::Migration[6.1] def change add_column :libraries, :allow_appointments, :boolean, default: true, after: :allow_members, null: false diff --git a/db/migrate/20211120222110_add_expires_at_to_holds.rb b/db/migrate/20211120222110_add_expires_at_to_holds.rb index 91a5460ff..de223a823 100644 --- a/db/migrate/20211120222110_add_expires_at_to_holds.rb +++ b/db/migrate/20211120222110_add_expires_at_to_holds.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddExpiresAtToHolds < ActiveRecord::Migration[6.1] def change add_column :holds, :expires_at, :datetime diff --git a/db/migrate/20211203200042_create_library_updates.rb b/db/migrate/20211203200042_create_library_updates.rb index 04032b554..e76e01a29 100644 --- a/db/migrate/20211203200042_create_library_updates.rb +++ b/db/migrate/20211203200042_create_library_updates.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateLibraryUpdates < ActiveRecord::Migration[6.1] def change create_table :library_updates do |t| diff --git a/db/migrate/20220202191706_create_enum_for_item_status.rb b/db/migrate/20220202191706_create_enum_for_item_status.rb index 7e5c6ce82..c1df58748 100644 --- a/db/migrate/20220202191706_create_enum_for_item_status.rb +++ b/db/migrate/20220202191706_create_enum_for_item_status.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateEnumForItemStatus < ActiveRecord::Migration[6.1] class Item < ActiveRecord::Base enum status: [:pending, :active, :maintenance, :retired] diff --git a/db/migrate/20220202214711_create_maintenance_reports.rb b/db/migrate/20220202214711_create_maintenance_reports.rb index 98a9a5168..22b010d2f 100644 --- a/db/migrate/20220202214711_create_maintenance_reports.rb +++ b/db/migrate/20220202214711_create_maintenance_reports.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + class CreateMaintenanceReports < ActiveRecord::Migration[6.1] def change create_table :maintenance_reports do |t| t.text :title t.integer :time_spent t.belongs_to :item, null: false, foreign_key: true - t.belongs_to :creator, null: false, foreign_key: {to_table: :users} + t.belongs_to :creator, null: false, foreign_key: { to_table: :users } t.enum :current_item_status, enum_type: "item_status" t.belongs_to :audit, foreign_key: true diff --git a/db/migrate/20220212072927_create_monthly_loans.rb b/db/migrate/20220212072927_create_monthly_loans.rb index 2715981a2..f9c00bdc1 100644 --- a/db/migrate/20220212072927_create_monthly_loans.rb +++ b/db/migrate/20220212072927_create_monthly_loans.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateMonthlyLoans < ActiveRecord::Migration[6.1] def change create_view :monthly_loans diff --git a/db/migrate/20220212073119_create_monthly_members.rb b/db/migrate/20220212073119_create_monthly_members.rb index 1c7c58a37..d4736fab9 100644 --- a/db/migrate/20220212073119_create_monthly_members.rb +++ b/db/migrate/20220212073119_create_monthly_members.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateMonthlyMembers < ActiveRecord::Migration[6.1] def change create_view :monthly_members diff --git a/db/migrate/20220212073628_create_monthly_appointments.rb b/db/migrate/20220212073628_create_monthly_appointments.rb index b29ff107b..ea86fda5e 100644 --- a/db/migrate/20220212073628_create_monthly_appointments.rb +++ b/db/migrate/20220212073628_create_monthly_appointments.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateMonthlyAppointments < ActiveRecord::Migration[6.1] def change create_view :monthly_appointments diff --git a/db/migrate/20220212081100_drop_monthly_activities_view.rb b/db/migrate/20220212081100_drop_monthly_activities_view.rb index af333786a..16236045f 100644 --- a/db/migrate/20220212081100_drop_monthly_activities_view.rb +++ b/db/migrate/20220212081100_drop_monthly_activities_view.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class DropMonthlyActivitiesView < ActiveRecord::Migration[6.1] def change drop_view :monthly_activities, revert_to_version: 1 diff --git a/db/migrate/20220215035541_add_additional_item_statuses.rb b/db/migrate/20220215035541_add_additional_item_statuses.rb index 9ba5056f7..3da450ea9 100644 --- a/db/migrate/20220215035541_add_additional_item_statuses.rb +++ b/db/migrate/20220215035541_add_additional_item_statuses.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddAdditionalItemStatuses < ActiveRecord::Migration[6.1] def change add_enum_value :item_status, "maintenance_repairing" diff --git a/db/migrate/20220225180000_add_ticket_status.rb b/db/migrate/20220225180000_add_ticket_status.rb index ddcec7526..77f931409 100644 --- a/db/migrate/20220225180000_add_ticket_status.rb +++ b/db/migrate/20220225180000_add_ticket_status.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddTicketStatus < ActiveRecord::Migration[6.1] def change create_enum :ticket_status, ["assess", "parts", "repairing", "resolved"] diff --git a/db/migrate/20220225184325_create_tickets.rb b/db/migrate/20220225184325_create_tickets.rb index 75a96f88e..d38630943 100644 --- a/db/migrate/20220225184325_create_tickets.rb +++ b/db/migrate/20220225184325_create_tickets.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + class CreateTickets < ActiveRecord::Migration[6.1] def change create_table :tickets do |t| t.string :title, null: false t.references :item, null: false, foreign_key: true t.enum :status, enum_type: "ticket_status", null: false, default: "assess" - t.belongs_to :creator, null: false, foreign_key: {to_table: :users} + t.belongs_to :creator, null: false, foreign_key: { to_table: :users } t.timestamps end diff --git a/db/migrate/20220225192017_drop_maintenance_reports.rb b/db/migrate/20220225192017_drop_maintenance_reports.rb index 0438d37ef..1475c53b1 100644 --- a/db/migrate/20220225192017_drop_maintenance_reports.rb +++ b/db/migrate/20220225192017_drop_maintenance_reports.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class DropMaintenanceReports < ActiveRecord::Migration[6.1] def change drop_table :maintenance_reports diff --git a/db/migrate/20220227204052_create_ticket_updates.rb b/db/migrate/20220227204052_create_ticket_updates.rb index 825923aa4..4b0cc793c 100644 --- a/db/migrate/20220227204052_create_ticket_updates.rb +++ b/db/migrate/20220227204052_create_ticket_updates.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + class CreateTicketUpdates < ActiveRecord::Migration[6.1] def change create_table :ticket_updates do |t| t.integer :time_spent t.belongs_to :ticket, null: false, foreign_key: true - t.belongs_to :creator, null: false, foreign_key: {to_table: :users} + t.belongs_to :creator, null: false, foreign_key: { to_table: :users } t.belongs_to :audit, foreign_key: true t.timestamps diff --git a/db/migrate/20220303060319_add_consumable_to_borrow_policy.rb b/db/migrate/20220303060319_add_consumable_to_borrow_policy.rb index d1439b2b7..609127637 100644 --- a/db/migrate/20220303060319_add_consumable_to_borrow_policy.rb +++ b/db/migrate/20220303060319_add_consumable_to_borrow_policy.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddConsumableToBorrowPolicy < ActiveRecord::Migration[6.1] def change add_column :borrow_policies, :consumable, :boolean, default: false diff --git a/db/migrate/20220303210904_remove_maintenance_statuses_from_items.rb b/db/migrate/20220303210904_remove_maintenance_statuses_from_items.rb index 39abbcf44..d15dc4bf3 100644 --- a/db/migrate/20220303210904_remove_maintenance_statuses_from_items.rb +++ b/db/migrate/20220303210904_remove_maintenance_statuses_from_items.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + class RemoveMaintenanceStatusesFromItems < ActiveRecord::Migration[6.1] def change execute "UPDATE items SET status = 'maintenance' WHERE status = 'maintenance_parts' OR status = 'maintenance_repairing'" execute "ALTER TYPE item_status RENAME TO item_status_old" create_enum :item_status, ["pending", "active", "maintenance", "retired"] execute <<~SQL - ALTER TABLE items + ALTER TABLE items#{' '} ALTER COLUMN status DROP DEFAULT, ALTER COLUMN status TYPE item_status USING (status::text::item_status), ALTER COLUMN status SET DEFAULT 'active' diff --git a/db/migrate/20220304025546_add_library_to_tickets_and_ticket_updates.rb b/db/migrate/20220304025546_add_library_to_tickets_and_ticket_updates.rb index 8df5d9b31..a4a5201ff 100644 --- a/db/migrate/20220304025546_add_library_to_tickets_and_ticket_updates.rb +++ b/db/migrate/20220304025546_add_library_to_tickets_and_ticket_updates.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddLibraryToTicketsAndTicketUpdates < ActiveRecord::Migration[6.1] def change add_reference :tickets, :library diff --git a/db/migrate/20220327010549_add_url_to_items.rb b/db/migrate/20220327010549_add_url_to_items.rb index bed9e1a75..b8666ae12 100644 --- a/db/migrate/20220327010549_add_url_to_items.rb +++ b/db/migrate/20220327010549_add_url_to_items.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddUrlToItems < ActiveRecord::Migration[6.1] def change add_column :items, :url, :string diff --git a/db/migrate/20220330165641_add_item_counts_to_category.rb b/db/migrate/20220330165641_add_item_counts_to_category.rb index 76321d273..d55630e54 100644 --- a/db/migrate/20220330165641_add_item_counts_to_category.rb +++ b/db/migrate/20220330165641_add_item_counts_to_category.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddItemCountsToCategory < ActiveRecord::Migration[6.1] def change add_column :categories, :item_counts, :jsonb, default: {} diff --git a/db/migrate/20220330175925_update_category_nodes_to_version_3.rb b/db/migrate/20220330175925_update_category_nodes_to_version_3.rb index d4930c4e9..4b9e8a365 100644 --- a/db/migrate/20220330175925_update_category_nodes_to_version_3.rb +++ b/db/migrate/20220330175925_update_category_nodes_to_version_3.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class UpdateCategoryNodesToVersion3 < ActiveRecord::Migration[6.1] def change update_view :category_nodes, diff --git a/db/migrate/20220403224122_add_unique_index_to_category_nodes.rb b/db/migrate/20220403224122_add_unique_index_to_category_nodes.rb index 87304e661..6a56b5a45 100644 --- a/db/migrate/20220403224122_add_unique_index_to_category_nodes.rb +++ b/db/migrate/20220403224122_add_unique_index_to_category_nodes.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddUniqueIndexToCategoryNodes < ActiveRecord::Migration[6.1] def change add_index :category_nodes, :id, unique: true diff --git a/db/migrate/20220421204258_update_category_nodes_to_version_4.rb b/db/migrate/20220421204258_update_category_nodes_to_version_4.rb index 6c124e909..3b93987ad 100644 --- a/db/migrate/20220421204258_update_category_nodes_to_version_4.rb +++ b/db/migrate/20220421204258_update_category_nodes_to_version_4.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class UpdateCategoryNodesToVersion4 < ActiveRecord::Migration[6.1] def change update_view :category_nodes, version: 4, revert_to_version: 3, materialized: true diff --git a/db/migrate/20220422172531_remove_item_counts_from_categories.rb b/db/migrate/20220422172531_remove_item_counts_from_categories.rb index 9f9f5b61c..b3f7aa995 100644 --- a/db/migrate/20220422172531_remove_item_counts_from_categories.rb +++ b/db/migrate/20220422172531_remove_item_counts_from_categories.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class RemoveItemCountsFromCategories < ActiveRecord::Migration[6.1] def change remove_column :categories, :item_counts, :jsonb, default: {} diff --git a/db/migrate/20220902013538_add_purchase_price_and_purchase_link_to_item.rb b/db/migrate/20220902013538_add_purchase_price_and_purchase_link_to_item.rb index f4b9c5a23..897340ec0 100644 --- a/db/migrate/20220902013538_add_purchase_price_and_purchase_link_to_item.rb +++ b/db/migrate/20220902013538_add_purchase_price_and_purchase_link_to_item.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddPurchasePriceAndPurchaseLinkToItem < ActiveRecord::Migration[6.1] def change add_column :items, :purchase_link, :string diff --git a/db/migrate/20221030174955_add_my_turn_item_type_to_items.rb b/db/migrate/20221030174955_add_my_turn_item_type_to_items.rb index 2bef5ef57..99a1f6f75 100644 --- a/db/migrate/20221030174955_add_my_turn_item_type_to_items.rb +++ b/db/migrate/20221030174955_add_my_turn_item_type_to_items.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddMyTurnItemTypeToItems < ActiveRecord::Migration[6.1] def change add_column :items, :myturn_item_type, :string diff --git a/db/schema.rb b/db/schema.rb index 681f2815f..1acd28925 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. @@ -11,7 +13,6 @@ # It's strongly recommended that you check this file into your version control system. ActiveRecord::Schema.define(version: 2022_10_30_174955) do - # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -701,5 +702,4 @@ FROM tree_nodes; SQL add_index "category_nodes", ["id"], name: "index_category_nodes_on_id", unique: true - end diff --git a/db/seeds.rb b/db/seeds.rb index 270335ccc..71c5315a2 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + def seed_library(library, email_suffix = "", postal_code = "60609") ActsAsTenant.with_tenant(library) do member_attrs = { phone_number: "3124567890", pronouns: ["she/her"], id_kind: 0, address_verified: false, desires: "saws, hammers", - address1: "123 S. Streetname St.", address2: "Apt. 4", city: "Chicago", region: "IL", postal_code: postal_code, + address1: "123 S. Streetname St.", address2: "Apt. 4", city: "Chicago", region: "IL", postal_code:, reminders_via_email: true, reminders_via_text: true, receive_newsletter: true, volunteer_interest: true } diff --git a/gems/active_storage_log_suppressor/Gemfile b/gems/active_storage_log_suppressor/Gemfile index 408c54d66..1aeb9acca 100644 --- a/gems/active_storage_log_suppressor/Gemfile +++ b/gems/active_storage_log_suppressor/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source "https://rubygems.org" git_source(:github) { |repo| "https://github.com/#{repo}.git" } diff --git a/gems/active_storage_log_suppressor/active_storage_log_suppressor.gemspec b/gems/active_storage_log_suppressor/active_storage_log_suppressor.gemspec index ecf7f90aa..6254ed0a1 100644 --- a/gems/active_storage_log_suppressor/active_storage_log_suppressor.gemspec +++ b/gems/active_storage_log_suppressor/active_storage_log_suppressor.gemspec @@ -1,3 +1,5 @@ +# frozen_string_literal: true + $:.push File.expand_path("lib", __dir__) # Maintain your gem's version: diff --git a/gems/active_storage_log_suppressor/lib/active_storage_log_suppressor/filters.rb b/gems/active_storage_log_suppressor/lib/active_storage_log_suppressor/filters.rb index 6ae7306b8..ca7abdd37 100644 --- a/gems/active_storage_log_suppressor/lib/active_storage_log_suppressor/filters.rb +++ b/gems/active_storage_log_suppressor/lib/active_storage_log_suppressor/filters.rb @@ -17,12 +17,11 @@ def redirect_to(event) module ActiveStorageLoggingFilters private + def info(event, colored_message) + end - def info(event, colored_message) - end - - def debug(event, colored_message) - end + def debug(event, colored_message) + end end module ActiveRecordLoggingFilters diff --git a/gems/active_storage_log_suppressor/lib/tasks/active_storage_log_suppressor_tasks.rake b/gems/active_storage_log_suppressor/lib/tasks/active_storage_log_suppressor_tasks.rake index bc2d6d4c4..0686758d0 100644 --- a/gems/active_storage_log_suppressor/lib/tasks/active_storage_log_suppressor_tasks.rake +++ b/gems/active_storage_log_suppressor/lib/tasks/active_storage_log_suppressor_tasks.rake @@ -1,3 +1,4 @@ +# frozen_string_literal: true # desc "Explaining what the task does" # task :active_storage_log_suppressor do # # Task goes here diff --git a/lib/rails_solargraph.rb b/lib/rails_solargraph.rb index c66cd05f1..09ada882e 100644 --- a/lib/rails_solargraph.rb +++ b/lib/rails_solargraph.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # https://gist.github.com/castwide/28b349566a223dfb439a337aea29713e # # The following comments fill some of the gaps in Solargraph's understanding of diff --git a/lib/tasks/categories.rake b/lib/tasks/categories.rake index 15ffce729..f6186038a 100644 --- a/lib/tasks/categories.rake +++ b/lib/tasks/categories.rake @@ -1,3 +1,5 @@ +# frozen_string_literal: true + namespace :categories do desc "Updates the category_nodes materialized view" task refresh_nodes: :environment do diff --git a/lib/tasks/db.rake b/lib/tasks/db.rake index 26e723bb9..70be6303c 100644 --- a/lib/tasks/db.rake +++ b/lib/tasks/db.rake @@ -1,3 +1,5 @@ +# frozen_string_literal: true + namespace :db do desc "Closes all other connections to the database" task close_connections: :environment do diff --git a/lib/tasks/devdata.rake b/lib/tasks/devdata.rake index f11b2ce6a..be466b07d 100644 --- a/lib/tasks/devdata.rake +++ b/lib/tasks/devdata.rake @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "fileutils" DEVDATA_DIR = File.expand_path("db/devdata", Rails.root) @@ -65,9 +67,9 @@ namespace :devdata do Library.all.each_with_index do |library, index| postal_code = postal_codes[index] ActsAsTenant.with_tenant(library) do - create_member(holds: 2, waiting_holds: 2, loans: 2, postal_code: postal_code) - create_member(loans: 5, postal_code: postal_code) - create_member(postal_code: postal_code) + create_member(holds: 2, waiting_holds: 2, loans: 2, postal_code:) + create_member(loans: 5, postal_code:) + create_member(postal_code:) end end end @@ -79,33 +81,33 @@ namespace :devdata do email = "member#{id}@example.com" member = Member.create!( - status: status, - email: email, - user: User.create!(email: email, password: "password"), + status:, + email:, + user: User.create!(email:, password: "password"), phone_number: "3121234567", full_name: "Member Number #{id}", preferred_name: "Member ##{id}", address1: "#{id} W. Chicago Ave", - postal_code: postal_code, + postal_code:, address_verified: true ) holds.times do item = random_model(Item.active.available) - Hold.create!(member: member, item: item, creator: member.user) + Hold.create!(member:, item:, creator: member.user) end # holds where this person is in line behind someone else waiting_holds.times do item = random_model(Item.active.available) member_in_front = random_model(Member) - Hold.create!(member: member_in_front, item: item, creator: member_in_front.user) - Hold.create!(member: member, item: item, creator: member.user) + Hold.create!(member: member_in_front, item:, creator: member_in_front.user) + Hold.create!(member:, item:, creator: member.user) end loans.times do item = random_model(Item.active.includes(:borrow_policy).available) - Loan.create!(item: item, member: member, due_at: 1.week.since, uniquely_numbered: item.borrow_policy.uniquely_numbered) + Loan.create!(item:, member:, due_at: 1.week.since, uniquely_numbered: item.borrow_policy.uniquely_numbered) end end diff --git a/lib/tasks/email.rake b/lib/tasks/email.rake index 252468119..c85f9f860 100644 --- a/lib/tasks/email.rake +++ b/lib/tasks/email.rake @@ -1,3 +1,5 @@ +# frozen_string_literal: true + def send_emails(mails, date) Time.use_zone("America/Chicago") do now = date ? Date.iso8601(date) : Time.current.to_date @@ -32,7 +34,7 @@ namespace :email do Membership.where(ended_at: (Date.today + 30.days).all_day).each do |membership| member = membership.member amount = member.last_membership&.amount || Money.new(0) - MemberMailer.with(member: member, amount: amount).membership_renewal_reminder.deliver_now + MemberMailer.with(member:, amount:).membership_renewal_reminder.deliver_now end end diff --git a/lib/tasks/export.rake b/lib/tasks/export.rake index 1d902c80d..cae2cee19 100644 --- a/lib/tasks/export.rake +++ b/lib/tasks/export.rake @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "csv" namespace :export do diff --git a/lib/tasks/holds.rake b/lib/tasks/holds.rake index 8bfff1c14..7d6911edb 100644 --- a/lib/tasks/holds.rake +++ b/lib/tasks/holds.rake @@ -1,9 +1,11 @@ +# frozen_string_literal: true + namespace :holds do desc "Check for holds that should be started and send emails to members" task start_waiting_holds: :environment do Time.use_zone("America/Chicago") do Hold.start_waiting_holds do |hold| - MemberMailer.with(member: hold.member, hold: hold).hold_available.deliver_now + MemberMailer.with(member: hold.member, hold:).hold_available.deliver_now end end end diff --git a/lib/tasks/import.rake b/lib/tasks/import.rake index 2e26a9251..08c43dc4b 100644 --- a/lib/tasks/import.rake +++ b/lib/tasks/import.rake @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "csv" # BorrowPolicy.create!(library_id: 1, code: "S", consumable: true, uniquely_numbered: false, name: "Single Use") @@ -99,7 +101,7 @@ namespace :import do next if row["categories"].to_s == "" category_ids = find_or_create_categories_from_names(item.id, row["categories"]) - item.update!(category_ids: category_ids) if category_ids + item.update!(category_ids:) if category_ids end end end diff --git a/lib/tasks/members.rake b/lib/tasks/members.rake index c5f732bc7..9354590c8 100644 --- a/lib/tasks/members.rake +++ b/lib/tasks/members.rake @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "securerandom" namespace :members do @@ -11,7 +13,7 @@ namespace :members do puts "found match for #{user.email}" else puts "creating member for #{user.email}" - Member.create!(user: user, email: user.email, full_name: user.email, phone_number: "7732420923", address1: "1048 W. 37th St.", postal_code: "60609") + Member.create!(user:, email: user.email, full_name: user.email, phone_number: "7732420923", address1: "1048 W. 37th St.", postal_code: "60609") end end end @@ -26,7 +28,7 @@ namespace :members do password = SecureRandom.hex begin - new_user = User.create!(email: member.email, password: password) + new_user = User.create!(email: member.email, password:) member.user = new_user member.save(validate: false) rescue ActiveRecord::RecordInvalid => e diff --git a/lib/tasks/neon.rake b/lib/tasks/neon.rake index 67e8992d2..1b58156ec 100644 --- a/lib/tasks/neon.rake +++ b/lib/tasks/neon.rake @@ -1,3 +1,5 @@ +# frozen_string_literal: true + namespace :neon do task search: :environment do client = Neon::Client.new(ENV.fetch("NEON_ORGANIZATION_ID"), ENV.fetch("NEON_API_KEY")) diff --git a/lib/tasks/production.rake b/lib/tasks/production.rake index 1329fce61..dd7d60383 100644 --- a/lib/tasks/production.rake +++ b/lib/tasks/production.rake @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "open3" def run_and_print(command) @@ -52,7 +54,7 @@ def scrub_data scrub_users Member.update_all(<<~SQL) - full_name = 'Firstname ' || id || ' Lastname', + full_name = 'Firstname ' || id || ' Lastname',#{' '} preferred_name = 'Member ' || id, email = 'member' || id || '@example.com', phone_number = '7732420923', diff --git a/lib/tasks/s3.rake b/lib/tasks/s3.rake index 644ce211e..f92ffb9a7 100644 --- a/lib/tasks/s3.rake +++ b/lib/tasks/s3.rake @@ -1,3 +1,5 @@ +# frozen_string_literal: true + task :s3_import do storage_folder = Rails.root.join("storage") storage_folder.mkpath diff --git a/lib/tasks/stats.rake b/lib/tasks/stats.rake index 67ba44e43..c38ce4106 100644 --- a/lib/tasks/stats.rake +++ b/lib/tasks/stats.rake @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "csv" desc "Export member stats to CSV" diff --git a/lib/tasks/sync.rake b/lib/tasks/sync.rake index 4cd6e30d3..b7198f969 100644 --- a/lib/tasks/sync.rake +++ b/lib/tasks/sync.rake @@ -1,3 +1,5 @@ +# frozen_string_literal: true + namespace :sync do desc "Syncronizes calendars with the events database" task calendars: :environment do @@ -8,7 +10,7 @@ namespace :sync do end def sync_calendar(calendar_id) - calendar = Google::Calendar.new(calendar_id: calendar_id) + calendar = Google::Calendar.new(calendar_id:) result = calendar.upcoming_events(Time.zone.now, 3.months.since) if result.success? Event.update_events(result.value) diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb index 2a7714add..c0885d787 100644 --- a/test/application_system_test_case.rb +++ b/test/application_system_test_case.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" Capybara.default_max_wait_time = 5 @@ -106,57 +108,54 @@ def fail_on_js_error(error) end end - refute fail, "there were JavaScript errors" + assert_not fail, "there were JavaScript errors" end private + def ignore_js_errors(reason: "I know what I am doing") + Rails.logger.info("Swallowed JS error because: #{reason}") + yield if block_given? + page.driver.browser.logs.get(:browser) + end - def ignore_js_errors(reason: "I know what I am doing") - Rails.logger.info("Swallowed JS error because: #{reason}") - yield if block_given? - page.driver.browser.logs.get(:browser) - end - - def sign_in_as_admin - @user = FactoryBot.create(:user, role: "admin") - login_as(@user, scope: :user) - end + def sign_in_as_admin + @user = FactoryBot.create(:user, role: "admin") + login_as(@user, scope: :user) + end - def audited_as_admin(&block) - Audited.audit_model.as_user(@user) do - yield + def audited_as_admin(&block) + Audited.audit_model.as_user(@user, &block) end - end - def fill_in_rich_text_area(locator = nil, with:) - find(:rich_text_area, locator).execute_script("this.editor.loadHTML(arguments[0])", with.to_s) - end + def fill_in_rich_text_area(locator = nil, with:) + find(:rich_text_area, locator).execute_script("this.editor.loadHTML(arguments[0])", with.to_s) + end - def assert_delivered_email(to:, &block) - delivered_mail = ActionMailer::Base.deliveries.last - assert_equal [to], delivered_mail.to + def assert_delivered_email(to:, &block) + delivered_mail = ActionMailer::Base.deliveries.last + assert_equal [to], delivered_mail.to - assert delivered_mail.body.parts.size == 2, "non multipart email was sent!" + assert delivered_mail.body.parts.size == 2, "non multipart email was sent!" - if delivered_mail.attachments.size > 0 - text = delivered_mail.body.parts[0].body.parts[0].body - html = delivered_mail.body.parts[0].body.parts[1].body - attachments = delivered_mail.attachments - else - html = delivered_mail.body.parts[0].body.to_s - text = delivered_mail.body.parts[1].body.to_s - attachments = [] + if delivered_mail.attachments.size > 0 + text = delivered_mail.body.parts[0].body.parts[0].body + html = delivered_mail.body.parts[0].body.parts[1].body + attachments = delivered_mail.attachments + else + html = delivered_mail.body.parts[0].body.to_s + text = delivered_mail.body.parts[1].body.to_s + attachments = [] + end + yield html, text, attachments end - yield html, text, attachments - end - def assert_date_displayed(datetime) - find("time[datetime='#{datetime.utc}']") - end + def assert_date_displayed(datetime) + find("time[datetime='#{datetime.utc}']") + end - # The GH action runners are _slow_ and things like image generation or - # MJML rendering will easily timeout unless given a lot of breathing room. - def slow_op_wait_time - ENV["GITHUB_ACTIONS"] ? 30 : 10 - end + # The GH action runners are _slow_ and things like image generation or + # MJML rendering will easily timeout unless given a lot of breathing room. + def slow_op_wait_time + ENV["GITHUB_ACTIONS"] ? 30 : 10 + end end diff --git a/test/channels/application_cable/connection_test.rb b/test/channels/application_cable/connection_test.rb index 6ba209f87..0810a5d86 100644 --- a/test/channels/application_cable/connection_test.rb +++ b/test/channels/application_cable/connection_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" # class ApplicationCable::ConnectionTest < ActionCable::Connection::TestCase diff --git a/test/controllers/account/appointments_controller_test.rb b/test/controllers/account/appointments_controller_test.rb index d5e46cb7e..8a6a8d0f7 100644 --- a/test/controllers/account/appointments_controller_test.rb +++ b/test/controllers/account/appointments_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" module Account @@ -33,7 +35,7 @@ class AppointmentsControllerTest < ActionDispatch::IntegrationTest assert_equal 1, @appointment.holds.count @hold2 = FactoryBot.create(:hold, member: @member) - put account_appointment_path(@appointment), params: {appointment: {hold_ids: [@hold.id, @hold2.id], time_range_string: @appointment.time_range_string, comment: @appointment.comment}} + put account_appointment_path(@appointment), params: { appointment: { hold_ids: [@hold.id, @hold2.id], time_range_string: @appointment.time_range_string, comment: @appointment.comment } } @appointment.reload assert_equal 2, @appointment.holds.count @@ -41,7 +43,7 @@ class AppointmentsControllerTest < ActionDispatch::IntegrationTest end test "should not update appointment with invalid params" do - put account_appointment_path(@appointment), params: {appointment: {hold_ids: [], time_range_string: @appointment.time_range_string, comment: @appointment.comment}} + put account_appointment_path(@appointment), params: { appointment: { hold_ids: [], time_range_string: @appointment.time_range_string, comment: @appointment.comment } } assert_template :edit assert_select "ul.error", /Please select an item to pick-up or return for your appointment/ @@ -53,7 +55,7 @@ class AppointmentsControllerTest < ActionDispatch::IntegrationTest test "should not update appointment scheduled after any holds expire" do @expired_hold = create(:hold, member: @member) @expired_hold.start!(@appointment.starts_at - Hold::HOLD_LENGTH - 1.days) - put account_appointment_path(@appointment), params: {appointment: {hold_ids: [@hold.id, @expired_hold.id], time_range_string: @appointment.time_range_string, comment: @appointment.comment}} + put account_appointment_path(@appointment), params: { appointment: { hold_ids: [@hold.id, @expired_hold.id], time_range_string: @appointment.time_range_string, comment: @appointment.comment } } assert_template :edit assert_select "ul.error", /on or before hold expires on/ diff --git a/test/controllers/account/holds_controller_test.rb b/test/controllers/account/holds_controller_test.rb index af59845f8..f87903b81 100644 --- a/test/controllers/account/holds_controller_test.rb +++ b/test/controllers/account/holds_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" module Account @@ -13,7 +15,7 @@ class HoldsControllerTest < ActionDispatch::IntegrationTest test "creates hold for an item and starts hold" do assert_difference("@item.holds.count") do - post account_holds_url, params: {item_id: @item.id} + post account_holds_url, params: { item_id: @item.id } end assert_redirected_to item_url(@item.id) @@ -26,13 +28,13 @@ class HoldsControllerTest < ActionDispatch::IntegrationTest create(:hold, item: @item) assert_difference("@item.holds.count") do - post account_holds_url, params: {item_id: @item.id} + post account_holds_url, params: { item_id: @item.id } end assert_redirected_to item_url(@item.id) hold = @item.holds.last - refute hold.started? + assert_not hold.started? end end end diff --git a/test/controllers/account/home_controller_test.rb b/test/controllers/account/home_controller_test.rb index f4758f519..cf2ac5483 100644 --- a/test/controllers/account/home_controller_test.rb +++ b/test/controllers/account/home_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" module Account @@ -45,7 +47,7 @@ class HomeControllerTest < ActionDispatch::IntegrationTest get account_home_url assert_match "some good news", response.body - refute_match "some old news", response.body + assert_no_match "some old news", response.body end end end diff --git a/test/controllers/account/loans_controller_test.rb b/test/controllers/account/loans_controller_test.rb index 69d482298..dc7c30c82 100644 --- a/test/controllers/account/loans_controller_test.rb +++ b/test/controllers/account/loans_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" module Account @@ -18,7 +20,7 @@ class LoansControllerTest < ActionDispatch::IntegrationTest assert_response :success assert_match @loan.item.complete_number, response.body - refute_match @others_loan.item.complete_number, response.body + assert_no_match @others_loan.item.complete_number, response.body end test "displays a member's current loans" do @@ -30,8 +32,8 @@ class LoansControllerTest < ActionDispatch::IntegrationTest assert_response :success assert_match @loan.item.complete_number, response.body - refute_match @others_loan.item.complete_number, response.body - refute_match @ended_loan.item.complete_number, response.body + assert_no_match @others_loan.item.complete_number, response.body + assert_no_match @ended_loan.item.complete_number, response.body end end end diff --git a/test/controllers/account/members_controller_test.rb b/test/controllers/account/members_controller_test.rb index 05cefe94f..e166ac820 100644 --- a/test/controllers/account/members_controller_test.rb +++ b/test/controllers/account/members_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" module Account @@ -21,13 +23,13 @@ class MembersControllerTest < ActionDispatch::IntegrationTest end test "member updates profile" do - patch account_member_url, params: {member: {full_name: "Updated Name"}} + patch account_member_url, params: { member: { full_name: "Updated Name" } } assert_redirected_to account_member_url assert_equal "Updated Name", @member.full_name end test "member update redirects to edit when provided invalid params" do - patch account_member_url, params: {member: {full_name: nil}} + patch account_member_url, params: { member: { full_name: nil } } assert_template :edit end end diff --git a/test/controllers/account/password_controller_test.rb b/test/controllers/account/password_controller_test.rb index c8369dabe..db6d8e171 100644 --- a/test/controllers/account/password_controller_test.rb +++ b/test/controllers/account/password_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" module Account @@ -23,13 +25,13 @@ class PasswordsControllerTest < ActionDispatch::IntegrationTest end test "member updates password" do - put account_password_url, params: {user: @user_password_edit} + put account_password_url, params: { user: @user_password_edit } assert_redirected_to account_member_url end test "member enters mismatched password" do @user_password_edit[:password_confirmation] = "mismatched" - put account_password_url, params: {user: @user_password_edit} + put account_password_url, params: { user: @user_password_edit } assert_redirected_to edit_account_password_url assert @user.errors.full_messages.include?("Password confirmation doesn't match Password") end @@ -37,14 +39,14 @@ class PasswordsControllerTest < ActionDispatch::IntegrationTest test "member enters short password" do @user_password_edit[:password] = "short" @user_password_edit[:password_confirmation] = "short" - put account_password_url, params: {user: @user_password_edit} + put account_password_url, params: { user: @user_password_edit } assert_redirected_to edit_account_password_url assert @user.errors.full_messages.include?("Password is too short (minimum is 6 characters)") end test "member enters incorrect current password" do @user_password_edit[:current_password] = "wrong_password" - put account_password_url, params: {user: @user_password_edit} + put account_password_url, params: { user: @user_password_edit } assert_redirected_to edit_account_password_url assert @user.errors.full_messages.include?("Current password is invalid") end diff --git a/test/controllers/account/renewal_requests_controller_test.rb b/test/controllers/account/renewal_requests_controller_test.rb index 23405858f..a1fb6f59e 100644 --- a/test/controllers/account/renewal_requests_controller_test.rb +++ b/test/controllers/account/renewal_requests_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" module Account @@ -15,8 +17,8 @@ class RenewalRequestsControllerTest < ActionDispatch::IntegrationTest test "member can request renewal for loans" do borrow_policy = create(:default_borrow_policy) - item = create(:item, borrow_policy: borrow_policy) - loan = create(:loan, member: @member, item: item) + item = create(:item, borrow_policy:) + loan = create(:loan, member: @member, item:) post account_renewal_requests_url(loan_id: loan) assert_redirected_to account_loans_url diff --git a/test/controllers/account/renewals_controller_test.rb b/test/controllers/account/renewals_controller_test.rb index 6aa3e6825..d2e7ec7a4 100644 --- a/test/controllers/account/renewals_controller_test.rb +++ b/test/controllers/account/renewals_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" module Account @@ -15,8 +17,8 @@ class RenewalsControllerTest < ActionDispatch::IntegrationTest test "member can renew their renewable loans" do borrow_policy = create(:member_renewable_borrow_policy) - item = create(:item, borrow_policy: borrow_policy) - loan = create(:loan, member: @member, item: item) + item = create(:item, borrow_policy:) + loan = create(:loan, member: @member, item:) post account_renewals_url(loan_id: loan) assert_redirected_to account_home_url diff --git a/test/controllers/admin/appointment_checkins_controller_test.rb b/test/controllers/admin/appointment_checkins_controller_test.rb index 1ff57580a..952fae144 100644 --- a/test/controllers/admin/appointment_checkins_controller_test.rb +++ b/test/controllers/admin/appointment_checkins_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "application_system_test_case" module Admin @@ -16,7 +18,7 @@ class AppointmentCheckinsControllerTest < ActionDispatch::IntegrationTest end test "returns a single item" do - post admin_appointment_checkins_path(@appointment), params: {loan_ids: [@loan.id]} + post admin_appointment_checkins_path(@appointment), params: { loan_ids: [@loan.id] } assert_enqueued_emails 0 end end diff --git a/test/controllers/admin/appointment_completions_controller_test.rb b/test/controllers/admin/appointment_completions_controller_test.rb index 91defab98..d9a7f1fdb 100644 --- a/test/controllers/admin/appointment_completions_controller_test.rb +++ b/test/controllers/admin/appointment_completions_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "application_system_test_case" module Admin diff --git a/test/controllers/admin/appointments_controller_test.rb b/test/controllers/admin/appointments_controller_test.rb index fa148620a..600dd2760 100644 --- a/test/controllers/admin/appointments_controller_test.rb +++ b/test/controllers/admin/appointments_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "application_system_test_case" module Admin @@ -23,7 +25,7 @@ class AppointmentsControllerTest < ActionDispatch::IntegrationTest test "index page includes links to item and member" do day = @appointment.starts_at.strftime("%F") - get admin_appointments_path(day: day) + get admin_appointments_path(day:) assert_select "a[href=?]", admin_item_path(@hold.item) assert_select "a[href=?]", admin_member_path(@appointment.member) @@ -33,7 +35,7 @@ class AppointmentsControllerTest < ActionDispatch::IntegrationTest starts_at = Time.current ends_at = starts_at + 2.hours - put admin_appointment_path(@appointment), params: {appointment: {time_range_string: "#{starts_at}..#{ends_at}"}} + put admin_appointment_path(@appointment), params: { appointment: { time_range_string: "#{starts_at}..#{ends_at}" } } assert_redirected_to admin_appointments_url @appointment.reload diff --git a/test/controllers/admin/borrow_policies_controller_test.rb b/test/controllers/admin/borrow_policies_controller_test.rb index 64b490c44..e6ad7415f 100644 --- a/test/controllers/admin/borrow_policies_controller_test.rb +++ b/test/controllers/admin/borrow_policies_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" module Admin @@ -23,14 +25,14 @@ class BorrowPoliciesControllerTest < ActionDispatch::IntegrationTest test "should redirect to admin borrow policies page" do @borrow_policy = create(:default_borrow_policy) - patch admin_borrow_policy_url(@borrow_policy), params: {borrow_policy: {duration: @borrow_policy.duration, fine_cents: @borrow_policy.fine_cents, fine_period: @borrow_policy.fine_period, name: @borrow_policy.name, code: "Q"}} + patch admin_borrow_policy_url(@borrow_policy), params: { borrow_policy: { duration: @borrow_policy.duration, fine_cents: @borrow_policy.fine_cents, fine_period: @borrow_policy.fine_period, name: @borrow_policy.name, code: "Q" } } assert_redirected_to admin_borrow_policies_url end test "should update borrow_policy" do @borrow_policy = create(:default_borrow_policy) - patch admin_borrow_policy_url(@borrow_policy), params: {borrow_policy: {duration: 10, fine: 8.23, fine_period: 26, name: "New name", code: "Q", member_renewable: true}} + patch admin_borrow_policy_url(@borrow_policy), params: { borrow_policy: { duration: 10, fine: 8.23, fine_period: 26, name: "New name", code: "Q", member_renewable: true } } @borrow_policy.reload assert_equal 10, @borrow_policy.duration diff --git a/test/controllers/admin/bulk_renewals_controller_test.rb b/test/controllers/admin/bulk_renewals_controller_test.rb index adf1553ea..b48c4d70c 100644 --- a/test/controllers/admin/bulk_renewals_controller_test.rb +++ b/test/controllers/admin/bulk_renewals_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" module Admin diff --git a/test/controllers/admin/categories_controller_test.rb b/test/controllers/admin/categories_controller_test.rb index bfdedf968..8afe0a48b 100644 --- a/test/controllers/admin/categories_controller_test.rb +++ b/test/controllers/admin/categories_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" module Admin @@ -22,7 +24,7 @@ class CategoriesControllerTest < ActionDispatch::IntegrationTest test "should create category" do assert_difference("Category.count") do - post admin_categories_url, params: {category: {name: "New Category"}} + post admin_categories_url, params: { category: { name: "New Category" } } end assert_redirected_to admin_categories_url(anchor: "category_#{Category.last.id}") @@ -34,7 +36,7 @@ class CategoriesControllerTest < ActionDispatch::IntegrationTest end test "should update category" do - patch admin_category_url(@category), params: {category: {name: @category.name, slug: @category.slug}} + patch admin_category_url(@category), params: { category: { name: @category.name, slug: @category.slug } } assert_redirected_to admin_categories_url(anchor: "category_#{@category.id}") end diff --git a/test/controllers/admin/dashboard_controller_test.rb b/test/controllers/admin/dashboard_controller_test.rb index d65c07b8c..dc522d3d2 100644 --- a/test/controllers/admin/dashboard_controller_test.rb +++ b/test/controllers/admin/dashboard_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class Admin::DashboardControllerTest < ActionDispatch::IntegrationTest diff --git a/test/controllers/admin/documents_controller_test.rb b/test/controllers/admin/documents_controller_test.rb index e4540765e..fe9751eca 100644 --- a/test/controllers/admin/documents_controller_test.rb +++ b/test/controllers/admin/documents_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" module Admin @@ -26,7 +28,7 @@ class DocumentsControllerTest < ActionDispatch::IntegrationTest end test "should update document" do - patch admin_document_url(@document), params: {document: {body: @document.body, name: @document.name, summary: @document.summary}} + patch admin_document_url(@document), params: { document: { body: @document.body, name: @document.name, summary: @document.summary } } assert_redirected_to admin_document_url(@document) end end diff --git a/test/controllers/admin/gift_memberships_controller_test.rb b/test/controllers/admin/gift_memberships_controller_test.rb index 080ae26a5..7c82c6699 100644 --- a/test/controllers/admin/gift_memberships_controller_test.rb +++ b/test/controllers/admin/gift_memberships_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" module Admin diff --git a/test/controllers/admin/hold_loans_controller_test.rb b/test/controllers/admin/hold_loans_controller_test.rb index ed035cb2c..b5e8751e5 100644 --- a/test/controllers/admin/hold_loans_controller_test.rb +++ b/test/controllers/admin/hold_loans_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" module Admin diff --git a/test/controllers/admin/hold_requests_controller_test.rb b/test/controllers/admin/hold_requests_controller_test.rb index 7af986094..93f9250c5 100644 --- a/test/controllers/admin/hold_requests_controller_test.rb +++ b/test/controllers/admin/hold_requests_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class Admin::HoldRequestsControllerTest < ActionDispatch::IntegrationTest diff --git a/test/controllers/admin/items/tickets_controller_test.rb b/test/controllers/admin/items/tickets_controller_test.rb index d46ee795d..8c67dca4c 100644 --- a/test/controllers/admin/items/tickets_controller_test.rb +++ b/test/controllers/admin/items/tickets_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" module Admin @@ -29,7 +31,7 @@ class TicketsControllerTest < ActionDispatch::IntegrationTest test "should create ticket" do assert_difference("Ticket.count") do - post admin_item_tickets_url(@item), params: {ticket: {status: "assess", title: "A ticket title", body: "A ticket body"}} + post admin_item_tickets_url(@item), params: { ticket: { status: "assess", title: "A ticket title", body: "A ticket body" } } end assert_redirected_to admin_item_ticket_url(@item, Ticket.last) @@ -55,7 +57,7 @@ class TicketsControllerTest < ActionDispatch::IntegrationTest test "should update ticket" do @ticket = create(:ticket, item: @item) - patch admin_item_ticket_url(@item, @ticket), params: {ticket: {status: "parts", time_spent: "15", body: "Waiting on parts"}} + patch admin_item_ticket_url(@item, @ticket), params: { ticket: { status: "parts", time_spent: "15", body: "Waiting on parts" } } assert_redirected_to admin_item_ticket_url(@item, @ticket) end diff --git a/test/controllers/admin/items_controller_test.rb b/test/controllers/admin/items_controller_test.rb index 8fbd4816e..f45328097 100644 --- a/test/controllers/admin/items_controller_test.rb +++ b/test/controllers/admin/items_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" module Admin @@ -22,7 +24,7 @@ class ItemsControllerTest < ActionDispatch::IntegrationTest test "should create item" do assert_difference("Item.count") do - post admin_items_url, params: {item: {brand: @item.brand, description: @item.description, model: @item.model, name: @item.name, serial: @item.serial, size: @item.size, strength: @item.strength, power_source: @item.power_source, borrow_policy_id: @item.borrow_policy_id}} + post admin_items_url, params: { item: { brand: @item.brand, description: @item.description, model: @item.model, name: @item.name, serial: @item.serial, size: @item.size, strength: @item.strength, power_source: @item.power_source, borrow_policy_id: @item.borrow_policy_id } } end assert_redirected_to admin_item_number_url(Item.last) @@ -39,7 +41,7 @@ class ItemsControllerTest < ActionDispatch::IntegrationTest end test "should update item" do - patch admin_item_url(@item), params: {item: {brand: @item.brand, description: @item.description, model: @item.model, name: @item.name, serial: @item.serial, size: @item.size, power_source: @item.power_source, borrow_policy_id: @item.borrow_policy_id}} + patch admin_item_url(@item), params: { item: { brand: @item.brand, description: @item.description, model: @item.model, name: @item.name, serial: @item.serial, size: @item.size, power_source: @item.power_source, borrow_policy_id: @item.borrow_policy_id } } assert_redirected_to admin_item_url(@item) end diff --git a/test/controllers/admin/items_in_maintenance_controller_test.rb b/test/controllers/admin/items_in_maintenance_controller_test.rb index cf3fa18f9..5efe69df6 100644 --- a/test/controllers/admin/items_in_maintenance_controller_test.rb +++ b/test/controllers/admin/items_in_maintenance_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class Admin::ItemInMaintenanceControllerTest < ActionDispatch::IntegrationTest diff --git a/test/controllers/admin/loan_summaries_controller_test.rb b/test/controllers/admin/loan_summaries_controller_test.rb index 8b8a6ca3a..238820c0e 100644 --- a/test/controllers/admin/loan_summaries_controller_test.rb +++ b/test/controllers/admin/loan_summaries_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" module Admin diff --git a/test/controllers/admin/loans_controller_test.rb b/test/controllers/admin/loans_controller_test.rb index 96ceafa5d..54df40d39 100644 --- a/test/controllers/admin/loans_controller_test.rb +++ b/test/controllers/admin/loans_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" module Admin @@ -18,7 +20,7 @@ class LoansControllerTest < ActionDispatch::IntegrationTest test "should create loan" do member = create(:member) assert_difference("Loan.count") do - post admin_loans_url, params: {loan: {item_id: @item.id, member_id: member.id}} + post admin_loans_url, params: { loan: { item_id: @item.id, member_id: member.id } } end assert_redirected_to admin_member_url(member, anchor: "loan_#{Loan.last.id}") @@ -27,12 +29,12 @@ class LoansControllerTest < ActionDispatch::IntegrationTest test "should return item by updating loan" do @loan = create(:loan, item: @item) assert_enqueued_emails 0 do - patch admin_loan_url(@loan), params: {loan: {ended: "1"}} + patch admin_loan_url(@loan), params: { loan: { ended: "1" } } end assert_redirected_to admin_member_url(@loan.member, anchor: "loan_#{@loan.id}") @loan.reload - refute flash[:checkout_error] + assert_not flash[:checkout_error] assert @loan.ended_at.present? end @@ -40,7 +42,7 @@ class LoansControllerTest < ActionDispatch::IntegrationTest @loan = create(:loan, item: @item) @renewal_request = create(:renewal_request, loan: @loan) - patch admin_loan_url(@loan), params: {loan: {ended: "1"}} + patch admin_loan_url(@loan), params: { loan: { ended: "1" } } assert_equal RenewalRequest.statuses[:rejected], @renewal_request.reload.status end @@ -48,18 +50,18 @@ class LoansControllerTest < ActionDispatch::IntegrationTest test "should return item by updating loan for an overdue item" do @loan = create(:loan, item: @item, due_at: 8.days.ago) assert_enqueued_emails 0 do - patch admin_loan_url(@loan), params: {loan: {ended: "1"}} + patch admin_loan_url(@loan), params: { loan: { ended: "1" } } end assert_redirected_to admin_member_url(@loan.member, anchor: "loan_#{@loan.id}") @loan.reload - refute flash[:checkout_error] + assert_not flash[:checkout_error] assert @loan.ended_at.present? end test "should undo a return by marking as not ended" do ended_loan = create(:ended_loan) - patch admin_loan_url(ended_loan), params: {loan: {ended: "0"}} + patch admin_loan_url(ended_loan), params: { loan: { ended: "0" } } assert_redirected_to admin_member_url(ended_loan.member, anchor: "loan_#{ended_loan.id}") ended_loan.reload diff --git a/test/controllers/admin/members/appointments_controller_test.rb b/test/controllers/admin/members/appointments_controller_test.rb index 1415d0143..c11ebff1f 100644 --- a/test/controllers/admin/members/appointments_controller_test.rb +++ b/test/controllers/admin/members/appointments_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" module Admin @@ -16,7 +18,7 @@ class AppointmentsControllerTest < ActionDispatch::IntegrationTest ends_at = starts_at + 2.hours assert_difference("member.appointments.count", 1) do - post admin_member_appointments_path(member), params: {appointment: {time_range_string: "#{starts_at}..#{ends_at}"}} + post admin_member_appointments_path(member), params: { appointment: { time_range_string: "#{starts_at}..#{ends_at}" } } end assert_redirected_to admin_appointment_path(member.reload.appointments.last) end diff --git a/test/controllers/admin/members/holds_controller_test.rb b/test/controllers/admin/members/holds_controller_test.rb index 596b263b2..4f591028b 100644 --- a/test/controllers/admin/members/holds_controller_test.rb +++ b/test/controllers/admin/members/holds_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" module Admin @@ -12,7 +14,7 @@ class HoldsControllerTest < ActionDispatch::IntegrationTest test "should lend a hold to a member" do member = create(:member) - hold = create(:hold, member: member, creator: @admin_user) + hold = create(:hold, member:, creator: @admin_user) assert_difference("member.holds.active.count", -1) do post lend_admin_member_hold_url(member, hold) @@ -25,7 +27,7 @@ class HoldsControllerTest < ActionDispatch::IntegrationTest item = create(:item) assert_difference("member.holds.active.count") do - post admin_member_holds_url(member), params: {hold: {item_id: item.id}} + post admin_member_holds_url(member), params: { hold: { item_id: item.id } } end hold = member.holds.last @@ -35,27 +37,27 @@ class HoldsControllerTest < ActionDispatch::IntegrationTest test "places a hold and does not start when item is unavailable" do member = create(:verified_member) item = create(:item) - create(:loan, item: item) + create(:loan, item:) assert_difference("member.holds.active.count") do - post admin_member_holds_url(member), params: {hold: {item_id: item.id}} + post admin_member_holds_url(member), params: { hold: { item_id: item.id } } end hold = member.holds.last - refute hold.started? + assert_not hold.started? end test "places a hold and does not start when item has other holds" do member = create(:verified_member) item = create(:item) - create(:hold, item: item) + create(:hold, item:) assert_difference("member.holds.active.count") do - post admin_member_holds_url(member), params: {hold: {item_id: item.id}} + post admin_member_holds_url(member), params: { hold: { item_id: item.id } } end hold = member.holds.last - refute hold.started? + assert_not hold.started? end end end diff --git a/test/controllers/admin/members_controller_test.rb b/test/controllers/admin/members_controller_test.rb index 31dc7ee71..112fab586 100644 --- a/test/controllers/admin/members_controller_test.rb +++ b/test/controllers/admin/members_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" module Admin @@ -53,7 +55,7 @@ class MembersControllerTest < ActionDispatch::IntegrationTest end test "should update member" do - patch admin_member_url(@member), params: {member: {address_verified: @member.address_verified, other_id_kind: @member.other_id_kind, email: @member.email, full_name: @member.full_name, id_kind: @member.id_kind, notes: @member.notes, phone_number: @member.phone_number, preferred_name: @member.preferred_name, postal_code: "60606"}} + patch admin_member_url(@member), params: { member: { address_verified: @member.address_verified, other_id_kind: @member.other_id_kind, email: @member.email, full_name: @member.full_name, id_kind: @member.id_kind, notes: @member.notes, phone_number: @member.phone_number, preferred_name: @member.preferred_name, postal_code: "60606" } } assert_redirected_to admin_member_url(@member) end end diff --git a/test/controllers/admin/memberships_controller_test.rb b/test/controllers/admin/memberships_controller_test.rb index fbab68576..94cdbbadf 100644 --- a/test/controllers/admin/memberships_controller_test.rb +++ b/test/controllers/admin/memberships_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" module Admin @@ -21,7 +23,7 @@ class MembershipsControllerTest < ActionDispatch::IntegrationTest post admin_member_memberships_url(@member), params: { membership_form: { amount_dollars: 12, - payment_source: payment_source, + payment_source:, with_payment: "true", start_membership: "1" } @@ -32,7 +34,7 @@ class MembershipsControllerTest < ActionDispatch::IntegrationTest membership = @member.memberships.last membership_adjustment, payment_adjustment = @member.adjustments.to_a[-2, 2] - refute membership.pending? + assert_not membership.pending? assert_equal membership, membership_adjustment.adjustable assert_equal Money.new(-1200), membership_adjustment.amount @@ -54,7 +56,7 @@ class MembershipsControllerTest < ActionDispatch::IntegrationTest post admin_member_memberships_url(@member), params: { membership_form: { amount_dollars: 12, - payment_source: payment_source, + payment_source:, with_payment: "true", start_membership: "0" } @@ -77,7 +79,7 @@ class MembershipsControllerTest < ActionDispatch::IntegrationTest assert_response :redirect membership = @member.memberships.last - refute membership.pending? + assert_not membership.pending? end test "creates new pending membership without payment" do diff --git a/test/controllers/admin/notes_controller_test.rb b/test/controllers/admin/notes_controller_test.rb index 349d0bc7b..1e43ad7d1 100644 --- a/test/controllers/admin/notes_controller_test.rb +++ b/test/controllers/admin/notes_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class Admin::NotesControllerTest < ActionDispatch::IntegrationTest @@ -14,23 +16,23 @@ class Admin::NotesControllerTest < ActionDispatch::IntegrationTest test "should create a note for a member" do assert_equal 0, @member_1.notes.length - post admin_member_notes_path(@member_1), params: {note: {body: "hello"}} + post admin_member_notes_path(@member_1), params: { note: { body: "hello" } } assert_equal 1, @member_1.reload.notes.length assert_redirected_to [:admin, @member_1, anchor: dom_id(@member_1.notes[0])] end test "should update a note for a member" do assert_equal 0, @member_1.notes.length - post admin_member_notes_path(@member_1), params: {note: {body: "hello"}} + post admin_member_notes_path(@member_1), params: { note: { body: "hello" } } assert_equal 1, @member_1.reload.notes.length - patch "/admin/members/#{@member_1.id}/notes/#{@member_1.notes[0].id}", params: {note: {body: "updated"}} + patch "/admin/members/#{@member_1.id}/notes/#{@member_1.notes[0].id}", params: { note: { body: "updated" } } assert_equal 1, @member_1.reload.notes.length assert_redirected_to [:admin, @member_1, anchor: dom_id(@member_1.notes[0])] end test "should delete a note for a member" do assert_equal 0, @member_1.notes.length - post admin_member_notes_path(@member_1), params: {note: {body: "hello"}} + post admin_member_notes_path(@member_1), params: { note: { body: "hello" } } assert_equal 1, @member_1.reload.notes.length delete "/admin/members/#{@member_1.id}/notes/#{@member_1.notes[0].id}" assert_redirected_to [:admin, @member_1] diff --git a/test/controllers/admin/renewal_requests_controller_test.rb b/test/controllers/admin/renewal_requests_controller_test.rb index a2723460f..a94107e03 100644 --- a/test/controllers/admin/renewal_requests_controller_test.rb +++ b/test/controllers/admin/renewal_requests_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" module Admin @@ -26,7 +28,7 @@ class RenewalRequestsControllerTest < ActionDispatch::IntegrationTest assert_response :redirect assert @renewal_request.reload.approved? - refute @renewal_request.loan.checked_out? + assert_not @renewal_request.loan.checked_out? end test "rejects a renewal" do @@ -53,7 +55,7 @@ class RenewalRequestsControllerAdditionalTest < ActionDispatch::IntegrationTest test "renews an already renewed loan on approval" do item = create(:item) - loan = create(:loan, item: item) + loan = create(:loan, item:) renewed_loan = renew_loan(loan) renewal_request = create(:renewal_request, loan: renewed_loan) @@ -66,14 +68,14 @@ class RenewalRequestsControllerAdditionalTest < ActionDispatch::IntegrationTest assert_response :redirect assert renewal_request.reload.approved? - refute renewal_request.loan.checked_out? + assert_not renewal_request.loan.checked_out? end test "does not renew an item that has been checked in" do item = create(:item) - loan = create(:loan, item: item) + loan = create(:loan, item:) - renewal_request = create(:renewal_request, loan: loan) + renewal_request = create(:renewal_request, loan:) return_loan(loan) assert item.reload.available? @@ -86,7 +88,7 @@ class RenewalRequestsControllerAdditionalTest < ActionDispatch::IntegrationTest assert_response :redirect end - refute renewal_request.reload.approved? + assert_not renewal_request.reload.approved? assert item.reload.available? end end diff --git a/test/controllers/admin/renewals_controller_test.rb b/test/controllers/admin/renewals_controller_test.rb index af956140a..570f4f362 100644 --- a/test/controllers/admin/renewals_controller_test.rb +++ b/test/controllers/admin/renewals_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" module Admin @@ -30,7 +32,7 @@ class RenewalsControllerTest < ActionDispatch::IntegrationTest assert_equal @loan.item_id, @renewal.item_id assert_equal @loan.member_id, @renewal.member_id assert_equal @loan.ended_at, @renewal.created_at - refute @renewal.ended_at + assert_not @renewal.ended_at end test "should delete renewal" do @@ -45,7 +47,7 @@ class RenewalsControllerTest < ActionDispatch::IntegrationTest @loan.reload - refute @loan.ended_at + assert_not @loan.ended_at assert_equal 0, @loan.renewals.count end end diff --git a/test/controllers/admin/reports/items_without_image_controller_test.rb b/test/controllers/admin/reports/items_without_image_controller_test.rb index 9edc214ac..058e306df 100644 --- a/test/controllers/admin/reports/items_without_image_controller_test.rb +++ b/test/controllers/admin/reports/items_without_image_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" module Admin diff --git a/test/controllers/admin/reports/member_requests_controller_test.rb b/test/controllers/admin/reports/member_requests_controller_test.rb index 583c5368a..22773fac7 100644 --- a/test/controllers/admin/reports/member_requests_controller_test.rb +++ b/test/controllers/admin/reports/member_requests_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" module Admin diff --git a/test/controllers/admin/reports/memberships_controller_test.rb b/test/controllers/admin/reports/memberships_controller_test.rb index ea2bb0dfc..dea324d54 100644 --- a/test/controllers/admin/reports/memberships_controller_test.rb +++ b/test/controllers/admin/reports/memberships_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" module Admin diff --git a/test/controllers/admin/reports/monthly_activities_controller_test.rb b/test/controllers/admin/reports/monthly_activities_controller_test.rb index e06a5286c..782bb631b 100644 --- a/test/controllers/admin/reports/monthly_activities_controller_test.rb +++ b/test/controllers/admin/reports/monthly_activities_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" module Admin diff --git a/test/controllers/admin/reports/monthly_adjustments_controller_test.rb b/test/controllers/admin/reports/monthly_adjustments_controller_test.rb index 939598502..2fecc65ae 100644 --- a/test/controllers/admin/reports/monthly_adjustments_controller_test.rb +++ b/test/controllers/admin/reports/monthly_adjustments_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" module Admin diff --git a/test/controllers/admin/reports/potential_volunteers_controller_test.rb b/test/controllers/admin/reports/potential_volunteers_controller_test.rb index ccfc6bd12..8f914f2c4 100644 --- a/test/controllers/admin/reports/potential_volunteers_controller_test.rb +++ b/test/controllers/admin/reports/potential_volunteers_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" module Admin diff --git a/test/controllers/admin/reports/requests_controller_test.rb b/test/controllers/admin/reports/requests_controller_test.rb index a12697f47..f6ff58982 100644 --- a/test/controllers/admin/reports/requests_controller_test.rb +++ b/test/controllers/admin/reports/requests_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" module Admin diff --git a/test/controllers/admin/reports/shifts_controller_test.rb b/test/controllers/admin/reports/shifts_controller_test.rb index 97eb3da84..f93775fbc 100644 --- a/test/controllers/admin/reports/shifts_controller_test.rb +++ b/test/controllers/admin/reports/shifts_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" module Admin diff --git a/test/controllers/admin/searches_controller_test.rb b/test/controllers/admin/searches_controller_test.rb index a23d8acd3..e14b572e5 100644 --- a/test/controllers/admin/searches_controller_test.rb +++ b/test/controllers/admin/searches_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" module Admin diff --git a/test/controllers/admin/ui_controller_test.rb b/test/controllers/admin/ui_controller_test.rb index 48209d69d..d2c04dadb 100644 --- a/test/controllers/admin/ui_controller_test.rb +++ b/test/controllers/admin/ui_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" module Admin @@ -12,7 +14,7 @@ class UIControllerTest < ActionDispatch::IntegrationTest test "autocompletes item names" do ["impact hammer", "Impact hammer", "Impact wrench", "hammer drill"].each do |name| - Item.create!(name: name, borrow_policy: @borrow_policy) + Item.create!(name:, borrow_policy: @borrow_policy) end get admin_ui_names_url(q: "im") @@ -23,7 +25,7 @@ class UIControllerTest < ActionDispatch::IntegrationTest test "autocompletes item brands" do ["Dewalt", "Delta", "ACDelco", "Dremel"].each do |brand| - Item.create!(name: "Tool name", brand: brand, borrow_policy: @borrow_policy) + Item.create!(name: "Tool name", brand:, borrow_policy: @borrow_policy) end get admin_ui_brands_url(q: "de") diff --git a/test/controllers/admin/users_controller_test.rb b/test/controllers/admin/users_controller_test.rb index ce3b4aecc..048e68cc3 100644 --- a/test/controllers/admin/users_controller_test.rb +++ b/test/controllers/admin/users_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" module Admin @@ -23,7 +25,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest test "should create user" do assert_difference("User.count") do - post admin_users_url, params: {user: {email: "new.user@example.com", role: "staff"}} + post admin_users_url, params: { user: { email: "new.user@example.com", role: "staff" } } end assert_redirected_to admin_users_url @@ -50,7 +52,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest test "should update user" do user = create(:user) - patch admin_user_url(user), params: {user: {email: "modified@example.com", role: "admin"}} + patch admin_user_url(user), params: { user: { email: "modified@example.com", role: "admin" } } assert_redirected_to admin_users_url user.reload @@ -62,7 +64,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest test "should not allow escalating to super_admin" do user = create(:user) - patch admin_user_url(user), params: {user: {email: "modified@example.com", role: "super_admin"}} + patch admin_user_url(user), params: { user: { email: "modified@example.com", role: "super_admin" } } assert_redirected_to admin_users_url user.reload @@ -77,7 +79,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest user = create(:user) - patch admin_user_url(user), params: {user: {email: "modified@example.com", role: "super_admin"}} + patch admin_user_url(user), params: { user: { email: "modified@example.com", role: "super_admin" } } assert_redirected_to admin_users_url user.reload diff --git a/test/controllers/admin/verifications_controller_test.rb b/test/controllers/admin/verifications_controller_test.rb index 64a1dbad8..0b9b5fbb5 100644 --- a/test/controllers/admin/verifications_controller_test.rb +++ b/test/controllers/admin/verifications_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class VerificationsControllerTest < ActionDispatch::IntegrationTest diff --git a/test/controllers/application_controller_test.rb b/test/controllers/application_controller_test.rb index f2fb68554..39aaa3649 100644 --- a/test/controllers/application_controller_test.rb +++ b/test/controllers/application_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class ApplicationControllerTest < ActionDispatch::IntegrationTest @@ -20,24 +22,24 @@ class ApplicationControllerTest < ActionDispatch::IntegrationTest end test "should redirect to previous page for admin after login if there is a referer" do - get new_user_session_path, headers: {referer: "http://www.example.com/original-page"} - post user_session_path, params: {user: {email: @admin_user.email, password: "password"}} + get new_user_session_path, headers: { referer: "http://www.example.com/original-page" } + post user_session_path, params: { user: { email: @admin_user.email, password: "password" } } assert_redirected_to "http://www.example.com/original-page" end test "should redirect to previous page for member after login if there is a referer" do - get new_user_session_path, headers: {referer: "http://www.example.com/items/1"} - post user_session_path, params: {user: {email: @user.email, password: "password"}} + get new_user_session_path, headers: { referer: "http://www.example.com/items/1" } + post user_session_path, params: { user: { email: @user.email, password: "password" } } assert_redirected_to "http://www.example.com/items/1" end test "should not redirect to previous page for member after login if referer is not of the same domain" do - get new_user_session_path, headers: {referer: "http://www.foreigndomain.com/circulate"} - post user_session_path, params: {user: {email: @user.email, password: "password"}} + get new_user_session_path, headers: { referer: "http://www.foreigndomain.com/circulate" } + post user_session_path, params: { user: { email: @user.email, password: "password" } } assert_redirected_to account_home_path end test "ignores a poorly formed referer" do - get new_user_session_path, headers: {referer: "not a valid referer"} + get new_user_session_path, headers: { referer: "not a valid referer" } end end diff --git a/test/controllers/concerns/lending_test.rb b/test/controllers/concerns/lending_test.rb index 246d7bcef..a4cc47d22 100644 --- a/test/controllers/concerns/lending_test.rb +++ b/test/controllers/concerns/lending_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class LendingTest < ActiveSupport::TestCase @@ -5,10 +7,10 @@ class LendingTest < ActiveSupport::TestCase test "renews a loan" do borrow_policy = create(:borrow_policy, duration: 7) - item = create(:item, borrow_policy: borrow_policy) + item = create(:item, borrow_policy:) sunday = Time.utc(2020, 1, 26).end_of_day - loan = create(:loan, item: item, created_at: (sunday - 7.days), due_at: sunday, uniquely_numbered: true) + loan = create(:loan, item:, created_at: (sunday - 7.days), due_at: sunday, uniquely_numbered: true) renewal = Loan.stub(:open_days, [0, 4]) { assert_difference("Loan.count") { renew_loan(loan, now: sunday) } @@ -24,10 +26,10 @@ class LendingTest < ActiveSupport::TestCase test "renews a loan for a full period starting today" do borrow_policy = create(:borrow_policy, duration: 7) - item = create(:item, borrow_policy: borrow_policy) + item = create(:item, borrow_policy:) sunday = Time.utc(2020, 1, 26).end_of_day - loan = create(:loan, item: item, created_at: (sunday - 17.days), due_at: (sunday - 10.days), uniquely_numbered: true) + loan = create(:loan, item:, created_at: (sunday - 17.days), due_at: (sunday - 10.days), uniquely_numbered: true) renewal = Loan.stub(:open_days, [0, 4]) { renew_loan(loan, now: sunday) } @@ -37,11 +39,11 @@ class LendingTest < ActiveSupport::TestCase test "renews a loan for a full period starting at due date" do borrow_policy = create(:borrow_policy, duration: 7) - item = create(:item, borrow_policy: borrow_policy) + item = create(:item, borrow_policy:) sunday = Time.utc(2020, 1, 26).end_of_day thursday = Time.utc(2020, 1, 30).end_of_day - loan = create(:loan, item: item, created_at: (thursday - 7.days), due_at: thursday, uniquely_numbered: true) + loan = create(:loan, item:, created_at: (thursday - 7.days), due_at: thursday, uniquely_numbered: true) renewal = Loan.stub(:open_days, [0, 4]) { renew_loan(loan, now: sunday) } @@ -51,11 +53,11 @@ class LendingTest < ActiveSupport::TestCase test "renews a loan due tomorrow" do borrow_policy = create(:borrow_policy, duration: 7) - item = create(:item, borrow_policy: borrow_policy) + item = create(:item, borrow_policy:) wednesday = Time.utc(2020, 1, 29).end_of_day thursday = Time.utc(2020, 1, 30).end_of_day - loan = create(:loan, item: item, created_at: (thursday - 7.days), due_at: thursday) + loan = create(:loan, item:, created_at: (thursday - 7.days), due_at: thursday) renewal = Loan.stub(:open_days, [0, 4]) { renew_loan(loan, now: wednesday) } @@ -68,11 +70,11 @@ class LendingTest < ActiveSupport::TestCase test "renews a renewal" do borrow_policy = create(:borrow_policy, duration: 7) - item = create(:item, borrow_policy: borrow_policy) + item = create(:item, borrow_policy:) sunday = Time.utc(2020, 1, 26).end_of_day monday = Time.utc(2020, 1, 27).end_of_day - loan = create(:loan, item: item, created_at: (sunday - 7.days), due_at: sunday, uniquely_numbered: true) + loan = create(:loan, item:, created_at: (sunday - 7.days), due_at: sunday, uniquely_numbered: true) assert loan.renewable? renewal = Loan.stub(:open_days, [0, 4]) { @@ -91,23 +93,23 @@ class LendingTest < ActiveSupport::TestCase test "can't renew past limit" do borrow_policy = create(:borrow_policy, duration: 7, renewal_limit: 1) - item = create(:item, borrow_policy: borrow_policy) + item = create(:item, borrow_policy:) sunday = Time.utc(2020, 1, 26).end_of_day - loan = create(:loan, item: item, created_at: (sunday - 7.days), due_at: sunday, uniquely_numbered: true) + loan = create(:loan, item:, created_at: (sunday - 7.days), due_at: sunday, uniquely_numbered: true) renewal = Loan.stub(:open_days, [0, 4]) { renew_loan(loan, now: sunday) } - refute renewal.renewable? + assert_not renewal.renewable? end test "updates appointment loans to point to the renewal" do borrow_policy = create(:borrow_policy, duration: 7) - item = create(:item, borrow_policy: borrow_policy) + item = create(:item, borrow_policy:) sunday = Time.utc(2020, 1, 26).end_of_day - loan = create(:loan, item: item, created_at: (sunday - 7.days), due_at: sunday, uniquely_numbered: true) + loan = create(:loan, item:, created_at: (sunday - 7.days), due_at: sunday, uniquely_numbered: true) appointment = create(:appointment, member: loan.member, loans: [loan]) appointment_loan = appointment.appointment_loans.first @@ -125,10 +127,10 @@ class LendingTest < ActiveSupport::TestCase test "restores appointment loan to previous loan when reverted" do borrow_policy = create(:borrow_policy, duration: 7) - item = create(:item, borrow_policy: borrow_policy) + item = create(:item, borrow_policy:) sunday = Time.utc(2020, 1, 26).end_of_day - loan = create(:loan, item: item, created_at: (sunday - 7.days), due_at: sunday, uniquely_numbered: true) + loan = create(:loan, item:, created_at: (sunday - 7.days), due_at: sunday, uniquely_numbered: true) appointment = create(:appointment, member: loan.member, loans: [loan]) appointment_loan = appointment.appointment_loans.first @@ -148,10 +150,10 @@ class LendingTest < ActiveSupport::TestCase test "reverts a renewal" do borrow_policy = create(:borrow_policy, duration: 7) - item = create(:item, borrow_policy: borrow_policy) + item = create(:item, borrow_policy:) sunday = Time.utc(2020, 1, 26).end_of_day - loan = create(:loan, item: item, created_at: (sunday - 7.days), due_at: sunday, uniquely_numbered: true) + loan = create(:loan, item:, created_at: (sunday - 7.days), due_at: sunday, uniquely_numbered: true) renewal = Loan.stub(:open_days, [0, 4]) { renew_loan(loan, now: sunday) } @@ -161,17 +163,17 @@ class LendingTest < ActiveSupport::TestCase end loan.reload - refute loan.ended_at + assert_not loan.ended_at - refute Loan.exists?(renewal.id) + assert_not Loan.exists?(renewal.id) end test "reverts a renewed renewal" do borrow_policy = create(:borrow_policy, duration: 7) - item = create(:item, borrow_policy: borrow_policy) + item = create(:item, borrow_policy:) sunday = Time.utc(2020, 1, 26).end_of_day - loan = create(:loan, item: item, created_at: (sunday - 7.days), due_at: sunday, uniquely_numbered: true) + loan = create(:loan, item:, created_at: (sunday - 7.days), due_at: sunday, uniquely_numbered: true) renewal = Loan.stub(:open_days, [0, 4]) { renew_loan(loan, now: sunday) } second_renewal = Loan.stub(:open_days, [0, 4]) { renew_loan(renewal, now: sunday) } @@ -180,15 +182,15 @@ class LendingTest < ActiveSupport::TestCase end renewal.reload - refute renewal.ended_at + assert_not renewal.ended_at assert loan.ended_at - refute Loan.exists?(second_renewal.id) + assert_not Loan.exists?(second_renewal.id) end test "returns a loan with a deleted item" do item = create(:item) - loan = create(:loan, item: item) + loan = create(:loan, item:) assert item.destroy @@ -199,7 +201,7 @@ class LendingTest < ActiveSupport::TestCase test "renews a loan with a deleted item" do item = create(:item) - loan = create(:loan, item: item) + loan = create(:loan, item:) assert item.destroy @@ -210,7 +212,7 @@ class LendingTest < ActiveSupport::TestCase test "automatically returns consumable items" do borrow_policy = create(:consumable_borrow_policy) - item = create(:item, quantity: 10, borrow_policy: borrow_policy) + item = create(:item, quantity: 10, borrow_policy:) member = create(:verified_member) loan = assert_no_difference "Audited::Audit.count" do @@ -224,7 +226,7 @@ class LendingTest < ActiveSupport::TestCase test "restores consumable quantity when undoing a loan" do borrow_policy = create(:consumable_borrow_policy) - item = create(:item, quantity: 10, borrow_policy: borrow_policy) + item = create(:item, quantity: 10, borrow_policy:) member = create(:verified_member) loan = create_loan(item, member) @@ -235,7 +237,7 @@ class LendingTest < ActiveSupport::TestCase test "marks the item as retired when the quantity hits 0" do borrow_policy = create(:consumable_borrow_policy) - item = create(:item, quantity: 1, borrow_policy: borrow_policy) + item = create(:item, quantity: 1, borrow_policy:) member = create(:verified_member) assert_difference "Audited::Audit.count" do @@ -249,7 +251,7 @@ class LendingTest < ActiveSupport::TestCase test "restores consumable quantity and status when undoing a loan that exhausted the item" do borrow_policy = create(:consumable_borrow_policy) - item = create(:item, quantity: 1, borrow_policy: borrow_policy) + item = create(:item, quantity: 1, borrow_policy:) member = create(:verified_member) loan = create_loan(item, member) diff --git a/test/controllers/concerns/page_attributes_test.rb b/test/controllers/concerns/page_attributes_test.rb index 040b40bc7..cd123760a 100644 --- a/test/controllers/concerns/page_attributes_test.rb +++ b/test/controllers/concerns/page_attributes_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class PageAttributesTest < ActiveSupport::TestCase @@ -15,6 +17,6 @@ def self.helper_method(_name) test "handles attributes that aren't set" do assert_nil page_attr(:title) - refute page_attr?(:title) + assert_not page_attr?(:title) end end diff --git a/test/controllers/documents_controller_test.rb b/test/controllers/documents_controller_test.rb index a490a3687..5bff96549 100644 --- a/test/controllers/documents_controller_test.rb +++ b/test/controllers/documents_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class DocumentsControllerTest < ActionDispatch::IntegrationTest diff --git a/test/controllers/errors_controller_test.rb b/test/controllers/errors_controller_test.rb index 8711402ab..6658f89c2 100644 --- a/test/controllers/errors_controller_test.rb +++ b/test/controllers/errors_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class ErrorsControllerTest < ActionDispatch::IntegrationTest diff --git a/test/controllers/items_controller_test.rb b/test/controllers/items_controller_test.rb index a780b113a..2f31f4f9e 100644 --- a/test/controllers/items_controller_test.rb +++ b/test/controllers/items_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class ItemsControllerTest < ActionDispatch::IntegrationTest @@ -42,7 +44,7 @@ class ItemsControllerTest < ActionDispatch::IntegrationTest [:retired, :pending].each do |status| test "doesn't display the show page for a #{status} item" do - hidden_item = create(:item, status: status) + hidden_item = create(:item, status:) assert_raises ActiveRecord::RecordNotFound do get item_url(hidden_item) @@ -51,21 +53,21 @@ class ItemsControllerTest < ActionDispatch::IntegrationTest test "hides #{status} items from the item index" do available_item = create(:item) - hidden_item = create(:item, status: status) + hidden_item = create(:item, status:) get items_url assert_match available_item.complete_number, @response.body - refute_match hidden_item.complete_number, @response.body + assert_no_match hidden_item.complete_number, @response.body end test "hides #{status} items from the item index for a category" do category = create(:category) - hidden_item = create(:item, status: status, categories: [category]) + hidden_item = create(:item, status:, categories: [category]) - get items_url(category: category) + get items_url(category:) - refute_match hidden_item.complete_number, @response.body + assert_no_match hidden_item.complete_number, @response.body end end end diff --git a/test/controllers/short_links_controller_test.rb b/test/controllers/short_links_controller_test.rb index 2e9550133..a35174f93 100644 --- a/test/controllers/short_links_controller_test.rb +++ b/test/controllers/short_links_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class ShortLinksControllerTest < ActionDispatch::IntegrationTest diff --git a/test/controllers/signup/payments_controller_test.rb b/test/controllers/signup/payments_controller_test.rb index afb7c7fc5..f218c18fa 100644 --- a/test/controllers/signup/payments_controller_test.rb +++ b/test/controllers/signup/payments_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" module Signup @@ -29,7 +31,7 @@ class PaymentsControllerTest < ActionDispatch::IntegrationTest }] SquareCheckout.stub :new, mock_checkout do - post signup_payments_url, params: {membership_payment_form: {amount_dollars: "12"}} + post signup_payments_url, params: { membership_payment_form: { amount_dollars: "12" } } end assert_redirected_to "https://squareup.com/checkout/12345" @@ -42,13 +44,13 @@ class PaymentsControllerTest < ActionDispatch::IntegrationTest test "fails to create a checkout_url" do mock_result = Minitest::Mock.new mock_result.expect :success?, false - mock_result.expect :error, [{code: "SOMETHING_WENT_WRONG"}] + mock_result.expect :error, [{ code: "SOMETHING_WENT_WRONG" }] mock_checkout = Minitest::Mock.new mock_checkout.expect :checkout_url, mock_result, [Hash] SquareCheckout.stub :new, mock_checkout do - post signup_payments_url, params: {membership_payment_form: {amount_dollars: "12"}} + post signup_payments_url, params: { membership_payment_form: { amount_dollars: "12" } } end assert_redirected_to "http://www.example.com/signup/payments/new" @@ -73,13 +75,13 @@ class PaymentsControllerTest < ActionDispatch::IntegrationTest SquareCheckout.stub :new, mock_checkout do assert_difference "Membership.count" => 1, "Adjustment.count" => 2 do - get callback_signup_payments_url, params: {transactionId: "abcd1234"} + get callback_signup_payments_url, params: { transactionId: "abcd1234" } end end assert_redirected_to signup_confirmation_url assert_equal 1234, session[:amount] - refute session[:member_id] + assert_not session[:member_id] assert_mock mock_result assert_mock mock_checkout @@ -88,14 +90,14 @@ class PaymentsControllerTest < ActionDispatch::IntegrationTest test "failed callback invocation" do mock_result = Minitest::Mock.new mock_result.expect :success?, false - mock_result.expect :error, [{code: "ERROR_CODE"}] + mock_result.expect :error, [{ code: "ERROR_CODE" }] mock_checkout = Minitest::Mock.new mock_checkout.expect :fetch_transaction, mock_result, [Hash] SquareCheckout.stub :new, mock_checkout do assert_no_difference ["Membership.count", "Adjustment.count"] do - get callback_signup_payments_url, params: {transactionId: "abcd1234"} + get callback_signup_payments_url, params: { transactionId: "abcd1234" } end end @@ -111,14 +113,14 @@ class PaymentsControllerTest < ActionDispatch::IntegrationTest test "failed callback invocation by not finding a transaction" do mock_result = Minitest::Mock.new mock_result.expect :success?, false - mock_result.expect :error, [{code: "NOT_FOUND"}] + mock_result.expect :error, [{ code: "NOT_FOUND" }] mock_checkout = Minitest::Mock.new mock_checkout.expect :fetch_transaction, mock_result, [Hash] SquareCheckout.stub :new, mock_checkout do assert_no_difference ["Membership.count", "Adjustment.count"] do - get callback_signup_payments_url, params: {transactionId: "abcd1234"} + get callback_signup_payments_url, params: { transactionId: "abcd1234" } end end @@ -135,13 +137,13 @@ class PaymentsControllerTest < ActionDispatch::IntegrationTest 11.times do |i| mock_result = Minitest::Mock.new mock_result.expect :success?, false - mock_result.expect :error, [{code: "NOT_FOUND"}] + mock_result.expect :error, [{ code: "NOT_FOUND" }] mock_checkout = Minitest::Mock.new mock_checkout.expect :fetch_transaction, mock_result, [Hash] SquareCheckout.stub :new, mock_checkout do - get callback_signup_payments_url, params: {transactionId: "abcd1234"} + get callback_signup_payments_url, params: { transactionId: "abcd1234" } end assert_mock mock_result @@ -153,7 +155,7 @@ class PaymentsControllerTest < ActionDispatch::IntegrationTest else assert_redirected_to "http://www.example.com/signup/confirmation" assert_match(/There was an error processing your payment/, flash[:error]) - refute session[:attempts] + assert_not session[:attempts] end end end diff --git a/test/controllers/super_admin/libraries_controller_test.rb b/test/controllers/super_admin/libraries_controller_test.rb index 0cfe83352..cc567216a 100644 --- a/test/controllers/super_admin/libraries_controller_test.rb +++ b/test/controllers/super_admin/libraries_controller_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" module SuperAdmin @@ -23,7 +25,7 @@ class LibrariesControllerTest < ActionDispatch::IntegrationTest test "should create library" do assert_difference("Library.count") do - post super_admin_libraries_url, params: {library: attributes_for(:library)} + post super_admin_libraries_url, params: { library: attributes_for(:library) } end assert_redirected_to super_admin_libraries_url @@ -40,7 +42,7 @@ class LibrariesControllerTest < ActionDispatch::IntegrationTest end test "should update item" do - patch super_admin_library_url(@library), params: {library: {name: "Bronze Tools Library", hostname: "bronze.example.com"}} + patch super_admin_library_url(@library), params: { library: { name: "Bronze Tools Library", hostname: "bronze.example.com" } } assert_redirected_to super_admin_library_url(@library) end @@ -69,10 +71,10 @@ def assert_access_denied(&block) assert_access_denied { get super_admin_libraries_url } assert_access_denied { get new_super_admin_library_url } - assert_access_denied { post super_admin_libraries_url, params: {library: {name: "Library", hostname: "library.example.com"}} } + assert_access_denied { post super_admin_libraries_url, params: { library: { name: "Library", hostname: "library.example.com" } } } assert_access_denied { get super_admin_library_url(library) } assert_access_denied { get edit_super_admin_library_url(library) } - assert_access_denied { patch super_admin_library_url(library), params: {library: {name: "Library", hostname: "library.example.com"}} } + assert_access_denied { patch super_admin_library_url(library), params: { library: { name: "Library", hostname: "library.example.com" } } } assert_access_denied { delete super_admin_library_url(library) } end end diff --git a/test/factories/adjustments.rb b/test/factories/adjustments.rb index 5b67efe4a..70cfff31f 100644 --- a/test/factories/adjustments.rb +++ b/test/factories/adjustments.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + FactoryBot.define do factory :adjustment do amount_cents { -100 } diff --git a/test/factories/appointment_holds.rb b/test/factories/appointment_holds.rb index affa85519..3b1791c02 100644 --- a/test/factories/appointment_holds.rb +++ b/test/factories/appointment_holds.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + FactoryBot.define do factory :appointment_hold do appointment diff --git a/test/factories/appointment_loans.rb b/test/factories/appointment_loans.rb index 370346d63..0c2df4b80 100644 --- a/test/factories/appointment_loans.rb +++ b/test/factories/appointment_loans.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + FactoryBot.define do factory :appointment_loan do appointment diff --git a/test/factories/appointments.rb b/test/factories/appointments.rb index ee8d70e12..68d766092 100644 --- a/test/factories/appointments.rb +++ b/test/factories/appointments.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + FactoryBot.define do factory :appointment do starts_at { "2020-09-23 11:14:27" } diff --git a/test/factories/borrow_policies.rb b/test/factories/borrow_policies.rb index 12857ff83..ff8169c47 100644 --- a/test/factories/borrow_policies.rb +++ b/test/factories/borrow_policies.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + FactoryBot.define do factory :borrow_policy do library { Library.first || create(:library) } diff --git a/test/factories/categories.rb b/test/factories/categories.rb index 20fae7c19..f9fe82dfd 100644 --- a/test/factories/categories.rb +++ b/test/factories/categories.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + FactoryBot.define do factory :category do library { Library.first || create(:library) } diff --git a/test/factories/documents.rb b/test/factories/documents.rb index e05ed15f4..d6e4f078c 100644 --- a/test/factories/documents.rb +++ b/test/factories/documents.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + FactoryBot.define do factory :document do library { Library.first || create(:library) } diff --git a/test/factories/events.rb b/test/factories/events.rb index d58471cb9..06758425e 100644 --- a/test/factories/events.rb +++ b/test/factories/events.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + FactoryBot.define do sequence :calendar_event_id do |n| "CALEVENTID#{n}" diff --git a/test/factories/gift_memberships.rb b/test/factories/gift_memberships.rb index 1bc6ca44f..98ba986fa 100644 --- a/test/factories/gift_memberships.rb +++ b/test/factories/gift_memberships.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + FactoryBot.define do factory :gift_membership do library { Library.first || create(:library) } diff --git a/test/factories/holds.rb b/test/factories/holds.rb index aabd5c898..9fc6b8f57 100644 --- a/test/factories/holds.rb +++ b/test/factories/holds.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + FactoryBot.define do factory :hold do library { Library.first || create(:library) } diff --git a/test/factories/item_attachments.rb b/test/factories/item_attachments.rb index dad27e0e0..d7b04a2ba 100644 --- a/test/factories/item_attachments.rb +++ b/test/factories/item_attachments.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + FactoryBot.define do factory :item_attachment do kind { "manual" } diff --git a/test/factories/items.rb b/test/factories/items.rb index b06098f14..6376e3093 100644 --- a/test/factories/items.rb +++ b/test/factories/items.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + FactoryBot.define do sequence :number, 1000 diff --git a/test/factories/libraries.rb b/test/factories/libraries.rb index 5d006b3db..8a2e79ca7 100644 --- a/test/factories/libraries.rb +++ b/test/factories/libraries.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + FactoryBot.define do factory :library do name { "Library of Alexandria" } diff --git a/test/factories/library_updates.rb b/test/factories/library_updates.rb index 001c5547a..dac192471 100644 --- a/test/factories/library_updates.rb +++ b/test/factories/library_updates.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + FactoryBot.define do factory :library_update do title { "for internal use" } diff --git a/test/factories/loans.rb b/test/factories/loans.rb index ba01fb7e4..b2215726d 100644 --- a/test/factories/loans.rb +++ b/test/factories/loans.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + FactoryBot.define do factory :loan do library { Library.first || create(:library) } diff --git a/test/factories/maintenance_reports.rb b/test/factories/maintenance_reports.rb index 7647ab4e0..5f1ed9a36 100644 --- a/test/factories/maintenance_reports.rb +++ b/test/factories/maintenance_reports.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + FactoryBot.define do factory :maintenance_report do title { "Update on this item" } diff --git a/test/factories/members.rb b/test/factories/members.rb index 2a924a7f4..6239da6cb 100644 --- a/test/factories/members.rb +++ b/test/factories/members.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + FactoryBot.define do sequence :email do |n| "person#{n}@example.com" @@ -34,7 +36,7 @@ factory :verified_member_with_membership do after(:create) do |member, evaluator| - create_list(:membership, 1, member: member) + create_list(:membership, 1, member:) end end end diff --git a/test/factories/memberships.rb b/test/factories/memberships.rb index ae90bbf3c..8d42316db 100644 --- a/test/factories/memberships.rb +++ b/test/factories/memberships.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + FactoryBot.define do factory :membership do library { Library.first || create(:library) } diff --git a/test/factories/notes.rb b/test/factories/notes.rb index 749b542f9..75900a7cc 100644 --- a/test/factories/notes.rb +++ b/test/factories/notes.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + FactoryBot.define do factory :note do association :creator, factory: :user diff --git a/test/factories/notifications.rb b/test/factories/notifications.rb index 0c6a5e4cd..741277d7d 100644 --- a/test/factories/notifications.rb +++ b/test/factories/notifications.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + FactoryBot.define do factory :notification do library { Library.first || create(:library) } diff --git a/test/factories/renewal_requests.rb b/test/factories/renewal_requests.rb index a8f2891f5..8b637fc59 100644 --- a/test/factories/renewal_requests.rb +++ b/test/factories/renewal_requests.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + FactoryBot.define do factory :renewal_request do loan diff --git a/test/factories/short_links.rb b/test/factories/short_links.rb index f198c69a0..cafd88485 100644 --- a/test/factories/short_links.rb +++ b/test/factories/short_links.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + FactoryBot.define do factory :short_link do library { Library.first || create(:library) } diff --git a/test/factories/tickets.rb b/test/factories/tickets.rb index cdce8c254..e1fe4df68 100644 --- a/test/factories/tickets.rb +++ b/test/factories/tickets.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + FactoryBot.define do factory :ticket do library { Library.first || create(:library) } diff --git a/test/factories/users.rb b/test/factories/users.rb index b1d5c6dd0..d3ba379e1 100644 --- a/test/factories/users.rb +++ b/test/factories/users.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + FactoryBot.define do factory :user do library { Library.first || create(:library) } diff --git a/test/forms/extend_holds_form_test.rb b/test/forms/extend_holds_form_test.rb index 15069e522..10485b82e 100644 --- a/test/forms/extend_holds_form_test.rb +++ b/test/forms/extend_holds_form_test.rb @@ -1,27 +1,29 @@ +# frozen_string_literal: true + require "test_helper" class ExtendHoldsFormTest < ActiveSupport::TestCase test "invalid when date is blank" do form = ExtendHoldsForm.new - refute form.valid? + assert_not form.valid? assert_equal ["must be a date within the next month"], form.errors[:date] end test "invalid with invalid date" do form = ExtendHoldsForm.new(date: "invalid date") - refute form.valid? + assert_not form.valid? assert_equal ["must be a date within the next month"], form.errors[:date] end test "invalid with past date" do form = ExtendHoldsForm.new(date: 1.day.ago.to_date.iso8601) - refute form.valid? + assert_not form.valid? assert_equal ["must be a date within the next month"], form.errors[:date] end test "invalid with far future date" do form = ExtendHoldsForm.new(date: 32.days.since.to_date.iso8601) - refute form.valid? + assert_not form.valid? assert_equal ["must be a date within the next month"], form.errors[:date] end diff --git a/test/forms/gift_membership_redemption_form_test.rb b/test/forms/gift_membership_redemption_form_test.rb index bbfd6ec0f..4b2fc2119 100644 --- a/test/forms/gift_membership_redemption_form_test.rb +++ b/test/forms/gift_membership_redemption_form_test.rb @@ -1,23 +1,25 @@ +# frozen_string_literal: true + require "test_helper" class GiftMembershipRedemptionFormTest < ActiveSupport::TestCase test "invalid when a code doesn't exist" do redemption = GiftMembershipRedemptionForm.new(code: "ABCD1234") - refute redemption.valid? + assert_not redemption.valid? assert_equal ["is not a valid code"], redemption.errors[:code] end test "invalid without a code" do redemption = GiftMembershipRedemptionForm.new - refute redemption.valid? + assert_not redemption.valid? assert_equal ["is not a valid code"], redemption.errors[:code] end test "invalid when a code has already been used" do membership = create(:membership) - gift_membership = create(:gift_membership, membership: membership) + gift_membership = create(:gift_membership, membership:) redemption = GiftMembershipRedemptionForm.new(code: gift_membership.code.value) - refute redemption.valid? + assert_not redemption.valid? assert_equal ["has already been redeemed"], redemption.errors[:code] end diff --git a/test/helpers/ensure_request_tenant.rb b/test/helpers/ensure_request_tenant.rb index 3d6b6cb24..56da8ad47 100644 --- a/test/helpers/ensure_request_tenant.rb +++ b/test/helpers/ensure_request_tenant.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module EnsureRequestTenant def self.included(base) base.setup do diff --git a/test/helpers/holds_helper_test.rb b/test/helpers/holds_helper_test.rb index ac8d2325e..ec014a1d1 100644 --- a/test/helpers/holds_helper_test.rb +++ b/test/helpers/holds_helper_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class HoldsHelperTest < ActionView::TestCase diff --git a/test/helpers/items_helper_test.rb b/test/helpers/items_helper_test.rb index 5a824d7b4..3962ec162 100644 --- a/test/helpers/items_helper_test.rb +++ b/test/helpers/items_helper_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class ItemsHelperTest < ActionView::TestCase @@ -41,7 +43,7 @@ def @image.variant(options) "#{filename}?#{options.to_query}" end - assert_equal "tool-image.jpg?#{{resize_to_limit: [80, 90], rotate: 90}.to_query}", + assert_equal "tool-image.jpg?#{{ resize_to_limit: [80, 90], rotate: 90 }.to_query}", item_image_url(@image, resize_to_limit: [80, 90]) end @@ -88,7 +90,7 @@ class ItemStatusTest < ItemsHelperTest test "item status for a checked out uniquely numbered item" do item = create(:item) - create(:loan, item: item) + create(:loan, item:) item.reload assert_equal ["label-warning", "Checked Out"], css_class_and_status_label(item) @@ -96,7 +98,7 @@ class ItemStatusTest < ItemsHelperTest test "item status for an overdue uniquely numbered item" do item = create(:item) - create(:overdue_loan, item: item) + create(:overdue_loan, item:) item.reload assert_equal ["label-error", "Overdue"], css_class_and_status_label(item) @@ -104,7 +106,7 @@ class ItemStatusTest < ItemsHelperTest test "item status for a uniquely numbered item with a hold" do item = create(:item) - create(:hold, item: item) + create(:hold, item:) item.reload assert_equal ["label-warning", "On Hold"], css_class_and_status_label(item) @@ -117,7 +119,7 @@ class ItemStatusTest < ItemsHelperTest [:pending, :retired].each do |status| test "item status for an uniquely numbered item with status #{status}" do - item = create(:item, status: status) + item = create(:item, status:) assert_equal ["", "Unavailable"], css_class_and_status_label(item) end end @@ -130,7 +132,7 @@ class ItemStatusTest < ItemsHelperTest test "item status for a checked out unnumbered item" do item = create(:uncounted_item) - create(:nonexclusive_loan, item: item) + create(:nonexclusive_loan, item:) item.reload assert_equal ["label-success", "Available"], css_class_and_status_label(item) @@ -138,7 +140,7 @@ class ItemStatusTest < ItemsHelperTest test "item status for an unnumbered item with a hold" do item = create(:uncounted_item) - create(:hold, item: item) + create(:hold, item:) item.reload assert_equal ["label-success", "Available"], css_class_and_status_label(item) @@ -151,7 +153,7 @@ class ItemStatusTest < ItemsHelperTest [:pending, :retired].each do |status| test "item status for an unnumbered item with status #{status}" do - item = create(:uncounted_item, status: status) + item = create(:uncounted_item, status:) assert_equal ["", "Unavailable"], css_class_and_status_label(item) end end diff --git a/test/helpers/loans_helper_test.rb b/test/helpers/loans_helper_test.rb index 3fa71c3d6..99136ecd4 100644 --- a/test/helpers/loans_helper_test.rb +++ b/test/helpers/loans_helper_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class LoansHelperTest < ActionView::TestCase diff --git a/test/helpers/return_values.rb b/test/helpers/return_values.rb index dba97761a..1919eeb5c 100644 --- a/test/helpers/return_values.rb +++ b/test/helpers/return_values.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Used when stubbing a methods that needs to return a sequence of different values to subsequent calls: # Thing.stub :name, ReturnValues.new("sharon", "bob") do # Thing.name => "sharon" diff --git a/test/helpers/shifts_helper_test.rb b/test/helpers/shifts_helper_test.rb index 6a49b6ebf..44c42eb70 100644 --- a/test/helpers/shifts_helper_test.rb +++ b/test/helpers/shifts_helper_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class ShiftsHelperTest < ActionView::TestCase diff --git a/test/lib/activity_notifier_test.rb b/test/lib/activity_notifier_test.rb index 51855ba29..a7c0d9afe 100644 --- a/test/lib/activity_notifier_test.rb +++ b/test/lib/activity_notifier_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class ActivityNotifierTest < ActiveSupport::TestCase @@ -18,15 +20,15 @@ class ActivityNotifierTest < ActiveSupport::TestCase end end - refute ActionMailer::Base.deliveries.empty? + assert_not ActionMailer::Base.deliveries.empty? mail = ActionMailer::Base.deliveries.find { |delivery| delivery.to == [loan.member.email] } - refute mail.nil? + assert_not mail.nil? assert_equal "Today's loan summary", mail.subject assert_includes mail.encoded, loan.item.complete_number assert_includes mail.encoded, loan2.item.complete_number - refute_includes mail.encoded, "return all overdue items as soon as possible" + assert_not_includes mail.encoded, "return all overdue items as soon as possible" end test "sends emails to folks who have items due on the following day" do @@ -152,7 +154,7 @@ class ActivityNotifierTest < ActiveSupport::TestCase loans = Time.use_zone("America/Chicago") { days.times.map do |i| - create(:nonexclusive_loan, item: item, due_at: Time.current.end_of_day - i.days, created_at: 1.week.ago) + create(:nonexclusive_loan, item:, due_at: Time.current.end_of_day - i.days, created_at: 1.week.ago) end } @@ -177,7 +179,7 @@ def black_hole.respond_to_missing?(*args) if i % 7 == 0 assert mailer_call else - refute mailer_call + assert_not mailer_call end end end @@ -185,20 +187,20 @@ def black_hole.respond_to_missing?(*args) test "only mentions items that are checked out or returned that day" do returned_today = create(:loan, due_at: 1.day.ago, created_at: 8.days.ago, ended_at: Time.current) member = returned_today.member - checked_out_today = create(:loan, member: member, due_at: 7.days.since) - previous_loan = create(:ended_loan, member: member) + checked_out_today = create(:loan, member:, due_at: 7.days.since) + previous_loan = create(:ended_loan, member:) Time.use_zone("America/Chicago") do notifier = ActivityNotifier.new notifier.send_daily_loan_summaries end - refute ActionMailer::Base.deliveries.empty? + assert_not ActionMailer::Base.deliveries.empty? mail = ActionMailer::Base.deliveries.find { |delivery| delivery.to == [member.email] } assert_includes mail.encoded, returned_today.item.complete_number assert_includes mail.encoded, checked_out_today.item.complete_number - refute_includes mail.encoded, previous_loan.item.complete_number + assert_not_includes mail.encoded, previous_loan.item.complete_number end test "sends emails to folks with rejected renewal requests" do @@ -213,19 +215,19 @@ def black_hole.respond_to_missing?(*args) assert return_loan(loan) end - create(:renewal_request, loan: loan, status: :rejected) + create(:renewal_request, loan:, status: :rejected) notifier = ActivityNotifier.new notifier.send_daily_loan_summaries end - refute ActionMailer::Base.deliveries.empty? + assert_not ActionMailer::Base.deliveries.empty? mail = ActionMailer::Base.deliveries.find { |delivery| delivery.to == [loan.member.email] } - refute mail.nil? + assert_not mail.nil? assert_equal "Today's loan summary", mail.subject assert_includes mail.encoded, loan.item.complete_number - refute_includes mail.encoded, "rejected" + assert_not_includes mail.encoded, "rejected" end end diff --git a/test/lib/certificate/generator_test.rb b/test/lib/certificate/generator_test.rb index 804e5c7bc..abb65f75f 100644 --- a/test/lib/certificate/generator_test.rb +++ b/test/lib/certificate/generator_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" module Certificate diff --git a/test/lib/item_exporter_test.rb b/test/lib/item_exporter_test.rb index f0b381f12..389b31f7c 100644 --- a/test/lib/item_exporter_test.rb +++ b/test/lib/item_exporter_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class ItemExporterTest < ActiveSupport::TestCase diff --git a/test/lib/manual_import_test.rb b/test/lib/manual_import_test.rb index 929ba734f..95aa0b31e 100644 --- a/test/lib/manual_import_test.rb +++ b/test/lib/manual_import_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class ManualImportTest < ActiveSupport::TestCase @@ -21,13 +23,13 @@ class ManualImportTest < ActiveSupport::TestCase test "is invalid without a URL" do manual_import = ManualImport.new(url: "not a real url") - refute manual_import.valid? + assert_not manual_import.valid? assert_equal ["must be a valid URL"], manual_import.errors[:url] end test "is invalid when a file isn't found at the URL", :remote do manual_import = ManualImport.new(url: "http://not.a.real.website/some/file.pdf") - refute manual_import.valid? + assert_not manual_import.valid? assert_equal ["could not be loaded"], manual_import.errors[:url] end end diff --git a/test/lib/map/chicago_test.rb b/test/lib/map/chicago_test.rb index f43626e9a..8ea6e6d86 100644 --- a/test/lib/map/chicago_test.rb +++ b/test/lib/map/chicago_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" module Map @@ -19,7 +21,7 @@ class ChicagoTest < ActiveSupport::TestCase 101 => 22, 103 => 30 } - map = Chicago.new(values, svg: svg, fill: "red") + map = Chicago.new(values, svg:, fill: "red") assert_equal <<~XML, map.to_xml diff --git a/test/lib/member_exporter_test.rb b/test/lib/member_exporter_test.rb index 2ceda5f96..690271535 100644 --- a/test/lib/member_exporter_test.rb +++ b/test/lib/member_exporter_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class MemberExporterTest < ActiveSupport::TestCase diff --git a/test/lib/neon_test.rb b/test/lib/neon_test.rb index 89b703478..b0e937303 100644 --- a/test/lib/neon_test.rb +++ b/test/lib/neon_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" require "json" diff --git a/test/lib/open_days_test.rb b/test/lib/open_days_test.rb index 413991365..d27f36d56 100644 --- a/test/lib/open_days_test.rb +++ b/test/lib/open_days_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class OpenDaysTest < ActiveSupport::TestCase diff --git a/test/lib/result_test.rb b/test/lib/result_test.rb index e040831f5..faf1014fa 100644 --- a/test/lib/result_test.rb +++ b/test/lib/result_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class ResultTest < ActiveSupport::TestCase @@ -5,7 +7,7 @@ class ResultTest < ActiveSupport::TestCase result = Result.success("🎉") assert result.success? - refute result.failure? + assert_not result.failure? assert_equal "🎉", result.value end @@ -14,7 +16,7 @@ class ResultTest < ActiveSupport::TestCase result = Result.failure("something bad happened") assert result.failure? - refute result.success? + assert_not result.success? assert_equal "something bad happened", result.error assert_nil result.value diff --git a/test/lib/square_checkout_test.rb b/test/lib/square_checkout_test.rb index c275d293a..d3eaab036 100644 --- a/test/lib/square_checkout_test.rb +++ b/test/lib/square_checkout_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class SquareCheckoutTest < ActiveSupport::TestCase @@ -116,7 +118,7 @@ class SquareCheckoutTest < ActiveSupport::TestCase idempotency_key: "test" ) - refute result.success? + assert_not result.success? assert_equal "ERRORS", result.error end @@ -129,7 +131,7 @@ class SquareCheckoutTest < ActiveSupport::TestCase member = create(:member) mock_body_transaction = Minitest::Mock.new - mock_body_transaction.expect :[], [{amount_money: {amount: 1200, currency: "USD"}}], [:tenders] + mock_body_transaction.expect :[], [{ amount_money: { amount: 1200, currency: "USD" } }], [:tenders] mock_body = Minitest::Mock.new mock_body.expect :transaction, mock_body_transaction @@ -139,14 +141,14 @@ class SquareCheckoutTest < ActiveSupport::TestCase mock_response.expect :body, mock_body mock_transactions = Minitest::Mock.new - mock_transactions.expect :retrieve_transaction, mock_response, [{location_id: "SQ_LOCATION_ID", transaction_id: "transaction_1"}] + mock_transactions.expect :retrieve_transaction, mock_response, [{ location_id: "SQ_LOCATION_ID", transaction_id: "transaction_1" }] mock_client = Minitest::Mock.new mock_client.expect :transactions, mock_transactions Square::Client.stub :new, mock_client do checkout = SquareCheckout.new(access_token: "SQ_ACCESS_TOKEN", location_id: "SQ_LOCATION_ID") - result = checkout.fetch_transaction(member: member, transaction_id: "transaction_1") + result = checkout.fetch_transaction(member:, transaction_id: "transaction_1") assert result.success? assert_equal Money.new(1200), result.value @@ -167,14 +169,14 @@ class SquareCheckoutTest < ActiveSupport::TestCase mock_response.expect :errors, "ERRORS" mock_transactions = Minitest::Mock.new - mock_transactions.expect :retrieve_transaction, mock_response, [{location_id: "SQ_LOCATION_ID", transaction_id: "transaction_1"}] + mock_transactions.expect :retrieve_transaction, mock_response, [{ location_id: "SQ_LOCATION_ID", transaction_id: "transaction_1" }] mock_client = Minitest::Mock.new mock_client.expect :transactions, mock_transactions Square::Client.stub :new, mock_client do checkout = SquareCheckout.new(access_token: "SQ_ACCESS_TOKEN", location_id: "SQ_LOCATION_ID") - result = checkout.fetch_transaction(member: member, transaction_id: "transaction_1") + result = checkout.fetch_transaction(member:, transaction_id: "transaction_1") assert result.failure? assert_equal "ERRORS", result.error diff --git a/test/mailers/member_mailer_test.rb b/test/mailers/member_mailer_test.rb index 2816af463..03c9426ec 100644 --- a/test/mailers/member_mailer_test.rb +++ b/test/mailers/member_mailer_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class MemberMailerTest < ActionMailer::TestCase @@ -10,11 +12,11 @@ class MemberMailerTest < ActionMailer::TestCase [:approved, :rejected].each do |status| test "renders renewal request #{status} email for a renewed loan" do item = create(:item, :with_image) - loan = create(:loan, item: item) + loan = create(:loan, item:) renewed_loan = renew_loan(loan) - renewal_request = create(:renewal_request, loan: renewed_loan, status: status) + renewal_request = create(:renewal_request, loan: renewed_loan, status:) - email = MemberMailer.with(renewal_request: renewal_request).renewal_request_updated + email = MemberMailer.with(renewal_request:).renewal_request_updated assert_emails 1 do email.deliver_later end @@ -22,10 +24,10 @@ class MemberMailerTest < ActionMailer::TestCase test "renders renewal request #{status} email for the first loan" do item = create(:item, :with_image) - loan = create(:loan, item: item) - renewal_request = create(:renewal_request, loan: loan, status: status) + loan = create(:loan, item:) + renewal_request = create(:renewal_request, loan:, status:) - email = MemberMailer.with(renewal_request: renewal_request).renewal_request_updated + email = MemberMailer.with(renewal_request:).renewal_request_updated assert_emails 1 do email.deliver_later end diff --git a/test/mailers/previews/gift_purchaser_mailer_preview.rb b/test/mailers/previews/gift_purchaser_mailer_preview.rb index 36aa563a7..f63492553 100644 --- a/test/mailers/previews/gift_purchaser_mailer_preview.rb +++ b/test/mailers/previews/gift_purchaser_mailer_preview.rb @@ -1,7 +1,9 @@ +# frozen_string_literal: true + # Preview all emails at http://localhost:3000/rails/mailers/member_mailer class GiftPurchaserMailerPreview < ActionMailer::Preview def confirmation gift_membership = GiftMembership.last! - GiftPurchaserMailer.with(gift_membership: gift_membership).confirmation + GiftPurchaserMailer.with(gift_membership:).confirmation end end diff --git a/test/mailers/previews/homepage_mailer_preview.rb b/test/mailers/previews/homepage_mailer_preview.rb index 4a0666788..dea7a20c3 100644 --- a/test/mailers/previews/homepage_mailer_preview.rb +++ b/test/mailers/previews/homepage_mailer_preview.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Preview all emails at http://localhost:3000/rails/mailers/member_mailer class HomepageMailerPreview < ActionMailer::Preview def inquiry @@ -11,6 +13,6 @@ def inquiry "inventory" => "Lots of tools." } - HomepageMailer.with(homepage_params: homepage_params).inquiry + HomepageMailer.with(homepage_params:).inquiry end end diff --git a/test/mailers/previews/member_mailer_preview.rb b/test/mailers/previews/member_mailer_preview.rb index 136c64984..f3427dbdd 100644 --- a/test/mailers/previews/member_mailer_preview.rb +++ b/test/mailers/previews/member_mailer_preview.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Preview all emails at http://localhost:3000/rails/mailers/member_mailer class MemberMailerPreview < ActionMailer::Preview include Lending @@ -31,7 +33,7 @@ def due_soon member = Member.verified.first loans = [] 3.times do - loans << Loan.create(item: Item.available.order("RANDOM()").first, member: member, due_at: tomorrow, uniquely_numbered: false, library: member.library) + loans << Loan.create(item: Item.available.order("RANDOM()").first, member:, due_at: tomorrow, uniquely_numbered: false, library: member.library) end loan_summaries = LoanSummary.where("due_at BETWEEN ? AND ?", tomorrow.beginning_of_day.utc, tomorrow.utc).limit(5).includes(item: :borrow_policy).to_a @@ -39,7 +41,7 @@ def due_soon first_item = loan_summaries.first.item Hold.create!(item: first_item, member: Member.second, creator: User.first, library: member.library) - MemberMailer.with(member: member, summaries: loan_summaries).return_reminder + MemberMailer.with(member:, summaries: loan_summaries).return_reminder end def items_on_hold @@ -47,7 +49,7 @@ def items_on_hold member = Member.second first_item = loan_summaries.first.item - Hold.create!(item: first_item, member: member, creator: User.first, library: member.library) + Hold.create!(item: first_item, member:, creator: User.first, library: member.library) loan_summaries.first.latest_loan = Loan.new(created_at: Time.current) MemberMailer.with(member: Member.first, summaries: loan_summaries).loan_summaries @@ -56,9 +58,9 @@ def items_on_hold def hold_available first_item = Item.active.first member = Member.second - hold = Hold.create!(item: first_item, member: member, creator: User.first, library: member.library) + hold = Hold.create!(item: first_item, member:, creator: User.first, library: member.library) - MemberMailer.with(member: Member.first, hold: hold, library: member.library).hold_available + MemberMailer.with(member: Member.first, hold:, library: member.library).hold_available end def membership_renewal_reminder @@ -69,23 +71,23 @@ def staff_daily_renewal_requests tomorrow = Time.current.end_of_day + 1.day member = Member.verified.first 3.times do - loan = Loan.create!(item: Item.available.order("RANDOM()").first, member: member, library: member.library, due_at: tomorrow, uniquely_numbered: false) - RenewalRequest.create!(loan: loan) + loan = Loan.create!(item: Item.available.order("RANDOM()").first, member:, library: member.library, due_at: tomorrow, uniquely_numbered: false) + RenewalRequest.create!(loan:) end renewal_requests = RenewalRequest.requested.where.not(loan_id: nil).where("created_at >= ?", Time.current.beginning_of_day.utc).includes(loan: [:item, :member]).limit(5) - MemberMailer.with(member: Member.joins(:user).where(users: {role: :admin}).first, renewal_requests: renewal_requests).staff_daily_renewal_requests + MemberMailer.with(member: Member.joins(:user).where(users: { role: :admin }).first, renewal_requests:).staff_daily_renewal_requests end def renewal_request_approved ActsAsTenant.with_tenant(Library.first) do tomorrow = Time.current.end_of_day + 1.day member = Member.verified.first - loan = Loan.create!(item: Item.available.order("RANDOM()").first, member: member, library: member.library, due_at: tomorrow, uniquely_numbered: false) + loan = Loan.create!(item: Item.available.order("RANDOM()").first, member:, library: member.library, due_at: tomorrow, uniquely_numbered: false) renew_loan(loan) - renewal_request = RenewalRequest.create!(loan: loan, status: :approved) - MemberMailer.with(renewal_request: renewal_request).renewal_request_updated + renewal_request = RenewalRequest.create!(loan:, status: :approved) + MemberMailer.with(renewal_request:).renewal_request_updated end end @@ -93,9 +95,9 @@ def renewal_request_rejected ActsAsTenant.with_tenant(Library.first) do tomorrow = Time.current.end_of_day + 1.day member = Member.verified.first - loan = Loan.create!(item: Item.available.order("RANDOM()").first, member: member, library: member.library, due_at: tomorrow, uniquely_numbered: false) - renewal_request = RenewalRequest.create!(loan: loan, status: :rejected) - MemberMailer.with(renewal_request: renewal_request).renewal_request_updated + loan = Loan.create!(item: Item.available.order("RANDOM()").first, member:, library: member.library, due_at: tomorrow, uniquely_numbered: false) + renewal_request = RenewalRequest.create!(loan:, status: :rejected) + MemberMailer.with(renewal_request:).renewal_request_updated end end @@ -103,9 +105,9 @@ def appointment_confirmation member = Member.verified.first tomorrow = Time.current + 1.day loan = Loan.create!(item: Item.available.order("RANDOM()").first, member: Member.verified.first, due_at: tomorrow, uniquely_numbered: false, library: member.library) - appointment = Appointment.new(starts_at: tomorrow, ends_at: tomorrow + 1.hour, member: member) + appointment = Appointment.new(starts_at: tomorrow, ends_at: tomorrow + 1.hour, member:) appointment.loans << loan appointment.save! - MemberMailer.with(member: member, appointment: appointment).appointment_confirmation + MemberMailer.with(member:, appointment:).appointment_confirmation end end diff --git a/test/models/adjustment_test.rb b/test/models/adjustment_test.rb index 461eb593b..8cd728f49 100644 --- a/test/models/adjustment_test.rb +++ b/test/models/adjustment_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class AdjustmentTest < ActiveSupport::TestCase diff --git a/test/models/agreement_acceptance_test.rb b/test/models/agreement_acceptance_test.rb index 1af4139a8..b1e5cc488 100644 --- a/test/models/agreement_acceptance_test.rb +++ b/test/models/agreement_acceptance_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class AgreementAcceptanceTest < ActiveSupport::TestCase diff --git a/test/models/agreement_test.rb b/test/models/agreement_test.rb index 98c5c1349..900f08b40 100644 --- a/test/models/agreement_test.rb +++ b/test/models/agreement_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class AgreementTest < ActiveSupport::TestCase diff --git a/test/models/appointment_hold_test.rb b/test/models/appointment_hold_test.rb index fd18d9523..a987afb44 100644 --- a/test/models/appointment_hold_test.rb +++ b/test/models/appointment_hold_test.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + require "test_helper" class AppointmentHoldTest < ActiveSupport::TestCase test "creates an appointment hold for member appointment" do appointment = FactoryBot.build(:appointment) user = FactoryBot.create(:user) - member = FactoryBot.create(:member, user: user) + member = FactoryBot.create(:member, user:) hold = FactoryBot.create(:hold, creator: member.user) hold_two = FactoryBot.create(:hold, creator: member.user) appointment.holds << hold diff --git a/test/models/appointment_loan_test.rb b/test/models/appointment_loan_test.rb index ca76cd54d..90a6116ef 100644 --- a/test/models/appointment_loan_test.rb +++ b/test/models/appointment_loan_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class AppointmentLoanTest < ActiveSupport::TestCase diff --git a/test/models/appointment_test.rb b/test/models/appointment_test.rb index a80b56ccd..26fd00a86 100644 --- a/test/models/appointment_test.rb +++ b/test/models/appointment_test.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + require "test_helper" class AppointmentTest < ActiveSupport::TestCase test "creates an appointment" do appointment = FactoryBot.build(:appointment) user = FactoryBot.create(:user) - member = FactoryBot.create(:member, user: user) + member = FactoryBot.create(:member, user:) hold = FactoryBot.create(:hold, creator: member.user) appointment.holds << hold appointment.starts_at = "2020-10-05 7:00AM" @@ -33,17 +35,17 @@ class AppointmentTest < ActiveSupport::TestCase appointment = Appointment.new appointment.time_range_string = value - refute appointment.starts_at - refute appointment.ends_at + assert_not appointment.starts_at + assert_not appointment.ends_at end end test "finds a simultaneous appointments" do member = create(:member) - hold = create(:hold, member: member) - hold2 = create(:hold, member: member) - original = create(:appointment, holds: [hold], member: member) - dupe = create(:appointment, holds: [hold2], member: member, starts_at: original.starts_at, ends_at: original.ends_at) + hold = create(:hold, member:) + hold2 = create(:hold, member:) + original = create(:appointment, holds: [hold], member:) + dupe = create(:appointment, holds: [hold2], member:, starts_at: original.starts_at, ends_at: original.ends_at) assert_equal [dupe], Appointment.simultaneous(original) assert_equal [original], Appointment.simultaneous(dupe) @@ -51,14 +53,14 @@ class AppointmentTest < ActiveSupport::TestCase test "merges appointments" do member = create(:member) - hold = create(:hold, member: member) - hold2 = create(:hold, member: member) - loan = create(:loan, member: member) - loan2 = create(:loan, member: member) + hold = create(:hold, member:) + hold2 = create(:hold, member:) + loan = create(:loan, member:) + loan2 = create(:loan, member:) original = create(:appointment, - holds: [hold], loans: [loan], member: member, comment: "First notes") + holds: [hold], loans: [loan], member:, comment: "First notes") dupe = create(:appointment, - holds: [hold2], loans: [loan2], member: member, comment: "Second notes", + holds: [hold2], loans: [loan2], member:, comment: "Second notes", starts_at: original.starts_at, ends_at: original.ends_at) original.merge!(dupe) diff --git a/test/models/borrow_policy_test.rb b/test/models/borrow_policy_test.rb index fa4c5f019..92fe1ed4c 100644 --- a/test/models/borrow_policy_test.rb +++ b/test/models/borrow_policy_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class BorrowPolicyTest < ActiveSupport::TestCase @@ -7,7 +9,7 @@ class BorrowPolicyTest < ActiveSupport::TestCase new_policy = BorrowPolicy.create!(name: "New", code: "N", default: true) assert new_policy.reload.default - refute old_policy.reload.default + assert_not old_policy.reload.default end test "allow_multiple_holds_per_member? is true when uniquely_numbered is false" do @@ -25,7 +27,7 @@ class BorrowPolicyTest < ActiveSupport::TestCase test "requires consumables to not be uniquely_numbered" do policy = BorrowPolicy.new(uniquely_numbered: true, consumable: true) - refute policy.valid? + assert_not policy.valid? assert_equal ["must not be enabled for consumables"], policy.errors[:uniquely_numbered] end diff --git a/test/models/category_node_test.rb b/test/models/category_node_test.rb index d3ded3f8d..f3deb6af9 100644 --- a/test/models/category_node_test.rb +++ b/test/models/category_node_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class CategoryNodeTest < ActiveSupport::TestCase diff --git a/test/models/category_test.rb b/test/models/category_test.rb index 6fc00afdf..59d6b9706 100644 --- a/test/models/category_test.rb +++ b/test/models/category_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class CategoryTest < ActiveSupport::TestCase @@ -11,7 +13,7 @@ class CategoryTest < ActiveSupport::TestCase power_tools = Category.create(name: "Power Tools") saws = Category.create!(name: "Saws", parent: power_tools) - refute power_tools.update(parent: saws) + assert_not power_tools.update(parent: saws) assert_equal ["can't be set to a child"], power_tools.errors[:parent_id] end end diff --git a/test/models/event_test.rb b/test/models/event_test.rb index 12ea11818..e54fd1497 100644 --- a/test/models/event_test.rb +++ b/test/models/event_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class EventTest < ActiveSupport::TestCase @@ -98,7 +100,7 @@ class EventTest < ActiveSupport::TestCase calendar_event_id: "ev1" ).first - refute updated_event + assert_not updated_event end test "handles cancelled events that have already been deleted" do diff --git a/test/models/fine_calculator_test.rb b/test/models/fine_calculator_test.rb index deafc8d9d..266b9841c 100644 --- a/test/models/fine_calculator_test.rb +++ b/test/models/fine_calculator_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class FineCalculatorTest < ActiveSupport::TestCase diff --git a/test/models/gift_membership_test.rb b/test/models/gift_membership_test.rb index 22cc60d13..d5573324d 100644 --- a/test/models/gift_membership_test.rb +++ b/test/models/gift_membership_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class GiftMembershipTest < ActiveSupport::TestCase diff --git a/test/models/hold_test.rb b/test/models/hold_test.rb index 9286781a7..30613b072 100644 --- a/test/models/hold_test.rb +++ b/test/models/hold_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class HoldTest < ActiveSupport::TestCase @@ -14,47 +16,47 @@ class HoldTest < ActiveSupport::TestCase hold = create(:hold, ended_at: nil, started_at: nil) assert hold.active? - refute hold.inactive? - refute hold.ended? - refute hold.expired? - refute hold.started? + assert_not hold.inactive? + assert_not hold.ended? + assert_not hold.expired? + assert_not hold.started? assert Hold.active.find_by(id: hold) - refute Hold.inactive.find_by(id: hold) - refute Hold.ended.find_by(id: hold) - refute Hold.expired.find_by(id: hold) - refute Hold.started.find_by(id: hold) + assert_not Hold.inactive.find_by(id: hold) + assert_not Hold.ended.find_by(id: hold) + assert_not Hold.expired.find_by(id: hold) + assert_not Hold.started.find_by(id: hold) end test "started hold" do hold = create(:started_hold) assert hold.active? - refute hold.inactive? - refute hold.ended? - refute hold.expired? + assert_not hold.inactive? + assert_not hold.ended? + assert_not hold.expired? assert hold.started? assert Hold.active.find_by(id: hold) - refute Hold.inactive.find_by(id: hold) - refute Hold.ended.find_by(id: hold) - refute Hold.expired.find_by(id: hold) + assert_not Hold.inactive.find_by(id: hold) + assert_not Hold.ended.find_by(id: hold) + assert_not Hold.expired.find_by(id: hold) assert Hold.started.find_by(id: hold) end test "ended hold" do hold = create(:hold, ended_at: 2.days.ago, started_at: 5.days.ago, expires_at: 3.days.since) - refute hold.active? + assert_not hold.active? assert hold.inactive? assert hold.ended? - refute hold.expired? + assert_not hold.expired? assert hold.started? - refute Hold.active.find_by(id: hold) + assert_not Hold.active.find_by(id: hold) assert Hold.inactive.find_by(id: hold) assert Hold.ended.find_by(id: hold) - refute Hold.expired.find_by(id: hold) + assert_not Hold.expired.find_by(id: hold) assert Hold.started.find_by(id: hold) end @@ -62,15 +64,15 @@ class HoldTest < ActiveSupport::TestCase hold = create(:hold, ended_at: nil) hold.start!(15.days.ago) - refute hold.active? + assert_not hold.active? assert hold.inactive? - refute hold.ended? + assert_not hold.ended? assert hold.expired? assert hold.started? - refute Hold.active.find_by(id: hold) + assert_not Hold.active.find_by(id: hold) assert Hold.inactive.find_by(id: hold) - refute Hold.ended.find_by(id: hold) + assert_not Hold.ended.find_by(id: hold) assert Hold.expired.find_by(id: hold) assert Hold.started.find_by(id: hold) end @@ -82,23 +84,23 @@ class HoldTest < ActiveSupport::TestCase travel_to (hold_started + Hold::HOLD_LENGTH).end_of_day do assert hold.active? - refute hold.inactive? - refute hold.ended? - refute hold.expired? + assert_not hold.inactive? + assert_not hold.ended? + assert_not hold.expired? assert hold.started? assert Hold.active.find_by(id: hold) - refute Hold.inactive.find_by(id: hold) - refute Hold.ended.find_by(id: hold) - refute Hold.expired.find_by(id: hold) + assert_not Hold.inactive.find_by(id: hold) + assert_not Hold.ended.find_by(id: hold) + assert_not Hold.expired.find_by(id: hold) assert Hold.started.find_by(id: hold) end end test "#start!" do hold = create(:hold) - refute hold.started_at - refute hold.expires_at + assert_not hold.started_at + assert_not hold.expires_at hold.start! assert hold.started_at @@ -116,21 +118,21 @@ class HoldTest < ActiveSupport::TestCase create(:loan, item: hold.item) hold.reload - refute hold.ready_for_pickup? + assert_not hold.ready_for_pickup? end test "#ready_for_pickup? is false when there is an earlier hold" do hold = create(:hold) second_hold = create(:hold, item: hold.item) - refute second_hold.ready_for_pickup? + assert_not second_hold.ready_for_pickup? end test "#ready_for_pickup? is true for uncounted items despite active loans" do item = create(:uncounted_item) - hold = create(:hold, item: item) - create(:loan, item: item) + hold = create(:hold, item:) + create(:loan, item:) hold.reload assert hold.ready_for_pickup? @@ -207,7 +209,7 @@ class HoldTest < ActiveSupport::TestCase test "starts all of the holds for an uncounted item" do item = create(:uncounted_item) 3.times do - create(:hold, item: item) + create(:hold, item:) end started = assert_difference("Hold.started.count", 3) { @@ -230,7 +232,7 @@ class HoldTest < ActiveSupport::TestCase hold1.reload hold2.reload assert hold1.started? - refute hold2.started? + assert_not hold2.started? assert_difference("Hold.started.count") do Hold.start_waiting_holds(15.days.since) do |hold| @@ -269,10 +271,10 @@ class HoldTest < ActiveSupport::TestCase test "is ready for pickup if item is uncounted" do item = create(:uncounted_item) - hold = create(:hold, item: item) + hold = create(:hold, item:) assert hold.ready_for_pickup? - second_hold = create(:hold, item: item) + second_hold = create(:hold, item:) assert second_hold.ready_for_pickup? end @@ -280,17 +282,17 @@ class HoldTest < ActiveSupport::TestCase item = create(:item, status: :active) member = create(:verified_member_with_membership) - hold = Hold.new(item: item, member: member, creator: member.user) + hold = Hold.new(item:, member:, creator: member.user) assert hold.valid? end %i[pending retired maintenance].each do |status| test "can't be put on hold if the item is #{status}" do - item = create(:item, status: status) + item = create(:item, status:) member = create(:verified_member_with_membership) - hold = Hold.new(item: item, member: member, creator: member.user) - refute hold.valid? + hold = Hold.new(item:, member:, creator: member.user) + assert_not hold.valid? assert_equal ["can not be placed on hold"], hold.errors[:item] end end diff --git a/test/models/item_attachment_test.rb b/test/models/item_attachment_test.rb index d5906ea99..1ecc1efcd 100644 --- a/test/models/item_attachment_test.rb +++ b/test/models/item_attachment_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class ItemAttachmentTest < ActiveSupport::TestCase diff --git a/test/models/item_test.rb b/test/models/item_test.rb index 6578928bf..0553043fb 100644 --- a/test/models/item_test.rb +++ b/test/models/item_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class ItemTest < ActiveSupport::TestCase @@ -5,7 +7,7 @@ class ItemTest < ActiveSupport::TestCase test "assigns a number" do borrow_policy = create(:borrow_policy) - item = build(:item, number: nil, borrow_policy: borrow_policy) + item = build(:item, number: nil, borrow_policy:) item.save! assert item.number @@ -20,7 +22,7 @@ class ItemTest < ActiveSupport::TestCase test "it is not available" do loan = create(:loan) loan.item.reload - refute loan.item.available? + assert_not loan.item.available? end test "it is available" do @@ -30,7 +32,7 @@ class ItemTest < ActiveSupport::TestCase test "validations" do item = Item.new(status: nil) - refute item.valid? + assert_not item.valid? assert_equal ["can't be blank"], item.errors[:name] assert_equal ["is not included in the list"], item.errors[:status] @@ -85,7 +87,7 @@ class ItemTest < ActiveSupport::TestCase test "can delete an item with a renewed loan" do item = create(:item) - loan = create(:loan, item: item) + loan = create(:loan, item:) renew_loan(loan) assert item.destroy @@ -93,45 +95,45 @@ class ItemTest < ActiveSupport::TestCase test "can delete an item with an active loan" do item = create(:item) - create(:loan, item: item) + create(:loan, item:) assert item.destroy end test "can delete an item with a hold" do item = create(:item) - create(:hold, item: item) + create(:hold, item:) assert item.destroy end test "can delete an item with an attachment" do item = create(:item) - create(:item_attachment, item: item, creator: create(:user)) - create(:hold, item: item) + create(:item_attachment, item:, creator: create(:user)) + create(:hold, item:) assert item.destroy end test "has a next_hold" do item = create(:item) - hold = create(:hold, item: item, created_at: 2.days.ago) - create(:hold, item: item, created_at: 1.day.ago) + hold = create(:hold, item:, created_at: 2.days.ago) + create(:hold, item:, created_at: 1.day.ago) assert_equal hold, item.next_hold end test "next_hold ignores inactive holds" do item = create(:item) - create(:ended_hold, item: item) - create(:expired_hold, item: item) + create(:ended_hold, item:) + create(:expired_hold, item:) - refute item.next_hold + assert_not item.next_hold end test "clears holds when changing to an inactive status" do item = create(:item) - create(:started_hold, item: item) + create(:started_hold, item:) item.update!(status: Item.statuses[:pending]) assert_equal item.active_holds.count, 1 @@ -145,7 +147,7 @@ class ItemTest < ActiveSupport::TestCase test "clears next hold when changed to maintenance" do item = create(:item) - hold = create(:started_hold, item: item) + hold = create(:started_hold, item:) item.update!(status: Item.statuses[:maintenance]) assert_nil hold.reload.started_at @@ -173,7 +175,7 @@ class ItemTest < ActiveSupport::TestCase test "the for_category scope returns all items for child categories" do parent = create(:category) - child = create(:category, parent: parent) + child = create(:category, parent:) grandchild = create(:category, parent: child) item1 = create(:item, categories: [parent]) @@ -205,7 +207,7 @@ class ItemTest < ActiveSupport::TestCase test "the for_category scope returns unique items" do parent = create(:category) - child = create(:category, parent: parent) + child = create(:category, parent:) grandchild = create(:category, parent: child) item1 = create(:item, categories: [parent, child]) @@ -235,7 +237,7 @@ class ItemTest < ActiveSupport::TestCase test "sets itself to retired when decrementing quantity to zero" do borrow_policy = create(:borrow_policy, consumable: true, uniquely_numbered: false) - item = create(:item, borrow_policy: borrow_policy, quantity: 1) + item = create(:item, borrow_policy:, quantity: 1) assert_equal "active", item.status @@ -247,7 +249,7 @@ class ItemTest < ActiveSupport::TestCase test "sets itself to active when quantity is restored" do borrow_policy = create(:borrow_policy, consumable: true, uniquely_numbered: false) - item = create(:item, borrow_policy: borrow_policy, quantity: 0, status: "retired") + item = create(:item, borrow_policy:, quantity: 0, status: "retired") assert_equal "retired", item.status @@ -259,9 +261,9 @@ class ItemTest < ActiveSupport::TestCase test "requires a value for quantity with a consumable borrow policy" do borrow_policy = create(:consumable_borrow_policy) - item = build(:item, borrow_policy: borrow_policy) + item = build(:item, borrow_policy:) - refute item.valid? + assert_not item.valid? assert_equal ["is not a number"], item.errors[:quantity] end end diff --git a/test/models/library_test.rb b/test/models/library_test.rb index e750528d9..9cc24e31c 100644 --- a/test/models/library_test.rb +++ b/test/models/library_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class LibraryTest < ActiveSupport::TestCase @@ -25,8 +27,8 @@ class LibraryTest < ActiveSupport::TestCase assert library.allows_postal_code?("90215") assert library.allows_postal_code?("19013") - refute library.allows_postal_code?("19011") - refute library.allows_postal_code?("90310") + assert_not library.allows_postal_code?("19011") + assert_not library.allows_postal_code?("90310") end test "allows any postal code when pattern is not set" do diff --git a/test/models/library_update_test.rb b/test/models/library_update_test.rb index bce9a2c12..f692aca79 100644 --- a/test/models/library_update_test.rb +++ b/test/models/library_update_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class LibraryUpdateTest < ActiveSupport::TestCase diff --git a/test/models/loan_summary_test.rb b/test/models/loan_summary_test.rb index a596cc2fc..d1e902173 100644 --- a/test/models/loan_summary_test.rb +++ b/test/models/loan_summary_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class LoanSummaryTest < ActiveSupport::TestCase diff --git a/test/models/loan_test.rb b/test/models/loan_test.rb index 047ef5faf..7ba6a8b9b 100644 --- a/test/models/loan_test.rb +++ b/test/models/loan_test.rb @@ -1,19 +1,21 @@ +# frozen_string_literal: true + require "test_helper" class LoanTest < ActiveSupport::TestCase test "an item can only have a single active loan" do item = create(:item) - create(:loan, item: item) - loan = build(:loan, item: item) + create(:loan, item:) + loan = build(:loan, item:) - refute loan.save + assert_not loan.save assert_equal ["is already on loan"], loan.errors[:item_id] end test "an item can only have a single numbered active loan enforced by the index" do item = create(:item) - create(:loan, item: item) - loan = build(:loan, item: item) + create(:loan, item:) + loan = build(:loan, item:) assert_raises ActiveRecord::RecordNotUnique do loan.save(validate: false) @@ -21,13 +23,13 @@ class LoanTest < ActiveSupport::TestCase end test "validates an empty record" do - refute Loan.new.valid? + assert_not Loan.new.valid? end test "an uncountable item can have multiple active loans" do item = create(:item) 2.times do - create(:loan, item: item, uniquely_numbered: false) + create(:loan, item:, uniquely_numbered: false) end end @@ -39,17 +41,17 @@ class LoanTest < ActiveSupport::TestCase %i[pending maintenance retired].each do |status| test "is invalid with an item with #{status} status" do - item = create(:item, status: status) - loan = build(:loan, item: item, due_at: Date.tomorrow.end_of_day) + item = create(:item, status:) + loan = build(:loan, item:, due_at: Date.tomorrow.end_of_day) - refute loan.save + assert_not loan.save assert_equal ["is not available to loan"], loan.errors[:item_id] end end test "knows if it is a renewal" do loan = create(:loan, renewal_count: 0) - refute loan.renewal? + assert_not loan.renewal? renewal = create(:loan, renewal_count: 1) assert renewal.renewal? @@ -80,12 +82,12 @@ class LoanTest < ActiveSupport::TestCase test "creates loans that end on an open day" do borrow_policy = create(:borrow_policy, duration: 7) - item = create(:item, borrow_policy: borrow_policy) + item = create(:item, borrow_policy:) member = create(:verified_member_with_membership) now = Time.utc(2020, 1, 18, 12) # saturday loan = Loan.stub(:open_days, [0, 4]) { - Loan.lend(item, to: member, now: now) + Loan.lend(item, to: member, now:) } sunday = Time.utc(2020, 1, 26).end_of_day @@ -139,70 +141,70 @@ class LoanTest < ActiveSupport::TestCase test "is member_renewable if borrow_policy allows member renewal is within original loan duration and has not exceeded limit" do borrow_policy = build(:member_renewable_borrow_policy) - item = build(:item, borrow_policy: borrow_policy) - loan = build(:loan, item: item) + item = build(:item, borrow_policy:) + loan = build(:loan, item:) assert loan.member_renewable? end test "is not member_renewable if renewal count exceeds limit" do borrow_policy = build(:member_renewable_borrow_policy) - item = build(:item, borrow_policy: borrow_policy) - loan = build(:loan, item: item, renewal_count: borrow_policy.renewal_limit) + item = build(:item, borrow_policy:) + loan = build(:loan, item:, renewal_count: borrow_policy.renewal_limit) - refute loan.member_renewable? + assert_not loan.member_renewable? end test "is not member renewable if borrow_policy does not allow member renewals" do borrow_policy = build(:borrow_policy, member_renewable: false) - item = build(:item, borrow_policy: borrow_policy) - loan = build(:loan, item: item) + item = build(:item, borrow_policy:) + loan = build(:loan, item:) - refute loan.member_renewable? + assert_not loan.member_renewable? end test "is not member_renewable if loan has end date" do borrow_policy = create(:member_renewable_borrow_policy) - item = create(:item, borrow_policy: borrow_policy) - loan = create(:loan, item: item, created_at: Time.current, ended_at: Time.current) + item = create(:item, borrow_policy:) + loan = create(:loan, item:, created_at: Time.current, ended_at: Time.current) - refute loan.member_renewable? + assert_not loan.member_renewable? end test "is member_renewal_requestable without a renewable borrow policy" do borrow_policy = create(:borrow_policy, member_renewable: false) - item = create(:item, borrow_policy: borrow_policy) - loan = create(:loan, item: item) + item = create(:item, borrow_policy:) + loan = create(:loan, item:) assert loan.member_renewal_requestable? end test "is not member_renewal_requestable if there are active holds" do borrow_policy = create(:borrow_policy, member_renewable: false) - item = create(:item, borrow_policy: borrow_policy) - loan = create(:loan, item: item) - create(:hold, item: item, member: loan.member, ended_at: nil) + item = create(:item, borrow_policy:) + loan = create(:loan, item:) + create(:hold, item:, member: loan.member, ended_at: nil) item.reload loan.reload - refute loan.member_renewal_requestable? + assert_not loan.member_renewal_requestable? end test "is not member_renewal_requestable if there are pending or rejected requests" do borrow_policy = create(:borrow_policy, member_renewable: false) - item = create(:item, borrow_policy: borrow_policy) - loan = create(:loan, item: item) - create(:renewal_request, loan: loan, status: RenewalRequest.statuses[:rejected]) + item = create(:item, borrow_policy:) + loan = create(:loan, item:) + create(:renewal_request, loan:, status: RenewalRequest.statuses[:rejected]) loan.reload - refute loan.member_renewal_requestable? + assert_not loan.member_renewal_requestable? end test "is member_renewal_requestable until the end of the day a loan expires" do loan_ends = Date.new(2021, 0o5, 27, 4).to_time borrow_policy = create(:borrow_policy, member_renewable: false) - item = create(:item, borrow_policy: borrow_policy) - loan = create(:loan, item: item, due_at: loan_ends) + item = create(:item, borrow_policy:) + loan = create(:loan, item:, due_at: loan_ends) travel_to loan_ends + 1.minute do assert loan.member_renewal_requestable? diff --git a/test/models/member_test.rb b/test/models/member_test.rb index 6e808da46..a21b4bb64 100644 --- a/test/models/member_test.rb +++ b/test/models/member_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class MemberTest < ActiveSupport::TestCase @@ -58,8 +60,8 @@ class MemberTest < ActiveSupport::TestCase assert member.valid? member.postal_code = "90210" - refute library.allows_postal_code? "90210" - refute member.valid? + assert_not library.allows_postal_code? "90210" + assert_not member.valid? assert member.errors.messages.include?(:postal_code) error_message = "must be one of: 60707, 60827, 606xx" assert member.errors.messages[:postal_code].include?(error_message) @@ -75,7 +77,7 @@ class MemberTest < ActiveSupport::TestCase test "member with a user has a default role of 'member'" do user = User.new - member = Member.new(user: user) + member = Member.new(user:) assert_equal [:member], member.roles assert member.member? @@ -83,7 +85,7 @@ class MemberTest < ActiveSupport::TestCase test "a 'staff' member has the role 'staff' and 'member'" do user = User.new(role: "staff") - member = Member.new(user: user) + member = Member.new(user:) assert_equal [:member, :staff], member.roles assert member.staff? @@ -91,7 +93,7 @@ class MemberTest < ActiveSupport::TestCase test "an 'admin' member has the role 'admin', 'staff', and 'member'" do user = User.new(role: "admin") - member = Member.new(user: user) + member = Member.new(user:) assert_equal [:member, :staff, :admin], member.roles assert member.admin? @@ -99,21 +101,21 @@ class MemberTest < ActiveSupport::TestCase test "can find its upcoming appointment of a hold" do member = create(:member) - hold = create(:hold, member: member) + hold = create(:hold, member:) assert_nil member.upcoming_appointment_of(hold), "it should return nil if there is no appointment found" - appointment = create(:appointment, member: member, starts_at: Time.now + 1.day, ends_at: Time.now + 1.day + 2.hours, holds: [hold]) + appointment = create(:appointment, member:, starts_at: Time.now + 1.day, ends_at: Time.now + 1.day + 2.hours, holds: [hold]) assert_equal appointment, member.upcoming_appointment_of(hold) end test "can find its upcoming appointment of a loan" do member = create(:member) - loan = create(:loan, member: member) + loan = create(:loan, member:) assert_nil member.upcoming_appointment_of(loan), "it should return nil if there is no appointment found" - appointment = create(:appointment, member: member, starts_at: Time.now + 1.day, ends_at: Time.now + 1.day + 2.hours, loans: [loan]) + appointment = create(:appointment, member:, starts_at: Time.now + 1.day, ends_at: Time.now + 1.day + 2.hours, loans: [loan]) assert_equal appointment, member.upcoming_appointment_of(loan) end @@ -133,7 +135,7 @@ class MemberTest < ActiveSupport::TestCase create(:member, email: "test@notunique.obv") dupe = build(:member, email: "test@notunique.obv") - refute dupe.valid? + assert_not dupe.valid? assert dupe.errors.messages.include?(:email) end @@ -159,15 +161,15 @@ class MemberTest < ActiveSupport::TestCase test "last_membership finds the only membership" do member = create(:member) - membership = create(:membership, member: member) + membership = create(:membership, member:) assert_equal membership, member.last_membership end test "last_membership finds the last membership" do member = create(:member) - create(:membership, member: member, created_at: 14.months.ago, started_at: 13.months.ago, ended_at: 1.month.ago) - newer_membership = create(:membership, member: member, created_at: 1.month.ago, started_at: 1.month.ago, ended_at: 11.months.since) + create(:membership, member:, created_at: 14.months.ago, started_at: 13.months.ago, ended_at: 1.month.ago) + newer_membership = create(:membership, member:, created_at: 1.month.ago, started_at: 1.month.ago, ended_at: 11.months.since) assert_equal newer_membership, member.last_membership end diff --git a/test/models/membership_test.rb b/test/models/membership_test.rb index 67e90c3f6..bd2c1a5a0 100644 --- a/test/models/membership_test.rb +++ b/test/models/membership_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class MembershipTest < ActiveSupport::TestCase @@ -7,7 +9,7 @@ class MembershipTest < ActiveSupport::TestCase membership = assert_difference("Membership.count", 1) { assert_difference("Adjustment.count", 0) { - Membership.create_for_member(member, now: now, start_membership: true) + Membership.create_for_member(member, now:, start_membership: true) } } @@ -22,7 +24,7 @@ class MembershipTest < ActiveSupport::TestCase membership = assert_difference("Membership.count", 1) { assert_difference("Adjustment.count", 0) { - Membership.create_for_member(member, now: now) + Membership.create_for_member(member, now:) } } @@ -38,7 +40,7 @@ class MembershipTest < ActiveSupport::TestCase membership = assert_difference("Membership.count", 1) { assert_difference("Adjustment.count", 2) { - Membership.create_for_member(member, now: now, amount: amount, source: "cash", start_membership: true) + Membership.create_for_member(member, now:, amount:, source: "cash", start_membership: true) } } @@ -65,7 +67,7 @@ class MembershipTest < ActiveSupport::TestCase membership = assert_difference("Membership.count", 1) { assert_difference("Adjustment.count", 2) { - Membership.create_for_member(member, now: now, amount: amount, source: "cash") + Membership.create_for_member(member, now:, amount:, source: "cash") } } @@ -92,7 +94,7 @@ class MembershipTest < ActiveSupport::TestCase membership = assert_difference("Membership.count", 1) { assert_difference("Adjustment.count", 2) { - Membership.create_for_member(member, now: now, amount: amount, start_membership: true, source: "square", square_transaction_id: "sq_abcd") + Membership.create_for_member(member, now:, amount:, start_membership: true, source: "square", square_transaction_id: "sq_abcd") } } @@ -121,7 +123,7 @@ class MembershipTest < ActiveSupport::TestCase membership = assert_difference("Membership.count", 1) { assert_difference("Adjustment.count", 2) { - Membership.create_for_member(member, now: now, amount: amount, source: "square", square_transaction_id: "sq_abcd") + Membership.create_for_member(member, now:, amount:, source: "square", square_transaction_id: "sq_abcd") } } @@ -154,25 +156,25 @@ class MembershipTest < ActiveSupport::TestCase test "prevents a member from having an overlapping later membership" do member = create(:member) - membership = create(:membership, member: member) + membership = create(:membership, member:) - later_membership = build(:membership, member: member, started_at: membership.ended_at) - refute later_membership.valid? + later_membership = build(:membership, member:, started_at: membership.ended_at) + assert_not later_membership.valid? assert_equal ["can't overlap with another membership"], later_membership.errors[:base] end test "prevents a member from having an overlapping earlier membership" do member = create(:member) - membership = create(:membership, member: member) + membership = create(:membership, member:) - earlier_membership = build(:membership, member: member, ended_at: membership.started_at) - refute earlier_membership.valid? + earlier_membership = build(:membership, member:, ended_at: membership.started_at) + assert_not earlier_membership.valid? assert_equal ["can't overlap with another membership"], earlier_membership.errors[:base] end test "allows different members to have overlapping memberships" do member = create(:member) - membership = create(:membership, member: member) + membership = create(:membership, member:) member2 = create(:member) create(:membership, member: member2, started_at: membership.started_at) diff --git a/test/models/monthly_adjustment_test.rb b/test/models/monthly_adjustment_test.rb index 8113c2005..60795bb49 100644 --- a/test/models/monthly_adjustment_test.rb +++ b/test/models/monthly_adjustment_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class MonthlyAdjustmentTest < ActiveSupport::TestCase diff --git a/test/models/note_test.rb b/test/models/note_test.rb index a7cec162e..58a34785d 100644 --- a/test/models/note_test.rb +++ b/test/models/note_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class NoteTest < ActiveSupport::TestCase diff --git a/test/models/notification_test.rb b/test/models/notification_test.rb index e1daba239..f5dc38904 100644 --- a/test/models/notification_test.rb +++ b/test/models/notification_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class NotificationTest < ActiveSupport::TestCase diff --git a/test/models/renewal_request_test.rb b/test/models/renewal_request_test.rb index ed293ed92..f8a6c3f97 100644 --- a/test/models/renewal_request_test.rb +++ b/test/models/renewal_request_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class RenewalRequestTest < ActiveSupport::TestCase diff --git a/test/models/reservation_test.rb b/test/models/reservation_test.rb index e46d15c54..04b1418f4 100644 --- a/test/models/reservation_test.rb +++ b/test/models/reservation_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class HoldTest < ActiveSupport::TestCase diff --git a/test/models/short_link_test.rb b/test/models/short_link_test.rb index 9c4167e77..94a3a04a8 100644 --- a/test/models/short_link_test.rb +++ b/test/models/short_link_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class ShortLinkTest < ActiveSupport::TestCase @@ -16,7 +18,7 @@ def link.unique_slug?(slug) test "generates a unique slug when created" do link = ShortLink.create!(url: "http://example.com") - refute_nil link.slug + assert_not_nil link.slug assert_size 6, link.slug end @@ -41,20 +43,20 @@ def link.unique_slug?(slug) test "requires url" do link = ShortLink.new - refute link.valid? + assert_not link.valid? assert_size 1, link.errors[:url] end test "requires valid url" do link = ShortLink.new(url: "notAvalidURL") - refute link.valid? + assert_not link.valid? assert_size 1, link.errors[:url] end test "requires unique url" do link = create(:short_link) dupe_link = ShortLink.new(url: link.url) - refute dupe_link.valid? + assert_not dupe_link.valid? assert_size 1, dupe_link.errors[:url] end diff --git a/test/models/ticket_test.rb b/test/models/ticket_test.rb index 307fc7eaf..d377e67e9 100644 --- a/test/models/ticket_test.rb +++ b/test/models/ticket_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class TicketTest < ActiveSupport::TestCase diff --git a/test/models/user_test.rb b/test/models/user_test.rb index 5c07f4900..e153b8395 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class UserTest < ActiveSupport::TestCase diff --git a/test/nulls/null_borrow_policy_test.rb b/test/nulls/null_borrow_policy_test.rb index 8c0d148ea..e1d578a72 100644 --- a/test/nulls/null_borrow_policy_test.rb +++ b/test/nulls/null_borrow_policy_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class NullBorrowPolicyTest < ActiveSupport::TestCase diff --git a/test/nulls/null_item_test.rb b/test/nulls/null_item_test.rb index 3a1113403..d9d6767e7 100644 --- a/test/nulls/null_item_test.rb +++ b/test/nulls/null_item_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "test_helper" class NullItemTest < ActiveSupport::TestCase diff --git a/test/system/admin/appointments_test.rb b/test/system/admin/appointments_test.rb index 1e313879a..35dc9cda9 100644 --- a/test/system/admin/appointments_test.rb +++ b/test/system/admin/appointments_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "application_system_test_case" module Admin diff --git a/test/system/admin/borrow_policies_test.rb b/test/system/admin/borrow_policies_test.rb index ae42c1c44..b22e53914 100644 --- a/test/system/admin/borrow_policies_test.rb +++ b/test/system/admin/borrow_policies_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "application_system_test_case" class BorrowPoliciesTest < ApplicationSystemTestCase diff --git a/test/system/admin/categories_test.rb b/test/system/admin/categories_test.rb index 201d7173a..4b3c2ba34 100644 --- a/test/system/admin/categories_test.rb +++ b/test/system/admin/categories_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "application_system_test_case" class CategoriesTest < ApplicationSystemTestCase diff --git a/test/system/admin/check_in_check_out_test.rb b/test/system/admin/check_in_check_out_test.rb index 7cd483a74..8df6884de 100644 --- a/test/system/admin/check_in_check_out_test.rb +++ b/test/system/admin/check_in_check_out_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "application_system_test_case" class CheckInCheckOutTest < ApplicationSystemTestCase @@ -197,7 +199,7 @@ def setup Time.use_zone "America/Chicago" do sunday = Time.new(2020, 1, 26).end_of_day borrow_policy = create(:borrow_policy, renewal_limit: 0) - @item = create(:item, borrow_policy: borrow_policy) + @item = create(:item, borrow_policy:) @member = create(:verified_member_with_membership) create(:loan, item: @item, member: @member, due_at: sunday, created_at: sunday - 7.days) diff --git a/test/system/admin/consumables_test.rb b/test/system/admin/consumables_test.rb index 4a561c47a..809d9b205 100644 --- a/test/system/admin/consumables_test.rb +++ b/test/system/admin/consumables_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "application_system_test_case" class ConsumablesTest < ApplicationSystemTestCase diff --git a/test/system/admin/gift_memberships_test.rb b/test/system/admin/gift_memberships_test.rb index a4de154f4..b836bf313 100644 --- a/test/system/admin/gift_memberships_test.rb +++ b/test/system/admin/gift_memberships_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "application_system_test_case" class GiftMembershipsTest < ApplicationSystemTestCase diff --git a/test/system/admin/holds_test.rb b/test/system/admin/holds_test.rb index 404e34cfb..602f099ad 100644 --- a/test/system/admin/holds_test.rb +++ b/test/system/admin/holds_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "application_system_test_case" class HoldsTest < ApplicationSystemTestCase diff --git a/test/system/admin/item_attachments_test.rb b/test/system/admin/item_attachments_test.rb index 28d6f951e..a4b12ffe5 100644 --- a/test/system/admin/item_attachments_test.rb +++ b/test/system/admin/item_attachments_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "application_system_test_case" class ItemAttachmentsTest < ApplicationSystemTestCase diff --git a/test/system/admin/items_test.rb b/test/system/admin/items_test.rb index 8de1d0618..1a64db236 100644 --- a/test/system/admin/items_test.rb +++ b/test/system/admin/items_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "application_system_test_case" class ItemsTest < ApplicationSystemTestCase diff --git a/test/system/admin/manage_features_test.rb b/test/system/admin/manage_features_test.rb index 5505d596f..b20c12bfd 100644 --- a/test/system/admin/manage_features_test.rb +++ b/test/system/admin/manage_features_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "application_system_test_case" class ManageFeaturesTest < ApplicationSystemTestCase diff --git a/test/system/admin/member_payment_test.rb b/test/system/admin/member_payment_test.rb index d7e4b1b32..420d38dce 100644 --- a/test/system/admin/member_payment_test.rb +++ b/test/system/admin/member_payment_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "application_system_test_case" class MemberPaymentTest < ApplicationSystemTestCase diff --git a/test/system/admin/member_verification_test.rb b/test/system/admin/member_verification_test.rb index 7f74aa3eb..b3dc5e21f 100644 --- a/test/system/admin/member_verification_test.rb +++ b/test/system/admin/member_verification_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "application_system_test_case" class MemberVerificationTest < ApplicationSystemTestCase diff --git a/test/system/admin/members_test.rb b/test/system/admin/members_test.rb index e0fe60d77..6ea8e2454 100644 --- a/test/system/admin/members_test.rb +++ b/test/system/admin/members_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "application_system_test_case" class Admin::MembersTest < ApplicationSystemTestCase diff --git a/test/system/admin/memberships_test.rb b/test/system/admin/memberships_test.rb index fdd9781c9..d6dcd3845 100644 --- a/test/system/admin/memberships_test.rb +++ b/test/system/admin/memberships_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "application_system_test_case" class MembershipsTest < ApplicationSystemTestCase @@ -126,7 +128,7 @@ def setup assert_content "Membership created" @member.reload - refute_equal @member.last_membership, @membership + assert_not_equal @member.last_membership, @membership within ".account" do assert_date_displayed(@member.last_membership.ended_at) @@ -157,6 +159,6 @@ def setup def membership_row_containing(text) within "table.memberships" do - find(:tr, text: text) + find(:tr, text:) end end diff --git a/test/system/admin/notes_test.rb b/test/system/admin/notes_test.rb index 2c0bb67e7..6f5ccc023 100644 --- a/test/system/admin/notes_test.rb +++ b/test/system/admin/notes_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "application_system_test_case" class NotesTest < ApplicationSystemTestCase diff --git a/test/system/admin/renewal_requests_test.rb b/test/system/admin/renewal_requests_test.rb index 04f8a2a64..1f2bb78ba 100644 --- a/test/system/admin/renewal_requests_test.rb +++ b/test/system/admin/renewal_requests_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "application_system_test_case" class AdminRenewalRequestsTest < ApplicationSystemTestCase diff --git a/test/system/admin/reports/monthly_activities_test.rb b/test/system/admin/reports/monthly_activities_test.rb index cfab97a88..25ff3318e 100644 --- a/test/system/admin/reports/monthly_activities_test.rb +++ b/test/system/admin/reports/monthly_activities_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "application_system_test_case" module Admin diff --git a/test/system/admin/users_test.rb b/test/system/admin/users_test.rb index 045ff5088..f92a2d496 100644 --- a/test/system/admin/users_test.rb +++ b/test/system/admin/users_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "application_system_test_case" class UsersTest < ApplicationSystemTestCase diff --git a/test/system/appointments_test.rb b/test/system/appointments_test.rb index 28a657086..cabedb7a7 100644 --- a/test/system/appointments_test.rb +++ b/test/system/appointments_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "application_system_test_case" class AppointmentsTest < ApplicationSystemTestCase @@ -8,7 +10,7 @@ def check_list_item_with_name(item_name) end def list_item_containing(text) - find("li", text: text) + find("li", text:) end def select_first_available_date diff --git a/test/system/holds_test.rb b/test/system/holds_test.rb index 846c75f8f..0c75126a2 100644 --- a/test/system/holds_test.rb +++ b/test/system/holds_test.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + require "application_system_test_case" class HoldsTest < ApplicationSystemTestCase def list_item_containing(text) - find("li", text: text) + find("li", text:) end setup do diff --git a/test/system/item_filtering_test.rb b/test/system/item_filtering_test.rb index 177fe36c5..7915910c0 100644 --- a/test/system/item_filtering_test.rb +++ b/test/system/item_filtering_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "application_system_test_case" class ItemFilteringTest < ApplicationSystemTestCase diff --git a/test/system/member_checked_out_items_test.rb b/test/system/member_checked_out_items_test.rb index 202773b29..30e07d74c 100644 --- a/test/system/member_checked_out_items_test.rb +++ b/test/system/member_checked_out_items_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "application_system_test_case" class MemberCheckedOutItemsTest < ApplicationSystemTestCase diff --git a/test/system/member_profile_test.rb b/test/system/member_profile_test.rb index c99cb96a3..58bce2a7d 100644 --- a/test/system/member_profile_test.rb +++ b/test/system/member_profile_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "application_system_test_case" class MemberProfileTest < ApplicationSystemTestCase diff --git a/test/system/membership_renewal_test.rb b/test/system/membership_renewal_test.rb index fcc8a8664..0f73a0cac 100644 --- a/test/system/membership_renewal_test.rb +++ b/test/system/membership_renewal_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "application_system_test_case" class MembershipRenewalTest < ApplicationSystemTestCase @@ -69,7 +71,7 @@ def complete_square_checkout assert_emails 1 assert_delivered_email(to: @member.email) do |html, text| assert_includes html, "Thank you for renewing" - refute_includes html, "Your payment of" + assert_not_includes html, "Your payment of" end end @@ -167,7 +169,7 @@ def complete_square_checkout assert_emails 1 assert_delivered_email(to: @member.email) do |html, text| assert_includes html, "Thank you for renewing" - refute_includes html, "Your payment" + assert_not_includes html, "Your payment" end assert_equal 0, @member.adjustments.count diff --git a/test/system/multitenancy_test.rb b/test/system/multitenancy_test.rb index 1ecdf9f48..42e54e817 100644 --- a/test/system/multitenancy_test.rb +++ b/test/system/multitenancy_test.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + require "application_system_test_case" class MultitenancyTest < ApplicationSystemTestCase test "login to library" do member = create(:member, full_name: "Reggie Brower") - user = create(:user, member: member) + user = create(:user, member:) visit user_session_url diff --git a/test/system/pronoun_selection_test.rb b/test/system/pronoun_selection_test.rb index 20ddd679a..800387ce5 100644 --- a/test/system/pronoun_selection_test.rb +++ b/test/system/pronoun_selection_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "application_system_test_case" class PronounSelectionTest < ApplicationSystemTestCase diff --git a/test/system/user_signup_test.rb b/test/system/user_signup_test.rb index d531f69b3..2b158ba93 100644 --- a/test/system/user_signup_test.rb +++ b/test/system/user_signup_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "application_system_test_case" class UserSignupTest < ApplicationSystemTestCase @@ -52,7 +54,7 @@ def complete_first_three_steps assert_emails 1 assert_delivered_email(to: "nkjemisin@test.com") do |html, text| assert_includes html, "Thank you for signing up" - refute_includes html, "Your payment of" + assert_not_includes html, "Your payment of" end end @@ -143,7 +145,7 @@ def complete_first_three_steps assert_emails 1 assert_delivered_email(to: "nkjemisin@test.com") do |html, text| assert_includes html, "Thank you for signing up" - refute_includes html, "Your payment" + assert_not_includes html, "Your payment" end assert_equal 0, Member.last.adjustments.count diff --git a/test/system/volunteer/shifts_test.rb b/test/system/volunteer/shifts_test.rb index ce1465739..d9b59fb2b 100644 --- a/test/system/volunteer/shifts_test.rb +++ b/test/system/volunteer/shifts_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "application_system_test_case" module Volunteer diff --git a/test/test_helper.rb b/test/test_helper.rb index df93341b9..b00e2acb8 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + ENV["RAILS_ENV"] ||= "test" require_relative "../config/environment" require "rails/test_help"