aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2009-04-04 17:31:11 +0100
committerPratik Naik <pratiknaik@gmail.com>2009-04-04 17:31:11 +0100
commitc55507e8ceca44558179a705118740540d7871b4 (patch)
tree59937226af81d49ce094e1282b90f0047ef15a36
parent4fe6d43cabe3bb2e094f308d010209c78005a3b9 (diff)
parent0e9efae4745e232b1c778fda69ee110e42a223a7 (diff)
downloadrails-c55507e8ceca44558179a705118740540d7871b4.tar.gz
rails-c55507e8ceca44558179a705118740540d7871b4.tar.bz2
rails-c55507e8ceca44558179a705118740540d7871b4.zip
Merge commit 'mainstream/master'
-rw-r--r--actionpack/lib/action_controller/test_process.rb2
-rw-r--r--actionpack/lib/action_view/paths.rb2
-rw-r--r--actionpack/lib/action_view/template.rb55
-rw-r--r--actionpack/test/controller/request_test.rb448
-rw-r--r--actionpack/test/controller/session/cookie_store_test.rb21
-rw-r--r--actionpack/test/controller/test_test.rb12
-rw-r--r--actionpack/test/fixtures/test/backup_files/item.html.erb1
-rw-r--r--actionpack/test/fixtures/test/backup_files/item.html.erb.orig1
-rw-r--r--actionpack/test/template/render_test.rb6
-rw-r--r--actionpack/test/template/template_test.rb34
-rw-r--r--activesupport/CHANGELOG5
-rw-r--r--activesupport/lib/active_support/cache/strategy/local_cache.rb5
-rw-r--r--activesupport/lib/active_support/core_ext/time/calculations.rb14
-rw-r--r--activesupport/test/core_ext/duration_test.rb12
-rw-r--r--activesupport/test/core_ext/time_ext_test.rb73
-rw-r--r--railties/builtin/rails_info/rails/info.rb11
-rw-r--r--railties/html/index.html7
17 files changed, 395 insertions, 314 deletions
diff --git a/actionpack/lib/action_controller/test_process.rb b/actionpack/lib/action_controller/test_process.rb
index 9dd09c30b4..b2d1341573 100644
--- a/actionpack/lib/action_controller/test_process.rb
+++ b/actionpack/lib/action_controller/test_process.rb
@@ -13,6 +13,7 @@ module ActionController #:nodoc:
@query_parameters = {}
@session = TestSession.new
+ @session_options ||= {}
initialize_default_values
initialize_containers
@@ -110,6 +111,7 @@ module ActionController #:nodoc:
end
def recycle!
+ @env["action_controller.request.request_parameters"] = {}
self.query_parameters = {}
self.path_parameters = {}
@headers, @request_method, @accepts, @content_type = nil, nil, nil, nil
diff --git a/actionpack/lib/action_view/paths.rb b/actionpack/lib/action_view/paths.rb
index 8cc3fe291c..a0a2f96886 100644
--- a/actionpack/lib/action_view/paths.rb
+++ b/actionpack/lib/action_view/paths.rb
@@ -61,7 +61,7 @@ module ActionView #:nodoc:
end
end
- return Template.new(original_template_path, original_template_path.to_s =~ /\A\// ? "" : ".") if File.file?(original_template_path)
+ return Template.new(original_template_path) if File.file?(original_template_path)
raise MissingTemplate.new(self, original_template_path, format)
end
diff --git a/actionpack/lib/action_view/template.rb b/actionpack/lib/action_view/template.rb
index c339c8a554..a974f2652b 100644
--- a/actionpack/lib/action_view/template.rb
+++ b/actionpack/lib/action_view/template.rb
@@ -107,9 +107,8 @@ module ActionView #:nodoc:
attr_accessor :locale, :name, :format, :extension
delegate :to_s, :to => :path
- def initialize(template_path, load_path)
- @template_path = template_path.dup
- @load_path, @filename = load_path, File.join(load_path, template_path)
+ def initialize(template_path, load_path = nil)
+ @template_path, @load_path = template_path.dup, load_path
@base_path, @name, @locale, @format, @extension = split(template_path)
@base_path.to_s.gsub!(/\/$/, '') # Push to split method
@@ -180,6 +179,12 @@ module ActionView #:nodoc:
@@exempt_from_layout.any? { |exempted| path =~ exempted }
end
+ def filename
+ # no load_path means this is an "absolute pathed" template
+ load_path ? File.join(load_path, template_path) : template_path
+ end
+ memoize :filename
+
def source
File.read(filename)
end
@@ -212,46 +217,30 @@ module ActionView #:nodoc:
end
def valid_locale?(locale)
- I18n.available_locales.include?(locale.to_sym)
+ locale && I18n.available_locales.include?(locale.to_sym)
end
# Returns file split into an array
# [base_path, name, locale, format, extension]
def split(file)
if m = file.to_s.match(/^(.*\/)?([^\.]+)\.(.*)$/)
- base_path = m[1]
- name = m[2]
- extensions = m[3]
- else
- return
+ [m[1], m[2], *parse_extensions(m[3])]
end
+ end
- locale = nil
- format = nil
- extension = nil
-
- if m = extensions.split(".")
- if valid_locale?(m[0]) && m[1] && valid_extension?(m[2]) # All three
- locale = m[0]
- format = m[1]
- extension = m[2]
- elsif m[0] && m[1] && valid_extension?(m[2]) # Multipart formats
- format = "#{m[0]}.#{m[1]}"
- extension = m[2]
- elsif valid_locale?(m[0]) && valid_extension?(m[1]) # locale and extension
- locale = m[0]
- extension = m[1]
- elsif valid_extension?(m[1]) # format and extension
- format = m[0]
- extension = m[1]
- elsif valid_extension?(m[0]) # Just extension
- extension = m[0]
- else # No extension
- format = m[0]
- end
+ # returns parsed extensions as an array
+ # [locale, format, extension]
+ def parse_extensions(extensions)
+ exts = extensions.split(".")
+
+ if extension = valid_extension?(exts.last) && exts.pop || nil
+ locale = valid_locale?(exts.first) && exts.shift || nil
+ format = exts.join('.') if exts.any? # join('.') is needed for multipart templates
+ else # no extension, just format
+ format = exts.last
end
- [base_path, name, locale, format, extension]
+ [locale, format, extension]
end
end
end
diff --git a/actionpack/test/controller/request_test.rb b/actionpack/test/controller/request_test.rb
index c72f885a05..c4cc63e628 100644
--- a/actionpack/test/controller/request_test.rb
+++ b/actionpack/test/controller/request_test.rb
@@ -3,7 +3,6 @@ require 'abstract_unit'
class RequestTest < ActiveSupport::TestCase
def setup
ActionController::Base.relative_url_root = nil
- @request = ActionController::TestRequest.new
end
def teardown
@@ -11,60 +10,52 @@ class RequestTest < ActiveSupport::TestCase
end
def test_remote_ip
- assert_equal '0.0.0.0', @request.remote_ip
+ request = stub_request 'REMOTE_ADDR' => '1.2.3.4'
+ assert_equal '1.2.3.4', request.remote_ip
- @request.remote_addr = '1.2.3.4'
- assert_equal '1.2.3.4', @request.remote_ip
+ request = stub_request 'REMOTE_ADDR' => '1.2.3.4,3.4.5.6'
+ assert_equal '1.2.3.4', request.remote_ip
- @request.remote_addr = '1.2.3.4,3.4.5.6'
- assert_equal '1.2.3.4', @request.remote_ip
+ request = stub_request 'REMOTE_ADDR' => '1.2.3.4',
+ 'HTTP_X_FORWARDED_FOR' => '3.4.5.6'
+ assert_equal '1.2.3.4', request.remote_ip
- @request.env['HTTP_CLIENT_IP'] = '2.3.4.5'
- assert_equal '1.2.3.4', @request.remote_ip
+ request = stub_request 'REMOTE_ADDR' => '127.0.0.1',
+ 'HTTP_X_FORWARDED_FOR' => '3.4.5.6'
+ assert_equal '3.4.5.6', request.remote_ip
- @request.remote_addr = '192.168.0.1'
- assert_equal '2.3.4.5', @request.remote_ip
- @request.env.delete 'HTTP_CLIENT_IP'
+ request = stub_request 'HTTP_X_FORWARDED_FOR' => 'unknown,3.4.5.6'
+ assert_equal '3.4.5.6', request.remote_ip
- @request.remote_addr = '1.2.3.4'
- @request.env['HTTP_X_FORWARDED_FOR'] = '3.4.5.6'
- assert_equal '1.2.3.4', @request.remote_ip
+ request = stub_request 'HTTP_X_FORWARDED_FOR' => '172.16.0.1,3.4.5.6'
+ assert_equal '3.4.5.6', request.remote_ip
- @request.remote_addr = '127.0.0.1'
- @request.env['HTTP_X_FORWARDED_FOR'] = '3.4.5.6'
- assert_equal '3.4.5.6', @request.remote_ip
+ request = stub_request 'HTTP_X_FORWARDED_FOR' => '192.168.0.1,3.4.5.6'
+ assert_equal '3.4.5.6', request.remote_ip
- @request.env['HTTP_X_FORWARDED_FOR'] = 'unknown,3.4.5.6'
- assert_equal '3.4.5.6', @request.remote_ip
+ request = stub_request 'HTTP_X_FORWARDED_FOR' => '10.0.0.1,3.4.5.6'
+ assert_equal '3.4.5.6', request.remote_ip
- @request.env['HTTP_X_FORWARDED_FOR'] = '172.16.0.1,3.4.5.6'
- assert_equal '3.4.5.6', @request.remote_ip
+ request = stub_request 'HTTP_X_FORWARDED_FOR' => '10.0.0.1, 10.0.0.1, 3.4.5.6'
+ assert_equal '3.4.5.6', request.remote_ip
- @request.env['HTTP_X_FORWARDED_FOR'] = '192.168.0.1,3.4.5.6'
- assert_equal '3.4.5.6', @request.remote_ip
+ request = stub_request 'HTTP_X_FORWARDED_FOR' => '127.0.0.1,3.4.5.6'
+ assert_equal '3.4.5.6', request.remote_ip
- @request.env['HTTP_X_FORWARDED_FOR'] = '10.0.0.1,3.4.5.6'
- assert_equal '3.4.5.6', @request.remote_ip
+ request = stub_request 'HTTP_X_FORWARDED_FOR' => 'unknown,192.168.0.1'
+ assert_equal 'unknown', request.remote_ip
- @request.env['HTTP_X_FORWARDED_FOR'] = '10.0.0.1, 10.0.0.1, 3.4.5.6'
- assert_equal '3.4.5.6', @request.remote_ip
+ request = stub_request 'HTTP_X_FORWARDED_FOR' => '9.9.9.9, 3.4.5.6, 10.0.0.1, 172.31.4.4'
+ assert_equal '3.4.5.6', request.remote_ip
- @request.env['HTTP_X_FORWARDED_FOR'] = '127.0.0.1,3.4.5.6'
- assert_equal '3.4.5.6', @request.remote_ip
-
- @request.env['HTTP_X_FORWARDED_FOR'] = 'unknown,192.168.0.1'
- assert_equal 'unknown', @request.remote_ip
-
- @request.env['HTTP_X_FORWARDED_FOR'] = '9.9.9.9, 3.4.5.6, 10.0.0.1, 172.31.4.4'
- assert_equal '3.4.5.6', @request.remote_ip
-
- @request.env['HTTP_CLIENT_IP'] = '8.8.8.8'
+ request = stub_request 'HTTP_X_FORWARDED_FOR' => '1.1.1.1',
+ 'HTTP_CLIENT_IP' => '2.2.2.2'
e = assert_raise(ActionController::ActionControllerError) {
- @request.remote_ip
+ request.remote_ip
}
assert_match /IP spoofing attack/, e.message
- assert_match /HTTP_X_FORWARDED_FOR="9.9.9.9, 3.4.5.6, 10.0.0.1, 172.31.4.4"/, e.message
- assert_match /HTTP_CLIENT_IP="8.8.8.8"/, e.message
+ assert_match /HTTP_X_FORWARDED_FOR="1.1.1.1"/, e.message
+ assert_match /HTTP_CLIENT_IP="2.2.2.2"/, e.message
# turn IP Spoofing detection off.
# This is useful for sites that are aimed at non-IP clients. The typical
@@ -72,336 +63,333 @@ class RequestTest < ActiveSupport::TestCase
# leap of faith to assume that their proxies are ever going to set the
# HTTP_CLIENT_IP/HTTP_X_FORWARDED_FOR headers properly.
ActionController::Base.ip_spoofing_check = false
- assert_equal('8.8.8.8', @request.remote_ip)
+ request = stub_request 'HTTP_X_FORWARDED_FOR' => '1.1.1.1',
+ 'HTTP_CLIENT_IP' => '2.2.2.2'
+ assert_equal '2.2.2.2', request.remote_ip
ActionController::Base.ip_spoofing_check = true
- @request.env['HTTP_X_FORWARDED_FOR'] = '8.8.8.8, 9.9.9.9'
- assert_equal '8.8.8.8', @request.remote_ip
-
- @request.env.delete 'HTTP_CLIENT_IP'
- @request.env.delete 'HTTP_X_FORWARDED_FOR'
+ request = stub_request 'HTTP_X_FORWARDED_FOR' => '8.8.8.8, 9.9.9.9'
+ assert_equal '9.9.9.9', request.remote_ip
end
def test_domains
- @request.host = "www.rubyonrails.org"
- assert_equal "rubyonrails.org", @request.domain
-
- @request.host = "www.rubyonrails.co.uk"
- assert_equal "rubyonrails.co.uk", @request.domain(2)
+ request = stub_request 'HTTP_HOST' => 'www.rubyonrails.org'
+ assert_equal "rubyonrails.org", request.domain
- @request.host = "192.168.1.200"
- assert_nil @request.domain
+ request = stub_request 'HTTP_HOST' => "www.rubyonrails.co.uk"
+ assert_equal "rubyonrails.co.uk", request.domain(2)
- @request.host = "foo.192.168.1.200"
- assert_nil @request.domain
+ request = stub_request 'HTTP_HOST' => "192.168.1.200"
+ assert_nil request.domain
- @request.host = "192.168.1.200.com"
- assert_equal "200.com", @request.domain
+ request = stub_request 'HTTP_HOST' => "foo.192.168.1.200"
+ assert_nil request.domain
- @request.host = nil
- assert_nil @request.domain
+ request = stub_request 'HTTP_HOST' => "192.168.1.200.com"
+ assert_equal "200.com", request.domain
end
def test_subdomains
- @request.host = "www.rubyonrails.org"
- assert_equal %w( www ), @request.subdomains
+ request = stub_request 'HTTP_HOST' => "www.rubyonrails.org"
+ assert_equal %w( www ), request.subdomains
- @request.host = "www.rubyonrails.co.uk"
- assert_equal %w( www ), @request.subdomains(2)
+ request = stub_request 'HTTP_HOST' => "www.rubyonrails.co.uk"
+ assert_equal %w( www ), request.subdomains(2)
- @request.host = "dev.www.rubyonrails.co.uk"
- assert_equal %w( dev www ), @request.subdomains(2)
+ request = stub_request 'HTTP_HOST' => "dev.www.rubyonrails.co.uk"
+ assert_equal %w( dev www ), request.subdomains(2)
- @request.host = "foobar.foobar.com"
- assert_equal %w( foobar ), @request.subdomains
+ request = stub_request 'HTTP_HOST' => "foobar.foobar.com"
+ assert_equal %w( foobar ), request.subdomains
- @request.host = "192.168.1.200"
- assert_equal [], @request.subdomains
+ request = stub_request 'HTTP_HOST' => "192.168.1.200"
+ assert_equal [], request.subdomains
- @request.host = "foo.192.168.1.200"
- assert_equal [], @request.subdomains
+ request = stub_request 'HTTP_HOST' => "foo.192.168.1.200"
+ assert_equal [], request.subdomains
- @request.host = "192.168.1.200.com"
- assert_equal %w( 192 168 1 ), @request.subdomains
+ request = stub_request 'HTTP_HOST' => "192.168.1.200.com"
+ assert_equal %w( 192 168 1 ), request.subdomains
- @request.host = nil
- assert_equal [], @request.subdomains
+ request = stub_request 'HTTP_HOST' => nil
+ assert_equal [], request.subdomains
end
def test_port_string
- @request.port = 80
- assert_equal "", @request.port_string
+ request = stub_request 'HTTP_HOST' => 'www.example.org:80'
+ assert_equal "", request.port_string
- @request.port = 8080
- assert_equal ":8080", @request.port_string
+ request = stub_request 'HTTP_HOST' => 'www.example.org:8080'
+ assert_equal ":8080", request.port_string
end
def test_request_uri
- @request.env['SERVER_SOFTWARE'] = 'Apache 42.342.3432'
+ request = stub_request 'REQUEST_URI' => "http://www.rubyonrails.org/path/of/some/uri?mapped=1"
+ assert_equal "/path/of/some/uri?mapped=1", request.request_uri
+ assert_equal "/path/of/some/uri", request.path
- @request.set_REQUEST_URI "http://www.rubyonrails.org/path/of/some/uri?mapped=1"
- assert_equal "/path/of/some/uri?mapped=1", @request.request_uri
- assert_equal "/path/of/some/uri", @request.path
+ request = stub_request 'REQUEST_URI' => "http://www.rubyonrails.org/path/of/some/uri"
+ assert_equal "/path/of/some/uri", request.request_uri
+ assert_equal "/path/of/some/uri", request.path
- @request.set_REQUEST_URI "http://www.rubyonrails.org/path/of/some/uri"
- assert_equal "/path/of/some/uri", @request.request_uri
- assert_equal "/path/of/some/uri", @request.path
+ request = stub_request 'REQUEST_URI' => "/path/of/some/uri"
+ assert_equal "/path/of/some/uri", request.request_uri
+ assert_equal "/path/of/some/uri", request.path
- @request.set_REQUEST_URI "/path/of/some/uri"
- assert_equal "/path/of/some/uri", @request.request_uri
- assert_equal "/path/of/some/uri", @request.path
+ request = stub_request 'REQUEST_URI' => "/"
+ assert_equal "/", request.request_uri
+ assert_equal "/", request.path
- @request.set_REQUEST_URI "/"
- assert_equal "/", @request.request_uri
- assert_equal "/", @request.path
+ request = stub_request 'REQUEST_URI' => "/?m=b"
+ assert_equal "/?m=b", request.request_uri
+ assert_equal "/", request.path
- @request.set_REQUEST_URI "/?m=b"
- assert_equal "/?m=b", @request.request_uri
- assert_equal "/", @request.path
-
- @request.set_REQUEST_URI "/"
- @request.env['SCRIPT_NAME'] = "/dispatch.cgi"
- assert_equal "/", @request.request_uri
- assert_equal "/", @request.path
+ request = stub_request 'REQUEST_URI' => "/", 'SCRIPT_NAME' => '/dispatch.cgi'
+ assert_equal "/", request.request_uri
+ assert_equal "/", request.path
ActionController::Base.relative_url_root = "/hieraki"
- @request.set_REQUEST_URI "/hieraki/"
- @request.env['SCRIPT_NAME'] = "/hieraki/dispatch.cgi"
- assert_equal "/hieraki/", @request.request_uri
- assert_equal "/", @request.path
+ request = stub_request 'REQUEST_URI' => "/hieraki/", 'SCRIPT_NAME' => "/hieraki/dispatch.cgi"
+ assert_equal "/hieraki/", request.request_uri
+ assert_equal "/", request.path
ActionController::Base.relative_url_root = nil
ActionController::Base.relative_url_root = "/collaboration/hieraki"
- @request.set_REQUEST_URI "/collaboration/hieraki/books/edit/2"
- @request.env['SCRIPT_NAME'] = "/collaboration/hieraki/dispatch.cgi"
- assert_equal "/collaboration/hieraki/books/edit/2", @request.request_uri
- assert_equal "/books/edit/2", @request.path
+ request = stub_request 'REQUEST_URI' => "/collaboration/hieraki/books/edit/2",
+ 'SCRIPT_NAME' => "/collaboration/hieraki/dispatch.cgi"
+ assert_equal "/collaboration/hieraki/books/edit/2", request.request_uri
+ assert_equal "/books/edit/2", request.path
ActionController::Base.relative_url_root = nil
# The following tests are for when REQUEST_URI is not supplied (as in IIS)
- @request.env['PATH_INFO'] = "/path/of/some/uri?mapped=1"
- @request.env['SCRIPT_NAME'] = nil #"/path/dispatch.rb"
- @request.set_REQUEST_URI nil
- assert_equal "/path/of/some/uri?mapped=1", @request.request_uri
- assert_equal "/path/of/some/uri", @request.path
+ request = stub_request 'PATH_INFO' => "/path/of/some/uri?mapped=1",
+ 'SCRIPT_NAME' => nil,
+ 'REQUEST_URI' => nil
+ assert_equal "/path/of/some/uri?mapped=1", request.request_uri
+ assert_equal "/path/of/some/uri", request.path
ActionController::Base.relative_url_root = '/path'
- @request.env['PATH_INFO'] = "/path/of/some/uri?mapped=1"
- @request.env['SCRIPT_NAME'] = "/path/dispatch.rb"
- @request.set_REQUEST_URI nil
- assert_equal "/path/of/some/uri?mapped=1", @request.request_uri
- assert_equal "/of/some/uri", @request.path
+ request = stub_request 'PATH_INFO' => "/path/of/some/uri?mapped=1",
+ 'SCRIPT_NAME' => "/path/dispatch.rb",
+ 'REQUEST_URI' => nil
+ assert_equal "/path/of/some/uri?mapped=1", request.request_uri
+ assert_equal "/of/some/uri", request.path
ActionController::Base.relative_url_root = nil
- @request.env['PATH_INFO'] = "/path/of/some/uri"
- @request.env['SCRIPT_NAME'] = nil
- @request.set_REQUEST_URI nil
- assert_equal "/path/of/some/uri", @request.request_uri
- assert_equal "/path/of/some/uri", @request.path
+ request = stub_request 'PATH_INFO' => "/path/of/some/uri",
+ 'SCRIPT_NAME' => nil,
+ 'REQUEST_URI' => nil
+ assert_equal "/path/of/some/uri", request.request_uri
+ assert_equal "/path/of/some/uri", request.path
- @request.env['PATH_INFO'] = "/"
- @request.set_REQUEST_URI nil
- assert_equal "/", @request.request_uri
- assert_equal "/", @request.path
+ request = stub_request 'PATH_INFO' => '/', 'REQUEST_URI' => nil
+ assert_equal "/", request.request_uri
+ assert_equal "/", request.path
- @request.env['PATH_INFO'] = "/?m=b"
- @request.set_REQUEST_URI nil
- assert_equal "/?m=b", @request.request_uri
- assert_equal "/", @request.path
+ request = stub_request 'PATH_INFO' => '/?m=b', 'REQUEST_URI' => nil
+ assert_equal "/?m=b", request.request_uri
+ assert_equal "/", request.path
- @request.env['PATH_INFO'] = "/"
- @request.env['SCRIPT_NAME'] = "/dispatch.cgi"
- @request.set_REQUEST_URI nil
- assert_equal "/", @request.request_uri
- assert_equal "/", @request.path
+ request = stub_request 'PATH_INFO' => "/",
+ 'SCRIPT_NAME' => "/dispatch.cgi",
+ 'REQUEST_URI' => nil
+ assert_equal "/", request.request_uri
+ assert_equal "/", request.path
ActionController::Base.relative_url_root = '/hieraki'
- @request.env['PATH_INFO'] = "/hieraki/"
- @request.env['SCRIPT_NAME'] = "/hieraki/dispatch.cgi"
- @request.set_REQUEST_URI nil
- assert_equal "/hieraki/", @request.request_uri
- assert_equal "/", @request.path
+ request = stub_request 'PATH_INFO' => "/hieraki/",
+ 'SCRIPT_NAME' => "/hieraki/dispatch.cgi",
+ 'REQUEST_URI' => nil
+ assert_equal "/hieraki/", request.request_uri
+ assert_equal "/", request.path
ActionController::Base.relative_url_root = nil
- @request.set_REQUEST_URI '/hieraki/dispatch.cgi'
+ request = stub_request 'REQUEST_URI' => '/hieraki/dispatch.cgi'
ActionController::Base.relative_url_root = '/hieraki'
- assert_equal "/dispatch.cgi", @request.path
+ assert_equal "/dispatch.cgi", request.path
ActionController::Base.relative_url_root = nil
- @request.set_REQUEST_URI '/hieraki/dispatch.cgi'
+ request = stub_request 'REQUEST_URI' => '/hieraki/dispatch.cgi'
ActionController::Base.relative_url_root = '/foo'
- assert_equal "/hieraki/dispatch.cgi", @request.path
+ assert_equal "/hieraki/dispatch.cgi", request.path
ActionController::Base.relative_url_root = nil
# This test ensures that Rails uses REQUEST_URI over PATH_INFO
ActionController::Base.relative_url_root = nil
- @request.env['REQUEST_URI'] = "/some/path"
- @request.env['PATH_INFO'] = "/another/path"
- @request.env['SCRIPT_NAME'] = "/dispatch.cgi"
- assert_equal "/some/path", @request.request_uri
- assert_equal "/some/path", @request.path
+ request = stub_request 'REQUEST_URI' => "/some/path",
+ 'PATH_INFO' => "/another/path",
+ 'SCRIPT_NAME' => "/dispatch.cgi"
+ assert_equal "/some/path", request.request_uri
+ assert_equal "/some/path", request.path
end
def test_host_with_default_port
- @request.host = "rubyonrails.org"
- @request.port = 80
- assert_equal "rubyonrails.org", @request.host_with_port
+ request = stub_request 'HTTP_HOST' => 'rubyonrails.org:80'
+ assert_equal "rubyonrails.org", request.host_with_port
end
def test_host_with_non_default_port
- @request.host = "rubyonrails.org"
- @request.port = 81
- assert_equal "rubyonrails.org:81", @request.host_with_port
+ request = stub_request 'HTTP_HOST' => 'rubyonrails.org:81'
+ assert_equal "rubyonrails.org:81", request.host_with_port
end
def test_server_software
- assert_equal nil, @request.server_software
+ request = stub_request
+ assert_equal nil, request.server_software
- @request.env['SERVER_SOFTWARE'] = 'Apache3.422'
- assert_equal 'apache', @request.server_software
+ request = stub_request 'SERVER_SOFTWARE' => 'Apache3.422'
+ assert_equal 'apache', request.server_software
- @request.env['SERVER_SOFTWARE'] = 'lighttpd(1.1.4)'
- assert_equal 'lighttpd', @request.server_software
+ request = stub_request 'SERVER_SOFTWARE' => 'lighttpd(1.1.4)'
+ assert_equal 'lighttpd', request.server_software
end
def test_xml_http_request
- assert !@request.xml_http_request?
- assert !@request.xhr?
+ request = stub_request
+
+ assert !request.xml_http_request?
+ assert !request.xhr?
- @request.env['HTTP_X_REQUESTED_WITH'] = "DefinitelyNotAjax1.0"
- assert !@request.xml_http_request?
- assert !@request.xhr?
+ request = stub_request 'HTTP_X_REQUESTED_WITH' => 'DefinitelyNotAjax1.0'
+ assert !request.xml_http_request?
+ assert !request.xhr?
- @request.env['HTTP_X_REQUESTED_WITH'] = "XMLHttpRequest"
- assert @request.xml_http_request?
- assert @request.xhr?
+ request = stub_request 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest'
+ assert request.xml_http_request?
+ assert request.xhr?
end
def test_reports_ssl
- assert !@request.ssl?
- @request.env['HTTPS'] = 'on'
- assert @request.ssl?
+ request = stub_request
+ assert !request.ssl?
+
+ request = stub_request 'HTTPS' => 'on'
+ assert request.ssl?
end
def test_reports_ssl_when_proxied_via_lighttpd
- assert !@request.ssl?
- @request.env['HTTP_X_FORWARDED_PROTO'] = 'https'
- assert @request.ssl?
+ request = stub_request
+ assert !request.ssl?
+
+ request = stub_request 'HTTP_X_FORWARDED_PROTO' => 'https'
+ assert request.ssl?
end
def test_symbolized_request_methods
[:get, :post, :put, :delete].each do |method|
- self.request_method = method
- assert_equal method, @request.method
+ request = stub_request 'REQUEST_METHOD' => method.to_s.upcase
+ assert_equal method, request.method
end
end
def test_invalid_http_method_raises_exception
assert_raise(ActionController::UnknownHttpMethod) do
- self.request_method = :random_method
- @request.request_method
+ request = stub_request 'REQUEST_METHOD' => 'RANDOM_METHOD'
+ request.request_method
end
end
def test_allow_method_hacking_on_post
[:get, :head, :options, :put, :post, :delete].each do |method|
- self.request_method = method
- assert_equal(method == :head ? :get : method, @request.method)
- end
- end
-
- def test_invalid_method_hacking_on_post_raises_exception
- assert_raise(ActionController::UnknownHttpMethod) do
- self.request_method = :_random_method
- @request.request_method
+ request = stub_request 'REQUEST_METHOD' => method.to_s.upcase
+ assert_equal(method == :head ? :get : method, request.method)
end
end
def test_restrict_method_hacking
- @request.instance_eval { @parameters = { :_method => 'put' } }
[:get, :put, :delete].each do |method|
- self.request_method = method
- assert_equal method, @request.method
+ request = stub_request 'REQUEST_METHOD' => method.to_s.upcase,
+ 'action_controller.request.request_parameters' => { :_method => 'put' }
+ assert_equal method, request.method
end
end
def test_head_masquerading_as_get
- self.request_method = :head
- assert_equal :get, @request.method
- assert @request.get?
- assert @request.head?
+ request = stub_request 'REQUEST_METHOD' => 'HEAD'
+ assert_equal :get, request.method
+ assert request.get?
+ assert request.head?
end
def test_xml_format
- @request.instance_eval { @parameters = { :format => 'xml' } }
- assert_equal Mime::XML, @request.format
+ request = stub_request
+ request.expects(:parameters).at_least_once.returns({ :format => 'xml' })
+ assert_equal Mime::XML, request.format
end
def test_xhtml_format
- @request.instance_eval { @parameters = { :format => 'xhtml' } }
- assert_equal Mime::HTML, @request.format
+ request = stub_request
+ request.expects(:parameters).at_least_once.returns({ :format => 'xhtml' })
+ assert_equal Mime::HTML, request.format
end
def test_txt_format
- @request.instance_eval { @parameters = { :format => 'txt' } }
- assert_equal Mime::TEXT, @request.format
+ request = stub_request
+ request.expects(:parameters).at_least_once.returns({ :format => 'txt' })
+ assert_equal Mime::TEXT, request.format
end
- def test_nil_format
+ def test_xml_http_request
ActionController::Base.use_accept_header, old =
false, ActionController::Base.use_accept_header
- @request.instance_eval { @parameters = {} }
- @request.env["HTTP_X_REQUESTED_WITH"] = "XMLHttpRequest"
- assert @request.xhr?
- assert_equal Mime::JS, @request.format
-
+ request = stub_request 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest'
+ request.expects(:parameters).at_least_once.returns({})
+ assert request.xhr?
+ assert_equal Mime::JS, request.format
ensure
ActionController::Base.use_accept_header = old
end
def test_content_type
- @request.env["CONTENT_TYPE"] = "text/html"
- assert_equal Mime::HTML, @request.content_type
+ request = stub_request 'CONTENT_TYPE' => 'text/html'
+ assert_equal Mime::HTML, request.content_type
end
- def test_format_assignment_should_set_format
- @request.instance_eval { self.format = :txt }
- assert !@request.format.xml?
- @request.instance_eval { self.format = :xml }
- assert @request.format.xml?
+ def test_can_override_format_with_parameter
+ request = stub_request
+ request.expects(:parameters).at_least_once.returns({ :format => :txt })
+ assert !request.format.xml?
+
+ request = stub_request
+ request.expects(:parameters).at_least_once.returns({ :format => :xml })
+ assert request.format.xml?
end
def test_content_no_type
- assert_equal nil, @request.content_type
+ request = stub_request
+ assert_equal nil, request.content_type
end
def test_content_type_xml
- @request.env["CONTENT_TYPE"] = "application/xml"
- assert_equal Mime::XML, @request.content_type
+ request = stub_request 'CONTENT_TYPE' => 'application/xml'
+ assert_equal Mime::XML, request.content_type
end
def test_content_type_with_charset
- @request.env["CONTENT_TYPE"] = "application/xml; charset=UTF-8"
- assert_equal Mime::XML, @request.content_type
+ request = stub_request 'CONTENT_TYPE' => 'application/xml; charset=UTF-8'
+ assert_equal Mime::XML, request.content_type
end
def test_user_agent
- assert_not_nil @request.user_agent
+ request = stub_request 'HTTP_USER_AGENT' => 'TestAgent'
+ assert_equal 'TestAgent', request.user_agent
end
def test_parameters
- @request.stubs(:request_parameters).returns({ "foo" => 1 })
- @request.stubs(:query_parameters).returns({ "bar" => 2 })
+ request = stub_request
+ request.stubs(:request_parameters).returns({ "foo" => 1 })
+ request.stubs(:query_parameters).returns({ "bar" => 2 })
- assert_equal({"foo" => 1, "bar" => 2}, @request.parameters)
- assert_equal({"foo" => 1}, @request.request_parameters)
- assert_equal({"bar" => 2}, @request.query_parameters)
+ assert_equal({"foo" => 1, "bar" => 2}, request.parameters)
+ assert_equal({"foo" => 1}, request.request_parameters)
+ assert_equal({"bar" => 2}, request.query_parameters)
+ end
+
+protected
+
+ def stub_request(env={})
+ ActionController::Request.new(env)
end
- protected
- def request_method=(method)
- @request.env['REQUEST_METHOD'] = method.to_s.upcase
- @request.request_method = nil # Reset the ivar cache
- end
end
diff --git a/actionpack/test/controller/session/cookie_store_test.rb b/actionpack/test/controller/session/cookie_store_test.rb
index 48a961ca34..40fcd56846 100644
--- a/actionpack/test/controller/session/cookie_store_test.rb
+++ b/actionpack/test/controller/session/cookie_store_test.rb
@@ -193,27 +193,6 @@ class CookieStoreTest < ActionController::IntegrationTest
end
end
- def test_session_store_with_expire_after
- app = ActionController::Session::CookieStore.new(DispatcherApp, :key => SessionKey, :secret => SessionSecret, :expire_after => 5.hours)
- @integration_session = open_session(app)
-
- with_test_route_set do
- # First request accesses the session
- cookies[SessionKey] = SignedBar
-
- get '/set_session_value'
- assert_response :success
- cookie = headers['Set-Cookie']
-
- # Second request does not access the session so the
- # expires header should not be changed
- get '/no_session_access'
- assert_response :success
- assert_equal cookie, headers['Set-Cookie'],
- "#{unmarshal_session(cookie).inspect} expected but was #{unmarshal_session(headers['Set-Cookie']).inspect}"
- end
- end
-
private
def with_test_route_set
with_routing do |set|
diff --git a/actionpack/test/controller/test_test.rb b/actionpack/test/controller/test_test.rb
index 65c894c2e7..6bf8a10f59 100644
--- a/actionpack/test/controller/test_test.rb
+++ b/actionpack/test/controller/test_test.rb
@@ -130,6 +130,10 @@ XML
ActionController::Routing::Routes.reload
end
+ def test_test_request_has_session_options_initialized
+ assert @request.session_options
+ end
+
def test_raw_post_handling
params = {:page => {:name => 'page name'}, 'some key' => 123}
post :render_raw_post, params.dup
@@ -515,6 +519,14 @@ XML
assert_nil @request.instance_variable_get("@request_method")
end
+ def test_params_reset_after_post_request
+ post :no_op, :foo => "bar"
+ assert_equal "bar", @request.params[:foo]
+ @request.recycle!
+ post :no_op
+ assert @request.params[:foo].blank?
+ end
+
%w(controller response request).each do |variable|
%w(get post put delete head process).each do |method|
define_method("test_#{variable}_missing_for_#{method}_raises_error") do
diff --git a/actionpack/test/fixtures/test/backup_files/item.html.erb b/actionpack/test/fixtures/test/backup_files/item.html.erb
new file mode 100644
index 0000000000..aaac0a2160
--- /dev/null
+++ b/actionpack/test/fixtures/test/backup_files/item.html.erb
@@ -0,0 +1 @@
+The correct item.erb was loaded.
diff --git a/actionpack/test/fixtures/test/backup_files/item.html.erb.orig b/actionpack/test/fixtures/test/backup_files/item.html.erb.orig
new file mode 100644
index 0000000000..a2b153e5a2
--- /dev/null
+++ b/actionpack/test/fixtures/test/backup_files/item.html.erb.orig
@@ -0,0 +1 @@
+This is an editor backup file and should never be loaded!
diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb
index 9adf053b09..80fd549fd7 100644
--- a/actionpack/test/template/render_test.rb
+++ b/actionpack/test/template/render_test.rb
@@ -255,6 +255,12 @@ module RenderTestCases
assert_equal Encoding::UTF_8, result.encoding
end
end
+
+ def test_render_with_backup_files
+ result = @view.render :file => "/test/backup_files/item"
+ assert_equal "The correct item.erb was loaded.\n", result
+ end
+
end
module TemplatesSetupTeardown
diff --git a/actionpack/test/template/template_test.rb b/actionpack/test/template/template_test.rb
new file mode 100644
index 0000000000..5c6523201b
--- /dev/null
+++ b/actionpack/test/template/template_test.rb
@@ -0,0 +1,34 @@
+require 'abstract_unit'
+
+class TemplateTest < Test::Unit::TestCase
+ def test_template_path_parsing
+ with_options :base_path => nil, :name => 'abc', :locale => nil, :format => 'html', :extension => 'erb' do |t|
+ t.assert_parses_template_path 'abc.en.html.erb', :locale => 'en'
+ t.assert_parses_template_path 'abc.en.plain.html.erb', :locale => 'en', :format => 'plain.html'
+ t.assert_parses_template_path 'abc.html.erb'
+ t.assert_parses_template_path 'abc.plain.html.erb', :format => 'plain.html'
+ t.assert_parses_template_path 'abc.erb', :format => nil
+ t.assert_parses_template_path 'abc.html', :extension => nil
+
+ t.assert_parses_template_path '_abc.html.erb', :name => '_abc'
+
+ t.assert_parses_template_path 'test/abc.html.erb', :base_path => 'test'
+ t.assert_parses_template_path './test/abc.html.erb', :base_path => './test'
+ t.assert_parses_template_path '../test/abc.html.erb', :base_path => '../test'
+
+ t.assert_parses_template_path 'abc', :extension => nil, :format => nil, :name => nil
+ t.assert_parses_template_path 'abc.xxx', :extension => nil, :format => 'xxx', :name => 'abc'
+ t.assert_parses_template_path 'abc.html.xxx', :extension => nil, :format => 'xxx', :name => 'abc'
+
+ t.assert_parses_template_path 'abc.html.erb.orig', :format => 'orig', :extension => nil
+ end
+ end
+
+ private
+ def assert_parses_template_path(path, parse_results)
+ template = ActionView::Template.new(path, '')
+ parse_results.each_pair do |k, v|
+ assert_block(%Q{Expected template to parse #{k.inspect} from "#{path}" as #{v.inspect}, but got #{template.send(k).inspect}}) { v == template.send(k) }
+ end
+ end
+end
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG
index ab40e1a17a..2acce97646 100644
--- a/activesupport/CHANGELOG
+++ b/activesupport/CHANGELOG
@@ -1,3 +1,8 @@
+*Edge
+
+* Time.local instances: Adding 24.hours across the DST boundary adds 24 hours instead of one day #2066 [Michael Curtis]
+
+
*2.3.2 [Final] (March 15, 2009)*
* XmlMini supports LibXML and Nokogiri backends. #2084, #2190 [Bart ten Brinke, Aaron Patterson]
diff --git a/activesupport/lib/active_support/cache/strategy/local_cache.rb b/activesupport/lib/active_support/cache/strategy/local_cache.rb
index d83e259a2a..84d9a0e6d8 100644
--- a/activesupport/lib/active_support/cache/strategy/local_cache.rb
+++ b/activesupport/lib/active_support/cache/strategy/local_cache.rb
@@ -27,6 +27,11 @@ module ActiveSupport
Thread.current[:#{thread_local_key}] = nil
end
EOS
+
+ def klass.to_s
+ "ActiveSupport::Cache::Strategy::LocalCache"
+ end
+
klass
end
end
diff --git a/activesupport/lib/active_support/core_ext/time/calculations.rb b/activesupport/lib/active_support/core_ext/time/calculations.rb
index 5ed750afcc..d13d0e01a7 100644
--- a/activesupport/lib/active_support/core_ext/time/calculations.rb
+++ b/activesupport/lib/active_support/core_ext/time/calculations.rb
@@ -116,22 +116,14 @@ module ActiveSupport #:nodoc:
seconds_to_advance == 0 ? time_advanced_by_date : time_advanced_by_date.since(seconds_to_advance)
end
- # Returns a new Time representing the time a number of seconds ago, this is basically a wrapper around the Numeric extension
+ # Returns a new Time representing the time a number of seconds ago
def ago(seconds)
self.since(-seconds)
end
- # Returns a new Time representing the time a number of seconds since the instance time, this is basically a wrapper around
- # the Numeric extension.
+ # Returns a new Time representing the time a number of seconds since the instance time
def since(seconds)
- f = seconds.since(self)
- if ActiveSupport::Duration === seconds
- f
- else
- initial_dst = self.dst? ? 1 : 0
- final_dst = f.dst? ? 1 : 0
- (seconds.abs >= 86400 && initial_dst != final_dst) ? f + (initial_dst - final_dst).hours : f
- end
+ self + seconds
rescue
self.to_datetime.since(seconds)
end
diff --git a/activesupport/test/core_ext/duration_test.rb b/activesupport/test/core_ext/duration_test.rb
index ab5a86668e..8954295d10 100644
--- a/activesupport/test/core_ext/duration_test.rb
+++ b/activesupport/test/core_ext/duration_test.rb
@@ -109,6 +109,18 @@ class DurationTest < ActiveSupport::TestCase
ensure
Time.zone_default = nil
end
+
+ def test_adding_hours_across_dst_boundary
+ with_env_tz 'CET' do
+ assert_equal Time.local(2009,3,29,0,0,0) + 24.hours, Time.local(2009,3,30,1,0,0)
+ end
+ end
+
+ def test_adding_day_across_dst_boundary
+ with_env_tz 'CET' do
+ assert_equal Time.local(2009,3,29,0,0,0) + 1.day, Time.local(2009,3,30,0,0,0)
+ end
+ end
protected
def with_env_tz(new_tz = 'US/Eastern')
diff --git a/activesupport/test/core_ext/time_ext_test.rb b/activesupport/test/core_ext/time_ext_test.rb
index c0855520e8..70cf4a9450 100644
--- a/activesupport/test/core_ext/time_ext_test.rb
+++ b/activesupport/test/core_ext/time_ext_test.rb
@@ -183,26 +183,46 @@ class TimeExtCalculationsTest < Test::Unit::TestCase
def test_daylight_savings_time_crossings_backward_start
with_env_tz 'US/Eastern' do
# dt: US: 2005 April 3rd 4:18am
- assert_equal Time.local(2005,4,2,4,18,0), Time.local(2005,4,3,4,18,0).ago(86400), 'dt-1.day=>st'
- assert_equal Time.local(2005,4,1,4,18,0), Time.local(2005,4,2,4,18,0).ago(86400), 'st-1.day=>st'
+ assert_equal Time.local(2005,4,2,3,18,0), Time.local(2005,4,3,4,18,0).ago(24.hours), 'dt-24.hours=>st'
+ assert_equal Time.local(2005,4,2,3,18,0), Time.local(2005,4,3,4,18,0).ago(86400), 'dt-86400=>st'
+ assert_equal Time.local(2005,4,2,3,18,0), Time.local(2005,4,3,4,18,0).ago(86400.seconds), 'dt-86400.seconds=>st'
+
+ assert_equal Time.local(2005,4,1,4,18,0), Time.local(2005,4,2,4,18,0).ago(24.hours), 'st-24.hours=>st'
+ assert_equal Time.local(2005,4,1,4,18,0), Time.local(2005,4,2,4,18,0).ago(86400), 'st-86400=>st'
+ assert_equal Time.local(2005,4,1,4,18,0), Time.local(2005,4,2,4,18,0).ago(86400.seconds), 'st-86400.seconds=>st'
end
with_env_tz 'NZ' do
# dt: New Zealand: 2006 October 1st 4:18am
- assert_equal Time.local(2006,9,30,4,18,0), Time.local(2006,10,1,4,18,0).ago(86400), 'dt-1.day=>st'
- assert_equal Time.local(2006,9,29,4,18,0), Time.local(2006,9,30,4,18,0).ago(86400), 'st-1.day=>st'
+ assert_equal Time.local(2006,9,30,3,18,0), Time.local(2006,10,1,4,18,0).ago(24.hours), 'dt-24.hours=>st'
+ assert_equal Time.local(2006,9,30,3,18,0), Time.local(2006,10,1,4,18,0).ago(86400.seconds), 'dt-86400.seconds=>st'
+ assert_equal Time.local(2006,9,30,3,18,0), Time.local(2006,10,1,4,18,0).ago(86400), 'dt-86400=>st'
+
+ assert_equal Time.local(2006,9,29,4,18,0), Time.local(2006,9,30,4,18,0).ago(86400), 'st-86400=>st'
+ assert_equal Time.local(2006,9,29,4,18,0), Time.local(2006,9,30,4,18,0).ago(24.hours), 'st-24.hours=>st'
+ assert_equal Time.local(2006,9,29,4,18,0), Time.local(2006,9,30,4,18,0).ago(86400.seconds), 'st-86400.seconds=>st'
end
end
def test_daylight_savings_time_crossings_backward_end
with_env_tz 'US/Eastern' do
# st: US: 2005 October 30th 4:03am
- assert_equal Time.local(2005,10,29,4,3), Time.local(2005,10,30,4,3,0).ago(86400), 'st-1.day=>dt'
- assert_equal Time.local(2005,10,28,4,3), Time.local(2005,10,29,4,3,0).ago(86400), 'dt-1.day=>dt'
+ assert_equal Time.local(2005,10,29,5,3), Time.local(2005,10,30,4,3,0).ago(24.hours), 'st-24.hours=>dt'
+ assert_equal Time.local(2005,10,29,5,3), Time.local(2005,10,30,4,3,0).ago(86400), 'st-86400=>dt'
+ assert_equal Time.local(2005,10,29,5,3), Time.local(2005,10,30,4,3,0).ago(86400.seconds), 'st-86400.seconds=>dt'
+
+ assert_equal Time.local(2005,10,28,4,3), Time.local(2005,10,29,4,3,0).ago(24.hours), 'dt-24.hours=>dt'
+ assert_equal Time.local(2005,10,28,4,3), Time.local(2005,10,29,4,3,0).ago(86400), 'dt-86400=>dt'
+ assert_equal Time.local(2005,10,28,4,3), Time.local(2005,10,29,4,3,0).ago(86400.seconds), 'dt-86400.seconds=>dt'
end
with_env_tz 'NZ' do
# st: New Zealand: 2006 March 19th 4:03am
- assert_equal Time.local(2006,3,18,4,3), Time.local(2006,3,19,4,3,0).ago(86400), 'st-1.day=>dt'
- assert_equal Time.local(2006,3,17,4,3), Time.local(2006,3,18,4,3,0).ago(86400), 'dt-1.day=>dt'
+ assert_equal Time.local(2006,3,18,5,3), Time.local(2006,3,19,4,3,0).ago(24.hours), 'st-24.hours=>dt'
+ assert_equal Time.local(2006,3,18,5,3), Time.local(2006,3,19,4,3,0).ago(86400), 'st-86400=>dt'
+ assert_equal Time.local(2006,3,18,5,3), Time.local(2006,3,19,4,3,0).ago(86400.seconds), 'st-86400.seconds=>dt'
+
+ assert_equal Time.local(2006,3,17,4,3), Time.local(2006,3,18,4,3,0).ago(24.hours), 'dt-24.hours=>dt'
+ assert_equal Time.local(2006,3,17,4,3), Time.local(2006,3,18,4,3,0).ago(86400), 'dt-86400=>dt'
+ assert_equal Time.local(2006,3,17,4,3), Time.local(2006,3,18,4,3,0).ago(86400.seconds), 'dt-86400.seconds=>dt'
end
end
@@ -231,6 +251,7 @@ class TimeExtCalculationsTest < Test::Unit::TestCase
assert_equal Time.local(2006,3,17,4,3), Time.local(2006,3,18,4,3,0).ago(1.day), 'dt-1.day=>dt'
end
end
+
def test_since
assert_equal Time.local(2005,2,22,10,10,11), Time.local(2005,2,22,10,10,10).since(1)
assert_equal Time.local(2005,2,22,11,10,10), Time.local(2005,2,22,10,10,10).since(3600)
@@ -243,13 +264,23 @@ class TimeExtCalculationsTest < Test::Unit::TestCase
def test_daylight_savings_time_crossings_forward_start
with_env_tz 'US/Eastern' do
# st: US: 2005 April 2nd 7:27pm
- assert_equal Time.local(2005,4,3,19,27,0), Time.local(2005,4,2,19,27,0).since(86400), 'st+1.day=>dt'
- assert_equal Time.local(2005,4,4,19,27,0), Time.local(2005,4,3,19,27,0).since(86400), 'dt+1.day=>dt'
+ assert_equal Time.local(2005,4,3,20,27,0), Time.local(2005,4,2,19,27,0).since(24.hours), 'st+24.hours=>dt'
+ assert_equal Time.local(2005,4,3,20,27,0), Time.local(2005,4,2,19,27,0).since(86400), 'st+86400=>dt'
+ assert_equal Time.local(2005,4,3,20,27,0), Time.local(2005,4,2,19,27,0).since(86400.seconds), 'st+86400.seconds=>dt'
+
+ assert_equal Time.local(2005,4,4,19,27,0), Time.local(2005,4,3,19,27,0).since(24.hours), 'dt+24.hoursy=>dt'
+ assert_equal Time.local(2005,4,4,19,27,0), Time.local(2005,4,3,19,27,0).since(86400), 'dt+86400=>dt'
+ assert_equal Time.local(2005,4,4,19,27,0), Time.local(2005,4,3,19,27,0).since(86400.seconds), 'dt+86400.seconds=>dt'
end
with_env_tz 'NZ' do
# st: New Zealand: 2006 September 30th 7:27pm
- assert_equal Time.local(2006,10,1,19,27,0), Time.local(2006,9,30,19,27,0).since(86400), 'st+1.day=>dt'
- assert_equal Time.local(2006,10,2,19,27,0), Time.local(2006,10,1,19,27,0).since(86400), 'dt+1.day=>dt'
+ assert_equal Time.local(2006,10,1,20,27,0), Time.local(2006,9,30,19,27,0).since(24.hours), 'st+24.hours=>dt'
+ assert_equal Time.local(2006,10,1,20,27,0), Time.local(2006,9,30,19,27,0).since(86400), 'st+86400=>dt'
+ assert_equal Time.local(2006,10,1,20,27,0), Time.local(2006,9,30,19,27,0).since(86400.seconds), 'st+86400.seconds=>dt'
+
+ assert_equal Time.local(2006,10,2,19,27,0), Time.local(2006,10,1,19,27,0).since(24.hours), 'dt+24.hours=>dt'
+ assert_equal Time.local(2006,10,2,19,27,0), Time.local(2006,10,1,19,27,0).since(86400), 'dt+86400=>dt'
+ assert_equal Time.local(2006,10,2,19,27,0), Time.local(2006,10,1,19,27,0).since(86400.seconds), 'dt+86400.seconds=>dt'
end
end
@@ -295,13 +326,23 @@ class TimeExtCalculationsTest < Test::Unit::TestCase
def test_daylight_savings_time_crossings_forward_end
with_env_tz 'US/Eastern' do
# dt: US: 2005 October 30th 12:45am
- assert_equal Time.local(2005,10,31,0,45,0), Time.local(2005,10,30,0,45,0).since(86400), 'dt+1.day=>st'
- assert_equal Time.local(2005,11, 1,0,45,0), Time.local(2005,10,31,0,45,0).since(86400), 'st+1.day=>st'
+ assert_equal Time.local(2005,10,30,23,45,0), Time.local(2005,10,30,0,45,0).since(24.hours), 'dt+24.hours=>st'
+ assert_equal Time.local(2005,10,30,23,45,0), Time.local(2005,10,30,0,45,0).since(86400), 'dt+86400=>st'
+ assert_equal Time.local(2005,10,30,23,45,0), Time.local(2005,10,30,0,45,0).since(86400.seconds), 'dt+86400.seconds=>st'
+
+ assert_equal Time.local(2005,11, 1,0,45,0), Time.local(2005,10,31,0,45,0).since(24.hours), 'st+24.hours=>st'
+ assert_equal Time.local(2005,11, 1,0,45,0), Time.local(2005,10,31,0,45,0).since(86400), 'st+86400=>st'
+ assert_equal Time.local(2005,11, 1,0,45,0), Time.local(2005,10,31,0,45,0).since(86400.seconds), 'st+86400.seconds=>st'
end
with_env_tz 'NZ' do
# dt: New Zealand: 2006 March 19th 1:45am
- assert_equal Time.local(2006,3,20,1,45,0), Time.local(2006,3,19,1,45,0).since(86400), 'dt+1.day=>st'
- assert_equal Time.local(2006,3,21,1,45,0), Time.local(2006,3,20,1,45,0).since(86400), 'st+1.day=>st'
+ assert_equal Time.local(2006,3,20,0,45,0), Time.local(2006,3,19,1,45,0).since(24.hours), 'dt+24.hours=>st'
+ assert_equal Time.local(2006,3,20,0,45,0), Time.local(2006,3,19,1,45,0).since(86400), 'dt+86400=>st'
+ assert_equal Time.local(2006,3,20,0,45,0), Time.local(2006,3,19,1,45,0).since(86400.seconds), 'dt+86400.seconds=>st'
+
+ assert_equal Time.local(2006,3,21,1,45,0), Time.local(2006,3,20,1,45,0).since(24.hours), 'st+24.hours=>st'
+ assert_equal Time.local(2006,3,21,1,45,0), Time.local(2006,3,20,1,45,0).since(86400), 'st+86400=>st'
+ assert_equal Time.local(2006,3,21,1,45,0), Time.local(2006,3,20,1,45,0).since(86400.seconds), 'st+86400.seconds=>st'
end
end
diff --git a/railties/builtin/rails_info/rails/info.rb b/railties/builtin/rails_info/rails/info.rb
index a20d9bfe62..0dd1c090c1 100644
--- a/railties/builtin/rails_info/rails/info.rb
+++ b/railties/builtin/rails_info/rails/info.rb
@@ -56,7 +56,12 @@ module Rails
returning table = '<table>' do
properties.each do |(name, value)|
table << %(<tr><td class="name">#{CGI.escapeHTML(name.to_s)}</td>)
- table << %(<td class="value">#{CGI.escapeHTML(value.to_s)}</td></tr>)
+ formatted_value = if value.kind_of?(Array)
+ "<ul>" + value.map { |v| "<li>#{CGI.escapeHTML(v.to_s)}</li>" }.join + "</ul>"
+ else
+ CGI.escapeHTML(value.to_s)
+ end
+ table << %(<td class="value">#{formatted_value}</td></tr>)
end
table << '</table>'
end
@@ -102,6 +107,10 @@ module Rails
end
end
+ property 'Middleware' do
+ ActionController::Dispatcher.middleware.active.map(&:inspect)
+ end
+
# The Rails Git revision, if it's checked out into vendor/rails.
property 'Edge Rails revision' do
edge_rails_revision
diff --git a/railties/html/index.html b/railties/html/index.html
index 0dd5189fb7..cd337dc74c 100644
--- a/railties/html/index.html
+++ b/railties/html/index.html
@@ -99,7 +99,12 @@
}
#about-content td.name {color: #555}
#about-content td.value {color: #000}
-
+
+ #about-content ul {
+ padding: 0;
+ list-style-type: none;
+ }
+
#about-content.failure {
background-color: #fcc;
border: 1px solid #f00;