Permalink
Browse files

Allow form.select to accept ranges.

  • Loading branch information...
1 parent fab664a commit c6dcc3537c09829cbbb15a6e9b133ab0bcd93988 @iHiD iHiD committed Jan 22, 2012
@@ -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:
#
@@ -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>",
@@ -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"

0 comments on commit c6dcc35

Please sign in to comment.