Permalink
Browse files

Added simulation of @request.request_uri in functional tests #1038 [J…

…amis Buck]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1103 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
dhh committed Apr 7, 2005
1 parent bd9a81c commit 4ab40059b7925f35cddb0f76dba27ea6cd018de7
View
@@ -1,5 +1,7 @@
*SVN*
+* Added simulation of @request.request_uri in functional tests #1038 [Jamis Buck]
+
* Fixed autolinking to work better in more cases #1013 [Jamis Buck]
* Added the possible of using symbols in form helpers that relate to instance variables like text_field :account, :name in addition to text_field "account", "name"'
@@ -258,6 +258,7 @@ def process(action, parameters = nil, session = nil, flash = nil)
@request.parameters.update(parameters) unless parameters.nil?
@request.session = ActionController::TestSession.new(session) unless session.nil?
@request.session["flash"] = ActionController::Flash::FlashHash.new.update(flash) if flash
+ build_request_uri(action, parameters)
@controller.process(@request, @response)
end
@@ -282,6 +283,14 @@ def follow_redirect
def assigns(name)
@response.template.assigns[name.to_s]
end
+
+ def build_request_uri(action, parameters)
+ return if @request.env['REQUEST_URI']
+ url = ActionController::UrlRewriter.new(@request, parameters)
+ @request.set_REQUEST_URI(
+ url.rewrite(@controller.send(:rewrite_options,
+ (parameters||{}).update(:only_path => true, :action=>action))))
+ end
end
end
end
@@ -5,12 +5,21 @@ class TestController < ActionController::Base
def set_flash
flash["test"] = ">#{flash["test"]}<"
end
+
+ def test_uri
+ render_text @request.request_uri
+ end
end
def setup
@controller = TestController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
+ ActionController::Routing::Routes.reload
+ end
+
+ def teardown
+ ActionController::Routing::Routes.reload
end
def test_process_without_flash
@@ -22,4 +31,20 @@ def test_process_with_flash
process :set_flash, nil, nil, { "test" => "value" }
assert_flash_equal ">value<", "test"
end
+
+ def test_process_with_request_uri_with_no_params
+ process :test_uri
+ assert_equal @response.body, "/test_test/test/test_uri"
+ end
+
+ def test_process_with_request_uri_with_params
+ process :test_uri, :id => 7
+ assert_equal @response.body, "/test_test/test/test_uri/7"
+ end
+
+ def test_process_with_request_uri_with_params_with_explicit_uri
+ @request.set_REQUEST_URI "/explicit/uri"
+ process :test_uri, :id => 7
+ assert_equal @response.body, "/explicit/uri"
+ end
end

0 comments on commit 4ab4005

Please sign in to comment.