aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
diff options
context:
space:
mode:
authorAndrew White <andyw@pixeltrix.co.uk>2013-04-18 17:02:21 +0100
committerAndrew White <andyw@pixeltrix.co.uk>2013-04-18 17:12:40 +0100
commit0883f9f508a4d6791428adff12eaf7b882bd2da1 (patch)
tree8eb459c6e4edc42171d40de0b05e35f43c450c1f /actionpack/test
parentc1024409178ccaff8dd6f2cb221e3463423d3fc6 (diff)
downloadrails-0883f9f508a4d6791428adff12eaf7b882bd2da1.tar.gz
rails-0883f9f508a4d6791428adff12eaf7b882bd2da1.tar.bz2
rails-0883f9f508a4d6791428adff12eaf7b882bd2da1.zip
Refactor ActionDispatch::Http::URL.build_host_url
Add support for extracting the port from the :host option and for removing the subdomain by using nil, false or ''.
Diffstat (limited to 'actionpack/test')
-rw-r--r--actionpack/test/dispatch/url_generation_test.rb41
1 files changed, 41 insertions, 0 deletions
diff --git a/actionpack/test/dispatch/url_generation_test.rb b/actionpack/test/dispatch/url_generation_test.rb
index 4123529092..f919592d24 100644
--- a/actionpack/test/dispatch/url_generation_test.rb
+++ b/actionpack/test/dispatch/url_generation_test.rb
@@ -56,6 +56,47 @@ module TestUrlGeneration
test "formatting host when protocol is present" do
assert_equal "http://www.example.com/foo", foo_url(host: "httpz://www.example.com", protocol: "http://")
end
+
+ test "default ports are removed from the host" do
+ assert_equal "http://www.example.com/foo", foo_url(host: "www.example.com:80", protocol: "http://")
+ assert_equal "https://www.example.com/foo", foo_url(host: "www.example.com:443", protocol: "https://")
+ end
+
+ test "port is extracted from the host" do
+ assert_equal "http://www.example.com:8080/foo", foo_url(host: "www.example.com:8080", protocol: "http://")
+ end
+
+ test "port option overides the host" do
+ assert_equal "http://www.example.com:8080/foo", foo_url(host: "www.example.com:8443", protocol: "http://", port: 8080)
+ end
+
+ test "port option disables the host when set to nil" do
+ assert_equal "http://www.example.com/foo", foo_url(host: "www.example.com:8443", protocol: "http://", port: nil)
+ end
+
+ test "port option disables the host when set to false" do
+ assert_equal "http://www.example.com/foo", foo_url(host: "www.example.com:8443", protocol: "http://", port: false)
+ end
+
+ test "keep subdomain when key is true" do
+ assert_equal "http://www.example.com/foo", foo_url(subdomain: true)
+ end
+
+ test "keep subdomain when key is missing" do
+ assert_equal "http://www.example.com/foo", foo_url
+ end
+
+ test "omit subdomain when key is nil" do
+ assert_equal "http://example.com/foo", foo_url(subdomain: nil)
+ end
+
+ test "omit subdomain when key is false" do
+ assert_equal "http://example.com/foo", foo_url(subdomain: false)
+ end
+
+ test "omit subdomain when key is blank" do
+ assert_equal "http://example.com/foo", foo_url(subdomain: "")
+ end
end
end