simple_workflow 1.3.2 → 1.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/lib/simple_workflow.rb +5 -1
- data/lib/simple_workflow/controller.rb +3 -1
- data/lib/simple_workflow/detour.rb +3 -1
- data/lib/simple_workflow/helper.rb +11 -6
- data/lib/simple_workflow/middleware.rb +17 -6
- data/lib/simple_workflow/railtie.rb +2 -2
- data/lib/simple_workflow/test_helper.rb +1 -0
- data/lib/simple_workflow/version.rb +1 -1
- data/test/middleware_test.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e1e29715cba13f98137c9b007e1adfe1a19cebfa
|
4
|
+
data.tar.gz: 03c8dd09e5f4de89fdb82d8a5e8e0ef3b5e57c5c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0c307cd9aa2798cf1e623546e7713d4b7ac3decc285a9948884ef0b7216ad72f77226e48edb95874e84e2cedeae26f1f1f7ff23b2c74d3e7e2e26e3f67c44c3
|
7
|
+
data.tar.gz: 45f5b80db062ec965d57703ea28eb544fecdbd234b083a4bdc2e9071818351421514952a1285fd4d92bf6b24f7bc8c231640d5507a953d066b290ca56205c4a9
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
data/lib/simple_workflow.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
unless $LOAD_PATH.include?(File.dirname(__FILE__)) ||
|
1
|
+
unless $LOAD_PATH.include?(File.dirname(__FILE__)) ||
|
2
|
+
$LOAD_PATH.include?(File.expand_path(File.dirname(__FILE__)))
|
2
3
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
4
|
end
|
4
5
|
|
@@ -11,15 +12,18 @@ require 'simple_workflow/test_helper'
|
|
11
12
|
require 'simple_workflow/middleware'
|
12
13
|
require 'simple_workflow/railtie'
|
13
14
|
|
15
|
+
# Make workflow test utility methods available in views
|
14
16
|
module ApplicationHelper
|
15
17
|
include SimpleWorkflow::Helper
|
16
18
|
end
|
17
19
|
|
20
|
+
# Make workflow test utility methods available in controllers
|
18
21
|
class ActionController::Base
|
19
22
|
include SimpleWorkflow::Helper
|
20
23
|
include SimpleWorkflow::Controller
|
21
24
|
end
|
22
25
|
|
26
|
+
# Make workflow test utility methods available in ActiveSupport test cases
|
23
27
|
class ActiveSupport::TestCase
|
24
28
|
include SimpleWorkflow::TestHelper
|
25
29
|
end
|
@@ -1,9 +1,11 @@
|
|
1
1
|
require 'simple_workflow/detour'
|
2
2
|
|
3
|
+
# Mixin to add controller methods for workflow navigation.
|
3
4
|
module SimpleWorkflow::Controller
|
4
5
|
include SimpleWorkflow::Detour
|
5
6
|
|
6
|
-
# Like ActionController::Base#redirect_to, but stores the location we come from, enabling
|
7
|
+
# Like ActionController::Base#redirect_to, but stores the location we come from, enabling
|
8
|
+
# returning here later.
|
7
9
|
def detour_to(options)
|
8
10
|
store_detour(params)
|
9
11
|
redirect_to(options)
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# Utility methods to manage the breadcrumb history
|
1
2
|
module SimpleWorkflow::Detour
|
2
3
|
def store_detour_in_session(session, options)
|
3
4
|
if session[:detours] && session[:detours].last == options
|
@@ -6,7 +7,8 @@ module SimpleWorkflow::Detour
|
|
6
7
|
end
|
7
8
|
session[:detours] ||= []
|
8
9
|
session[:detours] << options
|
9
|
-
Rails.logger
|
10
|
+
Rails.logger
|
11
|
+
.try(:debug, "Added detour (#{session[:detours].try(:size) || 0}): #{options.inspect}")
|
10
12
|
end
|
11
13
|
|
12
14
|
def pop_detour(session)
|
@@ -1,11 +1,15 @@
|
|
1
1
|
require_relative 'detour'
|
2
|
+
|
3
|
+
# View helper methods augmented with breadcrumb management.
|
2
4
|
module SimpleWorkflow::Helper
|
3
5
|
include SimpleWorkflow::Detour
|
4
6
|
|
5
7
|
def image_button_to(image_source, title, options, html_options = {})
|
6
|
-
image_submit_tag image_source, {
|
7
|
-
|
8
|
-
|
8
|
+
image_submit_tag image_source, {
|
9
|
+
class: 'image-submit', alt: title, title: title,
|
10
|
+
id: "#{title}_#{options[:id]}", name: title,
|
11
|
+
onclick: "form.action='#{url_for(options)}'"
|
12
|
+
}.update(html_options)
|
9
13
|
end
|
10
14
|
|
11
15
|
def detour_to(title, options = nil, html_options = nil, &block)
|
@@ -36,7 +40,7 @@ module SimpleWorkflow::Helper
|
|
36
40
|
end
|
37
41
|
|
38
42
|
def origin_options
|
39
|
-
params.reject { |k, _v| %i
|
43
|
+
params.reject { |k, _v| %i[detour return_from_detour].include? k.to_sym }
|
40
44
|
end
|
41
45
|
|
42
46
|
def image_detour_to(image_source, title, url_options, image_options = nil, link_options = nil)
|
@@ -56,7 +60,8 @@ module SimpleWorkflow::Helper
|
|
56
60
|
link_to image_tag(image_source, image_options), url_options, link_options
|
57
61
|
end
|
58
62
|
|
59
|
-
def image_link_to_remote(image_source, title, link_options, image_options = nil,
|
63
|
+
def image_link_to_remote(image_source, title, link_options, image_options = nil,
|
64
|
+
html_options = {})
|
60
65
|
if html_options == true
|
61
66
|
html_options = { method: :post }
|
62
67
|
elsif html_options == false
|
@@ -84,7 +89,7 @@ module SimpleWorkflow::Helper
|
|
84
89
|
link_options = options
|
85
90
|
end
|
86
91
|
|
87
|
-
link_to(title, link_options, html_options) if
|
92
|
+
link_to(title, link_options, html_options) if link_options
|
88
93
|
rescue ActionController::UrlGenerationError => e
|
89
94
|
if session[:detours]
|
90
95
|
logger.error "Exception linking to origin: #{e.class} #{e}"
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'simple_workflow/detour'
|
2
2
|
|
3
|
+
# Rack middleware to detect and store detours and manage returns from detours.
|
3
4
|
class SimpleWorkflow::Middleware
|
4
5
|
include SimpleWorkflow::Detour
|
5
6
|
|
@@ -38,7 +39,8 @@ class SimpleWorkflow::Middleware
|
|
38
39
|
end
|
39
40
|
|
40
41
|
def remove_old_detours(env)
|
41
|
-
return unless session(env).instance_variable_get('@by')
|
42
|
+
return unless session(env).instance_variable_get('@by')
|
43
|
+
.is_a?(ActionDispatch::Session::CookieStore)
|
42
44
|
session_size = workflow_size = nil
|
43
45
|
session = session(env)
|
44
46
|
# env[ActionDispatch::Cookies::COOKIES_SERIALIZER]
|
@@ -49,17 +51,26 @@ class SimpleWorkflow::Middleware
|
|
49
51
|
session_size = encryptor.encrypt_and_sign(ser_val).size
|
50
52
|
wf_ser_val = serialize_session(cookie_jar, session[:detours])
|
51
53
|
workflow_size = encryptor.encrypt_and_sign(wf_ser_val).size
|
52
|
-
break unless workflow_size >= 2048 ||
|
53
|
-
|
54
|
+
break unless workflow_size >= 2048 ||
|
55
|
+
(session_size >= 3072 && session[:detours] && !session[:detours].empty?)
|
56
|
+
Rails.logger.warn(
|
57
|
+
"Workflow too large (#{workflow_size}/#{session_size}). Dropping oldest detour."
|
58
|
+
)
|
54
59
|
session[:detours].shift
|
55
60
|
reset_workflow(session) if session[:detours].empty?
|
56
61
|
end
|
57
|
-
Rails.logger.debug
|
62
|
+
Rails.logger.debug <<-MSG.strip_heredoc
|
63
|
+
session: #{session_size} bytes, workflow(#{session[:detours].try(:size) || 0}): #{workflow_size} bytes
|
64
|
+
MSG
|
58
65
|
return unless session_size > 4096
|
59
|
-
Rails.logger.warn
|
66
|
+
Rails.logger.warn <<-MSG.strip_heredoc
|
67
|
+
simple_workflow: session exceeds cookie size limit: #{session_size} bytes. Workflow empty! Not My Fault!
|
68
|
+
MSG
|
60
69
|
Rails.logger.warn "simple_workflow: session: #{session.to_hash}"
|
61
70
|
return unless (old_flashes = session[:flash] && session[:flash]['discard'])
|
62
|
-
Rails.logger.warn
|
71
|
+
Rails.logger.warn <<-MSG.strip_heredoc
|
72
|
+
simple_workflow: found discarded flash entries: #{old_flashes}. Deleting them.
|
73
|
+
MSG
|
63
74
|
session[:flash]['flashes'] = session[:flash]['flashes'].except(*old_flashes)
|
64
75
|
Rails.logger.warn "simple_workflow: session: #{session.to_hash}"
|
65
76
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module SimpleWorkflow
|
2
|
+
# Railtie to activate the middleware.
|
2
3
|
class Railtie < Rails::Railtie
|
3
4
|
initializer 'SimpleWorkflow.configure_rails_initialization' do |app|
|
4
|
-
app.middleware.insert_before ActionDispatch::Flash,
|
5
|
-
SimpleWorkflow::Middleware
|
5
|
+
app.middleware.insert_before ActionDispatch::Flash, SimpleWorkflow::Middleware
|
6
6
|
end
|
7
7
|
end
|
8
8
|
end
|
data/test/middleware_test.rb
CHANGED
@@ -35,7 +35,7 @@ class MiddlewareTest < MiniTest::Test
|
|
35
35
|
assert_equal 200, status
|
36
36
|
assert_equal(env, headers)
|
37
37
|
assert_equal 'app response', response
|
38
|
-
assert_equal(%w
|
38
|
+
assert_equal(%w[session_id detours], headers['rack.session'].to_hash.keys)
|
39
39
|
assert_equal([{ 'controller' => 'test' }], headers['rack.session'].to_hash['detours'])
|
40
40
|
end
|
41
41
|
|
@@ -52,7 +52,7 @@ class MiddlewareTest < MiniTest::Test
|
|
52
52
|
|
53
53
|
assert_equal 200, status
|
54
54
|
assert_equal 'app response', response
|
55
|
-
assert_equal(%w
|
55
|
+
assert_equal(%w[session_id detours], env['rack.session'].to_hash.keys)
|
56
56
|
|
57
57
|
assert_equal(((57..99).to_a + [:last]).map { |i| { 'controller' => "test_#{i}" } },
|
58
58
|
env['rack.session'].to_hash['detours'])
|
@@ -69,7 +69,7 @@ class MiddlewareTest < MiniTest::Test
|
|
69
69
|
assert_equal 200, status
|
70
70
|
assert_equal(env, headers)
|
71
71
|
assert_equal 'app response', response
|
72
|
-
assert_equal(%w
|
72
|
+
assert_equal(%w[session_id], headers['rack.session'].to_hash.keys)
|
73
73
|
end
|
74
74
|
|
75
75
|
def test_return_from_detour
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_workflow
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Uwe Kubosch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|