From 618449bdc5ac9437d6695028dcaa342d98b3f6d6 Mon Sep 17 00:00:00 2001 From: Uwe Kubosch Date: Sun, 9 Jun 2024 17:10:13 +0200 Subject: [PATCH] Add support for Rails 7.1 and Ruby 3.3 and 3.2 --- .rubocop_todo.yml | 33 +++++++++++++++++++++++++------ lib/simple_workflow/controller.rb | 2 +- lib/simple_workflow/middleware.rb | 10 +++++----- test/controller_test.rb | 2 +- test/helper_test.rb | 2 +- test/middleware_test.rb | 22 ++++++++------------- 6 files changed, 43 insertions(+), 28 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 51a4148..b1391b3 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,28 +1,43 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2021-01-01 16:18:50 UTC using RuboCop version 1.7.0. +# on 2024-06-09 15:07:15 UTC using RuboCop version 1.64.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: 4 +# Configuration parameters: EnforcedStyle, AllowedGems, Include. +# SupportedStyles: Gemfile, gems.rb, gemspec +# Include: **/*.gemspec, **/Gemfile, **/gems.rb +Gemspec/DevelopmentDependencies: + Exclude: + - 'simple_workflow.gemspec' + +# Offense count: 1 +# Configuration parameters: Severity, Include. +# Include: **/*.gemspec +Gemspec/RequiredRubyVersion: + Exclude: + - 'simple_workflow.gemspec' + # Offense count: 8 -# Configuration parameters: IgnoredMethods, CountRepeatedAttributes. +# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes. Metrics/AbcSize: Max: 41 # Offense count: 2 -# Configuration parameters: IgnoredMethods. +# Configuration parameters: AllowedMethods, AllowedPatterns. Metrics/CyclomaticComplexity: Max: 9 -# Offense count: 8 -# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods. +# Offense count: 7 +# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. Metrics/MethodLength: Max: 26 # Offense count: 2 -# Configuration parameters: IgnoredMethods. +# Configuration parameters: AllowedMethods, AllowedPatterns. Metrics/PerceivedComplexity: Max: 10 @@ -33,6 +48,12 @@ Performance/CollectionLiteralInLoop: - 'lib/simple_workflow/helper.rb' - 'lib/simple_workflow/middleware.rb' +# Offense count: 4 +# This cop supports unsafe autocorrection (--autocorrect-all). +Rails/ActiveSupportOnLoad: + Exclude: + - 'lib/simple_workflow/railtie.rb' + # Offense count: 1 # Configuration parameters: AllowedMethods. # AllowedMethods: respond_to_missing? diff --git a/lib/simple_workflow/controller.rb b/lib/simple_workflow/controller.rb index f3d5993..0b264bf 100644 --- a/lib/simple_workflow/controller.rb +++ b/lib/simple_workflow/controller.rb @@ -66,7 +66,7 @@ def save_flash(response_status_and_flash) def redirect_to_post(options) url = url_for options - render text: <<~HTML.strip_heredoc, layout: false + render text: <<~HTML, layout: false
diff --git a/lib/simple_workflow/middleware.rb b/lib/simple_workflow/middleware.rb index ece041f..47301a5 100644 --- a/lib/simple_workflow/middleware.rb +++ b/lib/simple_workflow/middleware.rb @@ -14,9 +14,9 @@ def initialize(app) def call(env) store_detour_from_params(env) - status, headers, response = @app.call(env) + status, headers, body = @app.call(env) remove_old_detours(env) - [status, headers, response] + [status, headers, body] end private @@ -60,12 +60,12 @@ def remove_old_detours(env) session[:detours].shift reset_workflow(session) if session[:detours].empty? end - Rails.logger.debug <<-MSG.strip_heredoc + Rails.logger.debug { <<~MSG } session: #{session_size} bytes, workflow(#{session[:detours].try(:size) || 0}): #{workflow_size} bytes MSG return unless session_size > 4096 - Rails.logger.warn <<-MSG.strip_heredoc + Rails.logger.warn <<~MSG simple_workflow: session exceeds cookie size limit: #{session_size} bytes. Workflow empty! Not My Fault! MSG Rails.logger.warn "simple_workflow: session: #{session.to_hash}" @@ -75,7 +75,7 @@ def remove_old_detours(env) def remove_discarded_flashes(session) return unless (old_flashes = session[:flash] && session[:flash]['discard']) - Rails.logger.warn <<-MSG.strip_heredoc + Rails.logger.warn <<~MSG simple_workflow: found discarded flash entries: #{old_flashes}. Deleting them. MSG session[:flash]['flashes'] = session[:flash]['flashes'].except(*old_flashes) diff --git a/test/controller_test.rb b/test/controller_test.rb index d0d3985..4cd13e3 100644 --- a/test/controller_test.rb +++ b/test/controller_test.rb @@ -3,7 +3,7 @@ require_relative 'test_helper' require 'rails' -class ControllerTest < MiniTest::Test +class ControllerTest < Minitest::Test include SimpleWorkflow::Controller attr_accessor :cookies, :logger, :session diff --git a/test/helper_test.rb b/test/helper_test.rb index d155e22..308bccd 100644 --- a/test/helper_test.rb +++ b/test/helper_test.rb @@ -4,7 +4,7 @@ require 'action_controller/metal/exceptions' require 'test_app' -class HelperTest < MiniTest::Test +class HelperTest < Minitest::Test include SimpleWorkflow::Helper def test_with_detour diff --git a/test/middleware_test.rb b/test/middleware_test.rb index c7c525c..eb1755b 100644 --- a/test/middleware_test.rb +++ b/test/middleware_test.rb @@ -4,7 +4,7 @@ require 'simple_workflow/middleware' require_relative 'test_app' -class MiddlewareTest < MiniTest::Test +class MiddlewareTest < Minitest::Test def setup @app = TestApp.instance # @app = ->(env) { [200, env, 'app response'] } @@ -23,8 +23,7 @@ def test_get_without_detour status, headers, response = @stack.call env assert_equal 200, status - assert_equal env, headers - assert_equal 'app response', response + assert_equal ['app response'], response assert_equal [], headers['rack.session'].to_hash.keys assert_nil headers['rack.session'].to_hash['detours'] end @@ -32,11 +31,10 @@ def test_get_without_detour def test_detour env = env_for('/?detour[controller]=test') - status, headers, response = @stack.call env + status, headers, body = @stack.call(env) assert_equal 200, status - assert_equal(env, headers) - assert_equal 'app response', response + assert_equal ['app response'], body assert_equal(%w[session_id detours], headers['rack.session'].to_hash.keys) assert_equal([{ 'controller' => 'test' }], headers['rack.session'].to_hash['detours']) end @@ -55,7 +53,7 @@ def test_detour_cleanup status, env, response = @stack.call last_env assert_equal 200, status - assert_equal 'app response', response + assert_equal ['app response'], response assert_equal(%w[session_id detours], env['rack.session'].to_hash.keys) assert_equal(((57..99).to_a + [:last]).map { |i| { 'controller' => "test_#{i}" } }, @@ -71,8 +69,7 @@ def test_huge_detour_over_4k status, headers, response = @stack.call env assert_equal 200, status - assert_equal(env, headers) - assert_equal 'app response', response + assert_equal ['app response'], response assert_equal(%w[session_id], headers['rack.session'].to_hash.keys) end @@ -84,8 +81,8 @@ def test_return_from_detour status, headers, response = @stack.call env assert_equal 200, status - assert_equal env, headers - assert_equal 'app response', response + assert_match(%r{_session_id=\w+--\w+; path=/; httponly}, headers['set-cookie']) + assert_equal ['app response'], response assert_equal ['session_id'], headers['rack.session'].to_hash.keys assert_nil headers['rack.session'].to_hash['detours'] end @@ -101,9 +98,6 @@ def env_for(url, opts = {}) ActionDispatch::Cookies::GENERATOR_KEY => ActiveSupport::KeyGenerator.new('secret'), ActionDispatch::Cookies::SECRET_KEY_BASE => 'secret', } - if /^5\.2\./.match?(Rails.version) - default_opts[ActionDispatch::Cookies::COOKIES_ROTATIONS] = Struct.new(:encrypted).new([]) - end Rack::MockRequest.env_for(url, default_opts.update(opts)) end end