actionpack 2.2.3 → 2.3.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of actionpack might be problematic. Click here for more details.
- data/CHANGELOG +433 -375
- data/MIT-LICENSE +1 -1
- data/README +21 -75
- data/Rakefile +1 -1
- data/lib/action_controller.rb +80 -43
- data/lib/action_controller/assertions/model_assertions.rb +1 -0
- data/lib/action_controller/assertions/response_assertions.rb +43 -16
- data/lib/action_controller/assertions/routing_assertions.rb +1 -1
- data/lib/action_controller/assertions/selector_assertions.rb +17 -12
- data/lib/action_controller/assertions/tag_assertions.rb +1 -4
- data/lib/action_controller/base.rb +153 -82
- data/lib/action_controller/benchmarking.rb +9 -9
- data/lib/action_controller/caching.rb +9 -11
- data/lib/action_controller/caching/actions.rb +11 -18
- data/lib/action_controller/caching/fragments.rb +28 -20
- data/lib/action_controller/caching/pages.rb +13 -15
- data/lib/action_controller/caching/sweeping.rb +2 -2
- data/lib/action_controller/cgi_ext.rb +0 -1
- data/lib/action_controller/cgi_ext/cookie.rb +2 -0
- data/lib/action_controller/cgi_process.rb +54 -162
- data/lib/action_controller/cookies.rb +13 -25
- data/lib/action_controller/dispatcher.rb +43 -122
- data/lib/action_controller/failsafe.rb +52 -0
- data/lib/action_controller/flash.rb +38 -47
- data/lib/action_controller/helpers.rb +13 -9
- data/lib/action_controller/http_authentication.rb +203 -23
- data/lib/action_controller/integration.rb +126 -70
- data/lib/action_controller/layout.rb +36 -39
- data/lib/action_controller/middleware_stack.rb +119 -0
- data/lib/action_controller/middlewares.rb +13 -0
- data/lib/action_controller/mime_responds.rb +19 -4
- data/lib/action_controller/mime_type.rb +8 -0
- data/lib/action_controller/params_parser.rb +71 -0
- data/lib/action_controller/performance_test.rb +0 -1
- data/lib/action_controller/polymorphic_routes.rb +36 -30
- data/lib/action_controller/reloader.rb +14 -0
- data/lib/action_controller/request.rb +107 -499
- data/lib/action_controller/request_forgery_protection.rb +7 -39
- data/lib/action_controller/rescue.rb +55 -35
- data/lib/action_controller/resources.rb +34 -31
- data/lib/action_controller/response.rb +99 -57
- data/lib/action_controller/rewindable_input.rb +28 -0
- data/lib/action_controller/routing.rb +7 -7
- data/lib/action_controller/routing/builder.rb +4 -1
- data/lib/action_controller/routing/optimisations.rb +1 -1
- data/lib/action_controller/routing/recognition_optimisation.rb +1 -2
- data/lib/action_controller/routing/route.rb +15 -5
- data/lib/action_controller/routing/route_set.rb +82 -35
- data/lib/action_controller/routing/segments.rb +35 -0
- data/lib/action_controller/session/abstract_store.rb +181 -0
- data/lib/action_controller/session/cookie_store.rb +197 -175
- data/lib/action_controller/session/mem_cache_store.rb +36 -83
- data/lib/action_controller/session_management.rb +26 -134
- data/lib/action_controller/streaming.rb +24 -7
- data/lib/action_controller/templates/rescues/diagnostics.erb +2 -2
- data/lib/action_controller/templates/rescues/template_error.erb +2 -2
- data/lib/action_controller/test_case.rb +87 -30
- data/lib/action_controller/test_process.rb +145 -104
- data/lib/action_controller/uploaded_file.rb +44 -0
- data/lib/action_controller/url_rewriter.rb +3 -6
- data/lib/action_controller/vendor/html-scanner.rb +16 -0
- data/lib/action_controller/vendor/html-scanner/html/selector.rb +1 -1
- data/lib/action_controller/vendor/rack-1.0/rack.rb +89 -0
- data/lib/action_controller/vendor/rack-1.0/rack/adapter/camping.rb +22 -0
- data/lib/action_controller/vendor/rack-1.0/rack/auth/abstract/handler.rb +37 -0
- data/lib/action_controller/vendor/rack-1.0/rack/auth/abstract/request.rb +37 -0
- data/lib/action_controller/vendor/rack-1.0/rack/auth/basic.rb +58 -0
- data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/md5.rb +124 -0
- data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/nonce.rb +51 -0
- data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/params.rb +55 -0
- data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/request.rb +40 -0
- data/lib/action_controller/vendor/rack-1.0/rack/auth/openid.rb +480 -0
- data/lib/action_controller/vendor/rack-1.0/rack/builder.rb +63 -0
- data/lib/action_controller/vendor/rack-1.0/rack/cascade.rb +36 -0
- data/lib/action_controller/vendor/rack-1.0/rack/chunked.rb +49 -0
- data/lib/action_controller/vendor/rack-1.0/rack/commonlogger.rb +61 -0
- data/lib/action_controller/vendor/rack-1.0/rack/conditionalget.rb +45 -0
- data/lib/action_controller/vendor/rack-1.0/rack/content_length.rb +29 -0
- data/lib/action_controller/vendor/rack-1.0/rack/content_type.rb +23 -0
- data/lib/action_controller/vendor/rack-1.0/rack/deflater.rb +85 -0
- data/lib/action_controller/vendor/rack-1.0/rack/directory.rb +153 -0
- data/lib/action_controller/vendor/rack-1.0/rack/file.rb +88 -0
- data/lib/action_controller/vendor/rack-1.0/rack/handler.rb +48 -0
- data/lib/action_controller/vendor/rack-1.0/rack/handler/cgi.rb +61 -0
- data/lib/action_controller/vendor/rack-1.0/rack/handler/evented_mongrel.rb +8 -0
- data/lib/action_controller/vendor/rack-1.0/rack/handler/fastcgi.rb +89 -0
- data/lib/action_controller/vendor/rack-1.0/rack/handler/lsws.rb +55 -0
- data/lib/action_controller/vendor/rack-1.0/rack/handler/mongrel.rb +84 -0
- data/lib/action_controller/vendor/rack-1.0/rack/handler/scgi.rb +59 -0
- data/lib/action_controller/vendor/rack-1.0/rack/handler/swiftiplied_mongrel.rb +8 -0
- data/lib/action_controller/vendor/rack-1.0/rack/handler/thin.rb +18 -0
- data/lib/action_controller/vendor/rack-1.0/rack/handler/webrick.rb +67 -0
- data/lib/action_controller/vendor/rack-1.0/rack/head.rb +19 -0
- data/lib/action_controller/vendor/rack-1.0/rack/lint.rb +462 -0
- data/lib/action_controller/vendor/rack-1.0/rack/lobster.rb +65 -0
- data/lib/action_controller/vendor/rack-1.0/rack/lock.rb +16 -0
- data/lib/action_controller/vendor/rack-1.0/rack/methodoverride.rb +27 -0
- data/lib/action_controller/vendor/rack-1.0/rack/mime.rb +204 -0
- data/lib/action_controller/vendor/rack-1.0/rack/mock.rb +160 -0
- data/lib/action_controller/vendor/rack-1.0/rack/recursive.rb +57 -0
- data/lib/action_controller/vendor/rack-1.0/rack/reloader.rb +64 -0
- data/lib/action_controller/vendor/rack-1.0/rack/request.rb +241 -0
- data/lib/action_controller/vendor/rack-1.0/rack/response.rb +179 -0
- data/lib/action_controller/vendor/rack-1.0/rack/session/abstract/id.rb +142 -0
- data/lib/action_controller/vendor/rack-1.0/rack/session/cookie.rb +91 -0
- data/lib/action_controller/vendor/rack-1.0/rack/session/memcache.rb +109 -0
- data/lib/action_controller/vendor/rack-1.0/rack/session/pool.rb +100 -0
- data/lib/action_controller/vendor/rack-1.0/rack/showexceptions.rb +349 -0
- data/lib/action_controller/vendor/rack-1.0/rack/showstatus.rb +106 -0
- data/lib/action_controller/vendor/rack-1.0/rack/static.rb +38 -0
- data/lib/action_controller/vendor/rack-1.0/rack/urlmap.rb +55 -0
- data/lib/action_controller/vendor/rack-1.0/rack/utils.rb +392 -0
- data/lib/action_controller/verification.rb +1 -1
- data/lib/action_pack.rb +1 -1
- data/lib/action_pack/version.rb +2 -2
- data/lib/action_view.rb +22 -17
- data/lib/action_view/base.rb +53 -79
- data/lib/action_view/erb/util.rb +38 -0
- data/lib/action_view/helpers.rb +24 -5
- data/lib/action_view/helpers/active_record_helper.rb +2 -2
- data/lib/action_view/helpers/asset_tag_helper.rb +81 -50
- data/lib/action_view/helpers/atom_feed_helper.rb +1 -1
- data/lib/action_view/helpers/benchmark_helper.rb +26 -5
- data/lib/action_view/helpers/date_helper.rb +82 -7
- data/lib/action_view/helpers/form_helper.rb +295 -64
- data/lib/action_view/helpers/form_options_helper.rb +160 -18
- data/lib/action_view/helpers/form_tag_helper.rb +2 -2
- data/lib/action_view/helpers/number_helper.rb +31 -18
- data/lib/action_view/helpers/prototype_helper.rb +2 -12
- data/lib/action_view/helpers/sanitize_helper.rb +0 -10
- data/lib/action_view/helpers/scriptaculous_helper.rb +1 -0
- data/lib/action_view/helpers/tag_helper.rb +3 -4
- data/lib/action_view/helpers/text_helper.rb +99 -122
- data/lib/action_view/helpers/translation_helper.rb +19 -1
- data/lib/action_view/helpers/url_helper.rb +25 -2
- data/lib/action_view/inline_template.rb +1 -1
- data/lib/action_view/locale/en.yml +19 -1
- data/lib/action_view/partials.rb +46 -9
- data/lib/action_view/paths.rb +28 -84
- data/lib/action_view/reloadable_template.rb +117 -0
- data/lib/action_view/renderable.rb +28 -35
- data/lib/action_view/renderable_partial.rb +3 -4
- data/lib/action_view/template.rb +172 -31
- data/lib/action_view/template_error.rb +8 -9
- data/lib/action_view/template_handler.rb +1 -1
- data/lib/action_view/template_handlers.rb +9 -6
- data/lib/action_view/template_handlers/erb.rb +2 -39
- data/lib/action_view/template_handlers/rjs.rb +1 -0
- data/lib/action_view/test_case.rb +27 -1
- data/test/abstract_unit.rb +23 -17
- data/test/active_record_unit.rb +5 -4
- data/test/activerecord/active_record_store_test.rb +139 -106
- data/test/activerecord/render_partial_with_record_identification_test.rb +5 -21
- data/test/controller/action_pack_assertions_test.rb +25 -23
- data/test/controller/addresses_render_test.rb +3 -6
- data/test/controller/assert_select_test.rb +83 -70
- data/test/controller/base_test.rb +11 -13
- data/test/controller/benchmark_test.rb +3 -3
- data/test/controller/caching_test.rb +34 -24
- data/test/controller/capture_test.rb +3 -6
- data/test/controller/content_type_test.rb +3 -6
- data/test/controller/cookie_test.rb +31 -66
- data/test/controller/deprecation/deprecated_base_methods_test.rb +9 -11
- data/test/controller/dispatcher_test.rb +23 -28
- data/test/controller/fake_models.rb +8 -0
- data/test/controller/filters_test.rb +6 -2
- data/test/controller/flash_test.rb +2 -6
- data/test/controller/helper_test.rb +15 -1
- data/test/controller/html-scanner/document_test.rb +1 -1
- data/test/controller/html-scanner/sanitizer_test.rb +1 -1
- data/test/controller/http_basic_authentication_test.rb +88 -0
- data/test/controller/http_digest_authentication_test.rb +178 -0
- data/test/controller/integration_test.rb +56 -52
- data/test/controller/layout_test.rb +46 -44
- data/test/controller/middleware_stack_test.rb +90 -0
- data/test/controller/mime_responds_test.rb +7 -11
- data/test/controller/mime_type_test.rb +9 -0
- data/test/controller/polymorphic_routes_test.rb +235 -151
- data/test/controller/rack_test.rb +52 -81
- data/test/controller/redirect_test.rb +6 -14
- data/test/controller/render_test.rb +273 -60
- data/test/controller/request/json_params_parsing_test.rb +45 -0
- data/test/controller/request/multipart_params_parsing_test.rb +223 -0
- data/test/controller/request/query_string_parsing_test.rb +120 -0
- data/test/controller/request/url_encoded_params_parsing_test.rb +184 -0
- data/test/controller/request/xml_params_parsing_test.rb +88 -0
- data/test/controller/request_forgery_protection_test.rb +17 -98
- data/test/controller/request_test.rb +45 -530
- data/test/controller/rescue_test.rb +45 -22
- data/test/controller/resources_test.rb +112 -37
- data/test/controller/routing_test.rb +1442 -1384
- data/test/controller/selector_test.rb +3 -3
- data/test/controller/send_file_test.rb +30 -3
- data/test/controller/session/cookie_store_test.rb +169 -240
- data/test/controller/session/mem_cache_store_test.rb +94 -148
- data/test/controller/session/test_session_test.rb +58 -0
- data/test/controller/test_test.rb +32 -13
- data/test/controller/url_rewriter_test.rb +54 -4
- data/test/controller/verification_test.rb +1 -1
- data/test/controller/view_paths_test.rb +15 -15
- data/test/controller/webservice_test.rb +178 -147
- data/test/fixtures/alternate_helpers/foo_helper.rb +3 -0
- data/test/fixtures/layout_tests/alt/layouts/alt.rhtml +0 -0
- data/test/fixtures/layouts/default_html.html.erb +1 -0
- data/test/fixtures/layouts/xhr.html.erb +2 -0
- data/test/fixtures/multipart/empty +10 -0
- data/test/fixtures/multipart/hello.txt +1 -0
- data/test/fixtures/multipart/none +9 -0
- data/test/fixtures/public/500.da.html +1 -0
- data/test/fixtures/quiz/questions/_question.html.erb +1 -0
- data/test/fixtures/replies.yml +1 -1
- data/test/fixtures/test/_one.html.erb +1 -0
- data/test/fixtures/test/_two.html.erb +1 -0
- data/test/fixtures/test/dont_pick_me +1 -0
- data/test/fixtures/test/hello.builder +1 -1
- data/test/fixtures/test/hello_world.da.html.erb +1 -0
- data/test/fixtures/test/hello_world.erb~ +1 -0
- data/test/fixtures/test/hello_world.pt-BR.html.erb +1 -0
- data/test/fixtures/test/malformed/malformed.en.html.erb~ +1 -0
- data/test/fixtures/test/malformed/malformed.erb~ +1 -0
- data/test/fixtures/test/malformed/malformed.html.erb~ +1 -0
- data/test/fixtures/test/render_explicit_html_template.js.rjs +1 -0
- data/test/fixtures/test/render_implicit_html_template.js.rjs +1 -0
- data/test/fixtures/test/render_implicit_html_template_from_xhr_request.da.html.erb +1 -0
- data/test/fixtures/test/render_implicit_html_template_from_xhr_request.html.erb +1 -0
- data/test/fixtures/test/render_implicit_js_template_without_layout.js.erb +1 -0
- data/test/fixtures/test/utf8.html.erb +2 -0
- data/test/template/active_record_helper_i18n_test.rb +31 -33
- data/test/template/active_record_helper_test.rb +34 -0
- data/test/template/asset_tag_helper_test.rb +52 -14
- data/test/template/atom_feed_helper_test.rb +3 -5
- data/test/template/benchmark_helper_test.rb +50 -24
- data/test/template/compiled_templates_test.rb +177 -33
- data/test/template/date_helper_i18n_test.rb +88 -81
- data/test/template/date_helper_test.rb +427 -43
- data/test/template/form_helper_test.rb +243 -44
- data/test/template/form_options_helper_test.rb +631 -565
- data/test/template/form_tag_helper_test.rb +9 -2
- data/test/template/javascript_helper_test.rb +0 -5
- data/test/template/number_helper_i18n_test.rb +60 -48
- data/test/template/number_helper_test.rb +1 -0
- data/test/template/render_test.rb +117 -35
- data/test/template/test_test.rb +4 -6
- data/test/template/text_helper_test.rb +129 -50
- data/test/template/translation_helper_test.rb +23 -19
- data/test/template/url_helper_test.rb +35 -2
- data/test/view/test_case_test.rb +8 -0
- metadata +197 -23
- data/lib/action_controller/assertions.rb +0 -69
- data/lib/action_controller/caching/sql_cache.rb +0 -18
- data/lib/action_controller/cgi_ext/session.rb +0 -53
- data/lib/action_controller/components.rb +0 -169
- data/lib/action_controller/rack_process.rb +0 -297
- data/lib/action_controller/request_profiler.rb +0 -169
- data/lib/action_controller/session/active_record_store.rb +0 -340
- data/lib/action_controller/session/drb_server.rb +0 -32
- data/lib/action_controller/session/drb_store.rb +0 -35
- data/test/controller/cgi_test.rb +0 -269
- data/test/controller/components_test.rb +0 -156
- data/test/controller/http_authentication_test.rb +0 -54
- data/test/controller/integration_upload_test.rb +0 -43
- data/test/controller/session_fixation_test.rb +0 -89
- data/test/controller/session_management_test.rb +0 -178
- data/test/fixtures/test/hello_world.js +0 -1
@@ -1,685 +1,751 @@
|
|
1
1
|
require 'abstract_unit'
|
2
|
+
require 'tzinfo'
|
2
3
|
|
3
4
|
TZInfo::Timezone.cattr_reader :loaded_zones
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
tests ActionView::Helpers::FormOptionsHelper
|
6
|
+
class FormOptionsHelperTest < ActionView::TestCase
|
7
|
+
tests ActionView::Helpers::FormOptionsHelper
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
9
|
+
silence_warnings do
|
10
|
+
Post = Struct.new('Post', :title, :author_name, :body, :secret, :written_on, :category, :origin)
|
11
|
+
Continent = Struct.new('Continent', :continent_name, :countries)
|
12
|
+
Country = Struct.new('Country', :country_id, :country_name)
|
13
|
+
Firm = Struct.new('Firm', :time_zone)
|
14
|
+
Album = Struct.new('Album', :id, :title, :genre)
|
15
|
+
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
-
ActiveSupport::TimeZone.stubs(:all).returns(@fake_timezones)
|
17
|
+
def setup
|
18
|
+
@fake_timezones = %w(A B C D E).inject([]) do |zones, id|
|
19
|
+
tz = TZInfo::Timezone.loaded_zones[id] = stub(:name => id, :to_s => id)
|
20
|
+
ActiveSupport::TimeZone.stubs(:[]).with(id).returns(tz)
|
21
|
+
zones << tz
|
24
22
|
end
|
23
|
+
ActiveSupport::TimeZone.stubs(:all).returns(@fake_timezones)
|
24
|
+
end
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
26
|
+
def test_collection_options
|
27
|
+
assert_dom_equal(
|
28
|
+
"<option value=\"<Abe>\"><Abe> went home</option>\n<option value=\"Babe\">Babe went home</option>\n<option value=\"Cabe\">Cabe went home</option>",
|
29
|
+
options_from_collection_for_select(dummy_posts, "author_name", "title")
|
30
|
+
)
|
31
|
+
end
|
32
32
|
|
33
|
+
|
34
|
+
def test_collection_options_with_preselected_value
|
35
|
+
assert_dom_equal(
|
36
|
+
"<option value=\"<Abe>\"><Abe> went home</option>\n<option value=\"Babe\" selected=\"selected\">Babe went home</option>\n<option value=\"Cabe\">Cabe went home</option>",
|
37
|
+
options_from_collection_for_select(dummy_posts, "author_name", "title", "Babe")
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_collection_options_with_preselected_value_array
|
33
42
|
assert_dom_equal(
|
34
|
-
"<option value=\"<Abe>\"><Abe> went home</option>\n<option value=\"Babe\">Babe went home</option>\n<option value=\"Cabe\">Cabe went home</option>",
|
35
|
-
options_from_collection_for_select(
|
43
|
+
"<option value=\"<Abe>\"><Abe> went home</option>\n<option value=\"Babe\" selected=\"selected\">Babe went home</option>\n<option value=\"Cabe\" selected=\"selected\">Cabe went home</option>",
|
44
|
+
options_from_collection_for_select(dummy_posts, "author_name", "title", [ "Babe", "Cabe" ])
|
36
45
|
)
|
37
|
-
|
46
|
+
end
|
38
47
|
|
48
|
+
def test_collection_options_with_proc_for_selected
|
49
|
+
assert_dom_equal(
|
50
|
+
"<option value=\"<Abe>\"><Abe> went home</option>\n<option value=\"Babe\" selected=\"selected\">Babe went home</option>\n<option value=\"Cabe\">Cabe went home</option>",
|
51
|
+
options_from_collection_for_select(dummy_posts, "author_name", "title", lambda{|p| p.author_name == 'Babe' })
|
52
|
+
)
|
53
|
+
end
|
39
54
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
55
|
+
def test_collection_options_with_disabled_value
|
56
|
+
assert_dom_equal(
|
57
|
+
"<option value=\"<Abe>\"><Abe> went home</option>\n<option value=\"Babe\" disabled=\"disabled\">Babe went home</option>\n<option value=\"Cabe\">Cabe went home</option>",
|
58
|
+
options_from_collection_for_select(dummy_posts, "author_name", "title", :disabled => "Babe")
|
59
|
+
)
|
60
|
+
end
|
46
61
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
)
|
51
|
-
|
62
|
+
def test_collection_options_with_disabled_array
|
63
|
+
assert_dom_equal(
|
64
|
+
"<option value=\"<Abe>\"><Abe> went home</option>\n<option value=\"Babe\" disabled=\"disabled\">Babe went home</option>\n<option value=\"Cabe\" disabled=\"disabled\">Cabe went home</option>",
|
65
|
+
options_from_collection_for_select(dummy_posts, "author_name", "title", :disabled => [ "Babe", "Cabe" ])
|
66
|
+
)
|
67
|
+
end
|
52
68
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
assert_dom_equal(
|
61
|
-
"<option value=\"<Abe>\"><Abe> went home</option>\n<option value=\"Babe\" selected=\"selected\">Babe went home</option>\n<option value=\"Cabe\" selected=\"selected\">Cabe went home</option>",
|
62
|
-
options_from_collection_for_select(@posts, "author_name", "title", [ "Babe", "Cabe" ])
|
63
|
-
)
|
64
|
-
end
|
69
|
+
def test_collection_options_with_preselected_and_disabled_value
|
70
|
+
assert_dom_equal(
|
71
|
+
"<option value=\"<Abe>\"><Abe> went home</option>\n<option value=\"Babe\" disabled=\"disabled\">Babe went home</option>\n<option value=\"Cabe\" selected=\"selected\">Cabe went home</option>",
|
72
|
+
options_from_collection_for_select(dummy_posts, "author_name", "title", :selected => "Cabe", :disabled => "Babe")
|
73
|
+
)
|
74
|
+
end
|
65
75
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
76
|
+
def test_collection_options_with_proc_for_disabled
|
77
|
+
assert_dom_equal(
|
78
|
+
"<option value=\"<Abe>\"><Abe> went home</option>\n<option value=\"Babe\" disabled=\"disabled\">Babe went home</option>\n<option value=\"Cabe\" disabled=\"disabled\">Cabe went home</option>",
|
79
|
+
options_from_collection_for_select(dummy_posts, "author_name", "title", :disabled => lambda{|p| %w(Babe Cabe).include? p.author_name })
|
80
|
+
)
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_array_options_for_select
|
84
|
+
assert_dom_equal(
|
85
|
+
"<option value=\"<Denmark>\"><Denmark></option>\n<option value=\"USA\">USA</option>\n<option value=\"Sweden\">Sweden</option>",
|
86
|
+
options_for_select([ "<Denmark>", "USA", "Sweden" ])
|
87
|
+
)
|
88
|
+
end
|
72
89
|
|
73
|
-
|
90
|
+
def test_array_options_for_select_with_selection
|
91
|
+
assert_dom_equal(
|
92
|
+
"<option value=\"Denmark\">Denmark</option>\n<option value=\"<USA>\" selected=\"selected\"><USA></option>\n<option value=\"Sweden\">Sweden</option>",
|
93
|
+
options_for_select([ "Denmark", "<USA>", "Sweden" ], "<USA>")
|
94
|
+
)
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_array_options_for_select_with_selection_array
|
74
98
|
assert_dom_equal(
|
75
|
-
"<option value=\"Denmark\">Denmark</option>\n<option value=\"<USA>\" selected=\"selected\"><USA></option>\n<option value=\"Sweden\">Sweden</option>",
|
76
|
-
options_for_select([ "Denmark", "<USA>", "Sweden" ], "<USA>")
|
99
|
+
"<option value=\"Denmark\">Denmark</option>\n<option value=\"<USA>\" selected=\"selected\"><USA></option>\n<option value=\"Sweden\" selected=\"selected\">Sweden</option>",
|
100
|
+
options_for_select([ "Denmark", "<USA>", "Sweden" ], [ "<USA>", "Sweden" ])
|
77
101
|
)
|
78
|
-
|
102
|
+
end
|
79
103
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
104
|
+
def test_array_options_for_select_with_disabled_value
|
105
|
+
assert_dom_equal(
|
106
|
+
"<option value=\"Denmark\">Denmark</option>\n<option value=\"<USA>\" disabled=\"disabled\"><USA></option>\n<option value=\"Sweden\">Sweden</option>",
|
107
|
+
options_for_select([ "Denmark", "<USA>", "Sweden" ], :disabled => "<USA>")
|
108
|
+
)
|
109
|
+
end
|
86
110
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
"<option value=\"ruby\" selected=\"selected\">ruby</option>\n<option value=\"rubyonrails\">rubyonrails</option>",
|
94
|
-
options_for_select([ "ruby", "rubyonrails" ], "ruby")
|
95
|
-
)
|
96
|
-
assert_dom_equal(
|
97
|
-
%(<option value="ruby" selected="selected">ruby</option>\n<option value="rubyonrails">rubyonrails</option>\n<option value=""></option>),
|
98
|
-
options_for_select([ "ruby", "rubyonrails", nil ], "ruby")
|
99
|
-
)
|
100
|
-
end
|
111
|
+
def test_array_options_for_select_with_disabled_array
|
112
|
+
assert_dom_equal(
|
113
|
+
"<option value=\"Denmark\">Denmark</option>\n<option value=\"<USA>\" disabled=\"disabled\"><USA></option>\n<option value=\"Sweden\" disabled=\"disabled\">Sweden</option>",
|
114
|
+
options_for_select([ "Denmark", "<USA>", "Sweden" ], :disabled => ["<USA>", "Sweden"])
|
115
|
+
)
|
116
|
+
end
|
101
117
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
"<option value=\"<Kroner>\"><DKR></option>\n<option value=\"Dollar\" selected=\"selected\">$</option>",
|
109
|
-
options_for_select({ "$" => "Dollar", "<DKR>" => "<Kroner>" }, "Dollar").split("\n").sort.join("\n")
|
110
|
-
)
|
111
|
-
assert_dom_equal(
|
112
|
-
"<option value=\"<Kroner>\" selected=\"selected\"><DKR></option>\n<option value=\"Dollar\" selected=\"selected\">$</option>",
|
113
|
-
options_for_select({ "$" => "Dollar", "<DKR>" => "<Kroner>" }, [ "Dollar", "<Kroner>" ]).split("\n").sort.join("\n")
|
114
|
-
)
|
115
|
-
end
|
118
|
+
def test_array_options_for_select_with_selection_and_disabled_value
|
119
|
+
assert_dom_equal(
|
120
|
+
"<option value=\"Denmark\" selected=\"selected\">Denmark</option>\n<option value=\"<USA>\" disabled=\"disabled\"><USA></option>\n<option value=\"Sweden\">Sweden</option>",
|
121
|
+
options_for_select([ "Denmark", "<USA>", "Sweden" ], :selected => "Denmark", :disabled => "<USA>")
|
122
|
+
)
|
123
|
+
end
|
116
124
|
|
117
|
-
|
118
|
-
quack = Struct.new(:first, :last)
|
125
|
+
def test_array_options_for_string_include_in_other_string_bug_fix
|
119
126
|
assert_dom_equal(
|
120
|
-
"<option value=\"
|
121
|
-
options_for_select([
|
127
|
+
"<option value=\"ruby\">ruby</option>\n<option value=\"rubyonrails\" selected=\"selected\">rubyonrails</option>",
|
128
|
+
options_for_select([ "ruby", "rubyonrails" ], "rubyonrails")
|
122
129
|
)
|
123
130
|
assert_dom_equal(
|
124
|
-
"<option value=\"
|
125
|
-
options_for_select([
|
131
|
+
"<option value=\"ruby\" selected=\"selected\">ruby</option>\n<option value=\"rubyonrails\">rubyonrails</option>",
|
132
|
+
options_for_select([ "ruby", "rubyonrails" ], "ruby")
|
126
133
|
)
|
127
134
|
assert_dom_equal(
|
128
|
-
|
129
|
-
options_for_select([
|
135
|
+
%(<option value="ruby" selected="selected">ruby</option>\n<option value="rubyonrails">rubyonrails</option>\n<option value=""></option>),
|
136
|
+
options_for_select([ "ruby", "rubyonrails", nil ], "ruby")
|
130
137
|
)
|
131
|
-
|
132
|
-
|
133
|
-
def test_option_groups_from_collection_for_select
|
134
|
-
@continents = [
|
135
|
-
Continent.new("<Africa>", [Country.new("<sa>", "<South Africa>"), Country.new("so", "Somalia")] ),
|
136
|
-
Continent.new("Europe", [Country.new("dk", "Denmark"), Country.new("ie", "Ireland")] )
|
137
|
-
]
|
138
|
+
end
|
138
139
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
)
|
143
|
-
|
140
|
+
def test_hash_options_for_select
|
141
|
+
assert_dom_equal(
|
142
|
+
"<option value=\"<Kroner>\"><DKR></option>\n<option value=\"Dollar\">$</option>",
|
143
|
+
options_for_select("$" => "Dollar", "<DKR>" => "<Kroner>").split("\n").sort.join("\n")
|
144
|
+
)
|
145
|
+
assert_dom_equal(
|
146
|
+
"<option value=\"<Kroner>\"><DKR></option>\n<option value=\"Dollar\" selected=\"selected\">$</option>",
|
147
|
+
options_for_select({ "$" => "Dollar", "<DKR>" => "<Kroner>" }, "Dollar").split("\n").sort.join("\n")
|
148
|
+
)
|
149
|
+
assert_dom_equal(
|
150
|
+
"<option value=\"<Kroner>\" selected=\"selected\"><DKR></option>\n<option value=\"Dollar\" selected=\"selected\">$</option>",
|
151
|
+
options_for_select({ "$" => "Dollar", "<DKR>" => "<Kroner>" }, [ "Dollar", "<Kroner>" ]).split("\n").sort.join("\n")
|
152
|
+
)
|
153
|
+
end
|
144
154
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
155
|
+
def test_ducktyped_options_for_select
|
156
|
+
quack = Struct.new(:first, :last)
|
157
|
+
assert_dom_equal(
|
158
|
+
"<option value=\"<Kroner>\"><DKR></option>\n<option value=\"Dollar\">$</option>",
|
159
|
+
options_for_select([quack.new("<DKR>", "<Kroner>"), quack.new("$", "Dollar")])
|
160
|
+
)
|
161
|
+
assert_dom_equal(
|
162
|
+
"<option value=\"<Kroner>\"><DKR></option>\n<option value=\"Dollar\" selected=\"selected\">$</option>",
|
163
|
+
options_for_select([quack.new("<DKR>", "<Kroner>"), quack.new("$", "Dollar")], "Dollar")
|
164
|
+
)
|
165
|
+
assert_dom_equal(
|
166
|
+
"<option value=\"<Kroner>\" selected=\"selected\"><DKR></option>\n<option value=\"Dollar\" selected=\"selected\">$</option>",
|
167
|
+
options_for_select([quack.new("<DKR>", "<Kroner>"), quack.new("$", "Dollar")], ["Dollar", "<Kroner>"])
|
168
|
+
)
|
169
|
+
end
|
154
170
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
"<option value=\"D\" selected=\"selected\">D</option>\n" +
|
161
|
-
"<option value=\"E\">E</option>",
|
162
|
-
opts
|
163
|
-
end
|
171
|
+
def test_option_groups_from_collection_for_select
|
172
|
+
@continents = [
|
173
|
+
Continent.new("<Africa>", [Country.new("<sa>", "<South Africa>"), Country.new("so", "Somalia")] ),
|
174
|
+
Continent.new("Europe", [Country.new("dk", "Denmark"), Country.new("ie", "Ireland")] )
|
175
|
+
]
|
164
176
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
"<option value=\"D\">D</option>\n" +
|
171
|
-
"<option value=\"E\">E</option>",
|
172
|
-
opts
|
173
|
-
end
|
177
|
+
assert_dom_equal(
|
178
|
+
"<optgroup label=\"<Africa>\"><option value=\"<sa>\"><South Africa></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>",
|
179
|
+
option_groups_from_collection_for_select(@continents, "countries", "continent_name", "country_id", "country_name", "dk")
|
180
|
+
)
|
181
|
+
end
|
174
182
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
183
|
+
def test_grouped_options_for_select_with_array
|
184
|
+
assert_dom_equal(
|
185
|
+
"<optgroup label=\"North America\"><option value=\"US\">United States</option>\n<option value=\"Canada\">Canada</option></optgroup><optgroup label=\"Europe\"><option value=\"GB\">Great Britain</option>\n<option value=\"Germany\">Germany</option></optgroup>",
|
186
|
+
grouped_options_for_select([
|
187
|
+
["North America",
|
188
|
+
[['United States','US'],"Canada"]],
|
189
|
+
["Europe",
|
190
|
+
[["Great Britain","GB"], "Germany"]]
|
191
|
+
])
|
192
|
+
)
|
193
|
+
end
|
186
194
|
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
"<option value=\"A\">A</option>\n" +
|
194
|
-
"<option value=\"C\">C</option>\n" +
|
195
|
-
"<option value=\"D\">D</option>",
|
196
|
-
opts
|
197
|
-
end
|
195
|
+
def test_grouped_options_for_select_with_selected_and_prompt
|
196
|
+
assert_dom_equal(
|
197
|
+
"<option value=\"\">Choose a product...</option><optgroup label=\"Hats\"><option value=\"Baseball Cap\">Baseball Cap</option>\n<option selected=\"selected\" value=\"Cowboy Hat\">Cowboy Hat</option></optgroup>",
|
198
|
+
grouped_options_for_select([["Hats", ["Baseball Cap","Cowboy Hat"]]], "Cowboy Hat", "Choose a product...")
|
199
|
+
)
|
200
|
+
end
|
198
201
|
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
"<option value=\"A\">A</option>\n" +
|
206
|
-
"<option value=\"C\" selected=\"selected\">C</option>\n" +
|
207
|
-
"<option value=\"D\">D</option>",
|
208
|
-
opts
|
209
|
-
end
|
202
|
+
def test_optgroups_with_with_options_with_hash
|
203
|
+
assert_dom_equal(
|
204
|
+
"<optgroup label=\"Europe\"><option value=\"Denmark\">Denmark</option>\n<option value=\"Germany\">Germany</option></optgroup><optgroup label=\"North America\"><option value=\"United States\">United States</option>\n<option value=\"Canada\">Canada</option></optgroup>",
|
205
|
+
grouped_options_for_select({'North America' => ['United States','Canada'], 'Europe' => ['Denmark','Germany']})
|
206
|
+
)
|
207
|
+
end
|
210
208
|
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
209
|
+
def test_time_zone_options_no_parms
|
210
|
+
opts = time_zone_options_for_select
|
211
|
+
assert_dom_equal "<option value=\"A\">A</option>\n" +
|
212
|
+
"<option value=\"B\">B</option>\n" +
|
213
|
+
"<option value=\"C\">C</option>\n" +
|
214
|
+
"<option value=\"D\">D</option>\n" +
|
215
|
+
"<option value=\"E\">E</option>",
|
216
|
+
opts
|
217
|
+
end
|
219
218
|
|
220
|
-
|
221
|
-
|
222
|
-
|
219
|
+
def test_time_zone_options_with_selected
|
220
|
+
opts = time_zone_options_for_select( "D" )
|
221
|
+
assert_dom_equal "<option value=\"A\">A</option>\n" +
|
222
|
+
"<option value=\"B\">B</option>\n" +
|
223
|
+
"<option value=\"C\">C</option>\n" +
|
224
|
+
"<option value=\"D\" selected=\"selected\">D</option>\n" +
|
225
|
+
"<option value=\"E\">E</option>",
|
226
|
+
opts
|
227
|
+
end
|
223
228
|
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
229
|
+
def test_time_zone_options_with_unknown_selected
|
230
|
+
opts = time_zone_options_for_select( "K" )
|
231
|
+
assert_dom_equal "<option value=\"A\">A</option>\n" +
|
232
|
+
"<option value=\"B\">B</option>\n" +
|
233
|
+
"<option value=\"C\">C</option>\n" +
|
234
|
+
"<option value=\"D\">D</option>\n" +
|
235
|
+
"<option value=\"E\">E</option>",
|
236
|
+
opts
|
237
|
+
end
|
233
238
|
|
234
|
-
|
235
|
-
|
236
|
-
|
239
|
+
def test_time_zone_options_with_priority_zones
|
240
|
+
zones = [ ActiveSupport::TimeZone.new( "B" ), ActiveSupport::TimeZone.new( "E" ) ]
|
241
|
+
opts = time_zone_options_for_select( nil, zones )
|
242
|
+
assert_dom_equal "<option value=\"B\">B</option>\n" +
|
243
|
+
"<option value=\"E\">E</option>" +
|
244
|
+
"<option value=\"\" disabled=\"disabled\">-------------</option>\n" +
|
245
|
+
"<option value=\"A\">A</option>\n" +
|
246
|
+
"<option value=\"C\">C</option>\n" +
|
247
|
+
"<option value=\"D\">D</option>",
|
248
|
+
opts
|
249
|
+
end
|
237
250
|
|
238
|
-
|
239
|
-
|
240
|
-
|
251
|
+
def test_time_zone_options_with_selected_priority_zones
|
252
|
+
zones = [ ActiveSupport::TimeZone.new( "B" ), ActiveSupport::TimeZone.new( "E" ) ]
|
253
|
+
opts = time_zone_options_for_select( "E", zones )
|
254
|
+
assert_dom_equal "<option value=\"B\">B</option>\n" +
|
255
|
+
"<option value=\"E\" selected=\"selected\">E</option>" +
|
256
|
+
"<option value=\"\" disabled=\"disabled\">-------------</option>\n" +
|
257
|
+
"<option value=\"A\">A</option>\n" +
|
258
|
+
"<option value=\"C\">C</option>\n" +
|
259
|
+
"<option value=\"D\">D</option>",
|
260
|
+
opts
|
261
|
+
end
|
241
262
|
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
263
|
+
def test_time_zone_options_with_unselected_priority_zones
|
264
|
+
zones = [ ActiveSupport::TimeZone.new( "B" ), ActiveSupport::TimeZone.new( "E" ) ]
|
265
|
+
opts = time_zone_options_for_select( "C", zones )
|
266
|
+
assert_dom_equal "<option value=\"B\">B</option>\n" +
|
267
|
+
"<option value=\"E\">E</option>" +
|
268
|
+
"<option value=\"\" disabled=\"disabled\">-------------</option>\n" +
|
269
|
+
"<option value=\"A\">A</option>\n" +
|
270
|
+
"<option value=\"C\" selected=\"selected\">C</option>\n" +
|
271
|
+
"<option value=\"D\">D</option>",
|
272
|
+
opts
|
273
|
+
end
|
247
274
|
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
275
|
+
def test_select
|
276
|
+
@post = Post.new
|
277
|
+
@post.category = "<mus>"
|
278
|
+
assert_dom_equal(
|
279
|
+
"<select id=\"post_category\" name=\"post[category]\"><option value=\"abe\">abe</option>\n<option value=\"<mus>\" selected=\"selected\"><mus></option>\n<option value=\"hest\">hest</option></select>",
|
280
|
+
select("post", "category", %w( abe <mus> hest))
|
281
|
+
)
|
282
|
+
end
|
252
283
|
|
253
|
-
|
254
|
-
|
255
|
-
|
284
|
+
def test_select_under_fields_for
|
285
|
+
@post = Post.new
|
286
|
+
@post.category = "<mus>"
|
256
287
|
|
257
|
-
|
258
|
-
|
259
|
-
output_buffer
|
260
|
-
)
|
288
|
+
fields_for :post, @post do |f|
|
289
|
+
concat f.select(:category, %w( abe <mus> hest))
|
261
290
|
end
|
291
|
+
|
292
|
+
assert_dom_equal(
|
293
|
+
"<select id=\"post_category\" name=\"post[category]\"><option value=\"abe\">abe</option>\n<option value=\"<mus>\" selected=\"selected\"><mus></option>\n<option value=\"hest\">hest</option></select>",
|
294
|
+
output_buffer
|
295
|
+
)
|
296
|
+
end
|
262
297
|
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
assert_dom_equal(
|
267
|
-
"<select id=\"post_category\" name=\"post[category]\"><option value=\"\"></option>\n<option value=\"abe\">abe</option>\n<option value=\"<mus>\" selected=\"selected\"><mus></option>\n<option value=\"hest\">hest</option></select>",
|
268
|
-
select("post", "category", %w( abe <mus> hest), :include_blank => true)
|
269
|
-
)
|
270
|
-
end
|
298
|
+
def test_select_under_fields_for_with_index
|
299
|
+
@post = Post.new
|
300
|
+
@post.category = "<mus>"
|
271
301
|
|
272
|
-
|
273
|
-
|
274
|
-
@post.category = "<mus>"
|
275
|
-
assert_dom_equal(
|
276
|
-
"<select id=\"post_category\" name=\"post[category]\"><option value=\"\">None</option>\n<option value=\"abe\">abe</option>\n<option value=\"<mus>\" selected=\"selected\"><mus></option>\n<option value=\"hest\">hest</option></select>",
|
277
|
-
select("post", "category", %w( abe <mus> hest), :include_blank => 'None')
|
278
|
-
)
|
302
|
+
fields_for :post, @post, :index => 108 do |f|
|
303
|
+
concat f.select(:category, %w( abe <mus> hest))
|
279
304
|
end
|
280
305
|
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
select("post", "category", %w( abe <mus> hest), :prompt => true)
|
287
|
-
)
|
288
|
-
end
|
306
|
+
assert_dom_equal(
|
307
|
+
"<select id=\"post_108_category\" name=\"post[108][category]\"><option value=\"abe\">abe</option>\n<option value=\"<mus>\" selected=\"selected\"><mus></option>\n<option value=\"hest\">hest</option></select>",
|
308
|
+
output_buffer
|
309
|
+
)
|
310
|
+
end
|
289
311
|
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
"<select id=\"post_category\" name=\"post[category]\"><option value=\"abe\">abe</option>\n<option value=\"<mus>\" selected=\"selected\"><mus></option>\n<option value=\"hest\">hest</option></select>",
|
295
|
-
select("post", "category", %w( abe <mus> hest), :prompt => true)
|
296
|
-
)
|
297
|
-
end
|
312
|
+
def test_select_under_fields_for_with_auto_index
|
313
|
+
@post = Post.new
|
314
|
+
@post.category = "<mus>"
|
315
|
+
def @post.to_param; 108; end
|
298
316
|
|
299
|
-
|
300
|
-
|
301
|
-
@post.category = ""
|
302
|
-
assert_dom_equal(
|
303
|
-
"<select id=\"post_category\" name=\"post[category]\"><option value=\"\">The prompt</option>\n<option value=\"abe\">abe</option>\n<option value=\"<mus>\"><mus></option>\n<option value=\"hest\">hest</option></select>",
|
304
|
-
select("post", "category", %w( abe <mus> hest), :prompt => 'The prompt')
|
305
|
-
)
|
317
|
+
fields_for "post[]", @post do |f|
|
318
|
+
concat f.select(:category, %w( abe <mus> hest))
|
306
319
|
end
|
307
320
|
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
select("post", "category", %w( abe <mus> hest), :prompt => true, :include_blank => true)
|
314
|
-
)
|
315
|
-
end
|
321
|
+
assert_dom_equal(
|
322
|
+
"<select id=\"post_108_category\" name=\"post[108][category]\"><option value=\"abe\">abe</option>\n<option value=\"<mus>\" selected=\"selected\"><mus></option>\n<option value=\"hest\">hest</option></select>",
|
323
|
+
output_buffer
|
324
|
+
)
|
325
|
+
end
|
316
326
|
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
327
|
+
def test_select_with_blank
|
328
|
+
@post = Post.new
|
329
|
+
@post.category = "<mus>"
|
330
|
+
assert_dom_equal(
|
331
|
+
"<select id=\"post_category\" name=\"post[category]\"><option value=\"\"></option>\n<option value=\"abe\">abe</option>\n<option value=\"<mus>\" selected=\"selected\"><mus></option>\n<option value=\"hest\">hest</option></select>",
|
332
|
+
select("post", "category", %w( abe <mus> hest), :include_blank => true)
|
333
|
+
)
|
334
|
+
end
|
335
|
+
|
336
|
+
def test_select_with_blank_as_string
|
337
|
+
@post = Post.new
|
338
|
+
@post.category = "<mus>"
|
339
|
+
assert_dom_equal(
|
340
|
+
"<select id=\"post_category\" name=\"post[category]\"><option value=\"\">None</option>\n<option value=\"abe\">abe</option>\n<option value=\"<mus>\" selected=\"selected\"><mus></option>\n<option value=\"hest\">hest</option></select>",
|
341
|
+
select("post", "category", %w( abe <mus> hest), :include_blank => 'None')
|
342
|
+
)
|
343
|
+
end
|
344
|
+
|
345
|
+
def test_select_with_default_prompt
|
346
|
+
@post = Post.new
|
347
|
+
@post.category = ""
|
348
|
+
assert_dom_equal(
|
349
|
+
"<select id=\"post_category\" name=\"post[category]\"><option value=\"\">Please select</option>\n<option value=\"abe\">abe</option>\n<option value=\"<mus>\"><mus></option>\n<option value=\"hest\">hest</option></select>",
|
350
|
+
select("post", "category", %w( abe <mus> hest), :prompt => true)
|
351
|
+
)
|
352
|
+
end
|
353
|
+
|
354
|
+
def test_select_no_prompt_when_select_has_value
|
355
|
+
@post = Post.new
|
356
|
+
@post.category = "<mus>"
|
357
|
+
assert_dom_equal(
|
358
|
+
"<select id=\"post_category\" name=\"post[category]\"><option value=\"abe\">abe</option>\n<option value=\"<mus>\" selected=\"selected\"><mus></option>\n<option value=\"hest\">hest</option></select>",
|
359
|
+
select("post", "category", %w( abe <mus> hest), :prompt => true)
|
360
|
+
)
|
361
|
+
end
|
362
|
+
|
363
|
+
def test_select_with_given_prompt
|
364
|
+
@post = Post.new
|
365
|
+
@post.category = ""
|
366
|
+
assert_dom_equal(
|
367
|
+
"<select id=\"post_category\" name=\"post[category]\"><option value=\"\">The prompt</option>\n<option value=\"abe\">abe</option>\n<option value=\"<mus>\"><mus></option>\n<option value=\"hest\">hest</option></select>",
|
368
|
+
select("post", "category", %w( abe <mus> hest), :prompt => 'The prompt')
|
369
|
+
)
|
370
|
+
end
|
371
|
+
|
372
|
+
def test_select_with_prompt_and_blank
|
373
|
+
@post = Post.new
|
374
|
+
@post.category = ""
|
375
|
+
assert_dom_equal(
|
376
|
+
"<select id=\"post_category\" name=\"post[category]\"><option value=\"\">Please select</option>\n<option value=\"\"></option>\n<option value=\"abe\">abe</option>\n<option value=\"<mus>\"><mus></option>\n<option value=\"hest\">hest</option></select>",
|
377
|
+
select("post", "category", %w( abe <mus> hest), :prompt => true, :include_blank => true)
|
378
|
+
)
|
379
|
+
end
|
380
|
+
|
381
|
+
def test_select_with_selected_value
|
382
|
+
@post = Post.new
|
383
|
+
@post.category = "<mus>"
|
384
|
+
assert_dom_equal(
|
385
|
+
"<select id=\"post_category\" name=\"post[category]\"><option value=\"abe\" selected=\"selected\">abe</option>\n<option value=\"<mus>\"><mus></option>\n<option value=\"hest\">hest</option></select>",
|
386
|
+
select("post", "category", %w( abe <mus> hest ), :selected => 'abe')
|
387
|
+
)
|
388
|
+
end
|
389
|
+
|
390
|
+
def test_select_with_index_option
|
391
|
+
@album = Album.new
|
392
|
+
@album.id = 1
|
325
393
|
|
326
|
-
|
327
|
-
@album = Album.new
|
328
|
-
@album.id = 1
|
329
|
-
|
330
|
-
expected = "<select id=\"album__genre\" name=\"album[][genre]\"><option value=\"rap\">rap</option>\n<option value=\"rock\">rock</option>\n<option value=\"country\">country</option></select>"
|
394
|
+
expected = "<select id=\"album__genre\" name=\"album[][genre]\"><option value=\"rap\">rap</option>\n<option value=\"rock\">rock</option>\n<option value=\"country\">country</option></select>"
|
331
395
|
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
396
|
+
assert_dom_equal(
|
397
|
+
expected,
|
398
|
+
select("album[]", "genre", %w[rap rock country], {}, { :index => nil })
|
399
|
+
)
|
400
|
+
end
|
337
401
|
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
402
|
+
def test_select_with_selected_nil
|
403
|
+
@post = Post.new
|
404
|
+
@post.category = "<mus>"
|
405
|
+
assert_dom_equal(
|
406
|
+
"<select id=\"post_category\" name=\"post[category]\"><option value=\"abe\">abe</option>\n<option value=\"<mus>\"><mus></option>\n<option value=\"hest\">hest</option></select>",
|
407
|
+
select("post", "category", %w( abe <mus> hest ), :selected => nil)
|
408
|
+
)
|
409
|
+
end
|
346
410
|
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
411
|
+
def test_select_with_disabled_value
|
412
|
+
@post = Post.new
|
413
|
+
@post.category = "<mus>"
|
414
|
+
assert_dom_equal(
|
415
|
+
"<select id=\"post_category\" name=\"post[category]\"><option value=\"abe\">abe</option>\n<option value=\"<mus>\" selected=\"selected\"><mus></option>\n<option value=\"hest\" disabled=\"disabled\">hest</option></select>",
|
416
|
+
select("post", "category", %w( abe <mus> hest ), :disabled => 'hest')
|
417
|
+
)
|
418
|
+
end
|
353
419
|
|
354
|
-
|
355
|
-
|
420
|
+
def test_select_with_disabled_array
|
421
|
+
@post = Post.new
|
422
|
+
@post.category = "<mus>"
|
423
|
+
assert_dom_equal(
|
424
|
+
"<select id=\"post_category\" name=\"post[category]\"><option value=\"abe\" disabled=\"disabled\">abe</option>\n<option value=\"<mus>\" selected=\"selected\"><mus></option>\n<option value=\"hest\" disabled=\"disabled\">hest</option></select>",
|
425
|
+
select("post", "category", %w( abe <mus> hest ), :disabled => ['hest', 'abe'])
|
426
|
+
)
|
427
|
+
end
|
356
428
|
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
)
|
361
|
-
end
|
429
|
+
def test_collection_select
|
430
|
+
@post = Post.new
|
431
|
+
@post.author_name = "Babe"
|
362
432
|
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
]
|
433
|
+
assert_dom_equal(
|
434
|
+
"<select id=\"post_author_name\" name=\"post[author_name]\"><option value=\"<Abe>\"><Abe></option>\n<option value=\"Babe\" selected=\"selected\">Babe</option>\n<option value=\"Cabe\">Cabe</option></select>",
|
435
|
+
collection_select("post", "author_name", dummy_posts, "author_name", "author_name")
|
436
|
+
)
|
437
|
+
end
|
369
438
|
|
370
|
-
|
371
|
-
|
439
|
+
def test_collection_select_under_fields_for
|
440
|
+
@post = Post.new
|
441
|
+
@post.author_name = "Babe"
|
372
442
|
|
373
|
-
|
374
|
-
|
375
|
-
end
|
376
|
-
|
377
|
-
assert_dom_equal(
|
378
|
-
"<select id=\"post_author_name\" name=\"post[author_name]\"><option value=\"<Abe>\"><Abe></option>\n<option value=\"Babe\" selected=\"selected\">Babe</option>\n<option value=\"Cabe\">Cabe</option></select>",
|
379
|
-
output_buffer
|
380
|
-
)
|
443
|
+
fields_for :post, @post do |f|
|
444
|
+
concat f.collection_select(:author_name, dummy_posts, :author_name, :author_name)
|
381
445
|
end
|
446
|
+
|
447
|
+
assert_dom_equal(
|
448
|
+
"<select id=\"post_author_name\" name=\"post[author_name]\"><option value=\"<Abe>\"><Abe></option>\n<option value=\"Babe\" selected=\"selected\">Babe</option>\n<option value=\"Cabe\">Cabe</option></select>",
|
449
|
+
output_buffer
|
450
|
+
)
|
451
|
+
end
|
382
452
|
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
453
|
+
def test_collection_select_under_fields_for_with_index
|
454
|
+
@post = Post.new
|
455
|
+
@post.author_name = "Babe"
|
456
|
+
|
457
|
+
fields_for :post, @post, :index => 815 do |f|
|
458
|
+
concat f.collection_select(:author_name, dummy_posts, :author_name, :author_name)
|
459
|
+
end
|
389
460
|
|
390
|
-
|
391
|
-
|
461
|
+
assert_dom_equal(
|
462
|
+
"<select id=\"post_815_author_name\" name=\"post[815][author_name]\"><option value=\"<Abe>\"><Abe></option>\n<option value=\"Babe\" selected=\"selected\">Babe</option>\n<option value=\"Cabe\">Cabe</option></select>",
|
463
|
+
output_buffer
|
464
|
+
)
|
465
|
+
end
|
392
466
|
|
393
|
-
|
394
|
-
|
395
|
-
|
467
|
+
def test_collection_select_under_fields_for_with_auto_index
|
468
|
+
@post = Post.new
|
469
|
+
@post.author_name = "Babe"
|
470
|
+
def @post.to_param; 815; end
|
396
471
|
|
397
|
-
|
398
|
-
|
399
|
-
output_buffer
|
400
|
-
)
|
472
|
+
fields_for "post[]", @post do |f|
|
473
|
+
concat f.collection_select(:author_name, dummy_posts, :author_name, :author_name)
|
401
474
|
end
|
402
475
|
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
]
|
476
|
+
assert_dom_equal(
|
477
|
+
"<select id=\"post_815_author_name\" name=\"post[815][author_name]\"><option value=\"<Abe>\"><Abe></option>\n<option value=\"Babe\" selected=\"selected\">Babe</option>\n<option value=\"Cabe\">Cabe</option></select>",
|
478
|
+
output_buffer
|
479
|
+
)
|
480
|
+
end
|
409
481
|
|
410
|
-
|
411
|
-
|
412
|
-
|
482
|
+
def test_collection_select_with_blank_and_style
|
483
|
+
@post = Post.new
|
484
|
+
@post.author_name = "Babe"
|
413
485
|
|
414
|
-
|
415
|
-
|
416
|
-
|
486
|
+
assert_dom_equal(
|
487
|
+
"<select id=\"post_author_name\" name=\"post[author_name]\" style=\"width: 200px\"><option value=\"\"></option>\n<option value=\"<Abe>\"><Abe></option>\n<option value=\"Babe\" selected=\"selected\">Babe</option>\n<option value=\"Cabe\">Cabe</option></select>",
|
488
|
+
collection_select("post", "author_name", dummy_posts, "author_name", "author_name", { :include_blank => true }, "style" => "width: 200px")
|
489
|
+
)
|
490
|
+
end
|
417
491
|
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
)
|
422
|
-
end
|
492
|
+
def test_collection_select_with_blank_as_string_and_style
|
493
|
+
@post = Post.new
|
494
|
+
@post.author_name = "Babe"
|
423
495
|
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
]
|
496
|
+
assert_dom_equal(
|
497
|
+
"<select id=\"post_author_name\" name=\"post[author_name]\" style=\"width: 200px\"><option value=\"\">No Selection</option>\n<option value=\"<Abe>\"><Abe></option>\n<option value=\"Babe\" selected=\"selected\">Babe</option>\n<option value=\"Cabe\">Cabe</option></select>",
|
498
|
+
collection_select("post", "author_name", dummy_posts, "author_name", "author_name", { :include_blank => 'No Selection' }, "style" => "width: 200px")
|
499
|
+
)
|
500
|
+
end
|
430
501
|
|
431
|
-
|
432
|
-
|
502
|
+
def test_collection_select_with_multiple_option_appends_array_brackets
|
503
|
+
@post = Post.new
|
504
|
+
@post.author_name = "Babe"
|
433
505
|
|
434
|
-
|
435
|
-
"<select id=\"post_author_name\" name=\"post[author_name]\" style=\"width: 200px\"><option value=\"\"></option>\n<option value=\"<Abe>\"><Abe></option>\n<option value=\"Babe\" selected=\"selected\">Babe</option>\n<option value=\"Cabe\">Cabe</option></select>",
|
436
|
-
collection_select("post", "author_name", @posts, "author_name", "author_name", { :include_blank => true }, "style" => "width: 200px")
|
437
|
-
)
|
438
|
-
end
|
506
|
+
expected = "<select id=\"post_author_name\" name=\"post[author_name][]\" multiple=\"multiple\"><option value=\"\"></option>\n<option value=\"<Abe>\"><Abe></option>\n<option value=\"Babe\" selected=\"selected\">Babe</option>\n<option value=\"Cabe\">Cabe</option></select>"
|
439
507
|
|
440
|
-
|
441
|
-
|
442
|
-
Post.new("<Abe> went home", "<Abe>", "To a little house", "shh!"),
|
443
|
-
Post.new("Babe went home", "Babe", "To a little house", "shh!"),
|
444
|
-
Post.new("Cabe went home", "Cabe", "To a little house", "shh!")
|
445
|
-
]
|
508
|
+
# Should suffix default name with [].
|
509
|
+
assert_dom_equal expected, collection_select("post", "author_name", dummy_posts, "author_name", "author_name", { :include_blank => true }, :multiple => true)
|
446
510
|
|
447
|
-
|
448
|
-
|
511
|
+
# Shouldn't suffix custom name with [].
|
512
|
+
assert_dom_equal expected, collection_select("post", "author_name", dummy_posts, "author_name", "author_name", { :include_blank => true, :name => 'post[author_name][]' }, :multiple => true)
|
513
|
+
end
|
449
514
|
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
)
|
454
|
-
end
|
515
|
+
def test_collection_select_with_blank_and_selected
|
516
|
+
@post = Post.new
|
517
|
+
@post.author_name = "Babe"
|
455
518
|
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
]
|
519
|
+
assert_dom_equal(
|
520
|
+
%{<select id="post_author_name" name="post[author_name]"><option value=""></option>\n<option value="<Abe>" selected="selected"><Abe></option>\n<option value="Babe">Babe</option>\n<option value="Cabe">Cabe</option></select>},
|
521
|
+
collection_select("post", "author_name", dummy_posts, "author_name", "author_name", {:include_blank => true, :selected => "<Abe>"})
|
522
|
+
)
|
523
|
+
end
|
462
524
|
|
463
|
-
|
464
|
-
|
525
|
+
def test_collection_select_with_disabled
|
526
|
+
@post = Post.new
|
527
|
+
@post.author_name = "Babe"
|
465
528
|
|
466
|
-
|
529
|
+
assert_dom_equal(
|
530
|
+
"<select id=\"post_author_name\" name=\"post[author_name]\"><option value=\"<Abe>\"><Abe></option>\n<option value=\"Babe\" selected=\"selected\">Babe</option>\n<option value=\"Cabe\" disabled=\"disabled\">Cabe</option></select>",
|
531
|
+
collection_select("post", "author_name", dummy_posts, "author_name", "author_name", :disabled => 'Cabe')
|
532
|
+
)
|
533
|
+
end
|
467
534
|
|
468
|
-
|
469
|
-
|
535
|
+
def test_time_zone_select
|
536
|
+
@firm = Firm.new("D")
|
537
|
+
html = time_zone_select( "firm", "time_zone" )
|
538
|
+
assert_dom_equal "<select id=\"firm_time_zone\" name=\"firm[time_zone]\">" +
|
539
|
+
"<option value=\"A\">A</option>\n" +
|
540
|
+
"<option value=\"B\">B</option>\n" +
|
541
|
+
"<option value=\"C\">C</option>\n" +
|
542
|
+
"<option value=\"D\" selected=\"selected\">D</option>\n" +
|
543
|
+
"<option value=\"E\">E</option>" +
|
544
|
+
"</select>",
|
545
|
+
html
|
546
|
+
end
|
470
547
|
|
471
|
-
|
472
|
-
|
473
|
-
end
|
548
|
+
def test_time_zone_select_under_fields_for
|
549
|
+
@firm = Firm.new("D")
|
474
550
|
|
475
|
-
|
476
|
-
|
477
|
-
html = time_zone_select( "firm", "time_zone" )
|
478
|
-
assert_dom_equal "<select id=\"firm_time_zone\" name=\"firm[time_zone]\">" +
|
479
|
-
"<option value=\"A\">A</option>\n" +
|
480
|
-
"<option value=\"B\">B</option>\n" +
|
481
|
-
"<option value=\"C\">C</option>\n" +
|
482
|
-
"<option value=\"D\" selected=\"selected\">D</option>\n" +
|
483
|
-
"<option value=\"E\">E</option>" +
|
484
|
-
"</select>",
|
485
|
-
html
|
551
|
+
fields_for :firm, @firm do |f|
|
552
|
+
concat f.time_zone_select(:time_zone)
|
486
553
|
end
|
554
|
+
|
555
|
+
assert_dom_equal(
|
556
|
+
"<select id=\"firm_time_zone\" name=\"firm[time_zone]\">" +
|
557
|
+
"<option value=\"A\">A</option>\n" +
|
558
|
+
"<option value=\"B\">B</option>\n" +
|
559
|
+
"<option value=\"C\">C</option>\n" +
|
560
|
+
"<option value=\"D\" selected=\"selected\">D</option>\n" +
|
561
|
+
"<option value=\"E\">E</option>" +
|
562
|
+
"</select>",
|
563
|
+
output_buffer
|
564
|
+
)
|
565
|
+
end
|
487
566
|
|
488
|
-
|
489
|
-
|
567
|
+
def test_time_zone_select_under_fields_for_with_index
|
568
|
+
@firm = Firm.new("D")
|
490
569
|
|
491
|
-
|
492
|
-
|
493
|
-
end
|
494
|
-
|
495
|
-
assert_dom_equal(
|
496
|
-
"<select id=\"firm_time_zone\" name=\"firm[time_zone]\">" +
|
497
|
-
"<option value=\"A\">A</option>\n" +
|
498
|
-
"<option value=\"B\">B</option>\n" +
|
499
|
-
"<option value=\"C\">C</option>\n" +
|
500
|
-
"<option value=\"D\" selected=\"selected\">D</option>\n" +
|
501
|
-
"<option value=\"E\">E</option>" +
|
502
|
-
"</select>",
|
503
|
-
output_buffer
|
504
|
-
)
|
570
|
+
fields_for :firm, @firm, :index => 305 do |f|
|
571
|
+
concat f.time_zone_select(:time_zone)
|
505
572
|
end
|
506
573
|
|
507
|
-
|
508
|
-
|
574
|
+
assert_dom_equal(
|
575
|
+
"<select id=\"firm_305_time_zone\" name=\"firm[305][time_zone]\">" +
|
576
|
+
"<option value=\"A\">A</option>\n" +
|
577
|
+
"<option value=\"B\">B</option>\n" +
|
578
|
+
"<option value=\"C\">C</option>\n" +
|
579
|
+
"<option value=\"D\" selected=\"selected\">D</option>\n" +
|
580
|
+
"<option value=\"E\">E</option>" +
|
581
|
+
"</select>",
|
582
|
+
output_buffer
|
583
|
+
)
|
584
|
+
end
|
509
585
|
|
510
|
-
|
511
|
-
|
512
|
-
|
586
|
+
def test_time_zone_select_under_fields_for_with_auto_index
|
587
|
+
@firm = Firm.new("D")
|
588
|
+
def @firm.to_param; 305; end
|
513
589
|
|
514
|
-
|
515
|
-
|
516
|
-
"<option value=\"A\">A</option>\n" +
|
517
|
-
"<option value=\"B\">B</option>\n" +
|
518
|
-
"<option value=\"C\">C</option>\n" +
|
519
|
-
"<option value=\"D\" selected=\"selected\">D</option>\n" +
|
520
|
-
"<option value=\"E\">E</option>" +
|
521
|
-
"</select>",
|
522
|
-
output_buffer
|
523
|
-
)
|
590
|
+
fields_for "firm[]", @firm do |f|
|
591
|
+
concat f.time_zone_select(:time_zone)
|
524
592
|
end
|
525
593
|
|
526
|
-
|
527
|
-
|
528
|
-
|
594
|
+
assert_dom_equal(
|
595
|
+
"<select id=\"firm_305_time_zone\" name=\"firm[305][time_zone]\">" +
|
596
|
+
"<option value=\"A\">A</option>\n" +
|
597
|
+
"<option value=\"B\">B</option>\n" +
|
598
|
+
"<option value=\"C\">C</option>\n" +
|
599
|
+
"<option value=\"D\" selected=\"selected\">D</option>\n" +
|
600
|
+
"<option value=\"E\">E</option>" +
|
601
|
+
"</select>",
|
602
|
+
output_buffer
|
603
|
+
)
|
604
|
+
end
|
529
605
|
|
530
|
-
|
531
|
-
|
532
|
-
|
606
|
+
def test_time_zone_select_with_blank
|
607
|
+
@firm = Firm.new("D")
|
608
|
+
html = time_zone_select("firm", "time_zone", nil, :include_blank => true)
|
609
|
+
assert_dom_equal "<select id=\"firm_time_zone\" name=\"firm[time_zone]\">" +
|
610
|
+
"<option value=\"\"></option>\n" +
|
611
|
+
"<option value=\"A\">A</option>\n" +
|
612
|
+
"<option value=\"B\">B</option>\n" +
|
613
|
+
"<option value=\"C\">C</option>\n" +
|
614
|
+
"<option value=\"D\" selected=\"selected\">D</option>\n" +
|
615
|
+
"<option value=\"E\">E</option>" +
|
616
|
+
"</select>",
|
617
|
+
html
|
618
|
+
end
|
533
619
|
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
620
|
+
def test_time_zone_select_with_blank_as_string
|
621
|
+
@firm = Firm.new("D")
|
622
|
+
html = time_zone_select("firm", "time_zone", nil, :include_blank => 'No Zone')
|
623
|
+
assert_dom_equal "<select id=\"firm_time_zone\" name=\"firm[time_zone]\">" +
|
624
|
+
"<option value=\"\">No Zone</option>\n" +
|
625
|
+
"<option value=\"A\">A</option>\n" +
|
626
|
+
"<option value=\"B\">B</option>\n" +
|
627
|
+
"<option value=\"C\">C</option>\n" +
|
628
|
+
"<option value=\"D\" selected=\"selected\">D</option>\n" +
|
629
|
+
"<option value=\"E\">E</option>" +
|
630
|
+
"</select>",
|
631
|
+
html
|
632
|
+
end
|
545
633
|
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
634
|
+
def test_time_zone_select_with_style
|
635
|
+
@firm = Firm.new("D")
|
636
|
+
html = time_zone_select("firm", "time_zone", nil, {},
|
637
|
+
"style" => "color: red")
|
638
|
+
assert_dom_equal "<select id=\"firm_time_zone\" name=\"firm[time_zone]\" style=\"color: red\">" +
|
639
|
+
"<option value=\"A\">A</option>\n" +
|
640
|
+
"<option value=\"B\">B</option>\n" +
|
641
|
+
"<option value=\"C\">C</option>\n" +
|
642
|
+
"<option value=\"D\" selected=\"selected\">D</option>\n" +
|
643
|
+
"<option value=\"E\">E</option>" +
|
644
|
+
"</select>",
|
645
|
+
html
|
646
|
+
assert_dom_equal html, time_zone_select("firm", "time_zone", nil, {},
|
647
|
+
:style => "color: red")
|
648
|
+
end
|
559
649
|
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
650
|
+
def test_time_zone_select_with_blank_and_style
|
651
|
+
@firm = Firm.new("D")
|
652
|
+
html = time_zone_select("firm", "time_zone", nil,
|
653
|
+
{ :include_blank => true }, "style" => "color: red")
|
654
|
+
assert_dom_equal "<select id=\"firm_time_zone\" name=\"firm[time_zone]\" style=\"color: red\">" +
|
655
|
+
"<option value=\"\"></option>\n" +
|
656
|
+
"<option value=\"A\">A</option>\n" +
|
657
|
+
"<option value=\"B\">B</option>\n" +
|
658
|
+
"<option value=\"C\">C</option>\n" +
|
659
|
+
"<option value=\"D\" selected=\"selected\">D</option>\n" +
|
660
|
+
"<option value=\"E\">E</option>" +
|
661
|
+
"</select>",
|
662
|
+
html
|
663
|
+
assert_dom_equal html, time_zone_select("firm", "time_zone", nil,
|
664
|
+
{ :include_blank => true }, :style => "color: red")
|
665
|
+
end
|
573
666
|
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
667
|
+
def test_time_zone_select_with_blank_as_string_and_style
|
668
|
+
@firm = Firm.new("D")
|
669
|
+
html = time_zone_select("firm", "time_zone", nil,
|
670
|
+
{ :include_blank => 'No Zone' }, "style" => "color: red")
|
671
|
+
assert_dom_equal "<select id=\"firm_time_zone\" name=\"firm[time_zone]\" style=\"color: red\">" +
|
672
|
+
"<option value=\"\">No Zone</option>\n" +
|
673
|
+
"<option value=\"A\">A</option>\n" +
|
674
|
+
"<option value=\"B\">B</option>\n" +
|
675
|
+
"<option value=\"C\">C</option>\n" +
|
676
|
+
"<option value=\"D\" selected=\"selected\">D</option>\n" +
|
677
|
+
"<option value=\"E\">E</option>" +
|
678
|
+
"</select>",
|
679
|
+
html
|
680
|
+
assert_dom_equal html, time_zone_select("firm", "time_zone", nil,
|
681
|
+
{ :include_blank => 'No Zone' }, :style => "color: red")
|
682
|
+
end
|
589
683
|
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
{ :include_blank => true }, :style => "color: red")
|
605
|
-
end
|
684
|
+
def test_time_zone_select_with_priority_zones
|
685
|
+
@firm = Firm.new("D")
|
686
|
+
zones = [ ActiveSupport::TimeZone.new("A"), ActiveSupport::TimeZone.new("D") ]
|
687
|
+
html = time_zone_select("firm", "time_zone", zones )
|
688
|
+
assert_dom_equal "<select id=\"firm_time_zone\" name=\"firm[time_zone]\">" +
|
689
|
+
"<option value=\"A\">A</option>\n" +
|
690
|
+
"<option value=\"D\" selected=\"selected\">D</option>" +
|
691
|
+
"<option value=\"\" disabled=\"disabled\">-------------</option>\n" +
|
692
|
+
"<option value=\"B\">B</option>\n" +
|
693
|
+
"<option value=\"C\">C</option>\n" +
|
694
|
+
"<option value=\"E\">E</option>" +
|
695
|
+
"</select>",
|
696
|
+
html
|
697
|
+
end
|
606
698
|
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
699
|
+
def test_time_zone_select_with_priority_zones_as_regexp
|
700
|
+
@firm = Firm.new("D")
|
701
|
+
@fake_timezones.each_with_index do |tz, i|
|
702
|
+
tz.stubs(:=~).returns(i.zero? || i == 3)
|
703
|
+
end
|
704
|
+
|
705
|
+
html = time_zone_select("firm", "time_zone", /A|D/)
|
706
|
+
assert_dom_equal "<select id=\"firm_time_zone\" name=\"firm[time_zone]\">" +
|
707
|
+
"<option value=\"A\">A</option>\n" +
|
708
|
+
"<option value=\"D\" selected=\"selected\">D</option>" +
|
709
|
+
"<option value=\"\" disabled=\"disabled\">-------------</option>\n" +
|
710
|
+
"<option value=\"B\">B</option>\n" +
|
711
|
+
"<option value=\"C\">C</option>\n" +
|
712
|
+
"<option value=\"E\">E</option>" +
|
713
|
+
"</select>",
|
714
|
+
html
|
715
|
+
end
|
623
716
|
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
html = time_zone_select("firm", "time_zone",
|
717
|
+
def test_time_zone_select_with_default_time_zone_and_nil_value
|
718
|
+
@firm = Firm.new()
|
719
|
+
@firm.time_zone = nil
|
720
|
+
html = time_zone_select( "firm", "time_zone", nil, :default => 'B' )
|
628
721
|
assert_dom_equal "<select id=\"firm_time_zone\" name=\"firm[time_zone]\">" +
|
629
722
|
"<option value=\"A\">A</option>\n" +
|
630
|
-
"<option value=\"
|
631
|
-
"<option value=\"\" disabled=\"disabled\">-------------</option>\n" +
|
632
|
-
"<option value=\"B\">B</option>\n" +
|
723
|
+
"<option value=\"B\" selected=\"selected\">B</option>\n" +
|
633
724
|
"<option value=\"C\">C</option>\n" +
|
725
|
+
"<option value=\"D\">D</option>\n" +
|
634
726
|
"<option value=\"E\">E</option>" +
|
635
727
|
"</select>",
|
636
728
|
html
|
637
|
-
|
638
|
-
|
639
|
-
def test_time_zone_select_with_priority_zones_as_regexp
|
640
|
-
@firm = Firm.new("D")
|
641
|
-
@fake_timezones.each_with_index do |tz, i|
|
642
|
-
tz.stubs(:=~).returns(i.zero? || i == 3)
|
643
|
-
end
|
729
|
+
end
|
644
730
|
|
645
|
-
|
731
|
+
def test_time_zone_select_with_default_time_zone_and_value
|
732
|
+
@firm = Firm.new('D')
|
733
|
+
html = time_zone_select( "firm", "time_zone", nil, :default => 'B' )
|
646
734
|
assert_dom_equal "<select id=\"firm_time_zone\" name=\"firm[time_zone]\">" +
|
647
735
|
"<option value=\"A\">A</option>\n" +
|
648
|
-
"<option value=\"D\" selected=\"selected\">D</option>" +
|
649
|
-
"<option value=\"\" disabled=\"disabled\">-------------</option>\n" +
|
650
736
|
"<option value=\"B\">B</option>\n" +
|
651
737
|
"<option value=\"C\">C</option>\n" +
|
738
|
+
"<option value=\"D\" selected=\"selected\">D</option>\n" +
|
652
739
|
"<option value=\"E\">E</option>" +
|
653
740
|
"</select>",
|
654
741
|
html
|
655
|
-
|
742
|
+
end
|
656
743
|
|
657
|
-
|
658
|
-
@firm = Firm.new()
|
659
|
-
@firm.time_zone = nil
|
660
|
-
html = time_zone_select( "firm", "time_zone", nil, :default => 'B' )
|
661
|
-
assert_dom_equal "<select id=\"firm_time_zone\" name=\"firm[time_zone]\">" +
|
662
|
-
"<option value=\"A\">A</option>\n" +
|
663
|
-
"<option value=\"B\" selected=\"selected\">B</option>\n" +
|
664
|
-
"<option value=\"C\">C</option>\n" +
|
665
|
-
"<option value=\"D\">D</option>\n" +
|
666
|
-
"<option value=\"E\">E</option>" +
|
667
|
-
"</select>",
|
668
|
-
html
|
669
|
-
end
|
744
|
+
private
|
670
745
|
|
671
|
-
def
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
"<option value=\"A\">A</option>\n" +
|
676
|
-
"<option value=\"B\">B</option>\n" +
|
677
|
-
"<option value=\"C\">C</option>\n" +
|
678
|
-
"<option value=\"D\" selected=\"selected\">D</option>\n" +
|
679
|
-
"<option value=\"E\">E</option>" +
|
680
|
-
"</select>",
|
681
|
-
html
|
746
|
+
def dummy_posts
|
747
|
+
[ Post.new("<Abe> went home", "<Abe>", "To a little house", "shh!"),
|
748
|
+
Post.new("Babe went home", "Babe", "To a little house", "shh!"),
|
749
|
+
Post.new("Cabe went home", "Cabe", "To a little house", "shh!") ]
|
682
750
|
end
|
683
|
-
|
684
|
-
end
|
685
|
-
end
|
751
|
+
end
|