From 61781d84c11c8b5e37ad7cca5c40864759150a33 Mon Sep 17 00:00:00 2001 From: Gabriel Horner Date: Tue, 15 Mar 2011 09:23:17 -0400 Subject: doc :anchor option for #match in routes --- actionpack/lib/action_dispatch/routing/mapper.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index f67708722b..64368ca28f 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -364,6 +364,13 @@ module ActionDispatch # match 'path' => 'c#a', :defaults => { :format => 'jpg' } # # See Scoping#defaults for its scope equivalent. + # + # [:anchor] + # Boolean to anchor a #match pattern. Default is true. When set to + # false, the pattern matches any request prefixed with the given path. + # + # # Matches any request starting with 'path' + # match 'path' => 'c#a', :anchor => false def match(path, options=nil) mapping = Mapping.new(@set, @scope, path, options || {}).to_route @set.add_route(*mapping) -- cgit v1.2.3 From 2ddfdba9a0dab7d8499c3ad0d13583bddbac4f69 Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Tue, 22 Mar 2011 22:19:31 +0700 Subject: Do not show optional (.:format) block for wildcard route [#6605 state:resolved] This will make the output of `rake routes` to be correctly match to the behavior of the application, as the regular expression used to match the path is greedy and won't capture the format part by default --- actionpack/lib/action_dispatch/routing/mapper.rb | 2 +- actionpack/test/action_dispatch/routing/mapper_test.rb | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index cc6b8aa82d..1dba1d416c 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -107,7 +107,7 @@ module ActionDispatch if @options[:format] == false @options.delete(:format) path - elsif path.include?(":format") || path.end_with?('/') + elsif path.include?(":format") || path.end_with?('/') || path.match(/^\/?\*/) path else "#{path}(.:format)" diff --git a/actionpack/test/action_dispatch/routing/mapper_test.rb b/actionpack/test/action_dispatch/routing/mapper_test.rb index 9966234f1b..e21b271907 100644 --- a/actionpack/test/action_dispatch/routing/mapper_test.rb +++ b/actionpack/test/action_dispatch/routing/mapper_test.rb @@ -46,6 +46,13 @@ module ActionDispatch mapper.match '/one/two/', :to => 'posts#index', :as => :main assert_equal '/one/two(.:format)', fakeset.conditions.first[:path_info] end + + def test_map_wildcard + fakeset = FakeSet.new + mapper = Mapper.new fakeset + mapper.match '/*path', :to => 'pages#show', :as => :page + assert_equal '/*path', fakeset.conditions.first[:path_info] + end end end end -- cgit v1.2.3 From 5da9a74bd35284cf5124793c1f7558e506b52592 Mon Sep 17 00:00:00 2001 From: Manfred Stienstra Date: Fri, 25 Feb 2011 12:34:46 +0100 Subject: Add a failing test case for an implicit action with a before filter. Signed-off-by: Andrew White --- actionpack/test/controller/filters_test.rb | 22 ++++++++++++++++++++++ .../filter_test/implicit_actions/edit.html.erb | 1 + .../filter_test/implicit_actions/show.html.erb | 1 + 3 files changed, 24 insertions(+) create mode 100644 actionpack/test/fixtures/filter_test/implicit_actions/edit.html.erb create mode 100644 actionpack/test/fixtures/filter_test/implicit_actions/show.html.erb (limited to 'actionpack') diff --git a/actionpack/test/controller/filters_test.rb b/actionpack/test/controller/filters_test.rb index 330fa276d0..c95332220b 100644 --- a/actionpack/test/controller/filters_test.rb +++ b/actionpack/test/controller/filters_test.rb @@ -505,6 +505,16 @@ class FilterTest < ActionController::TestCase end end + class ImplicitActionsController < ActionController::Base + before_filter :find_user, :only => :edit + + private + + def find_user + @user = 'Jenny' + end + end + def test_sweeper_should_not_block_rendering response = test_process(SweeperTestController) assert_equal 'hello world', response.body @@ -783,6 +793,18 @@ class FilterTest < ActionController::TestCase assert_equal("I rescued this: #", response.body) end + def test_filter_runs_for_implicitly_defined_action_when_needed + test_process(ImplicitActionsController, 'edit') + assert_equal 'Jenny', assigns(:user) + assert_equal 'edit', response.body + end + + def test_filter_does_not_run_for_implicity_defined_action_when_not_needed + test_process(ImplicitActionsController, 'show') + assert_nil assigns(:user) + assert_equal 'show', response.body + end + private def test_process(controller, action = "show") @controller = controller.is_a?(Class) ? controller.new : controller diff --git a/actionpack/test/fixtures/filter_test/implicit_actions/edit.html.erb b/actionpack/test/fixtures/filter_test/implicit_actions/edit.html.erb new file mode 100644 index 0000000000..8491ab9f80 --- /dev/null +++ b/actionpack/test/fixtures/filter_test/implicit_actions/edit.html.erb @@ -0,0 +1 @@ +edit \ No newline at end of file diff --git a/actionpack/test/fixtures/filter_test/implicit_actions/show.html.erb b/actionpack/test/fixtures/filter_test/implicit_actions/show.html.erb new file mode 100644 index 0000000000..0a89cecf05 --- /dev/null +++ b/actionpack/test/fixtures/filter_test/implicit_actions/show.html.erb @@ -0,0 +1 @@ +show \ No newline at end of file -- cgit v1.2.3 From 9772de8d459960cc114c5b214343b7ce08fea21c Mon Sep 17 00:00:00 2001 From: Andrew White Date: Wed, 23 Mar 2011 23:09:00 +0000 Subject: Fix filter :only and :except with implicit actions The method_name argument is "default_render" for implicit actions so use the action_name attribute to determine which callbacks to run. [#5673 state:resolved] --- actionpack/lib/abstract_controller/callbacks.rb | 2 +- actionpack/test/controller/filters_test.rb | 27 +++++++++++++++---------- 2 files changed, 17 insertions(+), 12 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/abstract_controller/callbacks.rb b/actionpack/lib/abstract_controller/callbacks.rb index 95992c2698..1943ca4436 100644 --- a/actionpack/lib/abstract_controller/callbacks.rb +++ b/actionpack/lib/abstract_controller/callbacks.rb @@ -14,7 +14,7 @@ module AbstractController # Override AbstractController::Base's process_action to run the # process_action callbacks around the normal behavior. def process_action(method_name, *args) - run_callbacks(:process_action, method_name) do + run_callbacks(:process_action, action_name) do super end end diff --git a/actionpack/test/controller/filters_test.rb b/actionpack/test/controller/filters_test.rb index c95332220b..9e44e8e088 100644 --- a/actionpack/test/controller/filters_test.rb +++ b/actionpack/test/controller/filters_test.rb @@ -506,12 +506,17 @@ class FilterTest < ActionController::TestCase end class ImplicitActionsController < ActionController::Base - before_filter :find_user, :only => :edit + before_filter :find_only, :only => :edit + before_filter :find_except, :except => :edit private - def find_user - @user = 'Jenny' + def find_only + @only = 'Only' + end + + def find_except + @except = 'Except' end end @@ -793,16 +798,16 @@ class FilterTest < ActionController::TestCase assert_equal("I rescued this: #", response.body) end - def test_filter_runs_for_implicitly_defined_action_when_needed - test_process(ImplicitActionsController, 'edit') - assert_equal 'Jenny', assigns(:user) - assert_equal 'edit', response.body - end - - def test_filter_does_not_run_for_implicity_defined_action_when_not_needed + def test_filters_obey_only_and_except_for_implicit_actions test_process(ImplicitActionsController, 'show') - assert_nil assigns(:user) + assert_equal 'Except', assigns(:except) + assert_nil assigns(:only) assert_equal 'show', response.body + + test_process(ImplicitActionsController, 'edit') + assert_equal 'Only', assigns(:only) + assert_nil assigns(:except) + assert_equal 'edit', response.body end private -- cgit v1.2.3