Skip to content

Commit

Permalink
memoize host with port and refactor the tests which depend on it chan…
Browse files Browse the repository at this point in the history
…ging

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8164 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
NZKoz committed Nov 17, 2007
1 parent c07eae4 commit 6d0e5ea
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion actionpack/lib/action_controller/request.rb
Expand Up @@ -166,7 +166,7 @@ def host
# Returns a host:port string for this request, such as example.com or # Returns a host:port string for this request, such as example.com or
# example.com:8080. # example.com:8080.
def host_with_port def host_with_port
host + port_string @host_with_port ||= host + port_string
end end


# Returns the port number of this request as an integer. # Returns the port number of this request as an integer.
Expand Down
8 changes: 7 additions & 1 deletion actionpack/test/controller/caching_test.rb
Expand Up @@ -248,16 +248,22 @@ def test_cache_is_scoped_by_subdomain
@request.host = 'jamis.hostname.com' @request.host = 'jamis.hostname.com'
get :index get :index
jamis_cache = content_to_cache jamis_cache = content_to_cache


reset!

@request.host = 'david.hostname.com' @request.host = 'david.hostname.com'
get :index get :index
david_cache = content_to_cache david_cache = content_to_cache
assert_not_equal jamis_cache, @response.body assert_not_equal jamis_cache, @response.body


reset!

@request.host = 'jamis.hostname.com' @request.host = 'jamis.hostname.com'
get :index get :index
assert_equal jamis_cache, @response.body assert_equal jamis_cache, @response.body


reset!

@request.host = 'david.hostname.com' @request.host = 'david.hostname.com'
get :index get :index
assert_equal david_cache, @response.body assert_equal david_cache, @response.body
Expand Down
6 changes: 4 additions & 2 deletions actionpack/test/controller/request_test.rb
Expand Up @@ -252,11 +252,13 @@ def test_request_uri
end end




def test_host_with_port def test_host_with_default_port
@request.host = "rubyonrails.org" @request.host = "rubyonrails.org"
@request.port = 80 @request.port = 80
assert_equal "rubyonrails.org", @request.host_with_port assert_equal "rubyonrails.org", @request.host_with_port

end

def test_host_with_non_default_port
@request.host = "rubyonrails.org" @request.host = "rubyonrails.org"
@request.port = 81 @request.port = 81
assert_equal "rubyonrails.org:81", @request.host_with_port assert_equal "rubyonrails.org:81", @request.host_with_port
Expand Down

0 comments on commit 6d0e5ea

Please sign in to comment.