diff options
author | David Heinemeier Hansson <david@envy8.local> | 2008-04-11 12:34:44 -0500 |
---|---|---|
committer | David Heinemeier Hansson <david@envy8.local> | 2008-04-11 12:34:44 -0500 |
commit | e89093aeb4b1f544cb54caf54a0374075250cc59 (patch) | |
tree | cc4f9533e473c8453ce14e0a0340ef5e9dac0bd4 | |
parent | f46fd6f2fceb22f00669f066fc98f92a18e5875f (diff) | |
download | rails-e89093aeb4b1f544cb54caf54a0374075250cc59.tar.gz rails-e89093aeb4b1f544cb54caf54a0374075250cc59.tar.bz2 rails-e89093aeb4b1f544cb54caf54a0374075250cc59.zip |
Fixed that formatted_polymorphic_route should be able to take the :format as part of a single hash or as the option hash (references #8741)
-rw-r--r-- | actionpack/lib/action_controller/polymorphic_routes.rb | 12 | ||||
-rw-r--r-- | actionpack/test/controller/polymorphic_routes_test.rb | 11 |
2 files changed, 19 insertions, 4 deletions
diff --git a/actionpack/lib/action_controller/polymorphic_routes.rb b/actionpack/lib/action_controller/polymorphic_routes.rb index f043d89dae..2cc2ec7723 100644 --- a/actionpack/lib/action_controller/polymorphic_routes.rb +++ b/actionpack/lib/action_controller/polymorphic_routes.rb @@ -73,7 +73,7 @@ module ActionController end record = extract_record(record_or_hash_or_array) - format = (options[:action].to_s == "formatted" and record_or_hash_or_array.pop) + format = extract_format(record_or_hash_or_array, options) namespace = extract_namespace(record_or_hash_or_array) args = case record_or_hash_or_array @@ -152,6 +152,16 @@ module ActionController end end + def extract_format(record_or_hash_or_array, options) + if options[:action].to_s == "formatted" && record_or_hash_or_array.is_a?(Array) + record_or_hash_or_array.pop + elsif options[:format] + options[:format] + else + nil + end + end + def extract_namespace(record_or_hash_or_array) returning "" do |namespace| if record_or_hash_or_array.is_a?(Array) diff --git a/actionpack/test/controller/polymorphic_routes_test.rb b/actionpack/test/controller/polymorphic_routes_test.rb index 0d349a360c..4ec0d3cd4e 100644 --- a/actionpack/test/controller/polymorphic_routes_test.rb +++ b/actionpack/test/controller/polymorphic_routes_test.rb @@ -65,13 +65,18 @@ uses_mocha 'polymorphic URL helpers' do formatted_polymorphic_url([@article, :pdf]) end - # TODO: should this work? - def xtest_format_option + def test_format_option @article.save - expects(:article_url).with(@article, :format => :pdf) + expects(:article_url).with(@article, :pdf) polymorphic_url(@article, :format => :pdf) end + def test_id_and_format_option + @article.save + expects(:article_url).with(:id => @article, :format => :pdf) + polymorphic_url(:id => @article, :format => :pdf) + end + def test_with_nested @response.save expects(:article_response_url).with(@article, @response) |