Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

added route helper #32

Closed
wants to merge 2 commits into from

3 participants

@ssendev

I have added a route helper similar to the one from wizardry[https://github.com/lexmag/wizardry] which allows using the edit action and a step variable other than id.

wicked_resource :after_signup is all thats needed to enable it further details on how to use it are in the readme.

Manuel

@travisbot

This pull request fails (merged 3b72d61 into 99bf674).

@ssendev

In the current iteration I stored the parameters in the Controller they belong to. But in development mode they may be reloaded which causes them to lose that information, and since it is stored in routes.rb it won't reload. My first thought was to store it in the Routes class but unfortunately it does not exist. Storing it in Wicked would work assuming it's an external gem and wont be reloaded. Redrawing the routes if no config is found would also work.

@ssendev ssendev moved routes_config into Wicked::Wizard
previously it was stored in the controller which upon reload lost its configuration
e8df825
@schneems
Owner

Sorry for the delayed response, github is not sending me emails on repos i own. This is a ton of code for a feature i'm not really sure is needed. :-1: on idea :-1: on implementation. Adding additional DSL for what you can already do in rails in the same number of lines of code is a bit of an antipattern. Thanks for hacking on the project though. If you have ideas you're thinking of implementing in the future you can ping me on twitter with a gist, and i'll be happy to field ideas before you write the implementation.

@schneems schneems closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 26, 2012
  1. @ssendev

    added route helper

    ssendev authored
Commits on Sep 15, 2012
  1. @ssendev

    moved routes_config into Wicked::Wizard

    ssendev authored
    previously it was stored in the controller which upon reload lost its configuration
This page is out of date. Refresh to see the latest.
Showing with 491 additions and 6 deletions.
  1. +24 −0 README.md
  2. +3 −1 lib/wicked.rb
  3. +7 −2 lib/wicked/controller/concerns/path.rb
  4. +2 −0  lib/wicked/controller/concerns/steps.rb
  5. +71 −0 lib/wicked/routes.rb
  6. +8 −3 lib/wicked/wizard.rb
  7. +14 −0 test/dummy/app/controllers/bar2_controller.rb
  8. +13 −0 test/dummy/app/controllers/foo2_controller.rb
  9. +22 −0 test/dummy/app/controllers/jump2_controller.rb
  10. +6 −0 test/dummy/app/controllers/routes_controller.rb
  11. +13 −0 test/dummy/app/controllers/steps2_controller.rb
  12. +5 −0 test/dummy/app/views/bar2/first.html.erb
  13. +3 −0  test/dummy/app/views/bar2/last_step.html.erb
  14. +3 −0  test/dummy/app/views/bar2/second.html.erb
  15. +1 −0  test/dummy/app/views/foo2/first.html.erb
  16. +1 −0  test/dummy/app/views/foo2/last_step.html.erb
  17. +1 −0  test/dummy/app/views/foo2/second.html.erb
  18. +1 −0  test/dummy/app/views/jump2/first.html.erb
  19. +1 −0  test/dummy/app/views/jump2/last_step.html.erb
  20. +1 −0  test/dummy/app/views/jump2/second.html.erb
  21. +9 −0 test/dummy/app/views/step_positions2/_step_position.html.erb
  22. +1 −0  test/dummy/app/views/step_positions2/first.html.erb
  23. +1 −0  test/dummy/app/views/step_positions2/last_step.html.erb
  24. +1 −0  test/dummy/app/views/step_positions2/second.html.erb
  25. +8 −0 test/dummy/config/routes.rb
  26. +15 −0 test/integration/jump_test.rb
  27. +77 −0 test/integration/navigation_test.rb
  28. +154 −0 test/integration/routes_test.rb
  29. +25 −0 test/integration/steps_test.rb
View
24 README.md
@@ -85,6 +85,30 @@ The wizard is set to call steps in order in the show action, you can specify cus
**Note:** Wicked uses the `:id` parameter to control the flow of steps, if you need to have an id parameter, please use nested routes see [building objects with wicked](https://github.com/schneems/wicked/wiki/Partial-Validation-of-Active-Record-Objects) for an example. It will need to be prefixed, for example a Product's `:id` would be `:product_id`
+### Routing helpers
+
+The routing helper which was loaned from Wizardry(https://raw.github.com/lexmag/wizardry) allows for nicer routes
+
+```ruby
+resource :after_signup do
+ is_wicked
+end
+# same as
+wicked_resource :after_signup
+# or
+wicked_resources :products
+```
+
+will replace default `*:id/edit*` path with `*:id/edit/:step*` and update with `*:id/:step*`.
+`is_wicked` and wicked_resource also accepts a hash to further configure the behavior
+
+* `:step_constraint => /first/second/` Set to true to generate a regexp which allows only the steps which are assigned in the controller or pass a regexp.
+* `:step_optional => true` The route will be `*:id/edit(/:step)*` but be carefull not to shadow other routes.
+* `:step_parameter => :pets` Defaults to :step can but can be changed set to :id for backwards compatibility with the old routes.
+* `:show_step_action => :show` the action used to display the steps, defaults to :edit but can be set back to :show.
+wicked_resource(s) or the parent resource from is_wicked can take:
+* `:path_names => { :edit => 'amend' }` Changes the route to `*:id/amend/:step*` can be set to nil for `*:id/:step*`. `:update` will be set to the same as `:edit` if not specified. Use update_wizard_path in the form url if update path is not the same as edit path.
+
You'll need to call `render_wizard` at the end of your action to get the correct views to show up.
By default the wizard will render a view with the same name as the step. So for our controller `AfterSignupController` with a view path of `/views/after_signup/` if call the :confirm_password step, our wizard will render `/views/after_signup/confirm_password.html.erb`
View
4 lib/wicked.rb
@@ -1,3 +1,4 @@
+
module Wicked
module Controller
module Concerns
@@ -11,4 +12,5 @@ module Wizard
require 'wicked/controller/concerns/steps'
require 'wicked/controller/concerns/path'
require 'wicked/wizard'
-require 'wicked/engine'
+require 'wicked/engine'
+require 'wicked/routes'
View
9 lib/wicked/controller/concerns/path.rb
@@ -21,10 +21,15 @@ def wicked_action
def wizard_path(goto_step = nil, options = {})
options = { :controller => wicked_controller,
- :action => 'show',
- :id => goto_step || params[:id],
+ :action => @step_action,
+ @step_parameter.to_sym => goto_step || params[@step_parameter],
:only_path => true
}.merge options
url_for(options)
end
+
+ def update_wizard_path(goto_step = nil, options = {})
+ wizard_path(goto_step, { :action => :update }.merge(options))
+ end
+
end
View
2  lib/wicked/controller/concerns/steps.rb
@@ -47,6 +47,8 @@ module ClassMethods
def steps(*args)
options = args.extract_options!
steps = args
+ class_attribute :wicked_steps, instance_writer: false
+ self.wicked_steps = steps
prepend_before_filter(options) do
self.steps = steps
end
View
71 lib/wicked/routes.rb
@@ -0,0 +1,71 @@
+# inspired by https://github.com/lexmag/wizardry/blob/master/lib/wizardry/routes.rb
+
+class ActionDispatch::Routing::Mapper
+ def is_wicked(opts = {})
+ unless resource_scope?
+ raise ArgumentError, "can't use is_wicked outside resource(s) scope"
+ end
+
+ draw = { :update => true, :edit => true }
+
+ options = @scope[:scope_level_resource].options
+
+ except = Array.wrap(options.delete(:except)).map(&:to_sym)
+ only = Array.wrap(options.delete(:only)).map(&:to_sym)
+
+ only_was_present = only.present?
+ if only_was_present = only.present?
+ only.each { |action| except.delete(action) if except.include?(action) } # discard contradicting options
+ draw.each { |k,v| draw[k] = only.delete(k) == k }
+ end
+ draw.each { |k,v| draw[k] = v && ! except.include?(k) } if except.present?
+
+ options.merge!(only: only) if only_was_present
+ except += draw.keys
+ options.merge!(except: except.uniq)
+
+ controller = @scope[:controller].to_s.dup.concat('_controller').classify.constantize rescue nil
+ controller = @scope[:controller].to_s.singularize.concat('_controller').classify.constantize unless controller.present?
+
+ step_parameter = opts.delete(:step_parameter).try(:to_s) || 'step'
+ step_action = opts.delete(:show_step_action).try(:to_s) || 'edit'
+ routes_config = {}
+ routes_config = Wicked::Wizard.class_variable_get :@@routes_config if Wicked::Wizard.class_variable_defined? :@@routes_config
+ routes_config.merge!({ controller.name => { :step_parameter => step_parameter, :step_action => step_action }})
+ Wicked::Wizard.class_variable_set :@@routes_config, routes_config
+
+ path_name = 'edit'
+ path_name = @scope[:path_names][:edit] if @scope[:path_names].key? :edit
+ update_path_name = path_name
+ update_path_name = @scope[:path_names][:update] if @scope[:path_names].key? :update
+ step = opts.delete(:step_optional) ? "(/:#{step_parameter})" : "/:#{step_parameter}"
+ step = step.sub(/\//, '') unless path_name
+ edit_params = {"#{path_name}#{step}" => step_action.to_sym, as: step_action.to_sym, on: :member}
+ update_params = {"#{update_path_name}#{step}" => :update, as: :update, on: :member}
+
+ step_constraint = opts.delete(:step_constraint)
+ step_constraint = Regexp.new controller.wicked_steps.join('|') if step_constraint == true
+ if step_constraint
+ edit_params.merge! step_parameter.to_sym => step_constraint
+ update_params.merge! step_parameter.to_sym => step_constraint
+ end
+
+ get edit_params if draw[:edit]
+ put update_params if draw[:update]
+
+ end
+
+ [:resources, :resource].each do |method|
+ class_eval <<-EOT, __FILE__, __LINE__ + 1
+ def wicked_#{method}(*res) # def wicked_resources(*res)
+ wicked_options = res.extract_options! # wicked_options = res.extract_options!
+ options = wicked_options.slice! :step_constraint, :step_optional, :step_parameter, :show_step_action # options = wicked_options.slice! :step_constraint, :step_optional, :step_parameter, :show_step_action
+ res.push options if options.present? # res.push options if options.present?
+ #{method} *res do # resources *res do
+ is_wicked wicked_options # is_wicked wicked_options
+ yield if block_given? # yield if block_given?
+ end # end
+ end # end
+ EOT
+ end
+end
View
11 lib/wicked/wizard.rb
@@ -23,10 +23,15 @@ def index
private
def setup_wizard
- redirect_to wizard_path(steps.first) if params[:id].try(:to_sym) == :wizard_first
- redirect_to wizard_path(steps.last) if params[:id].try(:to_sym) == :wizard_last
+ routes_config = Wicked::Wizard.class_variable_get :@@routes_config if Wicked::Wizard.class_variable_defined? :@@routes_config
+ routes_config = routes_config && routes_config[self.class.name] || {}
+ @step_parameter = routes_config[:step_parameter] || :id
+ @step_action = routes_config[:step_action] || 'show'
- @step = params[:id].try(:to_sym) || steps.first
+ redirect_to wizard_path(steps.first) if params[@step_parameter].try(:to_sym) == :wizard_first
+ redirect_to wizard_path(steps.last) if params[@step_parameter].try(:to_sym) == :wizard_last
+
+ @step = params[@step_parameter].try(:to_sym) || steps.first
@previous_step = previous_step(@step)
@next_step = next_step(@step)
end
View
14 test/dummy/app/controllers/bar2_controller.rb
@@ -0,0 +1,14 @@
+## This controller uses includes
+
+class Bar2Controller < ApplicationController
+ include Wicked::Wizard
+ steps :first, :second, :last_step
+
+ def edit
+ skip_step if params[:skip_step]
+ render_wizard
+ end
+
+ def update
+ end
+end
View
13 test/dummy/app/controllers/foo2_controller.rb
@@ -0,0 +1,13 @@
+## This controller uses inheritance
+
+class Foo2Controller < Wicked::WizardController
+ steps :first, :second, :last_step
+
+ def edit
+ skip_step if params[:skip_step]
+ render_wizard
+ end
+
+ def update
+ end
+end
View
22 test/dummy/app/controllers/jump2_controller.rb
@@ -0,0 +1,22 @@
+## This controller uses includes
+
+class Jump2Controller < ApplicationController
+ include Wicked::Wizard
+ steps :first, :second, :last_step
+
+ def edit
+ skip_step if params[:skip_step]
+ jump_to :last_step if params[:jump_to]
+ if params[:resource]
+ value = params[:resource][:save] == 'true'
+ @bar = Bar.new(value)
+ render_wizard(@bar)
+ else
+ render_wizard
+ end
+ end
+
+ def update
+ end
+
+end
View
6 test/dummy/app/controllers/routes_controller.rb
@@ -0,0 +1,6 @@
+## This controller uses includes
+
+class ProductsController < ApplicationController
+ include Wicked::Wizard
+ steps :first, :second, :last_step
+end
View
13 test/dummy/app/controllers/steps2_controller.rb
@@ -0,0 +1,13 @@
+## This controller uses includes
+
+class StepPositions2Controller < ApplicationController
+ include Wicked::Wizard
+ steps :first, :second, :last_step
+
+ def edit
+ render_wizard
+ end
+
+ def update
+ end
+end
View
5 test/dummy/app/views/bar2/first.html.erb
@@ -0,0 +1,5 @@
+first
+
+<%= link_to 'last', wizard_path(:last_step) %>
+<%= link_to 'current', wizard_path %>
+<%= link_to 'skip', next_wizard_path %>
View
3  test/dummy/app/views/bar2/last_step.html.erb
@@ -0,0 +1,3 @@
+last_step
+
+<%= "step #{wizard_steps.index(step) + 1 } of #{wizard_steps.count}" %>
View
3  test/dummy/app/views/bar2/second.html.erb
@@ -0,0 +1,3 @@
+second
+
+<%= link_to 'previous', previous_wizard_path %>
View
1  test/dummy/app/views/foo2/first.html.erb
@@ -0,0 +1 @@
+first
View
1  test/dummy/app/views/foo2/last_step.html.erb
@@ -0,0 +1 @@
+last_step
View
1  test/dummy/app/views/foo2/second.html.erb
@@ -0,0 +1 @@
+second
View
1  test/dummy/app/views/jump2/first.html.erb
@@ -0,0 +1 @@
+first
View
1  test/dummy/app/views/jump2/last_step.html.erb
@@ -0,0 +1 @@
+last_step
View
1  test/dummy/app/views/jump2/second.html.erb
@@ -0,0 +1 @@
+second
View
9 test/dummy/app/views/step_positions2/_step_position.html.erb
@@ -0,0 +1,9 @@
+<% wizard_steps.each do |s| %>
+ <p>
+ <%= "#{s} step is the current step" if current_step?(s) %><br />
+ <%= "#{s} step is a past step" if past_step?(s) %><br />
+ <%= "#{s} step is a future step" if future_step?(s) %><br />
+ <%= "#{s} step was the previous step" if previous_step?(s) %><br />
+ <%= "#{s} step is the next step" if next_step?(s) %><br />
+ </p>
+<% end %>
View
1  test/dummy/app/views/step_positions2/first.html.erb
@@ -0,0 +1 @@
+<%= render 'step_position' %>
View
1  test/dummy/app/views/step_positions2/last_step.html.erb
@@ -0,0 +1 @@
+<%= render 'step_position' %>
View
1  test/dummy/app/views/step_positions2/second.html.erb
@@ -0,0 +1 @@
+<%= render 'step_position' %>
View
8 test/dummy/config/routes.rb
@@ -1,8 +1,16 @@
Dummy::Application.routes.draw do
resources :foo
+ wicked_resource :foo2, controller: :foo2
resources :bar
+ wicked_resource :bar2, controller: :bar2
resources :jump
+ wicked_resource :jump2, controller: :jump2
resources :step_positions
+ wicked_resource :step_positions2, controller: :step_positions2
+ resources :products, except: :destroy, path_names: { new: :make } do
+ get :commit, on: :collection
+ is_wicked step_constraint: true
+ end
# The priority is based upon order of creation:
# first created -> highest priority.
View
15 test/integration/jump_test.rb
@@ -13,4 +13,19 @@ class JumpNavigationTest < ActiveSupport::IntegrationCase
assert has_content?('first')
assert !has_content?('last_step')
end
+end
+
+class JumpNavigationEditTest < ActiveSupport::IntegrationCase
+ test 'consider jump_to when calling render_wizard with resource' do
+ step = :first
+ visit(edit_jump2_path(nil, step: step, :resource => {:save => true}, :jump_to => :last_step))
+ assert has_content?('last_step')
+ end
+
+ test 'disregard jump_to when saving the resource fails' do
+ step = :first
+ visit(edit_jump2_path(nil, step: step, :resource => {:save => false}, :jump_to => :last_step))
+ assert has_content?('first')
+ assert !has_content?('last_step')
+ end
end
View
77 test/integration/navigation_test.rb
@@ -40,6 +40,39 @@ class InheritNavigationTest < ActiveSupport::IntegrationCase
end
+class InheritNavigationEditTest < ActiveSupport::IntegrationCase
+ test 'edit first' do
+ step = :first
+ visit(edit_foo2_path(nil, step: step))
+ assert has_content?(step.to_s)
+ end
+
+ test 'edit second' do
+ step = :second
+ visit(edit_foo2_path(nil, step: step))
+ assert has_content?(step.to_s)
+ end
+
+ test 'skip first edit' do
+ step = :first
+ visit(edit_foo2_path(nil, skip_step: 'true', step: step))
+ assert has_content?('second')
+ end
+
+ test 'invalid edit step' do
+ step = :notastep
+ assert_raise(ActionView::MissingTemplate) do
+ visit(edit_foo2_path(nil, step: step))
+ end
+ end
+
+ test 'finish edit' do
+ step = :finish
+ visit(edit_foo2_path(nil, step: step))
+ assert has_content?('home')
+ end
+
+end
class IncludeNavigationTest < ActiveSupport::IntegrationCase
@@ -83,6 +116,50 @@ class IncludeNavigationTest < ActiveSupport::IntegrationCase
visit(bar_path(step))
assert has_content?('home')
end
+
end
+class IncludeNavigationEditTest < ActiveSupport::IntegrationCase
+ test 'edit first' do
+ step = :first
+ visit(edit_bar2_path(step))
+ assert has_content?(step.to_s)
+ end
+
+ test 'edit second' do
+ step = :second
+ visit(edit_bar2_path(step))
+ assert has_content?(step.to_s)
+ end
+
+ test 'skip first edit' do
+ step = :first
+ visit(edit_bar2_path(step, :skip_step => 'true'))
+ assert has_content?(:second.to_s)
+ end
+
+ test 'pointer to first edit' do
+ visit(edit_bar2_path(:wizard_first))
+ assert has_content?('first')
+ end
+
+ test 'pointer to last edit' do
+ visit(edit_bar2_path(:wizard_last))
+ assert has_content?('last_step')
+ end
+
+ test 'invalid edit step' do
+ step = :notastep
+ assert_raise(ActionView::MissingTemplate) do
+ visit(edit_bar2_path(step))
+ end
+ end
+
+ test 'finish edit' do
+ step = :finish
+ visit(edit_bar2_path(step))
+ assert has_content?('home')
+ end
+
+end
View
154 test/integration/routes_test.rb
@@ -0,0 +1,154 @@
+# mostly from https://github.com/lexmag/wizardry/blob/master/spec/wizardry/routes_spec.rb
+
+require 'test_helper'
+
+class RouteHelperTest < ActionController::TestCase
+
+ include Rails.application.routes.url_helpers
+
+
+ test 'must accept wizard `edit` routes' do
+ assert_recognizes({ controller: 'products', action: 'edit', id: '1', step: 'first'}, '/products/1/edit/first')
+ assert_recognizes({ controller: 'products', action: 'edit', id: '1', step: 'second'}, '/products/1/edit/second')
+ assert_recognizes({ controller: 'products', action: 'edit', id: '1', step: 'last_step'}, '/products/1/edit/last_step')
+ assert '/products/1/first', edit_product_path(id: 1, step: 'first')
+ end
+
+ test 'must accept only valid steps' do
+ assert_raises ActionController::RoutingError do
+ assert_recognizes({ controller: 'products', action: 'edit', id: '1', step: 'fictional'}, '/products/1/edit/fictional')
+ end
+ end
+
+ test 'must not accept default `edit` route' do
+ assert_raises ActionController::RoutingError do
+ assert_recognizes({ controller: 'products', action: 'edit', id: '1'}, '/products/1/edit')
+ end
+ end
+
+ test 'must not accept `destroy` route' do
+ assert_raises ActionController::RoutingError do
+ assert_recognizes({ controller: 'products', action: 'destroy', id: '1'}, { path: '/products/1', method: :delete })
+ end
+ end
+
+ test 'must accept routes defined in block' do
+ assert_recognizes({ controller: 'products', action: 'commit' }, '/products/commit')
+ assert '/products/commit', commit_products_path
+ end
+
+ test 'must have overriden `new` path name' do
+ assert_recognizes({ controller: 'products', action: 'new' }, '/products/make')
+ assert '/products/make', new_product_path
+ end
+
+ test 'must have `wicked_resources` helper' do
+ with_routing do |set|
+ set.draw{ wicked_resources :products }
+
+ assert_recognizes({ controller: 'products', action: 'edit', id: '1', step: 'initial'}, '/products/1/edit/initial')
+ end
+ end
+
+ test 'must have `wicked_resource` helper' do
+ with_routing do |set|
+ set.draw{ wicked_resource :products }
+
+ assert_recognizes({ controller: 'products', action: 'edit', step: 'initial'}, '/products/edit/initial')
+ end
+ end
+
+ test 'must not let to use `is_wicked` outside resource(s) scope' do
+ with_routing do |set|
+ assert_raises ArgumentError do
+ set.draw{ is_wicked }
+ end
+ end
+ end
+
+ test 'must not accept default `edit` route with `only` option' do
+ with_routing do |set|
+ set.draw{ wicked_resources :products, only: [:edit, :update] }
+
+ assert_raises ActionController::RoutingError do
+ assert_recognizes({ controller: 'products', action: 'edit', id: '1'}, '/products/1/edit')
+ end
+ end
+ end
+
+ test 'must have only wicked routes' do
+ with_routing do |set|
+ set.draw{ wicked_resource :products, only: [:edit, :update] }
+
+ assert_recognizes({ controller: 'products', action: 'edit', step: 'first'}, '/products/edit/first')
+ assert_recognizes({ controller: 'products', action: 'update', step: 'initial'}, { path: '/products/edit/initial', method: :put })
+ assert_equal 2, set.routes.count
+ end
+ end
+
+ test 'must not have edit, update routes' do
+ with_routing do |set|
+ set.draw{ wicked_resource :products, except: [:edit, :update], }
+
+ assert_raises ActionController::RoutingError do
+ assert_recognizes({ controller: 'products', action: 'edit', step: 'first'}, '/products/edit/first')
+ end
+ assert_raises ActionController::RoutingError do
+ assert_recognizes({ controller: 'products', action: 'edit'}, '/products/edit')
+ end
+ assert_raises ActionController::RoutingError do
+ assert_recognizes({ controller: 'products', action: 'update', step: 'first'}, { path: '/products/edit/first', method: :put })
+ end
+ assert_raises ActionController::RoutingError do
+ assert_recognizes({ controller: 'products', action: 'update', step: 'first'}, { path: '/products/first', method: :put })
+ end
+ assert_raises ActionController::RoutingError do
+ assert_recognizes({ controller: 'products', action: 'update'}, { path: '/products', method: :put })
+ end
+ assert_equal 4, set.routes.count
+ end
+ end
+
+ test 'must only have update route' do
+ with_routing do |set|
+ set.draw{ wicked_resource :products, except: [:edit, :update], only: :update }
+
+ assert_recognizes({ controller: 'products', action: 'update', step: 'first'}, { path: '/products/edit/first', method: :put })
+ assert_equal 1, set.routes.count
+ end
+ end
+
+ test 'must only have edit route' do
+ with_routing do |set|
+ set.draw{ wicked_resource :products, only: :edit }
+
+ assert_recognizes({ controller: 'products', action: 'edit', step: 'first'}, '/products/edit/first')
+ assert_equal 1, set.routes.count
+ end
+ end
+
+ test 'must rename edit route' do
+ with_routing do |set|
+ set.draw{ wicked_resource :products, path_names: { edit: :amend } }
+
+ assert_recognizes({ controller: 'products', action: 'edit', step: 'first'}, '/products/amend/first')
+ end
+ end
+
+ test 'must change edit route to omit /edit' do
+ with_routing do |set|
+ set.draw{ wicked_resource :products, path_names: { edit: nil } }
+
+ assert_recognizes({ controller: 'products', action: 'edit', step: 'first'}, '/products/first')
+ end
+ end
+
+ test 'step must be optional' do
+ with_routing do |set|
+ set.draw{ wicked_resource :products, step_optional: true }
+ assert_recognizes({ controller: 'products', action: 'edit', step: 'first'}, '/products/edit/first')
+ assert_recognizes({ controller: 'products', action: 'edit'}, '/products/edit')
+ end
+ end
+
+end
View
25 test/integration/steps_test.rb
@@ -25,6 +25,31 @@ class StepPositionsTest < ActiveSupport::IntegrationCase
end
+class StepPositionsEditTest < ActiveSupport::IntegrationCase
+
+ test 'on first' do
+ step = :first
+ visit(edit_step_positions2_path(step))
+ assert has_content?('first step is the current step') # current_step?
+ assert true # past_step?
+ assert has_content?('last_step step is a future step') # future_step?
+ assert has_content?('second step is a future step') # future_step?
+ assert true # previous_step?
+ assert has_content?('second step is the next step') # next_step?
+ end
+
+ test 'on second' do
+ step = :second
+ visit(edit_step_positions2_path(step))
+ assert has_content?('second step is the current step') # current_step?
+ assert has_content?('first step is a past step') # past_step?
+ assert has_content?('last_step step is a future step') # future_step?
+ assert has_content?('first step was the previous step') # previous_step?
+ assert has_content?('last_step step is the next step') # next_step?
+ end
+
+end
+
# current_step?
# past_step?
# future_step?
Something went wrong with that request. Please try again.