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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 11cb28be77c99ea61096702aa91925c6fc5f70a0
4
- data.tar.gz: 7bfe552498e8dc0b263b731b88f21afa203ce906
3
+ metadata.gz: b63f9f8d7d8f8c637a0aadb1efee7dbc2342375e
4
+ data.tar.gz: 3c318690cd2f9f2f0a5b24fae6ad990351398b60
5
5
  SHA512:
6
- metadata.gz: f01bf2e83f1a848225a59fa4bf6feb18567c1e14fe116aea9ba69a292a4ca878e35eef48646a013f8a0016c22e5c19a4e474d62c4f62a4ea81b8d5fd17114187
7
- data.tar.gz: c3d6640feacdee82c98b7c652fbcca9a0414b8669e9bf52e78fee80518c233266da3e99b66eeaa3f3fff2f630cedc696bec64520bf60d06752dc271f628f2c19
6
+ metadata.gz: ec7cdb890f429b88a73cf90c057ecbdfd89118a0287f02da5d3c293f3f807e1c9ac364945422a6c4ea9737cdbd77ccc4984a58c3b866251775a380770cd56045
7
+ data.tar.gz: b7d891997073d41429a7aa45cd6c7ee8b9d76782ddab6915ef1664df2939f5a854e8f094367cc13ff6e3accdb703514fa269753b64eba28f2a11aa54919da882
@@ -1,5 +1,9 @@
1
1
  ## Master
2
2
 
3
+ ## 1.3.2
4
+
5
+ * Support for params (#222)
6
+
3
7
  ## 1.3.1
4
8
 
5
9
  * Docs and minor fixes
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
- redirect_to wizard_path(@skip_to, @wicked_redirect_params || {}), options
9
+ url_params = (@wicked_redirect_params || {}).merge(params)
10
+ redirect_to wizard_path(@skip_to, url_params), options
10
11
  else
11
- render_step wizard_value(step), options
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
@@ -1,3 +1,3 @@
1
1
  module Wicked
2
- VERSION = "1.3.1"
2
+ VERSION = "1.3.2"
3
3
  end
@@ -32,7 +32,7 @@ class Wicked::WizardController < ApplicationController
32
32
  # @user.update_attributes(params[:user])
33
33
  # end
34
34
  # sign_in(@user, :bypass => true) # needed for devise
35
- # render_wizard
35
+ # render_wizard @user
36
36
  # end
37
37
  end
38
38
 
@@ -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
+ <%= render 'step_position' %>
@@ -0,0 +1 @@
1
+ <%= render 'step_position' %>
@@ -11,6 +11,6 @@
11
11
  </p>
12
12
  <% end %>
13
13
 
14
- <%= form_tag update_path(step), :method => :put do %>
14
+ <%= form_tag update_path(step, {one: 'two'}), :method => :put do %>
15
15
  <%= submit_tag "Next" %>
16
16
  <% end %>
@@ -9,6 +9,7 @@ Dummy::Application.routes.draw do
9
9
  resources :redirect_to_next
10
10
  resources :redirect_to_finish_flash
11
11
  resources :updates
12
+ resources :update_params
12
13
 
13
14
  resources :nested do
14
15
  resources :builder, :controller => 'nested/builder'
@@ -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.1
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: 2016-09-06 00:00:00.000000000 Z
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.4
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