actionpack 2.1.2 → 2.2.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 +223 -7
- data/README +6 -12
- data/Rakefile +11 -11
- data/lib/action_controller.rb +9 -9
- data/lib/action_controller/assertions/response_assertions.rb +29 -78
- data/lib/action_controller/assertions/routing_assertions.rb +33 -33
- data/lib/action_controller/assertions/selector_assertions.rb +9 -5
- data/lib/action_controller/base.rb +227 -161
- data/lib/action_controller/benchmarking.rb +37 -24
- data/lib/action_controller/caching/actions.rb +53 -21
- data/lib/action_controller/caching/fragments.rb +10 -36
- data/lib/action_controller/caching/sweeping.rb +3 -3
- data/lib/action_controller/cgi_ext/session.rb +2 -22
- data/lib/action_controller/cgi_process.rb +8 -46
- data/lib/action_controller/components.rb +4 -1
- data/lib/action_controller/cookies.rb +10 -0
- data/lib/action_controller/dispatcher.rb +49 -15
- data/lib/action_controller/filters.rb +48 -10
- data/lib/action_controller/headers.rb +16 -14
- data/lib/action_controller/helpers.rb +2 -2
- data/lib/action_controller/http_authentication.rb +1 -1
- data/lib/action_controller/integration.rb +57 -60
- data/lib/action_controller/layout.rb +27 -53
- data/lib/action_controller/mime_responds.rb +5 -1
- data/lib/action_controller/mime_type.rb +64 -42
- data/lib/action_controller/mime_types.rb +2 -1
- data/lib/action_controller/performance_test.rb +16 -0
- data/lib/action_controller/polymorphic_routes.rb +16 -9
- data/lib/action_controller/rack_process.rb +303 -0
- data/lib/action_controller/request.rb +205 -97
- data/lib/action_controller/request_forgery_protection.rb +2 -2
- data/lib/action_controller/request_profiler.rb +0 -0
- data/lib/action_controller/rescue.rb +20 -115
- data/lib/action_controller/resources.rb +186 -83
- data/lib/action_controller/response.rb +140 -26
- data/lib/action_controller/routing.rb +28 -30
- data/lib/action_controller/routing/builder.rb +45 -54
- data/lib/action_controller/routing/optimisations.rb +31 -21
- data/lib/action_controller/routing/recognition_optimisation.rb +33 -27
- data/lib/action_controller/routing/route.rb +162 -147
- data/lib/action_controller/routing/route_set.rb +8 -7
- data/lib/action_controller/routing/routing_ext.rb +4 -1
- data/lib/action_controller/routing/segments.rb +50 -21
- data/lib/action_controller/session/cookie_store.rb +3 -2
- data/lib/action_controller/session/drb_server.rb +7 -7
- data/lib/action_controller/session_management.rb +6 -2
- data/lib/action_controller/streaming.rb +15 -8
- 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 +66 -2
- data/lib/action_controller/test_process.rb +71 -66
- data/lib/action_controller/translation.rb +13 -0
- data/lib/action_controller/url_rewriter.rb +90 -13
- data/lib/action_controller/vendor/html-scanner/html/node.rb +9 -2
- data/lib/action_controller/vendor/html-scanner/html/sanitizer.rb +1 -1
- data/lib/action_controller/vendor/html-scanner/html/selector.rb +2 -2
- data/lib/action_controller/verification.rb +2 -2
- data/lib/action_pack/version.rb +1 -1
- data/lib/action_view.rb +19 -11
- data/lib/action_view/base.rb +184 -150
- data/lib/action_view/helpers.rb +38 -0
- data/lib/action_view/helpers/active_record_helper.rb +56 -27
- data/lib/action_view/helpers/asset_tag_helper.rb +356 -153
- data/lib/action_view/helpers/atom_feed_helper.rb +74 -19
- data/lib/action_view/helpers/benchmark_helper.rb +3 -3
- data/lib/action_view/helpers/cache_helper.rb +1 -2
- data/lib/action_view/helpers/capture_helper.rb +19 -44
- data/lib/action_view/helpers/date_helper.rb +486 -296
- data/lib/action_view/helpers/debug_helper.rb +20 -13
- data/lib/action_view/helpers/form_helper.rb +71 -30
- data/lib/action_view/helpers/form_options_helper.rb +15 -85
- data/lib/action_view/helpers/form_tag_helper.rb +61 -38
- data/lib/action_view/helpers/javascript_helper.rb +80 -89
- data/lib/action_view/helpers/number_helper.rb +179 -74
- data/lib/action_view/helpers/prototype_helper.rb +216 -201
- data/lib/action_view/helpers/record_tag_helper.rb +4 -5
- data/lib/action_view/helpers/sanitize_helper.rb +65 -33
- data/lib/action_view/helpers/scriptaculous_helper.rb +2 -2
- data/lib/action_view/helpers/tag_helper.rb +39 -22
- data/lib/action_view/helpers/text_helper.rb +212 -118
- data/lib/action_view/helpers/translation_helper.rb +21 -0
- data/lib/action_view/helpers/url_helper.rb +100 -58
- data/lib/action_view/inline_template.rb +13 -14
- data/lib/action_view/locale/en.yml +91 -0
- data/lib/action_view/partials.rb +100 -55
- data/lib/action_view/paths.rb +125 -0
- data/lib/action_view/renderable.rb +102 -0
- data/lib/action_view/renderable_partial.rb +48 -0
- data/lib/action_view/template.rb +90 -101
- data/lib/action_view/template_error.rb +11 -21
- data/lib/action_view/template_handler.rb +8 -28
- data/lib/action_view/template_handlers.rb +45 -0
- data/lib/action_view/template_handlers/builder.rb +5 -15
- data/lib/action_view/template_handlers/erb.rb +9 -6
- data/lib/action_view/template_handlers/rjs.rb +2 -17
- data/lib/action_view/test_case.rb +7 -4
- data/test/abstract_unit.rb +4 -1
- data/test/active_record_unit.rb +28 -30
- data/test/activerecord/render_partial_with_record_identification_test.rb +25 -12
- data/test/controller/action_pack_assertions_test.rb +8 -37
- data/test/controller/addresses_render_test.rb +0 -3
- data/test/controller/assert_select_test.rb +51 -24
- data/test/controller/base_test.rb +4 -4
- data/test/controller/caching_test.rb +136 -66
- data/test/controller/capture_test.rb +1 -21
- data/test/controller/cgi_test.rb +157 -10
- data/test/controller/components_test.rb +41 -25
- data/test/controller/content_type_test.rb +49 -17
- data/test/controller/cookie_test.rb +1 -1
- data/test/controller/deprecation/deprecated_base_methods_test.rb +0 -3
- data/test/controller/dispatcher_test.rb +9 -1
- data/test/controller/filter_params_test.rb +2 -2
- data/test/controller/filters_test.rb +13 -13
- data/test/controller/html-scanner/cdata_node_test.rb +15 -0
- data/test/controller/html-scanner/node_test.rb +21 -0
- data/test/controller/html-scanner/sanitizer_test.rb +14 -0
- data/test/controller/integration_test.rb +167 -6
- data/test/controller/layout_test.rb +11 -68
- data/test/controller/logging_test.rb +46 -0
- data/test/controller/mime_responds_test.rb +61 -59
- data/test/controller/mime_type_test.rb +6 -6
- data/test/controller/polymorphic_routes_test.rb +37 -2
- data/test/controller/rack_test.rb +323 -0
- data/test/controller/redirect_test.rb +72 -71
- data/test/controller/render_test.rb +1120 -108
- data/test/controller/request_forgery_protection_test.rb +66 -52
- data/test/controller/request_test.rb +103 -146
- data/test/controller/rescue_test.rb +20 -24
- data/test/controller/resources_test.rb +408 -25
- data/test/controller/routing_test.rb +1774 -1774
- data/test/controller/send_file_test.rb +0 -4
- data/test/controller/session/cookie_store_test.rb +53 -1
- data/test/controller/test_test.rb +15 -37
- data/test/controller/translation_test.rb +26 -0
- data/test/controller/url_rewriter_test.rb +27 -28
- data/test/controller/view_paths_test.rb +48 -47
- data/test/fixtures/_top_level_partial.html.erb +1 -0
- data/test/fixtures/_top_level_partial_only.erb +1 -0
- data/test/fixtures/developers/_developer.erb +1 -0
- data/test/fixtures/fun/games/_game.erb +1 -0
- data/test/fixtures/fun/serious/games/_game.erb +1 -0
- data/test/fixtures/functional_caching/formatted_fragment_cached.html.erb +3 -0
- data/test/fixtures/functional_caching/formatted_fragment_cached.js.rjs +6 -0
- data/test/fixtures/functional_caching/formatted_fragment_cached.xml.builder +5 -0
- data/test/fixtures/functional_caching/inline_fragment_cached.html.erb +2 -0
- data/test/fixtures/layouts/_column.html.erb +2 -0
- data/test/fixtures/projects/_project.erb +1 -0
- data/test/fixtures/public/javascripts/subdir/subdir.js +1 -0
- data/test/fixtures/public/stylesheets/subdir/subdir.css +1 -0
- data/test/fixtures/replies/_reply.erb +1 -0
- data/test/fixtures/test/_counter.html.erb +1 -0
- data/test/fixtures/test/_customer.erb +1 -1
- data/test/fixtures/test/_customer_with_var.erb +1 -0
- data/test/fixtures/test/_layout_for_block_with_args.html.erb +3 -0
- data/test/fixtures/test/_local_inspector.html.erb +1 -0
- data/test/fixtures/test/_partial_with_only_html_version.html.erb +1 -0
- data/test/fixtures/test/hello.builder +1 -1
- data/test/fixtures/test/hyphen-ated.erb +1 -0
- data/test/fixtures/test/implicit_content_type.atom.builder +2 -0
- data/test/fixtures/test/nested_layout.erb +3 -0
- data/test/fixtures/test/non_erb_block_content_for.builder +1 -1
- data/test/fixtures/test/sub_template_raise.html.erb +1 -0
- data/test/fixtures/test/template.erb +1 -0
- data/test/fixtures/test/using_layout_around_block_with_args.html.erb +1 -0
- data/test/template/active_record_helper_i18n_test.rb +46 -0
- data/test/template/active_record_helper_test.rb +24 -24
- data/test/template/asset_tag_helper_test.rb +161 -29
- data/test/template/atom_feed_helper_test.rb +114 -5
- data/test/template/compiled_templates_test.rb +59 -0
- data/test/template/date_helper_i18n_test.rb +113 -0
- data/test/template/date_helper_test.rb +403 -109
- data/test/template/form_helper_test.rb +213 -154
- data/test/template/form_options_helper_test.rb +249 -897
- data/test/template/form_tag_helper_test.rb +80 -32
- data/test/template/javascript_helper_test.rb +17 -18
- data/test/template/number_helper_i18n_test.rb +54 -0
- data/test/template/number_helper_test.rb +43 -13
- data/test/template/prototype_helper_test.rb +101 -84
- data/test/template/record_tag_helper_test.rb +24 -20
- data/test/template/render_test.rb +193 -0
- data/test/template/sanitize_helper_test.rb +3 -3
- data/test/template/tag_helper_test.rb +34 -14
- data/test/template/text_helper_test.rb +83 -9
- data/test/template/translation_helper_test.rb +28 -0
- data/test/template/url_helper_test.rb +55 -18
- metadata +57 -18
- data/lib/action_view/helpers/javascripts/controls.js +0 -963
- data/lib/action_view/helpers/javascripts/dragdrop.js +0 -972
- data/lib/action_view/helpers/javascripts/effects.js +0 -1120
- data/lib/action_view/helpers/javascripts/prototype.js +0 -4225
- data/lib/action_view/partial_template.rb +0 -70
- data/lib/action_view/template_finder.rb +0 -177
- data/lib/action_view/template_handlers/compilable.rb +0 -128
- data/test/controller/custom_handler_test.rb +0 -45
- data/test/controller/new_render_test.rb +0 -945
- data/test/fixtures/test/block_content_for.erb +0 -2
- data/test/fixtures/test/erb_content_for.erb +0 -2
- data/test/template/deprecated_erb_variable_test.rb +0 -9
- data/test/template/template_finder_test.rb +0 -73
- data/test/template/template_object_test.rb +0 -95
@@ -12,12 +12,19 @@ class FormTagHelperTest < ActionView::TestCase
|
|
12
12
|
@controller = @controller.new
|
13
13
|
end
|
14
14
|
|
15
|
+
VALID_HTML_ID = /^[A-Za-z][-_:.A-Za-z0-9]*$/ # see http://www.w3.org/TR/html4/types.html#type-name
|
16
|
+
|
15
17
|
def test_check_box_tag
|
16
18
|
actual = check_box_tag "admin"
|
17
19
|
expected = %(<input id="admin" name="admin" type="checkbox" value="1" />)
|
18
20
|
assert_dom_equal expected, actual
|
19
21
|
end
|
20
22
|
|
23
|
+
def test_check_box_tag_id_sanitized
|
24
|
+
label_elem = root_elem(check_box_tag("project[2][admin]"))
|
25
|
+
assert_match VALID_HTML_ID, label_elem['id']
|
26
|
+
end
|
27
|
+
|
21
28
|
def test_form_tag
|
22
29
|
actual = form_tag
|
23
30
|
expected = %(<form action="http://www.example.com" method="post">)
|
@@ -35,27 +42,27 @@ class FormTagHelperTest < ActionView::TestCase
|
|
35
42
|
expected = %(<form action="http://www.example.com" method="post"><div style='margin:0;padding:0'><input type="hidden" name="_method" value="put" /></div>)
|
36
43
|
assert_dom_equal expected, actual
|
37
44
|
end
|
38
|
-
|
45
|
+
|
39
46
|
def test_form_tag_with_method_delete
|
40
47
|
actual = form_tag({}, { :method => :delete })
|
41
48
|
expected = %(<form action="http://www.example.com" method="post"><div style='margin:0;padding:0'><input type="hidden" name="_method" value="delete" /></div>)
|
42
49
|
assert_dom_equal expected, actual
|
43
50
|
end
|
44
51
|
|
45
|
-
def
|
46
|
-
|
47
|
-
form_tag("http://example.com") {
|
52
|
+
def test_form_tag_with_block_in_erb
|
53
|
+
__in_erb_template = ''
|
54
|
+
form_tag("http://example.com") { concat "Hello world!" }
|
48
55
|
|
49
56
|
expected = %(<form action="http://example.com" method="post">Hello world!</form>)
|
50
|
-
assert_dom_equal expected,
|
57
|
+
assert_dom_equal expected, output_buffer
|
51
58
|
end
|
52
59
|
|
53
|
-
def
|
54
|
-
|
55
|
-
form_tag("http://example.com", :method => :put) {
|
60
|
+
def test_form_tag_with_block_and_method_in_erb
|
61
|
+
__in_erb_template = ''
|
62
|
+
form_tag("http://example.com", :method => :put) { concat "Hello world!" }
|
56
63
|
|
57
64
|
expected = %(<form action="http://example.com" method="post"><div style='margin:0;padding:0'><input type="hidden" name="_method" value="put" /></div>Hello world!</form>)
|
58
|
-
assert_dom_equal expected,
|
65
|
+
assert_dom_equal expected, output_buffer
|
59
66
|
end
|
60
67
|
|
61
68
|
def test_hidden_field_tag
|
@@ -64,6 +71,11 @@ class FormTagHelperTest < ActionView::TestCase
|
|
64
71
|
assert_dom_equal expected, actual
|
65
72
|
end
|
66
73
|
|
74
|
+
def test_hidden_field_tag_id_sanitized
|
75
|
+
input_elem = root_elem(hidden_field_tag("item[][title]"))
|
76
|
+
assert_match VALID_HTML_ID, input_elem['id']
|
77
|
+
end
|
78
|
+
|
67
79
|
def test_file_field_tag
|
68
80
|
assert_dom_equal "<input name=\"picsplz\" type=\"file\" id=\"picsplz\" />", file_field_tag("picsplz")
|
69
81
|
end
|
@@ -90,11 +102,11 @@ class FormTagHelperTest < ActionView::TestCase
|
|
90
102
|
actual = radio_button_tag("gender", "m") + radio_button_tag("gender", "f")
|
91
103
|
expected = %(<input id="gender_m" name="gender" type="radio" value="m" /><input id="gender_f" name="gender" type="radio" value="f" />)
|
92
104
|
assert_dom_equal expected, actual
|
93
|
-
|
105
|
+
|
94
106
|
actual = radio_button_tag("opinion", "-1") + radio_button_tag("opinion", "1")
|
95
107
|
expected = %(<input id="opinion_-1" name="opinion" type="radio" value="-1" /><input id="opinion_1" name="opinion" type="radio" value="1" />)
|
96
108
|
assert_dom_equal expected, actual
|
97
|
-
|
109
|
+
|
98
110
|
actual = radio_button_tag("person[gender]", "m")
|
99
111
|
expected = %(<input id="person_gender_m" name="person[gender]" type="radio" value="m" />)
|
100
112
|
assert_dom_equal expected, actual
|
@@ -105,19 +117,24 @@ class FormTagHelperTest < ActionView::TestCase
|
|
105
117
|
expected = %(<select id="people" name="people"><option>david</option></select>)
|
106
118
|
assert_dom_equal expected, actual
|
107
119
|
end
|
108
|
-
|
120
|
+
|
109
121
|
def test_select_tag_with_multiple
|
110
122
|
actual = select_tag "colors", "<option>Red</option><option>Blue</option><option>Green</option>", :multiple => :true
|
111
123
|
expected = %(<select id="colors" multiple="multiple" name="colors"><option>Red</option><option>Blue</option><option>Green</option></select>)
|
112
124
|
assert_dom_equal expected, actual
|
113
125
|
end
|
114
|
-
|
126
|
+
|
115
127
|
def test_select_tag_disabled
|
116
128
|
actual = select_tag "places", "<option>Home</option><option>Work</option><option>Pub</option>", :disabled => :true
|
117
129
|
expected = %(<select id="places" disabled="disabled" name="places"><option>Home</option><option>Work</option><option>Pub</option></select>)
|
118
130
|
assert_dom_equal expected, actual
|
119
131
|
end
|
120
132
|
|
133
|
+
def test_select_tag_id_sanitized
|
134
|
+
input_elem = root_elem(select_tag("project[1]people", "<option>david</option>"))
|
135
|
+
assert_match VALID_HTML_ID, input_elem['id']
|
136
|
+
end
|
137
|
+
|
121
138
|
def test_text_area_tag_size_string
|
122
139
|
actual = text_area_tag "body", "hello world", "size" => "20x40"
|
123
140
|
expected = %(<textarea cols="20" id="body" name="body" rows="40">hello world</textarea>)
|
@@ -147,43 +164,48 @@ class FormTagHelperTest < ActionView::TestCase
|
|
147
164
|
expected = %(<input class="admin" id="title" name="title" type="text" value="Hello!" />)
|
148
165
|
assert_dom_equal expected, actual
|
149
166
|
end
|
150
|
-
|
167
|
+
|
151
168
|
def test_text_field_tag_size_symbol
|
152
169
|
actual = text_field_tag "title", "Hello!", :size => 75
|
153
170
|
expected = %(<input id="title" name="title" size="75" type="text" value="Hello!" />)
|
154
171
|
assert_dom_equal expected, actual
|
155
172
|
end
|
156
|
-
|
173
|
+
|
157
174
|
def test_text_field_tag_size_string
|
158
175
|
actual = text_field_tag "title", "Hello!", "size" => "75"
|
159
176
|
expected = %(<input id="title" name="title" size="75" type="text" value="Hello!" />)
|
160
177
|
assert_dom_equal expected, actual
|
161
178
|
end
|
162
|
-
|
179
|
+
|
163
180
|
def test_text_field_tag_maxlength_symbol
|
164
181
|
actual = text_field_tag "title", "Hello!", :maxlength => 75
|
165
182
|
expected = %(<input id="title" name="title" maxlength="75" type="text" value="Hello!" />)
|
166
183
|
assert_dom_equal expected, actual
|
167
184
|
end
|
168
|
-
|
185
|
+
|
169
186
|
def test_text_field_tag_maxlength_string
|
170
187
|
actual = text_field_tag "title", "Hello!", "maxlength" => "75"
|
171
188
|
expected = %(<input id="title" name="title" maxlength="75" type="text" value="Hello!" />)
|
172
189
|
assert_dom_equal expected, actual
|
173
190
|
end
|
174
|
-
|
191
|
+
|
175
192
|
def test_text_field_disabled
|
176
193
|
actual = text_field_tag "title", "Hello!", :disabled => :true
|
177
194
|
expected = %(<input id="title" name="title" disabled="disabled" type="text" value="Hello!" />)
|
178
195
|
assert_dom_equal expected, actual
|
179
196
|
end
|
180
|
-
|
197
|
+
|
181
198
|
def test_text_field_tag_with_multiple_options
|
182
199
|
actual = text_field_tag "title", "Hello!", :size => 70, :maxlength => 80
|
183
200
|
expected = %(<input id="title" name="title" size="70" maxlength="80" type="text" value="Hello!" />)
|
184
201
|
assert_dom_equal expected, actual
|
185
202
|
end
|
186
203
|
|
204
|
+
def test_text_field_tag_id_sanitized
|
205
|
+
input_elem = root_elem(text_field_tag("item[][title]"))
|
206
|
+
assert_match VALID_HTML_ID, input_elem['id']
|
207
|
+
end
|
208
|
+
|
187
209
|
def test_label_tag_without_text
|
188
210
|
actual = label_tag "title"
|
189
211
|
expected = %(<label for="title">Title</label>)
|
@@ -208,10 +230,17 @@ class FormTagHelperTest < ActionView::TestCase
|
|
208
230
|
assert_dom_equal expected, actual
|
209
231
|
end
|
210
232
|
|
211
|
-
def
|
233
|
+
def test_label_tag_id_sanitized
|
234
|
+
label_elem = root_elem(label_tag("item[title]"))
|
235
|
+
assert_match VALID_HTML_ID, label_elem['for']
|
236
|
+
end
|
237
|
+
|
238
|
+
def test_boolean_options
|
212
239
|
assert_dom_equal %(<input checked="checked" disabled="disabled" id="admin" name="admin" readonly="readonly" type="checkbox" value="1" />), check_box_tag("admin", 1, true, 'disabled' => true, :readonly => "yes")
|
213
240
|
assert_dom_equal %(<input checked="checked" id="admin" name="admin" type="checkbox" value="1" />), check_box_tag("admin", 1, true, :disabled => false, :readonly => nil)
|
214
|
-
assert_dom_equal %(<
|
241
|
+
assert_dom_equal %(<input type="checkbox" />), tag(:input, :type => "checkbox", :checked => false)
|
242
|
+
assert_dom_equal %(<select id="people" multiple="multiple" name="people[]"><option>david</option></select>), select_tag("people", "<option>david</option>", :multiple => true)
|
243
|
+
assert_dom_equal %(<select id="people_" multiple="multiple" name="people[]"><option>david</option></select>), select_tag("people[]", "<option>david</option>", :multiple => true)
|
215
244
|
assert_dom_equal %(<select id="people" name="people"><option>david</option></select>), select_tag("people", "<option>david</option>", :multiple => nil)
|
216
245
|
end
|
217
246
|
|
@@ -242,31 +271,50 @@ class FormTagHelperTest < ActionView::TestCase
|
|
242
271
|
)
|
243
272
|
end
|
244
273
|
|
274
|
+
def test_image_submit_tag_with_confirmation
|
275
|
+
assert_dom_equal(
|
276
|
+
%(<input type="image" src="/images/save.gif" onclick="return confirm('Are you sure?');"/>),
|
277
|
+
image_submit_tag("save.gif", :confirm => "Are you sure?")
|
278
|
+
)
|
279
|
+
end
|
280
|
+
|
245
281
|
def test_pass
|
246
282
|
assert_equal 1, 1
|
247
283
|
end
|
248
284
|
|
249
|
-
def
|
250
|
-
|
251
|
-
field_set_tag("Your details") {
|
285
|
+
def test_field_set_tag_in_erb
|
286
|
+
__in_erb_template = ''
|
287
|
+
field_set_tag("Your details") { concat "Hello world!" }
|
252
288
|
|
253
289
|
expected = %(<fieldset><legend>Your details</legend>Hello world!</fieldset>)
|
254
|
-
assert_dom_equal expected,
|
290
|
+
assert_dom_equal expected, output_buffer
|
255
291
|
|
256
|
-
|
257
|
-
field_set_tag {
|
292
|
+
self.output_buffer = ''
|
293
|
+
field_set_tag { concat "Hello world!" }
|
258
294
|
|
259
295
|
expected = %(<fieldset>Hello world!</fieldset>)
|
260
|
-
assert_dom_equal expected,
|
261
|
-
|
262
|
-
|
263
|
-
field_set_tag('') {
|
296
|
+
assert_dom_equal expected, output_buffer
|
297
|
+
|
298
|
+
self.output_buffer = ''
|
299
|
+
field_set_tag('') { concat "Hello world!" }
|
264
300
|
|
265
301
|
expected = %(<fieldset>Hello world!</fieldset>)
|
266
|
-
assert_dom_equal expected,
|
302
|
+
assert_dom_equal expected, output_buffer
|
303
|
+
|
304
|
+
self.output_buffer = ''
|
305
|
+
field_set_tag('', :class => 'format') { concat "Hello world!" }
|
306
|
+
|
307
|
+
expected = %(<fieldset class="format">Hello world!</fieldset>)
|
308
|
+
assert_dom_equal expected, output_buffer
|
267
309
|
end
|
268
310
|
|
269
311
|
def protect_against_forgery?
|
270
312
|
false
|
271
313
|
end
|
314
|
+
|
315
|
+
private
|
316
|
+
|
317
|
+
def root_elem(rendered_content)
|
318
|
+
HTML::Document.new(rendered_content).root.children[0]
|
319
|
+
end
|
272
320
|
end
|
@@ -3,15 +3,10 @@ require 'abstract_unit'
|
|
3
3
|
class JavaScriptHelperTest < ActionView::TestCase
|
4
4
|
tests ActionView::Helpers::JavaScriptHelper
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
assert_not_nil src.split("\n")[1].match(/Prototype JavaScript framework/)
|
11
|
-
|
12
|
-
# check that scriptaculous.js is not in here, only needed if loaded remotely
|
13
|
-
assert_nil src.split("\n")[1].match(/var Scriptaculous = \{/)
|
14
|
-
end
|
6
|
+
attr_accessor :template_format, :output_buffer
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@template = self
|
15
10
|
end
|
16
11
|
|
17
12
|
def test_escape_javascript
|
@@ -51,7 +46,7 @@ class JavaScriptHelperTest < ActionView::TestCase
|
|
51
46
|
end
|
52
47
|
|
53
48
|
def test_link_to_function_with_href
|
54
|
-
assert_dom_equal %(<a href="http://example.com/" onclick="alert('Hello world!'); return false;">Greeting</a>),
|
49
|
+
assert_dom_equal %(<a href="http://example.com/" onclick="alert('Hello world!'); return false;">Greeting</a>),
|
55
50
|
link_to_function("Greeting", "alert('Hello world!')", :href => 'http://example.com/')
|
56
51
|
end
|
57
52
|
|
@@ -85,8 +80,12 @@ class JavaScriptHelperTest < ActionView::TestCase
|
|
85
80
|
end
|
86
81
|
|
87
82
|
def test_javascript_tag
|
83
|
+
self.output_buffer = 'foo'
|
84
|
+
|
88
85
|
assert_dom_equal "<script type=\"text/javascript\">\n//<![CDATA[\nalert('hello')\n//]]>\n</script>",
|
89
86
|
javascript_tag("alert('hello')")
|
87
|
+
|
88
|
+
assert_equal 'foo', output_buffer, 'javascript_tag without a block should not concat to output_buffer'
|
90
89
|
end
|
91
90
|
|
92
91
|
def test_javascript_tag_with_options
|
@@ -94,16 +93,16 @@ class JavaScriptHelperTest < ActionView::TestCase
|
|
94
93
|
javascript_tag("alert('hello')", :id => "the_js_tag")
|
95
94
|
end
|
96
95
|
|
97
|
-
def
|
98
|
-
|
99
|
-
javascript_tag {
|
100
|
-
assert_dom_equal "<script type=\"text/javascript\">\n//<![CDATA[\nalert('hello')\n//]]>\n</script>",
|
96
|
+
def test_javascript_tag_with_block_in_erb
|
97
|
+
__in_erb_template = ''
|
98
|
+
javascript_tag { concat "alert('hello')" }
|
99
|
+
assert_dom_equal "<script type=\"text/javascript\">\n//<![CDATA[\nalert('hello')\n//]]>\n</script>", output_buffer
|
101
100
|
end
|
102
101
|
|
103
|
-
def
|
104
|
-
|
105
|
-
javascript_tag(:id => "the_js_tag") {
|
106
|
-
assert_dom_equal "<script id=\"the_js_tag\" type=\"text/javascript\">\n//<![CDATA[\nalert('hello')\n//]]>\n</script>",
|
102
|
+
def test_javascript_tag_with_block_and_options_in_erb
|
103
|
+
__in_erb_template = ''
|
104
|
+
javascript_tag(:id => "the_js_tag") { concat "alert('hello')" }
|
105
|
+
assert_dom_equal "<script id=\"the_js_tag\" type=\"text/javascript\">\n//<![CDATA[\nalert('hello')\n//]]>\n</script>", output_buffer
|
107
106
|
end
|
108
107
|
|
109
108
|
def test_javascript_cdata_section
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
|
3
|
+
class NumberHelperI18nTests < Test::Unit::TestCase
|
4
|
+
include ActionView::Helpers::NumberHelper
|
5
|
+
|
6
|
+
attr_reader :request
|
7
|
+
|
8
|
+
uses_mocha 'number_helper_i18n_tests' do
|
9
|
+
def setup
|
10
|
+
@number_defaults = { :precision => 3, :delimiter => ',', :separator => '.' }
|
11
|
+
@currency_defaults = { :unit => '$', :format => '%u%n', :precision => 2 }
|
12
|
+
@human_defaults = { :precision => 1 }
|
13
|
+
@percentage_defaults = { :delimiter => '' }
|
14
|
+
@precision_defaults = { :delimiter => '' }
|
15
|
+
|
16
|
+
I18n.backend.store_translations 'en', :number => { :format => @number_defaults,
|
17
|
+
:currency => { :format => @currency_defaults }, :human => @human_defaults }
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_number_to_currency_translates_currency_formats
|
21
|
+
I18n.expects(:translate).with(:'number.format', :locale => 'en', :raise => true).returns(@number_defaults)
|
22
|
+
I18n.expects(:translate).with(:'number.currency.format', :locale => 'en',
|
23
|
+
:raise => true).returns(@currency_defaults)
|
24
|
+
number_to_currency(1, :locale => 'en')
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_number_with_precision_translates_number_formats
|
28
|
+
I18n.expects(:translate).with(:'number.format', :locale => 'en', :raise => true).returns(@number_defaults)
|
29
|
+
I18n.expects(:translate).with(:'number.precision.format', :locale => 'en',
|
30
|
+
:raise => true).returns(@precision_defaults)
|
31
|
+
number_with_precision(1, :locale => 'en')
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_number_with_delimiter_translates_number_formats
|
35
|
+
I18n.expects(:translate).with(:'number.format', :locale => 'en', :raise => true).returns(@number_defaults)
|
36
|
+
number_with_delimiter(1, :locale => 'en')
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_number_to_percentage_translates_number_formats
|
40
|
+
I18n.expects(:translate).with(:'number.format', :locale => 'en', :raise => true).returns(@number_defaults)
|
41
|
+
I18n.expects(:translate).with(:'number.percentage.format', :locale => 'en',
|
42
|
+
:raise => true).returns(@percentage_defaults)
|
43
|
+
number_to_percentage(1, :locale => 'en')
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_number_to_human_size_translates_human_formats
|
47
|
+
I18n.expects(:translate).with(:'number.format', :locale => 'en', :raise => true).returns(@number_defaults)
|
48
|
+
I18n.expects(:translate).with(:'number.human.format', :locale => 'en',
|
49
|
+
:raise => true).returns(@human_defaults)
|
50
|
+
# can't be called with 1 because this directly returns without calling I18n.translate
|
51
|
+
number_to_human_size(1025, :locale => 'en')
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -26,7 +26,8 @@ class NumberHelperTest < ActionView::TestCase
|
|
26
26
|
assert_equal("£1234567890,50", number_to_currency(1234567890.50, {:unit => "£", :separator => ",", :delimiter => ""}))
|
27
27
|
assert_equal("$1,234,567,890.50", number_to_currency("1234567890.50"))
|
28
28
|
assert_equal("1,234,567,890.50 Kč", number_to_currency("1234567890.50", {:unit => "Kč", :format => "%n %u"}))
|
29
|
-
assert_equal("$x.", number_to_currency("x"))
|
29
|
+
#assert_equal("$x.", number_to_currency("x")) # fails due to API consolidation
|
30
|
+
assert_equal("$x", number_to_currency("x"))
|
30
31
|
assert_nil number_to_currency(nil)
|
31
32
|
end
|
32
33
|
|
@@ -35,7 +36,9 @@ class NumberHelperTest < ActionView::TestCase
|
|
35
36
|
assert_equal("100%", number_to_percentage(100, {:precision => 0}))
|
36
37
|
assert_equal("302.06%", number_to_percentage(302.0574, {:precision => 2}))
|
37
38
|
assert_equal("100.000%", number_to_percentage("100"))
|
39
|
+
assert_equal("1000.000%", number_to_percentage("1000"))
|
38
40
|
assert_equal("x%", number_to_percentage("x"))
|
41
|
+
assert_equal("1.000,000%", number_to_percentage(1000, :delimiter => '.', :separator => ','))
|
39
42
|
assert_nil number_to_percentage(nil)
|
40
43
|
end
|
41
44
|
|
@@ -54,21 +57,33 @@ class NumberHelperTest < ActionView::TestCase
|
|
54
57
|
assert_nil number_with_delimiter(nil)
|
55
58
|
end
|
56
59
|
|
60
|
+
def test_number_with_delimiter_with_options_hash
|
61
|
+
assert_equal '12 345 678', number_with_delimiter(12345678, :delimiter => ' ')
|
62
|
+
assert_equal '12,345,678-05', number_with_delimiter(12345678.05, :separator => '-')
|
63
|
+
assert_equal '12.345.678,05', number_with_delimiter(12345678.05, :separator => ',', :delimiter => '.')
|
64
|
+
assert_equal '12.345.678,05', number_with_delimiter(12345678.05, :delimiter => '.', :separator => ',')
|
65
|
+
end
|
66
|
+
|
57
67
|
def test_number_with_precision
|
58
68
|
assert_equal("111.235", number_with_precision(111.2346))
|
59
|
-
assert_equal("31.83", number_with_precision(31.825, 2))
|
60
|
-
assert_equal("111.23", number_with_precision(111.2346, 2))
|
61
|
-
assert_equal("111.00", number_with_precision(111, 2))
|
69
|
+
assert_equal("31.83", number_with_precision(31.825, :precision => 2))
|
70
|
+
assert_equal("111.23", number_with_precision(111.2346, :precision => 2))
|
71
|
+
assert_equal("111.00", number_with_precision(111, :precision => 2))
|
62
72
|
assert_equal("111.235", number_with_precision("111.2346"))
|
63
|
-
assert_equal("31.83", number_with_precision("31.825", 2))
|
64
|
-
assert_equal("112", number_with_precision(111.50, 0))
|
65
|
-
assert_equal("1234567892", number_with_precision(1234567891.50, 0))
|
73
|
+
assert_equal("31.83", number_with_precision("31.825", :precision => 2))
|
74
|
+
assert_equal("112", number_with_precision(111.50, :precision => 0))
|
75
|
+
assert_equal("1234567892", number_with_precision(1234567891.50, :precision => 0))
|
66
76
|
|
67
77
|
# Return non-numeric params unchanged.
|
68
78
|
assert_equal("x", number_with_precision("x"))
|
69
79
|
assert_nil number_with_precision(nil)
|
70
80
|
end
|
71
81
|
|
82
|
+
def test_number_with_precision_with_custom_delimiter_and_separator
|
83
|
+
assert_equal '31,83', number_with_precision(31.825, :precision => 2, :separator => ',')
|
84
|
+
assert_equal '1.231,83', number_with_precision(1231.825, :precision => 2, :separator => ',', :delimiter => '.')
|
85
|
+
end
|
86
|
+
|
72
87
|
def test_number_to_human_size
|
73
88
|
assert_equal '0 Bytes', number_to_human_size(0)
|
74
89
|
assert_equal '1 Byte', number_to_human_size(1)
|
@@ -80,18 +95,33 @@ class NumberHelperTest < ActionView::TestCase
|
|
80
95
|
assert_equal '1.2 MB', number_to_human_size(1234567)
|
81
96
|
assert_equal '1.1 GB', number_to_human_size(1234567890)
|
82
97
|
assert_equal '1.1 TB', number_to_human_size(1234567890123)
|
98
|
+
assert_equal '1025 TB', number_to_human_size(1025.terabytes)
|
83
99
|
assert_equal '444 KB', number_to_human_size(444.kilobytes)
|
84
100
|
assert_equal '1023 MB', number_to_human_size(1023.megabytes)
|
85
101
|
assert_equal '3 TB', number_to_human_size(3.terabytes)
|
86
|
-
assert_equal '1.18 MB', number_to_human_size(1234567, 2)
|
87
|
-
assert_equal '3 Bytes', number_to_human_size(3.14159265, 4)
|
102
|
+
assert_equal '1.18 MB', number_to_human_size(1234567, :precision => 2)
|
103
|
+
assert_equal '3 Bytes', number_to_human_size(3.14159265, :precision => 4)
|
88
104
|
assert_equal("123 Bytes", number_to_human_size("123"))
|
89
|
-
assert_equal '1.01 KB', number_to_human_size(1.0123.kilobytes, 2)
|
90
|
-
assert_equal '1.01 KB', number_to_human_size(1.0100.kilobytes, 4)
|
91
|
-
assert_equal '10 KB', number_to_human_size(10.000.kilobytes, 4)
|
105
|
+
assert_equal '1.01 KB', number_to_human_size(1.0123.kilobytes, :precision => 2)
|
106
|
+
assert_equal '1.01 KB', number_to_human_size(1.0100.kilobytes, :precision => 4)
|
107
|
+
assert_equal '10 KB', number_to_human_size(10.000.kilobytes, :precision => 4)
|
92
108
|
assert_equal '1 Byte', number_to_human_size(1.1)
|
93
109
|
assert_equal '10 Bytes', number_to_human_size(10)
|
94
|
-
assert_nil number_to_human_size('x')
|
110
|
+
#assert_nil number_to_human_size('x') # fails due to API consolidation
|
95
111
|
assert_nil number_to_human_size(nil)
|
96
112
|
end
|
113
|
+
|
114
|
+
def test_number_to_human_size_with_options_hash
|
115
|
+
assert_equal '1.18 MB', number_to_human_size(1234567, :precision => 2)
|
116
|
+
assert_equal '3 Bytes', number_to_human_size(3.14159265, :precision => 4)
|
117
|
+
assert_equal '1.01 KB', number_to_human_size(1.0123.kilobytes, :precision => 2)
|
118
|
+
assert_equal '1.01 KB', number_to_human_size(1.0100.kilobytes, :precision => 4)
|
119
|
+
assert_equal '10 KB', number_to_human_size(10.000.kilobytes, :precision => 4)
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_number_to_human_size_with_custom_delimiter_and_separator
|
123
|
+
assert_equal '1,01 KB', number_to_human_size(1.0123.kilobytes, :precision => 2, :separator => ',')
|
124
|
+
assert_equal '1,01 KB', number_to_human_size(1.0100.kilobytes, :precision => 4, :separator => ',')
|
125
|
+
assert_equal '1.000,1 TB', number_to_human_size(1000.1.terabytes, :delimiter => '.', :separator => ',')
|
126
|
+
end
|
97
127
|
end
|