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
@@ -25,10 +25,10 @@ class Author::Nested < Author; end
|
|
25
25
|
|
26
26
|
|
27
27
|
class PrototypeHelperBaseTest < ActionView::TestCase
|
28
|
-
attr_accessor :template_format
|
28
|
+
attr_accessor :template_format, :output_buffer
|
29
29
|
|
30
30
|
def setup
|
31
|
-
@template =
|
31
|
+
@template = self
|
32
32
|
@controller = Class.new do
|
33
33
|
def url_for(options)
|
34
34
|
if options.is_a?(String)
|
@@ -54,7 +54,7 @@ class PrototypeHelperBaseTest < ActionView::TestCase
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def create_generator
|
57
|
-
block = Proc.new { |*args| yield *args if block_given? }
|
57
|
+
block = Proc.new { |*args| yield *args if block_given? }
|
58
58
|
JavaScriptGenerator.new self, &block
|
59
59
|
end
|
60
60
|
end
|
@@ -70,7 +70,7 @@ class PrototypeHelperTest < PrototypeHelperBaseTest
|
|
70
70
|
assert_dom_equal %(<a class=\"fine\" href=\"#\" onclick=\"new Ajax.Request('http://www.example.com/whatnot', {asynchronous:true, evalScripts:true}); return false;\">Remote outauthor</a>),
|
71
71
|
link_to_remote("Remote outauthor", { :url => { :action => "whatnot" }}, { :class => "fine" })
|
72
72
|
assert_dom_equal %(<a href=\"#\" onclick=\"new Ajax.Request('http://www.example.com/whatnot', {asynchronous:true, evalScripts:true, onComplete:function(request){alert(request.responseText)}}); return false;\">Remote outauthor</a>),
|
73
|
-
link_to_remote("Remote outauthor", :complete => "alert(request.responseText)", :url => { :action => "whatnot" })
|
73
|
+
link_to_remote("Remote outauthor", :complete => "alert(request.responseText)", :url => { :action => "whatnot" })
|
74
74
|
assert_dom_equal %(<a href=\"#\" onclick=\"new Ajax.Request('http://www.example.com/whatnot', {asynchronous:true, evalScripts:true, onSuccess:function(request){alert(request.responseText)}}); return false;\">Remote outauthor</a>),
|
75
75
|
link_to_remote("Remote outauthor", :success => "alert(request.responseText)", :url => { :action => "whatnot" })
|
76
76
|
assert_dom_equal %(<a href=\"#\" onclick=\"new Ajax.Request('http://www.example.com/whatnot', {asynchronous:true, evalScripts:true, onFailure:function(request){alert(request.responseText)}}); return false;\">Remote outauthor</a>),
|
@@ -82,29 +82,42 @@ class PrototypeHelperTest < PrototypeHelperBaseTest
|
|
82
82
|
assert_dom_equal %(<a href=\"#\" onclick=\"new Ajax.Request('http://www.example.com/whatnot', {asynchronous:true, evalScripts:true, insertion:'bottom'}); return false;\">Remote outauthor</a>),
|
83
83
|
link_to_remote("Remote outauthor", :url => { :action => "whatnot" }, :position => :bottom)
|
84
84
|
end
|
85
|
-
|
85
|
+
|
86
86
|
def test_link_to_remote_html_options
|
87
87
|
assert_dom_equal %(<a class=\"fine\" href=\"#\" onclick=\"new Ajax.Request('http://www.example.com/whatnot', {asynchronous:true, evalScripts:true}); return false;\">Remote outauthor</a>),
|
88
88
|
link_to_remote("Remote outauthor", { :url => { :action => "whatnot" }, :html => { :class => "fine" } })
|
89
89
|
end
|
90
|
-
|
90
|
+
|
91
91
|
def test_link_to_remote_url_quote_escaping
|
92
92
|
assert_dom_equal %(<a href="#" onclick="new Ajax.Request('http://www.example.com/whatnot\\\'s', {asynchronous:true, evalScripts:true}); return false;">Remote</a>),
|
93
93
|
link_to_remote("Remote", { :url => { :action => "whatnot's" } })
|
94
94
|
end
|
95
95
|
|
96
|
+
def test_button_to_remote
|
97
|
+
assert_dom_equal %(<input class=\"fine\" type=\"button\" value=\"Remote outpost\" onclick=\"new Ajax.Request('http://www.example.com/whatnot', {asynchronous:true, evalScripts:true});\" />),
|
98
|
+
button_to_remote("Remote outpost", { :url => { :action => "whatnot" }}, { :class => "fine" })
|
99
|
+
assert_dom_equal %(<input type=\"button\" value=\"Remote outpost\" onclick=\"new Ajax.Request('http://www.example.com/whatnot', {asynchronous:true, evalScripts:true, onComplete:function(request){alert(request.reponseText)}});\" />),
|
100
|
+
button_to_remote("Remote outpost", :complete => "alert(request.reponseText)", :url => { :action => "whatnot" })
|
101
|
+
assert_dom_equal %(<input type=\"button\" value=\"Remote outpost\" onclick=\"new Ajax.Request('http://www.example.com/whatnot', {asynchronous:true, evalScripts:true, onSuccess:function(request){alert(request.reponseText)}});\" />),
|
102
|
+
button_to_remote("Remote outpost", :success => "alert(request.reponseText)", :url => { :action => "whatnot" })
|
103
|
+
assert_dom_equal %(<input type=\"button\" value=\"Remote outpost\" onclick=\"new Ajax.Request('http://www.example.com/whatnot', {asynchronous:true, evalScripts:true, onFailure:function(request){alert(request.reponseText)}});\" />),
|
104
|
+
button_to_remote("Remote outpost", :failure => "alert(request.reponseText)", :url => { :action => "whatnot" })
|
105
|
+
assert_dom_equal %(<input type=\"button\" value=\"Remote outpost\" onclick=\"new Ajax.Request('http://www.example.com/whatnot?a=10&b=20', {asynchronous:true, evalScripts:true, onFailure:function(request){alert(request.reponseText)}});\" />),
|
106
|
+
button_to_remote("Remote outpost", :failure => "alert(request.reponseText)", :url => { :action => "whatnot", :a => '10', :b => '20' })
|
107
|
+
end
|
108
|
+
|
96
109
|
def test_periodically_call_remote
|
97
110
|
assert_dom_equal %(<script type="text/javascript">\n//<![CDATA[\nnew PeriodicalExecuter(function() {new Ajax.Updater('schremser_bier', 'http://www.example.com/mehr_bier', {asynchronous:true, evalScripts:true})}, 10)\n//]]>\n</script>),
|
98
111
|
periodically_call_remote(:update => "schremser_bier", :url => { :action => "mehr_bier" })
|
99
112
|
end
|
100
|
-
|
113
|
+
|
101
114
|
def test_periodically_call_remote_with_frequency
|
102
115
|
assert_dom_equal(
|
103
116
|
"<script type=\"text/javascript\">\n//<![CDATA[\nnew PeriodicalExecuter(function() {new Ajax.Request('http://www.example.com/', {asynchronous:true, evalScripts:true})}, 2)\n//]]>\n</script>",
|
104
117
|
periodically_call_remote(:frequency => 2)
|
105
118
|
)
|
106
119
|
end
|
107
|
-
|
120
|
+
|
108
121
|
def test_form_remote_tag
|
109
122
|
assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater('glass_of_beer', 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;\">),
|
110
123
|
form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast })
|
@@ -121,53 +134,48 @@ class PrototypeHelperTest < PrototypeHelperBaseTest
|
|
121
134
|
form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast }, :html => { :method => :put })
|
122
135
|
end
|
123
136
|
|
124
|
-
def
|
125
|
-
|
126
|
-
form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast }) {
|
127
|
-
assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater('glass_of_beer', 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;\">Hello world!</form>),
|
137
|
+
def test_form_remote_tag_with_block_in_erb
|
138
|
+
__in_erb_template = ''
|
139
|
+
form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast }) { concat "Hello world!" }
|
140
|
+
assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater('glass_of_beer', 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;\">Hello world!</form>), output_buffer
|
128
141
|
end
|
129
142
|
|
130
143
|
def test_remote_form_for_with_record_identification_with_new_record
|
131
|
-
_erbout = ''
|
132
144
|
remote_form_for(@record, {:html => { :id => 'create-author' }}) {}
|
133
|
-
|
145
|
+
|
134
146
|
expected = %(<form action='#{authors_path}' onsubmit="new Ajax.Request('#{authors_path}', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;" class='new_author' id='create-author' method='post'></form>)
|
135
|
-
assert_dom_equal expected,
|
147
|
+
assert_dom_equal expected, output_buffer
|
136
148
|
end
|
137
149
|
|
138
150
|
def test_remote_form_for_with_record_identification_without_html_options
|
139
|
-
_erbout = ''
|
140
151
|
remote_form_for(@record) {}
|
141
|
-
|
152
|
+
|
142
153
|
expected = %(<form action='#{authors_path}' onsubmit="new Ajax.Request('#{authors_path}', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;" class='new_author' method='post' id='new_author'></form>)
|
143
|
-
assert_dom_equal expected,
|
154
|
+
assert_dom_equal expected, output_buffer
|
144
155
|
end
|
145
156
|
|
146
157
|
def test_remote_form_for_with_record_identification_with_existing_record
|
147
158
|
@record.save
|
148
|
-
_erbout = ''
|
149
159
|
remote_form_for(@record) {}
|
150
|
-
|
160
|
+
|
151
161
|
expected = %(<form action='#{author_path(@record)}' id='edit_author_1' method='post' onsubmit="new Ajax.Request('#{author_path(@record)}', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;" class='edit_author'><div style='margin:0;padding:0'><input name='_method' type='hidden' value='put' /></div></form>)
|
152
|
-
assert_dom_equal expected,
|
162
|
+
assert_dom_equal expected, output_buffer
|
153
163
|
end
|
154
164
|
|
155
165
|
def test_remote_form_for_with_new_object_in_list
|
156
|
-
_erbout = ''
|
157
166
|
remote_form_for([@author, @article]) {}
|
158
|
-
|
167
|
+
|
159
168
|
expected = %(<form action='#{author_articles_path(@author)}' onsubmit="new Ajax.Request('#{author_articles_path(@author)}', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;" class='new_article' method='post' id='new_article'></form>)
|
160
|
-
assert_dom_equal expected,
|
169
|
+
assert_dom_equal expected, output_buffer
|
161
170
|
end
|
162
|
-
|
171
|
+
|
163
172
|
def test_remote_form_for_with_existing_object_in_list
|
164
173
|
@author.save
|
165
174
|
@article.save
|
166
|
-
_erbout = ''
|
167
175
|
remote_form_for([@author, @article]) {}
|
168
|
-
|
176
|
+
|
169
177
|
expected = %(<form action='#{author_article_path(@author, @article)}' id='edit_article_1' method='post' onsubmit="new Ajax.Request('#{author_article_path(@author, @article)}', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;" class='edit_article'><div style='margin:0;padding:0'><input name='_method' type='hidden' value='put' /></div></form>)
|
170
|
-
assert_dom_equal expected,
|
178
|
+
assert_dom_equal expected, output_buffer
|
171
179
|
end
|
172
180
|
|
173
181
|
def test_on_callbacks
|
@@ -182,18 +190,18 @@ class PrototypeHelperTest < PrototypeHelperBaseTest
|
|
182
190
|
assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater({success:'glass_of_beer',failure:'glass_of_water'}, 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, on#{callback.to_s.capitalize}:function(request){monkeys();}, parameters:Form.serialize(this)}); return false;">),
|
183
191
|
form_remote_tag(:update => { :success => "glass_of_beer", :failure => "glass_of_water" }, :url => { :action => :fast }, callback=>"monkeys();")
|
184
192
|
end
|
185
|
-
|
193
|
+
|
186
194
|
#HTTP status codes 200 up to 599 have callbacks
|
187
195
|
#these should work
|
188
196
|
100.upto(599) do |callback|
|
189
197
|
assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater('glass_of_beer', 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, on#{callback.to_s.capitalize}:function(request){monkeys();}, parameters:Form.serialize(this)}); return false;">),
|
190
198
|
form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast }, callback=>"monkeys();")
|
191
199
|
end
|
192
|
-
|
200
|
+
|
193
201
|
#test 200 and 404
|
194
202
|
assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater('glass_of_beer', 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, on200:function(request){monkeys();}, on404:function(request){bananas();}, parameters:Form.serialize(this)}); return false;">),
|
195
203
|
form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast }, 200=>"monkeys();", 404=>"bananas();")
|
196
|
-
|
204
|
+
|
197
205
|
#these shouldn't
|
198
206
|
1.upto(99) do |callback|
|
199
207
|
assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater('glass_of_beer', 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;">),
|
@@ -203,44 +211,44 @@ class PrototypeHelperTest < PrototypeHelperBaseTest
|
|
203
211
|
assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater('glass_of_beer', 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;">),
|
204
212
|
form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast }, callback=>"monkeys();")
|
205
213
|
end
|
206
|
-
|
214
|
+
|
207
215
|
#test ultimate combo
|
208
216
|
assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater('glass_of_beer', 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, on200:function(request){monkeys();}, on404:function(request){bananas();}, onComplete:function(request){c();}, onFailure:function(request){f();}, onLoading:function(request){c1()}, onSuccess:function(request){s()}, parameters:Form.serialize(this)}); return false;\">),
|
209
217
|
form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast }, :loading => "c1()", :success => "s()", :failure => "f();", :complete => "c();", 200=>"monkeys();", 404=>"bananas();")
|
210
|
-
|
218
|
+
|
211
219
|
end
|
212
|
-
|
220
|
+
|
213
221
|
def test_submit_to_remote
|
214
|
-
assert_dom_equal %(<input name=\"More beer!\" onclick=\"new Ajax.Updater('empty_bottle', 'http://www.example.com/', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this.form)})
|
222
|
+
assert_dom_equal %(<input name=\"More beer!\" onclick=\"new Ajax.Updater('empty_bottle', 'http://www.example.com/', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this.form)});\" type=\"button\" value=\"1000000\" />),
|
215
223
|
submit_to_remote("More beer!", 1_000_000, :update => "empty_bottle")
|
216
224
|
end
|
217
|
-
|
225
|
+
|
218
226
|
def test_observe_field
|
219
227
|
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Form.Element.Observer('glass', 300, function(element, value) {new Ajax.Request('http://www.example.com/reorder_if_empty', {asynchronous:true, evalScripts:true, parameters:value})})\n//]]>\n</script>),
|
220
228
|
observe_field("glass", :frequency => 5.minutes, :url => { :action => "reorder_if_empty" })
|
221
229
|
end
|
222
|
-
|
230
|
+
|
223
231
|
def test_observe_field_using_with_option
|
224
232
|
expected = %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Form.Element.Observer('glass', 300, function(element, value) {new Ajax.Request('http://www.example.com/check_value', {asynchronous:true, evalScripts:true, parameters:'id=' + encodeURIComponent(value)})})\n//]]>\n</script>)
|
225
233
|
assert_dom_equal expected, observe_field("glass", :frequency => 5.minutes, :url => { :action => "check_value" }, :with => 'id')
|
226
234
|
assert_dom_equal expected, observe_field("glass", :frequency => 5.minutes, :url => { :action => "check_value" }, :with => "'id=' + encodeURIComponent(value)")
|
227
235
|
end
|
228
|
-
|
236
|
+
|
229
237
|
def test_observe_field_using_json_in_with_option
|
230
238
|
expected = %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Form.Element.Observer('glass', 300, function(element, value) {new Ajax.Request('http://www.example.com/check_value', {asynchronous:true, evalScripts:true, parameters:{'id':value}})})\n//]]>\n</script>)
|
231
|
-
assert_dom_equal expected, observe_field("glass", :frequency => 5.minutes, :url => { :action => "check_value" }, :with => "{'id':value}")
|
239
|
+
assert_dom_equal expected, observe_field("glass", :frequency => 5.minutes, :url => { :action => "check_value" }, :with => "{'id':value}")
|
232
240
|
end
|
233
|
-
|
241
|
+
|
234
242
|
def test_observe_field_using_function_for_callback
|
235
243
|
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Form.Element.Observer('glass', 300, function(element, value) {alert('Element changed')})\n//]]>\n</script>),
|
236
244
|
observe_field("glass", :frequency => 5.minutes, :function => "alert('Element changed')")
|
237
245
|
end
|
238
|
-
|
246
|
+
|
239
247
|
def test_observe_form
|
240
248
|
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Form.Observer('cart', 2, function(element, value) {new Ajax.Request('http://www.example.com/cart_changed', {asynchronous:true, evalScripts:true, parameters:value})})\n//]]>\n</script>),
|
241
249
|
observe_form("cart", :frequency => 2, :url => { :action => "cart_changed" })
|
242
250
|
end
|
243
|
-
|
251
|
+
|
244
252
|
def test_observe_form_using_function_for_callback
|
245
253
|
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Form.Observer('cart', 2, function(element, value) {alert('Form changed')})\n//]]>\n</script>),
|
246
254
|
observe_form("cart", :frequency => 2, :function => "alert('Form changed')")
|
@@ -252,10 +260,14 @@ class PrototypeHelperTest < PrototypeHelperBaseTest
|
|
252
260
|
end
|
253
261
|
|
254
262
|
def test_update_page
|
263
|
+
old_output_buffer = output_buffer
|
264
|
+
|
255
265
|
block = Proc.new { |page| page.replace_html('foo', 'bar') }
|
256
266
|
assert_equal create_generator(&block).to_s, update_page(&block)
|
267
|
+
|
268
|
+
assert_equal old_output_buffer, output_buffer
|
257
269
|
end
|
258
|
-
|
270
|
+
|
259
271
|
def test_update_page_tag
|
260
272
|
block = Proc.new { |page| page.replace_html('foo', 'bar') }
|
261
273
|
assert_equal javascript_tag(create_generator(&block).to_s), update_page_tag(&block)
|
@@ -271,15 +283,15 @@ class PrototypeHelperTest < PrototypeHelperBaseTest
|
|
271
283
|
def author_path(record)
|
272
284
|
"/authors/#{record.id}"
|
273
285
|
end
|
274
|
-
|
286
|
+
|
275
287
|
def authors_path
|
276
288
|
"/authors"
|
277
289
|
end
|
278
|
-
|
290
|
+
|
279
291
|
def author_articles_path(author)
|
280
292
|
"/authors/#{author.id}/articles"
|
281
293
|
end
|
282
|
-
|
294
|
+
|
283
295
|
def author_article_path(author, article)
|
284
296
|
"/authors/#{author.id}/articles/#{article.id}"
|
285
297
|
end
|
@@ -290,7 +302,7 @@ class JavaScriptGeneratorTest < PrototypeHelperBaseTest
|
|
290
302
|
super
|
291
303
|
@generator = create_generator
|
292
304
|
end
|
293
|
-
|
305
|
+
|
294
306
|
def test_insert_html_with_string
|
295
307
|
assert_equal 'Element.insert("element", { top: "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E" });',
|
296
308
|
@generator.insert_html(:top, 'element', '<p>This is a test</p>')
|
@@ -301,70 +313,75 @@ class JavaScriptGeneratorTest < PrototypeHelperBaseTest
|
|
301
313
|
assert_equal 'Element.insert("element", { after: "\\u003Cp\u003EThis is a test\\u003C/p\u003E" });',
|
302
314
|
@generator.insert_html(:after, 'element', '<p>This is a test</p>')
|
303
315
|
end
|
304
|
-
|
316
|
+
|
305
317
|
def test_replace_html_with_string
|
306
318
|
assert_equal 'Element.update("element", "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E");',
|
307
319
|
@generator.replace_html('element', '<p>This is a test</p>')
|
308
320
|
end
|
309
|
-
|
321
|
+
|
310
322
|
def test_replace_element_with_string
|
311
323
|
assert_equal 'Element.replace("element", "\\u003Cdiv id=\"element\"\\u003E\\u003Cp\\u003EThis is a test\\u003C/p\\u003E\\u003C/div\\u003E");',
|
312
324
|
@generator.replace('element', '<div id="element"><p>This is a test</p></div>')
|
313
325
|
end
|
314
|
-
|
326
|
+
|
315
327
|
def test_remove
|
316
328
|
assert_equal 'Element.remove("foo");',
|
317
329
|
@generator.remove('foo')
|
318
330
|
assert_equal '["foo", "bar", "baz"].each(Element.remove);',
|
319
331
|
@generator.remove('foo', 'bar', 'baz')
|
320
332
|
end
|
321
|
-
|
333
|
+
|
322
334
|
def test_show
|
323
335
|
assert_equal 'Element.show("foo");',
|
324
336
|
@generator.show('foo')
|
325
337
|
assert_equal '["foo", "bar", "baz"].each(Element.show);',
|
326
|
-
@generator.show('foo', 'bar', 'baz')
|
338
|
+
@generator.show('foo', 'bar', 'baz')
|
327
339
|
end
|
328
|
-
|
340
|
+
|
329
341
|
def test_hide
|
330
342
|
assert_equal 'Element.hide("foo");',
|
331
343
|
@generator.hide('foo')
|
332
344
|
assert_equal '["foo", "bar", "baz"].each(Element.hide);',
|
333
|
-
@generator.hide('foo', 'bar', 'baz')
|
345
|
+
@generator.hide('foo', 'bar', 'baz')
|
334
346
|
end
|
335
|
-
|
347
|
+
|
336
348
|
def test_toggle
|
337
349
|
assert_equal 'Element.toggle("foo");',
|
338
350
|
@generator.toggle('foo')
|
339
351
|
assert_equal '["foo", "bar", "baz"].each(Element.toggle);',
|
340
|
-
@generator.toggle('foo', 'bar', 'baz')
|
352
|
+
@generator.toggle('foo', 'bar', 'baz')
|
341
353
|
end
|
342
|
-
|
354
|
+
|
343
355
|
def test_alert
|
344
356
|
assert_equal 'alert("hello");', @generator.alert('hello')
|
345
357
|
end
|
346
|
-
|
358
|
+
|
347
359
|
def test_redirect_to
|
348
360
|
assert_equal 'window.location.href = "http://www.example.com/welcome";',
|
349
361
|
@generator.redirect_to(:action => 'welcome')
|
350
362
|
assert_equal 'window.location.href = "http://www.example.com/welcome?a=b&c=d";',
|
351
363
|
@generator.redirect_to("http://www.example.com/welcome?a=b&c=d")
|
352
364
|
end
|
353
|
-
|
365
|
+
|
366
|
+
def test_reload
|
367
|
+
assert_equal 'window.location.reload();',
|
368
|
+
@generator.reload
|
369
|
+
end
|
370
|
+
|
354
371
|
def test_delay
|
355
372
|
@generator.delay(20) do
|
356
373
|
@generator.hide('foo')
|
357
374
|
end
|
358
|
-
|
375
|
+
|
359
376
|
assert_equal "setTimeout(function() {\n;\nElement.hide(\"foo\");\n}, 20000);", @generator.to_s
|
360
377
|
end
|
361
|
-
|
378
|
+
|
362
379
|
def test_to_s
|
363
380
|
@generator.insert_html(:top, 'element', '<p>This is a test</p>')
|
364
381
|
@generator.insert_html(:bottom, 'element', '<p>This is a test</p>')
|
365
382
|
@generator.remove('foo', 'bar')
|
366
383
|
@generator.replace_html('baz', '<p>This is a test</p>')
|
367
|
-
|
384
|
+
|
368
385
|
assert_equal <<-EOS.chomp, @generator.to_s
|
369
386
|
Element.insert("element", { top: "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E" });
|
370
387
|
Element.insert("element", { bottom: "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E" });
|
@@ -386,12 +403,12 @@ Element.update("baz", "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E");
|
|
386
403
|
@generator['hello'].hide
|
387
404
|
assert_equal %($("hello").hide();), @generator.to_s
|
388
405
|
end
|
389
|
-
|
406
|
+
|
390
407
|
def test_element_proxy_variable_access
|
391
408
|
@generator['hello']['style']
|
392
409
|
assert_equal %($("hello").style;), @generator.to_s
|
393
410
|
end
|
394
|
-
|
411
|
+
|
395
412
|
def test_element_proxy_variable_access_with_assignment
|
396
413
|
@generator['hello']['style']['color'] = 'red'
|
397
414
|
assert_equal %($("hello").style.color = "red";), @generator.to_s
|
@@ -406,7 +423,7 @@ Element.update("baz", "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E");
|
|
406
423
|
@generator['hello'].hide("first").clean_whitespace
|
407
424
|
assert_equal %($("hello").hide("first").cleanWhitespace();), @generator.to_s
|
408
425
|
end
|
409
|
-
|
426
|
+
|
410
427
|
def test_select_access
|
411
428
|
assert_equal %($$("div.hello");), @generator.select('div.hello')
|
412
429
|
end
|
@@ -415,31 +432,31 @@ Element.update("baz", "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E");
|
|
415
432
|
@generator.select('p.welcome b').first.hide
|
416
433
|
assert_equal %($$("p.welcome b").first().hide();), @generator.to_s
|
417
434
|
end
|
418
|
-
|
435
|
+
|
419
436
|
def test_visual_effect
|
420
|
-
assert_equal %(new Effect.Puff("blah",{});),
|
437
|
+
assert_equal %(new Effect.Puff("blah",{});),
|
421
438
|
@generator.visual_effect(:puff,'blah')
|
422
|
-
end
|
423
|
-
|
439
|
+
end
|
440
|
+
|
424
441
|
def test_visual_effect_toggle
|
425
|
-
assert_equal %(Effect.toggle("blah",'appear',{});),
|
442
|
+
assert_equal %(Effect.toggle("blah",'appear',{});),
|
426
443
|
@generator.visual_effect(:toggle_appear,'blah')
|
427
444
|
end
|
428
|
-
|
445
|
+
|
429
446
|
def test_sortable
|
430
|
-
assert_equal %(Sortable.create("blah", {onUpdate:function(){new Ajax.Request('http://www.example.com/order', {asynchronous:true, evalScripts:true, parameters:Sortable.serialize("blah")})}});),
|
447
|
+
assert_equal %(Sortable.create("blah", {onUpdate:function(){new Ajax.Request('http://www.example.com/order', {asynchronous:true, evalScripts:true, parameters:Sortable.serialize("blah")})}});),
|
431
448
|
@generator.sortable('blah', :url => { :action => "order" })
|
432
449
|
assert_equal %(Sortable.create("blah", {onUpdate:function(){new Ajax.Request('http://www.example.com/order', {asynchronous:false, evalScripts:true, parameters:Sortable.serialize("blah")})}});),
|
433
450
|
@generator.sortable('blah', :url => { :action => "order" }, :type => :synchronous)
|
434
451
|
end
|
435
|
-
|
452
|
+
|
436
453
|
def test_draggable
|
437
|
-
assert_equal %(new Draggable("blah", {});),
|
454
|
+
assert_equal %(new Draggable("blah", {});),
|
438
455
|
@generator.draggable('blah')
|
439
456
|
end
|
440
|
-
|
457
|
+
|
441
458
|
def test_drop_receiving
|
442
|
-
assert_equal %(Droppables.add("blah", {onDrop:function(element){new Ajax.Request('http://www.example.com/order', {asynchronous:true, evalScripts:true, parameters:'id=' + encodeURIComponent(element.id)})}});),
|
459
|
+
assert_equal %(Droppables.add("blah", {onDrop:function(element){new Ajax.Request('http://www.example.com/order', {asynchronous:true, evalScripts:true, parameters:'id=' + encodeURIComponent(element.id)})}});),
|
443
460
|
@generator.drop_receiving('blah', :url => { :action => "order" })
|
444
461
|
assert_equal %(Droppables.add("blah", {onDrop:function(element){new Ajax.Request('http://www.example.com/order', {asynchronous:false, evalScripts:true, parameters:'id=' + encodeURIComponent(element.id)})}});),
|
445
462
|
@generator.drop_receiving('blah', :url => { :action => "order" }, :type => :synchronous)
|
@@ -543,7 +560,7 @@ return array.reverse();
|
|
543
560
|
});
|
544
561
|
EOS
|
545
562
|
end
|
546
|
-
|
563
|
+
|
547
564
|
def test_collection_proxy_with_find_all
|
548
565
|
@generator.select('p').find_all 'a' do |value, index|
|
549
566
|
@generator << '(value.className == "welcome")'
|
@@ -555,7 +572,7 @@ return (value.className == "welcome");
|
|
555
572
|
});
|
556
573
|
EOS
|
557
574
|
end
|
558
|
-
|
575
|
+
|
559
576
|
def test_collection_proxy_with_in_groups_of
|
560
577
|
@generator.select('p').in_groups_of('a', 3)
|
561
578
|
@generator.select('p').in_groups_of('a', 3, 'x')
|
@@ -564,13 +581,13 @@ var a = $$("p").inGroupsOf(3);
|
|
564
581
|
var a = $$("p").inGroupsOf(3, "x");
|
565
582
|
EOS
|
566
583
|
end
|
567
|
-
|
584
|
+
|
568
585
|
def test_collection_proxy_with_each_slice
|
569
586
|
@generator.select('p').each_slice('a', 3)
|
570
587
|
@generator.select('p').each_slice('a', 3) do |group, index|
|
571
588
|
group.reverse
|
572
589
|
end
|
573
|
-
|
590
|
+
|
574
591
|
assert_equal <<-EOS.strip, @generator.to_s
|
575
592
|
var a = $$("p").eachSlice(3);
|
576
593
|
var a = $$("p").eachSlice(3, function(value, index) {
|
@@ -578,7 +595,7 @@ return value.reverse();
|
|
578
595
|
});
|
579
596
|
EOS
|
580
597
|
end
|
581
|
-
|
598
|
+
|
582
599
|
def test_debug_rjs
|
583
600
|
ActionView::Base.debug_rjs = true
|
584
601
|
@generator['welcome'].replace_html 'Welcome'
|
@@ -586,7 +603,7 @@ return value.reverse();
|
|
586
603
|
ensure
|
587
604
|
ActionView::Base.debug_rjs = false
|
588
605
|
end
|
589
|
-
|
606
|
+
|
590
607
|
def test_literal
|
591
608
|
literal = @generator.literal("function() {}")
|
592
609
|
assert_equal "function() {}", literal.to_json
|
@@ -597,7 +614,7 @@ return value.reverse();
|
|
597
614
|
@generator.form.focus('my_field')
|
598
615
|
assert_equal "Form.focus(\"my_field\");", @generator.to_s
|
599
616
|
end
|
600
|
-
|
617
|
+
|
601
618
|
def test_call_with_block
|
602
619
|
@generator.call(:before)
|
603
620
|
@generator.call(:my_method) do |p|
|
@@ -610,7 +627,7 @@ return value.reverse();
|
|
610
627
|
end
|
611
628
|
assert_equal "before();\nmy_method(function() { $(\"one\").show();\n$(\"two\").hide(); });\nin_between();\nmy_method_with_arguments(true, \"hello\", function() { $(\"three\").visualEffect(\"highlight\"); });", @generator.to_s
|
612
629
|
end
|
613
|
-
|
630
|
+
|
614
631
|
def test_class_proxy_call_with_block
|
615
632
|
@generator.my_object.my_method do |p|
|
616
633
|
p[:one].show
|