From ee1d508a6bbdbfafb20516ebb4b452f1596f9ebe Mon Sep 17 00:00:00 2001 From: Cheah Chu Yeow Date: Sun, 4 May 2008 23:54:08 +0800 Subject: Allow ActionController::Base#default_url_options to have a default options argument of nil. This fixes a bug introduced in [6a6b4392c16c665eb713705f2b38e959a658eeef] which was breaking routing in ActionController::UrlWriter. --- actionpack/lib/action_controller/base.rb | 2 +- actionpack/lib/action_controller/routing/optimisations.rb | 6 +++--- actionpack/test/controller/base_test.rb | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index 6b5914c4dd..c6d28b492a 100755 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -998,7 +998,7 @@ module ActionController #:nodoc: # As you can infer from the example, this is mostly useful for situations where you want to centralize dynamic decisions about the # urls as they stem from the business domain. Please note that any individual url_for call can always override the defaults set # by this method. - def default_url_options(options) #:doc: + def default_url_options(options = nil) end # Redirects the browser to the target specified in +options+. This parameter can take one of three forms: diff --git a/actionpack/lib/action_controller/routing/optimisations.rb b/actionpack/lib/action_controller/routing/optimisations.rb index 3e3a2225f0..cd4a423e6b 100644 --- a/actionpack/lib/action_controller/routing/optimisations.rb +++ b/actionpack/lib/action_controller/routing/optimisations.rb @@ -61,9 +61,9 @@ module ActionController # if they're using foo_url(:id=>2) it's one # argument, but we don't want to generate /foos/id2 if number_of_arguments == 1 - "(!defined?(default_url_options) || default_url_options(nil).blank?) && defined?(request) && request && args.size == 1 && !args.first.is_a?(Hash)" + "(!defined?(default_url_options) || default_url_options.blank?) && defined?(request) && request && args.size == 1 && !args.first.is_a?(Hash)" else - "(!defined?(default_url_options) || default_url_options(nil).blank?) && defined?(request) && request && args.size == #{number_of_arguments}" + "(!defined?(default_url_options) || default_url_options.blank?) && defined?(request) && request && args.size == #{number_of_arguments}" end end @@ -98,7 +98,7 @@ module ActionController # argument class PositionalArgumentsWithAdditionalParams < PositionalArguments def guard_condition - "(!defined?(default_url_options) || default_url_options(nil).blank?) && defined?(request) && request && args.size == #{route.segment_keys.size + 1} && !args.last.has_key?(:anchor) && !args.last.has_key?(:port) && !args.last.has_key?(:host)" + "(!defined?(default_url_options) || default_url_options.blank?) && defined?(request) && request && args.size == #{route.segment_keys.size + 1} && !args.last.has_key?(:anchor) && !args.last.has_key?(:port) && !args.last.has_key?(:host)" end # This case uses almost the same code as positional arguments, diff --git a/actionpack/test/controller/base_test.rb b/actionpack/test/controller/base_test.rb index 8416754c1e..ea63eda306 100644 --- a/actionpack/test/controller/base_test.rb +++ b/actionpack/test/controller/base_test.rb @@ -52,7 +52,7 @@ class DefaultUrlOptionsController < ActionController::Base def default_url_options_action end - def default_url_options(options) + def default_url_options(options = nil) { :host => 'www.override.com', :action => 'new', :bacon => 'chunky' } end end -- cgit v1.2.3 From 37599d16f2374179ebf001aeb79ff121e3d67519 Mon Sep 17 00:00:00 2001 From: rick Date: Mon, 5 May 2008 23:42:52 -0700 Subject: regression test for bug introduced in [6a6b4392c16c665eb713705f2b38e959a658eeef] [Ian White] [#22 state:resolved] --- actionpack/test/controller/base_test.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'actionpack') diff --git a/actionpack/test/controller/base_test.rb b/actionpack/test/controller/base_test.rb index ea63eda306..b28717597e 100644 --- a/actionpack/test/controller/base_test.rb +++ b/actionpack/test/controller/base_test.rb @@ -167,4 +167,17 @@ class DefaultUrlOptionsTest < Test::Unit::TestCase ensure ActionController::Routing::Routes.load! end +end + +class EnsureNamedRoutesWorksTicket22BugTest < Test::Unit::TestCase + def test_named_routes_still_work + ActionController::Routing::Routes.draw do |map| + map.resources :things + end + EmptyController.send :include, ActionController::UrlWriter + + assert_equal '/things', EmptyController.new.send(:things_path) + ensure + ActionController::Routing::Routes.load! + end end \ No newline at end of file -- cgit v1.2.3 From 04f52219f11944e50555dc59917c73c99581dac0 Mon Sep 17 00:00:00 2001 From: Andrew Vit Date: Mon, 5 May 2008 12:45:09 -0700 Subject: Fixed form helper's name attribute for question methods --- actionpack/lib/action_view/helpers/form_helper.rb | 14 +++++++++----- actionpack/test/template/form_helper_test.rb | 9 +++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 63c5fd57aa..b8600fe445 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -614,23 +614,27 @@ module ActionView end def tag_name - "#{@object_name}[#{@method_name}]" + "#{@object_name}[#{sanitized_method_name}]" end def tag_name_with_index(index) - "#{@object_name}[#{index}][#{@method_name}]" + "#{@object_name}[#{index}][#{sanitized_method_name}]" end def tag_id - "#{sanitized_object_name}_#{@method_name}" + "#{sanitized_object_name}_#{sanitized_method_name}" end def tag_id_with_index(index) - "#{sanitized_object_name}_#{index}_#{@method_name}" + "#{sanitized_object_name}_#{index}_#{sanitized_method_name}" end def sanitized_object_name - @object_name.gsub(/[^-a-zA-Z0-9:.]/, "_").sub(/_$/, "") + @sanitized_object_name ||= @object_name.gsub(/[^-a-zA-Z0-9:.]/, "_").sub(/_$/, "") + end + + def sanitized_method_name + @sanitized_method_name ||= @method_name.sub(/\?$/,"") end end diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index 204575fd89..4538b6dc6f 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -6,6 +6,7 @@ silence_warnings do alias_method :title_before_type_cast, :title unless respond_to?(:title_before_type_cast) alias_method :body_before_type_cast, :body unless respond_to?(:body_before_type_cast) alias_method :author_name_before_type_cast, :author_name unless respond_to?(:author_name_before_type_cast) + alias_method :secret?, :secret def new_record=(boolean) @new_record = boolean @@ -71,10 +72,12 @@ class FormHelperTest < ActionView::TestCase '', label("post", "title", nil, :class => 'title_label') ) + assert_dom_equal('', label("post", "secret?")) end def test_label_with_symbols assert_dom_equal('', label(:post, :title)) + assert_dom_equal('', label(:post, :secret?)) end def test_label_with_for_attribute_as_symbol @@ -140,6 +143,8 @@ class FormHelperTest < ActionView::TestCase def test_hidden_field assert_dom_equal '', hidden_field("post", "title") + assert_dom_equal '', + hidden_field("post", "secret?") end def test_hidden_field_with_escapes @@ -172,6 +177,10 @@ class FormHelperTest < ActionView::TestCase '', check_box("post", "secret") ) + assert_dom_equal( + '', + check_box("post", "secret?") + ) end def test_check_box_with_explicit_checked_and_unchecked_values -- cgit v1.2.3