Skip to content

Instantly share code, notes, and snippets.

@tgxworld
Last active August 29, 2015 14:06
Show Gist options
  • Save tgxworld/de167eb9cefa3d73f660 to your computer and use it in GitHub Desktop.
Save tgxworld/de167eb9cefa3d73f660 to your computer and use it in GitHub Desktop.
Bound Parameters
require 'abstract_unit'
class SomethingController < ApplicationController
def index
render plain: 'ok'
end
end
class SomethingTest < ActionDispatch::IntegrationTest
class SomeController < ApplicationController
def index
render plain: 'ok'
end
end
def test_non_nested_controller
# Both cases work as expected
with_routing do |set|
set.draw do
get ':controller(/:action(/:id))'
end
assert_equal '/something', @routes.path_for({controller: 'something', action: :index})
get '/something'
assert_equal 'ok', response.body
get '/something/index'
assert_equal 'ok', response.body
end
end
def test_nested_controller
with_routing do |set|
set.draw do
get ':controller(/:action)' # test wont pass for '/something_test/some/index' unless this has been added
get ':controller(/:action(/:id))'
end
assert_equal '/something_test/some', @routes.path_for({controller: 'something_test/some', action: :index})
get '/something_test/some/index', nil, { 'action_dispatch.show_exceptions' => false }
assert_equal 'ok', response.body
# This will fail unless the index action is specified in the url.
get '/something_test/some', nil, { 'action_dispatch.show_exceptions' => false }
assert_equal 'ok', response.body
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment