Skip to content

Commit

Permalink
Merge pull request #4604 from ihid/3-2-stable
Browse files Browse the repository at this point in the history
3-2-stable: Fixed regression - unable to use a range as choices for form.select.
  • Loading branch information
josevalim committed Jan 22, 2012
2 parents 9ab2904 + c6dcc35 commit 334e5ca
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions actionpack/lib/action_view/helpers/form_options_helper.rb
Expand Up @@ -578,6 +578,7 @@ class InstanceTag #:nodoc:

def to_select_tag(choices, options, html_options)
selected_value = options.has_key?(:selected) ? options[:selected] : value(object)
choices = choices.to_a if choices.is_a?(Range)

# Grouped choices look like this:
#
Expand Down
16 changes: 16 additions & 0 deletions actionpack/test/template/form_options_helper_test.rb
Expand Up @@ -159,6 +159,13 @@ def test_array_options_for_string_include_in_other_string_bug_fix
)
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_hash_options_for_select
assert_dom_equal(
"<option value=\"&lt;Kroner&gt;\">&lt;DKR&gt;</option>\n<option value=\"Dollar\">$</option>",
Expand Down Expand Up @@ -671,6 +678,15 @@ def test_select_with_disabled_array
)
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"
Expand Down

0 comments on commit 334e5ca

Please sign in to comment.