Permalink
Browse files

Add original_fullpath and original_url methods to Request

  • Loading branch information...
1 parent 4d872d1 commit c2af40b679223a0226068a824aa03227f8c09a28 @drogus drogus committed Dec 20, 2011
Showing with 32 additions and 0 deletions.
  1. +8 −0 actionpack/lib/action_dispatch/http/request.rb
  2. +24 −0 actionpack/test/dispatch/request_test.rb
@@ -130,10 +130,18 @@ def headers
Http::Headers.new(@env)
end
+ def original_fullpath
+ @original_fullpath ||= (env["ORIGINAL_FULLPATH"] || fullpath)
+ end
+
def fullpath
@fullpath ||= super
end
+ def original_url
+ base_url + original_fullpath
+ end
+
def forgery_whitelisted?
get?
end
@@ -606,6 +606,30 @@ def url_for(options = {})
assert_equal "/authenticate?secret", path
end
+ test "original_fullpath returns ORIGINAL_FULLPATH" do
+ request = stub_request('ORIGINAL_FULLPATH' => "/foo?bar")
+
+ path = request.original_fullpath
+ assert_equal "/foo?bar", path
+ end
+
+ test "original_url returns url built using ORIGINAL_FULLPATH" do
+ request = stub_request('ORIGINAL_FULLPATH' => "/foo?bar",
+ 'HTTP_HOST' => "example.org",
+ 'rack.url_scheme' => "http")
+
+ url = request.original_url
+ assert_equal "http://example.org/foo?bar", url
+ end
+
+ test "original_fullpath returns fullpath if ORIGINAL_FULLPATH is not present" do
+ request = stub_request('PATH_INFO' => "/foo",
+ 'QUERY_STRING' => "bar")
+
+ path = request.original_fullpath
+ assert_equal "/foo?bar", path
+ end
+
protected
def stub_request(env = {})

0 comments on commit c2af40b

Please sign in to comment.