diff options
author | Jeremy Walker <jez.walker@gmail.com> | 2012-01-21 16:13:47 +0000 |
---|---|---|
committer | Jeremy Walker <jez.walker@gmail.com> | 2012-01-21 16:13:47 +0000 |
commit | 2ee8c6a73b932e97fc7abc453b50314aea76544d (patch) | |
tree | 65ff1305f9c5d01f4a5c9bc73db3d50a29301a9e /actionpack | |
parent | a50382cacdfa2e30c882f9f462e982d78e3e8ef5 (diff) | |
download | rails-2ee8c6a73b932e97fc7abc453b50314aea76544d.tar.gz rails-2ee8c6a73b932e97fc7abc453b50314aea76544d.tar.bz2 rails-2ee8c6a73b932e97fc7abc453b50314aea76544d.zip |
Fix inconsistent ability to use a range as choices for select_tag.
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_view/helpers/tags/select.rb | 1 | ||||
-rw-r--r-- | actionpack/test/template/form_options_helper_test.rb | 16 |
2 files changed, 17 insertions, 0 deletions
diff --git a/actionpack/lib/action_view/helpers/tags/select.rb b/actionpack/lib/action_view/helpers/tags/select.rb index 71fd4d04b7..02b790db4e 100644 --- a/actionpack/lib/action_view/helpers/tags/select.rb +++ b/actionpack/lib/action_view/helpers/tags/select.rb @@ -4,6 +4,7 @@ module ActionView class Select < Base #:nodoc: def initialize(object_name, method_name, template_object, choices, options, html_options) @choices = choices + @choices = @choices.to_a if @choices.is_a?(Range) @html_options = html_options super(object_name, method_name, template_object, options) diff --git a/actionpack/test/template/form_options_helper_test.rb b/actionpack/test/template/form_options_helper_test.rb index 4a889beadd..a903e13bad 100644 --- a/actionpack/test/template/form_options_helper_test.rb +++ b/actionpack/test/template/form_options_helper_test.rb @@ -144,6 +144,13 @@ class FormOptionsHelperTest < ActionView::TestCase ) end + def test_range_options_for_select + assert_dom_equal( + "<option value=\"1\">1</option>\n<option value=\"2\">2</option>\n<option value=\"3\">3</option>", + options_for_select(1..3) + ) + end + def test_array_options_for_string_include_in_other_string_bug_fix assert_dom_equal( "<option value=\"ruby\">ruby</option>\n<option value=\"rubyonrails\" selected=\"selected\">rubyonrails</option>", @@ -671,6 +678,15 @@ class FormOptionsHelperTest < ActionView::TestCase ) end + def test_select_with_range + @post = Post.new + @post.category = 0 + assert_dom_equal( + "<select id=\"post_category\" name=\"post[category]\"><option value=\"1\">1</option>\n<option value=\"2\">2</option>\n<option value=\"3\">3</option></select>", + select("post", "category", 1..3) + ) + end + def test_collection_select @post = Post.new @post.author_name = "Babe" |