1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actionpack/test/controller/url_rewriter_tests.rb
Nicholas Seckar 3108764367 Fix overwrite params. Closes #1909
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2144 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2005-09-06 22:06:11 +00:00

37 lines
1.3 KiB
Ruby

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