diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7b2f3a2..2851ab5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -114,6 +114,7 @@ jobs: env: COMPOSE_FILE: docker-compose.yml:docker-compose.ci.yml DOCKER_APP_IMAGE: ${{ needs.merge.outputs.image }} + SECRET_KEY_BASE: ${{ secrets.SECRET_KEY_BASE }} steps: - name: Checkout code uses: actions/checkout@v4 diff --git a/.rubocop.yml b/.rubocop.yml index e20c7aa..e13a5f1 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,3 +1,9 @@ +plugins: + - rubocop-rails + - rubocop-rake + - rubocop-rspec + - rubocop-rspec_rails + AllCops: # Exclude generated files Exclude: @@ -6,11 +12,14 @@ AllCops: - 'node_modules/**/**/**/*' - 'lib/**/**' - 'db/*' + - 'config/initializers/new_framework_defaults_7_0.rb' - 'config/spring.rb' - 'config/puma.rb' + - 'spec/lib/secret_spec.rb' # this will be replaced by BerkeleyLibrary::Docker inherit_mode: merge: - Exclude + SuggestExtensions: false # Allow one line around block body (Layout/EmptyLines will still disallow two or more) Layout/EmptyLinesAroundBlockBody: @@ -92,6 +101,9 @@ Style/Lambda: Style/SingleLineBlockParams: Enabled: false +RSpec/InstanceVariable: + AssignmentOnly: true + ############################################################ # Enable newer cops @@ -177,7 +189,7 @@ Lint/TripleQuotes: # (new in 1.9) Enabled: true Style/IfWithBooleanLiteralBranches: # (new in 1.9) Enabled: true -Gemspec/DateAssignment: # (new in 1.10) +Gemspec/DeprecatedAttributeAssignment: # (new in 1.10) Enabled: true Style/HashConversion: # (new in 1.10) Enabled: true @@ -229,3 +241,325 @@ Style/MapToHash: # new in 1.24 Enabled: true Style/NestedFileDirname: # new in 1.26 Enabled: true +Gemspec/AddRuntimeDependency: # new in 1.65 + Enabled: true +Gemspec/AttributeAssignment: # new in 1.77 + Enabled: true +Gemspec/DevelopmentDependencies: # new in 1.44 + Enabled: true +Layout/EmptyLinesAfterModuleInclusion: # new in 1.79 + Enabled: true +Layout/LineContinuationLeadingSpace: # new in 1.31 + Enabled: true +Layout/LineContinuationSpacing: # new in 1.31 + Enabled: true +Lint/ArrayLiteralInRegexp: # new in 1.71 + Enabled: true +Lint/ConstantOverwrittenInRescue: # new in 1.31 + Enabled: true +Lint/ConstantReassignment: # new in 1.70 + Enabled: true +Lint/CopDirectiveSyntax: # new in 1.72 + Enabled: true +Lint/DuplicateMagicComment: # new in 1.37 + Enabled: true +Lint/DuplicateMatchPattern: # new in 1.50 + Enabled: true +Lint/DuplicateSetElement: # new in 1.67 + Enabled: true +Lint/HashNewWithKeywordArgumentsAsDefault: # new in 1.69 + Enabled: true +Lint/ItWithoutArgumentsInBlock: # new in 1.59 + Enabled: true +Lint/LiteralAssignmentInCondition: # new in 1.58 + Enabled: true +Lint/MixedCaseRange: # new in 1.53 + Enabled: true +Lint/NonAtomicFileOperation: # new in 1.31 + Enabled: true +Lint/NumericOperationWithConstantResult: # new in 1.69 + Enabled: true +Lint/RedundantRegexpQuantifiers: # new in 1.53 + Enabled: true +Lint/RedundantTypeConversion: # new in 1.72 + Enabled: true +Lint/RefinementImportMethods: # new in 1.27 + Enabled: true +Lint/RequireRangeParentheses: # new in 1.32 + Enabled: true +Lint/SharedMutableDefault: # new in 1.70 + Enabled: true +Lint/SuppressedExceptionInNumberConversion: # new in 1.72 + Enabled: true +Lint/UnescapedBracketInRegexp: # new in 1.68 + Enabled: true +Lint/UselessConstantScoping: # new in 1.72 + Enabled: true +Lint/UselessDefaultValueArgument: # new in 1.76 + Enabled: true +Lint/UselessDefined: # new in 1.69 + Enabled: true +Lint/UselessNumericOperation: # new in 1.66 + Enabled: true +Lint/UselessOr: # new in 1.76 + Enabled: true +Lint/UselessRescue: # new in 1.43 + Enabled: true +Metrics/CollectionLiteralLength: # new in 1.47 + Enabled: true +Naming/PredicateMethod: # new in 1.76 + Enabled: true +Security/CompoundHash: # new in 1.28 + Enabled: true +Style/AmbiguousEndlessMethodDefinition: # new in 1.68 + Enabled: true +Style/ArrayIntersect: # new in 1.40 + Enabled: true +Style/ArrayIntersectWithSingleElement: # new in 1.81 + Enabled: true +Style/BitwisePredicate: # new in 1.68 + Enabled: true +Style/CollectionQuerying: # new in 1.77 + Enabled: true +Style/CombinableDefined: # new in 1.68 + Enabled: true +Style/ComparableBetween: # new in 1.74 + Enabled: true +Style/ComparableClamp: # new in 1.44 + Enabled: true +Style/ConcatArrayLiterals: # new in 1.41 + Enabled: true +Style/DataInheritance: # new in 1.49 + Enabled: true +Style/DigChain: # new in 1.69 + Enabled: true +Style/DirEmpty: # new in 1.48 + Enabled: true +Style/EmptyHeredoc: # new in 1.32 + Enabled: true +Style/EmptyStringInsideInterpolation: # new in 1.76 + Enabled: true +Style/EnvHome: # new in 1.29 + Enabled: true +Style/ExactRegexpMatch: # new in 1.51 + Enabled: true +Style/FetchEnvVar: # new in 1.28 + Enabled: true +Style/FileEmpty: # new in 1.48 + Enabled: true +Style/FileNull: # new in 1.69 + Enabled: true +Style/FileTouch: # new in 1.69 + Enabled: true +Style/HashFetchChain: # new in 1.75 + Enabled: true +Style/HashSlice: # new in 1.71 + Enabled: true +Style/ItAssignment: # new in 1.70 + Enabled: true +Style/ItBlockParameter: # new in 1.75 + Enabled: true +Style/KeywordArgumentsMerging: # new in 1.68 + Enabled: true +Style/MagicCommentFormat: # new in 1.35 + Enabled: true +Style/MapCompactWithConditionalBlock: # new in 1.30 + Enabled: true +Style/MapIntoArray: # new in 1.63 + Enabled: true +Style/MapToSet: # new in 1.42 + Enabled: true +Style/MinMaxComparison: # new in 1.42 + Enabled: true +Style/ObjectThen: # new in 1.28 + Enabled: true +Style/OperatorMethodCall: # new in 1.37 + Enabled: true +Style/RedundantArrayConstructor: # new in 1.52 + Enabled: true +Style/RedundantArrayFlatten: # new in 1.76 + Enabled: true +Style/RedundantConstantBase: # new in 1.40 + Enabled: true +Style/RedundantCurrentDirectoryInPath: # new in 1.53 + Enabled: true +Style/RedundantDoubleSplatHashBraces: # new in 1.41 + Enabled: true +Style/RedundantEach: # new in 1.38 + Enabled: true +Style/RedundantFilterChain: # new in 1.52 + Enabled: true +Style/RedundantFormat: # new in 1.72 + Enabled: true +Style/RedundantHeredocDelimiterQuotes: # new in 1.45 + Enabled: true +Style/RedundantInitialize: # new in 1.27 + Enabled: true +Style/RedundantInterpolationUnfreeze: # new in 1.66 + Enabled: true +Style/RedundantLineContinuation: # new in 1.49 + Enabled: true +Style/RedundantRegexpArgument: # new in 1.53 + Enabled: true +Style/RedundantRegexpConstructor: # new in 1.52 + Enabled: true +Style/RedundantStringEscape: # new in 1.37 + Enabled: true +Style/ReturnNilInPredicateMethodDefinition: # new in 1.53 + Enabled: true +Style/SafeNavigationChainLength: # new in 1.68 + Enabled: true +Style/SendWithLiteralMethodName: # new in 1.64 + Enabled: true +Style/SingleLineDoEndBlock: # new in 1.57 + Enabled: true +Style/SuperArguments: # new in 1.64 + Enabled: true +Style/SuperWithArgsParentheses: # new in 1.58 + Enabled: true +Style/YAMLFileRead: # new in 1.53 + Enabled: true +Rails/ActionControllerFlashBeforeRender: # new in 2.16 + Enabled: true +Rails/ActionControllerTestCase: # new in 2.14 + Enabled: true +Rails/ActionOrder: # new in 2.17 + Enabled: true +Rails/ActiveRecordCallbacksOrder: # new in 2.7 + Enabled: true +Rails/ActiveSupportOnLoad: # new in 2.16 + Enabled: true +Rails/AddColumnIndex: # new in 2.11 + Enabled: true +Rails/AfterCommitOverride: # new in 2.8 + Enabled: true +Rails/AttributeDefaultBlockValue: # new in 2.9 + Enabled: true +Rails/CompactBlank: # new in 2.13 + Enabled: true +Rails/DangerousColumnNames: # new in 2.21 + Enabled: true +Rails/DeprecatedActiveModelErrorsMethods: # new in 2.14 + Enabled: true +Rails/DotSeparatedKeys: # new in 2.15 + Enabled: true +Rails/DuplicateAssociation: # new in 2.14 + Enabled: true +Rails/DuplicateScope: # new in 2.14 + Enabled: true +Rails/DurationArithmetic: # new in 2.13 + Enabled: true +Rails/EagerEvaluationLogMessage: # new in 2.11 + Enabled: true +Rails/EnumSyntax: # new in 2.26 + Enabled: true +Rails/EnvLocal: # new in 2.22 + Enabled: true +Rails/ExpandedDateRange: # new in 2.11 + Enabled: true +Rails/FindById: # new in 2.7 + Enabled: true +Rails/FindByOrAssignmentMemoization: # new in 2.33 + Enabled: true +Rails/FreezeTime: # new in 2.16 + Enabled: true +Rails/HttpStatusNameConsistency: # new in 2.34 + Enabled: true +Rails/I18nLazyLookup: # new in 2.14 + Enabled: true +Rails/I18nLocaleAssignment: # new in 2.11 + Enabled: true +Rails/I18nLocaleTexts: # new in 2.14 + Enabled: true +Rails/IgnoredColumnsAssignment: # new in 2.17 + Enabled: true +Rails/Inquiry: # new in 2.7 + Enabled: true +Rails/MailerName: # new in 2.7 + Enabled: true +Rails/MatchRoute: # new in 2.7 + Enabled: true +Rails/MigrationClassName: # new in 2.14 + Enabled: true +Rails/MultipleRoutePaths: # new in 2.29 + Enabled: true +Rails/NegateInclude: # new in 2.7 + Enabled: true +Rails/OrderArguments: # new in 2.33 + Enabled: true +Rails/Pluck: # new in 2.7 + Enabled: true +Rails/PluckInWhere: # new in 2.7 + Enabled: true +Rails/RedirectBackOrTo: # new in 2.34 + Enabled: true +Rails/RedundantActiveRecordAllMethod: # new in 2.21 + Enabled: true +Rails/RedundantPresenceValidationOnBelongsTo: # new in 2.13 + Enabled: true +Rails/RedundantTravelBack: # new in 2.12 + Enabled: true +Rails/RenderInline: # new in 2.7 + Enabled: true +Rails/RenderPlainText: # new in 2.7 + Enabled: true +Rails/ResponseParsedBody: # new in 2.18 + Enabled: true +Rails/RootJoinChain: # new in 2.13 + Enabled: true +Rails/RootPathnameMethods: # new in 2.16 + Enabled: true +Rails/RootPublicPath: # new in 2.15 + Enabled: true +Rails/SelectMap: # new in 2.21 + Enabled: true +Rails/ShortI18n: # new in 2.7 + Enabled: true +Rails/SquishedSQLHeredocs: # new in 2.8 + Enabled: true +Rails/StripHeredoc: # new in 2.15 + Enabled: true +Rails/StrongParametersExpect: # new in 2.29 + Enabled: true +Rails/ThreeStateBooleanColumn: # new in 2.19 + Enabled: true +Rails/TimeZoneAssignment: # new in 2.10 + Enabled: true +Rails/ToFormattedS: # new in 2.15 + Enabled: true +Rails/ToSWithArgument: # new in 2.16 + Enabled: true +Rails/TopLevelHashWithIndifferentAccess: # new in 2.16 + Enabled: true +Rails/TransactionExitStatement: # new in 2.14 + Enabled: true +Rails/UnusedRenderContent: # new in 2.21 + Enabled: true +Rails/WhereEquals: # new in 2.9 + Enabled: true +Rails/WhereExists: # new in 2.7 + Enabled: true +Rails/WhereMissing: # new in 2.16 + Enabled: true +Rails/WhereNot: # new in 2.8 + Enabled: true +Rails/WhereNotWithMultipleConditions: # new in 2.17 + Enabled: true +Rails/WhereRange: # new in 2.25 + Enabled: true +RSpec/IncludeExamples: # new in 3.6 + Enabled: true +RSpec/LeakyLocalVariable: # new in 3.8 + Enabled: true +RSpecRails/AvoidSetupHook: # new in 2.4 + Enabled: true +RSpecRails/HaveHttpStatus: # new in 2.12 + Enabled: true +RSpecRails/InferredSpecType: # new in 2.14 + Enabled: false +RSpecRails/MinitestAssertions: # new in 2.17 + Enabled: true +RSpecRails/NegationBeValid: # new in 2.23 + Enabled: true +RSpecRails/TravelAround: # new in 2.19 + Enabled: true \ No newline at end of file diff --git a/.ruby-version b/.ruby-version index e76033b..f0f3ba8 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -ruby-3.0.3 +ruby-3.3.10 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index c7a1dff..8783df2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ # The base stage scaffolds elements which are common to building and running # the application, such as installing ca-certificates, creating the app user, # and installing runtime system dependencies. -FROM ruby:3.0.3-slim AS base +FROM ruby:3.3-slim AS base # ------------------------------------------------------------ # Declarative metadata @@ -38,7 +38,8 @@ RUN apt-get install -y --no-install-recommends \ curl \ git \ gpg \ - libmariadb-dev + libmariadb-dev \ + libyaml-dev # Install Node.js and Yarn from their own repositories @@ -115,13 +116,16 @@ RUN apt-get install -y --no-install-recommends \ USER $APP_USER # Base image ships with an older version of bundler -RUN gem install bundler --version 2.2.33 +RUN gem install bundler --version 2.5.22 # Install gems. We don't enforce the validity of the Gemfile.lock until the # final (production) stage. COPY --chown=$APP_USER:$APP_USER Gemfile* ./ RUN bundle install +COPY --chown=$APP_USER:$APP_USER package.json yarn.lock ./ +RUN yarn install + # Copy the rest of the codebase. We do this after bundle-install so that # changes unrelated to the gemset don't invalidate the cache and force a slow # re-install. diff --git a/Gemfile b/Gemfile index d089af9..2d86b82 100644 --- a/Gemfile +++ b/Gemfile @@ -4,6 +4,8 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" } ruby '~> 3.0' gem 'amazing_print', '~> 1.1' +gem 'berkeley_library-docker' +gem 'berkeley_library-logging' gem 'bootstrap-sass' gem 'bundler-audit' gem 'coffee-rails' @@ -11,11 +13,11 @@ gem 'font-awesome-rails' gem 'jbuilder', '~> 2.7' gem 'jquery-rails', '~> 4.4' gem 'lograge', '~> 0.11' -gem 'mysql2', '~> 0.5' -gem 'nokogiri', '~> 1.13' +gem 'mysql2', '~> 0.5.4' +gem 'nokogiri', '~> 1.18' gem 'ougai', '~> 1.8' -gem 'puma', '~> 4.1' -gem 'rails', '~> 6.1' +gem 'puma', '~> 6.6.1' +gem 'rails', '~> 8.0.0' gem 'rails-healthcheck' gem 'rake' gem 'sass-rails', '>= 6' @@ -25,19 +27,23 @@ gem 'will_paginate' group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', platforms: %i[mri mingw x64_mingw] - gem 'rspec-rails' + gem 'rspec-rails', '~> 8.0' gem 'simplecov', require: false gem 'simplecov-rcov', require: false end group :development do gem 'listen', '~> 3.2' - gem 'rubocop', '~> 1.26.0' + gem 'rubocop', '~> 1.81.6', require: false + gem 'rubocop-rails', '~> 2.34.1', require: false + gem 'rubocop-rake', require: false + gem 'rubocop-rspec', require: false + gem 'rubocop-rspec_rails', require: false gem 'web-console', '>= 3.3.0' end group :test do - gem 'brakeman', '~> 4.8' + gem 'brakeman', '~> 7.0' gem 'capybara', '>= 2.15' gem 'rspec_junit_formatter', '~> 0.4.1' gem 'selenium-webdriver' diff --git a/Gemfile.lock b/Gemfile.lock index e2459df..c9ac258 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,91 +1,113 @@ GEM remote: https://rubygems.org/ specs: - actioncable (6.1.5.1) - actionpack (= 6.1.5.1) - activesupport (= 6.1.5.1) + actioncable (8.0.4) + actionpack (= 8.0.4) + activesupport (= 8.0.4) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (6.1.5.1) - actionpack (= 6.1.5.1) - activejob (= 6.1.5.1) - activerecord (= 6.1.5.1) - activestorage (= 6.1.5.1) - activesupport (= 6.1.5.1) - mail (>= 2.7.1) - actionmailer (6.1.5.1) - actionpack (= 6.1.5.1) - actionview (= 6.1.5.1) - activejob (= 6.1.5.1) - activesupport (= 6.1.5.1) - mail (~> 2.5, >= 2.5.4) - rails-dom-testing (~> 2.0) - actionpack (6.1.5.1) - actionview (= 6.1.5.1) - activesupport (= 6.1.5.1) - rack (~> 2.0, >= 2.0.9) + zeitwerk (~> 2.6) + actionmailbox (8.0.4) + actionpack (= 8.0.4) + activejob (= 8.0.4) + activerecord (= 8.0.4) + activestorage (= 8.0.4) + activesupport (= 8.0.4) + mail (>= 2.8.0) + actionmailer (8.0.4) + actionpack (= 8.0.4) + actionview (= 8.0.4) + activejob (= 8.0.4) + activesupport (= 8.0.4) + mail (>= 2.8.0) + rails-dom-testing (~> 2.2) + actionpack (8.0.4) + actionview (= 8.0.4) + activesupport (= 8.0.4) + nokogiri (>= 1.8.5) + rack (>= 2.2.4) + rack-session (>= 1.0.1) rack-test (>= 0.6.3) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (6.1.5.1) - actionpack (= 6.1.5.1) - activerecord (= 6.1.5.1) - activestorage (= 6.1.5.1) - activesupport (= 6.1.5.1) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + useragent (~> 0.16) + actiontext (8.0.4) + actionpack (= 8.0.4) + activerecord (= 8.0.4) + activestorage (= 8.0.4) + activesupport (= 8.0.4) + globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (6.1.5.1) - activesupport (= 6.1.5.1) + actionview (8.0.4) + activesupport (= 8.0.4) builder (~> 3.1) - erubi (~> 1.4) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.1, >= 1.2.0) - activejob (6.1.5.1) - activesupport (= 6.1.5.1) + erubi (~> 1.11) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + activejob (8.0.4) + activesupport (= 8.0.4) globalid (>= 0.3.6) - activemodel (6.1.5.1) - activesupport (= 6.1.5.1) - activerecord (6.1.5.1) - activemodel (= 6.1.5.1) - activesupport (= 6.1.5.1) - activestorage (6.1.5.1) - actionpack (= 6.1.5.1) - activejob (= 6.1.5.1) - activerecord (= 6.1.5.1) - activesupport (= 6.1.5.1) + activemodel (8.0.4) + activesupport (= 8.0.4) + activerecord (8.0.4) + activemodel (= 8.0.4) + activesupport (= 8.0.4) + timeout (>= 0.4.0) + activestorage (8.0.4) + actionpack (= 8.0.4) + activejob (= 8.0.4) + activerecord (= 8.0.4) + activesupport (= 8.0.4) marcel (~> 1.0) - mini_mime (>= 1.1.0) - activesupport (6.1.5.1) - concurrent-ruby (~> 1.0, >= 1.0.2) + activesupport (8.0.4) + base64 + benchmark (>= 0.3) + bigdecimal + concurrent-ruby (~> 1.0, >= 1.3.1) + connection_pool (>= 2.2.5) + drb i18n (>= 1.6, < 2) + logger (>= 1.4.2) minitest (>= 5.1) - tzinfo (~> 2.0) - zeitwerk (~> 2.3) - addressable (2.8.0) - public_suffix (>= 2.0.2, < 5.0) - amazing_print (1.4.0) - ast (2.4.2) - autoprefixer-rails (10.4.2.0) + securerandom (>= 0.3) + tzinfo (~> 2.0, >= 2.0.5) + uri (>= 0.13.1) + addressable (2.8.8) + public_suffix (>= 2.0.2, < 8.0) + amazing_print (1.8.1) + ast (2.4.3) + autoprefixer-rails (10.4.21.0) execjs (~> 2) + base64 (0.3.0) + benchmark (0.5.0) + berkeley_library-docker (0.2.0) + berkeley_library-logging (0.2.7) + activesupport (>= 6) + amazing_print (~> 1.1) + colorize (~> 0.8.1) + lograge (~> 0.11) + ougai (~> 1.8) + bigdecimal (3.3.1) bindex (0.8.1) bootstrap-sass (3.4.1) autoprefixer-rails (>= 5.2.1) sassc (>= 2.0.0) - brakeman (4.10.1) - builder (3.2.4) - bundler-audit (0.9.0.1) + brakeman (7.1.1) + racc + builder (3.3.0) + bundler-audit (0.9.2) bundler (>= 1.2.0, < 3) thor (~> 1.0) - byebug (11.1.3) - capybara (3.36.0) + byebug (12.0.0) + capybara (3.40.0) addressable matrix mini_mime (>= 0.1.3) - nokogiri (~> 1.8) + nokogiri (~> 1.11) rack (>= 1.6.0) rack-test (>= 0.6.3) regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) - childprocess (4.1.0) coffee-rails (5.0.0) coffee-script (>= 2.2.0) railties (>= 5.2.0) @@ -93,139 +115,211 @@ GEM coffee-script-source execjs coffee-script-source (1.12.2) - concurrent-ruby (1.1.10) + colorize (0.8.1) + concurrent-ruby (1.3.5) + connection_pool (2.5.5) crass (1.0.6) - diff-lcs (1.5.0) - docile (1.4.0) - erubi (1.10.0) - execjs (2.8.1) - ffi (1.15.5) - font-awesome-rails (4.7.0.8) - railties (>= 3.2, < 8.0) - globalid (1.0.0) - activesupport (>= 5.0) - i18n (1.10.0) + date (3.5.0) + diff-lcs (1.6.2) + docile (1.4.1) + drb (2.2.3) + erb (6.0.0) + erubi (1.13.1) + execjs (2.10.0) + ffi (1.17.2-aarch64-linux-gnu) + ffi (1.17.2-arm64-darwin) + ffi (1.17.2-x86_64-linux-gnu) + font-awesome-rails (4.7.0.9) + railties (>= 3.2, < 9.0) + globalid (1.3.0) + activesupport (>= 6.1) + i18n (1.14.7) concurrent-ruby (~> 1.0) - jbuilder (2.11.5) - actionview (>= 5.0.0) - activesupport (>= 5.0.0) - jquery-rails (4.4.0) + io-console (0.8.1) + irb (1.15.3) + pp (>= 0.6.0) + rdoc (>= 4.0.0) + reline (>= 0.4.2) + jbuilder (2.14.1) + actionview (>= 7.0.0) + activesupport (>= 7.0.0) + jquery-rails (4.6.1) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) - listen (3.7.1) + json (2.16.0) + language_server-protocol (3.17.0.5) + lint_roller (1.1.0) + listen (3.9.0) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) - lograge (0.11.2) + logger (1.7.0) + lograge (0.14.0) actionpack (>= 4) activesupport (>= 4) railties (>= 4) request_store (~> 1.0) - loofah (2.17.0) + loofah (2.24.1) crass (~> 1.0.2) - nokogiri (>= 1.5.9) - mail (2.7.1) + nokogiri (>= 1.12.0) + mail (2.9.0) + logger mini_mime (>= 0.1.1) - marcel (1.0.2) - matrix (0.4.2) - method_source (1.0.0) - mini_mime (1.1.2) - minitest (5.15.0) - mysql2 (0.5.3) - nio4r (2.5.8) - nokogiri (1.13.4-aarch64-linux) + net-imap + net-pop + net-smtp + marcel (1.1.0) + matrix (0.4.3) + mini_mime (1.1.5) + minitest (5.26.2) + mysql2 (0.5.7) + bigdecimal + net-imap (0.5.12) + date + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.2.2) + timeout + net-smtp (0.5.1) + net-protocol + nio4r (2.7.5) + nokogiri (1.18.10-aarch64-linux-gnu) racc (~> 1.4) - nokogiri (1.13.4-arm64-darwin) + nokogiri (1.18.10-arm64-darwin) racc (~> 1.4) - nokogiri (1.13.4-x86_64-darwin) + nokogiri (1.18.10-x86_64-linux-gnu) racc (~> 1.4) - nokogiri (1.13.4-x86_64-linux) - racc (~> 1.4) - oj (3.13.11) + oj (3.16.12) + bigdecimal (>= 3.0) + ostruct (>= 0.2) + ostruct (0.6.3) ougai (1.9.1) oj (~> 3.10) - parallel (1.21.0) - parser (3.1.1.0) + parallel (1.27.0) + parser (3.3.10.0) ast (~> 2.4.1) - public_suffix (4.0.6) - puma (4.3.11) + racc + pp (0.6.3) + prettyprint + prettyprint (0.2.0) + prism (1.6.0) + psych (5.2.6) + date + stringio + public_suffix (7.0.0) + puma (6.6.1) nio4r (~> 2.0) - racc (1.6.0) - rack (2.2.3) - rack-proxy (0.7.2) + racc (1.8.1) + rack (3.2.4) + rack-proxy (0.7.7) rack - rack-test (1.1.0) - rack (>= 1.0, < 3) - rails (6.1.5.1) - actioncable (= 6.1.5.1) - actionmailbox (= 6.1.5.1) - actionmailer (= 6.1.5.1) - actionpack (= 6.1.5.1) - actiontext (= 6.1.5.1) - actionview (= 6.1.5.1) - activejob (= 6.1.5.1) - activemodel (= 6.1.5.1) - activerecord (= 6.1.5.1) - activestorage (= 6.1.5.1) - activesupport (= 6.1.5.1) + rack-session (2.1.1) + base64 (>= 0.1.0) + rack (>= 3.0.0) + rack-test (2.2.0) + rack (>= 1.3) + rackup (2.2.1) + rack (>= 3) + rails (8.0.4) + actioncable (= 8.0.4) + actionmailbox (= 8.0.4) + actionmailer (= 8.0.4) + actionpack (= 8.0.4) + actiontext (= 8.0.4) + actionview (= 8.0.4) + activejob (= 8.0.4) + activemodel (= 8.0.4) + activerecord (= 8.0.4) + activestorage (= 8.0.4) + activesupport (= 8.0.4) bundler (>= 1.15.0) - railties (= 6.1.5.1) - sprockets-rails (>= 2.0.0) - rails-dom-testing (2.0.3) - activesupport (>= 4.2.0) + railties (= 8.0.4) + rails-dom-testing (2.3.0) + activesupport (>= 5.0.0) + minitest nokogiri (>= 1.6) rails-healthcheck (1.4.0) actionpack railties - rails-html-sanitizer (1.4.2) - loofah (~> 2.3) - railties (6.1.5.1) - actionpack (= 6.1.5.1) - activesupport (= 6.1.5.1) - method_source + rails-html-sanitizer (1.6.2) + loofah (~> 2.21) + nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0) + railties (8.0.4) + actionpack (= 8.0.4) + activesupport (= 8.0.4) + irb (~> 1.13) + rackup (>= 1.0.0) rake (>= 12.2) - thor (~> 1.0) + thor (~> 1.0, >= 1.2.2) + tsort (>= 0.2) + zeitwerk (~> 2.6) rainbow (3.1.1) - rake (13.0.6) - rb-fsevent (0.11.1) - rb-inotify (0.10.1) + rake (13.3.1) + rb-fsevent (0.11.2) + rb-inotify (0.11.1) ffi (~> 1.0) - regexp_parser (2.2.1) - request_store (1.5.1) + rdoc (6.16.0) + erb + psych (>= 4.0.0) + tsort + regexp_parser (2.11.3) + reline (0.6.3) + io-console (~> 0.5) + request_store (1.7.0) rack (>= 1.4) - rexml (3.2.5) - rspec-core (3.11.0) - rspec-support (~> 3.11.0) - rspec-expectations (3.11.0) + rexml (3.4.4) + rspec-core (3.13.6) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.5) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.11.0) - rspec-mocks (3.11.0) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.7) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.11.0) - rspec-rails (5.1.1) - actionpack (>= 5.2) - activesupport (>= 5.2) - railties (>= 5.2) - rspec-core (~> 3.10) - rspec-expectations (~> 3.10) - rspec-mocks (~> 3.10) - rspec-support (~> 3.10) - rspec-support (3.11.0) + rspec-support (~> 3.13.0) + rspec-rails (8.0.2) + actionpack (>= 7.2) + activesupport (>= 7.2) + railties (>= 7.2) + rspec-core (~> 3.13) + rspec-expectations (~> 3.13) + rspec-mocks (~> 3.13) + rspec-support (~> 3.13) + rspec-support (3.13.6) rspec_junit_formatter (0.4.1) rspec-core (>= 2, < 4, != 2.12.0) - rubocop (1.26.0) + rubocop (1.81.7) + json (~> 2.3) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.1.0) parallel (~> 1.10) - parser (>= 3.1.0.0) + parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) - regexp_parser (>= 1.8, < 3.0) - rexml - rubocop-ast (>= 1.16.0, < 2.0) + regexp_parser (>= 2.9.3, < 3.0) + rubocop-ast (>= 1.47.1, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.16.0) - parser (>= 3.1.1.0) - ruby-progressbar (1.11.0) - rubyzip (2.3.2) + unicode-display_width (>= 2.4.0, < 4.0) + rubocop-ast (1.48.0) + parser (>= 3.3.7.2) + prism (~> 1.4) + rubocop-rails (2.34.1) + activesupport (>= 4.2.0) + lint_roller (~> 1.1) + rack (>= 1.1) + rubocop (>= 1.75.0, < 2.0) + rubocop-ast (>= 1.44.0, < 2.0) + rubocop-rake (0.7.1) + lint_roller (~> 1.1) + rubocop (>= 1.72.1) + rubocop-rspec (3.8.0) + lint_roller (~> 1.1) + rubocop (~> 1.81) + rubocop-rspec_rails (2.32.0) + lint_roller (~> 1.1) + rubocop (~> 1.72, >= 1.72.1) + rubocop-rspec (~> 3.5) + ruby-progressbar (1.13.0) + rubyzip (3.2.2) sass-rails (6.0.0) sassc-rails (~> 2.1, >= 2.1.1) sassc (2.4.0) @@ -236,60 +330,73 @@ GEM sprockets (> 3.0) sprockets-rails tilt - selenium-webdriver (4.1.0) - childprocess (>= 0.5, < 5.0) + securerandom (0.4.1) + selenium-webdriver (4.38.0) + base64 (~> 0.2) + logger (~> 1.4) rexml (~> 3.2, >= 3.2.5) - rubyzip (>= 1.2.2) - semantic_range (3.0.0) - simplecov (0.21.2) + rubyzip (>= 1.2.2, < 4.0) + websocket (~> 1.0) + semantic_range (3.1.0) + simplecov (0.22.0) docile (~> 1.1) simplecov-html (~> 0.11) simplecov_json_formatter (~> 0.1) - simplecov-html (0.12.3) - simplecov-rcov (0.2.3) + simplecov-html (0.13.2) + simplecov-rcov (0.3.7) simplecov (>= 0.4.1) simplecov_json_formatter (0.1.4) - sprockets (4.0.3) + sprockets (4.2.2) concurrent-ruby (~> 1.0) - rack (> 1, < 3) - sprockets-rails (3.4.2) - actionpack (>= 5.2) - activesupport (>= 5.2) + logger + rack (>= 2.2.4, < 4) + sprockets-rails (3.5.2) + actionpack (>= 6.1) + activesupport (>= 6.1) sprockets (>= 3.0.0) - thor (1.2.1) - tilt (2.0.10) - tzinfo (2.0.4) + stringio (3.1.8) + thor (1.4.0) + tilt (2.6.1) + timeout (0.4.4) + tsort (0.2.0) + tzinfo (2.0.6) concurrent-ruby (~> 1.0) - unicode-display_width (2.1.0) - web-console (4.2.0) + unicode-display_width (3.2.0) + unicode-emoji (~> 4.1) + unicode-emoji (4.1.0) + uri (1.1.1) + useragent (0.16.11) + web-console (4.2.1) actionview (>= 6.0.0) activemodel (>= 6.0.0) bindex (>= 0.4.0) railties (>= 6.0.0) - webpacker (5.4.3) + webpacker (5.4.4) activesupport (>= 5.2) rack-proxy (>= 0.6.1) railties (>= 5.2) semantic_range (>= 2.3.0) - websocket-driver (0.7.5) + websocket (1.2.11) + websocket-driver (0.8.0) + base64 websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) - will_paginate (3.3.1) + will_paginate (4.0.1) xpath (3.2.0) nokogiri (~> 1.8) - zeitwerk (2.5.4) + zeitwerk (2.7.3) PLATFORMS - aarch64-linux - arm64-darwin - arm64-darwin-21 - x86_64-darwin + aarch64-linux-gnu + arm64-darwin-23 x86_64-linux DEPENDENCIES amazing_print (~> 1.1) + berkeley_library-docker + berkeley_library-logging bootstrap-sass - brakeman (~> 4.8) + brakeman (~> 7.0) bundler-audit byebug capybara (>= 2.15) @@ -299,16 +406,20 @@ DEPENDENCIES jquery-rails (~> 4.4) listen (~> 3.2) lograge (~> 0.11) - mysql2 (~> 0.5) - nokogiri (~> 1.13) + mysql2 (~> 0.5.4) + nokogiri (~> 1.18) ougai (~> 1.8) - puma (~> 4.1) - rails (~> 6.1) + puma (~> 6.6.1) + rails (~> 8.0.0) rails-healthcheck rake - rspec-rails + rspec-rails (~> 8.0) rspec_junit_formatter (~> 0.4.1) - rubocop (~> 1.26.0) + rubocop (~> 1.81.6) + rubocop-rails (~> 2.34.1) + rubocop-rake + rubocop-rspec + rubocop-rspec_rails sass-rails (>= 6) selenium-webdriver simplecov @@ -318,7 +429,7 @@ DEPENDENCIES will_paginate RUBY VERSION - ruby 3.0.3p157 + ruby 3.3.10p183 BUNDLED WITH - 2.2.33 + 2.5.22 diff --git a/Rakefile b/Rakefile index d5d0847..64a6655 100644 --- a/Rakefile +++ b/Rakefile @@ -14,7 +14,7 @@ task setup: %w[db:setup] # Check (setup + coverage) desc 'Set up, check test coverage' -task :check do +task check: :environment do ENV['RAILS_ENV'] = 'test' Rake::Task[:setup].invoke Rake::Task[:coverage].invoke diff --git a/app/controllers/searchcase_controller.rb b/app/controllers/searchcase_controller.rb index fb18e81..ff63316 100644 --- a/app/controllers/searchcase_controller.rb +++ b/app/controllers/searchcase_controller.rb @@ -8,7 +8,7 @@ def display @return = @return.paginate(page: params[:page], per_page: 100) return unless @return.empty? - flash[:notice] = 'Your query returned 0 results. please try another search term' + flash[:notice] = 'Your query returned 0 results. please try another search term' # rubocop:disable Rails/I18nLocaleTexts redirect_to action: :search end @@ -27,12 +27,12 @@ def sanitize_result def populate_search if @result.empty? - SearchCasefile.all.order(:LASTNAME, :FIRSTNAME) + SearchCasefile.order(:LASTNAME, :FIRSTNAME) else SearchCasefile .find_by_sql(['select *, MATCH(LASTNAME,FIRSTNAME,DESTINATION,' \ - 'BIRTHPLACE,PORT,DATE,SHIP) AGAINST(:search in boolean mode) as' \ - ' matchcount from NARA_CaseFiles where MATCH(LASTNAME,FIRSTNAME' \ + 'BIRTHPLACE,PORT,DATE,SHIP) AGAINST(:search in boolean mode) as ' \ + 'matchcount from NARA_CaseFiles where MATCH(LASTNAME,FIRSTNAME' \ ',DESTINATION,BIRTHPLACE,PORT,DATE,SHIP) AGAINST(:search in boolean ' \ "mode) = #{@query_count} order by LASTNAME,FIRSTNAME", { search: @result }]) end @@ -41,7 +41,7 @@ def populate_search def full_display @result = params[:data] @return = SearchCasefile - .where('Case_ID = ?', @result) + .where(Case_ID: @result) .select(:LASTNAME, :FIRSTNAME, :MIDDLENAME, :BOXNUMBER, :SERIES, :CASENUMBER, :SHIP, :DATE, :DESTINATION, :BIRTHPLACE, :BIRTHPLACE_CITY, :BIRTHPLACE_STATE, :DOB, :AGE, :GENDER, diff --git a/app/models/application_record.rb b/app/models/application_record.rb new file mode 100644 index 0000000..10a4cba --- /dev/null +++ b/app/models/application_record.rb @@ -0,0 +1,3 @@ +class ApplicationRecord < ActiveRecord::Base + self.abstract_class = true +end diff --git a/app/models/nara_casefile.rb b/app/models/nara_casefile.rb index e595248..8e4556b 100644 --- a/app/models/nara_casefile.rb +++ b/app/models/nara_casefile.rb @@ -1,4 +1,4 @@ -class NaraCasefile < ActiveRecord::Base +class NaraCasefile < ApplicationRecord self.table_name = 'NARA_CaseFiles' self.primary_key = 'Case_ID' end diff --git a/app/models/search_casefile.rb b/app/models/search_casefile.rb index cca2a38..a8bc3e4 100644 --- a/app/models/search_casefile.rb +++ b/app/models/search_casefile.rb @@ -1,4 +1,4 @@ -class SearchCasefile < ActiveRecord::Base +class SearchCasefile < ApplicationRecord self.table_name = 'NARA_CaseFiles' self.primary_key = 'Case_ID' end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 84116a6..c1278c0 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -1,14 +1,14 @@ - NARA + Early Arrivals Search (EARS) <%= stylesheet_link_tag :application %> <%= csrf_meta_tags %>
- <%= link_to image_tag(asset_path('nara.jpg')),"https://bancroft.berkeley.edu/collections/chinese-immigration-to-the-united-states-1884-1944/" %> + <%= link_to image_tag(asset_path('nara.jpg')),"https://web.archive.org/web/20220124061848/https://bancroft.berkeley.edu/collections/chinese-immigration-to-the-united-states-1884-1944/index.html" %>

The Early Arrivals Records Search (EARS)

@@ -18,7 +18,7 @@ <%= yield %> diff --git a/bin/brakeman b/bin/brakeman index 4b79003..ace1c9b 100755 --- a/bin/brakeman +++ b/bin/brakeman @@ -1,29 +1,7 @@ #!/usr/bin/env ruby -# frozen_string_literal: true - -# -# This file was generated by Bundler. -# -# The application 'brakeman' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -bundle_binstub = File.expand_path("../bundle", __FILE__) - -if File.file?(bundle_binstub) - if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ - load(bundle_binstub) - else - abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. -Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") - end -end - require "rubygems" require "bundler/setup" +ARGV.unshift("--ensure-latest") + load Gem.bin_path("brakeman", "brakeman") diff --git a/bin/dev b/bin/dev new file mode 100755 index 0000000..5f91c20 --- /dev/null +++ b/bin/dev @@ -0,0 +1,2 @@ +#!/usr/bin/env ruby +exec "./bin/rails", "server", *ARGV diff --git a/bin/rails b/bin/rails index 6fb4e40..efc0377 100755 --- a/bin/rails +++ b/bin/rails @@ -1,4 +1,4 @@ #!/usr/bin/env ruby -APP_PATH = File.expand_path('../config/application', __dir__) +APP_PATH = File.expand_path("../config/application", __dir__) require_relative "../config/boot" require "rails/commands" diff --git a/bin/rubocop b/bin/rubocop new file mode 100755 index 0000000..40330c0 --- /dev/null +++ b/bin/rubocop @@ -0,0 +1,8 @@ +#!/usr/bin/env ruby +require "rubygems" +require "bundler/setup" + +# explicit rubocop config increases performance slightly while avoiding config confusion. +ARGV.unshift("--config", File.expand_path("../.rubocop.yml", __dir__)) + +load Gem.bin_path("rubocop", "rubocop") diff --git a/bin/setup b/bin/setup index 90700ac..be3db3c 100755 --- a/bin/setup +++ b/bin/setup @@ -1,11 +1,10 @@ #!/usr/bin/env ruby 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 ==") + system(*args, exception: true) end FileUtils.chdir APP_ROOT do @@ -13,24 +12,23 @@ FileUtils.chdir APP_ROOT do # This script is idempotent, so that you can run it at any time and get an expectable outcome. # Add necessary setup steps to this file. - puts '== Installing dependencies ==' - system! 'gem install bundler --conservative' - system('bundle check') || system!('bundle install') - - # Install JavaScript dependencies - system! 'bin/yarn' + puts "== Installing dependencies ==" + system("bundle check") || system!("bundle install") # puts "\n== Copying sample files ==" - # unless File.exist?('config/database.yml') - # FileUtils.cp 'config/database.yml.sample', 'config/database.yml' + # unless File.exist?("config/database.yml") + # FileUtils.cp "config/database.yml.sample", "config/database.yml" # end puts "\n== Preparing database ==" - system! 'bin/rails db:prepare' + system! "bin/rails db:prepare" 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' + unless ARGV.include?("--skip-server") + puts "\n== Starting development server ==" + STDOUT.flush # flush the output before exec(2) so that it displays + exec "bin/dev" + end end diff --git a/bin/webpack b/bin/webpack index 1031168..bbf8892 100755 --- a/bin/webpack +++ b/bin/webpack @@ -8,7 +8,7 @@ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", Pathname.new(__FILE__).realpath) require "bundler/setup" - +require "logger" require "webpacker" require "webpacker/webpack_runner" diff --git a/config/application.rb b/config/application.rb index f54f76e..684c776 100644 --- a/config/application.rb +++ b/config/application.rb @@ -1,6 +1,3 @@ -require_relative '../lib/docker' -Docker::Secret.setup_environment! - require_relative 'boot' require 'rails/all' @@ -12,12 +9,19 @@ module NewNara class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. - config.load_defaults 6.0 + config.load_defaults 8.0 - # ############################################################ - # Customize logging + # Please, add to the `ignore` list any other `lib` subdirectories that do + # not contain `.rb` files, or that should not be reloaded or eager loaded. + # Common ones are `templates`, `generators`, or `middleware`, for example. + config.autoload_lib(ignore: %w[assets tasks]) - require 'lib_it/logging' - LibIT::Logging.configure! + # Configuration for the application, engines, and railties goes here. + # + # These settings can be overridden in specific environments using the files + # in config/environments, which are processed later. + # + # config.time_zone = "Central Time (US & Canada)" + # config.eager_load_paths << Rails.root.join("extras") end end diff --git a/config/environments/development.rb b/config/environments/development.rb index a43bdb4..d1aa4de 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,9 +1,10 @@ +require 'active_support/core_ext/integer/time' + Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. - # In the development environment your application's code is reloaded on - # every request. This slows down response time but is perfect for development - # since you don't have to restart the web server when you make code changes. - config.cache_classes = false + # Make code changes take effect immediately without server restart. + config.enable_reloading = true # Do not eager load code on boot. config.eager_load = false @@ -11,30 +12,34 @@ # Show full error reports. config.consider_all_requests_local = true - # Enable/disable caching. By default caching is disabled. - # Run rails dev:cache to toggle caching. - if Rails.root.join('tmp', 'caching-dev.txt').exist? + # Enable server timing. + config.server_timing = true + + # Enable/disable Action Controller caching. By default Action Controller caching is disabled. + # Run rails dev:cache to toggle Action Controller caching. + if Rails.root.join('tmp/caching-dev.txt').exist? config.action_controller.perform_caching = true config.action_controller.enable_fragment_cache_logging = true - - config.cache_store = :memory_store - config.public_file_server.headers = { - 'Cache-Control' => "public, max-age=#{2.days.to_i}" - } + config.public_file_server.headers = { 'cache-control' => "public, max-age=#{2.days.to_i}" } else config.action_controller.perform_caching = false - - config.cache_store = :null_store end + # Change to :null_store to avoid any caching. + config.cache_store = :memory_store + # Store uploaded files on the local file system (see config/storage.yml for options). config.active_storage.service = :local # Don't care if the mailer can't send. config.action_mailer.raise_delivery_errors = false + # Make template changes take effect immediately. config.action_mailer.perform_caching = false + # Set localhost to be used by links generated in mailer templates. + config.action_mailer.default_url_options = { host: 'localhost', port: 3000 } + # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log @@ -44,21 +49,28 @@ # Highlight code that triggered database queries in logs. config.active_record.verbose_query_logs = true - # Debug mode disables concatenation and preprocessing of assets. - # This option may cause significant delays in view rendering with a large - # number of complex assets. - config.assets.debug = true + # Append comments with runtime information tags to SQL queries in logs. + config.active_record.query_log_tags_enabled = true - # Suppress logger output for asset requests. - config.assets.quiet = true - # Raises error for missing translations. - # config.action_view.raise_on_missing_translations = true + # Highlight code that enqueued background job in logs. + config.active_job.verbose_enqueue_logs = true - # Use an evented file watcher to asynchronously detect changes in source code, - # routes, locales, etc. This feature depends on the listen gem. - config.file_watcher = ActiveSupport::EventedFileUpdateChecker + # Raises error for missing translations. + # config.i18n.raise_on_missing_translations = true # In development, bypass Rails 6 DNS rebinding attack protection # to allow access by default hostname, container host, etc. config.hosts.clear + + # Annotate rendered view with file names. + config.action_view.annotate_rendered_view_with_filenames = true + + # Uncomment if you wish to allow Action Cable access from any origin. + # config.action_cable.disable_request_forgery_protection = true + + # Raise error when a before_action's only/except options reference missing actions. + config.action_controller.raise_on_missing_callback_actions = true + + # Apply autocorrection by RuboCop to files generated by `bin/rails generate`. + # config.generators.apply_rubocop_autocorrect_after_generate! end diff --git a/config/environments/production.rb b/config/environments/production.rb index a5ca612..6c41245 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,106 +1,89 @@ +require 'active_support/core_ext/integer/time' + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # Code is not reloaded between requests. - config.cache_classes = true + config.enable_reloading = false - # Eager load code on boot. This eager loads most of Rails and - # your application in memory, allowing both threaded web servers - # and those relying on copy on write to perform better. - # Rake tasks automatically ignore this option for performance. + # Eager load code on boot for better performance and memory savings (ignored by Rake tasks). config.eager_load = true - # Full error reports are disabled and caching is turned on. - config.consider_all_requests_local = false - config.action_controller.perform_caching = true + # Full error reports are disabled. + config.consider_all_requests_local = false - # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] - # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). - # config.require_master_key = true + # Turn on fragment caching in view templates. + config.action_controller.perform_caching = true - # Disable serving static files from the `/public` folder by default since - # Apache or NGINX already handles this. - config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? + # Cache assets for far-future expiry since they are all digest stamped. + config.public_file_server.headers = { 'cache-control' => "public, max-age=#{1.year.to_i}" } # Enable serving of images, stylesheets, and JavaScripts from an asset server. - # config.action_controller.asset_host = 'http://assets.example.com' - - # Specifies the header that your server uses for sending files. - # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache - # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX + # config.asset_host = "http://assets.example.com" # Store uploaded files on the local file system (see config/storage.yml for options). config.active_storage.service = :local - # Mount Action Cable outside main process or domain. - # config.action_cable.mount_path = nil - # config.action_cable.url = 'wss://example.com/cable' - # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] + # Assume all access to the app is happening through a SSL-terminating reverse proxy. + config.assume_ssl = true # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. - config.force_ssl = false + config.force_ssl = true - # Use the lowest log level to ensure availability of diagnostic information - # when problems arise. - config.log_level = :debug + # Skip http-to-https redirect for the default health check endpoint. + # config.ssl_options = { redirect: { exclude: ->(request) { request.path == "/up" } } } - # Prepend all log lines with the following tags. + # Log to STDOUT with the current request id as a default log tag. config.log_tags = [:request_id] + config.logger = ActiveSupport::TaggedLogging.logger($stdout) - # Use a different cache store in production. - # config.cache_store = :mem_cache_store + # Change to "debug" to log everything (including potentially personally-identifiable information!) + config.log_level = ENV.fetch('RAILS_LOG_LEVEL', 'info') - # Use a real queuing backend for Active Job (and separate queues per environment). - # config.active_job.queue_adapter = :resque - # config.active_job.queue_name_prefix = "new_nara_production" + # Prevent health checks from clogging up the logs. + config.silence_healthcheck_path = '/up' - config.action_mailer.perform_caching = false + # Don't log any deprecations. + config.active_support.report_deprecations = false + + # Replace the default in-process memory cache store with a durable alternative. + # config.cache_store = :mem_cache_store + + # Replace the default in-process and non-durable queuing backend for Active Job. + # config.active_job.queue_adapter = :resque # Ignore bad email addresses and do not raise email delivery errors. # Set this to true and configure the email server for immediate delivery to raise delivery errors. # config.action_mailer.raise_delivery_errors = false + # Set host to be used by links generated in mailer templates. + config.action_mailer.default_url_options = { host: 'example.com' } + + # Specify outgoing SMTP server. Remember to add smtp/* credentials via rails credentials:edit. + # config.action_mailer.smtp_settings = { + # user_name: Rails.application.credentials.dig(:smtp, :user_name), + # password: Rails.application.credentials.dig(:smtp, :password), + # address: "smtp.example.com", + # port: 587, + # authentication: :plain + # } + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to # the I18n.default_locale when a translation cannot be found). config.i18n.fallbacks = true - # Send deprecation notices to registered listeners. - config.active_support.deprecation = :notify - - # Use default logging formatter so that PID and timestamp are not suppressed. - config.log_formatter = ::Logger::Formatter.new - - # Use a different logger for distributed setups. - # require 'syslog/logger' - # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') - - if ENV['RAILS_LOG_TO_STDOUT'].present? - logger = ActiveSupport::Logger.new($stdout) - logger.formatter = config.log_formatter - config.logger = ActiveSupport::TaggedLogging.new(logger) - end - # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false - # Inserts middleware to perform automatic connection switching. - # The `database_selector` hash is used to pass options to the DatabaseSelector - # middleware. The `delay` is used to determine how long to wait after a write - # to send a subsequent read to the primary. - # - # The `database_resolver` class is used by the middleware to determine which - # database is appropriate to use based on the time delay. - # - # The `database_resolver_context` class is used by the middleware to set - # timestamps for the last write to the primary. The resolver uses the context - # class timestamps to determine how long to wait before reading from the - # replica. + # Only use :id for inspections in production. + config.active_record.attributes_for_inspect = [:id] + + # Enable DNS rebinding protection and other `Host` header attacks. + # config.hosts = [ + # "example.com", # Allow requests from example.com + # /.*\.example\.com/ # Allow requests from subdomains like `www.example.com` + # ] # - # By default Rails will store a last write timestamp in the session. The - # DatabaseSelector middleware is designed as such you can define your own - # strategy for connection switching and pass that into the middleware through - # these configuration options. - # config.active_record.database_selector = { delay: 2.seconds } - # config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver - # config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session + # Skip DNS rebinding protection for the default health check endpoint. + # config.host_authorization = { exclude: ->(request) { request.path == "/up" } } end diff --git a/config/environments/test.rb b/config/environments/test.rb index dc077a1..db22041 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -6,27 +6,25 @@ Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. config.hosts.clear - config.cache_classes = false - config.action_view.cache_template_loading = true - - # Do not eager load code on boot. This avoids loading your whole application - # just for the purpose of running a single test. If you are using a tool that - # preloads Rails for running tests, you may have to set it to true. - config.eager_load = false - - # Configure public file server for tests with Cache-Control for performance. - config.public_file_server.enabled = true - config.public_file_server.headers = { - 'Cache-Control' => "public, max-age=#{1.hour.to_i}" - } - - # Show full error reports and disable caching. - config.consider_all_requests_local = true - config.action_controller.perform_caching = false + + # While tests run files are not watched, reloading is not necessary. + config.enable_reloading = false + + # Eager loading loads your entire application. When running a single test locally, + # this is usually not necessary, and can slow down your test suite. However, it's + # recommended that you enable it in continuous integration systems to ensure eager + # loading is working properly before deploying your code. + config.eager_load = ENV['CI'].present? + + # Configure public file server for tests with cache-control for performance. + config.public_file_server.headers = { 'cache-control' => 'public, max-age=3600' } + + # Show full error reports. + config.consider_all_requests_local = true config.cache_store = :null_store - # Raise exceptions instead of rendering exception templates. - config.action_dispatch.show_exceptions = false + # Render exception templates for rescuable exceptions and raise for other exceptions. + config.action_dispatch.show_exceptions = :rescuable # Disable request forgery protection in test environment. config.action_controller.allow_forgery_protection = false @@ -34,16 +32,23 @@ # Store uploaded files on the local file system in a temporary directory. config.active_storage.service = :test - config.action_mailer.perform_caching = false - # Tell Action Mailer not to deliver emails to the real world. # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test + # Set host to be used by links generated in mailer templates. + config.action_mailer.default_url_options = { host: 'example.com' } + # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr # Raises error for missing translations. - # config.action_view.raise_on_missing_translations = true + # config.i18n.raise_on_missing_translations = true + + # Annotate rendered view with file names. + # config.action_view.annotate_rendered_view_with_filenames = true + + # Raise error when a before_action's only/except options reference missing actions. + config.action_controller.raise_on_missing_callback_actions = true end diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index 0709a52..ee1f11b 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -5,10 +5,3 @@ # Add additional assets to the asset load path. # Rails.application.config.assets.paths << Emoji.images_path -# Add Yarn node_modules folder to the asset load path. -Rails.application.config.assets.paths << Rails.root.join('node_modules') - -# Precompile additional assets. -# application.js, application.css, and all non-JS/CSS in the app/assets -# folder are already added. -# Rails.application.config.assets.precompile += %w( application.css ) diff --git a/config/initializers/content_security_policy.rb b/config/initializers/content_security_policy.rb index 35d0f26..b3076b3 100644 --- a/config/initializers/content_security_policy.rb +++ b/config/initializers/content_security_policy.rb @@ -1,30 +1,25 @@ # Be sure to restart your server when you modify this file. -# Define an application-wide content security policy -# For further information see the following documentation -# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy +# Define an application-wide content security policy. +# See the Securing Rails Applications Guide for more information: +# https://guides.rubyonrails.org/security.html#content-security-policy-header -# Rails.application.config.content_security_policy do |policy| -# policy.default_src :self, :https -# policy.font_src :self, :https, :data -# policy.img_src :self, :https, :data -# policy.object_src :none -# policy.script_src :self, :https -# policy.style_src :self, :https -# # If you are using webpack-dev-server then specify webpack-dev-server host -# policy.connect_src :self, :https, "http://localhost:3035", "ws://localhost:3035" if Rails.env.development? - -# # Specify URI for violation reports -# # policy.report_uri "/csp-violation-report-endpoint" +# Rails.application.configure do +# config.content_security_policy do |policy| +# policy.default_src :self, :https +# policy.font_src :self, :https, :data +# policy.img_src :self, :https, :data +# policy.object_src :none +# policy.script_src :self, :https +# policy.style_src :self, :https +# # Specify URI for violation reports +# # policy.report_uri "/csp-violation-report-endpoint" +# end +# +# # Generate session nonces for permitted importmap, inline scripts, and inline styles. +# config.content_security_policy_nonce_generator = ->(request) { request.session.id.to_s } +# config.content_security_policy_nonce_directives = %w(script-src style-src) +# +# # Report violations without enforcing the policy. +# # config.content_security_policy_report_only = true # end - -# If you are using UJS then enable automatic nonce generation -# Rails.application.config.content_security_policy_nonce_generator = -> request { SecureRandom.base64(16) } - -# Set the nonce only to specific directives -# Rails.application.config.content_security_policy_nonce_directives = %w(script-src) - -# Report CSP violations to a specified URI -# For further information see the following documentation: -# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only -# Rails.application.config.content_security_policy_report_only = true diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb index 4a994e1..f72dcdf 100644 --- a/config/initializers/filter_parameter_logging.rb +++ b/config/initializers/filter_parameter_logging.rb @@ -1,4 +1,8 @@ # Be sure to restart your server when you modify this file. -# Configure sensitive parameters which will be filtered from the log file. -Rails.application.config.filter_parameters += [:password] +# Configure parameters to be partially matched (e.g. passw matches password) and filtered from the log file. +# Use this to limit dissemination of sensitive information. +# See the ActiveSupport::ParameterFilter documentation for supported notations and behaviors. +Rails.application.config.filter_parameters += %i[ + passw email secret token _key crypt salt certificate otp ssn cvv cvc +] diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index ac033bf..3860f65 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -4,13 +4,13 @@ # are locale specific, and you may define rules for as many different # locales as you wish. All of these examples are active by default: # ActiveSupport::Inflector.inflections(:en) do |inflect| -# inflect.plural /^(ox)$/i, '\1en' -# inflect.singular /^(ox)en/i, '\1' -# inflect.irregular 'person', 'people' +# inflect.plural /^(ox)$/i, "\\1en" +# inflect.singular /^(ox)en/i, "\\1" +# inflect.irregular "person", "people" # inflect.uncountable %w( fish sheep ) # end # These inflection rules are supported but not enabled by default: # ActiveSupport::Inflector.inflections(:en) do |inflect| -# inflect.acronym 'RESTful' +# inflect.acronym "RESTful" # end diff --git a/config/initializers/permissions_policy.rb b/config/initializers/permissions_policy.rb new file mode 100644 index 0000000..7db3b95 --- /dev/null +++ b/config/initializers/permissions_policy.rb @@ -0,0 +1,13 @@ +# Be sure to restart your server when you modify this file. + +# Define an application-wide HTTP permissions policy. For further +# information see: https://developers.google.com/web/updates/2018/06/feature-policy + +# Rails.application.config.permissions_policy do |policy| +# policy.camera :none +# policy.gyroscope :none +# policy.microphone :none +# policy.usb :none +# policy.fullscreen :self +# policy.payment :self, "https://secure.example.com" +# end diff --git a/config/puma.rb b/config/puma.rb index 50f7d30..a248513 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -1,37 +1,41 @@ -# Puma can serve each request in a thread from an internal thread pool. -# The `threads` method setting takes two numbers: a minimum and maximum. -# Any libraries that use thread pools should be configured to match -# the maximum value specified for Puma. Default is set to 5 threads for minimum -# and maximum; this matches the default thread size of Active Record. +# This configuration file will be evaluated by Puma. The top-level methods that +# are invoked here are part of Puma's configuration DSL. For more information +# about methods provided by the DSL, see https://puma.io/puma/Puma/DSL.html. # -max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } -min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count } -threads min_threads_count, max_threads_count - -# Bind to all interfaces (0.0.0.0) in all environments, not just production. -bind ENV.fetch('PUMA_BINDING', 'tcp://0.0.0.0:3000') - -# Specifies the `environment` that Puma will run in. +# Puma starts a configurable number of processes (workers) and each process +# serves each request in a thread from an internal thread pool. # -environment ENV.fetch("RAILS_ENV") { "development" } - -# Specifies the `pidfile` that Puma will use. -pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" } - -# Specifies the number of `workers` to boot in clustered mode. -# Workers are forked web server processes. If using threads and workers together -# the concurrency of the application would be max `threads` * `workers`. -# Workers do not work on JRuby or Windows (both of which do not support -# processes). +# You can control the number of workers using ENV["WEB_CONCURRENCY"]. You +# should only set this value when you want to run 2 or more workers. The +# default is already 1. # -# workers ENV.fetch("WEB_CONCURRENCY") { 2 } - -# Use the `preload_app!` method when specifying a `workers` number. -# This directive tells Puma to first boot the application and load code -# before forking the application. This takes advantage of Copy On Write -# process behavior so workers use less memory. +# The ideal number of threads per worker depends both on how much time the +# application spends waiting for IO operations and on how much you wish to +# prioritize throughput over latency. # -# preload_app! +# As a rule of thumb, increasing the number of threads will increase how much +# traffic a given process can handle (throughput), but due to CRuby's +# Global VM Lock (GVL) it has diminishing returns and will degrade the +# response time (latency) of the application. +# +# The default is set to 3 threads as it's deemed a decent compromise between +# throughput and latency for the average Rails application. +# +# Any libraries that use a connection pool or another resource pool should +# be configured to provide at least as many connections as the number of +# threads. This includes Active Record's `pool` parameter in `database.yml`. +threads_count = ENV.fetch("RAILS_MAX_THREADS", 3) +threads threads_count, threads_count + +# Specifies the `port` that Puma will listen on to receive requests; default is 3000. +port ENV.fetch("PORT", 3000) -# Allow puma to be restarted by `rails restart` command. +# Allow puma to be restarted by `bin/rails restart` command. plugin :tmp_restart + +# Run the Solid Queue supervisor inside of Puma for single-server deployments +plugin :solid_queue if ENV["SOLID_QUEUE_IN_PUMA"] + +# Specify the PID file. Defaults to tmp/pids/server.pid in development. +# In other environments, only set the PID file if requested. +pidfile ENV["PIDFILE"] if ENV["PIDFILE"] diff --git a/db/schema.rb b/db/schema.rb index ca74916..578e710 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 0) do +ActiveRecord::Schema[6.1].define(version: 0) do create_table "CPC", id: false, charset: "latin1", options: "ENGINE=MyISAM", force: :cascade do |t| t.integer "ID" diff --git a/docker-compose.ci.yml b/docker-compose.ci.yml index 10ceb7f..29638aa 100644 --- a/docker-compose.ci.yml +++ b/docker-compose.ci.yml @@ -6,6 +6,8 @@ services: image: ${DOCKER_APP_IMAGE} volumes: !override - artifacts:/opt/app/artifacts + environment: + SECRET_KEY_BASE: ${SECRET_KEY_BASE:?error} db: volumes: !reset diff --git a/lib/docker.rb b/lib/docker.rb deleted file mode 100644 index ab23613..0000000 --- a/lib/docker.rb +++ /dev/null @@ -1,13 +0,0 @@ -module Docker - class Secret - class << self - def setup_environment!(fileglob = '/run/secrets/*') - Dir[fileglob].each do |filepath| - secret = File.read(filepath) - secret_name = File.basename(filepath) - ENV[secret_name] = secret unless secret.empty? - end - end - end - end - end diff --git a/lib/lib_it/logging.rb b/lib/lib_it/logging.rb deleted file mode 100644 index a583817..0000000 --- a/lib/lib_it/logging.rb +++ /dev/null @@ -1,34 +0,0 @@ -require 'webpacker/instance' - -require 'lib_it/logging/events' -require 'lib_it/logging/formatters' -require 'lib_it/logging/loggers' - -module LibIT - module Logging - class << self - - # Configures custom logging for a Rails application. - def configure! - config = Rails.application.config - configure_lograge!(config.lograge) - - logger = Loggers.new_default_logger - logger.info("Custom logger initialized for environment #{Rails.env.inspect}") - - config.logger = logger - Webpacker::Instance.logger = logger - end - - private - - def configure_lograge!(lograge) - return unless lograge - - lograge.enabled = true - lograge.custom_options = Events.extract_data_for_lograge - lograge.formatter = Formatters.lograge_formatter - end - end - end -end diff --git a/lib/lib_it/logging/events.rb b/lib/lib_it/logging/events.rb deleted file mode 100644 index 205adbf..0000000 --- a/lib/lib_it/logging/events.rb +++ /dev/null @@ -1,39 +0,0 @@ -module LibIT - module Logging - module Events - class << self - def extract_data_for_lograge - ->(event) { extract_event_data(event) } - end - - private - - def extract_event_data(event) - event_data = { time: Time.now } - extracted_headers = extract_headers(event) - event_data.merge(extracted_headers) - end - - def extract_headers(event) - return {} unless (headers = event.payload[:headers]) - - extracted_headers = { - # yes, RFC 2616 uses a variant spelling for 'referrer', it's a known issue - # https://tools.ietf.org/html/rfc2616#section-14.36 - referer: headers['HTTP_REFERER'], - request_id: headers['action_dispatch.request_id'], - remote_ip: headers['action_dispatch.remote_ip'], - remote_addr: headers['REMOTE_ADDR'], - x_forwarded_for: headers['HTTP_X_FORWARDED_FOR'], - forwarded: headers['HTTP_FORWARDED'] # RFC 7239 - } - - # Some of these 'headers' include recursive structures - # that cause SystemStackErrors in JSON serialization, - # so we convert them all to strings - extracted_headers.transform_values(&:to_s) - end - end - end - end -end diff --git a/lib/lib_it/logging/formatters.rb b/lib/lib_it/logging/formatters.rb deleted file mode 100644 index 6916f46..0000000 --- a/lib/lib_it/logging/formatters.rb +++ /dev/null @@ -1,58 +0,0 @@ -require 'ougai/formatters/bunyan' -require 'ougai/formatters/readable' - -module Formatters - - class << self - def new_json_formatter - Bunyan.new - end - - def new_readable_formatter - Ougai::Formatters::Readable.new - end - - def lograge_formatter - Lograge.new - end - - def ensure_hash(message) - return {} unless message - return message if message.is_a?(Hash) - - { msg: message } - end - end - - # ------------------------------------------------------------ - # Private helper classes - - class Bunyan < Ougai::Formatters::Bunyan - include Ougai::Logging::Severity - - def _call(severity, time, progname, data) - original_data = Formatters.ensure_hash(data) - - # Ougai::Formatters::Bunyan replaces the human-readable severity string - # with a numeric level, so we add it here as a separate attribute - severity = ensure_human_readable(severity) - merged_data = { severity: severity }.merge(original_data) - super(severity, time, progname, merged_data) - end - - def ensure_human_readable(severity) - return to_label(severity) if severity.is_a?(Integer) - - severity.to_s - end - end - private_constant :Bunyan - - class Lograge - def call(data) - { msg: 'Request', request: Formatters.ensure_hash(data) } - end - end - private_constant :Lograge - -end diff --git a/lib/lib_it/logging/loggers.rb b/lib/lib_it/logging/loggers.rb deleted file mode 100644 index e886290..0000000 --- a/lib/lib_it/logging/loggers.rb +++ /dev/null @@ -1,54 +0,0 @@ -require 'lib_it/logging/formatters' -require 'lib_it/logging/tagged_logging_extensions' - -module LibIT - module Logging - module Loggers - class << self - def new_default_logger - return new_test_logger if Rails.env.test? - return new_production_logger if Rails.env.production? - return new_development_logger if Rails.env.development? - end - - def new_json_logger(logdev) - new_logger_with(logdev: logdev, formatter: Formatters.new_json_formatter) - end - - def new_readable_logger(logdev) - new_logger_with(logdev: logdev, formatter: Formatters.new_readable_formatter) - end - - private - - def new_test_logger - file_logger_for_env(:test) - end - - def new_production_logger - new_json_logger($stdout) - end - - def new_development_logger - new_json_logger($stdout).tap do |json_logger| - file_logger = file_logger_for_env(:dev) - json_logger.extend Ougai::Logger.broadcast(file_logger) - end - end - - def file_logger_for_env(env) - new_readable_logger("log/#{env}.log") - end - - def new_logger_with(logdev:, formatter:) - AvLogger.new(logdev).tap { |l| l.formatter = formatter } - end - end - - class AvLogger < Ougai::Logger - include ActiveSupport::LoggerThreadSafeLevel - include ActiveSupport::LoggerSilence - end - end - end -end diff --git a/lib/lib_it/logging/tagged_logging_extensions.rb b/lib/lib_it/logging/tagged_logging_extensions.rb deleted file mode 100644 index 1bf2e3c..0000000 --- a/lib/lib_it/logging/tagged_logging_extensions.rb +++ /dev/null @@ -1,17 +0,0 @@ -require 'active_support/tagged_logging' - -# Monkey-patch ActiveSupport::TaggedLogging::Formatter -# not to produce garbage by prepending tags to hashes. -module ActiveSupport - module TaggedLogging - module Formatter - def call(severity, time, progname, data) - return super unless current_tags.present? - - original_data = Formatters.ensure_hash(data) - merged_data = { tags: current_tags }.merge(original_data) - super(severity, time, progname, merged_data) - end - end - end -end diff --git a/package.json b/package.json index 8b9b5cc..48369de 100644 --- a/package.json +++ b/package.json @@ -13,5 +13,6 @@ "version": "0.1.0", "devDependencies": { "webpack-dev-server": "^3" - } + }, + "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" } diff --git a/public/400.html b/public/400.html new file mode 100644 index 0000000..282dbc8 --- /dev/null +++ b/public/400.html @@ -0,0 +1,114 @@ + + + + + + + The server cannot process the request due to a client error (400 Bad Request) + + + + + + + + + + + + + +
+
+ +
+
+

The server cannot process the request due to a client error. Please check the request and try again. If you’re the application owner check the logs for more information.

+
+
+ + + + diff --git a/public/404.html b/public/404.html index 9f832d1..c0670bc 100644 --- a/public/404.html +++ b/public/404.html @@ -1,69 +1,114 @@ - - - - The page you were looking for doesn't exist (404) - - - - - - -
-
-

The page you were looking for doesn't exist.

-

You may have mistyped the address or the page may have moved.

-
-

If you are the application owner check the logs for more information.

-
- + + + + + + + The page you were looking for doesn’t exist (404 Not found) + + + + + + + + + + + + + +
+
+ +
+
+

The page you were looking for doesn’t exist. You may have mistyped the address or the page may have moved. If you’re the application owner check the logs for more information.

+
+
+ + + diff --git a/public/406-unsupported-browser.html b/public/406-unsupported-browser.html new file mode 100644 index 0000000..9532a9c --- /dev/null +++ b/public/406-unsupported-browser.html @@ -0,0 +1,114 @@ + + + + + + + Your browser is not supported (406 Not Acceptable) + + + + + + + + + + + + + +
+
+ +
+
+

Your browser is not supported.
Please upgrade your browser to continue.

+
+
+ + + + diff --git a/public/422.html b/public/422.html index c08eac0..8bcf060 100644 --- a/public/422.html +++ b/public/422.html @@ -1,67 +1,114 @@ - - - - The change you wanted was rejected (422) - - - - - - -
-
-

The change you wanted was rejected.

-

Maybe you tried to change something you didn't have access to.

-
-

If you are the application owner check the logs for more information.

-
- + + + + + + + The change you wanted was rejected (422 Unprocessable Entity) + + + + + + + + + + + + + +
+
+ +
+
+

The change you wanted was rejected. Maybe you tried to change something you didn’t have access to. If you’re the application owner check the logs for more information.

+
+
+ + + diff --git a/public/500.html b/public/500.html index 78a030a..d77718c 100644 --- a/public/500.html +++ b/public/500.html @@ -1,66 +1,114 @@ - - - - We're sorry, but something went wrong (500) - - - - - - -
-
-

We're sorry, but something went wrong.

-
-

If you are the application owner check the logs for more information.

-
- + + + + + + + We’re sorry, but something went wrong (500 Internal Server Error) + + + + + + + + + + + + + +
+
+ +
+
+

We’re sorry, but something went wrong.
If you’re the application owner check the logs for more information.

+
+
+ + + diff --git a/public/robots.txt b/public/robots.txt index c120c70..c19f78a 100644 --- a/public/robots.txt +++ b/public/robots.txt @@ -1,2 +1 @@ # See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file - diff --git a/spec/.rubocop.yml b/spec/.rubocop.yml index 01afa78..ea6c510 100644 --- a/spec/.rubocop.yml +++ b/spec/.rubocop.yml @@ -10,4 +10,4 @@ Metrics/ModuleLength: Enabled: false Metrics/MethodLength: - Enabled: false + Enabled: false \ No newline at end of file diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb index 2f87f5f..d59842a 100644 --- a/spec/controllers/application_controller_spec.rb +++ b/spec/controllers/application_controller_spec.rb @@ -2,12 +2,12 @@ require 'rails_helper' -describe ApplicationController, 'Application controller', type: :controller do +describe ApplicationController, type: :controller do render_views - describe 'Land on saerch page' do + describe '#index' do it 'renders the index template' do get :index - expect(response.body).to match(/NARA/) + expect(response.body).to match(/Early Arrivals Search/) end end end diff --git a/spec/controllers/searchcase_controller_spec.rb b/spec/controllers/searchcase_controller_spec.rb index 685930b..2541b17 100644 --- a/spec/controllers/searchcase_controller_spec.rb +++ b/spec/controllers/searchcase_controller_spec.rb @@ -2,16 +2,22 @@ require 'rails_helper' -describe SearchcaseController, 'Searchcase controller', type: :controller do +describe SearchcaseController, type: :controller do render_views - describe 'search searchcase' do + describe '#display' do it 'searches against all when fed no values' do get :display expect(@return).to be_nil end - it 'Notifies user of no results when nothing found' do + + it 'redirects when nothing found' do + get :display, params: { q: 'bad search data' } + expect(response).to redirect_to action: :search + end + + it 'notifies user of no results when nothing found' do get :display, params: { q: 'bad search data' } - expect(response.body).to include('redirected') + expect(request.flash[:notice]).to include('0 results') end end end diff --git a/spec/lib/lib_it/logging/formatters_spec.rb b/spec/lib/lib_it/logging/formatters_spec.rb deleted file mode 100644 index 411aff4..0000000 --- a/spec/lib/lib_it/logging/formatters_spec.rb +++ /dev/null @@ -1,42 +0,0 @@ -require 'rails_helper' - -module LibIT - module Logging - describe Formatters do - describe :new_json_formatter do - it 'supports tagged logging' do - out = StringIO.new - logger = Logger.new(out) - logger.formatter = Formatters.new_json_formatter - - logger = ActiveSupport::TaggedLogging.new(logger) - - expected_tag = 'hello' - expected_msg = 'this is a test' - - logger.tagged(expected_tag) { logger.info(expected_msg) } - - logged_json = JSON.parse(out.string) - expect(logged_json['msg']).to eq(expected_msg) - expect(logged_json['tags']).to eq([expected_tag]) - end - end - - describe :ensure_hash do - it 'returns an empty hash for nil' do - expect(Formatters.ensure_hash(nil)).to eq({}) - end - - it 'returns the original hash for a hash' do - original_hash = { a: 1, b: 2 } - expect(Formatters.ensure_hash(original_hash)).to equal(original_hash) - end - - it 'wraps anything else in a hash' do - message = 'this is a message' - expect(Formatters.ensure_hash(message)).to eq({ msg: message }) - end - end - end - end -end diff --git a/spec/lib/lib_it/logging/loggers_spec.rb b/spec/lib/lib_it/logging/loggers_spec.rb deleted file mode 100644 index 1f77072..0000000 --- a/spec/lib/lib_it/logging/loggers_spec.rb +++ /dev/null @@ -1,61 +0,0 @@ -require 'rails_helper' - -module LibIT - module Logging - describe Loggers do - describe :new_json_logger do - it 'supports tagged logging' do - out = StringIO.new - logger = Loggers.new_json_logger(out) - logger = ActiveSupport::TaggedLogging.new(logger) - - expected_tag = 'hello' - expected_msg = 'this is a test' - - logger.tagged(expected_tag) { logger.info(expected_msg) } - - logged_json = JSON.parse(out.string) - expect(logged_json['msg']).to eq(expected_msg) - expect(logged_json['tags']).to eq([expected_tag]) - end - end - - describe :new_default_logger do - before(:each) do - @env_original = Rails.env - end - - after(:each) do - Rails.env = @env_original - end - - it 'returns a file logger in test' do - logger = Loggers.new_default_logger - expect(logger).not_to be_nil - logdev = logger.instance_variable_get(:@logdev) - expect(logdev.filename).to eq('log/test.log') - end - - it 'returns a stdout logger in production' do - Rails.env = 'production' - logger = Loggers.new_default_logger - expect(logger).not_to be_nil - logdev = logger.instance_variable_get(:@logdev) - expect(logdev.filename).to be_nil - expect(logdev.dev).to eq($stdout) - end - - it 'returns a stdout logger in development' do - Rails.env = 'development' - logger = Loggers.new_default_logger - expect(logger).not_to be_nil - logdev = logger.instance_variable_get(:@logdev) - expect(logdev.filename).to be_nil - expect(logdev.dev).to eq($stdout) - - # TODO: come up with a succinct way to test broadcast to file - end - end - end - end -end diff --git a/spec/lib/secret_spec.rb b/spec/lib/secret_spec.rb deleted file mode 100644 index 1e9f938..0000000 --- a/spec/lib/secret_spec.rb +++ /dev/null @@ -1,43 +0,0 @@ -require 'rails_helper' -require 'base64' - -describe Docker::Secret do - attr_reader :tmpdir_path - - before do - tmpdir = Dir.mktmpdir(File.basename(__FILE__, '.rb')) - @tmpdir_path = Pathname.new(tmpdir) - end - - after do - FileUtils.remove_dir(tmpdir_path, true) - end - - describe :setup_environment! do - attr_reader :expected_secrets - - before do - prefix = Time.now.to_i.to_s - random = Random.new - @expected_secrets = {} - (0..8).each do |i| - secret_name = "secret_#{prefix}_#{i}" - secret = Base64.strict_encode64(random.bytes(128)) - expected_secrets[secret_name] = secret - tmpdir_path.join(secret_name).binwrite(secret) - end - end - - after do - expected_secrets.each_key { |k| ENV.delete(k) } - end - - it 'injects secrets into the environment' do - fileglob = "#{tmpdir_path}/*" - Docker::Secret.setup_environment!(fileglob) - expected_secrets.each do |secret_name, secret_value| - expect(ENV[secret_name]).to eq(secret_value) - end - end - end -end diff --git a/spec/search_spec.rb b/spec/search_spec.rb index 39d0076..ab2d174 100644 --- a/spec/search_spec.rb +++ b/spec/search_spec.rb @@ -12,6 +12,7 @@ def generate_test_object ) end +# rubocop:disable RSpec/BeforeAfterAll RSpec.configure do |config| config.before(:all) do generate_test_object @@ -20,59 +21,50 @@ def generate_test_object NaraCasefile.destroy(1111) end end +# rubocop:enable RSpec/BeforeAfterAll -RSpec.describe 'Navigate NARA search', type: :feature do - scenario 'search' do - visit '/searchcase/search' - expect(page).to have_content('The Early Arrivals Records Search (EARS)') - end +RSpec.describe 'NARA search', type: :feature do + context 'when navigating search results' do + it 'returns a header search' do + visit '/searchcase/search' + expect(page).to have_content('The Early Arrivals Records Search (EARS)') + end - scenario 'Root re-directs to search' do - visit '/' - expect(page).to have_content('The Early Arrivals Records Search (EARS)') - end + scenario 'Root re-directs to search' do + visit '/' + expect(page).to have_content('The Early Arrivals Records Search (EARS)') + end - scenario 'empty search shows all results' do - visit '/' - expect(page).to have_content('The Early Arrivals Records Search (EARS)') - click_button 'Search' - expect(page).to have_content( - 'Last Name First Name Middle Name Age Gender ' \ - 'Port Date Ship Destination LASTNAME FIRSTNAME' - ) - end + scenario 'empty search shows all results' do # rubocop:disable RSpec/ExampleLength + visit '/' + click_button 'Search' + expect(page).to have_content( + 'Last Name First Name Middle Name Age Gender ' \ + 'Port Date Ship Destination LASTNAME FIRSTNAME' + ) + end - scenario 'Search query yields intended results' do - visit '/' - expect(page).to have_content('The Early Arrivals Records Search (EARS)') - find('#q').set('DOG') - click_button 'Search' - expect(page).to have_content('query returned 0 results') + scenario 'Search query yields intended results' do + visit '/' + find('#q').set('DOG') + click_button 'Search' + expect(page).to have_content('query returned 0 results') + end end -end -RSpec.describe 'Check NARA display', type: :feature do - scenario 'Display Shows intended view' do - visit '/' - expect(page).to have_content('The Early Arrivals Records Search (EARS)') - click_button 'Search' - expect(page).to have_content( - 'Last Name First Name Middle Name Age Gender ' \ - 'Port Date Ship Destination LASTNAME FIRSTNAME' - ) - first(:link, 'LASTNAME').click - expect(page).to have_content('Record details below') - end + context 'when viewing record display', type: :feature do + scenario 'Display Shows intended view' do + visit '/' + click_button 'Search' + first(:link, 'LASTNAME').click + expect(page).to have_content('Record details below') + end - scenario 'Display Shows intended footer' do - visit '/' - expect(page).to have_content('The Early Arrivals Records Search (EARS)') - click_button 'Search' - expect(page).to have_content( - 'Last Name First Name Middle Name Age Gender ' \ - 'Port Date Ship Destination LASTNAME FIRSTNAME' - ) - first(:link, 'LASTNAME').click - expect(page).to have_content('© University of California Regents. All rights reserved') + scenario 'Display Shows intended footer' do + visit '/' + click_button 'Search' + first(:link, 'LASTNAME').click + expect(page).to have_content('© University of California Regents. All rights reserved') + end end end