Skip to content
This repository
Browse code

Fix trouble using :subdomain in development environment when using nu…

…meric addresses.

Otherwise the following occurs:

TypeError: can't convert nil into String
    /Users/bfolkens/dev/bfolkens-rails-core/actionpack/lib/action_dispatch/http/url.rb:75:in host_or_subdomain_and_domain'
    /Users/bfolkens/dev/bfolkens-rails-core/actionpack/lib/action_dispatch/http/url.rb:37:in url_for'
    /Users/bfolkens/dev/bfolkens-rails-core/actionpack/lib/action_dispatch/routing/url_for.rb:147:in test_subdomain_may_be_accepted_with_numeric_host'
    /Users/bfolkens/dev/bfolkens-rails-core/activesupport/lib/active_support/testing/setup_and_teardown.rb:67:in run'
    /Users/bfolkens/dev/bfolkens-rails-core/activesupport/lib/active_support/callbacks.rb:426:in send'
    /Users/bfolkens/dev/bfolkens-rails-core/activesupport/lib/active_support/callbacks.rb:81:in run'
  • Loading branch information...
commit 92955d00531394e1bfa0aad7614371d326002097 1 parent 12df79c
Brad Folkens authored November 07, 2011
2  actionpack/lib/action_dispatch/http/url.rb
@@ -64,7 +64,7 @@ def rewrite_authentication(options)
64 64
         end
65 65
 
66 66
         def host_or_subdomain_and_domain(options)
67  
-          return options[:host] unless options[:subdomain] || options[:domain]
  67
+          return options[:host] unless (options[:subdomain] || options[:domain]) and named_host?(options[:host])
68 68
 
69 69
           tld_length = options[:tld_length] || @@tld_length
70 70
 
11  actionpack/test/controller/url_for_test.rb
@@ -16,6 +16,10 @@ def add_host!
16 16
         W.default_url_options[:host] = 'www.basecamphq.com'
17 17
       end
18 18
 
  19
+      def add_numeric_host!
  20
+        W.default_url_options[:host] = '127.0.0.1'
  21
+      end
  22
+
19 23
       def test_exception_is_thrown_without_host
20 24
         assert_raise ArgumentError do
21 25
           W.new.url_for :controller => 'c', :action => 'a', :id => 'i'
@@ -67,6 +71,13 @@ def test_subdomain_may_be_changed
67 71
         )
68 72
       end
69 73
 
  74
+      def test_subdomain_may_be_accepted_with_numeric_host
  75
+        add_numeric_host!
  76
+        assert_equal('http://127.0.0.1/c/a/i',
  77
+          W.new.url_for(:subdomain => 'api', :controller => 'c', :action => 'a', :id => 'i')
  78
+        )
  79
+      end
  80
+
70 81
       def test_domain_may_be_changed
71 82
         add_host!
72 83
         assert_equal('http://www.37signals.com/c/a/i',

0 notes on commit 92955d0

Please sign in to comment.
Something went wrong with that request. Please try again.