simple_workflow 1.5.1 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: d01e8c654f626222800e875ae04d34978579fb8a
4
- data.tar.gz: 96c3e66d0b7be9802411f4bac379c51c54c245ea
2
+ SHA256:
3
+ metadata.gz: 292e69a11faa0584c25618ffaa2bc2c2391e1b42d6e6e0503797fc3c94f6c2af
4
+ data.tar.gz: 2b57742db3c66f8b9b2edc088dcd8cabf848759556914abc4c3a329543a3e508
5
5
  SHA512:
6
- metadata.gz: 9a09260158fcd698e35acb0494e1dcbb277601c573605a705f4738cc4b5d36209b8629a16cf9f864e476829b4c9bf54621987df235d6248f2053dcc5ad969a3f
7
- data.tar.gz: 3b951b26526a34eb5929db7963268e5c40145477a6f776618ba310865ce4843e39f2eb065f79dcb45e4d6ee0fdb33be9f486ed344bdb4adfa7501e3f98c8f3e0
6
+ metadata.gz: 3c92b45c2959972fd8bb2d63c14357a10feadd9717268b233fed9bfad6d976c15f187ff3fb55e2737178240ac19ae462fcc96ddfc38db3588b737d3f7bf390e9
7
+ data.tar.gz: '0954579fb5d60a2be355f71f3cb32bb946eefbcfcf82705958008e1427da344b72a9c6b23c9d49749a323c6c830e2b2ba44d29011a6fa72170d869a1577fbf7b'
data/Gemfile CHANGED
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org/'
2
4
  gemspec
@@ -1,148 +1,186 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- simple_workflow (1.5.1)
5
- rails (>= 4, < 5.2)
4
+ simple_workflow (2.0.1)
5
+ rails (>= 4.2, < 6.1)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- actioncable (5.1.2)
11
- actionpack (= 5.1.2)
10
+ actioncable (6.0.3.4)
11
+ actionpack (= 6.0.3.4)
12
12
  nio4r (~> 2.0)
13
- websocket-driver (~> 0.6.1)
14
- actionmailer (5.1.2)
15
- actionpack (= 5.1.2)
16
- actionview (= 5.1.2)
17
- activejob (= 5.1.2)
13
+ websocket-driver (>= 0.6.1)
14
+ actionmailbox (6.0.3.4)
15
+ actionpack (= 6.0.3.4)
16
+ activejob (= 6.0.3.4)
17
+ activerecord (= 6.0.3.4)
18
+ activestorage (= 6.0.3.4)
19
+ activesupport (= 6.0.3.4)
20
+ mail (>= 2.7.1)
21
+ actionmailer (6.0.3.4)
22
+ actionpack (= 6.0.3.4)
23
+ actionview (= 6.0.3.4)
24
+ activejob (= 6.0.3.4)
18
25
  mail (~> 2.5, >= 2.5.4)
19
26
  rails-dom-testing (~> 2.0)
20
- actionpack (5.1.2)
21
- actionview (= 5.1.2)
22
- activesupport (= 5.1.2)
23
- rack (~> 2.0)
24
- rack-test (~> 0.6.3)
27
+ actionpack (6.0.3.4)
28
+ actionview (= 6.0.3.4)
29
+ activesupport (= 6.0.3.4)
30
+ rack (~> 2.0, >= 2.0.8)
31
+ rack-test (>= 0.6.3)
25
32
  rails-dom-testing (~> 2.0)
26
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
27
- actionview (5.1.2)
28
- activesupport (= 5.1.2)
33
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
34
+ actiontext (6.0.3.4)
35
+ actionpack (= 6.0.3.4)
36
+ activerecord (= 6.0.3.4)
37
+ activestorage (= 6.0.3.4)
38
+ activesupport (= 6.0.3.4)
39
+ nokogiri (>= 1.8.5)
40
+ actionview (6.0.3.4)
41
+ activesupport (= 6.0.3.4)
29
42
  builder (~> 3.1)
30
43
  erubi (~> 1.4)
31
44
  rails-dom-testing (~> 2.0)
32
- rails-html-sanitizer (~> 1.0, >= 1.0.3)
33
- activejob (5.1.2)
34
- activesupport (= 5.1.2)
45
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
46
+ activejob (6.0.3.4)
47
+ activesupport (= 6.0.3.4)
35
48
  globalid (>= 0.3.6)
36
- activemodel (5.1.2)
37
- activesupport (= 5.1.2)
38
- activerecord (5.1.2)
39
- activemodel (= 5.1.2)
40
- activesupport (= 5.1.2)
41
- arel (~> 8.0)
42
- activesupport (5.1.2)
49
+ activemodel (6.0.3.4)
50
+ activesupport (= 6.0.3.4)
51
+ activerecord (6.0.3.4)
52
+ activemodel (= 6.0.3.4)
53
+ activesupport (= 6.0.3.4)
54
+ activestorage (6.0.3.4)
55
+ actionpack (= 6.0.3.4)
56
+ activejob (= 6.0.3.4)
57
+ activerecord (= 6.0.3.4)
58
+ marcel (~> 0.3.1)
59
+ activesupport (6.0.3.4)
43
60
  concurrent-ruby (~> 1.0, >= 1.0.2)
44
- i18n (~> 0.7)
61
+ i18n (>= 0.7, < 2)
45
62
  minitest (~> 5.1)
46
63
  tzinfo (~> 1.1)
64
+ zeitwerk (~> 2.2, >= 2.2.2)
47
65
  ansi (1.5.0)
48
- arel (8.0.0)
49
- ast (2.3.0)
50
- builder (3.2.3)
51
- concurrent-ruby (1.0.5)
52
- docile (1.1.5)
53
- erubi (1.6.1)
54
- globalid (0.4.0)
66
+ ast (2.4.1)
67
+ builder (3.2.4)
68
+ concurrent-ruby (1.1.7)
69
+ crass (1.0.6)
70
+ docile (1.3.4)
71
+ erubi (1.10.0)
72
+ globalid (0.4.2)
55
73
  activesupport (>= 4.2.0)
56
- i18n (0.8.6)
57
- json (2.1.0)
58
- loofah (2.0.3)
74
+ i18n (1.8.5)
75
+ concurrent-ruby (~> 1.0)
76
+ loofah (2.8.0)
77
+ crass (~> 1.0.2)
59
78
  nokogiri (>= 1.5.9)
60
- mail (2.6.6)
61
- mime-types (>= 1.16, < 4)
62
- method_source (0.8.2)
63
- mime-types (3.1)
64
- mime-types-data (~> 3.2015)
65
- mime-types-data (3.2016.0521)
66
- mini_portile2 (2.2.0)
67
- minitest (5.10.2)
68
- minitest-reporters (1.1.14)
79
+ mail (2.7.1)
80
+ mini_mime (>= 0.1.1)
81
+ marcel (0.3.3)
82
+ mimemagic (~> 0.3.2)
83
+ method_source (1.0.0)
84
+ mimemagic (0.3.5)
85
+ mini_mime (1.0.2)
86
+ mini_portile2 (2.4.0)
87
+ minitest (5.14.2)
88
+ minitest-reporters (1.4.2)
69
89
  ansi
70
90
  builder
71
91
  minitest (>= 5.0)
72
92
  ruby-progressbar
73
- nio4r (2.1.0)
74
- nokogiri (1.8.0)
75
- mini_portile2 (~> 2.2.0)
76
- parallel (1.11.2)
77
- parser (2.4.0.0)
78
- ast (~> 2.2)
79
- powerpack (0.1.1)
80
- rack (2.0.3)
81
- rack-test (0.6.3)
82
- rack (>= 1.0)
83
- rails (5.1.2)
84
- actioncable (= 5.1.2)
85
- actionmailer (= 5.1.2)
86
- actionpack (= 5.1.2)
87
- actionview (= 5.1.2)
88
- activejob (= 5.1.2)
89
- activemodel (= 5.1.2)
90
- activerecord (= 5.1.2)
91
- activesupport (= 5.1.2)
92
- bundler (>= 1.3.0, < 2.0)
93
- railties (= 5.1.2)
93
+ nio4r (2.5.4)
94
+ nokogiri (1.10.10)
95
+ mini_portile2 (~> 2.4.0)
96
+ parallel (1.20.1)
97
+ parser (3.0.0.0)
98
+ ast (~> 2.4.1)
99
+ rack (2.2.3)
100
+ rack-test (1.1.0)
101
+ rack (>= 1.0, < 3)
102
+ rails (6.0.3.4)
103
+ actioncable (= 6.0.3.4)
104
+ actionmailbox (= 6.0.3.4)
105
+ actionmailer (= 6.0.3.4)
106
+ actionpack (= 6.0.3.4)
107
+ actiontext (= 6.0.3.4)
108
+ actionview (= 6.0.3.4)
109
+ activejob (= 6.0.3.4)
110
+ activemodel (= 6.0.3.4)
111
+ activerecord (= 6.0.3.4)
112
+ activestorage (= 6.0.3.4)
113
+ activesupport (= 6.0.3.4)
114
+ bundler (>= 1.3.0)
115
+ railties (= 6.0.3.4)
94
116
  sprockets-rails (>= 2.0.0)
95
117
  rails-dom-testing (2.0.3)
96
118
  activesupport (>= 4.2.0)
97
119
  nokogiri (>= 1.6)
98
- rails-html-sanitizer (1.0.3)
99
- loofah (~> 2.0)
100
- railties (5.1.2)
101
- actionpack (= 5.1.2)
102
- activesupport (= 5.1.2)
120
+ rails-html-sanitizer (1.3.0)
121
+ loofah (~> 2.3)
122
+ railties (6.0.3.4)
123
+ actionpack (= 6.0.3.4)
124
+ activesupport (= 6.0.3.4)
103
125
  method_source
104
126
  rake (>= 0.8.7)
105
- thor (>= 0.18.1, < 2.0)
106
- rainbow (2.2.2)
107
- rake
108
- rake (12.0.0)
109
- rubocop (0.49.1)
127
+ thor (>= 0.20.3, < 2.0)
128
+ rainbow (3.0.0)
129
+ rake (13.0.3)
130
+ regexp_parser (2.0.3)
131
+ rexml (3.2.4)
132
+ rubocop (1.7.0)
110
133
  parallel (~> 1.10)
111
- parser (>= 2.3.3.1, < 3.0)
112
- powerpack (~> 0.1)
113
- rainbow (>= 1.99.1, < 3.0)
134
+ parser (>= 2.7.1.5)
135
+ rainbow (>= 2.2.2, < 4.0)
136
+ regexp_parser (>= 1.8, < 3.0)
137
+ rexml
138
+ rubocop-ast (>= 1.2.0, < 2.0)
114
139
  ruby-progressbar (~> 1.7)
115
- unicode-display_width (~> 1.0, >= 1.0.1)
116
- ruby-progressbar (1.8.1)
117
- simplecov (0.14.1)
118
- docile (~> 1.1.0)
119
- json (>= 1.8, < 3)
120
- simplecov-html (~> 0.10.0)
121
- simplecov-html (0.10.1)
122
- sprockets (3.7.1)
140
+ unicode-display_width (>= 1.4.0, < 2.0)
141
+ rubocop-ast (1.3.0)
142
+ parser (>= 2.7.1.5)
143
+ rubocop-performance (1.9.2)
144
+ rubocop (>= 0.90.0, < 2.0)
145
+ rubocop-ast (>= 0.4.0)
146
+ rubocop-rails (2.9.1)
147
+ activesupport (>= 4.2.0)
148
+ rack (>= 1.1)
149
+ rubocop (>= 0.90.0, < 2.0)
150
+ ruby-progressbar (1.11.0)
151
+ simplecov (0.20.0)
152
+ docile (~> 1.1)
153
+ simplecov-html (~> 0.11)
154
+ simplecov_json_formatter (~> 0.1)
155
+ simplecov-html (0.12.3)
156
+ simplecov_json_formatter (0.1.2)
157
+ sprockets (4.0.2)
123
158
  concurrent-ruby (~> 1.0)
124
159
  rack (> 1, < 3)
125
- sprockets-rails (3.2.0)
160
+ sprockets-rails (3.2.2)
126
161
  actionpack (>= 4.0)
127
162
  activesupport (>= 4.0)
128
163
  sprockets (>= 3.0.0)
129
- thor (0.19.4)
164
+ thor (1.0.1)
130
165
  thread_safe (0.3.6)
131
- tzinfo (1.2.3)
166
+ tzinfo (1.2.9)
132
167
  thread_safe (~> 0.1)
133
- unicode-display_width (1.3.0)
134
- websocket-driver (0.6.5)
168
+ unicode-display_width (1.7.0)
169
+ websocket-driver (0.7.3)
135
170
  websocket-extensions (>= 0.1.0)
136
- websocket-extensions (0.1.2)
171
+ websocket-extensions (0.1.5)
172
+ zeitwerk (2.4.2)
137
173
 
138
174
  PLATFORMS
139
- ruby
175
+ x86_64-darwin-19
140
176
 
141
177
  DEPENDENCIES
142
178
  minitest-reporters (~> 1.0)
143
- rubocop (~> 0.45)
179
+ rubocop (~> 1.0)
180
+ rubocop-performance (~> 1.5)
181
+ rubocop-rails (~> 2.4)
144
182
  simple_workflow!
145
183
  simplecov (~> 0.9)
146
184
 
147
185
  BUNDLED WITH
148
- 1.15.3
186
+ 2.2.3
data/Rakefile CHANGED
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rake'
2
4
  require 'rake/clean'
3
5
  require 'rake/testtask'
4
- require File.dirname(__FILE__) + '/lib/simple_workflow/version'
6
+ require "#{File.dirname(__FILE__)}/lib/simple_workflow/version"
5
7
 
6
- GEM_FILE = "simple_workflow-#{SimpleWorkflow::VERSION}.gem".freeze
7
- GEM_SPEC_FILE = 'simple_workflow.gemspec'.freeze
8
+ GEM_FILE = "simple_workflow-#{SimpleWorkflow::VERSION}.gem"
9
+ GEM_SPEC_FILE = 'simple_workflow.gemspec'
8
10
 
9
11
  CLEAN.include('simple_workflow-*.gem', 'tmp')
10
12
 
@@ -22,6 +24,7 @@ desc 'Push the gem to RubyGems'
22
24
  task release: :gem do
23
25
  output = `git status --porcelain`
24
26
  raise "Workspace not clean!\n#{output}" unless output.empty?
27
+
25
28
  sh "git tag #{SimpleWorkflow::VERSION}"
26
29
  sh 'git push --tags'
27
30
  sh "gem push #{GEM_FILE}"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  unless $LOAD_PATH.include?(__dir__) || $LOAD_PATH.include?(File.expand_path(__dir__))
2
4
  $LOAD_PATH.unshift(__dir__)
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'simple_workflow/detour'
2
4
 
3
5
  # Mixin to add controller methods for workflow navigation.
@@ -29,6 +31,7 @@ module SimpleWorkflow::Controller
29
31
 
30
32
  def back(response_status_and_flash)
31
33
  return false if session[:detours].nil?
34
+
32
35
  detour = pop_detour(session)
33
36
  post = detour.delete(:request_method) == :post
34
37
  if post
@@ -38,7 +41,7 @@ module SimpleWorkflow::Controller
38
41
  redirect_to detour, response_status_and_flash
39
42
  end
40
43
  true
41
- rescue
44
+ rescue StandardError
42
45
  retry
43
46
  end
44
47
 
@@ -56,19 +59,20 @@ module SimpleWorkflow::Controller
56
59
  end
57
60
 
58
61
  return unless (other_flashes = response_status_and_flash.delete(:flash))
62
+
59
63
  flash.update(other_flashes)
60
64
  end
61
65
  private :save_flash
62
66
 
63
67
  def redirect_to_post(options)
64
68
  url = url_for options
65
- render text: <<EOF.strip_heredoc, layout: false
69
+ render text: <<~HTML.strip_heredoc, layout: false
66
70
  <html>
67
71
  <body onload="document.getElementById('form').submit()">
68
72
  <form id="form" action="#{url}" method="POST">
69
73
  </form>
70
74
  </body>
71
75
  </html>
72
- EOF
76
+ HTML
73
77
  end
74
78
  end
@@ -1,20 +1,28 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Utility methods to manage the breadcrumb history
2
4
  module SimpleWorkflow::Detour
3
5
  def store_detour_in_session(session, options)
4
- if session[:detours] && session[:detours].last == options
5
- Rails.logger.try(:debug, "Ignored duplicate detour: #{options.inspect}")
6
- return
6
+ if session[:detours]
7
+ if session[:detours].last == options
8
+ Rails.logger.try(:debug, "Ignored duplicate detour: #{options.inspect}")
9
+ return
10
+ end
11
+ if session[:detours].delete(options)
12
+ Rails.logger.try(:debug, "Deleted duplicate detour: #{options.inspect}")
13
+ end
14
+ else
15
+ session[:detours] = []
7
16
  end
8
- session[:detours] ||= []
9
17
  session[:detours] << options
10
- Rails.logger
11
- .try(:debug, "Added detour (#{session[:detours].try(:size) || 0}): #{options.inspect}")
18
+ Rails.logger.try(:debug, "Added detour (#{session[:detours].try(:size) || 0}): #{options.inspect}")
12
19
  end
13
20
 
14
- def pop_detour(session)
21
+ def pop_detour(session, origin_options = nil)
15
22
  detours = session[:detours]
16
23
  return nil unless detours
17
- detour = detours.pop
24
+
25
+ detour = detours.delete(origin_options) || detours.pop
18
26
  Rails.logger.debug "popped detour: #{detour.inspect} #{session[:detours].size} more"
19
27
  reset_workflow(session) if detours.empty?
20
28
  detour
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'detour'
2
4
 
3
5
  # View helper methods augmented with breadcrumb management.
@@ -42,7 +44,7 @@ module SimpleWorkflow::Helper
42
44
  end
43
45
  origin.update(origin_options) if origin.keys == [:anchor]
44
46
  url = url_for(options)
45
- url + (url =~ /\?/ ? '&' : '?') + origin.to_h.to_param('detour')
47
+ url + (/\?/.match?(url) ? '&' : '?') + origin.to_h.to_param('detour')
46
48
  end
47
49
 
48
50
  def origin_options
@@ -56,9 +58,10 @@ module SimpleWorkflow::Helper
56
58
  end
57
59
 
58
60
  def image_link_to(image_source, title, url_options, image_options = nil, link_options = nil)
59
- if link_options == true
61
+ case link_options
62
+ when true
60
63
  link_options = { method: :post }
61
- elsif link_options == false
64
+ when false
62
65
  link_options = nil
63
66
  end
64
67
  image_options ||= { class: 'image-submit' }
@@ -68,9 +71,10 @@ module SimpleWorkflow::Helper
68
71
 
69
72
  def image_link_to_remote(image_source, title, link_options, image_options = nil,
70
73
  html_options = {})
71
- if html_options == true
74
+ case html_options
75
+ when true
72
76
  html_options = { method: :post }
73
- elsif html_options == false
77
+ when false
74
78
  html_options = {}
75
79
  end
76
80
  image_options ||= { class: 'image-submit' }
@@ -82,7 +86,12 @@ module SimpleWorkflow::Helper
82
86
  !session[:detours].nil?
83
87
  end
84
88
 
85
- def back_or_link_to(title, options = nil, html_options = nil)
89
+ def back_or_link_to(title, options = nil, html_options = nil, &block)
90
+ if block
91
+ html_options = options
92
+ options = title
93
+ title = nil
94
+ end
86
95
  if session[:detours]
87
96
  link_options = { return_from_detour: true }.update(session[:detours].last)
88
97
 
@@ -95,7 +104,13 @@ module SimpleWorkflow::Helper
95
104
  link_options = options
96
105
  end
97
106
 
98
- link_to(title, link_options, html_options) if link_options
107
+ if link_options
108
+ if block
109
+ link_to(link_options, html_options, &block)
110
+ else
111
+ link_to(title, link_options, html_options)
112
+ end
113
+ end
99
114
  rescue ActionController::UrlGenerationError => e
100
115
  if session[:detours]
101
116
  logger.error "Exception linking to origin: #{e.class} #{e}"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'simple_workflow/detour'
2
4
  require 'active_support/core_ext/string/strip'
3
5
 
@@ -40,8 +42,8 @@ class SimpleWorkflow::Middleware
40
42
  end
41
43
 
42
44
  def remove_old_detours(env)
43
- return unless session(env).instance_variable_get('@by')
44
- .is_a?(ActionDispatch::Session::CookieStore)
45
+ return unless session(env).instance_variable_get('@by').is_a?(ActionDispatch::Session::CookieStore)
46
+
45
47
  session_size = workflow_size = nil
46
48
  session = session(env)
47
49
  cookie_jar = cookie_jar(env)
@@ -52,10 +54,9 @@ class SimpleWorkflow::Middleware
52
54
  wf_ser_val = serialize_session(cookie_jar, session[:detours])
53
55
  workflow_size = encryptor.encrypt_and_sign(wf_ser_val).size
54
56
  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
- )
57
+ (session_size >= 3072 && session[:detours] && !session[:detours].empty?)
58
+
59
+ Rails.logger.warn("Workflow too large (#{workflow_size}/#{session_size}). Dropping oldest detour.")
59
60
  session[:detours].shift
60
61
  reset_workflow(session) if session[:detours].empty?
61
62
  end
@@ -63,6 +64,7 @@ class SimpleWorkflow::Middleware
63
64
  session: #{session_size} bytes, workflow(#{session[:detours].try(:size) || 0}): #{workflow_size} bytes
64
65
  MSG
65
66
  return unless session_size > 4096
67
+
66
68
  Rails.logger.warn <<-MSG.strip_heredoc
67
69
  simple_workflow: session exceeds cookie size limit: #{session_size} bytes. Workflow empty! Not My Fault!
68
70
  MSG
@@ -72,6 +74,7 @@ class SimpleWorkflow::Middleware
72
74
 
73
75
  def remove_discarded_flashes(session)
74
76
  return unless (old_flashes = session[:flash] && session[:flash]['discard'])
77
+
75
78
  Rails.logger.warn <<-MSG.strip_heredoc
76
79
  simple_workflow: found discarded flash entries: #{old_flashes}. Deleting them.
77
80
  MSG
@@ -79,7 +82,7 @@ class SimpleWorkflow::Middleware
79
82
  Rails.logger.warn "simple_workflow: session: #{session.to_hash}"
80
83
  end
81
84
 
82
- if ActionPack::VERSION::MAJOR == 5
85
+ if ActionPack::VERSION::MAJOR >= 5
83
86
  def serialize_session(cookie_jar, session)
84
87
  cookie_jar.send(:serialize, session)
85
88
  end
@@ -91,12 +94,13 @@ class SimpleWorkflow::Middleware
91
94
 
92
95
  def encryptor(env)
93
96
  return @simple_workflow_encryptor if @simple_workflow_encryptor
97
+
94
98
  @simple_workflow_encryptor = cookie_jar(env).instance_variable_get(:@encryptor)
95
99
  return @simple_workflow_encryptor if @simple_workflow_encryptor
100
+
96
101
  Rails.logger.warn 'simple_workflow: Could not get encryptor from the cookie jar'
97
- secret_key_base = Rails.application.config.secret_key_base ||
98
- Rails.application.config.secret_token ||
99
- SecureRandom.hex(64)
102
+ secret_key_base = Rails.application.config.secret_key_base || Rails.application.config.secret_token ||
103
+ SecureRandom.hex(64)
100
104
  key_generator = ActiveSupport::KeyGenerator.new(secret_key_base, iterations: 1000)
101
105
  key_generator = ActiveSupport::CachingKeyGenerator.new(key_generator)
102
106
  secret = key_generator.generate_key('encrypted cookie')
@@ -105,10 +109,10 @@ class SimpleWorkflow::Middleware
105
109
  end
106
110
 
107
111
  def store_detour_from_params(env)
108
- if params(env)[:detour]
109
- store_detour_in_session(session(env), params(env)[:detour])
110
- end
112
+ store_detour_in_session(session(env), params(env)[:detour]) if params(env)[:detour]
111
113
  return unless params(env)[:return_from_detour] && session(env)[:detours]
112
- pop_detour(session(env))
114
+
115
+ params_hash = params(env).to_h.reject { |k, _v| %i[detour return_from_detour].include? k.to_sym }
116
+ pop_detour(session(env), params_hash)
113
117
  end
114
118
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SimpleWorkflow
2
4
  # Railtie to activate the middleware.
3
5
  class Railtie < Rails::Railtie
@@ -5,14 +7,14 @@ module SimpleWorkflow
5
7
  app.middleware.insert_before ActionDispatch::Flash, SimpleWorkflow::Middleware
6
8
 
7
9
  # Make workflow test utility methods available in views
8
- ActionView::Base.send :include, SimpleWorkflow::Helper
10
+ ActionView::Base.include SimpleWorkflow::Helper
9
11
 
10
12
  # Make workflow test utility methods available in controllers
11
- ActionController::Base.send :include, SimpleWorkflow::Helper
12
- ActionController::Base.send :include, SimpleWorkflow::Controller
13
+ ActionController::Base.include SimpleWorkflow::Helper
14
+ ActionController::Base.include SimpleWorkflow::Controller
13
15
 
14
16
  # Make workflow test utility methods available in ActiveSupport test cases
15
- ActiveSupport::TestCase.send :include, SimpleWorkflow::TestHelper
17
+ ActiveSupport::TestCase.include SimpleWorkflow::TestHelper
16
18
  end
17
19
  end
18
20
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Utility methods to ease testing.
2
4
  module SimpleWorkflow::TestHelper
3
5
  def add_stored_detour(location = { controller: :bogus, action: :location })
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SimpleWorkflow
2
- VERSION = '1.5.1'.freeze
4
+ VERSION = '2.0.1'
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'test_helper'
2
4
  require 'rails'
3
5
 
@@ -6,15 +8,17 @@ class ControllerTest < MiniTest::Test
6
8
  attr_accessor :cookies, :logger, :session
7
9
 
8
10
  def setup
9
- options = { encrypted_cookie_salt: 'salt1', encrypted_signed_cookie_salt: 'salt2', secret_key_base: 'secret_key_base' }
11
+ options = { encrypted_cookie_salt: 'salt1', encrypted_signed_cookie_salt: 'salt2',
12
+ secret_key_base: 'secret_key_base' }
10
13
  if Rails.gem_version < Gem::Version.new('5')
11
- @cookies = ActionDispatch::Cookies::CookieJar.new(ActiveSupport::KeyGenerator.new('secret'), nil, false, options)
14
+ @cookies = ActionDispatch::Cookies::CookieJar
15
+ .new(ActiveSupport::KeyGenerator.new('secret'), nil, false, options)
12
16
  end
13
17
  @logger = Rails.logger
14
18
  @session = {}
15
19
  @bad_route = false
16
20
  # TODO(uwe): Remove when we stop testing Rails 4.1
17
- Rails.app_class = TestApp if Rails.version !~ /^4\.1\./
21
+ Rails.app_class = TestApp unless /^4\.1\./.match?(Rails.version)
18
22
  # ODOT
19
23
  end
20
24
 
@@ -32,7 +36,7 @@ class ControllerTest < MiniTest::Test
32
36
  assert_equal({}, session)
33
37
  end
34
38
 
35
- def test_back_with_invalid_detour # not route
39
+ def test_back_with_invalid_detour
36
40
  store_detour(controller: :mycontroller, action: :missing_in_action)
37
41
  @bad_route = true
38
42
  back({})
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'test_helper'
2
4
  require 'action_controller/metal/exceptions'
3
5
  require 'test_app'
@@ -6,18 +8,26 @@ class HelperTest < MiniTest::Test
6
8
  include SimpleWorkflow::Helper
7
9
 
8
10
  def test_with_detour
9
- assert_equal '?detour%5Baction%5D=myaction&detour%5Bcontroller%5D=mycontroller&detour%5Bid%5D=42&detour%5Bquery%5D%5Bnested%5D=criterium',
10
- with_detour('')
11
+ assert_equal '?detour%5Baction%5D=myaction&detour%5Bcontroller%5D=mycontroller&detour%5Bid%5D=42' \
12
+ '&detour%5Bquery%5D%5Bnested%5D=criterium',
13
+ with_detour('')
11
14
  end
12
15
 
13
16
  def test_with_detour_with_origin
14
17
  assert_equal '?detour%5Baction%5D=index&detour%5Bcontroller%5D=dashboard',
15
- with_detour('', controller: :dashboard, action: :index)
18
+ with_detour('', controller: :dashboard, action: :index)
16
19
  end
17
20
 
18
21
  def test_with_detour_with_only_anchor_as_origin
19
- assert_equal '?detour%5Baction%5D=myaction&detour%5Banchor%5D=tab_2&detour%5Bcontroller%5D=mycontroller&detour%5Bid%5D=42&detour%5Bquery%5D%5Bnested%5D=criterium',
20
- with_detour('', anchor: :tab_2)
22
+ assert_equal '?detour%5Baction%5D=myaction&detour%5Banchor%5D=tab_2' \
23
+ '&detour%5Bcontroller%5D=mycontroller&detour%5Bid%5D=42&detour%5Bquery%5D%5Bnested%5D=criterium',
24
+ with_detour('', anchor: :tab_2)
25
+ end
26
+
27
+ module SimpleWorkflow::Controller
28
+ def self.binary_params_for?(_action)
29
+ false
30
+ end
21
31
  end
22
32
 
23
33
  def test_with_detour_with_string_origin
@@ -27,8 +37,9 @@ class HelperTest < MiniTest::Test
27
37
  get 'dashboard/index' => 'simple_workflow/#index'
28
38
  end
29
39
 
30
- assert_equal '?detour%5Baction%5D=index&detour%5Banchor%5D=tab_2&detour%5Bcontroller%5D=simple_workflow%2F&detour%5Bhullo%5D=1',
31
- with_detour('', '/dashboard/index?hullo=1#tab_2')
40
+ assert_equal '?detour%5Baction%5D=index&detour%5Banchor%5D=tab_2' \
41
+ '&detour%5Bcontroller%5D=simple_workflow%2F&detour%5Bhullo%5D=1',
42
+ with_detour('', '/dashboard/index?hullo=1#tab_2')
32
43
  ensure
33
44
  Rails.application = nil
34
45
  end
@@ -36,10 +47,11 @@ class HelperTest < MiniTest::Test
36
47
  def test_detour_to
37
48
  assert_equal [
38
49
  'Link Text',
39
- 'Link target?detour%5Baction%5D=myaction&detour%5Bcontroller%5D=mycontroller&detour%5Bid%5D=42&detour%5Bquery%5D%5Bnested%5D=criterium',
40
- { id: 'link_tag_id', title: 'Link title' }
50
+ 'Link target?detour%5Baction%5D=myaction&detour%5Bcontroller%5D=mycontroller&detour%5Bid%5D=42' \
51
+ '&detour%5Bquery%5D%5Bnested%5D=criterium',
52
+ { id: 'link_tag_id', title: 'Link title' },
41
53
  ],
42
- detour_to('Link Text', 'Link target', id: 'link_tag_id', title: 'Link title')
54
+ detour_to('Link Text', 'Link target', id: 'link_tag_id', title: 'Link title')
43
55
  end
44
56
 
45
57
  def test_image_button_to
@@ -50,26 +62,27 @@ class HelperTest < MiniTest::Test
50
62
  onclick: "form.action='{:id=>\"image_tag_id\"}'"
51
63
  }
52
64
  ],
53
- image_button_to('my_image.png', 'Link Title', { id: 'image_tag_id' }, title: 'Image title')
65
+ image_button_to('my_image.png', 'Link Title', { id: 'image_tag_id' },
66
+ title: 'Image title')
54
67
  end
55
68
 
56
69
  def test_image_link_to
57
70
  assert_equal [
58
71
  ['my_image.png', { title: 'Link Title', alt: 'Link Title' }], { id: 'image_tag_id' }, nil
59
72
  ],
60
- image_link_to('my_image.png', 'Link Title', { id: 'image_tag_id' }, title: 'Image title')
73
+ image_link_to('my_image.png', 'Link Title', { id: 'image_tag_id' }, title: 'Image title')
61
74
  end
62
75
 
63
76
  def test_back_or_link_to
64
77
  assert_equal ['Link title', { controller: :mycontroller, action: :my_action }, nil],
65
- back_or_link_to('Link title', controller: :mycontroller, action: :my_action)
78
+ back_or_link_to('Link title', controller: :mycontroller, action: :my_action)
66
79
  end
67
80
 
68
81
  def test_back_or_link_to_with_routing_error
69
82
  @session = { detours: [{ controller: :does_not_exist }] }
70
83
  @routing_error = ActionController::UrlGenerationError
71
84
  assert_equal ['Link title', { controller: :mycontroller, action: :my_action }, nil],
72
- back_or_link_to('Link title', controller: :mycontroller, action: :my_action)
85
+ back_or_link_to('Link title', controller: :mycontroller, action: :my_action)
73
86
  end
74
87
 
75
88
  private
@@ -80,8 +93,8 @@ class HelperTest < MiniTest::Test
80
93
 
81
94
  def params
82
95
  ActionController::Parameters.new(
83
- controller: 'mycontroller', action: 'myaction', id: 42, query: { nested: 'criterium' }
84
- )
96
+ controller: 'mycontroller', action: 'myaction', id: 42, query: { nested: 'criterium' }
97
+ )
85
98
  end
86
99
 
87
100
  def session
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'test_helper'
2
4
  require 'simple_workflow/middleware'
3
5
  require_relative 'test_app'
@@ -42,12 +44,14 @@ class MiddlewareTest < MiniTest::Test
42
44
  def test_detour_cleanup
43
45
  _, env, = @stack.call env_for('/?detour[controller]=test_first')
44
46
  (50..99).each do |i|
45
- next_env = env_for("/?detour[controller]=test_#{i}", 'rack.session' => env['rack.session'],
46
- 'rack.session.options' => env['rack.session.options'])
47
+ next_env = env_for("/?detour[controller]=test_#{i}",
48
+ 'rack.session' => env['rack.session'],
49
+ 'rack.session.options' => env['rack.session.options'])
47
50
  _, env, = @stack.call next_env
48
51
  end
49
- last_env = env_for('/?detour[controller]=test_last', 'rack.session' => env['rack.session'],
50
- 'rack.session.options' => env['rack.session.options'])
52
+ last_env = env_for('/?detour[controller]=test_last',
53
+ 'rack.session' => env['rack.session'],
54
+ 'rack.session.options' => env['rack.session.options'])
51
55
  status, env, response = @stack.call last_env
52
56
 
53
57
  assert_equal 200, status
@@ -55,7 +59,7 @@ class MiddlewareTest < MiniTest::Test
55
59
  assert_equal(%w[session_id detours], env['rack.session'].to_hash.keys)
56
60
 
57
61
  assert_equal(((57..99).to_a + [:last]).map { |i| { 'controller' => "test_#{i}" } },
58
- env['rack.session'].to_hash['detours'])
62
+ env['rack.session'].to_hash['detours'])
59
63
  end
60
64
 
61
65
  def test_huge_detour_over_4k
@@ -75,8 +79,8 @@ class MiddlewareTest < MiniTest::Test
75
79
  def test_return_from_detour
76
80
  _, headers1, = @stack.call env_for('/?detour[controller]=test_first')
77
81
  env = env_for('/?return_from_detour=true',
78
- 'rack.session' => headers1['rack.session'],
79
- 'rack.session.options' => headers1['rack.session.options'])
82
+ 'rack.session' => headers1['rack.session'],
83
+ 'rack.session.options' => headers1['rack.session.options'])
80
84
  status, headers, response = @stack.call env
81
85
 
82
86
  assert_equal 200, status
@@ -90,11 +94,16 @@ class MiddlewareTest < MiniTest::Test
90
94
 
91
95
  def env_for(url, opts = {})
92
96
  default_opts = {
97
+ ActionDispatch::Cookies::COOKIES_ROTATIONS => ActiveSupport::Messages::RotationConfiguration.new,
93
98
  ActionDispatch::Cookies::COOKIES_SERIALIZER => :json,
99
+ ActionDispatch::Cookies::ENCRYPTED_COOKIE_SALT => 'salt',
100
+ ActionDispatch::Cookies::ENCRYPTED_SIGNED_COOKIE_SALT => 'signed_salt',
94
101
  ActionDispatch::Cookies::GENERATOR_KEY => ActiveSupport::KeyGenerator.new('secret'),
95
102
  ActionDispatch::Cookies::SECRET_KEY_BASE => 'secret',
96
- # ActionDispatch::Cookies::SECRET_TOKEN => 'secret',
97
103
  }
104
+ if /^5\.2\./.match?(Rails.version)
105
+ default_opts[ActionDispatch::Cookies::COOKIES_ROTATIONS] = Struct.new(:encrypted).new([])
106
+ end
98
107
  Rack::MockRequest.env_for(url, default_opts.update(opts))
99
108
  end
100
109
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails'
2
4
 
3
5
  class TestApp < Rails::Application
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rubygems'
2
4
  require 'bundler/setup'
3
5
  require 'simplecov'
@@ -11,8 +13,4 @@ MiniTest::Reporters.use!
11
13
  require 'rails'
12
14
  require 'simple_workflow'
13
15
 
14
- if Gem::Requirement.new('~>4.2') =~ Gem::Version.new(Rails.version)
15
- ActiveSupport::TestCase.test_order = :random
16
- end
17
-
18
16
  FileUtils.mkdir_p File.expand_path '../log', __dir__
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.5.1
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Uwe Kubosch
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-28 00:00:00.000000000 Z
11
+ date: 2021-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,36 +16,36 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4'
19
+ version: '4.2'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '5.2'
22
+ version: '6.1'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '4'
29
+ version: '4.2'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '5.2'
32
+ version: '6.1'
33
33
  - !ruby/object:Gem::Dependency
34
- name: simplecov
34
+ name: minitest-reporters
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '0.9'
39
+ version: '1.0'
40
40
  type: :development
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: '0.9'
46
+ version: '1.0'
47
47
  - !ruby/object:Gem::Dependency
48
- name: minitest-reporters
48
+ name: rubocop
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - "~>"
@@ -59,20 +59,48 @@ dependencies:
59
59
  - !ruby/object:Gem::Version
60
60
  version: '1.0'
61
61
  - !ruby/object:Gem::Dependency
62
- name: rubocop
62
+ name: rubocop-performance
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
65
  - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: '0.45'
67
+ version: '1.5'
68
68
  type: :development
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
- version: '0.45'
75
- description: Expands Ruby On Rails to allow simple breadcrumb detour workflows.
74
+ version: '1.5'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rubocop-rails
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '2.4'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '2.4'
89
+ - !ruby/object:Gem::Dependency
90
+ name: simplecov
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '0.9'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '0.9'
103
+ description: Expands Ruby on Rails to allow simple breadcrumb detour workflows.
76
104
  email: uwe@kubosch.no
77
105
  executables: []
78
106
  extensions: []
@@ -100,24 +128,23 @@ homepage: https://github.com/donv/simple_workflow
100
128
  licenses:
101
129
  - MIT
102
130
  metadata: {}
103
- post_install_message:
131
+ post_install_message:
104
132
  rdoc_options: []
105
133
  require_paths:
106
134
  - lib
107
135
  required_ruby_version: !ruby/object:Gem::Requirement
108
136
  requirements:
109
- - - "~>"
137
+ - - ">="
110
138
  - !ruby/object:Gem::Version
111
- version: '2.2'
139
+ version: '2.5'
112
140
  required_rubygems_version: !ruby/object:Gem::Requirement
113
141
  requirements:
114
142
  - - ">="
115
143
  - !ruby/object:Gem::Version
116
144
  version: '0'
117
145
  requirements: []
118
- rubyforge_project: donv/simple_workflow
119
- rubygems_version: 2.6.11
120
- signing_key:
146
+ rubygems_version: 3.2.3
147
+ signing_key:
121
148
  specification_version: 4
122
149
  summary: Add simple breadcrumbs "detour" workflow to Ruby On Rails.
123
150
  test_files: []