aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/template
diff options
context:
space:
mode:
authorcodeape <dan@codeape.net>2009-08-09 19:18:01 -0700
committerJeremy Kemper <jeremy@bitsweat.net>2009-08-09 23:58:43 -0700
commit8c32248acbd71f7906a037fad499e2f8cae61bed (patch)
treed9616a5448ef8a370a2b3d991ebffec475bda7db /actionpack/test/template
parent7d16e94d827197d030fdd611db4310396aeb0114 (diff)
downloadrails-8c32248acbd71f7906a037fad499e2f8cae61bed.tar.gz
rails-8c32248acbd71f7906a037fad499e2f8cae61bed.tar.bz2
rails-8c32248acbd71f7906a037fad499e2f8cae61bed.zip
Introduce grouped_collection_select helper.
[#1249 state:committed] Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'actionpack/test/template')
-rw-r--r--actionpack/test/template/form_options_helper_test.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/actionpack/test/template/form_options_helper_test.rb b/actionpack/test/template/form_options_helper_test.rb
index 73624406be..aa40e46aa8 100644
--- a/actionpack/test/template/form_options_helper_test.rb
+++ b/actionpack/test/template/form_options_helper_test.rb
@@ -763,6 +763,40 @@ class FormOptionsHelperTest < ActionView::TestCase
html
end
+ def test_grouped_collection_select
+ @continents = [
+ Continent.new("<Africa>", [Country.new("<sa>", "<South Africa>"), Country.new("so", "Somalia")] ),
+ Continent.new("Europe", [Country.new("dk", "Denmark"), Country.new("ie", "Ireland")] )
+ ]
+
+ @post = Post.new
+ @post.origin = 'dk'
+
+ assert_dom_equal(
+ %Q{<select id="post_origin" name="post[origin]"><optgroup label="&lt;Africa&gt;"><option value="&lt;sa&gt;">&lt;South Africa&gt;</option>\n<option value="so">Somalia</option></optgroup><optgroup label="Europe"><option value="dk" selected="selected">Denmark</option>\n<option value="ie">Ireland</option></optgroup></select>},
+ grouped_collection_select("post", "origin", @continents, :countries, :continent_name, :country_id, :country_name)
+ )
+ end
+
+ def test_grouped_collection_select_under_fields_for
+ @continents = [
+ Continent.new("<Africa>", [Country.new("<sa>", "<South Africa>"), Country.new("so", "Somalia")] ),
+ Continent.new("Europe", [Country.new("dk", "Denmark"), Country.new("ie", "Ireland")] )
+ ]
+
+ @post = Post.new
+ @post.origin = 'dk'
+
+ fields_for :post, @post do |f|
+ concat f.grouped_collection_select("origin", @continents, :countries, :continent_name, :country_id, :country_name)
+ end
+
+ assert_dom_equal(
+ %Q{<select id="post_origin" name="post[origin]"><optgroup label="&lt;Africa&gt;"><option value="&lt;sa&gt;">&lt;South Africa&gt;</option>\n<option value="so">Somalia</option></optgroup><optgroup label="Europe"><option value="dk" selected="selected">Denmark</option>\n<option value="ie">Ireland</option></optgroup></select>},
+ output_buffer
+ )
+ end
+
private
def dummy_posts