From 824da60ae86ac26b5cbc7d6354d233205d2addc6 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sun, 27 Jun 2010 18:53:06 -0300 Subject: Move Rails module to abstract_unit to make test in isolation work MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- actionpack/test/abstract_unit.rb | 3 +++ actionpack/test/controller/base_test.rb | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index 2640e96453..3241b3d118 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -38,6 +38,9 @@ end require 'pp' # require 'pp' early to prevent hidden_methods from not picking up the pretty-print methods until too late +module Rails +end + ActiveSupport::Dependencies.hook! # Show backtraces for deprecated behavior for quicker cleanup. diff --git a/actionpack/test/controller/base_test.rb b/actionpack/test/controller/base_test.rb index 4f58b5d968..ae270b751e 100644 --- a/actionpack/test/controller/base_test.rb +++ b/actionpack/test/controller/base_test.rb @@ -2,9 +2,6 @@ require 'abstract_unit' require 'logger' require 'pp' # require 'pp' early to prevent hidden_methods from not picking up the pretty-print methods until too late -module Rails -end - # Provide some controller to run the tests on. module Submodule class ContainedEmptyController < ActionController::Base -- cgit v1.2.3 From f3bb185b03e746b52a4035a6df002597d8552e74 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 27 Jun 2010 17:53:52 -0700 Subject: Upgrade to Rack 1.2.1 --- .../request/multipart_params_parsing_test.rb | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/request/multipart_params_parsing_test.rb b/actionpack/test/dispatch/request/multipart_params_parsing_test.rb index 40c5ac2d09..e3ec5cf182 100644 --- a/actionpack/test/dispatch/request/multipart_params_parsing_test.rb +++ b/actionpack/test/dispatch/request/multipart_params_parsing_test.rb @@ -89,15 +89,21 @@ class MultipartParamsParsingTest < ActionController::IntegrationTest assert_equal 19512, file.size end + # Pending fix in Rack 1.2.2 + # http://rack.lighthouseapp.com/projects/22435-rack/tickets/79-multipart-handling-incorrectly-assuming-file-upload test "parses mixed files" do - params = parse_multipart('mixed_files') - assert_equal %w(files foo), params.keys.sort - assert_equal 'bar', params['foo'] - - # Rack doesn't handle multipart/mixed for us. - files = params['files'] - files.force_encoding('ASCII-8BIT') if files.respond_to?(:force_encoding) - assert_equal 19756, files.size + if Rack.release <= '1.2.1' + $stderr.puts 'multipart/mixed parsing pending fix in Rack 1.2.2' + else + params = parse_multipart('mixed_files') + assert_equal %w(files foo), params.keys.sort + assert_equal 'bar', params['foo'] + + # Rack doesn't handle multipart/mixed for us. + files = params['files'] + files.force_encoding('ASCII-8BIT') if files.respond_to?(:force_encoding) + assert_equal 19756, files.size + end end test "does not create tempfile if no file has been selected" do -- cgit v1.2.3 From 25215d7285db10e2c04d903f251b791342e4dd6a Mon Sep 17 00:00:00 2001 From: wycats Date: Sun, 27 Jun 2010 21:12:10 -0700 Subject: Fix several known web encoding issues: * Specify accept-charset on all forms. All recent browsers, as well as IE5+, will use the encoding specified for form parameters * Unfortunately, IE5+ will not look at accept-charset unless at least one character in the form's values is not in the page's charset. Since the user can override the default charset (which Rails sets to UTF-8), we provide a hidden input containing a unicode character, forcing IE to look at the accept-charset. * Now that the vast majority of web input is UTF-8, we set the inbound parameters to UTF-8. This will eliminate many cases of incompatible encodings between ASCII-8BIT and UTF-8. * You can safely ignore params[:_snowman_] TODO: * Validate inbound text to confirm it is UTF-8 * Combine the whole_form implementations in form_helper_test and form_tag_helper_test --- .../request/url_encoded_params_parsing_test.rb | 23 ++ actionpack/test/template/erb/form_for_test.rb | 2 +- actionpack/test/template/erb/tag_helper_test.rb | 4 +- actionpack/test/template/form_helper_test.rb | 385 +++++++++++---------- actionpack/test/template/form_tag_helper_test.rb | 56 ++- 5 files changed, 276 insertions(+), 194 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb b/actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb index 69dbd7f528..0bcef81534 100644 --- a/actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb +++ b/actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb @@ -141,6 +141,29 @@ class UrlEncodedParamsParsingTest < ActionController::IntegrationTest post "/parse", actual assert_response :ok assert_equal(expected, TestController.last_request_parameters) + assert_utf8(TestController.last_request_parameters) + end + end + + def assert_utf8(object) + return unless "ruby".encoding_aware? + + correct_encoding = Encoding.default_internal + + unless object.is_a?(Hash) + assert_equal correct_encoding, object.encoding, "#{object.inspect} should have been UTF-8" + return + end + + object.each do |k,v| + case v + when Hash + assert_utf8(v) + when Array + v.each {|el| assert_utf8(el) } + else + assert_utf8(v) + end end end end diff --git a/actionpack/test/template/erb/form_for_test.rb b/actionpack/test/template/erb/form_for_test.rb index ec6e872735..e722b40a9a 100644 --- a/actionpack/test/template/erb/form_for_test.rb +++ b/actionpack/test/template/erb/form_for_test.rb @@ -5,7 +5,7 @@ module ERBTest class TagHelperTest < BlockTestCase test "form_for works" do output = render_content "form_for(:staticpage, :url => {:controller => 'blah', :action => 'update'})", "" - assert_equal "
", output + assert_match %r{.*}, output end end end diff --git a/actionpack/test/template/erb/tag_helper_test.rb b/actionpack/test/template/erb/tag_helper_test.rb index 64a88bde1d..d073100986 100644 --- a/actionpack/test/template/erb/tag_helper_test.rb +++ b/actionpack/test/template/erb/tag_helper_test.rb @@ -28,8 +28,8 @@ module ERBTest end test "percent equals works with form tags" do - expected_output = "
hello
" - maybe_deprecated { assert_equal expected_output, render_content("form_tag('foo')", "<%= 'hello' %>") } + expected_output = %r{.*hello*} + maybe_deprecated { assert_match expected_output, render_content("form_tag('foo')", "<%= 'hello' %>") } end test "percent equals works with fieldset tags" do diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index 6ba407e230..eb6cf92805 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -583,7 +583,8 @@ class FormHelperTest < ActionView::TestCase end expected = - "
" + + "" + + snowman + "" + "" + "" + @@ -604,15 +605,14 @@ class FormHelperTest < ActionView::TestCase concat f.submit('Create post') end - expected = - "" + - "
" + + expected = whole_form("/posts/123", "create-post", "other_name_edit", :method => "put") do "" + "" + "" + "" + "" + - "
" + "" + end assert_dom_equal expected, output_buffer end @@ -626,14 +626,12 @@ class FormHelperTest < ActionView::TestCase end end - expected = - "
" + - "
" + + expected = whole_form("http://www.example.com", "create-post", nil, "put") do "" + "" + "" + - "" + - "
" + "" + end assert_dom_equal expected, output_buffer end @@ -647,14 +645,12 @@ class FormHelperTest < ActionView::TestCase end end - expected = - "
" + - "
" + + expected = whole_form("http://www.example.com", "create-post", nil, :method => "put", :remote => true) do "" + "" + "" + - "" + - "
" + "" + end assert_dom_equal expected, output_buffer end @@ -668,13 +664,12 @@ class FormHelperTest < ActionView::TestCase end end - expected = - "
" + + expected = whole_form("http://www.example.com", nil, nil, :remote => true) do "" + "" + "" + - "" + - "
" + "" + end assert_dom_equal expected, output_buffer end @@ -686,13 +681,12 @@ class FormHelperTest < ActionView::TestCase concat f.check_box(:secret) end - expected = - "
" + + expected = whole_form("http://www.example.com", "create-post") do "" + "" + "" + - "" + - "
" + "" + end assert_dom_equal expected, output_buffer end @@ -707,14 +701,13 @@ class FormHelperTest < ActionView::TestCase end end - expected = - "
" + + expected = whole_form do "" + "" + "" + "" + - "" + - "
" + "" + end assert_dom_equal expected, output_buffer end @@ -728,13 +721,12 @@ class FormHelperTest < ActionView::TestCase end end - expected = - "
" + + expected = whole_form do "" + "" + "" + - "" + - "
" + "" + end assert_dom_equal expected, output_buffer end @@ -749,9 +741,10 @@ class FormHelperTest < ActionView::TestCase end end - expected = "
" + - "" + - "
" + expected = whole_form do + "" + end + assert_dom_equal expected, output_buffer ensure I18n.locale = old_locale @@ -766,9 +759,10 @@ class FormHelperTest < ActionView::TestCase end end - expected = "
" + - "" + - "
" + expected = whole_form do + "" + end + assert_dom_equal expected, output_buffer ensure I18n.locale = old_locale @@ -781,9 +775,10 @@ class FormHelperTest < ActionView::TestCase concat f.submit :class => "extra" end - expected = "
" + - "" + - "
" + expected = whole_form do + "" + end + assert_dom_equal expected, output_buffer ensure I18n.locale = old_locale @@ -798,9 +793,10 @@ class FormHelperTest < ActionView::TestCase end end - expected = "
" + - "" + - "
" + expected = whole_form do + "" + end + assert_dom_equal expected, output_buffer ensure I18n.locale = old_locale @@ -815,9 +811,9 @@ class FormHelperTest < ActionView::TestCase end end - expected = "
" + - "" + - "
" + expected = whole_form do + "" + end assert_dom_equal expected, output_buffer end @@ -832,10 +828,10 @@ class FormHelperTest < ActionView::TestCase end end - expected = "
" + - "" + - "" + - "
" + expected = whole_form do + "" + + "" + end assert_dom_equal expected, output_buffer end @@ -850,10 +846,10 @@ class FormHelperTest < ActionView::TestCase end end - expected = "
" + - "" + - "" + - "
" + expected = whole_form do + "" + + "" + end assert_dom_equal expected, output_buffer end @@ -867,9 +863,9 @@ class FormHelperTest < ActionView::TestCase end end - expected = "
" + - "" + - "
" + expected = whole_form do + "" + end assert_dom_equal expected, output_buffer end @@ -883,9 +879,9 @@ class FormHelperTest < ActionView::TestCase end end - expected = "
" + - "" + - "
" + expected = whole_form do + "" + end assert_dom_equal expected, output_buffer end @@ -899,9 +895,9 @@ class FormHelperTest < ActionView::TestCase end end - expected = "
" + - "" + - "
" + expected = whole_form do + "" + end assert_dom_equal expected, output_buffer end @@ -915,9 +911,9 @@ class FormHelperTest < ActionView::TestCase end end - expected = "
" + - "" + - "
" + expected = whole_form do + "" + end assert_dom_equal expected, output_buffer end @@ -931,9 +927,9 @@ class FormHelperTest < ActionView::TestCase end end - expected = "
" + - "" + - "
" + expected = whole_form do + "" + end assert_dom_equal expected, output_buffer end @@ -952,12 +948,11 @@ class FormHelperTest < ActionView::TestCase } end - expected = "
" + - "" + - "
" + - "
" + - "" + - "
" + expected = whole_form do + "" + end + whole_form do + "" + end assert_dom_equal expected, output_buffer end @@ -975,10 +970,10 @@ class FormHelperTest < ActionView::TestCase end end - expected = '
' + - '' + - '' + - '
' + expected = whole_form do + '' + + '' + end assert_dom_equal expected, output_buffer end @@ -1006,11 +1001,11 @@ class FormHelperTest < ActionView::TestCase end end - expected = '
' + - '' + - '' + - '' + - '
' + expected = whole_form do + '' + + '' + + '' + end assert_dom_equal expected, output_buffer end @@ -1028,11 +1023,11 @@ class FormHelperTest < ActionView::TestCase end end - expected = '
' + - '' + - '' + - '' + - '
' + expected = whole_form do + '' + + '' + + '' + end assert_dom_equal expected, output_buffer end @@ -1051,13 +1046,13 @@ class FormHelperTest < ActionView::TestCase end end - expected = '
' + - '' + - '' + - '' + - '' + - '' + - '
' + expected = whole_form do + '' + + '' + + '' + + '' + + '' + end assert_dom_equal expected, output_buffer end @@ -1077,13 +1072,13 @@ class FormHelperTest < ActionView::TestCase end end - expected = '
' + - '' + - '' + - '' + - '' + - '' + - '
' + expected = whole_form do + '' + + '' + + '' + + '' + + '' + end assert_dom_equal expected, output_buffer end @@ -1102,11 +1097,11 @@ class FormHelperTest < ActionView::TestCase end end - expected = '
' + - '' + - '' + - '' + - '
' + expected = whole_form do + '' + + '' + + '' + end assert_dom_equal expected, output_buffer end @@ -1125,12 +1120,12 @@ class FormHelperTest < ActionView::TestCase end end - expected = '
' + - '' + - '' + - '' + - '' + - '
' + expected = whole_form do + '' + + '' + + '' + + '' + end assert_dom_equal expected, output_buffer end @@ -1145,9 +1140,9 @@ class FormHelperTest < ActionView::TestCase end end - expected = '
' + - '' + - '
' + expected = whole_form do + '' + end assert_dom_equal expected, output_buffer end @@ -1164,13 +1159,13 @@ class FormHelperTest < ActionView::TestCase end end - expected = '
' + - '' + - '' + - '' + - '' + - '' + - '
' + expected = whole_form do + '' + + '' + + '' + + '' + + '' + end assert_dom_equal expected, output_buffer end @@ -1188,13 +1183,13 @@ class FormHelperTest < ActionView::TestCase end end - expected = '
' + - '' + - '' + - '' + - '' + - '' + - '
' + expected = whole_form do + '' + + '' + + '' + + '' + + '' + end assert_dom_equal expected, output_buffer end @@ -1213,12 +1208,12 @@ class FormHelperTest < ActionView::TestCase end end - expected = '
' + - '' + - '' + - '' + - '' + - '
' + expected = whole_form do + '' + + '' + + '' + + '' + end assert_dom_equal expected, output_buffer assert_equal yielded_comments, @post.comments @@ -1235,10 +1230,10 @@ class FormHelperTest < ActionView::TestCase end end - expected = '
' + - '' + - '' + - '
' + expected = whole_form do + '' + + '' + end assert_dom_equal expected, output_buffer end @@ -1273,20 +1268,20 @@ class FormHelperTest < ActionView::TestCase end end - expected = '
' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '
' + expected = whole_form do + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + end assert_dom_equal expected, output_buffer end @@ -1426,7 +1421,8 @@ class FormHelperTest < ActionView::TestCase end expected = - "
" + + "" + + snowman + "" + "" + "" + @@ -1449,11 +1445,11 @@ class FormHelperTest < ActionView::TestCase end expected = - "" + - "" + - "" + - "" + - "
" + whole_form("http://www.example.com", "create-post") do + "" + + "" + + "" + end assert_dom_equal expected, output_buffer end @@ -1477,16 +1473,42 @@ class FormHelperTest < ActionView::TestCase end end - expected = - "
" + - "
" + - "
" + - "
" + - "
" + expected = whole_form do + "
" + + "
" + + "
" + end assert_dom_equal expected, output_buffer end + def snowman(method = nil) + txt = %{
} + txt << %{} + txt << %{} if method + txt << %{
} + end + + def form_text(action = "http://www.example.com", id = nil, html_class = nil, remote = nil) + txt = %{
} + end + + def whole_form(action = "http://www.example.com", id = nil, html_class = nil, options = nil) + contents = block_given? ? yield : "" + + if options.is_a?(Hash) + method, remote = options.values_at(:method, :remote) + else + method = options + end + + form_text(action, id, html_class, remote) + snowman(method) + contents + "
" + end + def test_default_form_builder old_default_form_builder, ActionView::Base.default_form_builder = ActionView::Base.default_form_builder, LabelledFormBuilder @@ -1499,12 +1521,11 @@ class FormHelperTest < ActionView::TestCase end end - expected = - "
" + + expected = whole_form do "
" + "
" + - "
" + - "
" + "
" + end assert_dom_equal expected, output_buffer ensure @@ -1577,7 +1598,7 @@ class FormHelperTest < ActionView::TestCase assert_deprecated do form_for(:post, @post, :html => {:id => 'some_form', :class => 'some_class'}) do |f| end end - expected = "
" + expected = whole_form("http://www.example.com", "some_form", "some_class") assert_dom_equal expected, output_buffer end @@ -1587,7 +1608,8 @@ class FormHelperTest < ActionView::TestCase form_for(:post, @post, :url => 'http://www.otherdomain.com') do |f| end end - assert_equal '
', output_buffer + assert_equal whole_form("http://www.otherdomain.com"), output_buffer + # assert_equal '
', output_buffer end def test_form_for_with_hash_url_option @@ -1604,14 +1626,15 @@ class FormHelperTest < ActionView::TestCase form_for(:post, @post, :url => @post) do |f| end end - expected = "
" + expected = whole_form("/posts/123") + # expected = "
" assert_equal expected, output_buffer end def test_form_for_with_existing_object form_for(@post) do |f| end - expected = "
" + expected = whole_form("/posts/123", "edit_post_123", "edit_post", "put") assert_equal expected, output_buffer end @@ -1622,7 +1645,7 @@ class FormHelperTest < ActionView::TestCase form_for(post) do |f| end - expected = "
" + expected = whole_form("/posts", "new_post", "new_post") assert_equal expected, output_buffer end @@ -1630,14 +1653,14 @@ class FormHelperTest < ActionView::TestCase @comment.save form_for([@post, @comment]) {} - expected = %(
) + expected = whole_form(comment_path(@post, @comment), "edit_comment_1", "edit_comment", "put") assert_dom_equal expected, output_buffer end def test_form_for_with_new_object_in_list form_for([@post, @comment]) {} - expected = %(
) + expected = whole_form(comments_path(@post), "new_comment", "new_comment") assert_dom_equal expected, output_buffer end @@ -1645,21 +1668,21 @@ class FormHelperTest < ActionView::TestCase @comment.save form_for([:admin, @post, @comment]) {} - expected = %(
) + expected = whole_form(admin_comment_path(@post, @comment), "edit_comment_1", "edit_comment", "put") assert_dom_equal expected, output_buffer end def test_form_for_with_new_object_and_namespace_in_list form_for([:admin, @post, @comment]) {} - expected = %(
) + expected = whole_form(admin_comments_path(@post), "new_comment", "new_comment") assert_dom_equal expected, output_buffer end def test_form_for_with_existing_object_and_custom_url form_for(@post, :url => "/super_posts") do |f| end - expected = "
" + expected = whole_form("/super_posts", "edit_post_123", "edit_post", "put") assert_equal expected, output_buffer end diff --git a/actionpack/test/template/form_tag_helper_test.rb b/actionpack/test/template/form_tag_helper_test.rb index b75863bb6a..75d2773c0a 100644 --- a/actionpack/test/template/form_tag_helper_test.rb +++ b/actionpack/test/template/form_tag_helper_test.rb @@ -8,6 +8,36 @@ class FormTagHelperTest < ActionView::TestCase @controller = BasicController.new end + def snowman(options = {}) + method = options[:method] + + txt = %{
} + txt << %{} + txt << %{} if method + txt << %{
} + end + + def form_text(action = "http://www.example.com", options = {}) + remote, enctype, html_class, id = options.values_at(:remote, :enctype, :html_class, :id) + + txt = %{
} + end + + def whole_form(action = "http://www.example.com", options = {}) + out = form_text(action, options) + snowman(options) + + if block_given? + out << yield << "
" + end + + out + end + def url_for(options) if options.is_a?(Hash) "http://www.example.com" @@ -31,51 +61,57 @@ class FormTagHelperTest < ActionView::TestCase def test_form_tag actual = form_tag - expected = %(
) + expected = whole_form assert_dom_equal expected, actual end def test_form_tag_multipart actual = form_tag({}, { 'multipart' => true }) - expected = %() + expected = whole_form("http://www.example.com", :enctype => true) assert_dom_equal expected, actual end def test_form_tag_with_method_put actual = form_tag({}, { :method => :put }) - expected = %(
) + expected = whole_form("http://www.example.com", :method => :put) assert_dom_equal expected, actual end def test_form_tag_with_method_delete actual = form_tag({}, { :method => :delete }) - expected = %(
) + + expected = whole_form("http://www.example.com", :method => :delete) assert_dom_equal expected, actual end def test_form_tag_with_remote actual = form_tag({}, :remote => true) - expected = %() + + expected = whole_form("http://www.example.com", :remote => true) assert_dom_equal expected, actual end def test_form_tag_with_remote_false actual = form_tag({}, :remote => false) - expected = %() + + expected = whole_form assert_dom_equal expected, actual end def test_form_tag_with_block_in_erb - output_buffer = form_tag("http://example.com") { concat "Hello world!" } + output_buffer = form_tag("http://www.example.com") { concat "Hello world!" } - expected = %(Hello world!
) + expected = whole_form { "Hello world!" } assert_dom_equal expected, output_buffer end def test_form_tag_with_block_and_method_in_erb - output_buffer = form_tag("http://example.com", :method => :put) { concat "Hello world!" } + output_buffer = form_tag("http://www.example.com", :method => :put) { concat "Hello world!" } + + expected = whole_form("http://www.example.com", :method => "put") do + "Hello world!" + end - expected = %(
Hello world!
) assert_dom_equal expected, output_buffer end -- cgit v1.2.3 From 2002e5877efa40b336b70b707670e734c6389958 Mon Sep 17 00:00:00 2001 From: Bruno Michel Date: Sat, 26 Jun 2010 19:00:57 +0200 Subject: Strip_tags never ending attribute should not raise a TypeError [#4870 state:resolved] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- actionpack/test/template/html-scanner/sanitizer_test.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/template/html-scanner/sanitizer_test.rb b/actionpack/test/template/html-scanner/sanitizer_test.rb index a6e760b0b6..c9edde8892 100644 --- a/actionpack/test/template/html-scanner/sanitizer_test.rb +++ b/actionpack/test/template/html-scanner/sanitizer_test.rb @@ -257,6 +257,10 @@ class SanitizerTest < ActionController::TestCase assert_sanitized %{my link} end + def test_should_sanitize_neverending_attribute + assert_sanitized "" + end + protected def assert_sanitized(input, expected = nil) @sanitizer ||= HTML::WhiteListSanitizer.new -- cgit v1.2.3 From 6d04fa6dc4865af1112c4d35a456a81008815ee7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 28 Jun 2010 12:23:41 +0200 Subject: Deprecate the old router DSL. Since it is still used intensively across ActionPack test suite, patches that translates Rails internal tests to the new router DSL are welcome (note though that a few tests shouldn't be translated since they are testing exactly the old mapper API, like the ones in actionpack/test/controller/resource_test.rb and actionpack/test/controller/routing_test.rb) --- actionpack/test/abstract_unit.rb | 8 ++++++ .../test/activerecord/polymorphic_routes_test.rb | 30 +++++++++++----------- 2 files changed, 23 insertions(+), 15 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index 3241b3d118..c8477fb83f 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -41,6 +41,14 @@ require 'pp' # require 'pp' early to prevent hidden_methods from not picking up module Rails end +# Monkey patch the old router initialization to be silenced. +class ActionDispatch::Routing::DeprecatedMapper + def initialize_with_silencer(*args) + ActiveSupport::Deprecation.silence { initialize_without_silencer(*args) } + end + alias_method_chain :initialize, :silencer +end + ActiveSupport::Dependencies.hook! # Show backtraces for deprecated behavior for quicker cleanup. diff --git a/actionpack/test/activerecord/polymorphic_routes_test.rb b/actionpack/test/activerecord/polymorphic_routes_test.rb index 6e1e6cdd20..90a1ef982c 100644 --- a/actionpack/test/activerecord/polymorphic_routes_test.rb +++ b/actionpack/test/activerecord/polymorphic_routes_test.rb @@ -408,18 +408,18 @@ class PolymorphicRoutesTest < ActionController::TestCase def with_admin_test_routes(options = {}) with_routing do |set| - set.draw do |map| - map.namespace :admin do |admin| - admin.resources :projects do |projects| - projects.resources :tasks - projects.resource :bid do |bid| - bid.resources :tasks + set.draw do + namespace :admin do + resources :projects do + resources :tasks + resource :bid do + resources :tasks end end - admin.resources :taxes do |taxes| - taxes.resources :faxes + resources :taxes do + resources :faxes end - admin.resources :series + resources :series end end @@ -430,12 +430,12 @@ class PolymorphicRoutesTest < ActionController::TestCase def with_admin_and_site_test_routes(options = {}) with_routing do |set| - set.draw do |map| - map.namespace :admin do |admin| - admin.resources :projects do |projects| - projects.namespace :site do |site| - site.resources :tasks do |tasks| - tasks.resources :steps + set.draw do + namespace :admin do + resources :projects do + namespace :site do + resources :tasks do + resources :steps end end end -- cgit v1.2.3 From 19ccd4628c1ab4aebc00dc8d480d6cbf1688a312 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Mon, 28 Jun 2010 00:53:36 +0100 Subject: Remove invalid conditions from route [#4989 state:resolved] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- actionpack/test/dispatch/routing_test.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index cf92b039e3..0548456b63 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -330,6 +330,10 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest resources :content + scope :constraints => { :id => /\d+/ } do + get '/tickets', :to => 'tickets#index', :as => :tickets + end + match '/:locale/*file.:format', :to => 'files#show', :file => /path\/to\/existing\/file/ end end @@ -1546,6 +1550,14 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end + def test_router_removes_invalid_conditions + with_test_routes do + get '/tickets' + assert_equal 'tickets#index', @response.body + assert_equal '/tickets', tickets_path + end + end + private def with_test_routes yield -- cgit v1.2.3 From e717631a8481935e8ac1eeb2445da341bdd4c868 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Mon, 28 Jun 2010 12:04:13 +0100 Subject: Merge :constraints from scope into resource options [#2694 state:resolved] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- actionpack/test/dispatch/routing_test.rb | 43 ++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 0548456b63..b5653a391a 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -334,6 +334,13 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get '/tickets', :to => 'tickets#index', :as => :tickets end + scope :constraints => { :id => /\d{4}/ } do + resources :movies do + resources :reviews + resource :trailer + end + end + match '/:locale/*file.:format', :to => 'files#show', :file => /path\/to\/existing\/file/ end end @@ -1558,6 +1565,42 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end + def test_constraints_are_merged_from_scope + with_test_routes do + get '/movies/0001' + assert_equal 'movies#show', @response.body + assert_equal '/movies/0001', movie_path(:id => '0001') + + get '/movies/00001' + assert_equal 'Not Found', @response.body + assert_raises(ActionController::RoutingError){ movie_path(:id => '00001') } + + get '/movies/0001/reviews' + assert_equal 'reviews#index', @response.body + assert_equal '/movies/0001/reviews', movie_reviews_path(:movie_id => '0001') + + get '/movies/00001/reviews' + assert_equal 'Not Found', @response.body + assert_raises(ActionController::RoutingError){ movie_reviews_path(:movie_id => '00001') } + + get '/movies/0001/reviews/0001' + assert_equal 'reviews#show', @response.body + assert_equal '/movies/0001/reviews/0001', movie_review_path(:movie_id => '0001', :id => '0001') + + get '/movies/00001/reviews/0001' + assert_equal 'Not Found', @response.body + assert_raises(ActionController::RoutingError){ movie_path(:movie_id => '00001', :id => '00001') } + + get '/movies/0001/trailer' + assert_equal 'trailers#show', @response.body + assert_equal '/movies/0001/trailer', movie_trailer_path(:movie_id => '0001') + + get '/movies/00001/trailer' + assert_equal 'Not Found', @response.body + assert_raises(ActionController::RoutingError){ movie_trailer_path(:movie_id => '00001') } + end + end + private def with_test_routes yield -- cgit v1.2.3 From 0b6ce3422370647cad3e91263a291f69b313d65b Mon Sep 17 00:00:00 2001 From: Andrew White Date: Sun, 27 Jun 2010 09:16:46 +0100 Subject: Restores the escaping of urls generated from hashes. [#4765 state:resolved] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit HTML specifications recommend the escaping of urls in web pages, which url_for does by default for string urls and consquently urls generated by path helpers as these return strings. Hashes passed to url_for are not escaped by default and this commit reverses this default so that they are escaped. Undoes the changes of this commit: http://github.com/rails/rails/commit/1b3195b63ca44f0a70b61b75fcf4991cb2fbb944 Signed-off-by: José Valim --- actionpack/test/template/url_helper_test.rb | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb index 72d4897630..897228677b 100644 --- a/actionpack/test/template/url_helper_test.rb +++ b/actionpack/test/template/url_helper_test.rb @@ -41,7 +41,7 @@ class UrlHelperTest < ActiveSupport::TestCase alias url_hash hash_for def test_url_for_escapes_urls - assert_equal "/?a=b&c=d", url_for(abcd) + assert_equal "/?a=b&c=d", url_for(abcd) assert_equal "/?a=b&c=d", url_for(abcd(:escape => true)) assert_equal "/?a=b&c=d", url_for(abcd(:escape => false)) end @@ -53,6 +53,7 @@ class UrlHelperTest < ActiveSupport::TestCase def test_url_for_escapes_url_once assert_equal "/?a=b&c=d", url_for("/?a=b&c=d") + assert_equal "/?a=b&c=d", url_for(abcd) end def test_url_for_with_back @@ -67,11 +68,6 @@ class UrlHelperTest < ActiveSupport::TestCase assert_equal 'javascript:history.back()', url_for(:back) end - def test_url_for_from_hash_doesnt_escape_ampersand - path = url_for(hash_for(:foo => :bar, :baz => :quux)) - assert_equal '/?baz=quux&foo=bar', sort_query_string_params(path) - end - # todo: missing test cases def test_button_to_with_straight_url assert_dom_equal "
", button_to("Hello", "http://www.example.com") @@ -345,7 +341,7 @@ class UrlHelperTest < ActiveSupport::TestCase link_to_unless_current("Showing", "http://www.example.com/?order=asc") @request = request_for_url("/?order=desc") - assert_equal %{Showing}, + assert_equal %{Showing}, link_to_unless_current("Showing", hash_for(:order => "desc", :page => 2)) assert_equal %{Showing}, link_to_unless_current("Showing", "http://www.example.com/?order=desc&page=2") @@ -415,7 +411,7 @@ class UrlHelperTest < ActiveSupport::TestCase private def sort_query_string_params(uri) path, qs = uri.split('?') - qs = qs.split('&').sort.join('&') if qs + qs = qs.split('&').sort.join('&') if qs qs ? "#{path}?#{qs}" : path end end -- cgit v1.2.3 From caab17611668ff18a3c8642b2d45b353be5d9691 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 29 Jun 2010 18:02:39 +0200 Subject: Rename _snowman_ to _snowman to be in sync with _method and _csrf_token. --- actionpack/test/template/form_helper_test.rb | 2 +- actionpack/test/template/form_tag_helper_test.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index eb6cf92805..4b9e41803f 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -1484,7 +1484,7 @@ class FormHelperTest < ActionView::TestCase def snowman(method = nil) txt = %{
} - txt << %{} + txt << %{} txt << %{} if method txt << %{
} end diff --git a/actionpack/test/template/form_tag_helper_test.rb b/actionpack/test/template/form_tag_helper_test.rb index 75d2773c0a..8a0f352bc0 100644 --- a/actionpack/test/template/form_tag_helper_test.rb +++ b/actionpack/test/template/form_tag_helper_test.rb @@ -12,7 +12,7 @@ class FormTagHelperTest < ActionView::TestCase method = options[:method] txt = %{
} - txt << %{} + txt << %{} txt << %{} if method txt << %{
} end -- cgit v1.2.3 From cba1460a2fe2bbe1153620582a66e03cec9ba7a5 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Tue, 29 Jun 2010 19:55:57 +0200 Subject: url_for no longer escapes HTML, the :escape option is also gone Rationale: url_for is just a path/URL generator, it is the responsability of the caller to escape conveniently HTML needs it, JavaScript needs different escaping, a text mail needs no escaping at all, etc. --- actionpack/test/template/url_helper_test.rb | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb index 897228677b..035f501f03 100644 --- a/actionpack/test/template/url_helper_test.rb +++ b/actionpack/test/template/url_helper_test.rb @@ -40,20 +40,8 @@ class UrlHelperTest < ActiveSupport::TestCase end alias url_hash hash_for - def test_url_for_escapes_urls - assert_equal "/?a=b&c=d", url_for(abcd) - assert_equal "/?a=b&c=d", url_for(abcd(:escape => true)) - assert_equal "/?a=b&c=d", url_for(abcd(:escape => false)) - end - - def test_url_for_escaping_is_safety_aware - assert url_for(abcd(:escape => true)).html_safe?, "escaped urls should be html_safe?" - assert !url_for(abcd(:escape => false)).html_safe?, "non-escaped urls should not be html_safe?" - end - - def test_url_for_escapes_url_once - assert_equal "/?a=b&c=d", url_for("/?a=b&c=d") - assert_equal "/?a=b&c=d", url_for(abcd) + def test_url_for_does_not_escape_urls + assert_equal "/?a=b&c=d", url_for(abcd) end def test_url_for_with_back @@ -151,7 +139,7 @@ class UrlHelperTest < ActiveSupport::TestCase end def test_link_tag_with_query_and_no_name - link = link_to(nil, "http://www.example.com?q1=v1&q2=v2") + link = link_to(nil, "http://www.example.com?q1=v1&q2=v2") expected = %{http://www.example.com?q1=v1&q2=v2} assert_dom_equal expected, link end @@ -308,7 +296,7 @@ class UrlHelperTest < ActiveSupport::TestCase @request = request_for_url("/?order=desc&page=1") assert current_page?(hash_for(:order => "desc", :page => "1")) - assert current_page?("http://www.example.com/?order=desc&page=1") + assert current_page?("http://www.example.com/?order=desc&page=1") end def test_link_unless_current -- cgit v1.2.3 From ec3bfa2ead7337fe99ff036d4b8b5ae0a321f8cd Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Wed, 30 Jun 2010 00:12:48 +0200 Subject: s/escape_once/html_escape/, since html safety is the contract that now says whether something has to be escaped --- actionpack/test/template/tag_helper_test.rb | 4 ++-- actionpack/test/template/url_helper_test.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/tag_helper_test.rb b/actionpack/test/template/tag_helper_test.rb index ec5fe3d1d7..507cdca8d0 100644 --- a/actionpack/test/template/tag_helper_test.rb +++ b/actionpack/test/template/tag_helper_test.rb @@ -95,9 +95,9 @@ class TagHelperTest < ActionView::TestCase assert_equal '1 < 2 & 3', escape_once('1 < 2 & 3') end - def test_double_escaping_attributes + def test_tag_honors_html_safe_for_param_values ['1&2', '1 < 2', '“test“'].each do |escaped| - assert_equal %(), tag('a', :href => escaped) + assert_equal %(), tag('a', :href => escaped.html_safe) end end diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb index 035f501f03..befb55fb48 100644 --- a/actionpack/test/template/url_helper_test.rb +++ b/actionpack/test/template/url_helper_test.rb @@ -65,8 +65,8 @@ class UrlHelperTest < ActiveSupport::TestCase assert_dom_equal "
", button_to("Hello", "http://www.example.com/q1=v1&q2=v2") end - def test_button_to_with_escaped_query - assert_dom_equal "
", button_to("Hello", "http://www.example.com/q1=v1&q2=v2") + def test_button_to_with_html_safe_URL + assert_dom_equal "
", button_to("Hello", "http://www.example.com/q1=v1&q2=v2".html_safe) end def test_button_to_with_query_and_no_name -- cgit v1.2.3 From 7bd00fcb7f8e7f94811387cd809480a727b61f11 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Tue, 29 Jun 2010 21:41:27 -0300 Subject: We are trying to test that & escapes here not that & is being escaped, also added a cosmetic change to test_link_tag_with_query_and_no_name Signed-off-by: Jeremy Kemper --- actionpack/test/template/url_helper_test.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb index befb55fb48..765beebfa3 100644 --- a/actionpack/test/template/url_helper_test.rb +++ b/actionpack/test/template/url_helper_test.rb @@ -135,13 +135,12 @@ class UrlHelperTest < ActiveSupport::TestCase def test_link_tag_with_query expected = %{
Hello} - assert_dom_equal expected, link_to("Hello", "http://www.example.com?q1=v1&q2=v2") + assert_dom_equal expected, link_to("Hello", "http://www.example.com?q1=v1&q2=v2") end def test_link_tag_with_query_and_no_name - link = link_to(nil, "http://www.example.com?q1=v1&q2=v2") expected = %{http://www.example.com?q1=v1&q2=v2} - assert_dom_equal expected, link + assert_dom_equal expected, link_to(nil, "http://www.example.com?q1=v1&q2=v2") end def test_link_tag_with_back -- cgit v1.2.3 From 06681af518036dcc84f4565b59a0dee460b01108 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 30 Jun 2010 12:34:15 +0200 Subject: A couple enhancements to the router: * Allow to use the get :symbol shortcut outside resources scopes as well; * Fix a bug where :action was not being picked from given options; * Giving :as option inside a resource now changes just the relative name instead of the full name; --- actionpack/test/dispatch/routing_test.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index b5653a391a..26bd641cd6 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -35,6 +35,13 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end + scope "bookmark", :controller => "bookmarks", :as => :bookmark do + get :new, :path => "build" + post :create, :path => "create", :as => "" + put :update + get "remove", :action => :destroy, :as => :remove + end + match 'account/logout' => redirect("/logout"), :as => :logout_redirect match 'account/login', :to => redirect("/login") @@ -545,6 +552,26 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end + def test_bookmarks + with_test_routes do + get '/bookmark/build' + assert_equal 'bookmarks#new', @response.body + assert_equal '/bookmark/build', new_bookmark_path + + post '/bookmark/create' + assert_equal 'bookmarks#create', @response.body + assert_equal '/bookmark/create', bookmark_path + + put '/bookmark' + assert_equal 'bookmarks#update', @response.body + assert_equal '/bookmark', update_bookmark_path + + get '/bookmark/remove' + assert_equal 'bookmarks#destroy', @response.body + assert_equal '/bookmark/remove', bookmark_remove_path + end + end + def test_admin with_test_routes do get '/admin', {}, {'REMOTE_ADDR' => '192.168.1.100'} -- cgit v1.2.3