From c1505e3e2b1a4f0d6d9c29731cac1dc096c13d2e Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 15 Sep 2005 05:24:29 +0000 Subject: Included UrlRewriter tests in rake run and made them not depend on Hash order git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2244 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/test/controller/url_rewriter_test.rb | 46 ++++++++++++++++++++++++ actionpack/test/controller/url_rewriter_tests.rb | 37 ------------------- 2 files changed, 46 insertions(+), 37 deletions(-) create mode 100644 actionpack/test/controller/url_rewriter_test.rb delete mode 100644 actionpack/test/controller/url_rewriter_tests.rb (limited to 'actionpack') diff --git a/actionpack/test/controller/url_rewriter_test.rb b/actionpack/test/controller/url_rewriter_test.rb new file mode 100644 index 0000000000..1219abdd9f --- /dev/null +++ b/actionpack/test/controller/url_rewriter_test.rb @@ -0,0 +1,46 @@ +require File.dirname(__FILE__) + '/../abstract_unit' + +class UrlRewriterTests < Test::Unit::TestCase + def setup + @request = ActionController::TestRequest.new + @params = {} + @rewriter = ActionController::UrlRewriter.new(@request, @params) + end + + def test_simple_build_query_string + assert_query_equal '?x=1&y=2', @rewriter.send(:build_query_string, :x => '1', :y => '2') + end + def test_convert_ints_build_query_string + assert_query_equal '?x=1&y=2', @rewriter.send(:build_query_string, :x => 1, :y => 2) + end + def test_escape_spaces_build_query_string + assert_query_equal '?x=hello+world&y=goodbye+world', @rewriter.send(:build_query_string, :x => 'hello world', :y => 'goodbye world') + end + def test_expand_array_build_query_string + assert_query_equal '?x[]=1&x[]=2', @rewriter.send(:build_query_string, :x => [1, 2]) + end + + def test_escape_spaces_build_query_string_selected_keys + assert_query_equal '?x=hello+world', @rewriter.send(:build_query_string, {:x => 'hello world', :y => 'goodbye world'}, [:x]) + end + + def test_overwrite_params + @params[:controller] = 'hi' + @params[:action] = 'bye' + @params[:id] = '2' + + assert_equal '/hi/hi/2', @rewriter.rewrite(:only_path => true, :overwrite_params => {:action => 'hi'}) + u = @rewriter.rewrite(:only_path => false, :overwrite_params => {:action => 'hi'}) + assert_match %r(/hi/hi/2$), u + end + + + private + def split_query_string(str) + [str[0].chr] + str[1..-1].split(/&/).sort + end + + def assert_query_equal(q1, q2) + assert_equal(split_query_string(q1), split_query_string(q2)) + end +end diff --git a/actionpack/test/controller/url_rewriter_tests.rb b/actionpack/test/controller/url_rewriter_tests.rb deleted file mode 100644 index af26c2dcf5..0000000000 --- a/actionpack/test/controller/url_rewriter_tests.rb +++ /dev/null @@ -1,37 +0,0 @@ -require File.dirname(__FILE__) + '/../abstract_unit' - -class UrlRewriterTests < Test::Unit::TestCase - def setup - @request = ActionController::TestRequest.new - @params = {} - @rewriter = ActionController::UrlRewriter.new(@request, @params) - end - - def test_simple_build_query_string - assert_equal '?x=1&y=2', @rewriter.send(:build_query_string, :x => '1', :y => '2') - end - def test_convert_ints_build_query_string - assert_equal '?x=1&y=2', @rewriter.send(:build_query_string, :x => 1, :y => 2) - end - def test_escape_spaces_build_query_string - assert_equal '?x=hello+world&y=goodbye+world', @rewriter.send(:build_query_string, :x => 'hello world', :y => 'goodbye world') - end - def test_expand_array_build_query_string - assert_equal '?x[]=1&x[]=2', @rewriter.send(:build_query_string, :x => [1, 2]) - end - - def test_escape_spaces_build_query_string_selected_keys - assert_equal '?x=hello+world', @rewriter.send(:build_query_string, {:x => 'hello world', :y => 'goodbye world'}, [:x]) - end - - def test_overwrite_params - @params[:controller] = 'hi' - @params[:action] = 'bye' - @params[:id] = '2' - - assert_equal '/hi/hi/2', @rewriter.rewrite(:only_path => true, :overwrite_params => {:action => 'hi'}) - u = @rewriter.rewrite(:only_path => false, :overwrite_params => {:action => 'hi'}) - assert_match %r(/hi/hi/2$), u - end - -end -- cgit v1.2.3