wicked 1.3.1 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +33 -0
- data/lib/wicked/controller/concerns/render_redirect.rb +15 -12
- data/lib/wicked/version.rb +1 -1
- data/lib/wicked/wizard_controller.rb +1 -1
- data/test/dummy/app/controllers/update_params_controller.rb +30 -0
- data/test/dummy/app/views/update_params/_step_position.html.erb +16 -0
- data/test/dummy/app/views/update_params/first.html.erb +1 -0
- data/test/dummy/app/views/update_params/index.html.erb +1 -0
- data/test/dummy/app/views/update_params/last_step.html.erb +1 -0
- data/test/dummy/app/views/update_params/second.html.erb +1 -0
- data/test/dummy/app/views/updates/_step_position.html.erb +1 -1
- data/test/dummy/config/routes.rb +1 -0
- data/test/integration/update_params_test.rb +20 -0
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b63f9f8d7d8f8c637a0aadb1efee7dbc2342375e
|
4
|
+
data.tar.gz: 3c318690cd2f9f2f0a5b24fae6ad990351398b60
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec7cdb890f429b88a73cf90c057ecbdfd89118a0287f02da5d3c293f3f807e1c9ac364945422a6c4ea9737cdbd77ccc4984a58c3b866251775a380770cd56045
|
7
|
+
data.tar.gz: b7d891997073d41429a7aa45cd6c7ee8b9d76782ddab6915ef1664df2939f5a854e8f094367cc13ff6e3accdb703514fa269753b64eba28f2a11aa54919da882
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -397,6 +397,39 @@ end
|
|
397
397
|
|
398
398
|
NOTE: The order of the `before_action` matters, when `setup_wizard` is called it will validate the presence of `self.steps`, you must call your custom step setting code before this point.
|
399
399
|
|
400
|
+
## Send params to finish_wizard_path method
|
401
|
+
|
402
|
+
If you wish to send parameters to the `finish_wizard_path` method that can be done by adding to your controller the method with the params argument `def finish_wizard_path(params) ... end`.
|
403
|
+
|
404
|
+
In order to send the parameters to the method here is an example of the show method:
|
405
|
+
|
406
|
+
```ruby
|
407
|
+
steps :first_step, :second_step
|
408
|
+
|
409
|
+
def show
|
410
|
+
# ...
|
411
|
+
render_wizard(nil, {}, { hello: 'world' })
|
412
|
+
end
|
413
|
+
|
414
|
+
def update
|
415
|
+
# ...
|
416
|
+
render_wizard(@user, {}, { hello: 'world' })
|
417
|
+
end
|
418
|
+
|
419
|
+
def finish_wizard_path(params)
|
420
|
+
# here you can access params and that would be equal to { hello: 'world' }
|
421
|
+
end
|
422
|
+
```
|
423
|
+
|
424
|
+
The `wizard_path` and `next_wizard_path` methods also take parameters that can then be accessed or visible in the `show` and `update` actions of the controller. You can use the methods like so:
|
425
|
+
|
426
|
+
```ruby
|
427
|
+
next_wizard_path({ hello: 'world' })
|
428
|
+
wizard_path(nil, { hello: 'world' })
|
429
|
+
# the wizard_path with the step specified would look like this
|
430
|
+
wizard_path(:wicked_finish, wizard_id: @user.id, hello: 'world')
|
431
|
+
```
|
432
|
+
|
400
433
|
## Keywords
|
401
434
|
|
402
435
|
There are a few "magical" keywords that will take you to the first step,
|
@@ -2,13 +2,14 @@ module Wicked::Controller::Concerns::RenderRedirect
|
|
2
2
|
extend ActiveSupport::Concern
|
3
3
|
|
4
4
|
|
5
|
-
def render_wizard(resource = nil, options = {})
|
5
|
+
def render_wizard(resource = nil, options = {}, params = {})
|
6
6
|
process_resource!(resource)
|
7
7
|
|
8
8
|
if @skip_to
|
9
|
-
|
9
|
+
url_params = (@wicked_redirect_params || {}).merge(params)
|
10
|
+
redirect_to wizard_path(@skip_to, url_params), options
|
10
11
|
else
|
11
|
-
render_step
|
12
|
+
render_step(wizard_value(step), options, params)
|
12
13
|
end
|
13
14
|
end
|
14
15
|
|
@@ -22,29 +23,31 @@ module Wicked::Controller::Concerns::RenderRedirect
|
|
22
23
|
end
|
23
24
|
end
|
24
25
|
|
25
|
-
def render_step(the_step, options = {})
|
26
|
+
def render_step(the_step, options = {}, params = {})
|
26
27
|
if the_step.nil? || the_step.to_s == Wicked::FINISH_STEP
|
27
|
-
redirect_to_finish_wizard options
|
28
|
+
redirect_to_finish_wizard options, params
|
28
29
|
else
|
29
30
|
render the_step, options
|
30
31
|
end
|
31
32
|
end
|
32
33
|
|
33
|
-
def redirect_to_next(next_step, options = {})
|
34
|
+
def redirect_to_next(next_step, options = {}, params = {})
|
34
35
|
if next_step.nil?
|
35
|
-
redirect_to_finish_wizard(options)
|
36
|
+
redirect_to_finish_wizard(options, params)
|
36
37
|
else
|
37
|
-
redirect_to wizard_path(next_step), options
|
38
|
+
redirect_to wizard_path(next_step, params), options
|
38
39
|
end
|
39
40
|
end
|
40
41
|
|
41
42
|
# TODO redirect to resource if one is passed to render_wizard
|
42
|
-
def finish_wizard_path
|
43
|
-
'/'
|
43
|
+
def finish_wizard_path(params = {})
|
44
|
+
url = '/'
|
45
|
+
url = "#{url}?#{params.to_query}" unless params.blank?
|
46
|
+
url
|
44
47
|
end
|
45
48
|
|
46
|
-
def redirect_to_finish_wizard(options = {})
|
47
|
-
wicked_final_redirect_path = finish_wizard_path
|
49
|
+
def redirect_to_finish_wizard(options = {}, params = {})
|
50
|
+
wicked_final_redirect_path = method(:finish_wizard_path).arity == 1 ? finish_wizard_path(params) : finish_wizard_path
|
48
51
|
Rails.logger.debug("Wizard has finished, redirecting to finish_wizard_path: #{wicked_final_redirect_path.inspect}")
|
49
52
|
# flash.keep is required for Rails 3 where a flash message is lost on a second redirect.
|
50
53
|
flash.keep
|
data/lib/wicked/version.rb
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
class UpdateParamsController < ApplicationController
|
2
|
+
include Wicked::Wizard
|
3
|
+
|
4
|
+
class Thing
|
5
|
+
def save
|
6
|
+
true
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
steps :first, :second, :last_step
|
11
|
+
|
12
|
+
def index
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
def show
|
17
|
+
render_wizard(nil, {}, { one: 'two' })
|
18
|
+
end
|
19
|
+
|
20
|
+
def update
|
21
|
+
@thing = Thing.new
|
22
|
+
render_wizard(@thing, { notice: "Thing was updated from step #{step}." }, { one: 'two' })
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def finish_wizard_path(params)
|
28
|
+
update_params_path(params)
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<% wizard_steps.each do |s| %>
|
2
|
+
<%= s.inspect %>
|
3
|
+
<%= I18n.t("wicked.#{s}") %>
|
4
|
+
<p>
|
5
|
+
<strong><u><%= s.inspect %></u></strong><br />
|
6
|
+
<%= current_step?(s) ? "#{s} step is the current step" : "nope" %><br />
|
7
|
+
<%= past_step?(s) ? "#{s} step is a past step" : "nope" %><br />
|
8
|
+
<%= future_step?(s) ? "#{s} step is a future step" : "nope" %><br />
|
9
|
+
<%= previous_step?(s) ? "#{s} step was the previous step" : "nope" %><br />
|
10
|
+
<%= next_step?(s) ? "#{s} step is the next step" : "nope" %><br />
|
11
|
+
</p>
|
12
|
+
<% end %>
|
13
|
+
|
14
|
+
<%= form_tag update_param_path(step, {one: 'two'}), :method => :put do %>
|
15
|
+
<%= submit_tag "Next" %>
|
16
|
+
<% end %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= render 'step_position' %>
|
@@ -0,0 +1 @@
|
|
1
|
+
Index page.
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= render 'step_position' %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= render 'step_position' %>
|
data/test/dummy/config/routes.rb
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class UpdateParamsTest < ActiveSupport::IntegrationCase
|
4
|
+
test 'on first' do
|
5
|
+
step = :first
|
6
|
+
visit(update_param_path(step))
|
7
|
+
|
8
|
+
click_button("Next")
|
9
|
+
assert_equal page.current_path, update_param_path(:second)
|
10
|
+
assert_has_content?("notice:Thing was updated from step first.")
|
11
|
+
|
12
|
+
click_button("Next")
|
13
|
+
assert_equal page.current_path, update_param_path(:last_step)
|
14
|
+
assert_has_content?("notice:Thing was updated from step second.")
|
15
|
+
|
16
|
+
click_button("Next")
|
17
|
+
assert_equal page.current_url, update_params_url({host: 'www.example.com', one: 'two' })
|
18
|
+
assert_has_content?("notice:Thing was updated from step last_step.")
|
19
|
+
end
|
20
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wicked
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Schneeman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -128,6 +128,7 @@ files:
|
|
128
128
|
- test/dummy/app/controllers/redirect_to_next_controller.rb
|
129
129
|
- test/dummy/app/controllers/step_positions_controller.rb
|
130
130
|
- test/dummy/app/controllers/string_steps_controller.rb
|
131
|
+
- test/dummy/app/controllers/update_params_controller.rb
|
131
132
|
- test/dummy/app/controllers/updates_controller.rb
|
132
133
|
- test/dummy/app/helpers/application_helper.rb
|
133
134
|
- test/dummy/app/models/bar.rb
|
@@ -157,6 +158,11 @@ files:
|
|
157
158
|
- test/dummy/app/views/step_positions/last_step.html.erb
|
158
159
|
- test/dummy/app/views/step_positions/second.html.erb
|
159
160
|
- test/dummy/app/views/string_steps/second.html.erb
|
161
|
+
- test/dummy/app/views/update_params/_step_position.html.erb
|
162
|
+
- test/dummy/app/views/update_params/first.html.erb
|
163
|
+
- test/dummy/app/views/update_params/index.html.erb
|
164
|
+
- test/dummy/app/views/update_params/last_step.html.erb
|
165
|
+
- test/dummy/app/views/update_params/second.html.erb
|
160
166
|
- test/dummy/app/views/updates/_step_position.html.erb
|
161
167
|
- test/dummy/app/views/updates/first.html.erb
|
162
168
|
- test/dummy/app/views/updates/index.html.erb
|
@@ -200,6 +206,7 @@ files:
|
|
200
206
|
- test/integration/redirect_to_next_test.rb
|
201
207
|
- test/integration/security_test.rb
|
202
208
|
- test/integration/steps_test.rb
|
209
|
+
- test/integration/update_params_test.rb
|
203
210
|
- test/integration/updates_test.rb
|
204
211
|
- test/support/integration_case.rb
|
205
212
|
- test/support/wicked_controller_test_case.rb
|
@@ -226,7 +233,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
226
233
|
version: '0'
|
227
234
|
requirements: []
|
228
235
|
rubyforge_project:
|
229
|
-
rubygems_version: 2.6.
|
236
|
+
rubygems_version: 2.6.11
|
230
237
|
signing_key:
|
231
238
|
specification_version: 4
|
232
239
|
summary: Use Wicked to turn your controller into a wizard
|
@@ -246,6 +253,7 @@ test_files:
|
|
246
253
|
- test/dummy/app/controllers/redirect_to_next_controller.rb
|
247
254
|
- test/dummy/app/controllers/step_positions_controller.rb
|
248
255
|
- test/dummy/app/controllers/string_steps_controller.rb
|
256
|
+
- test/dummy/app/controllers/update_params_controller.rb
|
249
257
|
- test/dummy/app/controllers/updates_controller.rb
|
250
258
|
- test/dummy/app/helpers/application_helper.rb
|
251
259
|
- test/dummy/app/models/bar.rb
|
@@ -275,6 +283,11 @@ test_files:
|
|
275
283
|
- test/dummy/app/views/step_positions/last_step.html.erb
|
276
284
|
- test/dummy/app/views/step_positions/second.html.erb
|
277
285
|
- test/dummy/app/views/string_steps/second.html.erb
|
286
|
+
- test/dummy/app/views/update_params/_step_position.html.erb
|
287
|
+
- test/dummy/app/views/update_params/first.html.erb
|
288
|
+
- test/dummy/app/views/update_params/index.html.erb
|
289
|
+
- test/dummy/app/views/update_params/last_step.html.erb
|
290
|
+
- test/dummy/app/views/update_params/second.html.erb
|
278
291
|
- test/dummy/app/views/updates/_step_position.html.erb
|
279
292
|
- test/dummy/app/views/updates/first.html.erb
|
280
293
|
- test/dummy/app/views/updates/index.html.erb
|
@@ -318,6 +331,7 @@ test_files:
|
|
318
331
|
- test/integration/redirect_to_next_test.rb
|
319
332
|
- test/integration/security_test.rb
|
320
333
|
- test/integration/steps_test.rb
|
334
|
+
- test/integration/update_params_test.rb
|
321
335
|
- test/integration/updates_test.rb
|
322
336
|
- test/support/integration_case.rb
|
323
337
|
- test/support/wicked_controller_test_case.rb
|