wicked 0.1.6 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of wicked might be problematic. Click here for more details.

@@ -1,3 +1,9 @@
1
+ ## 0.2.0 (07/27/2012)
2
+
3
+ * Make step configuration an instance level config instead of class.
4
+ * [#25] current_step?, past_step?, future_step?, next_step? & previous_step? step helper methods to be used in the view(thanks @ahorner)
5
+ # [#28] accept options to `render_wizard` (@nata79)
6
+
1
7
  ## 0.1.6 (06/02/2012)
2
8
 
3
9
  * remove `WizardController#_reset_invocation_response`
data/README.md CHANGED
@@ -6,7 +6,7 @@ Use wicked to make your Rails controllers into step-by-step wizards. To see Wick
6
6
 
7
7
  ## Why
8
8
 
9
- Many times I'm left wanting a RESTful way to display a step by step process that may or not be associated with a resource. Wicked gives the flexibility to do what I want while hiding all the really scary stuff you shouldn't do in a controller to make this possible. At it's core Wicked is a RESTful(ish) state machine, but you don't need to know that, just use it.
9
+ Many times I'm left wanting a RESTful way to display a step by step process that may or not be associated with a resource. Wicked gives the flexibility to do what I want while hiding all the really nasty stuff you shouldn't do in a controller to make this possible. At it's core Wicked is a RESTful(ish) state machine, but you don't need to know that, just use it.
10
10
 
11
11
  ## Install
12
12
 
@@ -20,7 +20,7 @@ Then run `bundle install` and you're ready to start
20
20
 
21
21
  ## Quicklinks
22
22
 
23
- * Deal with validation in a Wizard using [Partial Validation of Active Record Objects](https://github.com/schneems/wicked/wiki/Partial-Validation-of-Active-Record-Objects)
23
+ * Build an object step-by-step using [Partial Validation of Active Record Objects](https://github.com/schneems/wicked/wiki/Partial-Validation-of-Active-Record-Objects)
24
24
  * [Show Current Wizard Progress to User](https://github.com/schneems/wicked/wiki/Show-Current-Wizard-Progress-to-User)
25
25
  * [Example App](https://github.com/schneems/wicked_example)
26
26
  * [Screencast](http://schneems.com/post/18437886598/wizard-ify-your-rails-controllers-with-wicked)
@@ -180,7 +180,6 @@ View/URL Helpers
180
180
  Controller Tidbits:
181
181
 
182
182
  ```ruby
183
-
184
183
  steps :first, :second # Sets the order of steps
185
184
  step # Gets symbol of current step
186
185
  next_step # Gets symbol of next step
@@ -189,16 +188,6 @@ Controller Tidbits:
189
188
  render_wizard(@user) # Shows next_step if @user.save, otherwise renders current step
190
189
  ```
191
190
 
192
- Testing with RSpec
193
-
194
- ```ruby
195
- # Test find_friends block of show action
196
- get :show, :id => :find_friends
197
-
198
- # Test find_friends block of update action
199
- put :update, {'id' => 'find_friends', "user" => {"id"=>@user.id.to_s}}
200
-
201
- ```
202
191
 
203
192
  Finally:
204
193
 
@@ -213,6 +202,31 @@ Don't forget to create your named views
213
202
  # ...
214
203
  ```
215
204
 
205
+
206
+ # Finish Wizard Path
207
+
208
+ You can specify the url that your user goes to by over-riding the `finish_wizard_path` in your wizard controller.
209
+
210
+
211
+ ```
212
+ def finish_wizard_path
213
+ user_path(current_user)
214
+ end
215
+ ```
216
+
217
+
218
+ Testing with RSpec
219
+
220
+ ```ruby
221
+ # Test find_friends block of show action
222
+ get :show, :id => :find_friends
223
+
224
+ # Test find_friends block of update action
225
+ put :update, {'id' => 'find_friends', "user" => { "id" => @user.id.to_s }}
226
+ ```
227
+
228
+
229
+
216
230
  ## About
217
231
 
218
232
  Please poke around the source code, if you see easier ways to get a Rails controller do do what I want, let me know.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.6
1
+ 0.2.0
@@ -2,13 +2,13 @@ module Wicked::Controller::Concerns::RenderRedirect
2
2
  extend ActiveSupport::Concern
3
3
 
4
4
 
5
- def render_wizard(resource = nil)
5
+ def render_wizard(resource = nil, options = {})
6
6
  process_resource!(resource)
7
7
 
8
8
  if @skip_to
9
- redirect_to wizard_path @skip_to
9
+ redirect_to wizard_path(@skip_to), options
10
10
  else
11
- render_step @step
11
+ render_step @step, options
12
12
  end
13
13
  end
14
14
 
@@ -22,11 +22,11 @@ module Wicked::Controller::Concerns::RenderRedirect
22
22
  end
23
23
  end
24
24
 
25
- def render_step(the_step)
25
+ def render_step(the_step, options = {})
26
26
  if the_step.nil? || the_step == :finish
27
- redirect_to_finish_wizard
27
+ redirect_to_finish_wizard options
28
28
  else
29
- render the_step
29
+ render the_step, options
30
30
  end
31
31
  end
32
32
 
@@ -43,8 +43,8 @@ module Wicked::Controller::Concerns::RenderRedirect
43
43
  '/'
44
44
  end
45
45
 
46
- def redirect_to_finish_wizard
47
- redirect_to finish_wizard_path
46
+ def redirect_to_finish_wizard(options = nil)
47
+ redirect_to finish_wizard_path, options
48
48
  end
49
49
 
50
50
  end
@@ -13,19 +13,52 @@ module Wicked::Controller::Concerns::Steps
13
13
  @step
14
14
  end
15
15
 
16
+ # will return true if step passed in is the currently rendered step
17
+ def current_step?(step_name)
18
+ return false if step_name.nil? || step.nil?
19
+ step == step_name
20
+ end
21
+
22
+ # will return true if the step passed in has already been executed by the wizard
23
+ def past_step?(step_name)
24
+ return false if steps.index(step).nil? || steps.index(step_name).nil?
25
+ steps.index(step) > steps.index(step_name)
26
+ end
27
+
28
+ # will return true if the step passed in has already been executed by the wizard
29
+ def future_step?(step_name)
30
+ return false if steps.index(step).nil? || steps.index(step_name).nil?
31
+ steps.index(step) < steps.index(step_name)
32
+ end
33
+
34
+ # will return true if the last step is the step passed in
35
+ def previous_step?(step_name)
36
+ return false if steps.index(step).nil? || steps.index(step_name).nil?
37
+ steps.index(step) - 1 == steps.index(step_name)
38
+ end
39
+
40
+ # will return true if the next step is the step passed in
41
+ def next_step?(step_name)
42
+ return false if steps.index(step).nil? || steps.index(step_name).nil?
43
+ steps.index(step) + 1 == steps.index(step_name)
44
+ end
45
+
16
46
  module ClassMethods
17
- def steps=(steps)
18
- @wizard_steps = steps
47
+ def steps(*args)
48
+ options = args.last.is_a?(Hash) ? callbacks.pop : {}
49
+ steps = args
50
+ prepend_before_filter(options) do
51
+ self.steps = steps
52
+ end
19
53
  end
54
+ end
20
55
 
21
- def steps(*steps_to_set)
22
- @wizard_steps = steps_to_set unless steps_to_set.blank?
23
- @wizard_steps
24
- end
56
+ def steps=(wizard_steps)
57
+ @wizard_steps = wizard_steps
25
58
  end
26
59
 
27
60
  def steps
28
- self.class.steps
61
+ @wizard_steps
29
62
  end
30
63
  alias :wizard_steps :steps
31
64
  alias :steps_list :steps
@@ -9,7 +9,10 @@ module Wicked
9
9
 
10
10
  included do
11
11
  # Give our Views helper methods!
12
- helper_method :wizard_path, :next_wizard_path, :previous_wizard_path, :step, :wizard_steps
12
+ helper_method :wizard_path, :next_wizard_path, :previous_wizard_path,
13
+ :step, :wizard_steps, :current_step?,
14
+ :past_step?, :future_step?, :previous_step?,
15
+ :next_step?
13
16
  # Set @step and @next_step variables
14
17
  before_filter :setup_wizard
15
18
  end
@@ -0,0 +1,13 @@
1
+ ## This controller uses includes
2
+
3
+ class StepPositionsController < ApplicationController
4
+ include Wicked::Wizard
5
+ steps :first, :second, :last_step
6
+
7
+ def show
8
+ render_wizard
9
+ end
10
+
11
+ def update
12
+ end
13
+ end
@@ -1,6 +1,5 @@
1
1
  first
2
2
 
3
-
4
3
  <%= link_to 'last', wizard_path(:last_step) %>
5
4
  <%= link_to 'current', wizard_path %>
6
5
  <%= link_to 'skip', next_wizard_path %>
@@ -0,0 +1,9 @@
1
+ <% wizard_steps.each do |s| %>
2
+ <p>
3
+ <%= "#{s} step is the current step" if current_step?(s) %><br />
4
+ <%= "#{s} step is a past step" if past_step?(s) %><br />
5
+ <%= "#{s} step is a future step" if future_step?(s) %><br />
6
+ <%= "#{s} step was the previous step" if previous_step?(s) %><br />
7
+ <%= "#{s} step is the next step" if next_step?(s) %><br />
8
+ </p>
9
+ <% end %>
@@ -0,0 +1 @@
1
+ <%= render 'step_position' %>
@@ -0,0 +1 @@
1
+ <%= render 'step_position' %>
@@ -0,0 +1 @@
1
+ <%= render 'step_position' %>
@@ -2,6 +2,7 @@ Dummy::Application.routes.draw do
2
2
  resources :foo
3
3
  resources :bar
4
4
  resources :jump
5
+ resources :step_positions
5
6
 
6
7
  # The priority is based upon order of creation:
7
8
  # first created -> highest priority.
@@ -0,0 +1,32 @@
1
+ require 'test_helper'
2
+
3
+ class StepPositionsTest < ActiveSupport::IntegrationCase
4
+
5
+ test 'on first' do
6
+ step = :first
7
+ visit(step_position_path(step))
8
+ assert has_content?('first step is the current step') # current_step?
9
+ assert true # past_step?
10
+ assert has_content?('last_step step is a future step') # future_step?
11
+ assert has_content?('second step is a future step') # future_step?
12
+ assert true # previous_step?
13
+ assert has_content?('second step is the next step') # next_step?
14
+ end
15
+
16
+ test 'on second' do
17
+ step = :second
18
+ visit(step_position_path(step))
19
+ assert has_content?('second step is the current step') # current_step?
20
+ assert has_content?('first step is a past step') # past_step?
21
+ assert has_content?('last_step step is a future step') # future_step?
22
+ assert has_content?('first step was the previous step') # previous_step?
23
+ assert has_content?('last_step step is the next step') # next_step?
24
+ end
25
+
26
+ end
27
+
28
+ # current_step?
29
+ # past_step?
30
+ # future_step?
31
+ # previous_step?
32
+ # next_step?
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "wicked"
8
- s.version = "0.1.6"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["schneems"]
12
- s.date = "2012-06-02"
12
+ s.date = "2012-07-27"
13
13
  s.description = "Wicked is a Rails engine for producing easy wizard controllers"
14
14
  s.email = "richard.schneeman@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -37,6 +37,7 @@ Gem::Specification.new do |s|
37
37
  "test/dummy/app/controllers/bar_controller.rb",
38
38
  "test/dummy/app/controllers/foo_controller.rb",
39
39
  "test/dummy/app/controllers/jump_controller.rb",
40
+ "test/dummy/app/controllers/steps_controller.rb",
40
41
  "test/dummy/app/helpers/application_helper.rb",
41
42
  "test/dummy/app/models/bar.rb",
42
43
  "test/dummy/app/views/bar/first.html.erb",
@@ -49,6 +50,10 @@ Gem::Specification.new do |s|
49
50
  "test/dummy/app/views/jump/last_step.html.erb",
50
51
  "test/dummy/app/views/jump/second.html.erb",
51
52
  "test/dummy/app/views/layouts/application.html.erb",
53
+ "test/dummy/app/views/step_positions/_step_position.html.erb",
54
+ "test/dummy/app/views/step_positions/first.html.erb",
55
+ "test/dummy/app/views/step_positions/last_step.html.erb",
56
+ "test/dummy/app/views/step_positions/second.html.erb",
52
57
  "test/dummy/config.ru",
53
58
  "test/dummy/config/application.rb",
54
59
  "test/dummy/config/boot.rb",
@@ -80,6 +85,7 @@ Gem::Specification.new do |s|
80
85
  "test/integration/helpers_test.rb",
81
86
  "test/integration/jump_test.rb",
82
87
  "test/integration/navigation_test.rb",
88
+ "test/integration/steps_test.rb",
83
89
  "test/support/integration_case.rb",
84
90
  "test/test_helper.rb",
85
91
  "test/wicked_test.rb",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wicked
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-02 00:00:00.000000000Z
12
+ date: 2012-07-27 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &70351864816900 !ruby/object:Gem::Requirement
16
+ requirement: &70254091223080 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.0.7
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70351864816900
24
+ version_requirements: *70254091223080
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rails
27
- requirement: &70351864816420 !ruby/object:Gem::Requirement
27
+ requirement: &70254091222500 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 3.0.7
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70351864816420
35
+ version_requirements: *70254091222500
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &70351864815860 !ruby/object:Gem::Requirement
38
+ requirement: &70254091221900 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70351864815860
46
+ version_requirements: *70254091221900
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: jeweler
49
- requirement: &70351864815340 !ruby/object:Gem::Requirement
49
+ requirement: &70254091221420 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.6.4
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70351864815340
57
+ version_requirements: *70254091221420
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rcov
60
- requirement: &70351864814820 !ruby/object:Gem::Requirement
60
+ requirement: &70254091139260 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70351864814820
68
+ version_requirements: *70254091139260
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: capybara
71
- requirement: &70351864814340 !ruby/object:Gem::Requirement
71
+ requirement: &70254091138740 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 0.4.0
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70351864814340
79
+ version_requirements: *70254091138740
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: sqlite3
82
- requirement: &70351864813820 !ruby/object:Gem::Requirement
82
+ requirement: &70254091138220 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70351864813820
90
+ version_requirements: *70254091138220
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: launchy
93
- requirement: &70351864813300 !ruby/object:Gem::Requirement
93
+ requirement: &70254091137620 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,7 +98,7 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *70351864813300
101
+ version_requirements: *70254091137620
102
102
  description: Wicked is a Rails engine for producing easy wizard controllers
103
103
  email: richard.schneeman@gmail.com
104
104
  executables: []
@@ -127,6 +127,7 @@ files:
127
127
  - test/dummy/app/controllers/bar_controller.rb
128
128
  - test/dummy/app/controllers/foo_controller.rb
129
129
  - test/dummy/app/controllers/jump_controller.rb
130
+ - test/dummy/app/controllers/steps_controller.rb
130
131
  - test/dummy/app/helpers/application_helper.rb
131
132
  - test/dummy/app/models/bar.rb
132
133
  - test/dummy/app/views/bar/first.html.erb
@@ -139,6 +140,10 @@ files:
139
140
  - test/dummy/app/views/jump/last_step.html.erb
140
141
  - test/dummy/app/views/jump/second.html.erb
141
142
  - test/dummy/app/views/layouts/application.html.erb
143
+ - test/dummy/app/views/step_positions/_step_position.html.erb
144
+ - test/dummy/app/views/step_positions/first.html.erb
145
+ - test/dummy/app/views/step_positions/last_step.html.erb
146
+ - test/dummy/app/views/step_positions/second.html.erb
142
147
  - test/dummy/config.ru
143
148
  - test/dummy/config/application.rb
144
149
  - test/dummy/config/boot.rb
@@ -170,6 +175,7 @@ files:
170
175
  - test/integration/helpers_test.rb
171
176
  - test/integration/jump_test.rb
172
177
  - test/integration/navigation_test.rb
178
+ - test/integration/steps_test.rb
173
179
  - test/support/integration_case.rb
174
180
  - test/test_helper.rb
175
181
  - test/wicked_test.rb
@@ -189,7 +195,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
189
195
  version: '0'
190
196
  segments:
191
197
  - 0
192
- hash: -1992748704531741576
198
+ hash: 3200335910919771555
193
199
  required_rubygems_version: !ruby/object:Gem::Requirement
194
200
  none: false
195
201
  requirements: