Skip to content

Commit

Permalink
Add support for Rails 7.1 and Ruby 3.3 and 3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
UweKubosch committed Jun 9, 2024
1 parent 4857ba1 commit 618449b
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 28 deletions.
33 changes: 27 additions & 6 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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?
Expand Down
2 changes: 1 addition & 1 deletion lib/simple_workflow/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
<html>
<body onload="document.getElementById('form').submit()">
<form id="form" action="#{url}" method="POST">
Expand Down
10 changes: 5 additions & 5 deletions lib/simple_workflow/middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}"
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion test/controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion test/helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 8 additions & 14 deletions test/middleware_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'] }
Expand All @@ -23,20 +23,18 @@ 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

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
Expand All @@ -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}" } },
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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

0 comments on commit 618449b

Please sign in to comment.