actionpack 2.0.5 → 2.1.0
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 +149 -7
- data/MIT-LICENSE +1 -1
- data/README +1 -1
- data/Rakefile +5 -6
- data/lib/action_controller.rb +2 -2
- data/lib/action_controller/assertions/model_assertions.rb +2 -1
- data/lib/action_controller/assertions/response_assertions.rb +4 -2
- data/lib/action_controller/assertions/routing_assertions.rb +3 -3
- data/lib/action_controller/assertions/selector_assertions.rb +30 -27
- data/lib/action_controller/assertions/tag_assertions.rb +3 -3
- data/lib/action_controller/base.rb +103 -129
- data/lib/action_controller/benchmarking.rb +3 -3
- data/lib/action_controller/caching.rb +41 -652
- data/lib/action_controller/caching/actions.rb +144 -0
- data/lib/action_controller/caching/fragments.rb +138 -0
- data/lib/action_controller/caching/pages.rb +154 -0
- data/lib/action_controller/caching/sql_cache.rb +18 -0
- data/lib/action_controller/caching/sweeping.rb +97 -0
- data/lib/action_controller/cgi_ext/cookie.rb +27 -23
- data/lib/action_controller/cgi_ext/stdinput.rb +1 -0
- data/lib/action_controller/cgi_process.rb +6 -4
- data/lib/action_controller/components.rb +7 -6
- data/lib/action_controller/cookies.rb +31 -19
- data/lib/action_controller/dispatcher.rb +51 -84
- data/lib/action_controller/filters.rb +295 -421
- data/lib/action_controller/flash.rb +1 -6
- data/lib/action_controller/headers.rb +31 -0
- data/lib/action_controller/helpers.rb +26 -9
- data/lib/action_controller/http_authentication.rb +1 -1
- data/lib/action_controller/integration.rb +65 -13
- data/lib/action_controller/layout.rb +24 -39
- data/lib/action_controller/mime_responds.rb +7 -3
- data/lib/action_controller/mime_type.rb +25 -9
- data/lib/action_controller/mime_types.rb +1 -1
- data/lib/action_controller/polymorphic_routes.rb +32 -17
- data/lib/action_controller/record_identifier.rb +10 -4
- data/lib/action_controller/request.rb +46 -30
- data/lib/action_controller/request_forgery_protection.rb +10 -9
- data/lib/action_controller/request_profiler.rb +29 -8
- data/lib/action_controller/rescue.rb +24 -24
- data/lib/action_controller/resources.rb +66 -23
- data/lib/action_controller/response.rb +2 -2
- data/lib/action_controller/routing.rb +113 -1229
- data/lib/action_controller/routing/builder.rb +204 -0
- data/lib/action_controller/{routing_optimisation.rb → routing/optimisations.rb} +13 -12
- data/lib/action_controller/routing/recognition_optimisation.rb +158 -0
- data/lib/action_controller/routing/route.rb +240 -0
- data/lib/action_controller/routing/route_set.rb +435 -0
- data/lib/action_controller/routing/routing_ext.rb +46 -0
- data/lib/action_controller/routing/segments.rb +283 -0
- data/lib/action_controller/session/active_record_store.rb +13 -8
- data/lib/action_controller/session/cookie_store.rb +20 -17
- data/lib/action_controller/session_management.rb +10 -3
- data/lib/action_controller/streaming.rb +45 -31
- data/lib/action_controller/test_case.rb +33 -23
- data/lib/action_controller/test_process.rb +39 -35
- data/lib/action_controller/url_rewriter.rb +18 -12
- data/lib/action_controller/vendor/html-scanner/html/tokenizer.rb +1 -1
- data/lib/action_pack.rb +1 -1
- data/lib/action_pack/version.rb +2 -2
- data/lib/action_view.rb +11 -3
- data/lib/action_view/base.rb +73 -390
- data/lib/action_view/helpers/active_record_helper.rb +83 -62
- data/lib/action_view/helpers/asset_tag_helper.rb +101 -44
- data/lib/action_view/helpers/atom_feed_helper.rb +35 -7
- data/lib/action_view/helpers/benchmark_helper.rb +5 -3
- data/lib/action_view/helpers/cache_helper.rb +3 -2
- data/lib/action_view/helpers/capture_helper.rb +1 -2
- data/lib/action_view/helpers/date_helper.rb +104 -82
- data/lib/action_view/helpers/form_helper.rb +148 -75
- data/lib/action_view/helpers/form_options_helper.rb +44 -23
- data/lib/action_view/helpers/form_tag_helper.rb +22 -13
- data/lib/action_view/helpers/javascripts/controls.js +1 -1
- data/lib/action_view/helpers/javascripts/dragdrop.js +1 -1
- data/lib/action_view/helpers/javascripts/effects.js +1 -1
- data/lib/action_view/helpers/number_helper.rb +10 -3
- data/lib/action_view/helpers/prototype_helper.rb +61 -29
- data/lib/action_view/helpers/record_tag_helper.rb +3 -3
- data/lib/action_view/helpers/sanitize_helper.rb +23 -17
- data/lib/action_view/helpers/scriptaculous_helper.rb +86 -60
- data/lib/action_view/helpers/text_helper.rb +153 -125
- data/lib/action_view/helpers/url_helper.rb +83 -28
- data/lib/action_view/inline_template.rb +20 -0
- data/lib/action_view/partial_template.rb +70 -0
- data/lib/action_view/partials.rb +31 -73
- data/lib/action_view/template.rb +127 -0
- data/lib/action_view/template_error.rb +8 -7
- data/lib/action_view/template_finder.rb +177 -0
- data/lib/action_view/template_handler.rb +18 -1
- data/lib/action_view/template_handlers/builder.rb +10 -2
- data/lib/action_view/template_handlers/compilable.rb +128 -0
- data/lib/action_view/template_handlers/erb.rb +37 -2
- data/lib/action_view/template_handlers/rjs.rb +14 -1
- data/lib/action_view/test_case.rb +58 -0
- data/test/abstract_unit.rb +1 -1
- data/test/active_record_unit.rb +3 -6
- data/test/activerecord/active_record_store_test.rb +1 -2
- data/test/activerecord/render_partial_with_record_identification_test.rb +158 -41
- data/test/adv_attr_test.rb +20 -0
- data/test/controller/action_pack_assertions_test.rb +16 -19
- data/test/controller/addresses_render_test.rb +1 -1
- data/test/controller/assert_select_test.rb +13 -6
- data/test/controller/base_test.rb +48 -2
- data/test/controller/benchmark_test.rb +1 -2
- data/test/controller/caching_test.rb +282 -21
- data/test/controller/capture_test.rb +1 -1
- data/test/controller/cgi_test.rb +1 -1
- data/test/controller/components_test.rb +1 -1
- data/test/controller/content_type_test.rb +2 -2
- data/test/controller/cookie_test.rb +13 -2
- data/test/controller/custom_handler_test.rb +14 -10
- data/test/controller/deprecation/deprecated_base_methods_test.rb +1 -1
- data/test/controller/dispatcher_test.rb +31 -49
- data/test/controller/fake_controllers.rb +17 -0
- data/test/controller/fake_models.rb +6 -0
- data/test/controller/filter_params_test.rb +14 -8
- data/test/controller/filters_test.rb +44 -16
- data/test/controller/flash_test.rb +2 -2
- data/test/controller/header_test.rb +14 -0
- data/test/controller/helper_test.rb +19 -15
- data/test/controller/html-scanner/document_test.rb +1 -2
- data/test/controller/html-scanner/node_test.rb +1 -2
- data/test/controller/html-scanner/sanitizer_test.rb +8 -5
- data/test/controller/html-scanner/tag_node_test.rb +1 -2
- data/test/controller/html-scanner/text_node_test.rb +2 -3
- data/test/controller/html-scanner/tokenizer_test.rb +8 -2
- data/test/controller/http_authentication_test.rb +1 -1
- data/test/controller/integration_test.rb +14 -16
- data/test/controller/integration_upload_test.rb +43 -0
- data/test/controller/layout_test.rb +26 -6
- data/test/controller/mime_responds_test.rb +39 -7
- data/test/controller/mime_type_test.rb +29 -5
- data/test/controller/new_render_test.rb +105 -34
- data/test/controller/polymorphic_routes_test.rb +32 -20
- data/test/controller/record_identifier_test.rb +38 -2
- data/test/controller/redirect_test.rb +21 -1
- data/test/controller/render_test.rb +59 -15
- data/test/controller/request_forgery_protection_test.rb +92 -5
- data/test/controller/request_test.rb +64 -6
- data/test/controller/rescue_test.rb +22 -6
- data/test/controller/resources_test.rb +102 -14
- data/test/controller/routing_test.rb +231 -19
- data/test/controller/selector_test.rb +2 -2
- data/test/controller/send_file_test.rb +14 -3
- data/test/controller/session/cookie_store_test.rb +16 -4
- data/test/controller/session/mem_cache_store_test.rb +3 -4
- data/test/controller/session_fixation_test.rb +1 -1
- data/test/controller/session_management_test.rb +23 -1
- data/test/controller/test_test.rb +39 -18
- data/test/controller/url_rewriter_test.rb +35 -1
- data/test/controller/verification_test.rb +1 -1
- data/test/controller/view_paths_test.rb +15 -12
- data/test/controller/webservice_test.rb +48 -3
- data/test/fixtures/bad_customers/_bad_customer.html.erb +1 -0
- data/test/fixtures/company.rb +1 -0
- data/test/fixtures/customers/_customer.html.erb +1 -0
- data/test/fixtures/db_definitions/sqlite.sql +6 -0
- data/test/fixtures/functional_caching/_partial.erb +3 -0
- data/test/fixtures/functional_caching/fragment_cached.html.erb +2 -0
- data/test/fixtures/functional_caching/html_fragment_cached_with_partial.html.erb +1 -0
- data/test/fixtures/functional_caching/js_fragment_cached_with_partial.js.rjs +1 -0
- data/test/fixtures/good_customers/_good_customer.html.erb +1 -0
- data/test/fixtures/mascot.rb +3 -0
- data/test/fixtures/mascots.yml +4 -0
- data/test/fixtures/mascots/_mascot.html.erb +1 -0
- data/test/fixtures/multipart/boundary_problem_file +10 -0
- data/test/fixtures/public/javascripts/application.js +1 -0
- data/test/fixtures/public/javascripts/controls.js +1 -0
- data/test/fixtures/public/javascripts/dragdrop.js +1 -0
- data/test/fixtures/public/javascripts/effects.js +1 -0
- data/test/fixtures/public/javascripts/prototype.js +1 -0
- data/test/fixtures/public/javascripts/version.1.0.js +1 -0
- data/test/fixtures/public/stylesheets/version.1.0.css +1 -0
- data/test/fixtures/reply.rb +1 -0
- data/test/fixtures/shared.html.erb +1 -0
- data/test/fixtures/symlink_parent/symlinked_layout.erb +5 -0
- data/test/fixtures/test/_customer_counter.erb +1 -0
- data/test/fixtures/test/_form.erb +1 -0
- data/test/fixtures/test/_labelling_form.erb +1 -0
- data/test/fixtures/test/_raise.html.erb +1 -0
- data/test/fixtures/test/greeting.js.rjs +1 -0
- data/test/fixtures/topics/_topic.html.erb +1 -0
- data/test/template/active_record_helper_test.rb +25 -8
- data/test/template/asset_tag_helper_test.rb +100 -17
- data/test/template/atom_feed_helper_test.rb +29 -1
- data/test/template/benchmark_helper_test.rb +10 -22
- data/test/template/date_helper_test.rb +455 -153
- data/test/template/erb_util_test.rb +10 -42
- data/test/template/form_helper_test.rb +192 -66
- data/test/template/form_options_helper_test.rb +19 -8
- data/test/template/form_tag_helper_test.rb +11 -8
- data/test/template/javascript_helper_test.rb +3 -9
- data/test/template/number_helper_test.rb +6 -3
- data/test/template/prototype_helper_test.rb +27 -40
- data/test/template/record_tag_helper_test.rb +54 -0
- data/test/template/sanitize_helper_test.rb +5 -6
- data/test/template/scriptaculous_helper_test.rb +7 -13
- data/test/template/tag_helper_test.rb +3 -6
- data/test/template/template_finder_test.rb +73 -0
- data/test/template/template_object_test.rb +95 -0
- data/test/template/test_test.rb +56 -0
- data/test/template/text_helper_test.rb +46 -33
- data/test/template/url_helper_test.rb +8 -10
- metadata +65 -12
- data/lib/action_view/compiled_templates.rb +0 -69
- data/test/action_view_test.rb +0 -44
- data/test/activerecord/fixtures_test.rb +0 -24
- data/test/controller/fragment_store_setting_test.rb +0 -47
- data/test/template/compiled_templates_test.rb +0 -197
- data/test/template/deprecate_ivars_test.rb +0 -51
@@ -1,50 +1,18 @@
|
|
1
|
-
require
|
1
|
+
require 'abstract_unit'
|
2
2
|
|
3
3
|
class ErbUtilTest < Test::Unit::TestCase
|
4
4
|
include ERB::Util
|
5
|
-
|
6
|
-
def test_amp
|
7
|
-
assert_equal '&', html_escape('&')
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_quot
|
11
|
-
assert_equal '"', html_escape('"')
|
12
|
-
end
|
13
5
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
def test_gt
|
19
|
-
assert_equal '>', html_escape('>')
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_rest_in_ascii
|
23
|
-
(0..127).to_a.map(&:chr).each do |chr|
|
24
|
-
next if %w(& " < >).include?(chr)
|
25
|
-
assert_equal chr, html_escape(chr)
|
6
|
+
ERB::Util::HTML_ESCAPE.each do |given, expected|
|
7
|
+
define_method "test_html_escape_#{expected.gsub /\W/, ''}" do
|
8
|
+
assert_equal expected, html_escape(given)
|
26
9
|
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
require "#{File.dirname(__FILE__)}/../abstract_unit"
|
30
|
-
|
31
|
-
class ErbUtilTest < Test::Unit::TestCase
|
32
|
-
include ERB::Util
|
33
|
-
|
34
|
-
def test_amp
|
35
|
-
assert_equal '&', html_escape('&')
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_quot
|
39
|
-
assert_equal '"', html_escape('"')
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_lt
|
43
|
-
assert_equal '<', html_escape('<')
|
44
|
-
end
|
45
10
|
|
46
|
-
|
47
|
-
|
11
|
+
unless given == '"'
|
12
|
+
define_method "test_json_escape_#{expected.gsub /\W/, ''}" do
|
13
|
+
assert_equal ERB::Util::JSON_ESCAPE[given], json_escape(given)
|
14
|
+
end
|
15
|
+
end
|
48
16
|
end
|
49
17
|
|
50
18
|
def test_rest_in_ascii
|
@@ -53,4 +21,4 @@ class ErbUtilTest < Test::Unit::TestCase
|
|
53
21
|
assert_equal chr, html_escape(chr)
|
54
22
|
end
|
55
23
|
end
|
56
|
-
end
|
24
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'abstract_unit'
|
2
2
|
|
3
3
|
silence_warnings do
|
4
4
|
Post = Struct.new(:title, :author_name, :body, :secret, :written_on, :cost)
|
@@ -6,11 +6,12 @@ silence_warnings do
|
|
6
6
|
alias_method :title_before_type_cast, :title unless respond_to?(:title_before_type_cast)
|
7
7
|
alias_method :body_before_type_cast, :body unless respond_to?(:body_before_type_cast)
|
8
8
|
alias_method :author_name_before_type_cast, :author_name unless respond_to?(:author_name_before_type_cast)
|
9
|
-
|
9
|
+
alias_method :secret?, :secret
|
10
|
+
|
10
11
|
def new_record=(boolean)
|
11
12
|
@new_record = boolean
|
12
13
|
end
|
13
|
-
|
14
|
+
|
14
15
|
def new_record?
|
15
16
|
@new_record
|
16
17
|
end
|
@@ -30,26 +31,19 @@ end
|
|
30
31
|
class Comment::Nested < Comment; end
|
31
32
|
|
32
33
|
|
33
|
-
class FormHelperTest <
|
34
|
-
|
35
|
-
include ActionView::Helpers::FormTagHelper
|
36
|
-
include ActionView::Helpers::UrlHelper
|
37
|
-
include ActionView::Helpers::TagHelper
|
38
|
-
include ActionView::Helpers::TextHelper
|
39
|
-
include ActionView::Helpers::ActiveRecordHelper
|
40
|
-
include ActionView::Helpers::RecordIdentificationHelper
|
41
|
-
include ActionController::PolymorphicRoutes
|
34
|
+
class FormHelperTest < ActionView::TestCase
|
35
|
+
tests ActionView::Helpers::FormHelper
|
42
36
|
|
43
37
|
def setup
|
44
38
|
@post = Post.new
|
45
39
|
@comment = Comment.new
|
46
|
-
def @post.errors()
|
47
|
-
Class.new{
|
48
|
-
def on(field); "can't be empty" if field == "author_name"; end
|
49
|
-
def empty?() false end
|
40
|
+
def @post.errors()
|
41
|
+
Class.new{
|
42
|
+
def on(field); "can't be empty" if field == "author_name"; end
|
43
|
+
def empty?() false end
|
50
44
|
def count() 1 end
|
51
|
-
def full_messages() [ "Author name can't be empty" ] end
|
52
|
-
}.new
|
45
|
+
def full_messages() [ "Author name can't be empty" ] end
|
46
|
+
}.new
|
53
47
|
end
|
54
48
|
def @post.id; 123; end
|
55
49
|
def @post.id_before_type_cast; 123; end
|
@@ -78,10 +72,20 @@ class FormHelperTest < Test::Unit::TestCase
|
|
78
72
|
'<label class="title_label" for="post_title">Title</label>',
|
79
73
|
label("post", "title", nil, :class => 'title_label')
|
80
74
|
)
|
75
|
+
assert_dom_equal('<label for="post_secret">Secret?</label>', label("post", "secret?"))
|
81
76
|
end
|
82
|
-
|
77
|
+
|
83
78
|
def test_label_with_symbols
|
84
79
|
assert_dom_equal('<label for="post_title">Title</label>', label(:post, :title))
|
80
|
+
assert_dom_equal('<label for="post_secret">Secret?</label>', label(:post, :secret?))
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_label_with_for_attribute_as_symbol
|
84
|
+
assert_dom_equal('<label for="my_for">Title</label>', label(:post, :title, nil, :for => "my_for"))
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_label_with_for_attribute_as_string
|
88
|
+
assert_dom_equal('<label for="my_for">Title</label>', label(:post, :title, nil, "for" => "my_for"))
|
85
89
|
end
|
86
90
|
|
87
91
|
def test_text_field
|
@@ -103,6 +107,14 @@ class FormHelperTest < Test::Unit::TestCase
|
|
103
107
|
)
|
104
108
|
end
|
105
109
|
|
110
|
+
def test_text_field_with_html_entities
|
111
|
+
@post.title = "The HTML Entity for & is &"
|
112
|
+
assert_dom_equal(
|
113
|
+
'<input id="post_title" name="post[title]" size="30" type="text" value="The HTML Entity for & is &amp;" />',
|
114
|
+
text_field("post", "title")
|
115
|
+
)
|
116
|
+
end
|
117
|
+
|
106
118
|
def test_text_field_with_options
|
107
119
|
expected = '<input id="post_title" name="post[title]" size="35" type="text" value="Hello World" />'
|
108
120
|
assert_dom_equal expected, text_field("post", "title", "size" => 35)
|
@@ -131,6 +143,8 @@ class FormHelperTest < Test::Unit::TestCase
|
|
131
143
|
def test_hidden_field
|
132
144
|
assert_dom_equal '<input id="post_title" name="post[title]" type="hidden" value="Hello World" />',
|
133
145
|
hidden_field("post", "title")
|
146
|
+
assert_dom_equal '<input id="post_secret" name="post[secret]" type="hidden" value="1" />',
|
147
|
+
hidden_field("post", "secret?")
|
134
148
|
end
|
135
149
|
|
136
150
|
def test_hidden_field_with_escapes
|
@@ -163,6 +177,21 @@ class FormHelperTest < Test::Unit::TestCase
|
|
163
177
|
'<input checked="checked" id="post_secret" name="post[secret]" type="checkbox" value="1" /><input name="post[secret]" type="hidden" value="0" />',
|
164
178
|
check_box("post", "secret")
|
165
179
|
)
|
180
|
+
assert_dom_equal(
|
181
|
+
'<input checked="checked" id="post_secret" name="post[secret]" type="checkbox" value="1" /><input name="post[secret]" type="hidden" value="0" />',
|
182
|
+
check_box("post", "secret?")
|
183
|
+
)
|
184
|
+
|
185
|
+
@post.secret = ['0']
|
186
|
+
assert_dom_equal(
|
187
|
+
'<input id="post_secret" name="post[secret]" type="checkbox" value="1" /><input name="post[secret]" type="hidden" value="0" />',
|
188
|
+
check_box("post", "secret")
|
189
|
+
)
|
190
|
+
@post.secret = ['1']
|
191
|
+
assert_dom_equal(
|
192
|
+
'<input checked="checked" id="post_secret" name="post[secret]" type="checkbox" value="1" /><input name="post[secret]" type="hidden" value="0" />',
|
193
|
+
check_box("post", "secret")
|
194
|
+
)
|
166
195
|
end
|
167
196
|
|
168
197
|
def test_check_box_with_explicit_checked_and_unchecked_values
|
@@ -187,6 +216,9 @@ class FormHelperTest < Test::Unit::TestCase
|
|
187
216
|
assert_dom_equal('<input id="post_title_goodbye_world" name="post[title]" type="radio" value="Goodbye World" />',
|
188
217
|
radio_button("post", "title", "Goodbye World")
|
189
218
|
)
|
219
|
+
assert_dom_equal('<input id="item_subobject_title_inside_world" name="item[subobject][title]" type="radio" value="inside world"/>',
|
220
|
+
radio_button("item[subobject]", "title", "inside world")
|
221
|
+
)
|
190
222
|
end
|
191
223
|
|
192
224
|
def test_radio_button_is_checked_with_integers
|
@@ -223,6 +255,14 @@ class FormHelperTest < Test::Unit::TestCase
|
|
223
255
|
)
|
224
256
|
end
|
225
257
|
|
258
|
+
def test_text_area_with_html_entities
|
259
|
+
@post.body = "The HTML Entity for & is &"
|
260
|
+
assert_dom_equal(
|
261
|
+
'<textarea cols="40" id="post_body" name="post[body]" rows="20">The HTML Entity for & is &amp;</textarea>',
|
262
|
+
text_area("post", "body")
|
263
|
+
)
|
264
|
+
end
|
265
|
+
|
226
266
|
def test_text_area_with_size_option
|
227
267
|
assert_dom_equal(
|
228
268
|
'<textarea cols="183" id="post_body" name="post[body]" rows="820">Back to the hill and over it again!</textarea>',
|
@@ -307,7 +347,7 @@ class FormHelperTest < Test::Unit::TestCase
|
|
307
347
|
_erbout.concat f.submit('Create post')
|
308
348
|
end
|
309
349
|
|
310
|
-
expected =
|
350
|
+
expected =
|
311
351
|
"<form action='http://www.example.com' id='create-post' method='post'>" +
|
312
352
|
"<label for='post_title'>Title</label>" +
|
313
353
|
"<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
|
@@ -329,7 +369,7 @@ class FormHelperTest < Test::Unit::TestCase
|
|
329
369
|
_erbout.concat f.check_box(:secret)
|
330
370
|
end
|
331
371
|
|
332
|
-
expected =
|
372
|
+
expected =
|
333
373
|
"<form action='http://www.example.com' id='create-post' method='post'>" +
|
334
374
|
"<div style='margin:0;padding:0'><input name='_method' type='hidden' value='put' /></div>" +
|
335
375
|
"<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
|
@@ -350,7 +390,7 @@ class FormHelperTest < Test::Unit::TestCase
|
|
350
390
|
_erbout.concat f.check_box(:secret)
|
351
391
|
end
|
352
392
|
|
353
|
-
expected =
|
393
|
+
expected =
|
354
394
|
"<form action='http://www.example.com' id='create-post' method='post'>" +
|
355
395
|
"<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
|
356
396
|
"<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
|
@@ -363,15 +403,15 @@ class FormHelperTest < Test::Unit::TestCase
|
|
363
403
|
|
364
404
|
def test_form_for_with_index
|
365
405
|
_erbout = ''
|
366
|
-
|
406
|
+
|
367
407
|
form_for("post[]", @post) do |f|
|
368
408
|
_erbout.concat f.label(:title)
|
369
409
|
_erbout.concat f.text_field(:title)
|
370
410
|
_erbout.concat f.text_area(:body)
|
371
411
|
_erbout.concat f.check_box(:secret)
|
372
412
|
end
|
373
|
-
|
374
|
-
expected =
|
413
|
+
|
414
|
+
expected =
|
375
415
|
"<form action='http://www.example.com' method='post'>" +
|
376
416
|
"<label for=\"post_123_title\">Title</label>" +
|
377
417
|
"<input name='post[123][title]' size='30' type='text' id='post_123_title' value='Hello World' />" +
|
@@ -383,6 +423,26 @@ class FormHelperTest < Test::Unit::TestCase
|
|
383
423
|
assert_dom_equal expected, _erbout
|
384
424
|
end
|
385
425
|
|
426
|
+
def test_form_for_with_nil_index_option_override
|
427
|
+
_erbout = ''
|
428
|
+
|
429
|
+
form_for("post[]", @post, :index => nil) do |f|
|
430
|
+
_erbout.concat f.text_field(:title)
|
431
|
+
_erbout.concat f.text_area(:body)
|
432
|
+
_erbout.concat f.check_box(:secret)
|
433
|
+
end
|
434
|
+
|
435
|
+
expected =
|
436
|
+
"<form action='http://www.example.com' method='post'>" +
|
437
|
+
"<input name='post[][title]' size='30' type='text' id='post__title' value='Hello World' />" +
|
438
|
+
"<textarea name='post[][body]' id='post__body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
|
439
|
+
"<input name='post[][secret]' checked='checked' type='checkbox' id='post__secret' value='1' />" +
|
440
|
+
"<input name='post[][secret]' type='hidden' value='0' />" +
|
441
|
+
"</form>"
|
442
|
+
|
443
|
+
assert_dom_equal expected, _erbout
|
444
|
+
end
|
445
|
+
|
386
446
|
def test_nested_fields_for
|
387
447
|
_erbout = ''
|
388
448
|
form_for(:post, @post) do |f|
|
@@ -407,7 +467,7 @@ class FormHelperTest < Test::Unit::TestCase
|
|
407
467
|
_erbout.concat f.check_box(:secret)
|
408
468
|
end
|
409
469
|
|
410
|
-
expected =
|
470
|
+
expected =
|
411
471
|
"<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
|
412
472
|
"<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
|
413
473
|
"<input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />" +
|
@@ -416,6 +476,60 @@ class FormHelperTest < Test::Unit::TestCase
|
|
416
476
|
assert_dom_equal expected, _erbout
|
417
477
|
end
|
418
478
|
|
479
|
+
def test_fields_for_with_index
|
480
|
+
_erbout = ''
|
481
|
+
|
482
|
+
fields_for("post[]", @post) do |f|
|
483
|
+
_erbout.concat f.text_field(:title)
|
484
|
+
_erbout.concat f.text_area(:body)
|
485
|
+
_erbout.concat f.check_box(:secret)
|
486
|
+
end
|
487
|
+
|
488
|
+
expected =
|
489
|
+
"<input name='post[123][title]' size='30' type='text' id='post_123_title' value='Hello World' />" +
|
490
|
+
"<textarea name='post[123][body]' id='post_123_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
|
491
|
+
"<input name='post[123][secret]' checked='checked' type='checkbox' id='post_123_secret' value='1' />" +
|
492
|
+
"<input name='post[123][secret]' type='hidden' value='0' />"
|
493
|
+
|
494
|
+
assert_dom_equal expected, _erbout
|
495
|
+
end
|
496
|
+
|
497
|
+
def test_fields_for_with_nil_index_option_override
|
498
|
+
_erbout = ''
|
499
|
+
|
500
|
+
fields_for("post[]", @post, :index => nil) do |f|
|
501
|
+
_erbout.concat f.text_field(:title)
|
502
|
+
_erbout.concat f.text_area(:body)
|
503
|
+
_erbout.concat f.check_box(:secret)
|
504
|
+
end
|
505
|
+
|
506
|
+
expected =
|
507
|
+
"<input name='post[][title]' size='30' type='text' id='post__title' value='Hello World' />" +
|
508
|
+
"<textarea name='post[][body]' id='post__body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
|
509
|
+
"<input name='post[][secret]' checked='checked' type='checkbox' id='post__secret' value='1' />" +
|
510
|
+
"<input name='post[][secret]' type='hidden' value='0' />"
|
511
|
+
|
512
|
+
assert_dom_equal expected, _erbout
|
513
|
+
end
|
514
|
+
|
515
|
+
def test_fields_for_with_index_option_override
|
516
|
+
_erbout = ''
|
517
|
+
|
518
|
+
fields_for("post[]", @post, :index => "abc") do |f|
|
519
|
+
_erbout.concat f.text_field(:title)
|
520
|
+
_erbout.concat f.text_area(:body)
|
521
|
+
_erbout.concat f.check_box(:secret)
|
522
|
+
end
|
523
|
+
|
524
|
+
expected =
|
525
|
+
"<input name='post[abc][title]' size='30' type='text' id='post_abc_title' value='Hello World' />" +
|
526
|
+
"<textarea name='post[abc][body]' id='post_abc_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
|
527
|
+
"<input name='post[abc][secret]' checked='checked' type='checkbox' id='post_abc_secret' value='1' />" +
|
528
|
+
"<input name='post[abc][secret]' type='hidden' value='0' />"
|
529
|
+
|
530
|
+
assert_dom_equal expected, _erbout
|
531
|
+
end
|
532
|
+
|
419
533
|
def test_fields_for_without_object
|
420
534
|
_erbout = ''
|
421
535
|
fields_for(:post) do |f|
|
@@ -424,7 +538,7 @@ class FormHelperTest < Test::Unit::TestCase
|
|
424
538
|
_erbout.concat f.check_box(:secret)
|
425
539
|
end
|
426
540
|
|
427
|
-
expected =
|
541
|
+
expected =
|
428
542
|
"<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
|
429
543
|
"<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
|
430
544
|
"<input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />" +
|
@@ -441,7 +555,7 @@ class FormHelperTest < Test::Unit::TestCase
|
|
441
555
|
_erbout.concat f.check_box(:secret)
|
442
556
|
end
|
443
557
|
|
444
|
-
expected =
|
558
|
+
expected =
|
445
559
|
"<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
|
446
560
|
"<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
|
447
561
|
"<input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />" +
|
@@ -462,6 +576,18 @@ class FormHelperTest < Test::Unit::TestCase
|
|
462
576
|
_erbout
|
463
577
|
end
|
464
578
|
|
579
|
+
def test_fields_for_object_with_bracketed_name_and_index
|
580
|
+
_erbout = ''
|
581
|
+
fields_for("author[post]", @post, :index => 1) do |f|
|
582
|
+
_erbout.concat f.label(:title)
|
583
|
+
_erbout.concat f.text_field(:title)
|
584
|
+
end
|
585
|
+
|
586
|
+
assert_dom_equal "<label for=\"author_post_1_title\">Title</label>" +
|
587
|
+
"<input name='author[post][1][title]' size='30' type='text' id='author_post_1_title' value='Hello World' />",
|
588
|
+
_erbout
|
589
|
+
end
|
590
|
+
|
465
591
|
def test_form_builder_does_not_have_form_for_method
|
466
592
|
assert ! ActionView::Helpers::FormBuilder.instance_methods.include?('form_for')
|
467
593
|
end
|
@@ -478,7 +604,7 @@ class FormHelperTest < Test::Unit::TestCase
|
|
478
604
|
end
|
479
605
|
end
|
480
606
|
|
481
|
-
expected =
|
607
|
+
expected =
|
482
608
|
"<form action='http://www.example.com' id='create-post' method='post'>" +
|
483
609
|
"<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
|
484
610
|
"<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
|
@@ -501,7 +627,7 @@ class FormHelperTest < Test::Unit::TestCase
|
|
501
627
|
end
|
502
628
|
end
|
503
629
|
|
504
|
-
expected =
|
630
|
+
expected =
|
505
631
|
"<form action='http://www.example.com' id='create-post' method='post'>" +
|
506
632
|
"<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
|
507
633
|
"<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
|
@@ -531,7 +657,7 @@ class FormHelperTest < Test::Unit::TestCase
|
|
531
657
|
_erbout.concat f.check_box(:secret)
|
532
658
|
end
|
533
659
|
|
534
|
-
expected =
|
660
|
+
expected =
|
535
661
|
"<form action='http://www.example.com' method='post'>" +
|
536
662
|
"<label for='title'>Title:</label> <input name='post[title]' size='30' type='text' id='post_title' value='Hello World' /><br/>" +
|
537
663
|
"<label for='body'>Body:</label> <textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea><br/>" +
|
@@ -553,7 +679,7 @@ class FormHelperTest < Test::Unit::TestCase
|
|
553
679
|
_erbout.concat f.check_box(:secret)
|
554
680
|
end
|
555
681
|
|
556
|
-
expected =
|
682
|
+
expected =
|
557
683
|
"<form action='http://www.example.com' method='post'>" +
|
558
684
|
"<label for='title'>Title:</label> <input name='post[title]' size='30' type='text' id='post_title' value='Hello World' /><br/>" +
|
559
685
|
"<label for='body'>Body:</label> <textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea><br/>" +
|
@@ -567,39 +693,39 @@ class FormHelperTest < Test::Unit::TestCase
|
|
567
693
|
end
|
568
694
|
|
569
695
|
def test_default_form_builder_with_active_record_helpers
|
570
|
-
|
571
|
-
_erbout = ''
|
696
|
+
|
697
|
+
_erbout = ''
|
572
698
|
form_for(:post, @post) do |f|
|
573
699
|
_erbout.concat f.error_message_on('author_name')
|
574
700
|
_erbout.concat f.error_messages
|
575
|
-
end
|
576
|
-
|
577
|
-
expected = %(<form action='http://www.example.com' method='post'>) +
|
578
|
-
%(<div class='formError'>can't be empty</div>) +
|
701
|
+
end
|
702
|
+
|
703
|
+
expected = %(<form action='http://www.example.com' method='post'>) +
|
704
|
+
%(<div class='formError'>can't be empty</div>) +
|
579
705
|
%(<div class="errorExplanation" id="errorExplanation"><h2>1 error prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>) +
|
580
706
|
%(</form>)
|
581
|
-
|
707
|
+
|
582
708
|
assert_dom_equal expected, _erbout
|
583
709
|
|
584
710
|
end
|
585
|
-
|
711
|
+
|
586
712
|
def test_default_form_builder_no_instance_variable
|
587
713
|
post = @post
|
588
714
|
@post = nil
|
589
|
-
|
590
|
-
_erbout = ''
|
715
|
+
|
716
|
+
_erbout = ''
|
591
717
|
form_for(:post, post) do |f|
|
592
718
|
_erbout.concat f.error_message_on('author_name')
|
593
719
|
_erbout.concat f.error_messages
|
594
|
-
end
|
595
|
-
|
596
|
-
expected = %(<form action='http://www.example.com' method='post'>) +
|
597
|
-
%(<div class='formError'>can't be empty</div>) +
|
720
|
+
end
|
721
|
+
|
722
|
+
expected = %(<form action='http://www.example.com' method='post'>) +
|
723
|
+
%(<div class='formError'>can't be empty</div>) +
|
598
724
|
%(<div class="errorExplanation" id="errorExplanation"><h2>1 error prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>) +
|
599
725
|
%(</form>)
|
600
|
-
|
726
|
+
|
601
727
|
assert_dom_equal expected, _erbout
|
602
|
-
|
728
|
+
|
603
729
|
end
|
604
730
|
|
605
731
|
# Perhaps this test should be moved to prototype helper tests.
|
@@ -613,7 +739,7 @@ class FormHelperTest < Test::Unit::TestCase
|
|
613
739
|
_erbout.concat f.check_box(:secret)
|
614
740
|
end
|
615
741
|
|
616
|
-
expected =
|
742
|
+
expected =
|
617
743
|
%(<form action="http://www.example.com" onsubmit="new Ajax.Request('http://www.example.com', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;" method="post">) +
|
618
744
|
"<label for='title'>Title:</label> <input name='post[title]' size='30' type='text' id='post_title' value='Hello World' /><br/>" +
|
619
745
|
"<label for='body'>Body:</label> <textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea><br/>" +
|
@@ -623,31 +749,31 @@ class FormHelperTest < Test::Unit::TestCase
|
|
623
749
|
|
624
750
|
assert_dom_equal expected, _erbout
|
625
751
|
end
|
626
|
-
|
752
|
+
|
627
753
|
def test_fields_for_with_labelled_builder
|
628
754
|
_erbout = ''
|
629
|
-
|
755
|
+
|
630
756
|
fields_for(:post, @post, :builder => LabelledFormBuilder) do |f|
|
631
757
|
_erbout.concat f.text_field(:title)
|
632
758
|
_erbout.concat f.text_area(:body)
|
633
759
|
_erbout.concat f.check_box(:secret)
|
634
760
|
end
|
635
|
-
|
636
|
-
expected =
|
761
|
+
|
762
|
+
expected =
|
637
763
|
"<label for='title'>Title:</label> <input name='post[title]' size='30' type='text' id='post_title' value='Hello World' /><br/>" +
|
638
764
|
"<label for='body'>Body:</label> <textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea><br/>" +
|
639
765
|
"<label for='secret'>Secret:</label> <input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />" +
|
640
766
|
"<input name='post[secret]' type='hidden' value='0' /><br/>"
|
641
|
-
|
767
|
+
|
642
768
|
assert_dom_equal expected, _erbout
|
643
769
|
end
|
644
770
|
|
645
771
|
def test_form_for_with_html_options_adds_options_to_form_tag
|
646
772
|
_erbout = ''
|
647
|
-
|
773
|
+
|
648
774
|
form_for(:post, @post, :html => {:id => 'some_form', :class => 'some_class'}) do |f| end
|
649
775
|
expected = "<form action=\"http://www.example.com\" class=\"some_class\" id=\"some_form\" method=\"post\"></form>"
|
650
|
-
|
776
|
+
|
651
777
|
assert_dom_equal expected, _erbout
|
652
778
|
end
|
653
779
|
|
@@ -723,16 +849,16 @@ class FormHelperTest < Test::Unit::TestCase
|
|
723
849
|
@comment.save
|
724
850
|
_erbout = ''
|
725
851
|
form_for([:admin, @post, @comment]) {}
|
726
|
-
|
852
|
+
|
727
853
|
expected = %(<form action="#{admin_comment_path(@post, @comment)}" class="edit_comment" id="edit_comment_1" method="post"><div style="margin:0;padding:0"><input name="_method" type="hidden" value="put" /></div></form>)
|
728
854
|
assert_dom_equal expected, _erbout
|
729
855
|
end
|
730
|
-
|
856
|
+
|
731
857
|
def test_form_for_with_new_object_and_namespace_in_list
|
732
858
|
@post.new_record = false
|
733
859
|
_erbout = ''
|
734
860
|
form_for([:admin, @post, @comment]) {}
|
735
|
-
|
861
|
+
|
736
862
|
expected = %(<form action="#{admin_comments_path(@post)}" class="new_comment" id="new_comment" method="post"></form>)
|
737
863
|
assert_dom_equal expected, _erbout
|
738
864
|
end
|
@@ -749,10 +875,10 @@ class FormHelperTest < Test::Unit::TestCase
|
|
749
875
|
def test_remote_form_for_with_html_options_adds_options_to_form_tag
|
750
876
|
self.extend ActionView::Helpers::PrototypeHelper
|
751
877
|
_erbout = ''
|
752
|
-
|
878
|
+
|
753
879
|
remote_form_for(:post, @post, :html => {:id => 'some_form', :class => 'some_class'}) do |f| end
|
754
880
|
expected = "<form action=\"http://www.example.com\" class=\"some_class\" id=\"some_form\" method=\"post\" onsubmit=\"new Ajax.Request('http://www.example.com', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;\"></form>"
|
755
|
-
|
881
|
+
|
756
882
|
assert_dom_equal expected, _erbout
|
757
883
|
end
|
758
884
|
|
@@ -767,21 +893,21 @@ class FormHelperTest < Test::Unit::TestCase
|
|
767
893
|
"/posts/#{post.id}/comments/#{comment.id}"
|
768
894
|
end
|
769
895
|
alias_method :post_comment_path, :comment_path
|
770
|
-
|
896
|
+
|
771
897
|
def admin_comments_path(post)
|
772
898
|
"/admin/posts/#{post.id}/comments"
|
773
899
|
end
|
774
900
|
alias_method :admin_post_comments_path, :admin_comments_path
|
775
|
-
|
901
|
+
|
776
902
|
def admin_comment_path(post, comment)
|
777
903
|
"/admin/posts/#{post.id}/comments/#{comment.id}"
|
778
904
|
end
|
779
905
|
alias_method :admin_post_comment_path, :admin_comment_path
|
780
|
-
|
906
|
+
|
781
907
|
def posts_path
|
782
908
|
"/posts"
|
783
|
-
end
|
784
|
-
|
909
|
+
end
|
910
|
+
|
785
911
|
def post_path(post)
|
786
912
|
"/posts/#{post.id}"
|
787
913
|
end
|