From 01c2739f3eabfe4b8c9658efc3bde956d12c579f Mon Sep 17 00:00:00 2001 From: "Daniel (dB.) Doubrovkine" Date: Tue, 19 Mar 2024 12:08:44 -0400 Subject: [PATCH 1/7] Upgraded Rubocop to 1.62.1. --- .rubocop.yml | 9 +++- .rubocop_todo.yml | 73 ++++++++++++++++++++++++++----- Gemfile | 6 ++- Gemfile.lock | 49 ++++++++++++++++----- config/environments/production.rb | 2 +- gemfiles/rails_6.gemfile | 8 +++- gemfiles/rails_6_1.gemfile | 8 +++- gemfiles/rails_7.gemfile | 8 +++- gemfiles/rails_edge.gemfile | 8 +++- spec/api/ping_spec.rb | 1 + spec/api/protected_spec.rb | 2 + spec/features/homepage_spec.rb | 5 ++- spec/features/swagger_spec.rb | 5 ++- 13 files changed, 146 insertions(+), 38 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index f613a7a..440c672 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,6 +2,7 @@ AllCops: Exclude: - vendor/**/* - bin/**/* + NewCops: enable Style/Documentation: Enabled: false @@ -9,7 +10,13 @@ Style/Documentation: Style/FrozenStringLiteralComment: Enabled: false -Metrics/LineLength: +Layout/LineLength: Enabled: false +require: + - rubocop-capybara + - rubocop-rails + - rubocop-rake + - rubocop-rspec + inherit_from: .rubocop_todo.yml diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index bdcf77b..a2a2ca7 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,21 +1,72 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2019-07-06 10:22:55 -0400 using RuboCop version 0.72.0. +# on 2024-03-19 16:06:55 UTC using RuboCop version 1.62.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 2 -# Configuration parameters: CountComments, ExcludedMethods. -# ExcludedMethods: refine -Metrics/BlockLength: - Max: 33 +# Offense count: 1 +# Configuration parameters: AllowComments, AllowEmptyLambdas. +Lint/EmptyBlock: + Exclude: + - 'spec/helpers/welcome_helper_spec.rb' # Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, AllowInnerSlashes. -# SupportedStyles: slashes, percent_r, mixed -Style/RegexpLiteral: +# This cop supports unsafe autocorrection (--autocorrect-all). +RSpec/EmptyExampleGroup: + Exclude: + - 'spec/helpers/welcome_helper_spec.rb' + +# Offense count: 4 +# Configuration parameters: CountAsOne. +RSpec/ExampleLength: + Max: 13 + +# Offense count: 5 +# Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly. +# Include: **/*_spec*rb*, **/spec/**/* +RSpec/FilePath: + Exclude: + - 'spec/api/headers_spec.rb' + - 'spec/api/ping_spec.rb' + - 'spec/api/post_spec.rb' + - 'spec/api/protected_spec.rb' + - 'spec/api/raise_spec.rb' + +# Offense count: 4 +RSpec/MultipleExpectations: + Max: 2 + +# Offense count: 4 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: ResponseMethods. +# ResponseMethods: response, last_response +RSpec/Rails/HaveHttpStatus: + Exclude: + - 'spec/api/post_spec.rb' + - 'spec/api/protected_spec.rb' + +# Offense count: 2 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: Inferences. +RSpec/Rails/InferredSpecType: + Exclude: + - 'spec/features/homepage_spec.rb' + - 'spec/features/swagger_spec.rb' + +# Offense count: 2 +RSpec/RepeatedExample: + Exclude: + - 'spec/api/headers_spec.rb' + +# Offense count: 5 +# Configuration parameters: Include, CustomTransform, IgnoreMethods, IgnoreMetadata. +# Include: **/*_spec.rb +RSpec/SpecFilePathFormat: Exclude: - - 'spec/spec_helper.rb' + - 'spec/api/headers_spec.rb' + - 'spec/api/ping_spec.rb' + - 'spec/api/post_spec.rb' + - 'spec/api/protected_spec.rb' + - 'spec/api/raise_spec.rb' diff --git a/Gemfile b/Gemfile index ee59b6e..76c2273 100644 --- a/Gemfile +++ b/Gemfile @@ -72,7 +72,11 @@ group :test do gem 'capybara' gem 'rspec' gem 'rspec-rails' - gem 'rubocop' + gem 'rubocop', '1.62.1' + gem 'rubocop-capybara' + gem 'rubocop-rails' + gem 'rubocop-rake' + gem 'rubocop-rspec' gem 'selenium-webdriver' gem 'webdrivers' end diff --git a/Gemfile.lock b/Gemfile.lock index d30338f..bd7bc66 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -131,6 +131,8 @@ GEM jbuilder (2.11.5) actionview (>= 5.0.0) activesupport (>= 5.0.0) + json (2.7.1) + language_server-protocol (3.17.0.3) loofah (2.19.1) crass (~> 1.0.2) nokogiri (>= 1.5.9) @@ -165,9 +167,10 @@ GEM racc (~> 1.4) nokogiri (1.14.3-x86_64-linux) racc (~> 1.4) - parallel (1.22.1) - parser (3.1.2.0) + parallel (1.24.0) + parser (3.3.0.5) ast (~> 2.4.1) + racc pg (1.3.5) public_suffix (4.0.7) puma (5.6.7) @@ -231,18 +234,35 @@ GEM rspec-mocks (~> 3.10) rspec-support (~> 3.10) rspec-support (3.11.0) - rubocop (1.30.1) + rubocop (1.62.1) + json (~> 2.3) + language_server-protocol (>= 3.17.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 (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.18.0, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.18.0) - parser (>= 3.1.1.0) - ruby-progressbar (1.11.0) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.31.2) + parser (>= 3.3.0.4) + rubocop-capybara (2.20.0) + rubocop (~> 1.41) + rubocop-factory_bot (2.25.1) + rubocop (~> 1.41) + rubocop-rails (2.24.0) + activesupport (>= 4.2.0) + rack (>= 1.1) + rubocop (>= 1.33.0, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) + rubocop-rake (0.6.0) + rubocop (~> 1.0) + rubocop-rspec (2.27.1) + rubocop (~> 1.40) + rubocop-capybara (~> 2.17) + rubocop-factory_bot (~> 2.22) + ruby-progressbar (1.13.0) ruby2_keywords (0.0.5) rubyzip (2.3.2) selenium-webdriver (4.2.1) @@ -267,7 +287,7 @@ GEM railties (>= 6.0.0) tzinfo (2.0.6) concurrent-ruby (~> 1.0) - unicode-display_width (2.1.0) + unicode-display_width (2.5.0) web-console (4.2.0) actionview (>= 6.0.0) activemodel (>= 6.0.0) @@ -287,6 +307,7 @@ GEM PLATFORMS arm64-darwin-21 + x86_64-darwin-19 x86_64-darwin-20 x86_64-linux @@ -304,7 +325,11 @@ DEPENDENCIES rails (~> 7.0.4) rspec rspec-rails - rubocop + rubocop (= 1.62.1) + rubocop-capybara + rubocop-rails + rubocop-rake + rubocop-rspec selenium-webdriver sprockets-rails stimulus-rails @@ -314,4 +339,4 @@ DEPENDENCIES webdrivers BUNDLED WITH - 2.3.16 + 2.3.26 diff --git a/config/environments/production.rb b/config/environments/production.rb index 8072182..e2408b6 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -76,7 +76,7 @@ config.active_support.report_deprecations = false # Use default logging formatter so that PID and timestamp are not suppressed. - config.log_formatter = ::Logger::Formatter.new + config.log_formatter = Logger::Formatter.new # Use a different logger for distributed setups. # require "syslog/logger" diff --git a/gemfiles/rails_6.gemfile b/gemfiles/rails_6.gemfile index e7a226c..4bf9ccf 100644 --- a/gemfiles/rails_6.gemfile +++ b/gemfiles/rails_6.gemfile @@ -8,7 +8,7 @@ gem 'grape-swagger' gem 'importmap-rails' gem 'jbuilder' gem 'pg', '~> 1.1' -gem 'puma', '~> 5.0' +gem 'puma', '~> 5.6' gem 'rails', '~> 6.0' gem 'sprockets-rails' gem 'stimulus-rails' @@ -28,7 +28,11 @@ group :test do gem 'capybara' gem 'rspec' gem 'rspec-rails' - gem 'rubocop' + gem 'rubocop', '1.62.1' + gem 'rubocop-capybara' + gem 'rubocop-rails' + gem 'rubocop-rake' + gem 'rubocop-rspec' gem 'selenium-webdriver' gem 'webdrivers' end diff --git a/gemfiles/rails_6_1.gemfile b/gemfiles/rails_6_1.gemfile index 23c7f21..412d942 100644 --- a/gemfiles/rails_6_1.gemfile +++ b/gemfiles/rails_6_1.gemfile @@ -8,7 +8,7 @@ gem 'grape-swagger' gem 'importmap-rails' gem 'jbuilder' gem 'pg', '~> 1.1' -gem 'puma', '~> 5.0' +gem 'puma', '~> 5.6' gem 'rails', '~> 6.1' gem 'sprockets-rails' gem 'stimulus-rails' @@ -28,7 +28,11 @@ group :test do gem 'capybara' gem 'rspec' gem 'rspec-rails' - gem 'rubocop' + gem 'rubocop', '1.62.1' + gem 'rubocop-capybara' + gem 'rubocop-rails' + gem 'rubocop-rake' + gem 'rubocop-rspec' gem 'selenium-webdriver' gem 'webdrivers' end diff --git a/gemfiles/rails_7.gemfile b/gemfiles/rails_7.gemfile index 782fd41..6c15878 100644 --- a/gemfiles/rails_7.gemfile +++ b/gemfiles/rails_7.gemfile @@ -8,7 +8,7 @@ gem 'grape-swagger' gem 'importmap-rails' gem 'jbuilder' gem 'pg', '~> 1.1' -gem 'puma', '~> 5.0' +gem 'puma', '~> 5.6' gem 'rails', '~> 7.0' gem 'sprockets-rails' gem 'stimulus-rails' @@ -28,7 +28,11 @@ group :test do gem 'capybara' gem 'rspec' gem 'rspec-rails' - gem 'rubocop' + gem 'rubocop', '1.62.1' + gem 'rubocop-capybara' + gem 'rubocop-rails' + gem 'rubocop-rake' + gem 'rubocop-rspec' gem 'selenium-webdriver' gem 'webdrivers' end diff --git a/gemfiles/rails_edge.gemfile b/gemfiles/rails_edge.gemfile index 68d7f32..8bb31df 100644 --- a/gemfiles/rails_edge.gemfile +++ b/gemfiles/rails_edge.gemfile @@ -8,7 +8,7 @@ gem 'grape-swagger' gem 'importmap-rails' gem 'jbuilder' gem 'pg', '~> 1.1' -gem 'puma', '~> 5.0' +gem 'puma', '~> 5.6' gem 'rails', git: 'https://github.com/rails/rails.git' gem 'sprockets-rails' gem 'stimulus-rails' @@ -28,7 +28,11 @@ group :test do gem 'capybara' gem 'rspec' gem 'rspec-rails' - gem 'rubocop' + gem 'rubocop', '1.62.1' + gem 'rubocop-capybara' + gem 'rubocop-rails' + gem 'rubocop-rake' + gem 'rubocop-rspec' gem 'selenium-webdriver' gem 'webdrivers' end diff --git a/spec/api/ping_spec.rb b/spec/api/ping_spec.rb index 1c9603c..055a480 100644 --- a/spec/api/ping_spec.rb +++ b/spec/api/ping_spec.rb @@ -5,6 +5,7 @@ get '/api/ping' expect(response.body).to eq({ ping: 'pong' }.to_json) end + it 'ping with a parameter' do get '/api/ping?pong=test' expect(response.body).to eq({ ping: 'test' }.to_json) diff --git a/spec/api/protected_spec.rb b/spec/api/protected_spec.rb index 8cb6a9d..c1135b8 100644 --- a/spec/api/protected_spec.rb +++ b/spec/api/protected_spec.rb @@ -8,6 +8,7 @@ expect(response.body).to eq '' end end + context 'with incorrect authorization' do it 'ping' do get '/api/protected/ping', @@ -19,6 +20,7 @@ expect(response.body).to eq '' end end + context 'with authorization' do it 'ping' do get '/api/protected/ping', diff --git a/spec/features/homepage_spec.rb b/spec/features/homepage_spec.rb index f242888..4583a70 100644 --- a/spec/features/homepage_spec.rb +++ b/spec/features/homepage_spec.rb @@ -1,9 +1,10 @@ require 'spec_helper' -describe 'Homepage', js: true, type: :feature do - before :each do +describe 'Homepage', :js, type: :feature do + before do visit '/' end + it 'displays index.html page' do expect(page.find('h1')).to have_content 'Grape' end diff --git a/spec/features/swagger_spec.rb b/spec/features/swagger_spec.rb index 7652aad..552df22 100644 --- a/spec/features/swagger_spec.rb +++ b/spec/features/swagger_spec.rb @@ -1,9 +1,10 @@ require 'spec_helper' -describe 'Swagger', js: true, type: :feature do - before :each do +describe 'Swagger', :js, type: :feature do + before do visit '/swagger' end + it 'displays Swagger page' do expect(page.find('.title')).to have_content 'grape-on-rails' end From a3b845e7badd1acd09b9ca0f9f6204e95085e065 Mon Sep 17 00:00:00 2001 From: "Daniel (dB.) Doubrovkine" Date: Tue, 19 Mar 2024 12:15:17 -0400 Subject: [PATCH 2/7] Upgraded puma to 6.4.2 in Rails 7. --- gemfiles/rails_7.gemfile | 2 +- gemfiles/rails_edge.gemfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gemfiles/rails_7.gemfile b/gemfiles/rails_7.gemfile index 6c15878..2e980a5 100644 --- a/gemfiles/rails_7.gemfile +++ b/gemfiles/rails_7.gemfile @@ -8,7 +8,7 @@ gem 'grape-swagger' gem 'importmap-rails' gem 'jbuilder' gem 'pg', '~> 1.1' -gem 'puma', '~> 5.6' +gem 'puma', '~> 6.4.2' gem 'rails', '~> 7.0' gem 'sprockets-rails' gem 'stimulus-rails' diff --git a/gemfiles/rails_edge.gemfile b/gemfiles/rails_edge.gemfile index 8bb31df..49440a0 100644 --- a/gemfiles/rails_edge.gemfile +++ b/gemfiles/rails_edge.gemfile @@ -8,7 +8,7 @@ gem 'grape-swagger' gem 'importmap-rails' gem 'jbuilder' gem 'pg', '~> 1.1' -gem 'puma', '~> 5.6' +gem 'puma', '~> 6.4.2' gem 'rails', git: 'https://github.com/rails/rails.git' gem 'sprockets-rails' gem 'stimulus-rails' From 09329ac5c5125376261ad84cdeda6bf92e9bda7f Mon Sep 17 00:00:00 2001 From: "Daniel (dB.) Doubrovkine" Date: Tue, 19 Mar 2024 12:20:33 -0400 Subject: [PATCH 3/7] Ruby 2.7 no longer works with latest Rails. --- .github/workflows/test.yml | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9707118..556fa2c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,22 +11,18 @@ jobs: strategy: fail-fast: false matrix: - ruby: - - "2.7" - - "3.0" - - "3.1" - - "3.2" gemfile: - - { file: rails_6, experimental: false } - - { file: rails_6_1, experimental: false } - - { file: rails_7, experimental: false } - - { file: rails_edge, experimental: true } + - { ruby: '2.7', file: rails_6, experimental: false } + - { ruby: '3.0', file: rails_6_1, experimental: false } + - { ruby: '3.1', file: rails_7, experimental: false } + - { ruby: '3.2', file: rails_7, experimental: false } + - { ruby: '3.2' ,file: rails_edge, experimental: true } steps: - uses: actions/checkout@v3 - name: Set up Ruby uses: ruby/setup-ruby@v1 with: - ruby-version: ${{ matrix.ruby }} + ruby-version: ${{ matrix.entry.ruby }} bundler-cache: true - name: Setup Firefox uses: browser-actions/setup-firefox@latest From 5809f7c71e01b0a259ac2aec3a04b5ff75e92781 Mon Sep 17 00:00:00 2001 From: "Daniel (dB.) Doubrovkine" Date: Tue, 19 Mar 2024 12:21:17 -0400 Subject: [PATCH 4/7] Newer versions of Rack do not return Version. --- spec/api/headers_spec.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/spec/api/headers_spec.rb b/spec/api/headers_spec.rb index 48a166e..ff860a7 100644 --- a/spec/api/headers_spec.rb +++ b/spec/api/headers_spec.rb @@ -3,11 +3,10 @@ describe Acme::Headers do it 'returns all headers' do get '/api/headers' - expect(JSON.parse(response.body)).to eq( + expect(JSON.parse(response.body)).to include( 'Accept' => 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5', 'Cookie' => '', - 'Host' => 'www.example.com', - 'Version' => 'HTTP/1.0' + 'Host' => 'www.example.com' ) end @@ -27,13 +26,12 @@ 'Something' => 1, 'SOMETHING_ELSE' => 1 } - expect(JSON.parse(response.body)).to eq( + expect(JSON.parse(response.body)).to include( 'Accept' => 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5', 'Cookie' => '', 'Host' => 'www.example.com', 'Reticulated-Spline' => 42, - 'Something' => 1, - 'Version' => 'HTTP/1.0' + 'Something' => 1 ) end end From 3950e81e8a892f09ab9e59a344547a0fac7ff7bd Mon Sep 17 00:00:00 2001 From: "Daniel (dB.) Doubrovkine" Date: Tue, 19 Mar 2024 12:31:31 -0400 Subject: [PATCH 5/7] Reorder routes, compatibility with Rails 7. --- config/routes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index 15642c1..0fe0ce6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,5 @@ Rails.application.routes.draw do get 'welcome/index' - mount API => '/' root 'welcome#index' + mount API => '/' end From 7d25baef958dbd6eae507f32066e008d1a3e4484 Mon Sep 17 00:00:00 2001 From: "Daniel (dB.) Doubrovkine" Date: Tue, 19 Mar 2024 12:34:38 -0400 Subject: [PATCH 6/7] Remove edge, noise. --- .github/workflows/test.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 556fa2c..22405df 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,16 +7,15 @@ jobs: RAILS_ENV: test DATABASE_URL: postgres://test:password@127.0.0.1:5432/grape_on_rails_test BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile.file }}.gemfile - continue-on-error: ${{ matrix.gemfile.experimental }} strategy: fail-fast: false matrix: gemfile: - - { ruby: '2.7', file: rails_6, experimental: false } - - { ruby: '3.0', file: rails_6_1, experimental: false } - - { ruby: '3.1', file: rails_7, experimental: false } - - { ruby: '3.2', file: rails_7, experimental: false } - - { ruby: '3.2' ,file: rails_edge, experimental: true } + - { ruby: '2.7', file: rails_6 } + - { ruby: '3.0', file: rails_6_1 } + - { ruby: '3.1', file: rails_7 } + - { ruby: '3.2', file: rails_7 } +# - { ruby: '3.2' ,file: rails_edge } steps: - uses: actions/checkout@v3 - name: Set up Ruby From a24c2c983cf1acc6482842953b6618f9c5ce502f Mon Sep 17 00:00:00 2001 From: "Daniel (dB.) Doubrovkine" Date: Tue, 19 Mar 2024 12:35:38 -0400 Subject: [PATCH 7/7] Added ruby 3.3. --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 22405df..2baaba9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,6 +15,7 @@ jobs: - { ruby: '3.0', file: rails_6_1 } - { ruby: '3.1', file: rails_7 } - { ruby: '3.2', file: rails_7 } + - { ruby: '3.3', file: rails_7 } # - { ruby: '3.2' ,file: rails_edge } steps: - uses: actions/checkout@v3