wicked 1.3.1 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/check_changelog.yml +13 -0
- data/.gitignore +1 -0
- data/.travis.yml +10 -21
- data/Appraisals +6 -25
- data/CHANGELOG.md +18 -1
- data/Gemfile +1 -5
- data/README.md +69 -22
- data/gemfiles/rails_5.1.gemfile +12 -0
- data/gemfiles/rails_5.2.gemfile +12 -0
- data/gemfiles/rails_6.0.1.gemfile +12 -0
- data/lib/wicked/controller/concerns/path.rb +12 -3
- data/lib/wicked/controller/concerns/render_redirect.rb +29 -22
- data/lib/wicked/controller/concerns/steps.rb +3 -7
- data/lib/wicked/version.rb +1 -1
- data/lib/wicked/wizard/translated.rb +1 -4
- data/lib/wicked/wizard.rb +14 -14
- data/lib/wicked/wizard_controller.rb +1 -2
- data/test/dummy/app/controllers/update_params_controller.rb +30 -0
- data/test/dummy/app/views/bar/first.html.erb +3 -1
- data/test/dummy/app/views/bar/second.html.erb +2 -1
- 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/helpers_test.rb +27 -0
- data/test/integration/security_test.rb +0 -2
- data/test/integration/update_params_test.rb +20 -0
- data/test/test_helper.rb +9 -9
- metadata +24 -13
- data/gemfiles/3.1.gemfile +0 -12
- data/gemfiles/3.2.gemfile +0 -12
- data/gemfiles/4.0.gemfile +0 -12
- data/gemfiles/4.1.gemfile +0 -12
- data/gemfiles/4.2.gemfile +0 -12
- data/gemfiles/5.0.beta2.gemfile +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ebda68c36a8e0e08aa54c850b91c176720d5fa4897482d0312182c2bee6a418f
|
4
|
+
data.tar.gz: f7a27e0b7baafe854a3891d0ec185a425f6d0e57694325dd2597ca9f7f94d85b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bad278bb225e74a389efb8413290763b644625ff2bdc89213da99c7941b214abbdbfbc1e9e85c691a03196be064321f07d3c1222a2916c45bb6be3c425aee874
|
7
|
+
data.tar.gz: db3bdd321cc8902b9fa693e4884c567aa9fe474ad7fbe5cdd6f7452beec054ba9b21252441dabfd42e23adc94ee1e7fceac4bda07394d456c7cc36e65f50d82d
|
@@ -0,0 +1,13 @@
|
|
1
|
+
name: Check Changelog
|
2
|
+
|
3
|
+
on:
|
4
|
+
pull_request:
|
5
|
+
types: [opened, reopened, edited, synchronize]
|
6
|
+
jobs:
|
7
|
+
build:
|
8
|
+
runs-on: ubuntu-latest
|
9
|
+
steps:
|
10
|
+
- uses: actions/checkout@v1
|
11
|
+
- name: Check that CHANGELOG is touched
|
12
|
+
run: |
|
13
|
+
cat $GITHUB_EVENT_PATH | jq .pull_request.title | grep -i '\[\(\(changelog skip\)\|\(ci skip\)\)\]' || git diff remotes/origin/${{ github.base_ref }} --name-only | grep CHANGELOG.md
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,28 +1,17 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
-
|
4
|
-
- 2.
|
5
|
-
- 2.
|
6
|
-
- 2.2.2
|
7
|
-
- ruby-head
|
8
|
-
- jruby-19mode
|
3
|
+
- 2.5.8
|
4
|
+
- 2.6.6
|
5
|
+
- 2.7.1
|
9
6
|
|
10
7
|
sudo: false
|
11
8
|
|
12
9
|
gemfile:
|
13
|
-
- gemfiles/
|
14
|
-
- gemfiles/
|
15
|
-
- gemfiles/
|
16
|
-
- gemfiles/4.1.gemfile
|
17
|
-
- gemfiles/4.2.gemfile
|
18
|
-
matrix:
|
19
|
-
include:
|
20
|
-
- gemfile: gemfiles/5.0.beta2.gemfile
|
21
|
-
rvm: 2.2.2
|
22
|
-
allow_failures:
|
23
|
-
- gemfile: gemfiles/3.0.gemfile
|
24
|
-
rvm: 2.0.0
|
25
|
-
- gemfile: gemfiles/3.0.gemfile
|
26
|
-
rvm: 2.1.1
|
27
|
-
- rvm: ruby-head
|
10
|
+
- gemfiles/rails_5.1.gemfile
|
11
|
+
- gemfiles/rails_5.2.gemfile
|
12
|
+
- gemfiles/rails_6.0.1.gemfile
|
28
13
|
|
14
|
+
jobs:
|
15
|
+
exclude:
|
16
|
+
- gemfile: gemfiles/rails_5.1.gemfile
|
17
|
+
rvm: 2.7.1
|
data/Appraisals
CHANGED
@@ -1,30 +1,11 @@
|
|
1
|
-
appraise "
|
2
|
-
gem "rails", "~>
|
3
|
-
gemspec
|
1
|
+
appraise "rails-5.1" do
|
2
|
+
gem "rails", "~> 5.2"
|
4
3
|
end
|
5
4
|
|
6
|
-
appraise "
|
7
|
-
gem "rails", "~>
|
8
|
-
gemspec
|
5
|
+
appraise "rails-5.2" do
|
6
|
+
gem "rails", "~> 5.2"
|
9
7
|
end
|
10
8
|
|
11
|
-
appraise "
|
12
|
-
gem "rails", "~>
|
13
|
-
gemspec
|
14
|
-
end
|
15
|
-
|
16
|
-
appraise "4.1" do
|
17
|
-
gem "rails", "~> 4.1.0"
|
18
|
-
gemspec
|
19
|
-
end
|
20
|
-
|
21
|
-
|
22
|
-
appraise "4.2" do
|
23
|
-
gem "rails", "~> 4.2"
|
24
|
-
gemspec
|
25
|
-
end
|
26
|
-
|
27
|
-
appraise "5.0.beta2" do
|
28
|
-
gem "rails", "~> 5.0.0.beta2"
|
29
|
-
gemspec
|
9
|
+
appraise "rails-6.0.1" do
|
10
|
+
gem "rails", "~> 6.0.1"
|
30
11
|
end
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,21 @@
|
|
1
|
-
##
|
1
|
+
## Unreleased
|
2
|
+
|
3
|
+
## 1.4.0
|
4
|
+
|
5
|
+
* Update readme to include `current_step?` (https://github.com/zombocom/wicked/pull/271)
|
6
|
+
* Add `*_url` versions of `wizard_path`, `next_wizard_path`, and `previous_wizard_path` (https://github.com/zombocom/wicked/pull/272)
|
7
|
+
|
8
|
+
## 1.3.4
|
9
|
+
|
10
|
+
* Remove arity check for AR objects (https://github.com/schneems/wicked/pull/257)
|
11
|
+
|
12
|
+
## 1.3.3
|
13
|
+
|
14
|
+
* Support being able to set a context in validation (https://github.com/schneems/wicked/pull/236)
|
15
|
+
|
16
|
+
## 1.3.2
|
17
|
+
|
18
|
+
* Support for params (#222)
|
2
19
|
|
3
20
|
## 1.3.1
|
4
21
|
|
data/Gemfile
CHANGED
@@ -1,10 +1,6 @@
|
|
1
1
|
source "https://rubygems.org"
|
2
2
|
|
3
|
-
|
4
|
-
# Put all runtime dependencies in wicked.gemspec
|
5
|
-
# Put development requirements for different platforms here
|
6
|
-
# Put more specific gem declarations in different gemfiles/*.gemfile files
|
7
|
-
gemspec :path => ::File.expand_path("../.", __FILE__)
|
3
|
+
gemspec
|
8
4
|
|
9
5
|
group :development, :test do
|
10
6
|
gem "sqlite3", :platform => [:ruby, :mswin, :mingw]
|
data/README.md
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
|
5
5
|
[![Build Status](https://travis-ci.org/schneems/wicked.svg?branch=master)](https://travis-ci.org/schneems/wicked)
|
6
6
|
[![Code Climate](https://codeclimate.com/github/schneems/wicked/badges/gpa.svg)](https://codeclimate.com/github/schneems/wicked)
|
7
|
+
[![Help Contribute to Open Source](https://www.codetriage.com/schneems/wicked/badges/users.svg)](https://www.codetriage.com/schneems/wicked)
|
7
8
|
|
8
9
|
|
9
10
|
Use wicked to make your Rails controllers into step-by-step wizards. To see Wicked in action check out the example [Rails app](https://github.com/schneems/wicked_example) or [watch the screencast](http://schneems.com/post/18437886598/wizard-ify-your-rails-controllers-with-wicked).
|
@@ -120,11 +121,17 @@ class AfterSignupController < ApplicationController
|
|
120
121
|
@user = current_user
|
121
122
|
case step
|
122
123
|
when :confirm_password
|
123
|
-
@user.update_attributes(
|
124
|
+
@user.update_attributes(user_params)
|
124
125
|
end
|
125
126
|
sign_in(@user, bypass: true) # needed for devise
|
126
127
|
render_wizard @user
|
127
128
|
end
|
129
|
+
|
130
|
+
private
|
131
|
+
def user_params
|
132
|
+
params.require(:user)
|
133
|
+
.permit(:email, :current_password) # ...
|
134
|
+
end
|
128
135
|
end
|
129
136
|
```
|
130
137
|
|
@@ -170,12 +177,17 @@ Now you've got a fully functioning AfterSignup controller! If you have questions
|
|
170
177
|
**View/URL Helpers:**
|
171
178
|
|
172
179
|
```ruby
|
173
|
-
wizard_path #
|
174
|
-
wizard_path(:specific_step) #
|
175
|
-
next_wizard_path #
|
176
|
-
previous_wizard_path #
|
180
|
+
wizard_path # relative url of the current step
|
181
|
+
wizard_path(:specific_step) # relative url of a :specific_step
|
182
|
+
next_wizard_path # relative url of the next step
|
183
|
+
previous_wizard_path # relative url of the previous step
|
184
|
+
|
185
|
+
wizard_url # fully qualified url of the current step
|
186
|
+
wizard_url(:specific_step) # fully qualified url of a :specific_step
|
187
|
+
next_wizard_url # fully qualified url of the next step
|
188
|
+
previous_wizard_url # fully qualified url of the previous step
|
177
189
|
|
178
|
-
# These only work while in a Wizard
|
190
|
+
# These only work while in a Wizard
|
179
191
|
# You can have multiple wizards in a project with multiple `wizard_path` calls
|
180
192
|
```
|
181
193
|
|
@@ -183,19 +195,21 @@ previous_wizard_path # Url of the previous step
|
|
183
195
|
**Controller Tidbits:**
|
184
196
|
|
185
197
|
```ruby
|
186
|
-
steps :first, :second
|
187
|
-
step
|
188
|
-
next_step
|
189
|
-
previous_step
|
190
|
-
skip_step
|
191
|
-
jump_to(:specific_step)
|
192
|
-
render_wizard
|
193
|
-
render_wizard(@user)
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
198
|
+
steps :first, :second # Sets the order of steps
|
199
|
+
step # Gets current step
|
200
|
+
next_step # Gets next step
|
201
|
+
previous_step # Gets previous step
|
202
|
+
skip_step # Tells render_wizard to skip to the next logical step
|
203
|
+
jump_to(:specific_step) # Jump to :specific_step
|
204
|
+
render_wizard # Renders the current step
|
205
|
+
render_wizard(@user) # Shows next_step if @user.save, otherwise renders
|
206
|
+
render_wizard(@user, context: :account_setup) # Shows next_step if @user.save(context: :account_setup), otherwise renders
|
207
|
+
wizard_steps # Gets ordered list of steps
|
208
|
+
current_step?(step) # is step the same as the current request's step
|
209
|
+
past_step?(step) # does step come before the current request's step in wizard_steps
|
210
|
+
future_step?(step) # does step come after the current request's step in wizard_steps
|
211
|
+
previous_step?(step) # is step immediately before the current request's step
|
212
|
+
next_step?(step) # is step immediately after the current request's step
|
199
213
|
```
|
200
214
|
|
201
215
|
**Redirect options**
|
@@ -243,10 +257,10 @@ end
|
|
243
257
|
|
244
258
|
```ruby
|
245
259
|
# Test find_friends block of show action
|
246
|
-
get :show, id: :find_friends
|
260
|
+
get :show, params: { id: :find_friends }
|
247
261
|
|
248
262
|
# Test find_friends block of update action
|
249
|
-
|
263
|
+
patch :update, params: {'id' => 'find_friends', "user" => { "id" => @user.id.to_s }}
|
250
264
|
```
|
251
265
|
|
252
266
|
### Internationalization of URLS (I18n)
|
@@ -397,6 +411,39 @@ end
|
|
397
411
|
|
398
412
|
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
413
|
|
414
|
+
## Send params to finish_wizard_path method
|
415
|
+
|
416
|
+
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`.
|
417
|
+
|
418
|
+
In order to send the parameters to the method here is an example of the show method:
|
419
|
+
|
420
|
+
```ruby
|
421
|
+
steps :first_step, :second_step
|
422
|
+
|
423
|
+
def show
|
424
|
+
# ...
|
425
|
+
render_wizard(nil, {}, { hello: 'world' })
|
426
|
+
end
|
427
|
+
|
428
|
+
def update
|
429
|
+
# ...
|
430
|
+
render_wizard(@user, {}, { hello: 'world' })
|
431
|
+
end
|
432
|
+
|
433
|
+
def finish_wizard_path(params)
|
434
|
+
# here you can access params and that would be equal to { hello: 'world' }
|
435
|
+
end
|
436
|
+
```
|
437
|
+
|
438
|
+
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:
|
439
|
+
|
440
|
+
```ruby
|
441
|
+
next_wizard_path({ hello: 'world' })
|
442
|
+
wizard_path(nil, { hello: 'world' })
|
443
|
+
# the wizard_path with the step specified would look like this
|
444
|
+
wizard_path(:wicked_finish, wizard_id: @user.id, hello: 'world')
|
445
|
+
```
|
446
|
+
|
400
447
|
## Keywords
|
401
448
|
|
402
449
|
There are a few "magical" keywords that will take you to the first step,
|
@@ -431,7 +478,7 @@ This project rocks and uses MIT-LICENSE.
|
|
431
478
|
|
432
479
|
## Compatibility
|
433
480
|
|
434
|
-
Refer to the Travis CI test matrix for test using your version of Ruby and Rails. If there is a newer Ruby or Rails you don't see on there, please add an entry to the
|
481
|
+
Refer to the Travis CI test matrix for test using your version of Ruby and Rails. If there is a newer Ruby or Rails you don't see on there, please add an entry to the Appraisals file, then run `$ appraisals install` and update the `.travis.yml` file and send me a pull request.
|
435
482
|
|
436
483
|
Note: Rails 3.0 support is only for Ruby 1.9.3 or JRuby, not Ruby 2.0.0 or newer.
|
437
484
|
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "rails", "~> 5.2"
|
6
|
+
|
7
|
+
group :development, :test do
|
8
|
+
gem "sqlite3", platform: [:ruby, :mswin, :mingw]
|
9
|
+
gem "activerecord-jdbcsqlite3-adapter", "~> 1.3.13", platform: :jruby
|
10
|
+
end
|
11
|
+
|
12
|
+
gemspec path: "../"
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "rails", "~> 5.2"
|
6
|
+
|
7
|
+
group :development, :test do
|
8
|
+
gem "sqlite3", platform: [:ruby, :mswin, :mingw]
|
9
|
+
gem "activerecord-jdbcsqlite3-adapter", "~> 1.3.13", platform: :jruby
|
10
|
+
end
|
11
|
+
|
12
|
+
gemspec path: "../"
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "rails", "~> 6.0.1"
|
6
|
+
|
7
|
+
group :development, :test do
|
8
|
+
gem "sqlite3", platform: [:ruby, :mswin, :mingw]
|
9
|
+
gem "activerecord-jdbcsqlite3-adapter", "~> 1.3.13", platform: :jruby
|
10
|
+
end
|
11
|
+
|
12
|
+
gemspec path: "../"
|
@@ -1,15 +1,22 @@
|
|
1
1
|
module Wicked::Controller::Concerns::Path
|
2
2
|
extend ActiveSupport::Concern
|
3
3
|
|
4
|
-
|
5
4
|
def next_wizard_path(options = {})
|
6
5
|
wizard_path(@next_step, options)
|
7
6
|
end
|
8
7
|
|
8
|
+
def next_wizard_url(options = {})
|
9
|
+
wizard_url(@next_step, options)
|
10
|
+
end
|
11
|
+
|
9
12
|
def previous_wizard_path(options = {})
|
10
13
|
wizard_path(@previous_step, options)
|
11
14
|
end
|
12
15
|
|
16
|
+
def previous_wizard_url(options = {})
|
17
|
+
wizard_url(@previous_step, options)
|
18
|
+
end
|
19
|
+
|
13
20
|
def wicked_controller
|
14
21
|
params[:controller]
|
15
22
|
end
|
@@ -18,7 +25,6 @@ module Wicked::Controller::Concerns::Path
|
|
18
25
|
params[:action]
|
19
26
|
end
|
20
27
|
|
21
|
-
|
22
28
|
def wizard_path(goto_step = nil, options = {})
|
23
29
|
options = options.respond_to?(:to_h) ? options.to_h : options
|
24
30
|
options = { :controller => wicked_controller,
|
@@ -28,5 +34,8 @@ module Wicked::Controller::Concerns::Path
|
|
28
34
|
}.merge options
|
29
35
|
url_for(options)
|
30
36
|
end
|
31
|
-
end
|
32
37
|
|
38
|
+
def wizard_url(goto_step = nil, options = {})
|
39
|
+
wizard_path(goto_step, options.merge(only_path: false))
|
40
|
+
end
|
41
|
+
end
|
@@ -1,54 +1,61 @@
|
|
1
1
|
module Wicked::Controller::Concerns::RenderRedirect
|
2
2
|
extend ActiveSupport::Concern
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
process_resource!(resource)
|
4
|
+
def render_wizard(resource = nil, options = {}, params = {})
|
5
|
+
process_resource!(resource, options)
|
7
6
|
|
8
7
|
if @skip_to
|
9
|
-
|
8
|
+
url_params = (@wicked_redirect_params || {}).merge(params)
|
9
|
+
redirect_to wizard_path(@skip_to, url_params), options
|
10
10
|
else
|
11
|
-
render_step
|
11
|
+
render_step(wizard_value(step), options, params)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
def process_resource!(resource)
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
15
|
+
def process_resource!(resource, options = {})
|
16
|
+
return unless resource
|
17
|
+
|
18
|
+
if options[:context]
|
19
|
+
did_save = resource.save(context: options[:context])
|
20
|
+
else
|
21
|
+
did_save = resource.save
|
22
|
+
end
|
23
|
+
|
24
|
+
if did_save
|
25
|
+
@skip_to ||= @next_step
|
26
|
+
else
|
27
|
+
@skip_to = nil
|
22
28
|
end
|
23
29
|
end
|
24
30
|
|
25
|
-
def render_step(the_step, options = {})
|
31
|
+
def render_step(the_step, options = {}, params = {})
|
26
32
|
if the_step.nil? || the_step.to_s == Wicked::FINISH_STEP
|
27
|
-
redirect_to_finish_wizard options
|
33
|
+
redirect_to_finish_wizard options, params
|
28
34
|
else
|
29
35
|
render the_step, options
|
30
36
|
end
|
31
37
|
end
|
32
38
|
|
33
|
-
def redirect_to_next(next_step, options = {})
|
39
|
+
def redirect_to_next(next_step, options = {}, params = {})
|
34
40
|
if next_step.nil?
|
35
|
-
redirect_to_finish_wizard(options)
|
41
|
+
redirect_to_finish_wizard(options, params)
|
36
42
|
else
|
37
|
-
redirect_to wizard_path(next_step), options
|
43
|
+
redirect_to wizard_path(next_step, params), options
|
38
44
|
end
|
39
45
|
end
|
40
46
|
|
41
47
|
# TODO redirect to resource if one is passed to render_wizard
|
42
|
-
def finish_wizard_path
|
43
|
-
'/'
|
48
|
+
def finish_wizard_path(params = {})
|
49
|
+
url = '/'
|
50
|
+
url = "#{url}?#{params.to_query}" unless params.blank?
|
51
|
+
url
|
44
52
|
end
|
45
53
|
|
46
|
-
def redirect_to_finish_wizard(options = {})
|
47
|
-
wicked_final_redirect_path = finish_wizard_path
|
54
|
+
def redirect_to_finish_wizard(options = {}, params = {})
|
55
|
+
wicked_final_redirect_path = method(:finish_wizard_path).arity == 1 ? finish_wizard_path(params) : finish_wizard_path
|
48
56
|
Rails.logger.debug("Wizard has finished, redirecting to finish_wizard_path: #{wicked_final_redirect_path.inspect}")
|
49
57
|
# flash.keep is required for Rails 3 where a flash message is lost on a second redirect.
|
50
58
|
flash.keep
|
51
59
|
redirect_to wicked_final_redirect_path, options
|
52
60
|
end
|
53
61
|
end
|
54
|
-
|
@@ -83,7 +83,6 @@ module Wicked::Controller::Concerns::Steps
|
|
83
83
|
step ||= steps.first
|
84
84
|
end
|
85
85
|
|
86
|
-
|
87
86
|
def next_step(current_step = nil)
|
88
87
|
return @next_step if current_step.nil?
|
89
88
|
index = steps.index(current_step)
|
@@ -91,18 +90,15 @@ module Wicked::Controller::Concerns::Steps
|
|
91
90
|
step ||= Wicked::FINISH_STEP
|
92
91
|
end
|
93
92
|
|
94
|
-
private
|
95
|
-
|
96
|
-
def step_index_for(step_name)
|
93
|
+
private def step_index_for(step_name)
|
97
94
|
steps.index(step_name)
|
98
95
|
end
|
99
96
|
|
100
|
-
def current_step_index
|
97
|
+
private def current_step_index
|
101
98
|
step_index_for(step)
|
102
99
|
end
|
103
100
|
|
104
|
-
def current_and_given_step_exists?(step_name)
|
101
|
+
private def current_and_given_step_exists?(step_name)
|
105
102
|
current_step_index.present? && steps.index(step_name).present?
|
106
103
|
end
|
107
104
|
end
|
108
|
-
|
data/lib/wicked/version.rb
CHANGED
@@ -57,7 +57,6 @@ module Wicked
|
|
57
57
|
end
|
58
58
|
|
59
59
|
|
60
|
-
private
|
61
60
|
# sets up a translated wizard controller
|
62
61
|
# translations are expected under the 'wicked' namespace
|
63
62
|
#
|
@@ -74,12 +73,10 @@ module Wicked
|
|
74
73
|
#
|
75
74
|
# steps "wicked.first", "wicked.second"
|
76
75
|
#
|
77
|
-
def setup_wizard_translated
|
76
|
+
private def setup_wizard_translated
|
78
77
|
self.steps = wizard_translations.keys # must come before setting previous/next steps
|
79
78
|
setup_wizard
|
80
79
|
end
|
81
|
-
public
|
82
80
|
end
|
83
81
|
end
|
84
82
|
end
|
85
|
-
|
data/lib/wicked/wizard.rb
CHANGED
@@ -15,7 +15,6 @@ module Wicked
|
|
15
15
|
end
|
16
16
|
|
17
17
|
# Include the modules!!
|
18
|
-
|
19
18
|
include Wicked::Controller::Concerns::Path
|
20
19
|
include Wicked::Controller::Concerns::RenderRedirect
|
21
20
|
include Wicked::Controller::Concerns::Steps
|
@@ -23,12 +22,12 @@ module Wicked
|
|
23
22
|
included do
|
24
23
|
include Wicked::Controller::Concerns::Action
|
25
24
|
# Give our Views helper methods!
|
26
|
-
helper_method :wizard_path,
|
27
|
-
:step,
|
28
|
-
:
|
29
|
-
|
25
|
+
helper_method :wizard_path, :wizard_url, :next_wizard_path, :next_wizard_url, :previous_wizard_path,
|
26
|
+
:previous_wizard_url, :step, :wizard_steps, :current_step?, :past_step?, :future_step?,
|
27
|
+
:next_step?, :previous_step?
|
28
|
+
|
30
29
|
# Set @step and @next_step variables
|
31
|
-
before_action :setup_wizard
|
30
|
+
before_action :initialize_wicked_variables, :setup_wizard
|
32
31
|
end
|
33
32
|
|
34
33
|
# forward to first step with whatever params are provided
|
@@ -41,14 +40,17 @@ module Wicked
|
|
41
40
|
step_name
|
42
41
|
end
|
43
42
|
|
44
|
-
private
|
43
|
+
private def initialize_wicked_variables
|
44
|
+
@skip_to = nil
|
45
|
+
@wicked_redirect_params = nil
|
46
|
+
end
|
45
47
|
|
46
|
-
def check_redirect_to_first_last!(step)
|
48
|
+
private def check_redirect_to_first_last!(step)
|
47
49
|
redirect_to wizard_path(steps.first) if step.to_s == Wicked::FIRST_STEP
|
48
50
|
redirect_to wizard_path(steps.last) if step.to_s == Wicked::LAST_STEP
|
49
51
|
end
|
50
52
|
|
51
|
-
def setup_step_from(the_step)
|
53
|
+
private def setup_step_from(the_step)
|
52
54
|
return if steps.nil?
|
53
55
|
|
54
56
|
the_step ||= steps.first
|
@@ -61,23 +63,21 @@ module Wicked
|
|
61
63
|
the_step
|
62
64
|
end
|
63
65
|
|
64
|
-
def check_steps!
|
66
|
+
private def check_steps!
|
65
67
|
raise UndefinedStepsError if steps.nil?
|
66
68
|
end
|
67
69
|
|
68
|
-
def set_previous_next(step)
|
70
|
+
private def set_previous_next(step)
|
69
71
|
@previous_step = previous_step(step)
|
70
72
|
@next_step = next_step(step)
|
71
73
|
end
|
72
74
|
|
73
|
-
def setup_wizard
|
75
|
+
private def setup_wizard
|
74
76
|
check_steps!
|
75
77
|
return if params[:id].nil?
|
76
78
|
|
77
79
|
@step = setup_step_from(params[:id])
|
78
80
|
set_previous_next(@step)
|
79
81
|
end
|
80
|
-
public
|
81
82
|
end
|
82
83
|
end
|
83
|
-
|
@@ -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
|
@@ -4,4 +4,6 @@ first
|
|
4
4
|
<%= "params[:foo] #{params[:foo]}" %>
|
5
5
|
<%= link_to 'last', wizard_path(:last_step) %>
|
6
6
|
<%= link_to 'current', wizard_path %>
|
7
|
-
<%= link_to '
|
7
|
+
<%= link_to 'current url', wizard_url %>
|
8
|
+
<%= link_to 'skip', next_wizard_path %>
|
9
|
+
<%= link_to 'next url', next_wizard_url %>
|
@@ -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
@@ -5,13 +5,23 @@ class HelpersTest < ActiveSupport::IntegrationCase
|
|
5
5
|
test 'next_wizard_path' do
|
6
6
|
step = :first
|
7
7
|
visit(bar_path(step))
|
8
|
+
assert has_link?('skip', href: '/bar/second')
|
8
9
|
click_link 'skip'
|
9
10
|
assert_has_content?('second')
|
10
11
|
end
|
11
12
|
|
13
|
+
test 'next_wizard_url' do
|
14
|
+
step = :first
|
15
|
+
visit(bar_path(step))
|
16
|
+
assert has_link?('next url', href: 'http://www.example.com/bar/second')
|
17
|
+
click_link 'next url'
|
18
|
+
assert_has_content?('second')
|
19
|
+
end
|
20
|
+
|
12
21
|
test 'wizard_path' do
|
13
22
|
step = :first
|
14
23
|
visit(bar_path(step))
|
24
|
+
assert has_link?('current', href: '/bar/first')
|
15
25
|
click_link 'current'
|
16
26
|
assert_has_content?(step.to_s)
|
17
27
|
end
|
@@ -23,9 +33,26 @@ class HelpersTest < ActiveSupport::IntegrationCase
|
|
23
33
|
assert_has_content?('last_step')
|
24
34
|
end
|
25
35
|
|
36
|
+
test 'wizard_url' do
|
37
|
+
step = :first
|
38
|
+
visit(bar_path(step))
|
39
|
+
assert has_link?('current url', href: 'http://www.example.com/bar/first')
|
40
|
+
click_link 'current'
|
41
|
+
assert_has_content?(step.to_s)
|
42
|
+
end
|
43
|
+
|
26
44
|
test 'previous_wizard_path' do
|
27
45
|
step = :second
|
28
46
|
visit(bar_path(step))
|
47
|
+
assert has_link?('previous', href: '/bar/first')
|
48
|
+
click_link 'previous'
|
49
|
+
assert_has_content?("first")
|
50
|
+
end
|
51
|
+
|
52
|
+
test 'previous_wizard_url' do
|
53
|
+
step = :second
|
54
|
+
visit(bar_path(step))
|
55
|
+
assert has_link?('previous url', href: 'http://www.example.com/bar/first')
|
29
56
|
click_link 'previous'
|
30
57
|
assert_has_content?("first")
|
31
58
|
end
|
@@ -7,7 +7,6 @@ class SecurityTest < ActiveSupport::IntegrationCase
|
|
7
7
|
assert_raise(Wicked::Wizard::InvalidStepError) do
|
8
8
|
visit(bar_path(step))
|
9
9
|
end
|
10
|
-
refute has_content?('sqlite3')
|
11
10
|
end
|
12
11
|
|
13
12
|
# only works on *nix systems
|
@@ -18,6 +17,5 @@ class SecurityTest < ActiveSupport::IntegrationCase
|
|
18
17
|
assert_raise(Wicked::Wizard::InvalidStepError) do
|
19
18
|
visit(bar_path(step))
|
20
19
|
end
|
21
|
-
refute has_content?('aardvark')
|
22
20
|
end
|
23
21
|
end
|
@@ -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
|
data/test/test_helper.rb
CHANGED
@@ -1,15 +1,10 @@
|
|
1
1
|
# Configure Rails Envinronment
|
2
2
|
ENV["RAILS_ENV"] = "test"
|
3
3
|
|
4
|
-
|
5
|
-
|
6
4
|
ENGINE_RAILS_ROOT=File.join(File.dirname(__FILE__), '../')
|
7
5
|
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
8
6
|
require "rails/test_help"
|
9
7
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
8
|
ActionMailer::Base.delivery_method = :test
|
14
9
|
ActionMailer::Base.perform_deliveries = true
|
15
10
|
ActionMailer::Base.default_url_options[:host] = "test.com"
|
@@ -21,10 +16,15 @@ require "capybara/rails"
|
|
21
16
|
Capybara.default_driver = :rack_test
|
22
17
|
Capybara.default_selector = :css
|
23
18
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
ActiveRecord::
|
19
|
+
# https://github.com/plataformatec/devise/blob/master/test/orm/active_record.rb
|
20
|
+
migrate_path = File.expand_path("../rails_app/db/migrate", __FILE__)
|
21
|
+
if Rails.version.start_with? '6'
|
22
|
+
ActiveRecord::MigrationContext.new(migrate_path, ActiveRecord::SchemaMigration).migrate
|
23
|
+
elsif Rails.version.start_with? '5.2'
|
24
|
+
ActiveRecord::MigrationContext.new(migrate_path).migrate
|
25
|
+
else
|
26
|
+
ActiveRecord::Migrator.migrate(migrate_path)
|
27
|
+
end
|
28
28
|
|
29
29
|
# Load support files
|
30
30
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
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.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Schneeman
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -88,6 +88,7 @@ extensions: []
|
|
88
88
|
extra_rdoc_files:
|
89
89
|
- README.md
|
90
90
|
files:
|
91
|
+
- ".github/workflows/check_changelog.yml"
|
91
92
|
- ".gitignore"
|
92
93
|
- ".travis.yml"
|
93
94
|
- Appraisals
|
@@ -97,12 +98,9 @@ files:
|
|
97
98
|
- MIT-LICENSE
|
98
99
|
- README.md
|
99
100
|
- Rakefile
|
100
|
-
- gemfiles/
|
101
|
-
- gemfiles/
|
102
|
-
- gemfiles/
|
103
|
-
- gemfiles/4.1.gemfile
|
104
|
-
- gemfiles/4.2.gemfile
|
105
|
-
- gemfiles/5.0.beta2.gemfile
|
101
|
+
- gemfiles/rails_5.1.gemfile
|
102
|
+
- gemfiles/rails_5.2.gemfile
|
103
|
+
- gemfiles/rails_6.0.1.gemfile
|
106
104
|
- lib/wicked.rb
|
107
105
|
- lib/wicked/controller/concerns/action.rb
|
108
106
|
- lib/wicked/controller/concerns/path.rb
|
@@ -128,6 +126,7 @@ files:
|
|
128
126
|
- test/dummy/app/controllers/redirect_to_next_controller.rb
|
129
127
|
- test/dummy/app/controllers/step_positions_controller.rb
|
130
128
|
- test/dummy/app/controllers/string_steps_controller.rb
|
129
|
+
- test/dummy/app/controllers/update_params_controller.rb
|
131
130
|
- test/dummy/app/controllers/updates_controller.rb
|
132
131
|
- test/dummy/app/helpers/application_helper.rb
|
133
132
|
- test/dummy/app/models/bar.rb
|
@@ -157,6 +156,11 @@ files:
|
|
157
156
|
- test/dummy/app/views/step_positions/last_step.html.erb
|
158
157
|
- test/dummy/app/views/step_positions/second.html.erb
|
159
158
|
- test/dummy/app/views/string_steps/second.html.erb
|
159
|
+
- test/dummy/app/views/update_params/_step_position.html.erb
|
160
|
+
- test/dummy/app/views/update_params/first.html.erb
|
161
|
+
- test/dummy/app/views/update_params/index.html.erb
|
162
|
+
- test/dummy/app/views/update_params/last_step.html.erb
|
163
|
+
- test/dummy/app/views/update_params/second.html.erb
|
160
164
|
- test/dummy/app/views/updates/_step_position.html.erb
|
161
165
|
- test/dummy/app/views/updates/first.html.erb
|
162
166
|
- test/dummy/app/views/updates/index.html.erb
|
@@ -200,6 +204,7 @@ files:
|
|
200
204
|
- test/integration/redirect_to_next_test.rb
|
201
205
|
- test/integration/security_test.rb
|
202
206
|
- test/integration/steps_test.rb
|
207
|
+
- test/integration/update_params_test.rb
|
203
208
|
- test/integration/updates_test.rb
|
204
209
|
- test/support/integration_case.rb
|
205
210
|
- test/support/wicked_controller_test_case.rb
|
@@ -210,7 +215,7 @@ homepage: https://github.com/schneems/wicked
|
|
210
215
|
licenses:
|
211
216
|
- MIT
|
212
217
|
metadata: {}
|
213
|
-
post_install_message:
|
218
|
+
post_install_message:
|
214
219
|
rdoc_options: []
|
215
220
|
require_paths:
|
216
221
|
- lib
|
@@ -225,9 +230,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
225
230
|
- !ruby/object:Gem::Version
|
226
231
|
version: '0'
|
227
232
|
requirements: []
|
228
|
-
|
229
|
-
|
230
|
-
signing_key:
|
233
|
+
rubygems_version: 3.2.32
|
234
|
+
signing_key:
|
231
235
|
specification_version: 4
|
232
236
|
summary: Use Wicked to turn your controller into a wizard
|
233
237
|
test_files:
|
@@ -246,6 +250,7 @@ test_files:
|
|
246
250
|
- test/dummy/app/controllers/redirect_to_next_controller.rb
|
247
251
|
- test/dummy/app/controllers/step_positions_controller.rb
|
248
252
|
- test/dummy/app/controllers/string_steps_controller.rb
|
253
|
+
- test/dummy/app/controllers/update_params_controller.rb
|
249
254
|
- test/dummy/app/controllers/updates_controller.rb
|
250
255
|
- test/dummy/app/helpers/application_helper.rb
|
251
256
|
- test/dummy/app/models/bar.rb
|
@@ -275,6 +280,11 @@ test_files:
|
|
275
280
|
- test/dummy/app/views/step_positions/last_step.html.erb
|
276
281
|
- test/dummy/app/views/step_positions/second.html.erb
|
277
282
|
- test/dummy/app/views/string_steps/second.html.erb
|
283
|
+
- test/dummy/app/views/update_params/_step_position.html.erb
|
284
|
+
- test/dummy/app/views/update_params/first.html.erb
|
285
|
+
- test/dummy/app/views/update_params/index.html.erb
|
286
|
+
- test/dummy/app/views/update_params/last_step.html.erb
|
287
|
+
- test/dummy/app/views/update_params/second.html.erb
|
278
288
|
- test/dummy/app/views/updates/_step_position.html.erb
|
279
289
|
- test/dummy/app/views/updates/first.html.erb
|
280
290
|
- test/dummy/app/views/updates/index.html.erb
|
@@ -318,6 +328,7 @@ test_files:
|
|
318
328
|
- test/integration/redirect_to_next_test.rb
|
319
329
|
- test/integration/security_test.rb
|
320
330
|
- test/integration/steps_test.rb
|
331
|
+
- test/integration/update_params_test.rb
|
321
332
|
- test/integration/updates_test.rb
|
322
333
|
- test/support/integration_case.rb
|
323
334
|
- test/support/wicked_controller_test_case.rb
|
data/gemfiles/3.1.gemfile
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
# This file was generated by Appraisal
|
2
|
-
|
3
|
-
source "https://rubygems.org"
|
4
|
-
|
5
|
-
gem "rails", "~> 3.1.0"
|
6
|
-
|
7
|
-
group :development, :test do
|
8
|
-
gem "sqlite3", :platform => [:ruby, :mswin, :mingw]
|
9
|
-
gem "activerecord-jdbcsqlite3-adapter", "~> 1.3.13", :platform => :jruby
|
10
|
-
end
|
11
|
-
|
12
|
-
gemspec :path => "../"
|
data/gemfiles/3.2.gemfile
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
# This file was generated by Appraisal
|
2
|
-
|
3
|
-
source "https://rubygems.org"
|
4
|
-
|
5
|
-
gem "rails", "~> 3.2.15"
|
6
|
-
|
7
|
-
group :development, :test do
|
8
|
-
gem "sqlite3", :platform => [:ruby, :mswin, :mingw]
|
9
|
-
gem "activerecord-jdbcsqlite3-adapter", "~> 1.3.13", :platform => :jruby
|
10
|
-
end
|
11
|
-
|
12
|
-
gemspec :path => "../"
|
data/gemfiles/4.0.gemfile
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
# This file was generated by Appraisal
|
2
|
-
|
3
|
-
source "https://rubygems.org"
|
4
|
-
|
5
|
-
gem "rails", "~> 4.0.0"
|
6
|
-
|
7
|
-
group :development, :test do
|
8
|
-
gem "sqlite3", :platform => [:ruby, :mswin, :mingw]
|
9
|
-
gem "activerecord-jdbcsqlite3-adapter", "~> 1.3.13", :platform => :jruby
|
10
|
-
end
|
11
|
-
|
12
|
-
gemspec :path => "../"
|
data/gemfiles/4.1.gemfile
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
# This file was generated by Appraisal
|
2
|
-
|
3
|
-
source "https://rubygems.org"
|
4
|
-
|
5
|
-
gem "rails", "~> 4.1.0"
|
6
|
-
|
7
|
-
group :development, :test do
|
8
|
-
gem "sqlite3", :platform => [:ruby, :mswin, :mingw]
|
9
|
-
gem "activerecord-jdbcsqlite3-adapter", "~> 1.3.13", :platform => :jruby
|
10
|
-
end
|
11
|
-
|
12
|
-
gemspec :path => "../"
|
data/gemfiles/4.2.gemfile
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
# This file was generated by Appraisal
|
2
|
-
|
3
|
-
source "https://rubygems.org"
|
4
|
-
|
5
|
-
gem "rails", "~> 4.2"
|
6
|
-
|
7
|
-
group :development, :test do
|
8
|
-
gem "sqlite3", :platform => [:ruby, :mswin, :mingw]
|
9
|
-
gem "activerecord-jdbcsqlite3-adapter", "~> 1.3.13", :platform => :jruby
|
10
|
-
end
|
11
|
-
|
12
|
-
gemspec :path => "../"
|
data/gemfiles/5.0.beta2.gemfile
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
# This file was generated by Appraisal
|
2
|
-
|
3
|
-
source "https://rubygems.org"
|
4
|
-
|
5
|
-
gem "rails", "~> 5.0.0.beta2"
|
6
|
-
|
7
|
-
group :development, :test do
|
8
|
-
gem "sqlite3", :platform => [:ruby, :mswin, :mingw]
|
9
|
-
gem "activerecord-jdbcsqlite3-adapter", "~> 1.3.13", :platform => :jruby
|
10
|
-
end
|
11
|
-
|
12
|
-
gemspec :path => "../"
|