actionpack 2.0.5 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,4 +1,4 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'abstract_unit'
|
|
2
2
|
|
|
3
3
|
class MockTimeZone
|
|
4
4
|
attr_reader :name
|
|
@@ -22,15 +22,15 @@ end
|
|
|
22
22
|
|
|
23
23
|
ActionView::Helpers::FormOptionsHelper::TimeZone = MockTimeZone
|
|
24
24
|
|
|
25
|
-
class FormOptionsHelperTest <
|
|
26
|
-
|
|
27
|
-
include ActionView::Helpers::FormOptionsHelper
|
|
25
|
+
class FormOptionsHelperTest < ActionView::TestCase
|
|
26
|
+
tests ActionView::Helpers::FormOptionsHelper
|
|
28
27
|
|
|
29
28
|
silence_warnings do
|
|
30
29
|
Post = Struct.new('Post', :title, :author_name, :body, :secret, :written_on, :category, :origin)
|
|
31
30
|
Continent = Struct.new('Continent', :continent_name, :countries)
|
|
32
31
|
Country = Struct.new('Country', :country_id, :country_name)
|
|
33
32
|
Firm = Struct.new('Firm', :time_zone)
|
|
33
|
+
Album = Struct.new('Album', :id, :title, :genre)
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
def test_collection_options
|
|
@@ -109,19 +109,18 @@ class FormOptionsHelperTest < Test::Unit::TestCase
|
|
|
109
109
|
)
|
|
110
110
|
end
|
|
111
111
|
|
|
112
|
-
# FIXME: fails on Ruby 1.9, probably in html-scanner
|
|
113
112
|
def test_hash_options_for_select
|
|
114
113
|
assert_dom_equal(
|
|
115
114
|
"<option value=\"<Kroner>\"><DKR></option>\n<option value=\"Dollar\">$</option>",
|
|
116
|
-
options_for_select(
|
|
115
|
+
options_for_select("$" => "Dollar", "<DKR>" => "<Kroner>").split("\n").sort.join("\n")
|
|
117
116
|
)
|
|
118
117
|
assert_dom_equal(
|
|
119
118
|
"<option value=\"<Kroner>\"><DKR></option>\n<option value=\"Dollar\" selected=\"selected\">$</option>",
|
|
120
|
-
options_for_select({ "$" => "Dollar", "<DKR>" => "<Kroner>" }, "Dollar")
|
|
119
|
+
options_for_select({ "$" => "Dollar", "<DKR>" => "<Kroner>" }, "Dollar").split("\n").sort.join("\n")
|
|
121
120
|
)
|
|
122
121
|
assert_dom_equal(
|
|
123
122
|
"<option value=\"<Kroner>\" selected=\"selected\"><DKR></option>\n<option value=\"Dollar\" selected=\"selected\">$</option>",
|
|
124
|
-
options_for_select({ "$" => "Dollar", "<DKR>" => "<Kroner>" }, [ "Dollar", "<Kroner>" ])
|
|
123
|
+
options_for_select({ "$" => "Dollar", "<DKR>" => "<Kroner>" }, [ "Dollar", "<Kroner>" ]).split("\n").sort.join("\n")
|
|
125
124
|
)
|
|
126
125
|
end
|
|
127
126
|
|
|
@@ -306,6 +305,18 @@ class FormOptionsHelperTest < Test::Unit::TestCase
|
|
|
306
305
|
select("post", "category", %w( abe <mus> hest ), :selected => 'abe')
|
|
307
306
|
)
|
|
308
307
|
end
|
|
308
|
+
|
|
309
|
+
def test_select_with_index_option
|
|
310
|
+
@album = Album.new
|
|
311
|
+
@album.id = 1
|
|
312
|
+
|
|
313
|
+
expected = "<select id=\"album__genre\" name=\"album[][genre]\"><option value=\"rap\">rap</option>\n<option value=\"rock\">rock</option>\n<option value=\"country\">country</option></select>"
|
|
314
|
+
|
|
315
|
+
assert_dom_equal(
|
|
316
|
+
expected,
|
|
317
|
+
select("album[]", "genre", %w[rap rock country], {}, { :index => nil })
|
|
318
|
+
)
|
|
319
|
+
end
|
|
309
320
|
|
|
310
321
|
def test_select_with_selected_nil
|
|
311
322
|
@post = Post.new
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'abstract_unit'
|
|
2
2
|
|
|
3
|
-
class FormTagHelperTest <
|
|
4
|
-
|
|
5
|
-
include ActionView::Helpers::TagHelper
|
|
6
|
-
include ActionView::Helpers::FormTagHelper
|
|
7
|
-
include ActionView::Helpers::TextHelper
|
|
8
|
-
include ActionView::Helpers::CaptureHelper
|
|
3
|
+
class FormTagHelperTest < ActionView::TestCase
|
|
4
|
+
tests ActionView::Helpers::FormTagHelper
|
|
9
5
|
|
|
10
6
|
def setup
|
|
11
7
|
@controller = Class.new do
|
|
@@ -221,11 +217,18 @@ class FormTagHelperTest < Test::Unit::TestCase
|
|
|
221
217
|
|
|
222
218
|
def test_submit_tag
|
|
223
219
|
assert_dom_equal(
|
|
224
|
-
%(<input name='commit' type='submit' value='Save' onclick="this.setAttribute('originalValue', this.value);this.disabled=true;this.value='Saving...';alert('hello!');result = (this.form.onsubmit ? (this.form.onsubmit() ? this.form.submit() : false) : this.form.submit());if (result == false) { this.value = this.getAttribute('originalValue'); this.disabled = false };return result" />),
|
|
220
|
+
%(<input name='commit' type='submit' value='Save' onclick="this.setAttribute('originalValue', this.value);this.disabled=true;this.value='Saving...';alert('hello!');result = (this.form.onsubmit ? (this.form.onsubmit() ? this.form.submit() : false) : this.form.submit());if (result == false) { this.value = this.getAttribute('originalValue'); this.disabled = false };return result;" />),
|
|
225
221
|
submit_tag("Save", :disable_with => "Saving...", :onclick => "alert('hello!')")
|
|
226
222
|
)
|
|
227
223
|
end
|
|
228
224
|
|
|
225
|
+
def test_submit_tag_with_confirmation
|
|
226
|
+
assert_dom_equal(
|
|
227
|
+
%(<input name='commit' type='submit' value='Save' onclick="return confirm('Are you sure?');"/>),
|
|
228
|
+
submit_tag("Save", :confirm => "Are you sure?")
|
|
229
|
+
)
|
|
230
|
+
end
|
|
231
|
+
|
|
229
232
|
def test_pass
|
|
230
233
|
assert_equal 1, 1
|
|
231
234
|
end
|
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'abstract_unit'
|
|
2
2
|
|
|
3
|
-
class JavaScriptHelperTest <
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
include ActionView::Helpers::UrlHelper
|
|
7
|
-
include ActionView::Helpers::TagHelper
|
|
8
|
-
include ActionView::Helpers::TextHelper
|
|
9
|
-
include ActionView::Helpers::FormHelper
|
|
10
|
-
include ActionView::Helpers::CaptureHelper
|
|
3
|
+
class JavaScriptHelperTest < ActionView::TestCase
|
|
4
|
+
tests ActionView::Helpers::JavaScriptHelper
|
|
11
5
|
|
|
12
6
|
def test_define_javascript_functions
|
|
13
7
|
# check if prototype.js is included first
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'abstract_unit'
|
|
2
2
|
|
|
3
|
-
class NumberHelperTest <
|
|
4
|
-
|
|
3
|
+
class NumberHelperTest < ActionView::TestCase
|
|
4
|
+
tests ActionView::Helpers::NumberHelper
|
|
5
5
|
|
|
6
6
|
def test_number_to_phone
|
|
7
7
|
assert_equal("800-555-1212", number_to_phone(8005551212))
|
|
@@ -25,6 +25,7 @@ class NumberHelperTest < Test::Unit::TestCase
|
|
|
25
25
|
assert_equal("$1,234,567,890.5", number_to_currency(1234567890.50, {:precision => 1}))
|
|
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
|
+
assert_equal("1,234,567,890.50 Kč", number_to_currency("1234567890.50", {:unit => "Kč", :format => "%n %u"}))
|
|
28
29
|
assert_equal("$x.", number_to_currency("x"))
|
|
29
30
|
assert_nil number_to_currency(nil)
|
|
30
31
|
end
|
|
@@ -55,9 +56,11 @@ class NumberHelperTest < Test::Unit::TestCase
|
|
|
55
56
|
|
|
56
57
|
def test_number_with_precision
|
|
57
58
|
assert_equal("111.235", number_with_precision(111.2346))
|
|
59
|
+
assert_equal("31.83", number_with_precision(31.825, 2))
|
|
58
60
|
assert_equal("111.23", number_with_precision(111.2346, 2))
|
|
59
61
|
assert_equal("111.00", number_with_precision(111, 2))
|
|
60
62
|
assert_equal("111.235", number_with_precision("111.2346"))
|
|
63
|
+
assert_equal("31.83", number_with_precision("31.825", 2))
|
|
61
64
|
assert_equal("112", number_with_precision(111.50, 0))
|
|
62
65
|
assert_equal("1234567892", number_with_precision(1234567891.50, 0))
|
|
63
66
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'abstract_unit'
|
|
2
2
|
|
|
3
3
|
Bunny = Struct.new(:Bunny, :id)
|
|
4
4
|
|
|
@@ -24,24 +24,9 @@ end
|
|
|
24
24
|
class Author::Nested < Author; end
|
|
25
25
|
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
base.send :attr_accessor, :template_format
|
|
30
|
-
end
|
|
27
|
+
class PrototypeHelperBaseTest < ActionView::TestCase
|
|
28
|
+
attr_accessor :template_format
|
|
31
29
|
|
|
32
|
-
include ActionView::Helpers::JavaScriptHelper
|
|
33
|
-
include ActionView::Helpers::PrototypeHelper
|
|
34
|
-
include ActionView::Helpers::ScriptaculousHelper
|
|
35
|
-
|
|
36
|
-
include ActionView::Helpers::UrlHelper
|
|
37
|
-
include ActionView::Helpers::TagHelper
|
|
38
|
-
include ActionView::Helpers::TextHelper
|
|
39
|
-
include ActionView::Helpers::FormTagHelper
|
|
40
|
-
include ActionView::Helpers::FormHelper
|
|
41
|
-
include ActionView::Helpers::CaptureHelper
|
|
42
|
-
include ActionView::Helpers::RecordIdentificationHelper
|
|
43
|
-
include ActionController::PolymorphicRoutes
|
|
44
|
-
|
|
45
30
|
def setup
|
|
46
31
|
@template = nil
|
|
47
32
|
@controller = Class.new do
|
|
@@ -59,25 +44,22 @@ module BaseTest
|
|
|
59
44
|
end.new
|
|
60
45
|
end
|
|
61
46
|
|
|
62
|
-
protected
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
end
|
|
47
|
+
protected
|
|
48
|
+
def request_forgery_protection_token
|
|
49
|
+
nil
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def protect_against_forgery?
|
|
53
|
+
false
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def create_generator
|
|
57
|
+
block = Proc.new { |*args| yield *args if block_given? }
|
|
58
|
+
JavaScriptGenerator.new self, &block
|
|
59
|
+
end
|
|
76
60
|
end
|
|
77
61
|
|
|
78
|
-
class PrototypeHelperTest <
|
|
79
|
-
include BaseTest
|
|
80
|
-
|
|
62
|
+
class PrototypeHelperTest < PrototypeHelperBaseTest
|
|
81
63
|
def setup
|
|
82
64
|
@record = @author = Author.new
|
|
83
65
|
@article = Article.new
|
|
@@ -102,6 +84,11 @@ class PrototypeHelperTest < Test::Unit::TestCase
|
|
|
102
84
|
link_to_remote("Remote outauthor", { :url => { :action => "whatnot" }, :html => { :class => "fine" } })
|
|
103
85
|
end
|
|
104
86
|
|
|
87
|
+
def test_link_to_remote_url_quote_escaping
|
|
88
|
+
assert_dom_equal %(<a href="#" onclick="new Ajax.Request('http://www.example.com/whatnot\\\'s', {asynchronous:true, evalScripts:true}); return false;">Remote</a>),
|
|
89
|
+
link_to_remote("Remote", { :url => { :action => "whatnot's" } })
|
|
90
|
+
end
|
|
91
|
+
|
|
105
92
|
def test_periodically_call_remote
|
|
106
93
|
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>),
|
|
107
94
|
periodically_call_remote(:update => "schremser_bier", :url => { :action => "mehr_bier" })
|
|
@@ -230,9 +217,9 @@ class PrototypeHelperTest < Test::Unit::TestCase
|
|
|
230
217
|
end
|
|
231
218
|
|
|
232
219
|
def test_observe_field_using_with_option
|
|
233
|
-
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>)
|
|
220
|
+
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>)
|
|
234
221
|
assert_dom_equal expected, observe_field("glass", :frequency => 5.minutes, :url => { :action => "check_value" }, :with => 'id')
|
|
235
|
-
assert_dom_equal expected, observe_field("glass", :frequency => 5.minutes, :url => { :action => "check_value" }, :with => "'id=' + value")
|
|
222
|
+
assert_dom_equal expected, observe_field("glass", :frequency => 5.minutes, :url => { :action => "check_value" }, :with => "'id=' + encodeURIComponent(value)")
|
|
236
223
|
end
|
|
237
224
|
|
|
238
225
|
def test_observe_field_using_json_in_with_option
|
|
@@ -294,9 +281,7 @@ class PrototypeHelperTest < Test::Unit::TestCase
|
|
|
294
281
|
end
|
|
295
282
|
end
|
|
296
283
|
|
|
297
|
-
class JavaScriptGeneratorTest <
|
|
298
|
-
include BaseTest
|
|
299
|
-
|
|
284
|
+
class JavaScriptGeneratorTest < PrototypeHelperBaseTest
|
|
300
285
|
def setup
|
|
301
286
|
super
|
|
302
287
|
@generator = create_generator
|
|
@@ -358,6 +343,8 @@ class JavaScriptGeneratorTest < Test::Unit::TestCase
|
|
|
358
343
|
def test_redirect_to
|
|
359
344
|
assert_equal 'window.location.href = "http://www.example.com/welcome";',
|
|
360
345
|
@generator.redirect_to(:action => 'welcome')
|
|
346
|
+
assert_equal 'window.location.href = "http://www.example.com/welcome?a=b&c=d";',
|
|
347
|
+
@generator.redirect_to("http://www.example.com/welcome?a=b&c=d")
|
|
361
348
|
end
|
|
362
349
|
|
|
363
350
|
def test_delay
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
require 'abstract_unit'
|
|
2
|
+
|
|
3
|
+
class Post
|
|
4
|
+
def id
|
|
5
|
+
45
|
|
6
|
+
end
|
|
7
|
+
def body
|
|
8
|
+
"What a wonderful world!"
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
class RecordTagHelperTest < ActionView::TestCase
|
|
13
|
+
tests ActionView::Helpers::RecordTagHelper
|
|
14
|
+
|
|
15
|
+
def setup
|
|
16
|
+
@post = Post.new
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test_content_tag_for
|
|
20
|
+
_erbout = ''
|
|
21
|
+
expected = %(<li class="post bar" id="post_45"></li>)
|
|
22
|
+
actual = content_tag_for(:li, @post, :class => 'bar') { }
|
|
23
|
+
assert_dom_equal expected, actual
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_content_tag_for_prefix
|
|
27
|
+
_erbout = ''
|
|
28
|
+
expected = %(<ul class="post" id="archived_post_45"></ul>)
|
|
29
|
+
actual = content_tag_for(:ul, @post, :archived) { }
|
|
30
|
+
assert_dom_equal expected, actual
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_content_tag_for_with_extra_html_tags
|
|
34
|
+
_erbout = ''
|
|
35
|
+
expected = %(<tr class="post bar" id="post_45" style='background-color: #f0f0f0'></tr>)
|
|
36
|
+
actual = content_tag_for(:tr, @post, {:class => "bar", :style => "background-color: #f0f0f0"}) { }
|
|
37
|
+
assert_dom_equal expected, actual
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_block_works_with_content_tag_for
|
|
41
|
+
_erbout = ''
|
|
42
|
+
expected = %(<tr class="post" id="post_45">#{@post.body}</tr>)
|
|
43
|
+
actual = content_tag_for(:tr, @post) { _erbout.concat @post.body }
|
|
44
|
+
assert_dom_equal expected, actual
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def test_div_for
|
|
48
|
+
_erbout = ''
|
|
49
|
+
expected = %(<div class="post bar" id="post_45">#{@post.body}</div>)
|
|
50
|
+
actual = div_for(@post, :class => "bar") { _erbout.concat @post.body }
|
|
51
|
+
assert_dom_equal expected, actual
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
end
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
require
|
|
2
|
-
require
|
|
1
|
+
require 'abstract_unit'
|
|
2
|
+
require 'testing_sandbox'
|
|
3
3
|
|
|
4
4
|
# The exhaustive tests are in test/controller/html/sanitizer_test.rb.
|
|
5
5
|
# This tests the that the helpers hook up correctly to the sanitizer classes.
|
|
6
|
-
class SanitizeHelperTest <
|
|
7
|
-
|
|
8
|
-
include ActionView::Helpers::TagHelper
|
|
6
|
+
class SanitizeHelperTest < ActionView::TestCase
|
|
7
|
+
tests ActionView::Helpers::SanitizeHelper
|
|
9
8
|
include TestingSandbox
|
|
10
9
|
|
|
11
10
|
def test_strip_links
|
|
@@ -46,4 +45,4 @@ class SanitizeHelperTest < Test::Unit::TestCase
|
|
|
46
45
|
def assert_sanitized(text, expected = nil)
|
|
47
46
|
assert_equal((expected || text), sanitize(text))
|
|
48
47
|
end
|
|
49
|
-
end
|
|
48
|
+
end
|
|
@@ -1,16 +1,8 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'abstract_unit'
|
|
2
|
+
|
|
3
|
+
class ScriptaculousHelperTest < ActionView::TestCase
|
|
4
|
+
tests ActionView::Helpers::ScriptaculousHelper
|
|
2
5
|
|
|
3
|
-
class ScriptaculousHelperTest < Test::Unit::TestCase
|
|
4
|
-
include ActionView::Helpers::JavaScriptHelper
|
|
5
|
-
include ActionView::Helpers::PrototypeHelper
|
|
6
|
-
include ActionView::Helpers::ScriptaculousHelper
|
|
7
|
-
|
|
8
|
-
include ActionView::Helpers::UrlHelper
|
|
9
|
-
include ActionView::Helpers::TagHelper
|
|
10
|
-
include ActionView::Helpers::TextHelper
|
|
11
|
-
include ActionView::Helpers::FormHelper
|
|
12
|
-
include ActionView::Helpers::CaptureHelper
|
|
13
|
-
|
|
14
6
|
def setup
|
|
15
7
|
@controller = Class.new do
|
|
16
8
|
def url_for(options)
|
|
@@ -88,8 +80,10 @@ class ScriptaculousHelperTest < Test::Unit::TestCase
|
|
|
88
80
|
drop_receiving_element("droptarget1", :accept => 'products', :update => 'infobox')
|
|
89
81
|
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nDroppables.add(\"droptarget1\", {accept:['tshirts','mugs'], onDrop:function(element){new Ajax.Updater('infobox', 'http://www.example.com/', {asynchronous:true, evalScripts:true, parameters:'id=' + encodeURIComponent(element.id)})}})\n//]]>\n</script>),
|
|
90
82
|
drop_receiving_element("droptarget1", :accept => ['tshirts','mugs'], :update => 'infobox')
|
|
91
|
-
|
|
83
|
+
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nDroppables.add("droptarget1", {hoverclass:'dropready', onDrop:function(element){if (confirm('Are you sure?')) { new Ajax.Request('http://www.example.com/update_drop', {asynchronous:true, evalScripts:true, parameters:'id=' + encodeURIComponent(element.id)}); }}})\n//]]>\n</script>),
|
|
84
|
+
drop_receiving_element('droptarget1', :hoverclass=>'dropready', :url=>{:action=>'update_drop'}, :confirm => 'Are you sure?')
|
|
92
85
|
|
|
86
|
+
end
|
|
93
87
|
def protect_against_forgery?
|
|
94
88
|
false
|
|
95
89
|
end
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'abstract_unit'
|
|
2
2
|
|
|
3
|
-
class TagHelperTest <
|
|
4
|
-
|
|
5
|
-
include ActionView::Helpers::UrlHelper
|
|
6
|
-
include ActionView::Helpers::TextHelper
|
|
7
|
-
include ActionView::Helpers::CaptureHelper
|
|
3
|
+
class TagHelperTest < ActionView::TestCase
|
|
4
|
+
tests ActionView::Helpers::TagHelper
|
|
8
5
|
|
|
9
6
|
def test_tag
|
|
10
7
|
assert_equal "<br />", tag("br")
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
require 'abstract_unit'
|
|
2
|
+
|
|
3
|
+
class TemplateFinderTest < Test::Unit::TestCase
|
|
4
|
+
|
|
5
|
+
LOAD_PATH_ROOT = File.join(File.dirname(__FILE__), '..', 'fixtures')
|
|
6
|
+
|
|
7
|
+
def setup
|
|
8
|
+
ActionView::TemplateFinder.process_view_paths(LOAD_PATH_ROOT)
|
|
9
|
+
ActionView::Template::register_template_handler :mab, Class.new(ActionView::TemplateHandler)
|
|
10
|
+
@template = ActionView::Base.new
|
|
11
|
+
@finder = ActionView::TemplateFinder.new(@template, LOAD_PATH_ROOT)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def test_should_raise_exception_for_unprocessed_view_path
|
|
15
|
+
assert_raises ActionView::TemplateFinder::InvalidViewPath do
|
|
16
|
+
ActionView::TemplateFinder.new(@template, File.dirname(__FILE__))
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_should_cache_file_extension_properly
|
|
21
|
+
assert_equal ["builder", "erb", "rhtml", "rjs", "rxml", "mab"].sort,
|
|
22
|
+
ActionView::TemplateFinder.file_extension_cache[LOAD_PATH_ROOT].values.flatten.uniq.sort
|
|
23
|
+
|
|
24
|
+
assert_equal (Dir.glob("#{LOAD_PATH_ROOT}/**/*/*.{erb,rjs,rhtml,builder,rxml,mab}") |
|
|
25
|
+
Dir.glob("#{LOAD_PATH_ROOT}/**.{erb,rjs,rhtml,builder,rxml,mab}")).size,
|
|
26
|
+
ActionView::TemplateFinder.file_extension_cache[LOAD_PATH_ROOT].keys.size
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def test_should_cache_dir_content_properly
|
|
30
|
+
assert ActionView::TemplateFinder.processed_view_paths[LOAD_PATH_ROOT]
|
|
31
|
+
assert_equal (Dir.glob("#{LOAD_PATH_ROOT}/**/*/**") | Dir.glob("#{LOAD_PATH_ROOT}/**")).find_all {|f| !File.directory?(f) }.size,
|
|
32
|
+
ActionView::TemplateFinder.processed_view_paths[LOAD_PATH_ROOT].size
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def test_find_template_extension_from_first_render
|
|
36
|
+
assert_nil @finder.send(:find_template_extension_from_first_render)
|
|
37
|
+
|
|
38
|
+
{
|
|
39
|
+
nil => nil,
|
|
40
|
+
'' => nil,
|
|
41
|
+
'foo' => nil,
|
|
42
|
+
'/foo' => nil,
|
|
43
|
+
'foo.rb' => 'rb',
|
|
44
|
+
'foo.bar.rb' => 'bar.rb',
|
|
45
|
+
'baz/foo.rb' => 'rb',
|
|
46
|
+
'baz/foo.bar.rb' => 'bar.rb',
|
|
47
|
+
'baz/foo.o/foo.rb' => 'rb',
|
|
48
|
+
'baz/foo.o/foo.bar.rb' => 'bar.rb',
|
|
49
|
+
}.each do |input,expectation|
|
|
50
|
+
@template.instance_variable_set('@first_render', input)
|
|
51
|
+
assert_equal expectation, @finder.send(:find_template_extension_from_first_render)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def test_should_report_file_exists_correctly
|
|
56
|
+
assert_nil @finder.send(:find_template_extension_from_first_render)
|
|
57
|
+
assert_equal false, @finder.send(:file_exists?, 'test.rhtml')
|
|
58
|
+
assert_equal false, @finder.send(:file_exists?, 'test.rb')
|
|
59
|
+
|
|
60
|
+
@template.instance_variable_set('@first_render', 'foo.rb')
|
|
61
|
+
|
|
62
|
+
assert_equal 'rb', @finder.send(:find_template_extension_from_first_render)
|
|
63
|
+
assert_equal false, @finder.send(:file_exists?, 'baz')
|
|
64
|
+
assert_equal false, @finder.send(:file_exists?, 'baz.rb')
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
uses_mocha 'Template finder tests' do
|
|
68
|
+
def test_should_update_extension_cache_when_template_handler_is_registered
|
|
69
|
+
ActionView::TemplateFinder.expects(:update_extension_cache_for).with("funky")
|
|
70
|
+
ActionView::Template::register_template_handler :funky, Class.new(ActionView::TemplateHandler)
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|