stair_master 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +7 -0
  2. data/{LICENSE → MIT-LICENSE} +1 -1
  3. data/README.md +5 -6
  4. data/Rakefile +2 -2
  5. data/app/concerns/stair_master/controller.rb +20 -10
  6. data/lib/stair_master/concerns/ordering.rb +1 -6
  7. data/lib/stair_master/concerns/tests.rb +0 -5
  8. data/lib/stair_master/concerns/traversal.rb +1 -1
  9. data/lib/stair_master/conditions.rb +0 -1
  10. data/lib/stair_master/conditions/base.rb +0 -8
  11. data/lib/stair_master/step.rb +2 -10
  12. data/lib/stair_master/version.rb +1 -1
  13. data/spec/controllers/base/ordering_spec.rb +0 -23
  14. data/spec/controllers/base/skip_if_spec.rb +395 -0
  15. data/spec/controllers/base/skip_unless_spec.rb +151 -0
  16. data/spec/controllers/base/traversal_spec.rb +247 -158
  17. data/spec/dummy/Rakefile +1 -1
  18. data/spec/dummy/app/controllers/concerns/skip_if_methods.rb +24 -0
  19. data/spec/dummy/app/controllers/concerns/skip_unless_methods.rb +24 -0
  20. data/spec/dummy/app/controllers/skip_if/step_one_controller.rb +11 -0
  21. data/spec/dummy/app/controllers/skip_if/step_three_controller.rb +11 -0
  22. data/spec/dummy/app/controllers/skip_if/step_two_controller.rb +11 -0
  23. data/spec/dummy/app/controllers/skip_unless/step_one_controller.rb +11 -0
  24. data/spec/dummy/app/controllers/skip_unless/step_three_controller.rb +11 -0
  25. data/spec/dummy/app/controllers/skip_unless/step_two_controller.rb +11 -0
  26. data/spec/dummy/app/steps/skip_if_map.rb +11 -0
  27. data/spec/dummy/app/steps/skip_unless_map.rb +11 -0
  28. data/spec/dummy/config/routes.rb +12 -0
  29. data/spec/dummy/log/development.log +0 -227
  30. data/spec/dummy/log/test.log +14941 -875
  31. data/spec/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  32. data/spec/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  33. data/spec/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  34. data/spec/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  35. data/spec/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  36. data/spec/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  37. data/spec/spec_helper.rb +0 -1
  38. metadata +78 -108
  39. data/.gitignore +0 -18
  40. data/.rspec +0 -1
  41. data/Gemfile +0 -4
  42. data/Gemfile.lock +0 -152
  43. data/Guardfile +0 -16
  44. data/LICENSE.txt +0 -22
  45. data/lib/stair_master/conditions/availability.rb +0 -13
  46. data/spec/controllers/base/getters_spec.rb +0 -9
  47. data/spec/dummy/app/assets/images/.keep +0 -0
  48. data/spec/dummy/app/mailers/.keep +0 -0
  49. data/spec/dummy/app/models/.keep +0 -0
  50. data/spec/dummy/app/models/concerns/.keep +0 -0
  51. data/spec/dummy/app/steps/available_if_map.rb +0 -13
  52. data/spec/dummy/lib/assets/.keep +0 -0
  53. data/spec/dummy/log/.keep +0 -0
  54. data/stair_master.gemspec +0 -33
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 506012055f95599b09cc8307c34f2e27d675487a
4
+ data.tar.gz: ff08113af0b7cf528e65620339a93d0cc185eb64
5
+ SHA512:
6
+ metadata.gz: 92d88d92f1be968effceec89a605880920cfbc7b13ebb7b1b6f60161868ccda46e427d1d7d0cbd786154601d9f5aac4b74ee0f541bd4173d8fd151a241b0c4fb
7
+ data.tar.gz: 6d840af01c7791e74cb6ffdcebf16b01b5447faf0168d7f8647f0d5914cd842a3ee6a11945a442191dce3664754dac66fba8f91fbe598dde7505f75ba93ed38e
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2014 Digital Opera
3
+ Copyright (c) 2014 Digital Opera LLC
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
  this software and associated documentation files (the "Software"), to deal in
data/README.md CHANGED
@@ -43,9 +43,8 @@ The named route for the path of this step.
43
43
 
44
44
  **conditions** :hash
45
45
 
46
- Define the conditions that are to be used when resolving which steps will be available, and/or should be skipped based on the current context. Available conditions are:
46
+ Define the conditions that are to be used when resolving which steps will be available, and/or should be skipped based on the current context. Available conditions are:
47
47
 
48
- - available_if/unless
49
48
  - skip_if/unless
50
49
 
51
50
  **Note** we recommend placing your maps in `app/maps` however you can place them where ever you would like.
@@ -55,9 +54,9 @@ Define the conditions that are to be used when resolving which steps will be ava
55
54
  #
56
55
  class MyProcessMap < StairMaster::WorkflowMap
57
56
  # We must override the define_map! method with our mapping rules
58
- add_step :home, "First Step", :first_step_path, available_if: :method_name
57
+ add_step :home, "First Step", :first_step_path, skip_if: :method_name
59
58
  ...
60
-
59
+
61
60
  set_order :home, ...
62
61
  end
63
62
  ```
@@ -72,7 +71,7 @@ When setting up your controllers, we would recommend setting up a base controlle
72
71
  class MyProcess::BaseController < ApplicationController
73
72
  # Include the stair master controller concern
74
73
  include StairMaster::Controller
75
-
74
+
76
75
  # Tell stair master what map to use
77
76
  stair_master_map_class MyProcessMap
78
77
  end
@@ -85,7 +84,7 @@ end
85
84
  class MyProcess::HomeController < MyProcess::BaseController
86
85
  def show
87
86
  end
88
-
87
+
89
88
  def update
90
89
  end
91
90
  end
data/Rakefile CHANGED
@@ -19,11 +19,11 @@ load 'rails/tasks/engine.rake'
19
19
 
20
20
  Bundler::GemHelper.install_tasks
21
21
 
22
+ Dir[File.join(File.dirname(__FILE__), 'lib/tasks/**/*.rake')].each {|f| load f }
23
+
22
24
  require 'rspec/core'
23
25
  require 'rspec/core/rake_task'
24
26
 
25
- Dir[File.join(File.dirname(__FILE__), 'lib/tasks/**/*.rake')].each {|f| load f }
26
-
27
27
  desc "Run all specs in spec directory (excluding plugin specs)"
28
28
  RSpec::Core::RakeTask.new(:spec => 'app:db:test:prepare')
29
29
  task :default => :spec
@@ -14,11 +14,25 @@ module StairMaster
14
14
 
15
15
  included do
16
16
  helper_method :workflow_map, :params_for_redirect
17
- before_filter :check_step_availability, only: [:show, :update]
17
+ before_filter :check_step_skippable, only: [:show, :update]
18
+
19
+ class << self
20
+ attr_reader :stair_master_workflow_map
21
+ end
18
22
  end
19
23
 
20
24
  def workflow_map
21
- @stair_master_workflow_map ||= self.class.workflow_map.new
25
+ @workflow_map ||= (
26
+ @stair_master_workflow_map ||= (
27
+ self.class.ancestors.map do |a|
28
+ a.stair_master_workflow_map if a.respond_to? :stair_master_workflow_map
29
+ end.flatten.compact.first
30
+ )
31
+
32
+ map = @stair_master_workflow_map.present? ? @stair_master_workflow_map : self.class.workflow_map
33
+
34
+ map.new
35
+ )
22
36
  end
23
37
 
24
38
  private # ---------------------------------------------
@@ -34,18 +48,14 @@ module StairMaster
34
48
  mod_params.empty? ? nil : mod_params
35
49
  end
36
50
 
37
- def check_step_availability
38
- if is_available_step?
39
- redirect_to next_step_path(params_for_redirect) if step_should_be_skipped?
40
- else
41
- redirect_to first_step_path(params_for_redirect)
42
- end
51
+ def check_step_skippable
52
+ redirect_to next_step_path(params_for_redirect) if step_should_be_skipped?
43
53
  end
44
54
 
45
55
  module ClassMethods
46
56
  def workflow_map(map_class=nil)
47
- return (@@stair_master_workflow_map || ::StairMaster::WorkflowMap) if map_class.nil?
48
- @@stair_master_workflow_map = map_class.to_s.camelize.constantize
57
+ return (@stair_master_workflow_map || ::StairMaster::WorkflowMap) if map_class.nil?
58
+ @stair_master_workflow_map = map_class.to_s.camelize.constantize
49
59
  end
50
60
  end
51
61
  end
@@ -12,12 +12,7 @@ module StairMaster
12
12
  end
13
13
 
14
14
  def available_steps
15
- @stair_master_available_steps ||= workflow_map.order.map{ |step_name| step_name if step_is_available?(step_name) }.compact
16
- end
17
-
18
- def step_is_available?(step_name)
19
- step = get_step_by_name(step_name)
20
- step.available?(self)
15
+ @stair_master_available_steps ||= workflow_map.order.map{ |step_name| step_name }.compact
21
16
  end
22
17
  end
23
18
  end
@@ -29,11 +29,6 @@ module StairMaster
29
29
  step_name == available_steps.first
30
30
  end
31
31
 
32
- def is_available_step?(step=nil)
33
- step_name = step.nil? ? controller_name.to_sym : step.key
34
- available_steps.include? step_name
35
- end
36
-
37
32
  def step_should_be_skipped?(step=nil)
38
33
  step = step.nil? ? current_step : step
39
34
  step.skip?(self)
@@ -54,7 +54,7 @@ module StairMaster
54
54
  end
55
55
 
56
56
  ## Previous Step ------------------------------------
57
- def previous_step_index(base_step_index=nil)
57
+ def previous_step_index
58
58
  @stair_master_previous_step_index ||= get_previous_step_index
59
59
  end
60
60
 
@@ -1,7 +1,6 @@
1
1
  # app/stair_master/conditions.rb
2
2
 
3
3
  require_relative "conditions/base"
4
- require_relative "conditions/availability"
5
4
  require_relative "conditions/skippable"
6
5
 
7
6
  module StairMaster
@@ -16,14 +16,6 @@ module StairMaster
16
16
 
17
17
  ## Methods ------------------------------------------
18
18
 
19
- def available?
20
- raise NotImplmenetedError
21
- end
22
-
23
- def not_available?
24
- raise NotImplmenetedError
25
- end
26
-
27
19
  def description
28
20
  raise NotImplementedError
29
21
  end
@@ -13,11 +13,6 @@ module StairMaster
13
13
 
14
14
  ## Methods --------------------------------------------
15
15
 
16
- def available?(context)
17
- rules = @conditions[:availability]
18
- ( rules.empty? ? [true] : test_rules(rules, context) ).all?
19
- end
20
-
21
16
  def skip?(context)
22
17
  rules = @conditions[:skippable]
23
18
  ( rules.empty? ? [false] : test_rules(rules, context) ).all?
@@ -47,15 +42,12 @@ module StairMaster
47
42
 
48
43
  def build_conditions(conditions)
49
44
  conditions = conditions.empty? ? {} : conditions.first
50
- availability_rules = []
51
45
  skip_rules = []
52
46
 
53
47
  conditions.each do |k,v|
54
48
  condition_type, type = k.to_s.split('_').map{ |v| v.to_sym }
55
49
 
56
- if condition_type == :available ## It is an "availability" condition
57
- availability_rules << ::StairMaster::Conditions::Availability.new(self, type, v)
58
- elsif condition_type == :skip ## It is a "skip" condition
50
+ if condition_type == :skip ## It is a "skip" condition
59
51
  skip_rules << ::StairMaster::Conditions::Skippable.new(self, type, v)
60
52
  else
61
53
  ## We don't know what this type of condition is so raise an exception
@@ -63,7 +55,7 @@ module StairMaster
63
55
  end
64
56
  end
65
57
 
66
- { availability: availability_rules, skippable: skip_rules }
58
+ { skippable: skip_rules }
67
59
  end
68
60
  end
69
61
  end
@@ -1,3 +1,3 @@
1
1
  module StairMaster
2
- VERSION = "0.0.3"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -13,28 +13,5 @@ describe 'ordering methods' do
13
13
  subject.available_steps.should eq [:step_one, :step_two, :step_three]
14
14
  end
15
15
  end
16
-
17
- describe '#step_is_available?' do
18
- it 'should return true if in list' do
19
- get :show
20
-
21
- subject.should be_step_is_available(:step_one)
22
- subject.should be_step_is_available(:step_two)
23
- subject.should be_step_is_available(:step_three)
24
- end
25
-
26
- it 'should return false if not available' do
27
- StairMaster::Step.any_instance.stubs(:available?).returns(false)
28
- get :show
29
-
30
- subject.should_not be_step_is_available(:step_one)
31
- end
32
-
33
- it 'should throw error if not apart of inital list' do
34
- get :show
35
-
36
- expect{ subject.step_is_available?(:step_four) }.to raise_error
37
- end
38
- end
39
16
  end
40
17
  end
@@ -0,0 +1,395 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'when skip_if condition is defined' do
4
+ describe '#previous_step' do
5
+ context 'when second step' do
6
+ context 'when should NOT be skipped' do
7
+ before(:all) {
8
+ @controller = SkipIf::StepTwoController.new
9
+ }
10
+
11
+ it 'should get step 1' do
12
+ SkipIf::StepTwoController.any_instance.stubs(:skip_step_two?).returns(false)
13
+ SkipIf::StepTwoController.any_instance.stubs(:skip_step_one?).returns(false)
14
+ get :show
15
+
16
+ expect(subject.previous_step.label).to eq 'Step 1'
17
+ end
18
+ end
19
+
20
+ context 'when should be skipped' do
21
+ before(:all) {
22
+ @controller = SkipIf::StepTwoController.new
23
+ }
24
+
25
+ it 'should return nil' do
26
+ SkipIf::StepTwoController.any_instance.stubs(:skip_step_two?).returns(false)
27
+ get :show
28
+
29
+ expect(subject.previous_step).to be_nil
30
+ end
31
+ end
32
+ end
33
+
34
+ context 'when third step' do
35
+ context 'when should NOT be skipped' do
36
+ before(:all) {
37
+ @controller = SkipIf::StepThreeController.new
38
+ }
39
+
40
+ it 'should get step 2' do
41
+ SkipIf::StepThreeController.any_instance.stubs(:skip_step_two?).returns(false)
42
+ SkipIf::StepThreeController.any_instance.stubs(:skip_step_three?).returns(false)
43
+ get :show
44
+
45
+ expect(subject.previous_step.label).to eq 'Step 2'
46
+ end
47
+ end
48
+
49
+ context 'when should be skipped' do
50
+ before(:all) {
51
+ @controller = SkipIf::StepThreeController.new
52
+ }
53
+
54
+ it 'should return step 1' do
55
+ SkipIf::StepThreeController.any_instance.stubs(:skip_step_one?).returns(false)
56
+ SkipIf::StepThreeController.any_instance.stubs(:skip_step_three?).returns(false)
57
+ get :show
58
+
59
+ expect(subject.previous_step.label).to eq 'Step 1'
60
+ end
61
+ end
62
+ end
63
+ end
64
+
65
+ describe '#previous_step_index' do
66
+ context 'when second step' do
67
+ context 'when should NOT be skipped' do
68
+ before(:all) {
69
+ @controller = SkipIf::StepTwoController.new
70
+ }
71
+
72
+ it 'should get step 1 index' do
73
+ SkipIf::StepTwoController.any_instance.stubs(:skip_step_two?).returns(false)
74
+ SkipIf::StepTwoController.any_instance.stubs(:skip_step_one?).returns(false)
75
+ get :show
76
+
77
+ expect(subject.previous_step_index).to eq 0
78
+ end
79
+ end
80
+
81
+ context 'when should be skipped' do
82
+ before(:all) {
83
+ @controller = SkipIf::StepTwoController.new
84
+ }
85
+
86
+ it 'should return nil' do
87
+ SkipIf::StepTwoController.any_instance.stubs(:skip_step_two?).returns(false)
88
+ get :show
89
+
90
+ expect(subject.previous_step_index).to be_nil
91
+ end
92
+ end
93
+ end
94
+
95
+ context 'when third step' do
96
+ context 'when should NOT be skipped' do
97
+ before(:all) {
98
+ @controller = SkipIf::StepThreeController.new
99
+ }
100
+
101
+ it 'should get step 2 index' do
102
+ SkipIf::StepThreeController.any_instance.stubs(:skip_step_two?).returns(false)
103
+ SkipIf::StepThreeController.any_instance.stubs(:skip_step_three?).returns(false)
104
+ get :show
105
+
106
+ expect(subject.previous_step_index).to eq 1
107
+ end
108
+ end
109
+
110
+ context 'when should be skipped' do
111
+ before(:all) {
112
+ @controller = SkipIf::StepThreeController.new
113
+ }
114
+
115
+ it 'should return step 1 index' do
116
+ SkipIf::StepThreeController.any_instance.stubs(:skip_step_one?).returns(false)
117
+ SkipIf::StepThreeController.any_instance.stubs(:skip_step_three?).returns(false)
118
+ get :show
119
+
120
+ expect(subject.previous_step_index).to eq 0
121
+ end
122
+ end
123
+ end
124
+ end
125
+
126
+ describe '#previous_step_name' do
127
+ context 'when first step' do
128
+ before(:all) {
129
+ @controller = SkipIf::StepOneController.new
130
+ }
131
+
132
+ it 'should return nil' do
133
+ SkipIf::StepOneController.any_instance.stubs(:skip_step_one?).returns(false)
134
+ get :show
135
+
136
+ expect(subject.previous_step_name).to be_nil
137
+ end
138
+ end
139
+
140
+ context 'when second step' do
141
+ context 'when should NOT be skipped' do
142
+ before(:all) {
143
+ @controller = SkipIf::StepTwoController.new
144
+ }
145
+
146
+ it 'should get step 1 name' do
147
+ SkipIf::StepTwoController.any_instance.stubs(:skip_step_two?).returns(false)
148
+ SkipIf::StepTwoController.any_instance.stubs(:skip_step_one?).returns(false)
149
+ get :show
150
+
151
+ expect(subject.previous_step_name).to eq :step_one
152
+ end
153
+ end
154
+
155
+ context 'when should be skipped' do
156
+ before(:all) {
157
+ @controller = SkipIf::StepTwoController.new
158
+ }
159
+
160
+ it 'should return nil' do
161
+ SkipIf::StepTwoController.any_instance.stubs(:skip_step_two?).returns(false)
162
+ get :show
163
+
164
+ expect(subject.previous_step_name).to be_nil
165
+ end
166
+ end
167
+ end
168
+
169
+ context 'when third step' do
170
+ context 'when should NOT be skipped' do
171
+ before(:all) {
172
+ @controller = SkipIf::StepThreeController.new
173
+ }
174
+
175
+ it 'should get step 2 name' do
176
+ SkipIf::StepThreeController.any_instance.stubs(:skip_step_two?).returns(false)
177
+ SkipIf::StepThreeController.any_instance.stubs(:skip_step_three?).returns(false)
178
+ get :show
179
+
180
+ expect(subject.previous_step_name).to eq :step_two
181
+ end
182
+ end
183
+
184
+ context 'when should be skipped' do
185
+ before(:all) {
186
+ @controller = SkipIf::StepThreeController.new
187
+ }
188
+
189
+ it 'should return step 1 name' do
190
+ SkipIf::StepThreeController.any_instance.stubs(:skip_step_one?).returns(false)
191
+ SkipIf::StepThreeController.any_instance.stubs(:skip_step_three?).returns(false)
192
+ get :show
193
+
194
+ expect(subject.previous_step_name).to eq :step_one
195
+ end
196
+ end
197
+ end
198
+ end
199
+
200
+ describe '#next_step' do
201
+ context 'when first step' do
202
+ context 'when should NOT be skipped' do
203
+ before(:all) {
204
+ @controller = SkipIf::StepOneController.new
205
+ }
206
+
207
+ it 'should return step 2' do
208
+ SkipIf::StepOneController.any_instance.stubs(:skip_step_one?).returns(false)
209
+ SkipIf::StepOneController.any_instance.stubs(:skip_step_two?).returns(false)
210
+ get :show
211
+
212
+ expect(subject.next_step.label).to eq 'Step 2'
213
+ end
214
+ end
215
+
216
+ context 'when should be skipped' do
217
+ before(:all) {
218
+ @controller = SkipIf::StepOneController.new
219
+ }
220
+
221
+ it 'should return step 3' do
222
+ SkipIf::StepOneController.any_instance.stubs(:skip_step_one?).returns(false)
223
+ SkipIf::StepOneController.any_instance.stubs(:skip_step_three?).returns(false)
224
+ get :show
225
+
226
+ expect(subject.next_step.label).to eq 'Step 3'
227
+ end
228
+ end
229
+ end
230
+
231
+ context 'when second step' do
232
+ context 'when should NOT be skipped' do
233
+ before(:all) {
234
+ @controller = SkipIf::StepTwoController.new
235
+ }
236
+
237
+ it 'should get step 3' do
238
+ SkipIf::StepTwoController.any_instance.stubs(:skip_step_two?).returns(false)
239
+ SkipIf::StepTwoController.any_instance.stubs(:skip_step_three?).returns(false)
240
+ get :show
241
+
242
+ expect(subject.next_step.label).to eq 'Step 3'
243
+ end
244
+ end
245
+
246
+ context 'when should be skipped' do
247
+ before(:all) {
248
+ @controller = SkipIf::StepTwoController.new
249
+ }
250
+
251
+ it 'should return nil' do
252
+ SkipIf::StepTwoController.any_instance.stubs(:skip_step_two?).returns(false)
253
+ get :show
254
+
255
+ expect(subject.next_step).to be_nil
256
+ end
257
+ end
258
+ end
259
+ end
260
+
261
+ describe '#next_step_index' do
262
+ context 'when first step' do
263
+ context 'when should NOT be skipped' do
264
+ before(:all) {
265
+ @controller = SkipIf::StepOneController.new
266
+ }
267
+
268
+ it 'should return step 2 index' do
269
+ SkipIf::StepOneController.any_instance.stubs(:skip_step_one?).returns(false)
270
+ SkipIf::StepOneController.any_instance.stubs(:skip_step_two?).returns(false)
271
+ get :show
272
+
273
+ expect(subject.next_step_index).to eq 1
274
+ end
275
+ end
276
+
277
+ context 'when should be skipped' do
278
+ before(:all) {
279
+ @controller = SkipIf::StepOneController.new
280
+ }
281
+
282
+ it 'should return step 3 index' do
283
+ SkipIf::StepOneController.any_instance.stubs(:skip_step_one?).returns(false)
284
+ SkipIf::StepOneController.any_instance.stubs(:skip_step_three?).returns(false)
285
+ get :show
286
+
287
+ expect(subject.next_step_index).to eq 2
288
+ end
289
+ end
290
+ end
291
+
292
+ context 'when second step' do
293
+ context 'when should NOT be skipped' do
294
+ before(:all) {
295
+ @controller = SkipIf::StepTwoController.new
296
+ }
297
+
298
+ it 'should get step 3 index' do
299
+ SkipIf::StepTwoController.any_instance.stubs(:skip_step_two?).returns(false)
300
+ SkipIf::StepTwoController.any_instance.stubs(:skip_step_three?).returns(false)
301
+ get :show
302
+
303
+ expect(subject.next_step_index).to eq 2
304
+ end
305
+ end
306
+
307
+ context 'when should be skipped' do
308
+ before(:all) {
309
+ @controller = SkipIf::StepTwoController.new
310
+ }
311
+
312
+ it 'should return nil' do
313
+ SkipIf::StepTwoController.any_instance.stubs(:skip_step_two?).returns(false)
314
+ get :show
315
+
316
+ expect(subject.next_step_index).to be_nil
317
+ end
318
+ end
319
+ end
320
+ end
321
+
322
+ describe '#next_step_name' do
323
+ context 'when first step' do
324
+ context 'when should NOT be skipped' do
325
+ before(:all) {
326
+ @controller = SkipIf::StepOneController.new
327
+ }
328
+
329
+ it 'should return step_two' do
330
+ SkipIf::StepOneController.any_instance.stubs(:skip_step_one?).returns(false)
331
+ SkipIf::StepOneController.any_instance.stubs(:skip_step_two?).returns(false)
332
+ get :show
333
+
334
+ expect(subject.next_step_name).to eq :step_two
335
+ end
336
+ end
337
+
338
+ context 'when should be skipped' do
339
+ before(:all) {
340
+ @controller = SkipIf::StepOneController.new
341
+ }
342
+
343
+ it 'should return step_three' do
344
+ SkipIf::StepOneController.any_instance.stubs(:skip_step_one?).returns(false)
345
+ SkipIf::StepOneController.any_instance.stubs(:skip_step_three?).returns(false)
346
+ get :show
347
+
348
+ expect(subject.next_step_name).to eq :step_three
349
+ end
350
+ end
351
+ end
352
+
353
+ context 'when second step' do
354
+ context 'when should NOT be skipped' do
355
+ before(:all) {
356
+ @controller = SkipIf::StepTwoController.new
357
+ }
358
+
359
+ it 'should return step_three' do
360
+ SkipIf::StepTwoController.any_instance.stubs(:skip_step_two?).returns(false)
361
+ SkipIf::StepTwoController.any_instance.stubs(:skip_step_three?).returns(false)
362
+ get :show
363
+
364
+ expect(subject.next_step_name).to eq :step_three
365
+ end
366
+ end
367
+
368
+ context 'when should be skipped' do
369
+ before(:all) {
370
+ @controller = SkipIf::StepTwoController.new
371
+ }
372
+
373
+ it 'should return nil' do
374
+ SkipIf::StepTwoController.any_instance.stubs(:skip_step_two?).returns(false)
375
+ get :show
376
+
377
+ expect(subject.next_step_name).to be_nil
378
+ end
379
+ end
380
+ end
381
+
382
+ context 'when third step' do
383
+ before(:all) {
384
+ @controller = SkipIf::StepThreeController.new
385
+ }
386
+
387
+ it 'should return nil' do
388
+ SkipIf::StepThreeController.any_instance.stubs(:skip_step_three?).returns(false)
389
+ get :show
390
+
391
+ expect(subject.next_step_name).to be_nil
392
+ end
393
+ end
394
+ end
395
+ end