diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index a9c5796118..ca5b153552 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,3 +1,8 @@ +*SVN* + +* Added the possibility of passing nil to UrlHelper#link_to to use the link itself as the name + + *1.2.0* (January 4th, 2005) * Added MemCacheStore for storing session data in Danga's MemCache system [Bob Cottrell] diff --git a/actionpack/lib/action_controller/filters.rb b/actionpack/lib/action_controller/filters.rb index bd5c545dfb..1691f031f8 100644 --- a/actionpack/lib/action_controller/filters.rb +++ b/actionpack/lib/action_controller/filters.rb @@ -130,15 +130,15 @@ module ActionController #:nodoc: # The passed filters will be appended to the array of filters that's run _before_ actions # on this controller are performed. def append_before_filter(*filters, &block) - filters << block if block_given? - append_filter_to_chain("before", filters) + filters << block if block_given? + append_filter_to_chain("before", filters) end # The passed filters will be prepended to the array of filters that's run _before_ actions # on this controller are performed. def prepend_before_filter(*filters, &block) - filters << block if block_given? - prepend_filter_to_chain("before", filters) + filters << block if block_given? + prepend_filter_to_chain("before", filters) end # Short-hand for append_before_filter since that's the most common of the two. @@ -147,15 +147,15 @@ module ActionController #:nodoc: # The passed filters will be appended to the array of filters that's run _after_ actions # on this controller are performed. def append_after_filter(*filters, &block) - filters << block if block_given? - append_filter_to_chain("after", filters) + filters << block if block_given? + append_filter_to_chain("after", filters) end # The passed filters will be prepended to the array of filters that's run _after_ actions # on this controller are performed. def prepend_after_filter(*filters, &block) - filters << block if block_given? - prepend_filter_to_chain("after", filters) + filters << block if block_given? + prepend_filter_to_chain("after", filters) end # Short-hand for append_after_filter since that's the most common of the two. diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb index 098fce8100..0113c42eb7 100644 --- a/actionpack/lib/action_view/helpers/url_helper.rb +++ b/actionpack/lib/action_view/helpers/url_helper.rb @@ -13,15 +13,18 @@ module ActionView # Creates a link tag of the given +name+ using an URL created by the set of +options+. See the valid options in # link:classes/ActionController/Base.html#M000021. It's also possible to pass a string instead of an options hash to - # get a link tag that just points without consideration. The html_options have a special feature for creating javascript - # confirm alerts where if you pass :confirm => 'Are you sure?', the link will be guarded with a JS popup asking that question. - # If the user accepts, the link is processed, otherwise not. + # get a link tag that just points without consideration. If nil is passed as a name, the link itself will become the name. + # The html_options have a special feature for creating javascript confirm alerts where if you pass :confirm => 'Are you sure?', + # the link will be guarded with a JS popup asking that question. If the user accepts, the link is processed, otherwise not. def link_to(name, options = {}, html_options = {}, *parameters_for_method_reference) convert_confirm_option_to_javascript!(html_options) unless html_options.nil? if options.is_a?(String) - content_tag "a", name, (html_options || {}).merge({ "href" => options }) + content_tag "a", name || options, (html_options || {}).merge({ "href" => options }) else - content_tag("a", name, (html_options || {}).merge({ "href" => url_for(options, *parameters_for_method_reference) })) + content_tag( + "a", name || url_for(options, *parameters_for_method_reference), + (html_options || {}).merge({ "href" => url_for(options, *parameters_for_method_reference) }) + ) end end diff --git a/actionpack/test/controller/filters_test.rb b/actionpack/test/controller/filters_test.rb index f4d7a689b5..382109505c 100644 --- a/actionpack/test/controller/filters_test.rb +++ b/actionpack/test/controller/filters_test.rb @@ -15,6 +15,24 @@ class FilterTest < Test::Unit::TestCase end end + class LimitedFilterController < ActionController::Base + before_filter :ensure_login, :for => :show + + def show + render_text "ran action" + end + + def show_without_filter + render_text "ran action without filter" + end + + private + def ensure_login + @ran_filter ||= [] + @ran_filter << "ensure_login" + end + end + class PrependingController < TestController prepend_before_filter :wonderful_life @@ -125,6 +143,11 @@ class FilterTest < Test::Unit::TestCase def test_running_filters_with_class assert test_process(AuditController).template.assigns["was_audited"] end + + def test_running_limited_filters + assert_equal %w( fire_flash ensure_login ), test_process(LimitedFilterController, "show").template.assigns["ran_filter"] + assert_equal %w( fire_flash ), test_process(LimitedFilterController, "show_without_filter").template.assigns["ran_filter"] + end def test_bad_filter assert_raises(ActionController::ActionControllerError) { @@ -151,9 +174,9 @@ class FilterTest < Test::Unit::TestCase end private - def test_process(controller) + def test_process(controller, action = "show") request = ActionController::TestRequest.new - request.action = "show" + request.action = action controller.process(request, ActionController::TestResponse.new) end end \ No newline at end of file