diff --git a/.rubocop.yml b/.rubocop.yml index 1bd34bc..1be4370 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,9 +1,149 @@ --- +AllCops: + NewCops: enable + +Gemspec/DeprecatedAttributeAssignment: # new in 1.30 + Enabled: true +Gemspec/RequireMFA: # new in 1.23 + Enabled: true +Layout/LineContinuationLeadingSpace: # new in 1.31 + Enabled: true +Layout/LineContinuationSpacing: # new in 1.31 + Enabled: true +Layout/LineEndStringConcatenationIndentation: # new in 1.18 + Enabled: true +Layout/SpaceBeforeBrackets: # new in 1.7 + Enabled: true +Lint/AmbiguousAssignment: # new in 1.7 + Enabled: true +Lint/AmbiguousOperatorPrecedence: # new in 1.21 + Enabled: true +Lint/AmbiguousRange: # new in 1.19 + Enabled: true +Lint/ConstantOverwrittenInRescue: # new in 1.31 + Enabled: true +Lint/DeprecatedConstants: # new in 1.8 + Enabled: true +Lint/DuplicateBranch: # new in 1.3 + Enabled: true +Lint/DuplicateRegexpCharacterClassElement: # new in 1.1 + Enabled: true +Lint/EmptyBlock: # new in 1.1 + Enabled: true +Lint/EmptyClass: # new in 1.3 + Enabled: true +Lint/EmptyInPattern: # new in 1.16 + Enabled: true +Lint/IncompatibleIoSelectWithFiberScheduler: # new in 1.21 + Enabled: true +Lint/LambdaWithoutLiteralBlock: # new in 1.8 + Enabled: true +Lint/NoReturnInBeginEndBlocks: # new in 1.2 + Enabled: true +Lint/NonAtomicFileOperation: # new in 1.31 + Enabled: true +Lint/NumberedParameterAssignment: # new in 1.9 + Enabled: true +Lint/OrAssignmentToConstant: # new in 1.9 + Enabled: true +Lint/RedundantDirGlobSort: # new in 1.8 + Enabled: true +Lint/RefinementImportMethods: # new in 1.27 + Enabled: true +Lint/RequireRangeParentheses: # new in 1.32 + Enabled: true +Lint/RequireRelativeSelfPath: # new in 1.22 + Enabled: true +Lint/SymbolConversion: # new in 1.9 + Enabled: true +Lint/Syntax: + Enabled: true +Lint/ToEnumArguments: # new in 1.1 + Enabled: true +Lint/TripleQuotes: # new in 1.9 + Enabled: true +Lint/UnexpectedBlockArity: # new in 1.5 + Enabled: true +Lint/UnmodifiedReduceAccumulator: # new in 1.1 + Enabled: true +Lint/UselessRuby2Keywords: # new in 1.23 + Enabled: true +Naming/BlockForwarding: # new in 1.24 + Enabled: true +Security/CompoundHash: # new in 1.28 + Enabled: true +Security/IoMethods: # new in 1.22 + Enabled: true +Style/ArgumentsForwarding: # new in 1.1 + Enabled: true +Style/CollectionCompact: # new in 1.2 + Enabled: true +Style/DocumentDynamicEvalDefinition: # new in 1.1 + Enabled: true +Style/EmptyHeredoc: # new in 1.32 + Enabled: true +Style/EndlessMethod: # new in 1.8 + Enabled: true +Style/EnvHome: # new in 1.29 + Enabled: true +Style/FetchEnvVar: # new in 1.28 + Enabled: true +Style/FileRead: # new in 1.24 + Enabled: true +Style/FileWrite: # new in 1.24 + Enabled: true +Style/HashConversion: # new in 1.10 + Enabled: true +Style/HashExcept: # new in 1.7 + Enabled: true +Style/IfWithBooleanLiteralBranches: # new in 1.9 + Enabled: true +Style/InPatternThen: # new in 1.16 + Enabled: true +Style/MapCompactWithConditionalBlock: # new in 1.30 + Enabled: true +Style/MapToHash: # new in 1.24 + Enabled: true +Style/MultilineInPatternThen: # new in 1.16 + Enabled: true +Style/NegatedIfElseCondition: # new in 1.2 + Enabled: true +Style/NestedFileDirname: # new in 1.26 + Enabled: true +Style/NilLambda: # new in 1.3 + Enabled: true +Style/NumberedParameters: # new in 1.22 + Enabled: true +Style/NumberedParametersLimit: # new in 1.22 + Enabled: true +Style/ObjectThen: # new in 1.28 + Enabled: true +Style/OpenStructUse: # new in 1.23 + Enabled: true +Style/QuotedSymbols: # new in 1.16 + Enabled: true +Style/RedundantArgument: # new in 1.4 + Enabled: true +Style/RedundantInitialize: # new in 1.27 + Enabled: true +Style/RedundantSelfAssignmentBranch: # new in 1.19 + Enabled: true +Style/SelectByRegexp: # new in 1.22 + Enabled: true +Style/StringChars: # new in 1.12 + Enabled: true +Style/SwapValues: # new in 1.1 + Enabled: true + Layout/EmptyLinesAroundBlockBody: Exclude: - 'db/schema.rb' +Layout/LineLength: + Max: 160 + Metrics/AbcSize: + Max: 35 Exclude: - 'db/migrate/**/*.rb' @@ -16,10 +156,8 @@ Metrics/BlockLength: - 'db/seeds.rb' - 'spec/**/*.rb' -Metrics/LineLength: - Max: 100 - Metrics/MethodLength: + Max: 15 Exclude: - 'db/migrate/**/*.rb' diff --git a/.ruby-version b/.ruby-version index 49cdd66..ef538c2 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.7.6 +3.1.2 diff --git a/Dockerfile b/Dockerfile index 6ea5eac..0683424 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,8 @@ -FROM ruby:2.7.6-alpine3.15 +FROM ruby:3.1.2-alpine3.15 RUN apk add --update alpine-sdk && \ apk add bash build-base git libxml2-dev libxslt-dev nodejs postgresql-dev readline-dev tzdata zlib-dev && \ + gem install bundler && \ mkdir /app WORKDIR /app diff --git a/Gemfile b/Gemfile index 6b9cda0..62b9972 100644 --- a/Gemfile +++ b/Gemfile @@ -1,75 +1,82 @@ # frozen_string_literal: true -ruby '2.7.6' +ruby '3.1.2' + +source 'https://rubygems.org' git_source(:github) { |repo| "https://github.com/#{repo}.git" } -source 'https://rubygems.org' do - gem 'bundle', '~> 2.3', '>= 2.3.18' - # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' - gem 'rails', '~> 5.2', '>= 5.2.8.1' - # Use Postgres as the database for Active Record - gem 'pg' - # Use Puma as the app server - gem 'puma', '~> 4.3', '>= 4.3.9' - # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder - gem 'jbuilder', '~> 2.10', '>= 2.10.0' - # Use Redis adapter to run Action Cable in production - # gem 'redis', '~> 4.0' - # Use ActiveModel has_secure_password - gem 'bcrypt', '~> 3.1.7' - - # v1 api is [JSONAPI](https://jsonapi.org/) - gem 'jsonapi-resources', '~> 0.10', '>= 0.10.7' - - # v2 api is [GraphQL](https://graphql.org/) - gem 'graphql', '~> 1.7', '>= 1.7.14' - - # Use ActiveStorage variant - # gem 'mini_magick', '~> 4.8' - - # Use Capistrano for deployment - # gem 'capistrano-rails', group: :development - - # Reduces boot times through caching; required in config/boot.rb - gem 'bootsnap', '>= 1.1.0', require: false - - # Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making - # cross-origin AJAX possible - # gem 'rack-cors' - - # Geokit for distance information - gem 'geokit-rails' - - 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 'database_cleaner', '~> 1.7', '>= 1.7.0' - gem 'factory_bot_rails', '~> 4.11', '>= 4.11.1' - gem 'faker', '~> 1.9', '>= 1.9.1' - gem 'rspec-graphql_matchers' - gem 'rspec-rails', '~> 3.9', '>= 3.9.1' - gem 'shoulda-matchers', '~> 3.1', '>= 3.1.3' - end - - group :development do - gem 'listen', '>= 3.0.5', '< 3.2' - gem 'rerun' - gem 'rubocop' - # Spring speeds up development by keeping your application running in the - # background. Read more: https://github.com/rails/spring - gem 'spring' - gem 'spring-watcher-listen', '~> 2.0.1' - gem 'yard' - end - - group :test do - gem 'coveralls', require: false - # gem 'simplecov', require: false - gem 'timecop', '~> 0.9' - end - - # Windows does not include zoneinfo files, so bundle the tzinfo-data gem - gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby] +gem 'bundler', '~> 2.3', '>= 2.3.18' +gem 'rexml', '~> 3.2', '>= 3.2.5' + +# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' +gem 'rails', '~> 6.0' # , '>= 5.2.8.1' +# Use Postgres as the database for Active Record +gem 'pg' +# Use Puma as the app server +gem 'puma', '~> 5.6', '>= 5.6.4' +# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder +gem 'jbuilder', '~> 2.11', '>= 2.11.5' +# Use Redis adapter to run Action Cable in production +# gem 'redis', '~> 4.0' +# Use ActiveModel has_secure_password +gem 'bcrypt', '~> 3.1', '>= 3.1.18' + +# v1 api is [JSONAPI](https://jsonapi.org/) +gem 'jsonapi-resources', '~> 0.10', '>= 0.10.7' + +# v2 api is [GraphQL](https://graphql.org/) +gem 'graphql', '~> 1.13', '>= 1.13.15' + +# Use ActiveStorage variant +# gem 'mini_magick', '~> 4.8' + +# Use Capistrano for deployment +# gem 'capistrano-rails', group: :development + +# Reduces boot times through caching; required in config/boot.rb +gem 'bootsnap', '>= 1.12.0', require: false + +# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making +# cross-origin AJAX possible +# gem 'rack-cors' + +# Geokit for distance information +gem 'geokit-rails', '~> 2.3' + +# Net - ref: https://stackoverflow.com/questions/70500220/rails-7-ruby-3-1-loaderror-cannot-load-such-file-net-smtp. +gem 'net-imap', require: false +gem 'net-pop', require: false +gem 'net-smtp', require: false + +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 'database_cleaner', '~> 1.7', '>= 1.7.0' + gem 'factory_bot_rails', '~> 4.11', '>= 4.11.1' + gem 'faker', '~> 2.21', '>= 2.21.0' + gem 'rspec-graphql_matchers', '~> 1.3' + gem 'rspec-rails', '~> 3.9', '>= 3.9.1' + gem 'shoulda-matchers', '~> 3.1', '>= 3.1.3' +end + +group :development do + gem 'listen', '>= 3.0.5', '< 3.2' + gem 'rerun', '>= 0.13.1' + gem 'rubocop', '~> 1.32' + # Spring speeds up development by keeping your application running in the + # background. Read more: https://github.com/rails/spring + gem 'spring' + gem 'spring-watcher-listen', '~> 2.0.1' + gem 'yard' +end + +group :test do + gem 'coveralls', require: false + # gem 'simplecov', require: false + gem 'timecop', '~> 0.9' end + +# Windows does not include zoneinfo files, so bundle the tzinfo-data gem +gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby] diff --git a/Gemfile.lock b/Gemfile.lock index 837f074..b7a9e5f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,53 +1,67 @@ -GEM - specs: - GEM remote: https://rubygems.org/ specs: - actioncable (5.2.8.1) - actionpack (= 5.2.8.1) + actioncable (6.1.6.1) + actionpack (= 6.1.6.1) + activesupport (= 6.1.6.1) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailer (5.2.8.1) - actionpack (= 5.2.8.1) - actionview (= 5.2.8.1) - activejob (= 5.2.8.1) + actionmailbox (6.1.6.1) + actionpack (= 6.1.6.1) + activejob (= 6.1.6.1) + activerecord (= 6.1.6.1) + activestorage (= 6.1.6.1) + activesupport (= 6.1.6.1) + mail (>= 2.7.1) + actionmailer (6.1.6.1) + actionpack (= 6.1.6.1) + actionview (= 6.1.6.1) + activejob (= 6.1.6.1) + activesupport (= 6.1.6.1) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.2.8.1) - actionview (= 5.2.8.1) - activesupport (= 5.2.8.1) - rack (~> 2.0, >= 2.0.8) + actionpack (6.1.6.1) + actionview (= 6.1.6.1) + activesupport (= 6.1.6.1) + rack (~> 2.0, >= 2.0.9) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.2.8.1) - activesupport (= 5.2.8.1) + rails-html-sanitizer (~> 1.0, >= 1.2.0) + actiontext (6.1.6.1) + actionpack (= 6.1.6.1) + activerecord (= 6.1.6.1) + activestorage (= 6.1.6.1) + activesupport (= 6.1.6.1) + nokogiri (>= 1.8.5) + actionview (6.1.6.1) + activesupport (= 6.1.6.1) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (5.2.8.1) - activesupport (= 5.2.8.1) + rails-html-sanitizer (~> 1.1, >= 1.2.0) + activejob (6.1.6.1) + activesupport (= 6.1.6.1) globalid (>= 0.3.6) - activemodel (5.2.8.1) - activesupport (= 5.2.8.1) - activerecord (5.2.8.1) - activemodel (= 5.2.8.1) - activesupport (= 5.2.8.1) - arel (>= 9.0) - activestorage (5.2.8.1) - actionpack (= 5.2.8.1) - activerecord (= 5.2.8.1) - marcel (~> 1.0.0) - activesupport (5.2.8.1) + activemodel (6.1.6.1) + activesupport (= 6.1.6.1) + activerecord (6.1.6.1) + activemodel (= 6.1.6.1) + activesupport (= 6.1.6.1) + activestorage (6.1.6.1) + actionpack (= 6.1.6.1) + activejob (= 6.1.6.1) + activerecord (= 6.1.6.1) + activesupport (= 6.1.6.1) + marcel (~> 1.0) + mini_mime (>= 1.1.0) + activesupport (6.1.6.1) concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 0.7, < 2) - minitest (~> 5.1) - tzinfo (~> 1.1) - arel (9.0.0) - ast (2.4.0) - bcrypt (3.1.12) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) + zeitwerk (~> 2.3) + ast (2.4.2) + bcrypt (3.1.18) bootsnap (1.12.0) msgpack (~> 1.2) builder (3.2.4) @@ -62,6 +76,7 @@ GEM crass (1.0.6) database_cleaner (1.7.0) diff-lcs (1.5.0) + digest (3.1.0) docile (1.3.1) erubi (1.10.0) factory_bot (4.11.1) @@ -69,19 +84,18 @@ GEM factory_bot_rails (4.11.1) factory_bot (~> 4.11.1) railties (>= 3.0.0) - faker (1.9.1) - i18n (>= 0.7) - ffi (1.12.2) + faker (2.21.0) + i18n (>= 1.8.11, < 2) + ffi (1.15.5) geokit (1.13.1) geokit-rails (2.3.2) geokit (~> 1.5) rails (>= 3.0) globalid (1.0.0) activesupport (>= 5.0) - graphql (1.8.13) + graphql (1.13.15) i18n (1.12.0) concurrent-ruby (~> 1.0) - jaro_winkler (1.5.2) jbuilder (2.11.5) actionview (>= 5.0.0) activesupport (>= 5.0.0) @@ -90,10 +104,9 @@ GEM activerecord (>= 4.1) concurrent-ruby railties (>= 4.1) - listen (3.1.5) + listen (3.0.8) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) - ruby_dep (~> 1.2) loofah (2.18.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) @@ -105,59 +118,81 @@ GEM mini_portile2 (2.8.0) minitest (5.16.2) msgpack (1.5.3) + net-imap (0.2.3) + digest + net-protocol + strscan + net-pop (0.1.1) + digest + net-protocol + timeout + net-protocol (0.1.3) + timeout + net-smtp (0.3.1) + digest + net-protocol + timeout nio4r (2.5.8) - nokogiri (1.13.7) + nokogiri (1.13.8) mini_portile2 (~> 2.8.0) racc (~> 1.4) - parallel (1.13.0) - parser (2.6.0.0) - ast (~> 2.4.0) + parallel (1.22.1) + parser (3.1.2.0) + ast (~> 2.4.1) pg (1.1.4) - powerpack (0.1.2) - puma (4.3.12) + puma (5.6.4) nio4r (~> 2.0) racc (1.6.0) rack (2.2.4) rack-test (2.0.2) rack (>= 1.3) - rails (5.2.8.1) - actioncable (= 5.2.8.1) - actionmailer (= 5.2.8.1) - actionpack (= 5.2.8.1) - actionview (= 5.2.8.1) - activejob (= 5.2.8.1) - activemodel (= 5.2.8.1) - activerecord (= 5.2.8.1) - activestorage (= 5.2.8.1) - activesupport (= 5.2.8.1) - bundler (>= 1.3.0) - railties (= 5.2.8.1) + rails (6.1.6.1) + actioncable (= 6.1.6.1) + actionmailbox (= 6.1.6.1) + actionmailer (= 6.1.6.1) + actionpack (= 6.1.6.1) + actiontext (= 6.1.6.1) + actionview (= 6.1.6.1) + activejob (= 6.1.6.1) + activemodel (= 6.1.6.1) + activerecord (= 6.1.6.1) + activestorage (= 6.1.6.1) + activesupport (= 6.1.6.1) + bundler (>= 1.15.0) + railties (= 6.1.6.1) sprockets-rails (>= 2.0.0) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) rails-html-sanitizer (1.4.3) loofah (~> 2.3) - railties (5.2.8.1) - actionpack (= 5.2.8.1) - activesupport (= 5.2.8.1) + railties (6.1.6.1) + actionpack (= 6.1.6.1) + activesupport (= 6.1.6.1) method_source - rake (>= 0.8.7) - thor (>= 0.19.0, < 2.0) - rainbow (3.0.0) + rake (>= 12.2) + thor (~> 1.0) + rainbow (3.1.1) rake (13.0.6) - rb-fsevent (0.10.4) + rb-fsevent (0.11.1) rb-inotify (0.10.1) ffi (~> 1.0) - rerun (0.13.0) + regexp_parser (2.5.0) + rerun (0.13.1) listen (~> 3.0) + rexml (3.2.5) + rspec (3.9.0) + rspec-core (~> 3.9.0) + rspec-expectations (~> 3.9.0) + rspec-mocks (~> 3.9.0) rspec-core (3.9.3) rspec-support (~> 3.9.3) rspec-expectations (3.9.4) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.9.0) - rspec-graphql_matchers (0.7.1) - graphql (>= 0.9, < 2) + rspec-graphql_matchers (1.3.1) + graphql (>= 1.8, < 2.0) + rspec (~> 3.0) rspec-mocks (3.9.1) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.9.0) @@ -170,16 +205,19 @@ GEM rspec-mocks (~> 3.9.0) rspec-support (~> 3.9.0) rspec-support (3.9.4) - rubocop (0.63.1) - jaro_winkler (~> 1.5.1) + rubocop (1.32.0) + json (~> 2.3) parallel (~> 1.10) - parser (>= 2.5, != 2.5.1.1) - powerpack (~> 0.1) + parser (>= 3.1.0.0) rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.19.1, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (~> 1.4.0) - ruby-progressbar (1.10.0) - ruby_dep (1.5.0) + unicode-display_width (>= 1.4.0, < 3.0) + rubocop-ast (1.19.1) + parser (>= 3.1.1.0) + ruby-progressbar (1.11.0) shoulda-matchers (3.1.3) activesupport (>= 4.0.0) simplecov (0.16.1) @@ -198,54 +236,61 @@ GEM actionpack (>= 5.2) activesupport (>= 5.2) sprockets (>= 3.0.0) + strscan (3.0.4) sync (0.5.0) term-ansicolor (1.7.1) tins (~> 1.0) - thor (1.0.1) - thread_safe (0.3.6) - timecop (0.9.1) + thor (1.2.1) + timecop (0.9.5) + timeout (0.3.0) tins (1.24.1) sync - tzinfo (1.2.10) - thread_safe (~> 0.1) - unicode-display_width (1.4.1) + tzinfo (2.0.5) + concurrent-ruby (~> 1.0) + unicode-display_width (2.2.0) websocket-driver (0.7.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) yard (0.9.20) + zeitwerk (2.6.0) PLATFORMS ruby DEPENDENCIES - bcrypt (~> 3.1.7)! - bootsnap (>= 1.1.0)! - byebug! - coveralls! - database_cleaner (~> 1.7, >= 1.7.0)! - factory_bot_rails (~> 4.11, >= 4.11.1)! - faker (~> 1.9, >= 1.9.1)! - geokit-rails! - graphql (~> 1.7, >= 1.7.14)! - jbuilder (~> 2.10, >= 2.10.0)! - jsonapi-resources (~> 0.10, >= 0.10.7)! - listen (>= 3.0.5, < 3.2)! - pg! - puma (~> 4.3, >= 4.3.9)! - rails (~> 5.2, >= 5.2.8.1)! - rerun! - rspec-graphql_matchers! - rspec-rails (~> 3.9, >= 3.9.1)! - rubocop! - shoulda-matchers (~> 3.1, >= 3.1.3)! - spring! - spring-watcher-listen (~> 2.0.1)! - timecop (~> 0.9)! - tzinfo-data! - yard! + bcrypt (~> 3.1, >= 3.1.18) + bootsnap (>= 1.12.0) + bundler (~> 2.3, >= 2.3.18) + byebug + coveralls + database_cleaner (~> 1.7, >= 1.7.0) + factory_bot_rails (~> 4.11, >= 4.11.1) + faker (~> 2.21, >= 2.21.0) + geokit-rails (~> 2.3) + graphql (~> 1.13, >= 1.13.15) + jbuilder (~> 2.11, >= 2.11.5) + jsonapi-resources (~> 0.10, >= 0.10.7) + listen (>= 3.0.5, < 3.2) + net-imap + net-pop + net-smtp + pg + puma (~> 5.6, >= 5.6.4) + rails (~> 6.0) + rerun (>= 0.13.1) + rexml (~> 3.2, >= 3.2.5) + rspec-graphql_matchers (~> 1.3) + rspec-rails (~> 3.9, >= 3.9.1) + rubocop (~> 1.32) + shoulda-matchers (~> 3.1, >= 3.1.3) + spring + spring-watcher-listen (~> 2.0.1) + timecop (~> 0.9) + tzinfo-data + yard RUBY VERSION - ruby 2.7.6p219 + ruby 3.1.2p20 BUNDLED WITH 2.3.18 diff --git a/app/controllers/graphql_controller.rb b/app/controllers/graphql_controller.rb index 1cf5136..8d03ddf 100644 --- a/app/controllers/graphql_controller.rb +++ b/app/controllers/graphql_controller.rb @@ -8,7 +8,7 @@ class GraphqlController < ApplicationController # Exectus things # # @return [void] - def execute # rubocop:disable Metrics/MethodLength + def execute variables = ensure_hash(params[:variables]) query = params[:query] operation_name = params[:operationName] @@ -16,17 +16,12 @@ def execute # rubocop:disable Metrics/MethodLength # Query context goes here, for example: # current_user: current_user, } - result = FreqFinderSchema.execute( - query, - variables: variables, - context: context, - operation_name: operation_name - ) + result = FreqFinderSchema.execute(query, variables:, context:, operation_name:) render json: result - rescue StandardError => error - raise error unless Rails.env.development? + rescue StandardError => e + raise e unless Rails.env.development? - handle_error_in_development(error) + handle_error_in_development(e) end private @@ -35,7 +30,7 @@ def execute # rubocop:disable Metrics/MethodLength # # @param [Hash] ambiguous_param # @return [Hash] - def ensure_hash(ambiguous_param) # rubocop:disable Metrics/MethodLength + def ensure_hash(ambiguous_param) case ambiguous_param when String if ambiguous_param.present? diff --git a/app/controllers/transmitters_controller.rb b/app/controllers/transmitters_controller.rb index dd60169..4b8e912 100644 --- a/app/controllers/transmitters_controller.rb +++ b/app/controllers/transmitters_controller.rb @@ -9,7 +9,7 @@ class TransmittersController < ApplicationController before_action :set_location, only: %i[index show] before_action :set_transmitter, only: [:show] - LATLNG_PATTERN = /^(-?\d+\.\d+),(-?\d+\.\d+)$/.freeze + LATLNG_PATTERN = /^(-?\d+\.\d+),(-?\d+\.\d+)$/ # GET /stations def index diff --git a/app/graphql/types/query_type.rb b/app/graphql/types/query_type.rb index eecbdea..b4a9b20 100644 --- a/app/graphql/types/query_type.rb +++ b/app/graphql/types/query_type.rb @@ -16,7 +16,8 @@ class QueryType < Types::BaseObject argument :id, ID, required: true end - field :allStations, Types::StationConnectionType, null: true, connection: true do + field :allStations, Types::StationConnectionType, null: true, resolver_method: :all_stations, + connection: true do description 'All the stations' end @@ -27,7 +28,11 @@ class QueryType < Types::BaseObject argument :location, String, required: false end - field :allTransmitters, Types::TransmitterConnectionType, null: true, connection: true do + field :allTransmitters, + Types::TransmitterConnectionType, + null: true, + resolver_method: :all_transmitters, + connection: true do description 'All the transmitters' argument :location, String, required: false argument :order_by, String, required: false # , default: 'frequency_ASC' @@ -54,7 +59,7 @@ def all_stations # @param [String] location comma separated GPS coordinate # @return [Transmitter] def transmitter(id:, location: nil) - Transmitter.where(id: id) + Transmitter.where(id:) .by_distance_with_backup_sort(location) .first end diff --git a/app/graphql/types/transmitter_type.rb b/app/graphql/types/transmitter_type.rb index f4e1c90..078cdbe 100644 --- a/app/graphql/types/transmitter_type.rb +++ b/app/graphql/types/transmitter_type.rb @@ -39,26 +39,31 @@ class TransmitterType < Types::BaseObject field :technical_specification_number, Integer, null: false field :zone, Integer, null: false - field :distance, - Float, - null: true, - resolve: lambda { |transmitter, _args, ctx| - # There are options on obtaining the location - tmp = ctx.irep_node - location = nil - loop do - tmp = tmp.parent - break if tmp.nil? + field :distance, Float, null: true, resolver_method: :distance, extras: [:parent] - if tmp.arguments.respond_to?(:location) - location = tmp.arguments.location - break - end - end - return nil if location.nil? || !Location.valid_gps?(location) + # Distance is used to calculate the value for the field :distance. + # + # @param [Object] parent + # @return [Numeric] + def distance(parent:) + # There are options on obtaining the location + ancestor = parent + location = nil - Location.normalize(location) - .distance_to(transmitter.location, units: :meters) - } + loop do + break if ancestor.nil? + + if ancestor.arguments.respond_to?(:location) + location = ancestor.arguments.location + break + end + + ancestor = ancestor.parent + end + + return nil if location.nil? || !Location.valid_gps?(location) + + Location.normalize(location).distance_to(transmitter.location, units: :meters) + end end end diff --git a/app/lib/extract_transform_load.rb b/app/lib/extract_transform_load.rb index 87d069d..1538d09 100644 --- a/app/lib/extract_transform_load.rb +++ b/app/lib/extract_transform_load.rb @@ -20,7 +20,7 @@ def export_subdirectory # Exports the data to an RFC3337 subdirectory of the export directory. # # @return [void] - def export! # rubocop:disable Metrics/AbcSize, Metrics/MethodLength + def export! export_path = BASE_DIR.join(export_subdirectory) FileUtils.mkdir_p(export_path) @@ -31,7 +31,7 @@ def export! # rubocop:disable Metrics/AbcSize, Metrics/MethodLength end filename = s[:title].blank? ? 'null' : s[:title].downcase.gsub(/[^\da-z]/, '_') - File.open(export_path.join("#{filename}.yml"), 'w+') { |w| w.write(station.to_yaml) } + File.write(export_path.join("#{filename}.yml"), station.to_yaml) Rails.logger.info("Exported transmitters for #{s.title} (id: #{s.id})") end end @@ -40,7 +40,7 @@ def export! # rubocop:disable Metrics/AbcSize, Metrics/MethodLength # # @param [String] subdirectory explicitly provide a subdirectory # @return [void] - def import!(subdirectory = nil) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength + def import!(subdirectory = nil) # rubocop:disable Metrics/MethodLength path = import_path_for(subdirectory) import_files(path).each do |station_file| @@ -51,7 +51,7 @@ def import!(subdirectory = nil) # rubocop:disable Metrics/AbcSize, Metrics/Metho station = Station.find_or_create_by(title: station_data[:title]) station_data[:transmitters].each do |transmitter| - transmitter = transmitter.reject { |k, _v| EXCLUDE_KEYS.include?(k) } + transmitter = transmitter.except(*EXCLUDE_KEYS) t = Transmitter.find_or_initialize_by(transmitter) t.station = station t.save @@ -61,7 +61,7 @@ def import!(subdirectory = nil) # rubocop:disable Metrics/AbcSize, Metrics/Metho Rails.logger.info("Data: #{transmitter.inspect}\nErrors: #{t.errors.messages}") end - transmitter_count = Transmitter.where(station: station).count + transmitter_count = Transmitter.where(station:).count Rails.logger.info( "Imported #{transmitter_count} transmitters for #{station.title} (id: #{station.id})" ) @@ -88,9 +88,7 @@ def import_files(path) def import_path_for(subdirectory = nil) return BASE_DIR if subdirectory.nil? - if !subdirectory.is_a?(String) || !Dir.exist?(BASE_DIR.join(subdirectory)) - raise ArgumentError, 'subdirectory does not exist' - end + raise ArgumentError, 'subdirectory does not exist' if !subdirectory.is_a?(String) || !Dir.exist?(BASE_DIR.join(subdirectory)) BASE_DIR.join(subdirectory) end diff --git a/app/lib/location.rb b/app/lib/location.rb index 54ad79a..7217de4 100644 --- a/app/lib/location.rb +++ b/app/lib/location.rb @@ -6,7 +6,7 @@ # @author Joel Courtney class Location < Geokit::LatLng # @!group Constants - LATLNG_PATTERN = /^(-?\d+\.\d+),(-?\d+\.\d+)$/.freeze + LATLNG_PATTERN = /^(-?\d+\.\d+),(-?\d+\.\d+)$/ # @!endgroup # @!group Class methods diff --git a/app/views/stations/index.json.jbuilder b/app/views/stations/index.json.jbuilder index 9011504..a945526 100644 --- a/app/views/stations/index.json.jbuilder +++ b/app/views/stations/index.json.jbuilder @@ -2,5 +2,5 @@ # app/views/stations/index.json.jbuilder json.array! @stations do |station| - json.partial! 'station', station: station + json.partial! 'station', station: end diff --git a/bin/rails b/bin/rails index 3504c3f..33ffd90 100755 --- a/bin/rails +++ b/bin/rails @@ -1,11 +1,7 @@ #!/usr/bin/env ruby # frozen_string_literal: true -begin - load File.expand_path('spring', __dir__) -rescue LoadError => e - raise unless e.message.include?('spring') -end +load File.expand_path('spring', __dir__) APP_PATH = File.expand_path('../config/application', __dir__) require_relative '../config/boot' require 'rails/commands' diff --git a/bin/rake b/bin/rake index 1fe6cf0..05ee931 100755 --- a/bin/rake +++ b/bin/rake @@ -1,11 +1,7 @@ #!/usr/bin/env ruby # frozen_string_literal: true -begin - load File.expand_path('spring', __dir__) -rescue LoadError => e - raise unless e.message.include?('spring') -end +load File.expand_path('spring', __dir__) require_relative '../config/boot' require 'rake' Rake.application.run diff --git a/bin/setup b/bin/setup index f17c566..234da41 100755 --- a/bin/setup +++ b/bin/setup @@ -2,7 +2,6 @@ # frozen_string_literal: true require 'fileutils' -include FileUtils # path to your application root. APP_ROOT = File.expand_path('..', __dir__) @@ -11,8 +10,9 @@ def system!(*args) system(*args) || abort("\n== Command #{args} failed ==") end -chdir APP_ROOT do - # This script is a starting point to setup your application. +FileUtils.chdir APP_ROOT do + # This script is a way to set up or update your development environment automatically. + # 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 ==' @@ -21,11 +21,11 @@ chdir APP_ROOT do # puts "\n== Copying sample files ==" # unless File.exist?('config/database.yml') - # cp 'config/database.yml.sample', 'config/database.yml' + # FileUtils.cp 'config/database.yml.sample', 'config/database.yml' # end puts "\n== Preparing database ==" - system! 'bin/rails db:setup' + system! 'bin/rails db:prepare' puts "\n== Removing old logs and tempfiles ==" system! 'bin/rails log:clear tmp:clear' diff --git a/bin/spring b/bin/spring index 9bd27ec..5e8e380 100755 --- a/bin/spring +++ b/bin/spring @@ -1,18 +1,16 @@ #!/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' +if !defined?(Spring) && [nil, 'development', 'test'].include?(ENV.fetch('RAILS_ENV', nil)) + gem 'bundler' require 'bundler' - lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read) - spring = lockfile.specs.detect { |spec| spec.name == 'spring' } - if spring + # Load Spring without loading other gems in the Gemfile, for speed. + Bundler.locked_gems&.specs&.find { |spec| spec.name == 'spring' }&.tap do |spring| Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path gem 'spring', spring.version require 'spring/binstub' + rescue Gem::LoadError + # Ignore when Spring is not installed. end end diff --git a/config.ru b/config.ru index 842bccc..6dc8321 100644 --- a/config.ru +++ b/config.ru @@ -5,3 +5,4 @@ require_relative 'config/environment' run Rails.application +Rails.application.load_server diff --git a/config/application.rb b/config/application.rb index 82a03fe..52620f3 100644 --- a/config/application.rb +++ b/config/application.rb @@ -10,6 +10,8 @@ require 'active_storage/engine' require 'action_controller/railtie' require 'action_mailer/railtie' +require 'action_mailbox/engine' +require 'action_text/engine' require 'action_view/railtie' require 'action_cable/engine' # require "sprockets/railtie" @@ -28,11 +30,13 @@ class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. config.load_defaults 5.2 - # Settings in config/environments/* take precedence over those specified - # here. - # Application configuration can go into files in config/initializers - # -- all .rb files in that directory are automatically loaded after loading - # the framework and any gems in your application. + # 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") # Only loads a smaller set of middleware suitable for API only apps. # Middleware like session, flash, cookies can be added back manually. diff --git a/config/cable.yml b/config/cable.yml index 0760902..087470f 100644 --- a/config/cable.yml +++ b/config/cable.yml @@ -7,4 +7,4 @@ test: production: adapter: redis url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %> - channel_prefix: freq-finder_production + channel_prefix: freq_finder_production diff --git a/config/database.yml b/config/database.yml index 70d8663..9008c9a 100644 --- a/config/database.yml +++ b/config/database.yml @@ -13,24 +13,28 @@ # Configure Using Gemfile # gem 'pg' # -default: &default +development: adapter: postgresql encoding: unicode pool: 5 - -development: - <<: *default - database: freqfinder_development + host: <%= ENV['PGHOST'] %> + user: <%= ENV['PGUSER'] %> + password: <%= ENV['PGPASSWORD'] %> + database: <%= ENV['PGDB'] %> # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. test: - <<: *default + adapter: postgresql + encoding: unicode + pool: 5 host: <%= ENV['PGHOST'] %> user: <%= ENV['PGUSER'] %> password: <%= ENV['PGPASSWORD'] %> database: <%= ENV['PGDB'] %> production: - <<: *default + adapter: postgresql + encoding: unicode + pool: 5 database: freqfinder_production diff --git a/config/environments/development.rb b/config/environments/development.rb index 6ee8405..d3ab08f 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,11 +1,12 @@ # frozen_string_literal: true +require 'active_support/core_ext/integer/time' + Rails.application.configure do - # Settings specified here will take precedence over those in - # `config/application.rb`. + # 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 + # In the development environment your application's code is reloaded any time + # it changes. 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 @@ -18,8 +19,6 @@ # Enable/disable caching. By default caching is disabled. # Run rails dev:cache to toggle caching. if Rails.root.join('tmp', 'caching-dev.txt').exist? - config.action_controller.perform_caching = true - config.cache_store = :memory_store config.public_file_server.headers = { 'Cache-Control' => "public, max-age=#{2.days.to_i}" @@ -30,8 +29,7 @@ config.cache_store = :null_store end - # Store uploaded files on the local file system (see config/storage.yml for - # options) + # 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. @@ -42,16 +40,28 @@ # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log + # Raise exceptions for disallowed deprecations. + config.active_support.disallowed_deprecation = :raise + + # Tell Active Support which deprecation messages to disallow. + config.active_support.disallowed_deprecation_warnings = [] + # Raise an error on page load if there are pending migrations. config.active_record.migration_error = :page_load # Highlight code that triggered database queries in logs. config.active_record.verbose_query_logs = true - # Raises error for missing translations - # config.action_view.raise_on_missing_translations = true + # Raises error for missing translations. + # config.i18n.raise_on_missing_translations = true + + # Annotate rendered view with file names. + # config.action_view.annotate_rendered_view_with_filenames = 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 + + # Uncomment if you wish to allow Action Cable access from any origin. + # config.action_cable.disable_request_forgery_protection = true end diff --git a/config/environments/production.rb b/config/environments/production.rb index dce7351..8a2c103 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,8 +1,9 @@ # frozen_string_literal: true +require 'active_support/core_ext/integer/time' + Rails.application.configure do - # Settings specified here will take precedence over those in - # `config/application.rb`. + # Settings specified here will take precedence over those in config/application.rb. # Code is not reloaded between requests. config.cache_classes = true @@ -14,46 +15,37 @@ 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 + 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 + # 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 # 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? # Enable serving of images, stylesheets, and JavaScripts from an asset server. - # config.action_controller.asset_host = 'http://assets.example.com' + # config.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 - # Store uploaded files on the local file system (see config/storage.yml for - # options) + # 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.*/ - # ] - - # Force all access to the app over SSL, use Strict-Transport-Security, and use - # secure cookies. - # - # config.force_ssl = true + # 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.*/ ] + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + # config.force_ssl = true - # Use the lowest log level to ensure availability of diagnostic information - # when problems arise. - config.log_level = :debug + # Include generic and useful information about system operation, but avoid logging too much + # information to avoid inadvertent exposure of personally identifiable information (PII). + config.log_level = :info # Prepend all log lines with the following tags. config.log_tags = [:request_id] @@ -61,16 +53,14 @@ # Use a different cache store in production. # config.cache_store = :mem_cache_store - # Use a real queuing backend for Active Job (and separate queues per - # environment) + # 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 = "freq-finder_#{Rails.env}" + # config.active_job.queue_name_prefix = "freq_finder_production" config.action_mailer.perform_caching = false # 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. + # Set this to true and configure the email server for immediate delivery to raise delivery errors. # config.action_mailer.raise_delivery_errors = false # Enable locale fallbacks for I18n (makes lookups for any locale fall back to @@ -80,21 +70,46 @@ # Send deprecation notices to registered listeners. config.active_support.deprecation = :notify + # Log disallowed deprecations. + config.active_support.disallowed_deprecation = :log + + # Tell Active Support which deprecation messages to disallow. + config.active_support.disallowed_deprecation_warnings = [] + # 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' - # ) + # 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 = 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. + # + # 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 end diff --git a/config/environments/test.rb b/config/environments/test.rb index 460761d..337b89c 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -1,14 +1,17 @@ # frozen_string_literal: true +require 'active_support/core_ext/integer/time' + +# The test environment is used exclusively to run your application's +# test suite. You never need to work with it otherwise. Remember that +# your test database is "scratch space" for the test suite and is wiped +# and recreated between test runs. Don't rely on the data there! + Rails.application.configure do - # Settings specified here will take precedence over those in - # `config/application.rb`. + # Settings specified here will take precedence over those in config/application.rb. - # The test environment is used exclusively to run your application's - # test suite. You never need to work with it otherwise. Remember that - # your test database is "scratch space" for the test suite and is wiped - # and recreated between test runs. Don't rely on the data there! - config.cache_classes = true + 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 @@ -24,6 +27,7 @@ # Show full error reports and disable caching. config.consider_all_requests_local = true config.action_controller.perform_caching = false + config.cache_store = :null_store # Raise exceptions instead of rendering exception templates. config.action_dispatch.show_exceptions = false @@ -31,7 +35,7 @@ # Disable request forgery protection in test environment. config.action_controller.allow_forgery_protection = false - # Store uploaded files on the local file system in a temporary directory + # Store uploaded files on the local file system in a temporary directory. config.active_storage.service = :test config.action_mailer.perform_caching = false @@ -44,6 +48,15 @@ # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr - # Raises error for missing translations - # config.action_view.raise_on_missing_translations = true + # Raise exceptions for disallowed deprecations. + config.active_support.disallowed_deprecation = :raise + + # Tell Active Support which deprecation messages to disallow. + config.active_support.disallowed_deprecation_warnings = [] + + # Raises error for missing translations. + config.i18n.raise_on_missing_translations = false + + # Annotate rendered view with file names. + # config.action_view.annotate_rendered_view_with_filenames = true end diff --git a/config/initializers/application_controller_renderer.rb b/config/initializers/application_controller_renderer.rb index 6d56e43..f4556db 100644 --- a/config/initializers/application_controller_renderer.rb +++ b/config/initializers/application_controller_renderer.rb @@ -1,5 +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 00b58d8..d43cc1d 100644 --- a/config/initializers/backtrace_silencers.rb +++ b/config/initializers/backtrace_silencers.rb @@ -2,12 +2,9 @@ # 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. -# -# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } +# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. +# Rails.backtrace_cleaner.add_silencer { |line| /my_noisy_library/.match?(line) } -# You can also remove all the silencers if you're trying to debug a problem that -# might stem from framework code. - -# Rails.backtrace_cleaner.remove_silencers! +# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code +# by setting BACKTRACE=1 before calling your invocation, like "BACKTRACE=1 ./bin/rails runner 'MyClass.perform'". +Rails.backtrace_cleaner.remove_silencers! if ENV['BACKTRACE'] diff --git a/config/initializers/cors.rb b/config/initializers/cors.rb index ef1ab43..5f68d44 100644 --- a/config/initializers/cors.rb +++ b/config/initializers/cors.rb @@ -1,10 +1,8 @@ # frozen_string_literal: true - # Be sure to restart your server when you modify this file. # Avoid CORS issues when API is called from the frontend app. -# Handle Cross-Origin Resource Sharing (CORS) in order to accept cross-origin -# AJAX requests. +# Handle Cross-Origin Resource Sharing (CORS) in order to accept cross-origin AJAX requests. # Read more: https://github.com/cyu/rack-cors diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb index 7a4f47b..3babc73 100644 --- a/config/initializers/filter_parameter_logging.rb +++ b/config/initializers/filter_parameter_logging.rb @@ -3,4 +3,6 @@ # 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] +Rails.application.config.filter_parameters += %i[ + passw secret token _key crypt salt certificate otp ssn +] diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index dc84742..aa7435f 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -1,5 +1,4 @@ # 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/mime_types.rb b/config/initializers/mime_types.rb index be6fedc..6e1d16f 100644 --- a/config/initializers/mime_types.rb +++ b/config/initializers/mime_types.rb @@ -1,5 +1,4 @@ # 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/new_framework_defaults_6_1.rb b/config/initializers/new_framework_defaults_6_1.rb new file mode 100644 index 0000000..0b4ce02 --- /dev/null +++ b/config/initializers/new_framework_defaults_6_1.rb @@ -0,0 +1,68 @@ +# frozen_string_literal: true +# Be sure to restart your server when you modify this file. +# +# This file contains migration options to ease your Rails 6.1 upgrade. +# +# Once upgraded flip defaults one by one to migrate to the new default. +# +# Read the Guide for Upgrading Ruby on Rails for more info on each option. + +# Support for inversing belongs_to -> has_many Active Record associations. +# Rails.application.config.active_record.has_many_inversing = true + +# Track Active Storage variants in the database. +# Rails.application.config.active_storage.track_variants = true + +# Apply random variation to the delay when retrying failed jobs. +# Rails.application.config.active_job.retry_jitter = 0.15 + +# Stop executing `after_enqueue`/`after_perform` callbacks if +# `before_enqueue`/`before_perform` respectively halts with `throw :abort`. +# Rails.application.config.active_job.skip_after_callbacks_if_terminated = true + +# Specify cookies SameSite protection level: either :none, :lax, or :strict. +# +# This change is not backwards compatible with earlier Rails versions. +# It's best enabled when your entire app is migrated and stable on 6.1. +# Rails.application.config.action_dispatch.cookies_same_site_protection = :lax + +# Generate CSRF tokens that are encoded in URL-safe Base64. +# +# This change is not backwards compatible with earlier Rails versions. +# It's best enabled when your entire app is migrated and stable on 6.1. +# Rails.application.config.action_controller.urlsafe_csrf_tokens = true + +# Specify whether `ActiveSupport::TimeZone.utc_to_local` returns a time with an +# UTC offset or a UTC time. +# ActiveSupport.utc_to_local_returns_utc_offset_times = true + +# Change the default HTTP status code to `308` when redirecting non-GET/HEAD +# requests to HTTPS in `ActionDispatch::SSL` middleware. +# Rails.application.config.action_dispatch.ssl_default_redirect_status = 308 + +# Use new connection handling API. For most applications this won't have any +# effect. For applications using multiple databases, this new API provides +# support for granular connection swapping. +# Rails.application.config.active_record.legacy_connection_handling = false + +# Make `form_with` generate non-remote forms by default. +# Rails.application.config.action_view.form_with_generates_remote_forms = false + +# Set the default queue name for the analysis job to the queue adapter default. +# Rails.application.config.active_storage.queues.analysis = nil + +# Set the default queue name for the purge job to the queue adapter default. +# Rails.application.config.active_storage.queues.purge = nil + +# Set the default queue name for the incineration job to the queue adapter default. +# Rails.application.config.action_mailbox.queues.incineration = nil + +# Set the default queue name for the routing job to the queue adapter default. +# Rails.application.config.action_mailbox.queues.routing = nil + +# Set the default queue name for the mail deliver job to the queue adapter default. +# Rails.application.config.action_mailer.deliver_later_queue_name = nil + +# Generate a `Link` header that gives a hint to modern browsers about +# preloading assets when using `javascript_include_tag` and `stylesheet_link_tag`. +# Rails.application.config.action_view.preload_links_header = true diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb index c2179da..2f3c0db 100644 --- a/config/initializers/wrap_parameters.rb +++ b/config/initializers/wrap_parameters.rb @@ -5,8 +5,7 @@ # This file contains settings for ActionController::ParamsWrapper which # is enabled by default. -# Enable parameter wrapping for JSON. You can disable this by setting :format to -# an empty array. +# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. ActiveSupport.on_load(:action_controller) do wrap_parameters format: [:json] end diff --git a/config/locales/en.yml b/config/locales/en.yml index decc5a8..1bbe3bf 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1,3 +1,4 @@ +--- # Files in the config/locales directory are used for internationalization # and are automatically loaded by Rails. If you want to use locales other # than English, add the necessary files in this directory. @@ -27,7 +28,6 @@ # 'true': 'foo' # # To learn more, please read the Rails Internationalization guide -# available at http://guides.rubyonrails.org/i18n.html. - +# available at https://guides.rubyonrails.org/i18n.html. en: hello: "Hello world" diff --git a/config/puma.rb b/config/puma.rb index 2215b0d..8ae6a78 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -6,20 +6,28 @@ # 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. # -threads_count = ENV.fetch('RAILS_MAX_THREADS') { 5 } -threads threads_count, threads_count +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 -# Specifies the `port` that Puma will listen on to receive requests; default is -# 3000. +# Specifies the `worker_timeout` threshold that Puma will use to wait before +# terminating a worker in development environments. # -port ENV.fetch('PORT') { 3000 } +worker_timeout 3600 if ENV.fetch('RAILS_ENV', 'development') == 'development' + +# Specifies the `port` that Puma will listen on to receive requests; default is 3000. +# +port ENV.fetch('PORT', 3000) # Specifies the `environment` that Puma will run in. # -environment ENV.fetch('RAILS_ENV') { 'development' } +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 webserver processes. If using threads and workers together +# 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). diff --git a/config/spring.rb b/config/spring.rb index c5933e4..93cd0ff 100644 --- a/config/spring.rb +++ b/config/spring.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true -%w[ - .ruby-version - .rbenv-vars - tmp/restart.txt - tmp/caching-dev.txt -].each { |path| Spring.watch(path) } +Spring.watch( + '.ruby-version', + '.rbenv-vars', + 'tmp/restart.txt', + 'tmp/caching-dev.txt' +) diff --git a/db/legacy_seeds.rb b/db/legacy_seeds.rb index 7b8779e..c38f901 100644 --- a/db/legacy_seeds.rb +++ b/db/legacy_seeds.rb @@ -24,7 +24,7 @@ def string_to_latitude(string) string.scan(/(\d+)\s(\d+)\s(\d+)([NS])/) .map do |d, m, s, pp| - (d.to_f + m.to_f / 60 + s.to_f / 3600) * (pp == 'N' ? 1 : -1) + (d.to_f + (m.to_f / 60) + (s.to_f / 3600)) * (pp == 'N' ? 1 : -1) end.first end @@ -37,7 +37,7 @@ def string_to_latitude(string) def string_to_longitude(string) string.scan(/(\d+)\s(\d+)\s(\d+)([EW])/) .map do |d, m, s, pp| - (d.to_f + m.to_f / 60 + s.to_f / 3600) * (pp == 'E' ? 1 : -1) + (d.to_f + (m.to_f / 60) + (s.to_f / 3600)) * (pp == 'E' ? 1 : -1) end.first end diff --git a/db/migrate/20220726034516_create_active_storage_tables.active_storage.rb b/db/migrate/20220726034516_create_active_storage_tables.active_storage.rb new file mode 100644 index 0000000..95b67cc --- /dev/null +++ b/db/migrate/20220726034516_create_active_storage_tables.active_storage.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +# This migration comes from active_storage (originally 20170806125915) +class CreateActiveStorageTables < ActiveRecord::Migration[5.2] + def change + create_table :active_storage_blobs do |t| + t.string :key, null: false + t.string :filename, null: false + t.string :content_type + t.text :metadata + t.string :service_name, null: false + t.bigint :byte_size, null: false + t.string :checksum, null: false + t.datetime :created_at, null: false + + t.index [:key], unique: true + end + + create_table :active_storage_attachments do |t| + t.string :name, null: false + t.references :record, null: false, polymorphic: true, index: false + t.references :blob, null: false + + t.datetime :created_at, null: false + + t.index %i[record_type record_id name blob_id], + name: 'index_active_storage_attachments_uniqueness', unique: true + t.foreign_key :active_storage_blobs, column: :blob_id + end + + create_table :active_storage_variant_records do |t| + t.belongs_to :blob, null: false, index: false + t.string :variation_digest, null: false + + t.index %i[blob_id variation_digest], + name: 'index_active_storage_variant_records_uniqueness', unique: true + t.foreign_key :active_storage_blobs, column: :blob_id + end + end +end diff --git a/db/schema.rb b/db/schema.rb index c515799..ada036e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1,22 +1,48 @@ -# 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. # -# Note that this schema.rb definition is the authoritative source for your -# database schema. If you need to create the application database on another -# system, you should be using db:schema:load, not running all the migrations -# from scratch. The latter is a flawed and unsustainable approach (the more migrations -# you'll amass, the slower it'll run and the greater likelihood for issues). +# This file is the source Rails uses to define your schema when running `bin/rails +# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to +# be faster and is potentially less error prone than running all of your +# migrations from scratch. Old migrations may fail to apply correctly if those +# migrations use external dependencies or application code. # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_12_20_022157) do +ActiveRecord::Schema.define(version: 2022_07_26_034516) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" + create_table "active_storage_attachments", force: :cascade do |t| + t.string "name", null: false + t.string "record_type", null: false + t.bigint "record_id", null: false + t.bigint "blob_id", null: false + t.datetime "created_at", null: false + t.index ["blob_id"], name: "index_active_storage_attachments_on_blob_id" + t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true + end + + create_table "active_storage_blobs", force: :cascade do |t| + t.string "key", null: false + t.string "filename", null: false + t.string "content_type" + t.text "metadata" + t.string "service_name", null: false + t.bigint "byte_size", null: false + t.string "checksum", null: false + t.datetime "created_at", null: false + t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true + end + + create_table "active_storage_variant_records", force: :cascade do |t| + t.bigint "blob_id", null: false + t.string "variation_digest", null: false + t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true + end + create_table "stations", force: :cascade do |t| t.string "title" t.datetime "created_at", null: false @@ -56,4 +82,6 @@ t.index ["station_id"], name: "index_transmitters_on_station_id" end + add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id" + add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id" end diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index ba52bbe..fcd0f10 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -2,7 +2,12 @@ version: '3.4' services: db: - image: postgres + image: postgres:14.4-alpine + restart: always + environment: + POSTGRES_DB: freq_finder_development + POSTGRES_PASSWORD: password + POSTGRES_USER: postgres web: build: . command: bundle exec rerun --background "bundle exec rackup -p 3000 -o '0.0.0.0'" @@ -12,7 +17,9 @@ services: environment: RAILS_ENV: development RACK_ENV: development + PGDB: freq_finder_development PGHOST: db + PGPASSWORD: password PGUSER: postgres ports: - "3000:3000" diff --git a/docker-compose.test.yml b/docker-compose.test.yml index c74b071..a289337 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -5,12 +5,12 @@ services: image: postgres:14.4-alpine restart: always environment: - POSTGRES_DB: db_test + POSTGRES_DB: freq_finder_test POSTGRES_PASSWORD: password POSTGRES_USER: postgres - web: + web_test: build: . - command: bundle exec rspec + command: bundle exec rerun rake spec depends_on: - db_test entrypoint: '' @@ -19,11 +19,12 @@ services: CI: 'true' RAILS_ENV: test RACK_ENV: test - PGDB: db_test + PGDB: freq_finder_test PGHOST: db_test PGPASSWORD: password PGUSER: postgres ports: - - "3000:3000" + - '3000:3000' + tty: true volumes: - ./:/app diff --git a/spec/controllers/stations_controller_spec.rb b/spec/controllers/stations_controller_spec.rb index 439f43f..531b322 100644 --- a/spec/controllers/stations_controller_spec.rb +++ b/spec/controllers/stations_controller_spec.rb @@ -2,5 +2,5 @@ require 'rails_helper' -RSpec.describe StationsController, type: :controller do -end +# RSpec.describe StationsController, type: :controller do +# end diff --git a/spec/controllers/transmitters_controller_spec.rb b/spec/controllers/transmitters_controller_spec.rb index 71beeac..8e54bf7 100644 --- a/spec/controllers/transmitters_controller_spec.rb +++ b/spec/controllers/transmitters_controller_spec.rb @@ -2,5 +2,5 @@ require 'rails_helper' -RSpec.describe TransmittersController, type: :controller do -end +# RSpec.describe TransmittersController, type: :controller do +# end diff --git a/spec/factories/station_factory.rb b/spec/factories/station_factory.rb index 77fd9af..8e16db4 100644 --- a/spec/factories/station_factory.rb +++ b/spec/factories/station_factory.rb @@ -10,7 +10,7 @@ end after(:create) do |station, evaluator| - create_list(:transmitter, evaluator.count, station: station) + create_list(:transmitter, evaluator.count, station:) end end end diff --git a/spec/factories/transmitter_factory.rb b/spec/factories/transmitter_factory.rb index ccdbc83..97b36ea 100644 --- a/spec/factories/transmitter_factory.rb +++ b/spec/factories/transmitter_factory.rb @@ -25,7 +25,7 @@ power { 0 } purpose { 'Commercial' } site_id { 0 } - sequence(:site_name) { |n| [Faker::Pokemon.name, n].join('-') } + sequence(:site_name) { |n| [Faker::Games::Pokemon.name, n].join('-') } state { 'NSW' } status { 'Issued' } technical_specification_number { 0 } diff --git a/spec/requests/api/v2/stations_request_spec.rb b/spec/requests/api/v2/stations_request_spec.rb index 5417783..bd3650f 100644 --- a/spec/requests/api/v2/stations_request_spec.rb +++ b/spec/requests/api/v2/stations_request_spec.rb @@ -13,8 +13,8 @@ let(:result) do res = FreqFinderSchema.execute( query_string, - context: context, - variables: variables + context:, + variables: ) # Print any errors pp res if res['errors'] @@ -27,13 +27,13 @@ end it 'returns a 200' do - post url, params: { query: query } + post url, params: { query: } expect(response.response_code).to eq 200 end context 'no stations' do it 'has no errors' do - post url, params: { query: query } + post url, params: { query: } expect(response.parsed_body['errors']).to eq(nil) end end @@ -42,7 +42,7 @@ before(:each) { FactoryBot.create(:station) } it 'has no errors' do - post url, params: { query: query } + post url, params: { query: } expect(response.parsed_body['errors']).to eq(nil) end end @@ -51,7 +51,7 @@ before(:each) { FactoryBot.create_list(:station, 10) } it 'has no errors' do - post url, params: { query: query } + post url, params: { query: } expect(response.parsed_body['errors']).to eq(nil) end end @@ -63,13 +63,13 @@ end it 'returns a 200 even with an error' do - post url, params: { query: query } + post url, params: { query: } expect(response.response_code).to eq 200 end context 'no stations' do it 'has no errors' do - post url, params: { query: query } + post url, params: { query: } expect(response.parsed_body['errors'].length).to be > 0 end end @@ -89,7 +89,7 @@ let(:variables) { { 'stationId' => station.id } } it 'has no errors' do - post url, params: { query: query, variables: variables } + post url, params: { query:, variables: } expect(response.parsed_body['errors']).to eq(nil) end end @@ -99,7 +99,7 @@ let(:variables) { { 'stationId' => '-1' } } it 'empty response' do - post url, params: { query: query, variables: variables } + post url, params: { query:, variables: } expect(response.parsed_body).to be_blank end end @@ -126,7 +126,7 @@ let(:variables) { { 'stationId' => station.id } } it 'has no errors' do - post url, params: { query: query, variables: variables } + post url, params: { query:, variables: } expect(response.parsed_body['errors']).to eq(nil) end end @@ -136,7 +136,7 @@ let(:variables) { { 'stationId' => '-1' } } it 'empty response' do - post url, params: { query: query, variables: variables } + post url, params: { query:, variables: } expect(response.parsed_body).to be_blank end end @@ -165,7 +165,7 @@ let(:variables) { { 'stationId' => station.id } } it 'has no errors' do - post url, params: { query: query, variables: variables } + post url, params: { query:, variables: } expect(response.parsed_body['errors']).to eq(nil) end end @@ -175,7 +175,7 @@ let(:variables) { { 'stationId' => '-1' } } it 'empty response' do - post url, params: { query: query, variables: variables } + post url, params: { query:, variables: } expect(response.parsed_body).to be_blank end end diff --git a/spec/requests/api/v2/transmitters_request_spec.rb b/spec/requests/api/v2/transmitters_request_spec.rb index 0bb8cba..0570e52 100644 --- a/spec/requests/api/v2/transmitters_request_spec.rb +++ b/spec/requests/api/v2/transmitters_request_spec.rb @@ -13,8 +13,8 @@ let(:result) do res = FreqFinderSchema.execute( query_string, - context: context, - variables: variables + context:, + variables: ) # Print any errors pp res if res['errors'] @@ -38,13 +38,13 @@ end it 'returns a 200' do - post url, params: { query: query } + post url, params: { query: } expect(response.response_code).to eq 200 end context 'no transmitters' do it 'has no errors' do - post url, params: { query: query } + post url, params: { query: } expect(response.parsed_body['errors']).to eq(nil) end end @@ -53,7 +53,7 @@ before(:each) { FactoryBot.create(:transmitter) } it 'has no errors' do - post url, params: { query: query } + post url, params: { query: } expect(response.parsed_body['errors']).to eq(nil) end end @@ -62,7 +62,7 @@ before(:each) { FactoryBot.create_list(:transmitter, 10) } it 'has no errors' do - post url, params: { query: query } + post url, params: { query: } expect(response.parsed_body['errors']).to eq(nil) end end @@ -74,13 +74,13 @@ end it 'returns a 200 even with an error' do - post url, params: { query: query } + post url, params: { query: } expect(response.response_code).to eq 200 end context 'no transmitters' do it 'has no errors' do - post url, params: { query: query } + post url, params: { query: } expect(response.parsed_body['errors'].length).to be > 0 end end @@ -100,7 +100,7 @@ let(:variables) { { 'transmitterId' => transmitter.id } } it 'has no errors' do - post url, params: { query: query, variables: variables } + post url, params: { query:, variables: } expect(response.parsed_body['errors']).to eq(nil) end end @@ -110,7 +110,7 @@ let(:variables) { { 'transmitterId' => '-1' } } it 'empty response' do - post url, params: { query: query, variables: variables } + post url, params: { query:, variables: } expect(response.parsed_body['data']['transmitter']).to be_nil end end @@ -129,7 +129,7 @@ let(:variables) { { 'transmitterId' => transmitter.id } } it 'has no errors' do - post url, params: { query: query, variables: variables } + post url, params: { query:, variables: } expect(response.parsed_body['errors']).to eq(nil) end end