Permalink
Browse files

Fix tests for the request refactor

  • Loading branch information...
1 parent c92d598 commit eb49bd694997954783632eada901553f041c9507 Carl Lerche committed Mar 3, 2010
@@ -51,6 +51,7 @@ def setup
@request = ActionController::TestRequest.new
@request.host = 'hostname.com'
+ @request.env.delete('PATH_INFO')
@response = ActionController::TestResponse.new
@controller = PageCachingTestController.new
@@ -110,7 +111,7 @@ def test_should_cache_with_trailing_slash_on_url
end
def test_should_cache_ok_at_custom_path
- @request.request_uri = "/index.html"
+ @request.env['PATH_INFO'] = '/index.html'
get :ok
assert_response :ok
assert File.exist?("#{FILE_STORE_PATH}/index.html")
@@ -128,6 +128,7 @@ def setup
@controller = TestController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
+ @request.env['PATH_INFO'] = nil
end
def test_raw_post_handling
@@ -199,7 +200,7 @@ def test_process_with_request_uri_with_params
end
def test_process_with_request_uri_with_params_with_explicit_uri
- @request.request_uri = "/explicit/uri"
+ @request.env['PATH_INFO'] = "/explicit/uri"
process :test_uri, :id => 7
assert_equal "/explicit/uri", @response.body
end
@@ -210,7 +211,8 @@ def test_process_with_query_string
end
def test_process_with_query_string_with_explicit_uri
- @request.request_uri = "/explicit/uri?q=test?extra=question"
+ @request.env['PATH_INFO'] = '/explicit/uri'
+ @request.env['QUERY_STRING'] = 'q=test?extra=question'
process :test_query_string
assert_equal "q=test?extra=question", @response.body
end
@@ -1,9 +1,8 @@
# encoding: utf-8
require 'abstract_unit'
+require 'active_support/ordered_options'
require 'controller/fake_controllers'
-RequestMock = Struct.new("Request", :request_uri, :protocol, :host_with_port, :env)
-
class UrlHelperTest < ActionView::TestCase
include ActiveSupport::Configurable
DEFAULT_CONFIG = ActionView::DEFAULT_CONFIG
@@ -15,8 +14,13 @@ def setup
def url_for(options)
url
end
+ def config
+ ActiveSupport::InheritableOptions.new({})
+ end
end
+
@controller = @controller.new
+ @request = @controller.request = ActionDispatch::TestRequest.new
@controller.url = "http://www.example.com"
end
@@ -38,12 +42,13 @@ def test_url_for_escapes_url_once
end
def test_url_for_with_back
- @controller.request = RequestMock.new("http://www.example.com/weblog/show", nil, nil, {'HTTP_REFERER' => 'http://www.example.com/referer'})
+ @request.env['HTTP_REFERER'] = 'http://www.example.com/referer'
assert_equal 'http://www.example.com/referer', url_for(:back)
end
def test_url_for_with_back_and_no_referer
- @controller.request = RequestMock.new("http://www.example.com/weblog/show", nil, nil, {})
+ @request.env['HOST_NAME'] = 'www.example.com'
+ @request.env['PATH_INFO'] = '/weblog/show'
assert_equal 'javascript:history.back()', url_for(:back)
end
@@ -144,22 +149,28 @@ def test_link_tag_with_query_and_no_name
end
def test_link_tag_with_back
- @controller.request = RequestMock.new("http://www.example.com/weblog/show", nil, nil, {'HTTP_REFERER' => 'http://www.example.com/referer'})
+ @request.env['HOST_NAME'] = 'www.example.com'
+ @request.env['PATH_INFO'] = '/weblog/show'
+ @request.env['HTTP_REFERER'] = 'http://www.example.com/referer'
assert_dom_equal "<a href=\"http://www.example.com/referer\">go back</a>", link_to('go back', :back)
end
def test_link_tag_with_back_and_no_referer
- @controller.request = RequestMock.new("http://www.example.com/weblog/show", nil, nil, {})
+ @request.env['HOST_NAME'] = 'www.example.com'
+ @request.env['PATH_INFO'] = '/weblog/show'
assert_dom_equal "<a href=\"javascript:history.back()\">go back</a>", link_to('go back', :back)
end
def test_link_tag_with_back
- @controller.request = RequestMock.new("http://www.example.com/weblog/show", nil, nil, {'HTTP_REFERER' => 'http://www.example.com/referer'})
+ @request.env['HOST_NAME'] = 'www.example.com'
+ @request.env['PATH_INFO'] = '/weblog/show'
+ @request.env['HTTP_REFERER'] = 'http://www.example.com/referer'
assert_dom_equal "<a href=\"http://www.example.com/referer\">go back</a>", link_to('go back', :back)
end
def test_link_tag_with_back_and_no_referer
- @controller.request = RequestMock.new("http://www.example.com/weblog/show", nil, nil, {})
+ @request.env['HOST_NAME'] = 'www.example.com'
+ @request.env['PATH_INFO'] = '/weblog/show'
assert_dom_equal "<a href=\"javascript:history.back()\">go back</a>", link_to('go back', :back)
end
@@ -263,55 +274,60 @@ def test_link_to_if
end
def test_current_page_with_simple_url
- @controller.request = RequestMock.new("http://www.example.com/weblog/show")
+ @request.env['HTTP_HOST'] = 'www.example.com'
+ @request.env['PATH_INFO'] = '/weblog/show'
@controller.url = "http://www.example.com/weblog/show"
assert current_page?({ :action => "show", :controller => "weblog" })
assert current_page?("http://www.example.com/weblog/show")
end
def test_current_page_ignoring_params
- @controller.request = RequestMock.new("http://www.example.com/weblog/show?order=desc&page=1")
+ @request.env['HTTP_HOST'] = 'www.example.com'
+ @request.env['PATH_INFO'] = '/weblog/show'
+ @request.env['QUERY_STRING'] = 'order=desc&page=1'
@controller.url = "http://www.example.com/weblog/show?order=desc&page=1"
assert current_page?({ :action => "show", :controller => "weblog" })
assert current_page?("http://www.example.com/weblog/show")
end
def test_current_page_with_params_that_match
- @controller.request = RequestMock.new("http://www.example.com/weblog/show?order=desc&page=1")
+ @request.env['HTTP_HOST'] = 'www.example.com'
+ @request.env['PATH_INFO'] = '/weblog/show'
+ @request.env['QUERY_STRING'] = 'order=desc&page=1'
@controller.url = "http://www.example.com/weblog/show?order=desc&page=1"
assert current_page?({ :action => "show", :controller => "weblog", :order => "desc", :page => "1" })
assert current_page?("http://www.example.com/weblog/show?order=desc&amp;page=1")
end
def test_link_unless_current
- @controller.request = RequestMock.new("http://www.example.com/weblog/show")
+ @request.env['HTTP_HOST'] = 'www.example.com'
+ @request.env['PATH_INFO'] = '/weblog/show'
@controller.url = "http://www.example.com/weblog/show"
assert_equal "Showing", link_to_unless_current("Showing", { :action => "show", :controller => "weblog" })
assert_equal "Showing", link_to_unless_current("Showing", "http://www.example.com/weblog/show")
- @controller.request = RequestMock.new("http://www.example.com/weblog/show?order=desc")
+ @request.env['QUERY_STRING'] = 'order=desc'
@controller.url = "http://www.example.com/weblog/show"
assert_equal "Showing", link_to_unless_current("Showing", { :action => "show", :controller => "weblog" })
assert_equal "Showing", link_to_unless_current("Showing", "http://www.example.com/weblog/show")
- @controller.request = RequestMock.new("http://www.example.com/weblog/show?order=desc&page=1")
+ @request.env['QUERY_STRING'] = 'order=desc&page=1'
@controller.url = "http://www.example.com/weblog/show?order=desc&page=1"
assert_equal "Showing", link_to_unless_current("Showing", { :action => "show", :controller => "weblog", :order=>'desc', :page=>'1' })
assert_equal "Showing", link_to_unless_current("Showing", "http://www.example.com/weblog/show?order=desc&page=1")
assert_equal "Showing", link_to_unless_current("Showing", "http://www.example.com/weblog/show?order=desc&page=1")
- @controller.request = RequestMock.new("http://www.example.com/weblog/show?order=desc")
+ @request.env['QUERY_STRING'] = 'order=desc'
@controller.url = "http://www.example.com/weblog/show?order=asc"
assert_equal "<a href=\"http://www.example.com/weblog/show?order=asc\">Showing</a>", link_to_unless_current("Showing", { :action => "show", :controller => "weblog" })
assert_equal "<a href=\"http://www.example.com/weblog/show?order=asc\">Showing</a>", link_to_unless_current("Showing", "http://www.example.com/weblog/show?order=asc")
- @controller.request = RequestMock.new("http://www.example.com/weblog/show?order=desc&page=1")
+ @request.env['QUERY_STRING'] = 'order=desc&page=1'
@controller.url = "http://www.example.com/weblog/show?order=desc&page=2"
assert_equal "<a href=\"http://www.example.com/weblog/show?order=desc&page=2\">Showing</a>", link_to_unless_current("Showing", { :action => "show", :controller => "weblog" })
assert_equal "<a href=\"http://www.example.com/weblog/show?order=desc&amp;page=2\">Showing</a>", link_to_unless_current("Showing", "http://www.example.com/weblog/show?order=desc&page=2")
-
- @controller.request = RequestMock.new("http://www.example.com/weblog/show")
+ @request.env['QUERY_STRING'] = ''
@controller.url = "http://www.example.com/weblog/list"
assert_equal "<a href=\"http://www.example.com/weblog/list\">Listing</a>",
link_to_unless_current("Listing", :action => "list", :controller => "weblog")

0 comments on commit eb49bd6

Please sign in to comment.