aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/dispatch/request_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/test/dispatch/request_test.rb')
-rw-r--r--actionpack/test/dispatch/request_test.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/actionpack/test/dispatch/request_test.rb b/actionpack/test/dispatch/request_test.rb
index 8f672c1149..75b674ec1a 100644
--- a/actionpack/test/dispatch/request_test.rb
+++ b/actionpack/test/dispatch/request_test.rb
@@ -1,6 +1,31 @@
require 'abstract_unit'
class RequestTest < ActiveSupport::TestCase
+
+ def url_for(options = {})
+ options.reverse_merge!(:host => 'www.example.com')
+ ActionDispatch::Http::URL.url_for(options)
+ end
+
+ test "url_for class method" do
+ e = assert_raise(ArgumentError) { url_for(:host => nil) }
+ assert_match(/Please provide the :host parameter/, e.message)
+
+ assert_equal '/books', url_for(:only_path => true, :path => '/books')
+
+ assert_equal 'http://www.example.com', url_for
+ assert_equal 'http://api.example.com', url_for(:subdomain => 'api')
+ assert_equal 'http://www.ror.com', url_for(:domain => 'ror.com')
+ assert_equal 'http://api.ror.co.uk', url_for(:host => 'www.ror.co.uk', :subdomain => 'api', :tld_length => 2)
+ assert_equal 'http://www.example.com:8080', url_for(:port => 8080)
+ assert_equal 'https://www.example.com', url_for(:protocol => 'https')
+ assert_equal 'http://www.example.com/docs', url_for(:path => '/docs')
+ assert_equal 'http://www.example.com#signup', url_for(:anchor => 'signup')
+ assert_equal 'http://www.example.com/', url_for(:trailing_slash => true)
+ assert_equal 'http://dhh:supersecret@www.example.com', url_for(:user => 'dhh', :password => 'supersecret')
+ assert_equal 'http://www.example.com?search=books', url_for(:params => { :search => 'books' })
+ end
+
test "remote ip" do
request = stub_request 'REMOTE_ADDR' => '1.2.3.4'
assert_equal '1.2.3.4', request.remote_ip