提交 e3c26e99 编写于 作者: M Michael Koziarski

Merge branch 'master' into patches

*2.1.0 RC1 (May 11th, 2008)*
*2.1.0 (May 31st, 2008)*
* Fixed that a return-path header would be ignored #7572 [joost]
......
......@@ -55,7 +55,7 @@ spec = Gem::Specification.new do |s|
s.rubyforge_project = "actionmailer"
s.homepage = "http://www.rubyonrails.org"
s.add_dependency('actionpack', '= 2.0.991' + PKG_BUILD)
s.add_dependency('actionpack', '= 2.1.0' + PKG_BUILD)
s.has_rdoc = true
s.requirements << 'none'
......
module ActionMailer
module VERSION #:nodoc:
MAJOR = 2
MINOR = 0
TINY = 991
MINOR = 1
TINY = 0
STRING = [MAJOR, MINOR, TINY].join('.')
end
......
* InstanceTag#default_time_from_options overflows to DateTime [Geoff Buesing]
* Allow caches_action to accept a layout option [José Valim]
* Added Rack processor [Ezra Zygmuntowicz, Josh Peek]
*2.1.0 RC1 (May 11th, 2008)*
*2.1.0 (May 31st, 2008)*
* InstanceTag#default_time_from_options overflows to DateTime [Geoff Buesing]
* Fixed that forgery protection can be used without session tracking (Peter Jones) [#139]
......
......@@ -76,7 +76,7 @@ spec = Gem::Specification.new do |s|
s.has_rdoc = true
s.requirements << 'none'
s.add_dependency('activesupport', '= 2.0.991' + PKG_BUILD)
s.add_dependency('activesupport', '= 2.1.0' + PKG_BUILD)
s.require_path = 'lib'
s.autorequire = 'action_controller'
......
......@@ -53,6 +53,7 @@
require 'action_controller/session_management'
require 'action_controller/http_authentication'
require 'action_controller/components'
require 'action_controller/rack_process'
require 'action_controller/record_identifier'
require 'action_controller/request_forgery_protection'
require 'action_controller/headers'
......
......@@ -40,6 +40,8 @@ module Caching
# controller.send(:list_url, c.params[:id]) }
# end
#
# If you pass :layout => false, it will only cache your action content. It is useful when your layout has dynamic information.
#
module Actions
def self.included(base) #:nodoc:
base.extend(ClassMethods)
......@@ -54,7 +56,8 @@ module ClassMethods
def caches_action(*actions)
return unless cache_configured?
options = actions.extract_options!
around_filter(ActionCacheFilter.new(:cache_path => options.delete(:cache_path)), {:only => actions}.merge(options))
cache_filter = ActionCacheFilter.new(:layout => options.delete(:layout), :cache_path => options.delete(:cache_path))
around_filter(cache_filter, {:only => actions}.merge(options))
end
end
......@@ -81,7 +84,9 @@ def before(controller)
if cache = controller.read_fragment(cache_path.path)
controller.rendered_action_cache = true
set_content_type!(controller, cache_path.extension)
controller.send!(:render_for_text, cache)
options = { :text => cache }
options.merge!(:layout => true) if cache_layout?
controller.send!(:render, options)
false
else
controller.action_cache_path = cache_path
......@@ -90,7 +95,8 @@ def before(controller)
def after(controller)
return if controller.rendered_action_cache || !caching_allowed(controller)
controller.write_fragment(controller.action_cache_path.path, controller.response.body)
action_content = cache_layout? ? content_for_layout(controller) : controller.response.body
controller.write_fragment(controller.action_cache_path.path, action_content)
end
private
......@@ -105,6 +111,14 @@ def path_options_for(controller, options)
def caching_allowed(controller)
controller.request.get? && controller.response.headers['Status'].to_i == 200
end
def cache_layout?
@options[:layout] == false
end
def content_for_layout(controller)
controller.response.layout && controller.response.template.instance_variable_get('@content_for_layout')
end
end
class ActionCachePath
......
......@@ -96,7 +96,7 @@ def failsafe_logger
include ActiveSupport::Callbacks
define_callbacks :prepare_dispatch, :before_dispatch, :after_dispatch
def initialize(output, request = nil, response = nil)
def initialize(output = $stdout, request = nil, response = nil)
@output, @request, @response = output, request, response
end
......@@ -123,6 +123,12 @@ def dispatch_cgi(cgi, session_options)
failsafe_rescue exception
end
def call(env)
@request = RackRequest.new(env)
@response = RackResponse.new(@request)
dispatch
end
def reload_application
# Run prepare callbacks before every request in development mode
run_callbacks :prepare_dispatch
......@@ -135,7 +141,7 @@ def reload_application
# be reloaded on the next request without restarting the server.
def cleanup_application
ActiveRecord::Base.reset_subclasses if defined?(ActiveRecord)
Dependencies.clear
ActiveSupport::Dependencies.clear
ActiveRecord::Base.clear_reloadable_connections! if defined?(ActiveRecord)
end
......
require 'action_controller/cgi_ext'
require 'action_controller/session/cookie_store'
module ActionController #:nodoc:
class RackRequest < AbstractRequest #:nodoc:
attr_accessor :env, :session_options
attr_reader :cgi
class SessionFixationAttempt < StandardError #:nodoc:
end
DEFAULT_SESSION_OPTIONS = {
:database_manager => CGI::Session::CookieStore, # store data in cookie
:prefix => "ruby_sess.", # prefix session file names
:session_path => "/", # available to all paths in app
:session_key => "_session_id",
:cookie_only => true
} unless const_defined?(:DEFAULT_SESSION_OPTIONS)
def initialize(env, session_options = DEFAULT_SESSION_OPTIONS)
@session_options = session_options
@env = env
@cgi = CGIWrapper.new(self)
super()
end
# The request body is an IO input stream. If the RAW_POST_DATA environment
# variable is already set, wrap it in a StringIO.
def body
if raw_post = env['RAW_POST_DATA']
StringIO.new(raw_post)
else
@env['rack.input']
end
end
def key?(key)
@env.key? key
end
def query_parameters
@query_parameters ||= self.class.parse_query_parameters(query_string)
end
def request_parameters
@request_parameters ||= parse_formatted_request_parameters
end
def cookies
return {} unless @env["HTTP_COOKIE"]
if @env["rack.request.cookie_string"] == @env["HTTP_COOKIE"]
@env["rack.request.cookie_hash"]
else
@env["rack.request.cookie_string"] = @env["HTTP_COOKIE"]
# According to RFC 2109:
# If multiple cookies satisfy the criteria above, they are ordered in
# the Cookie header such that those with more specific Path attributes
# precede those with less specific. Ordering with respect to other
# attributes (e.g., Domain) is unspecified.
@env["rack.request.cookie_hash"] =
parse_query(@env["rack.request.cookie_string"], ';,').inject({}) { |h, (k,v)|
h[k] = Array === v ? v.first : v
h
}
end
end
def host_with_port_without_standard_port_handling
if forwarded = @env["HTTP_X_FORWARDED_HOST"]
forwarded.split(/,\s?/).last
elsif http_host = @env['HTTP_HOST']
http_host
elsif server_name = @env['SERVER_NAME']
server_name
else
"#{env['SERVER_ADDR']}:#{env['SERVER_PORT']}"
end
end
def host
host_with_port_without_standard_port_handling.sub(/:\d+$/, '')
end
def port
if host_with_port_without_standard_port_handling =~ /:(\d+)$/
$1.to_i
else
standard_port
end
end
def remote_addr
@env['REMOTE_ADDR']
end
def session
unless defined?(@session)
if @session_options == false
@session = Hash.new
else
stale_session_check! do
if cookie_only? && query_parameters[session_options_with_string_keys['session_key']]
raise SessionFixationAttempt
end
case value = session_options_with_string_keys['new_session']
when true
@session = new_session
when false
begin
@session = CGI::Session.new(@cgi, session_options_with_string_keys)
# CGI::Session raises ArgumentError if 'new_session' == false
# and no session cookie or query param is present.
rescue ArgumentError
@session = Hash.new
end
when nil
@session = CGI::Session.new(@cgi, session_options_with_string_keys)
else
raise ArgumentError, "Invalid new_session option: #{value}"
end
@session['__valid_session']
end
end
end
@session
end
def reset_session
@session.delete if defined?(@session) && @session.is_a?(CGI::Session)
@session = new_session
end
private
# Delete an old session if it exists then create a new one.
def new_session
if @session_options == false
Hash.new
else
CGI::Session.new(@cgi, session_options_with_string_keys.merge("new_session" => false)).delete rescue nil
CGI::Session.new(@cgi, session_options_with_string_keys.merge("new_session" => true))
end
end
def cookie_only?
session_options_with_string_keys['cookie_only']
end
def stale_session_check!
yield
rescue ArgumentError => argument_error
if argument_error.message =~ %r{undefined class/module ([\w:]*\w)}
begin
# Note that the regexp does not allow $1 to end with a ':'
$1.constantize
rescue LoadError, NameError => const_error
raise ActionController::SessionRestoreError, <<-end_msg
Session contains objects whose class definition isn\'t available.
Remember to require the classes for all objects kept in the session.
(Original exception: #{const_error.message} [#{const_error.class}])
end_msg
end
retry
else
raise
end
end
def session_options_with_string_keys
@session_options_with_string_keys ||= DEFAULT_SESSION_OPTIONS.merge(@session_options).stringify_keys
end
# From Rack::Utils
def parse_query(qs, d = '&;')
params = {}
(qs || '').split(/[#{d}] */n).inject(params) { |h,p|
k, v = unescape(p).split('=',2)
if cur = params[k]
if cur.class == Array
params[k] << v
else
params[k] = [cur, v]
end
else
params[k] = v
end
}
return params
end
def unescape(s)
s.tr('+', ' ').gsub(/((?:%[0-9a-fA-F]{2})+)/n){
[$1.delete('%')].pack('H*')
}
end
end
class RackResponse < AbstractResponse #:nodoc:
attr_accessor :status
def initialize(request)
@request = request
@writer = lambda { |x| @body << x }
@block = nil
super()
end
def out(output = $stdout, &block)
@block = block
normalize_headers(@headers)
if [204, 304].include?(@status.to_i)
@headers.delete "Content-Type"
[status.to_i, @headers.to_hash, []]
else
[status.to_i, @headers.to_hash, self]
end
end
alias to_a out
def each(&callback)
if @body.respond_to?(:call)
@writer = lambda { |x| callback.call(x) }
@body.call(self, self)
else
@body.each(&callback)
end
@writer = callback
@block.call(self) if @block
end
def write(str)
@writer.call str.to_s
str
end
def close
@body.close if @body.respond_to?(:close)
end
def empty?
@block == nil && @body.empty?
end
private
def normalize_headers(options = "text/html")
if options.is_a?(String)
headers['Content-Type'] = options unless headers['Content-Type']
else
headers['Content-Length'] = options.delete('Content-Length').to_s if options['Content-Length']
headers['Content-Type'] = options.delete('type') || "text/html"
headers['Content-Type'] += "; charset=" + options.delete('charset') if options['charset']
headers['Content-Language'] = options.delete('language') if options['language']
headers['Expires'] = options.delete('expires') if options['expires']
@status = options.delete('Status') if options['Status']
@status ||= 200
# Convert 'cookie' header to 'Set-Cookie' headers.
# Because Set-Cookie header can appear more the once in the response body,
# we store it in a line break seperated string that will be translated to
# multiple Set-Cookie header by the handler.
if cookie = options.delete('cookie')
cookies = []
case cookie
when Array then cookie.each { |c| cookies << c.to_s }
when Hash then cookie.each { |_, c| cookies << c.to_s }
else cookies << cookie.to_s
end
@request.cgi.output_cookies.each { |c| cookies << c.to_s } if @request.cgi.output_cookies
headers['Set-Cookie'] = [headers['Set-Cookie'], cookies].flatten.compact
end
options.each { |k,v| headers[k] = v }
end
""
end
end
class CGIWrapper < ::CGI
attr_reader :output_cookies
def initialize(request, *args)
@request = request
@args = *args
@input = request.body
super *args
end
def params
@params ||= @request.params
end
def cookies
@request.cookies
end
def query_string
@request.query_string
end
# Used to wrap the normal args variable used inside CGI.
def args
@args
end
# Used to wrap the normal env_table variable used inside CGI.
def env_table
@request.env
end
# Used to wrap the normal stdinput variable used inside CGI.
def stdinput
@input
end
end
end
......@@ -369,7 +369,7 @@ def controller_relative_to(controller, previous)
Routes = RouteSet.new
::Inflector.module_eval do
ActiveSupport::Inflector.module_eval do
# Ensures that routes are reloaded when Rails inflections are updated.
def inflections_with_route_reloading(&block)
returning(inflections_without_route_reloading(&block)) {
......
module ActionPack #:nodoc:
module VERSION #:nodoc:
MAJOR = 2
MINOR = 0
TINY = 991
MINOR = 1
TINY = 0
STRING = [MAJOR, MINOR, TINY].join('.')
end
......
......@@ -156,6 +156,7 @@ class ActionCachingTestController < ActionController::Base
caches_action :show, :cache_path => 'http://test.host/custom/show'
caches_action :edit, :cache_path => Proc.new { |c| c.params[:id] ? "http://test.host/#{c.params[:id]};edit" : "http://test.host/edit" }
caches_action :with_layout
caches_action :layout_false, :layout => false
layout 'talk_from_action.erb'
......@@ -181,6 +182,7 @@ def with_layout
alias_method :show, :index
alias_method :edit, :index
alias_method :destroy, :index
alias_method :layout_false, :with_layout
def expire
expire_action :controller => 'action_caching_test', :action => 'index'
......@@ -263,6 +265,19 @@ def test_action_cache_with_layout
assert_equal @response.body, read_fragment('hostname.com/action_caching_test/with_layout')
end
def test_action_cache_with_layout_and_layout_cache_false
get :layout_false
cached_time = content_to_cache
assert_not_equal cached_time, @response.body
assert fragment_exist?('hostname.com/action_caching_test/layout_false')
reset!
get :layout_false
assert_not_equal cached_time, @response.body
assert_equal cached_time, read_fragment('hostname.com/action_caching_test/layout_false')
end
def test_action_cache_conditional_options
@request.env['HTTP_ACCEPT'] = 'application/json'
get :index
......
......@@ -114,3 +114,36 @@ def test_body_should_be_rewound
assert_equal 0, request.body.pos
end
end
class CgiResponseTest < BaseCgiTest
def setup
super
@fake_cgi.expects(:header).returns("HTTP/1.0 200 OK\nContent-Type: text/html\n")
@response = ActionController::CgiResponse.new(@fake_cgi)
@output = StringIO.new('')
end
def test_simple_output
@response.body = "Hello, World!"
@response.out(@output)
assert_equal "HTTP/1.0 200 OK\nContent-Type: text/html\nHello, World!", @output.string
end
def test_head_request
@fake_cgi.env_table['REQUEST_METHOD'] = 'HEAD'
@response.body = "Hello, World!"
@response.out(@output)
assert_equal "HTTP/1.0 200 OK\nContent-Type: text/html\n", @output.string
end
def test_streaming_block
@response.body = Proc.new do |response, output|
5.times { |n| output.write(n) }
end
@response.out(@output)
assert_equal "HTTP/1.0 200 OK\nContent-Type: text/html\n01234", @output.string
end
end
......@@ -27,14 +27,14 @@ def teardown
def test_clears_dependencies_after_dispatch_if_in_loading_mode
ActionController::Routing::Routes.expects(:reload).once
Dependencies.expects(:clear).once
ActiveSupport::Dependencies.expects(:clear).once
dispatch(@output, false)
end
def test_leaves_dependencies_after_dispatch_if_not_in_loading_mode
ActionController::Routing::Routes.expects(:reload).never
Dependencies.expects(:clear).never
ActiveSupport::Dependencies.expects(:clear).never
dispatch
end
......
......@@ -28,7 +28,7 @@ class << self
# end
def test_post_with_upload
uses_mocha "test_post_with_upload" do
Dependencies.stubs(:load?).returns(false)
ActiveSupport::Dependencies.stubs(:load?).returns(false)
with_routing do |set|
set.draw do |map|
map.update 'update', :controller => "upload_test", :action => "update", :method => :post
......
require 'abstract_unit'
require 'action_controller/rack_process'
class BaseRackTest < Test::Unit::TestCase
def setup
@env = {
"HTTP_MAX_FORWARDS" => "10",
"SERVER_NAME" => "glu.ttono.us:8007",
"FCGI_ROLE" => "RESPONDER",
"HTTP_X_FORWARDED_HOST" => "glu.ttono.us",
"HTTP_ACCEPT_ENCODING" => "gzip, deflate",
"HTTP_USER_AGENT" => "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en)",
"PATH_INFO" => "",
"HTTP_ACCEPT_LANGUAGE" => "en",
"HTTP_HOST" => "glu.ttono.us:8007",
"SERVER_PROTOCOL" => "HTTP/1.1",
"REDIRECT_URI" => "/dispatch.fcgi",
"SCRIPT_NAME" => "/dispatch.fcgi",
"SERVER_ADDR" => "207.7.108.53",
"REMOTE_ADDR" => "207.7.108.53",
"SERVER_SOFTWARE" => "lighttpd/1.4.5",
"HTTP_COOKIE" => "_session_id=c84ace84796670c052c6ceb2451fb0f2; is_admin=yes",
"HTTP_X_FORWARDED_SERVER" => "glu.ttono.us",
"REQUEST_URI" => "/admin",
"DOCUMENT_ROOT" => "/home/kevinc/sites/typo/public",
"SERVER_PORT" => "8007",
"QUERY_STRING" => "",
"REMOTE_PORT" => "63137",
"GATEWAY_INTERFACE" => "CGI/1.1",
"HTTP_X_FORWARDED_FOR" => "65.88.180.234",
"HTTP_ACCEPT" => "*/*",
"SCRIPT_FILENAME" => "/home/kevinc/sites/typo/public/dispatch.fcgi",
"REDIRECT_STATUS" => "200",
"REQUEST_METHOD" => "GET"
}
# some Nokia phone browsers omit the space after the semicolon separator.
# some developers have grown accustomed to using comma in cookie values.
@alt_cookie_fmt_request_hash = {"HTTP_COOKIE"=>"_session_id=c84ace847,96670c052c6ceb2451fb0f2;is_admin=yes"}
@request = ActionController::RackRequest.new(@env)
end
def default_test; end
end
class RackRequestTest < BaseRackTest
def test_proxy_request
assert_equal 'glu.ttono.us', @request.host_with_port
end
def test_http_host
@env.delete "HTTP_X_FORWARDED_HOST"
@env['HTTP_HOST'] = "rubyonrails.org:8080"
assert_equal "rubyonrails.org:8080", @request.host_with_port
@env['HTTP_X_FORWARDED_HOST'] = "www.firsthost.org, www.secondhost.org"
assert_equal "www.secondhost.org", @request.host
end
def test_http_host_with_default_port_overrides_server_port
@env.delete "HTTP_X_FORWARDED_HOST"
@env['HTTP_HOST'] = "rubyonrails.org"
assert_equal "rubyonrails.org", @request.host_with_port
end
def test_host_with_port_defaults_to_server_name_if_no_host_headers
@env.delete "HTTP_X_FORWARDED_HOST"
@env.delete "HTTP_HOST"
assert_equal "glu.ttono.us:8007", @request.host_with_port
end
def test_host_with_port_falls_back_to_server_addr_if_necessary
@env.delete "HTTP_X_FORWARDED_HOST"
@env.delete "HTTP_HOST"
@env.delete "SERVER_NAME"
assert_equal "207.7.108.53:8007", @request.host_with_port
end
def test_host_with_port_if_http_standard_port_is_specified
@env['HTTP_X_FORWARDED_HOST'] = "glu.ttono.us:80"
assert_equal "glu.ttono.us", @request.host_with_port
end
def test_host_with_port_if_https_standard_port_is_specified
@env['HTTP_X_FORWARDED_PROTO'] = "https"
@env['HTTP_X_FORWARDED_HOST'] = "glu.ttono.us:443"
assert_equal "glu.ttono.us", @request.host_with_port
end
def test_host_if_ipv6_reference
@env.delete "HTTP_X_FORWARDED_HOST"
@env['HTTP_HOST'] = "[2001:1234:5678:9abc:def0::dead:beef]"
assert_equal "[2001:1234:5678:9abc:def0::dead:beef]", @request.host
end
def test_host_if_ipv6_reference_with_port
@env.delete "HTTP_X_FORWARDED_HOST"
@env['HTTP_HOST'] = "[2001:1234:5678:9abc:def0::dead:beef]:8008"
assert_equal "[2001:1234:5678:9abc:def0::dead:beef]", @request.host
end
def test_cookie_syntax_resilience
cookies = CGI::Cookie::parse(@env["HTTP_COOKIE"]);
assert_equal ["c84ace84796670c052c6ceb2451fb0f2"], cookies["_session_id"], cookies.inspect
assert_equal ["yes"], cookies["is_admin"], cookies.inspect
alt_cookies = CGI::Cookie::parse(@alt_cookie_fmt_request_hash["HTTP_COOKIE"]);
assert_equal ["c84ace847,96670c052c6ceb2451fb0f2"], alt_cookies["_session_id"], alt_cookies.inspect
assert_equal ["yes"], alt_cookies["is_admin"], alt_cookies.inspect
end
end
class RackRequestParamsParsingTest < BaseRackTest
def test_doesnt_break_when_content_type_has_charset
data = 'flamenco=love'
@request.env['CONTENT_LENGTH'] = data.length
@request.env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded; charset=utf-8'
@request.env['RAW_POST_DATA'] = data
assert_equal({"flamenco"=> "love"}, @request.request_parameters)
end
def test_doesnt_interpret_request_uri_as_query_string_when_missing
@request.env['REQUEST_URI'] = 'foo'
assert_equal({}, @request.query_parameters)
end
end
class RackRequestNeedsRewoundTest < BaseRackTest
def test_body_should_be_rewound
data = 'foo'
@env['rack.input'] = StringIO.new(data)
@env['CONTENT_LENGTH'] = data.length
@env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded; charset=utf-8'
# Read the request body by parsing params.
request = ActionController::RackRequest.new(@env)
request.request_parameters
# Should have rewound the body.
assert_equal 0, request.body.pos
end
end
class RackResponseTest < BaseRackTest
def setup
super
@response = ActionController::RackResponse.new(@request)
@output = StringIO.new('')
end
def test_simple_output
@response.body = "Hello, World!"
status, headers, body = @response.out(@output)
assert_equal 200, status
assert_equal({"Content-Type" => "text/html", "Cache-Control" => "no-cache", "Set-Cookie" => []}, headers)
parts = []
body.each { |part| parts << part }
assert_equal ["Hello, World!"], parts
end
def test_streaming_block
@response.body = Proc.new do |response, output|
5.times { |n| output.write(n) }
end
status, headers, body = @response.out(@output)
assert_equal 200, status
assert_equal({"Content-Type" => "text/html", "Cache-Control" => "no-cache", "Set-Cookie" => []}, headers)
parts = []
body.each { |part| parts << part }
assert_equal ["0", "1", "2", "3", "4"], parts
end
def test_set_session_cookie
cookie = CGI::Cookie.new({"name" => "name", "value" => "Josh"})
@request.cgi.send :instance_variable_set, '@output_cookies', [cookie]
@response.body = "Hello, World!"
status, headers, body = @response.out(@output)
assert_equal 200, status
assert_equal({
"Content-Type" => "text/html",
"Cache-Control" => "no-cache",
"Set-Cookie" => ["name=Josh; path="]
}, headers)
parts = []
body.each { |part| parts << part }
assert_equal ["Hello, World!"], parts
end
end
......@@ -2392,10 +2392,10 @@ def test_bang_forces_reload
end
def test_adding_inflections_forces_reload
Inflector::Inflections.instance.expects(:uncountable).with('equipment')
ActiveSupport::Inflector::Inflections.instance.expects(:uncountable).with('equipment')
routes.expects(:reload!)
Inflector.inflections { |inflect| inflect.uncountable('equipment') }
ActiveSupport::Inflector.inflections { |inflect| inflect.uncountable('equipment') }
end
def test_load_with_configuration
......
*Edge*
* Added SQL escaping for :limit and :offset in MySQL [Jonathan Wiess]
*2.1.0 (May 31st, 2008)*
* Add ActiveRecord::Base.sti_name that checks ActiveRecord::Base#store_full_sti_class? and returns either the full or demodulized name. [rick]
* Add first/last methods to associations/named_scope. Resolved #226. [Ryan Bates]
*2.1.0 RC1 (May 11th, 2008)*
* Added SQL escaping for :limit and :offset #288 [Aaron Bedra, Steven Bristol, Jonathan Wiess]
* Added first/last methods to associations/named_scope. Resolved #226. [Ryan Bates]
* Ensure hm:t preloading honours reflection options. Resolves #137. [Frederick Cheung]
......
......@@ -171,7 +171,7 @@ spec = Gem::Specification.new do |s|
s.files = s.files + Dir.glob( "#{dir}/**/*" ).delete_if { |item| item.include?( "\.svn" ) }
end
s.add_dependency('activesupport', '= 2.0.991' + PKG_BUILD)
s.add_dependency('activesupport', '= 2.1.0' + PKG_BUILD)
s.files.delete FIXTURES_ROOT + "/fixture_database.sqlite"
s.files.delete FIXTURES_ROOT + "/fixture_database_2.sqlite"
......
......@@ -237,7 +237,7 @@ def build_through_conditions
end
def build_sti_condition
"#{@reflection.through_reflection.quoted_table_name}.#{@reflection.through_reflection.klass.inheritance_column} = #{@reflection.klass.quote_value(@reflection.through_reflection.klass.name.demodulize)}"
"#{@reflection.through_reflection.quoted_table_name}.#{@reflection.through_reflection.klass.inheritance_column} = #{@reflection.klass.quote_value(@reflection.through_reflection.klass.sti_name)}"
end
alias_method :sql_conditions, :conditions
......
......@@ -372,7 +372,7 @@ def self.inherited(child) #:nodoc:
def self.reset_subclasses #:nodoc:
nonreloadables = []
subclasses.each do |klass|
unless Dependencies.autoloaded? klass
unless ActiveSupport::Dependencies.autoloaded? klass
nonreloadables << klass
next
end
......@@ -1293,6 +1293,10 @@ def respond_to?(method_id, include_private = false)
super
end
def sti_name
store_full_sti_class ? name : name.demodulize
end
private
def find_initial(options)
options.update(:limit => 1)
......@@ -1452,7 +1456,11 @@ def instantiate(record)
# Nest the type name in the same module as this class.
# Bar is "MyApp::Business::Bar" relative to MyApp::Business::Foo
def type_name_with_module(type_name)
(/^::/ =~ type_name) ? type_name : "#{parent.name}::#{type_name}"
if store_full_sti_class
type_name
else
(/^::/ =~ type_name) ? type_name : "#{parent.name}::#{type_name}"
end
end
def construct_finder_sql(options)
......@@ -1571,8 +1579,8 @@ def add_conditions!(sql, conditions, scope = :auto)
def type_condition
quoted_inheritance_column = connection.quote_column_name(inheritance_column)
type_condition = subclasses.inject("#{quoted_table_name}.#{quoted_inheritance_column} = '#{store_full_sti_class ? name : name.demodulize}' ") do |condition, subclass|
condition << "OR #{quoted_table_name}.#{quoted_inheritance_column} = '#{store_full_sti_class ? subclass.name : subclass.name.demodulize}' "
type_condition = subclasses.inject("#{quoted_table_name}.#{quoted_inheritance_column} = '#{sti_name}' ") do |condition, subclass|
condition << "OR #{quoted_table_name}.#{quoted_inheritance_column} = '#{subclass.sti_name}' "
end
" (#{type_condition}) "
......@@ -2508,7 +2516,7 @@ def create
# Message class in that example.
def ensure_proper_type
unless self.class.descends_from_active_record?
write_attribute(self.class.inheritance_column, store_full_sti_class ? self.class.name : self.class.name.demodulize)
write_attribute(self.class.inheritance_column, self.class.sti_name)
end
end
......
......@@ -71,7 +71,7 @@ def maximum(column_name, options = {})
#
# Person.sum('age')
def sum(column_name, options = {})
calculate(:sum, column_name, options) || 0
calculate(:sum, column_name, options)
end
# This calculates aggregate values in the given column. Methods for count, sum, average, minimum, and maximum have been added as shortcuts.
......@@ -266,6 +266,7 @@ def type_cast_calculated_value(value, column, operation = nil)
operation = operation.to_s.downcase
case operation
when 'count' then value.to_i
when 'sum' then value =~ /\./ ? value.to_f : value.to_i
when 'avg' then value && value.to_f
else column ? column.type_cast(value) : value
end
......
......@@ -293,14 +293,14 @@ def destroy_with_callbacks #:nodoc:
private
def callback(method)
notify(method)
result = run_callbacks(method) { |result, object| result == false }
if result != false && respond_to_without_attributes?(method)
result = send(method)
end
notify(method)
return result
end
......
......@@ -106,11 +106,16 @@ def add_limit!(sql, options)
# SELECT * FROM suppliers LIMIT 10 OFFSET 50
def add_limit_offset!(sql, options)
if limit = options[:limit]
sql << " LIMIT #{limit}"
sql << " LIMIT #{sanitize_limit(limit)}"
if offset = options[:offset]
sql << " OFFSET #{offset}"
sql << " OFFSET #{offset.to_i}"
end
end
sql
end
def sanitize_limit(limit)
limit.to_s[/,/] ? limit.split(',').map{ |i| i.to_i }.join(',') : limit.to_i
end
# Appends a locking clause to an SQL statement.
......
......@@ -336,10 +336,11 @@ def rollback_db_transaction #:nodoc:
def add_limit_offset!(sql, options) #:nodoc:
if limit = options[:limit]
limit = sanitize_limit(limit)
unless offset = options[:offset]
sql << " LIMIT #{limit}"
else
sql << " LIMIT #{offset}, #{limit}"
sql << " LIMIT #{offset.to_i}, #{limit}"
end
end
end
......
module ActiveRecord
module VERSION #:nodoc:
MAJOR = 2
MINOR = 0
TINY = 991
MINOR = 1
TINY = 0
STRING = [MAJOR, MINOR, TINY].join('.')
end
......
......@@ -104,4 +104,24 @@ def test_reset_table_with_non_integer_pk
end
end
def test_add_limit_offset_should_sanitize_sql_injection_for_limit_without_comas
sql_inject = "1 select * from schema"
assert_equal " LIMIT 1", @connection.add_limit_offset!("", :limit=>sql_inject)
if current_adapter?(:MysqlAdapter)
assert_equal " LIMIT 7, 1", @connection.add_limit_offset!("", :limit=>sql_inject, :offset=>7)
else
assert_equal " LIMIT 1 OFFSET 7", @connection.add_limit_offset!("", :limit=>sql_inject, :offset=>7)
end
end
def test_add_limit_offset_should_sanitize_sql_injection_for_limit_with_comas
sql_inject = "1, 7 procedure help()"
if current_adapter?(:MysqlAdapter)
assert_equal " LIMIT 1,7", @connection.add_limit_offset!("", :limit=>sql_inject)
assert_equal " LIMIT 7, 1", @connection.add_limit_offset!("", :limit=> '1 ; DROP TABLE USERS', :offset=>7)
else
assert_equal " LIMIT 1,7", @connection.add_limit_offset!("", :limit=>sql_inject)
assert_equal " LIMIT 1,7 OFFSET 7", @connection.add_limit_offset!("", :limit=>sql_inject, :offset=>7)
end
end
end
......@@ -137,7 +137,7 @@ def test_accessing_cached_attributes_caches_the_converted_values_and_nothing_els
end
end
end
def test_time_attributes_are_retrieved_in_current_time_zone
in_time_zone "Pacific Time (US & Canada)" do
utc_time = Time.utc(2008, 1, 1)
......@@ -145,7 +145,7 @@ def test_time_attributes_are_retrieved_in_current_time_zone
record[:written_on] = utc_time
assert_equal utc_time, record.written_on # record.written on is equal to (i.e., simultaneous with) utc_time
assert_kind_of ActiveSupport::TimeWithZone, record.written_on # but is a TimeWithZone
assert_equal TimeZone["Pacific Time (US & Canada)"], record.written_on.time_zone # and is in the current Time.zone
assert_equal ActiveSupport::TimeZone["Pacific Time (US & Canada)"], record.written_on.time_zone # and is in the current Time.zone
assert_equal Time.utc(2007, 12, 31, 16), record.written_on.time # and represents time values adjusted accordingly
end
end
......@@ -156,7 +156,7 @@ def test_setting_time_zone_aware_attribute_to_utc
record = @target.new
record.written_on = utc_time
assert_equal utc_time, record.written_on
assert_equal TimeZone["Pacific Time (US & Canada)"], record.written_on.time_zone
assert_equal ActiveSupport::TimeZone["Pacific Time (US & Canada)"], record.written_on.time_zone
assert_equal Time.utc(2007, 12, 31, 16), record.written_on.time
end
end
......@@ -168,7 +168,7 @@ def test_setting_time_zone_aware_attribute_in_other_time_zone
record = @target.new
record.written_on = cst_time
assert_equal utc_time, record.written_on
assert_equal TimeZone["Pacific Time (US & Canada)"], record.written_on.time_zone
assert_equal ActiveSupport::TimeZone["Pacific Time (US & Canada)"], record.written_on.time_zone
assert_equal Time.utc(2007, 12, 31, 16), record.written_on.time
end
end
......@@ -181,12 +181,12 @@ def test_setting_time_zone_aware_attribute_with_string
record = @target.new
record.written_on = time_string
assert_equal Time.zone.parse(time_string), record.written_on
assert_equal TimeZone["Pacific Time (US & Canada)"], record.written_on.time_zone
assert_equal ActiveSupport::TimeZone["Pacific Time (US & Canada)"], record.written_on.time_zone
assert_equal Time.utc(2007, 12, 31, 16), record.written_on.time
end
end
end
def test_setting_time_zone_aware_attribute_to_blank_string_returns_nil
in_time_zone "Pacific Time (US & Canada)" do
record = @target.new
......@@ -202,7 +202,7 @@ def test_setting_time_zone_aware_attribute_interprets_time_zone_unaware_string_i
record = @target.new
record.written_on = time_string
assert_equal Time.zone.parse(time_string), record.written_on
assert_equal TimeZone[timezone_offset], record.written_on.time_zone
assert_equal ActiveSupport::TimeZone[timezone_offset], record.written_on.time_zone
assert_equal Time.utc(2008, 1, 1), record.written_on.time
end
end
......@@ -214,7 +214,7 @@ def test_setting_time_zone_aware_attribute_in_current_time_zone
record = @target.new
record.written_on = utc_time.in_time_zone
assert_equal utc_time, record.written_on
assert_equal TimeZone["Pacific Time (US & Canada)"], record.written_on.time_zone
assert_equal ActiveSupport::TimeZone["Pacific Time (US & Canada)"], record.written_on.time_zone
assert_equal Time.utc(2007, 12, 31, 16), record.written_on.time
end
end
......@@ -223,12 +223,12 @@ def test_setting_time_zone_aware_attribute_in_current_time_zone
def time_related_columns_on_topic
Topic.columns.select{|c| [:time, :date, :datetime, :timestamp].include?(c.type)}.map(&:name)
end
def in_time_zone(zone)
old_zone = Time.zone
old_tz = ActiveRecord::Base.time_zone_aware_attributes
Time.zone = zone ? TimeZone[zone] : nil
Time.zone = zone ? ActiveSupport::TimeZone[zone] : nil
ActiveRecord::Base.time_zone_aware_attributes = !zone.nil?
yield
ensure
......
......@@ -133,19 +133,19 @@ def test_read_attributes_before_type_cast
category_attrs = {"name"=>"Test categoty", "type" => nil}
assert_equal category_attrs , category.attributes_before_type_cast
end
if current_adapter?(:MysqlAdapter)
def test_read_attributes_before_type_cast_on_boolean
bool = Booleantest.create({ "value" => false })
assert_equal 0, bool.attributes_before_type_cast["value"]
end
end
def test_read_attributes_before_type_cast_on_datetime
developer = Developer.find(:first)
assert_equal developer.created_at.to_s(:db) , developer.attributes_before_type_cast["created_at"]
end
def test_hash_content
topic = Topic.new
topic.content = { "one" => 1, "two" => 2 }
......@@ -251,7 +251,7 @@ def test_create_through_factory
topic = Topic.create("title" => "New Topic")
topicReloaded = Topic.find(topic.id)
assert_equal(topic, topicReloaded)
end
end
def test_create_through_factory_with_block
topic = Topic.create("title" => "New Topic") do |t|
......@@ -576,7 +576,7 @@ def test_table_name_guesses
def test_destroy_all
original_count = Topic.count
topics_by_mary = Topic.count(:conditions => mary = "author_name = 'Mary'")
Topic.destroy_all mary
assert_equal original_count - topics_by_mary, Topic.count
end
......@@ -665,7 +665,7 @@ def test_update_many
def test_delete_all
assert Topic.count > 0
assert_equal Topic.count, Topic.delete_all
end
......@@ -970,7 +970,7 @@ def test_multiparameter_attributes_on_time
topic.attributes = attributes
assert_equal Time.local(2004, 6, 24, 16, 24, 0), topic.written_on
end
def test_multiparameter_attributes_on_time_with_old_date
attributes = {
"written_on(1i)" => "1850", "written_on(2i)" => "6", "written_on(3i)" => "24",
......@@ -998,7 +998,7 @@ def test_multiparameter_attributes_on_time_with_utc
def test_multiparameter_attributes_on_time_with_time_zone_aware_attributes
ActiveRecord::Base.time_zone_aware_attributes = true
ActiveRecord::Base.default_timezone = :utc
Time.zone = TimeZone[-28800]
Time.zone = ActiveSupport::TimeZone[-28800]
attributes = {
"written_on(1i)" => "2004", "written_on(2i)" => "6", "written_on(3i)" => "24",
"written_on(4i)" => "16", "written_on(5i)" => "24", "written_on(6i)" => "00"
......@@ -1016,7 +1016,7 @@ def test_multiparameter_attributes_on_time_with_time_zone_aware_attributes
def test_multiparameter_attributes_on_time_with_time_zone_aware_attributes_false
ActiveRecord::Base.time_zone_aware_attributes = false
Time.zone = TimeZone[-28800]
Time.zone = ActiveSupport::TimeZone[-28800]
attributes = {
"written_on(1i)" => "2004", "written_on(2i)" => "6", "written_on(3i)" => "24",
"written_on(4i)" => "16", "written_on(5i)" => "24", "written_on(6i)" => "00"
......@@ -1032,7 +1032,7 @@ def test_multiparameter_attributes_on_time_with_time_zone_aware_attributes_false
def test_multiparameter_attributes_on_time_with_skip_time_zone_conversion_for_attributes
ActiveRecord::Base.time_zone_aware_attributes = true
ActiveRecord::Base.default_timezone = :utc
Time.zone = TimeZone[-28800]
Time.zone = ActiveSupport::TimeZone[-28800]
Topic.skip_time_zone_conversion_for_attributes = [:written_on]
attributes = {
"written_on(1i)" => "2004", "written_on(2i)" => "6", "written_on(3i)" => "24",
......@@ -1647,7 +1647,7 @@ def test_find_last
last = Developer.find :last
assert_equal last, Developer.find(:first, :order => 'id desc')
end
def test_last
assert_equal Developer.find(:first, :order => 'id desc'), Developer.last
end
......@@ -1655,7 +1655,7 @@ def test_last
def test_all_with_conditions
assert_equal Developer.find(:all, :order => 'id desc'), Developer.all(:order => 'id desc')
end
def test_find_ordered_last
last = Developer.find :last, :order => 'developers.salary ASC'
assert_equal last, Developer.find(:all, :order => 'developers.salary ASC').last
......@@ -1670,14 +1670,14 @@ def test_find_multiple_ordered_last
last = Developer.find :last, :order => 'developers.name, developers.salary DESC'
assert_equal last, Developer.find(:all, :order => 'developers.name, developers.salary DESC').last
end
def test_find_scoped_ordered_last
last_developer = Developer.with_scope(:find => { :order => 'developers.salary ASC' }) do
Developer.find(:last)
end
assert_equal last_developer, Developer.find(:all, :order => 'developers.salary ASC').last
end
def test_abstract_class
assert !ActiveRecord::Base.abstract_class?
assert LoosePerson.abstract_class?
......
......@@ -99,6 +99,12 @@ def test_should_sum_field_with_conditions
def test_should_return_zero_if_sum_conditions_return_nothing
assert_equal 0, Account.sum(:credit_limit, :conditions => '1 = 2')
assert_equal 0, companies(:rails_core).companies.sum(:id, :conditions => '1 = 2')
end
def test_sum_should_return_valid_values_for_decimals
NumericData.create(:bank_balance => 19.83)
assert_equal 19.83, NumericData.sum(:bank_balance)
end
def test_should_group_by_summed_field_with_conditions
......@@ -266,6 +272,6 @@ def test_count_with_too_many_parameters_raises
end
def test_should_sum_expression
assert_equal "636", Account.sum("2 * credit_limit")
assert_equal 636, Account.sum("2 * credit_limit")
end
end
require "cases/helper"
class Comment < ActiveRecord::Base
attr_accessor :callers
before_validation :record_callers
def after_validation
record_callers
end
def record_callers
callers << self.class if callers
end
end
class CommentObserver < ActiveRecord::Observer
attr_accessor :callers
def after_validation(model)
callers << self.class if callers
end
end
class CallbacksObserversTest < ActiveRecord::TestCase
def test_model_callbacks_fire_before_observers_are_notified
callers = []
comment = Comment.new
comment.callers = callers
CommentObserver.instance.callers = callers
comment.valid?
assert_equal [Comment, Comment, CommentObserver], callers, "model callbacks did not fire before observers were notified"
end
end
......@@ -5,7 +5,23 @@
class InheritanceTest < ActiveRecord::TestCase
fixtures :companies, :projects, :subscribers, :accounts
def test_class_with_store_full_sti_class_returns_full_name
old = ActiveRecord::Base.store_full_sti_class
ActiveRecord::Base.store_full_sti_class = true
assert_equal 'Namespaced::Company', Namespaced::Company.sti_name
ensure
ActiveRecord::Base.store_full_sti_class = old
end
def test_class_without_store_full_sti_class_returns_demodulized_name
old = ActiveRecord::Base.store_full_sti_class
ActiveRecord::Base.store_full_sti_class = false
assert_equal 'Company', Namespaced::Company.sti_name
ensure
ActiveRecord::Base.store_full_sti_class = old
end
def test_should_store_demodulized_class_name_with_store_full_sti_class_option_disabled
old = ActiveRecord::Base.store_full_sti_class
ActiveRecord::Base.store_full_sti_class = false
......@@ -207,11 +223,11 @@ class InheritanceComputeTypeTest < ActiveRecord::TestCase
fixtures :companies
def setup
Dependencies.log_activity = true
ActiveSupport::Dependencies.log_activity = true
end
def teardown
Dependencies.log_activity = false
ActiveSupport::Dependencies.log_activity = false
self.class.const_remove :FirmOnTheFly rescue nil
Firm.const_remove :FirmOnTheFly rescue nil
end
......
......@@ -51,7 +51,7 @@ def test_associations
def test_course_connection_should_survive_dependency_reload
assert Course.connection
Dependencies.clear
ActiveSupport::Dependencies.clear
Object.send(:remove_const, :Course)
require_dependency 'models/course'
......
*2.1.0 RC1 (May 11th, 2008)*
*Edge*
* Fixed Base#exists? to check status code as integer [#299 state:resolved] (Wes Oldenbeuving)
*2.1.0 (May 31st, 2008)*
* Fixed response logging to use length instead of the entire thing (seangeo) [#27]
......
......@@ -64,7 +64,7 @@ spec = Gem::Specification.new do |s|
s.files = s.files + Dir.glob( "#{dir}/**/*" ).delete_if { |item| item.include?( "\.svn" ) }
end
s.add_dependency('activesupport', '= 2.0.991' + PKG_BUILD)
s.add_dependency('activesupport', '= 2.1.0' + PKG_BUILD)
s.require_path = 'lib'
s.autorequire = 'active_resource'
......
......@@ -538,7 +538,7 @@ def exists?(id, options = {})
prefix_options, query_options = split_options(options[:params])
path = element_path(id, prefix_options, query_options)
response = connection.head(path, headers)
response.code == 200
response.code.to_i == 200
end
# id && !find_single(id, options).nil?
rescue ActiveResource::ResourceNotFound
......
module ActiveResource
module VERSION #:nodoc:
MAJOR = 2
MINOR = 0
TINY = 991
MINOR = 1
TINY = 0
STRING = [MAJOR, MINOR, TINY].join('.')
end
......
*Edge*
* Add more standard Hash methods to ActiveSupport::OrderedHash [Steve Purcell]
* Namespace Inflector, Dependencies, OrderedOptions, and TimeZone under ActiveSupport [Josh Peek]
* Added StringQuestioneer for doing things like StringQuestioneer.new("production").production? # => true and StringQuestioneer.new("production").development? # => false [DHH]
* Fixed Date#end_of_quarter to not blow up on May 31st [#289 state:resolved] (Danger)
*2.1.0 (May 31st, 2008)*
* TimeZone#to_s shows offset as GMT instead of UTC, because GMT will be more familiar to end users (see time zone selects used by Windows OS, google.com and yahoo.com.) Reverts [8370] [Geoff Buesing]
* Hash.from_xml: datetime xml types overflow to Ruby DateTime class when out of range of Time. Adding tests for utc offsets [Geoff Buesing]
......@@ -6,8 +19,6 @@
* Time#to_json: don't convert to utc before encoding. References #175 [Geoff Buesing]
*2.1.0 RC1 (May 11th, 2008)*
* Remove unused JSON::RESERVED_WORDS, JSON.valid_identifier? and JSON.reserved_word? methods. Resolves #164. [Cheah Chu Yeow]
* Adding Date.current, which returns Time.zone.today if config.time_zone is set; otherwise returns Date.today [Geoff Buesing]
......@@ -166,7 +177,6 @@
* Introduce ActiveSupport::TimeWithZone, for wrapping Time instances with a TimeZone. Introduce instance methods to Time for creating TimeWithZone instances, and class methods for managing a global time zone. [Geoff Buesing]
>>>>>>> .r8815
* Replace non-dst-aware TimeZone class with dst-aware class from tzinfo_timezone plugin. TimeZone#adjust and #unadjust are no longer available; tzinfo gem must now be present in order to perform time zone calculations, via #local_to_utc and #utc_to_local methods. [Geoff Buesing]
* Extract ActiveSupport::Callbacks from Active Record, test case setup and teardown, and ActionController::Dispatcher. #10727 [Josh Peek]
......
......@@ -43,6 +43,8 @@
require 'active_support/ordered_options'
require 'active_support/option_merger'
require 'active_support/string_questioneer'
require 'active_support/values/time_zone'
require 'active_support/duration'
......@@ -53,3 +55,7 @@
require 'active_support/base64'
require 'active_support/time_with_zone'
Inflector = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('Inflector', 'ActiveSupport::Inflector')
Dependencies = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('Dependencies', 'ActiveSupport::Dependencies')
TimeZone = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('TimeZone', 'ActiveSupport::TimeZone')
......@@ -184,7 +184,7 @@ def beginning_of_quarter
# Returns a new Date/DateTime representing the end of the quarter (last day of march, june, september, december; DateTime objects will have time set to 23:59:59)
def end_of_quarter
change(:month => [3, 6, 9, 12].detect { |m| m >= self.month }).end_of_month
beginning_of_month.change(:month => [3, 6, 9, 12].detect { |m| m >= self.month }).end_of_month
end
alias :at_end_of_quarter :end_of_quarter
......
......@@ -15,7 +15,9 @@ module Slice
# Returns a new hash with only the given keys.
def slice(*keys)
allowed = Set.new(respond_to?(:convert_key) ? keys.map { |key| convert_key(key) } : keys)
reject { |key,| !allowed.include?(key) }
hash = {}
allowed.each { |k| hash[k] = self[k] if has_key?(k) }
hash
end
# Replaces the hash with only the given keys.
......
......@@ -144,17 +144,11 @@ def collect_deprecations
end
end
# Stand-in for <tt>@request</tt>, <tt>@attributes</tt>, <tt>@params</tt>, etc.
# which emits deprecation warnings on any method call (except +inspect+).
class DeprecatedInstanceVariableProxy #:nodoc:
class DeprecationProxy #:nodoc:
silence_warnings do
instance_methods.each { |m| undef_method m unless m =~ /^__/ }
end
def initialize(instance, method, var = "@#{method}")
@instance, @method, @var = instance, method, var
end
# Don't give a deprecation warning on inspect since test/unit and error
# logs rely on it for diagnostics.
def inspect
......@@ -166,7 +160,16 @@ def method_missing(called, *args, &block)
warn caller, called, args
target.__send__(called, *args, &block)
end
end
# Stand-in for <tt>@request</tt>, <tt>@attributes</tt>, <tt>@params</tt>, etc.
# which emits deprecation warnings on any method call (except +inspect+).
class DeprecatedInstanceVariableProxy < DeprecationProxy #:nodoc:
def initialize(instance, method, var = "@#{method}")
@instance, @method, @var = instance, method, var
end
private
def target
@instance.__send__(@method)
end
......@@ -176,6 +179,21 @@ def warn(callstack, called, args)
end
end
class DeprecatedConstantProxy < DeprecationProxy #:nodoc:
def initialize(old_const, new_const)
@old_const = old_const
@new_const = new_const
end
private
def target
@new_const.to_s.constantize
end
def warn(callstack, called, args)
ActiveSupport::Deprecation.warn("#{@old_const} is deprecated! Use #{@new_const} instead.", callstack)
end
end
end
end
......
Inflector.inflections do |inflect|
inflect.plural(/$/, 's')
inflect.plural(/s$/i, 's')
inflect.plural(/(ax|test)is$/i, '\1es')
inflect.plural(/(octop|vir)us$/i, '\1i')
inflect.plural(/(alias|status)$/i, '\1es')
inflect.plural(/(bu)s$/i, '\1ses')
inflect.plural(/(buffal|tomat)o$/i, '\1oes')
inflect.plural(/([ti])um$/i, '\1a')
inflect.plural(/sis$/i, 'ses')
inflect.plural(/(?:([^f])fe|([lr])f)$/i, '\1\2ves')
inflect.plural(/(hive)$/i, '\1s')
inflect.plural(/([^aeiouy]|qu)y$/i, '\1ies')
inflect.plural(/(x|ch|ss|sh)$/i, '\1es')
inflect.plural(/(matr|vert|ind)(?:ix|ex)$/i, '\1ices')
inflect.plural(/([m|l])ouse$/i, '\1ice')
inflect.plural(/^(ox)$/i, '\1en')
inflect.plural(/(quiz)$/i, '\1zes')
module ActiveSupport
Inflector.inflections do |inflect|
inflect.plural(/$/, 's')
inflect.plural(/s$/i, 's')
inflect.plural(/(ax|test)is$/i, '\1es')
inflect.plural(/(octop|vir)us$/i, '\1i')
inflect.plural(/(alias|status)$/i, '\1es')
inflect.plural(/(bu)s$/i, '\1ses')
inflect.plural(/(buffal|tomat)o$/i, '\1oes')
inflect.plural(/([ti])um$/i, '\1a')
inflect.plural(/sis$/i, 'ses')
inflect.plural(/(?:([^f])fe|([lr])f)$/i, '\1\2ves')
inflect.plural(/(hive)$/i, '\1s')
inflect.plural(/([^aeiouy]|qu)y$/i, '\1ies')
inflect.plural(/(x|ch|ss|sh)$/i, '\1es')
inflect.plural(/(matr|vert|ind)(?:ix|ex)$/i, '\1ices')
inflect.plural(/([m|l])ouse$/i, '\1ice')
inflect.plural(/^(ox)$/i, '\1en')
inflect.plural(/(quiz)$/i, '\1zes')
inflect.singular(/s$/i, '')
inflect.singular(/(n)ews$/i, '\1ews')
inflect.singular(/([ti])a$/i, '\1um')
inflect.singular(/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i, '\1\2sis')
inflect.singular(/(^analy)ses$/i, '\1sis')
inflect.singular(/([^f])ves$/i, '\1fe')
inflect.singular(/(hive)s$/i, '\1')
inflect.singular(/(tive)s$/i, '\1')
inflect.singular(/([lr])ves$/i, '\1f')
inflect.singular(/([^aeiouy]|qu)ies$/i, '\1y')
inflect.singular(/(s)eries$/i, '\1eries')
inflect.singular(/(m)ovies$/i, '\1ovie')
inflect.singular(/(x|ch|ss|sh)es$/i, '\1')
inflect.singular(/([m|l])ice$/i, '\1ouse')
inflect.singular(/(bus)es$/i, '\1')
inflect.singular(/(o)es$/i, '\1')
inflect.singular(/(shoe)s$/i, '\1')
inflect.singular(/(cris|ax|test)es$/i, '\1is')
inflect.singular(/(octop|vir)i$/i, '\1us')
inflect.singular(/(alias|status)es$/i, '\1')
inflect.singular(/^(ox)en/i, '\1')
inflect.singular(/(vert|ind)ices$/i, '\1ex')
inflect.singular(/(matr)ices$/i, '\1ix')
inflect.singular(/(quiz)zes$/i, '\1')
inflect.singular(/s$/i, '')
inflect.singular(/(n)ews$/i, '\1ews')
inflect.singular(/([ti])a$/i, '\1um')
inflect.singular(/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i, '\1\2sis')
inflect.singular(/(^analy)ses$/i, '\1sis')
inflect.singular(/([^f])ves$/i, '\1fe')
inflect.singular(/(hive)s$/i, '\1')
inflect.singular(/(tive)s$/i, '\1')
inflect.singular(/([lr])ves$/i, '\1f')
inflect.singular(/([^aeiouy]|qu)ies$/i, '\1y')
inflect.singular(/(s)eries$/i, '\1eries')
inflect.singular(/(m)ovies$/i, '\1ovie')
inflect.singular(/(x|ch|ss|sh)es$/i, '\1')
inflect.singular(/([m|l])ice$/i, '\1ouse')
inflect.singular(/(bus)es$/i, '\1')
inflect.singular(/(o)es$/i, '\1')
inflect.singular(/(shoe)s$/i, '\1')
inflect.singular(/(cris|ax|test)es$/i, '\1is')
inflect.singular(/(octop|vir)i$/i, '\1us')
inflect.singular(/(alias|status)es$/i, '\1')
inflect.singular(/^(ox)en/i, '\1')
inflect.singular(/(vert|ind)ices$/i, '\1ex')
inflect.singular(/(matr)ices$/i, '\1ix')
inflect.singular(/(quiz)zes$/i, '\1')
inflect.irregular('person', 'people')
inflect.irregular('man', 'men')
inflect.irregular('child', 'children')
inflect.irregular('sex', 'sexes')
inflect.irregular('move', 'moves')
inflect.irregular('cow', 'kine')
inflect.irregular('person', 'people')
inflect.irregular('man', 'men')
inflect.irregular('child', 'children')
inflect.irregular('sex', 'sexes')
inflect.irregular('move', 'moves')
inflect.irregular('cow', 'kine')
inflect.uncountable(%w(equipment information rice money species series fish sheep))
inflect.uncountable(%w(equipment information rice money species series fish sheep))
end
end
......@@ -38,6 +38,20 @@ def to_hash
each { |array| hash[array[0]] = array[1] }
end
end
def has_key?(k)
!assoc(k).nil?
end
alias_method :key?, :has_key?
alias_method :include?, :has_key?
alias_method :member?, :has_key?
def has_value?(v)
any? { |key, value| value == v }
end
alias_method :value?, :has_value?
end
end
end
class OrderedOptions < ActiveSupport::OrderedHash #:nodoc:
def []=(key, value)
super(key.to_sym, value)
end
module ActiveSupport #:nodoc:
class OrderedOptions < OrderedHash #:nodoc:
def []=(key, value)
super(key.to_sym, value)
end
def [](key)
super(key.to_sym)
end
def [](key)
super(key.to_sym)
end
def method_missing(name, *args)
if name.to_s =~ /(.*)=$/
self[$1.to_sym] = args.first
else
self[name]
def method_missing(name, *args)
if name.to_s =~ /(.*)=$/
self[$1.to_sym] = args.first
else
self[name]
end
end
end
end
class StringQuestioneer < String
def method_missing(method_name, *arguments)
if method_name.to_s.ends_with?("?")
self == method_name.to_s[0..-2]
else
super
end
end
end
\ No newline at end of file
module ActiveSupport
module VERSION #:nodoc:
MAJOR = 2
MINOR = 0
TINY = 991
MINOR = 1
TINY = 0
STRING = [MAJOR, MINOR, TINY].join('.')
end
......
......@@ -21,7 +21,7 @@ def to_param
"#{self}1"
end
end
def test_string_array
assert_equal '', %w().to_param
assert_equal 'hello/world', %w(hello world).to_param
......@@ -31,7 +31,7 @@ def test_string_array
def test_number_array
assert_equal '10/20', [10, 20].to_param
end
def test_to_param_array
assert_equal 'custom1/param1', [ToParam.new('custom'), ToParam.new('param')].to_param
end
......@@ -222,6 +222,11 @@ def test_to_xml_with_block
assert xml.include?(%(<count>2</count>)), xml
end
def test_to_xml_with_empty
xml = [].to_xml
assert_match(/type="array"\/>/, xml)
end
end
class ArrayExtractOptionsTests < Test::Unit::TestCase
......@@ -234,17 +239,15 @@ def test_extract_options
end
uses_mocha "ArrayExtRandomTests" do
class ArrayExtRandomTests < Test::Unit::TestCase
def test_random_element_from_array
assert_nil [].rand
class ArrayExtRandomTests < Test::Unit::TestCase
def test_random_element_from_array
assert_nil [].rand
Kernel.expects(:rand).with(1).returns(0)
assert_equal 'x', ['x'].rand
Kernel.expects(:rand).with(1).returns(0)
assert_equal 'x', ['x'].rand
Kernel.expects(:rand).with(3).returns(1)
assert_equal 2, [1, 2, 3].rand
Kernel.expects(:rand).with(3).returns(1)
assert_equal 2, [1, 2, 3].rand
end
end
end
end
......@@ -5,5 +5,6 @@ def test_to_yaml
assert_equal("--- 100000.30020320320000000000000000000000000000001\n", BigDecimal.new('100000.30020320320000000000000000000000000000001').to_yaml)
assert_equal("--- .Inf\n", BigDecimal.new('Infinity').to_yaml)
assert_equal("--- .NaN\n", BigDecimal.new('NaN').to_yaml)
assert_equal("--- -.Inf\n", BigDecimal.new('-Infinity').to_yaml)
end
end
\ No newline at end of file
......@@ -76,6 +76,7 @@ def test_end_of_quarter
assert_equal Date.new(2008,3,31), Date.new(2008,3,31).end_of_quarter
assert_equal Date.new(2008,12,31), Date.new(2008,10,8).end_of_quarter
assert_equal Date.new(2008,6,30), Date.new(2008,4,14).end_of_quarter
assert_equal Date.new(2008,6,30), Date.new(2008,5,31).end_of_quarter
assert_equal Date.new(2008,9,30), Date.new(2008,8,21).end_of_quarter
end
......@@ -171,7 +172,7 @@ def test_next_month_on_31st
def test_last_month_on_31st
assert_equal Date.new(2004, 2, 29), Date.new(2004, 3, 31).last_month
end
end
def test_yesterday_constructor
assert_equal Date.today - 1, Date.yesterday
......@@ -196,7 +197,11 @@ def test_beginning_of_day
def test_end_of_day
assert_equal Time.local(2005,2,21,23,59,59), Date.new(2005,2,21).end_of_day
end
def test_date_acts_like_date
assert Date.new.acts_like_date?
end
def test_xmlschema
with_env_tz 'US/Eastern' do
assert_match(/^1980-02-28T00:00:00-05:?00$/, Date.new(1980, 2, 28).xmlschema)
......@@ -208,7 +213,7 @@ def test_xmlschema
end
end
end
uses_mocha 'TestDateCurrent' do
def test_current_returns_date_today_when_zone_default_not_set
with_env_tz 'US/Central' do
......@@ -217,10 +222,10 @@ def test_current_returns_date_today_when_zone_default_not_set
assert_equal Date.new(1999, 12, 31), Date.current
end
end
def test_current_returns_time_zone_today_when_zone_default_set
silence_warnings do # silence warnings raised by tzinfo gem
Time.zone_default = TimeZone['Eastern Time (US & Canada)']
Time.zone_default = ActiveSupport::TimeZone['Eastern Time (US & Canada)']
with_env_tz 'US/Central' do
Time.stubs(:now).returns Time.local(1999, 12, 31, 23)
assert_equal Date.new(1999, 12, 31), Date.today
......@@ -238,5 +243,5 @@ def with_env_tz(new_tz = 'US/Eastern')
yield
ensure
old_tz ? ENV['TZ'] = old_tz : ENV.delete('TZ')
end
end
end
......@@ -219,14 +219,14 @@ def test_local_offset
assert_equal Rational(-6, 24), DateTime.local_offset
end
end
def test_utc?
assert_equal true, DateTime.civil(2005, 2, 21, 10, 11, 12).utc?
assert_equal true, DateTime.civil(2005, 2, 21, 10, 11, 12, 0).utc?
assert_equal false, DateTime.civil(2005, 2, 21, 10, 11, 12, 0.25).utc?
assert_equal false, DateTime.civil(2005, 2, 21, 10, 11, 12, -0.25).utc?
end
def test_utc_offset
assert_equal 0, DateTime.civil(2005, 2, 21, 10, 11, 12).utc_offset
assert_equal 0, DateTime.civil(2005, 2, 21, 10, 11, 12, 0).utc_offset
......@@ -234,7 +234,7 @@ def test_utc_offset
assert_equal( -21600, DateTime.civil(2005, 2, 21, 10, 11, 12, -0.25).utc_offset )
assert_equal( -18000, DateTime.civil(2005, 2, 21, 10, 11, 12, Rational(-5, 24)).utc_offset )
end
def test_utc
assert_equal DateTime.civil(2005, 2, 21, 16, 11, 12, 0), DateTime.civil(2005, 2, 21, 10, 11, 12, Rational(-6, 24)).utc
assert_equal DateTime.civil(2005, 2, 21, 15, 11, 12, 0), DateTime.civil(2005, 2, 21, 10, 11, 12, Rational(-5, 24)).utc
......@@ -242,37 +242,37 @@ def test_utc
assert_equal DateTime.civil(2005, 2, 21, 9, 11, 12, 0), DateTime.civil(2005, 2, 21, 10, 11, 12, Rational(1, 24)).utc
assert_equal DateTime.civil(2005, 2, 21, 9, 11, 12, 0), DateTime.civil(2005, 2, 21, 10, 11, 12, Rational(1, 24)).getutc
end
def test_formatted_offset_with_utc
assert_equal '+00:00', DateTime.civil(2000).formatted_offset
assert_equal '+0000', DateTime.civil(2000).formatted_offset(false)
assert_equal 'UTC', DateTime.civil(2000).formatted_offset(true, 'UTC')
end
def test_formatted_offset_with_local
dt = DateTime.civil(2005, 2, 21, 10, 11, 12, Rational(-5, 24))
assert_equal '-05:00', dt.formatted_offset
assert_equal '-0500', dt.formatted_offset(false)
end
def test_compare_with_time
assert_equal 1, DateTime.civil(2000) <=> Time.utc(1999, 12, 31, 23, 59, 59)
assert_equal 0, DateTime.civil(2000) <=> Time.utc(2000, 1, 1, 0, 0, 0)
assert_equal(-1, DateTime.civil(2000) <=> Time.utc(2000, 1, 1, 0, 0, 1))
end
def test_compare_with_datetime
assert_equal 1, DateTime.civil(2000) <=> DateTime.civil(1999, 12, 31, 23, 59, 59)
assert_equal 0, DateTime.civil(2000) <=> DateTime.civil(2000, 1, 1, 0, 0, 0)
assert_equal(-1, DateTime.civil(2000) <=> DateTime.civil(2000, 1, 1, 0, 0, 1))
end
def test_compare_with_time_with_zone
assert_equal 1, DateTime.civil(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(1999, 12, 31, 23, 59, 59), TimeZone['UTC'] )
assert_equal 0, DateTime.civil(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 0), TimeZone['UTC'] )
assert_equal(-1, DateTime.civil(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 1), TimeZone['UTC'] ))
assert_equal 1, DateTime.civil(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(1999, 12, 31, 23, 59, 59), ActiveSupport::TimeZone['UTC'] )
assert_equal 0, DateTime.civil(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 0), ActiveSupport::TimeZone['UTC'] )
assert_equal(-1, DateTime.civil(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 1), ActiveSupport::TimeZone['UTC'] ))
end
def test_to_f
assert_equal 946684800.0, DateTime.civil(2000).to_f
assert_equal 946684800.0, DateTime.civil(1999,12,31,19,0,0,Rational(-5,24)).to_f
......
......@@ -29,7 +29,7 @@ def test_argument_error
flunk("ArgumentError should be raised, but we got #{$!.class} instead")
end
end
uses_mocha 'TestDurationSinceAndAgoWithCurrentTime' do
def test_since_and_ago_anchored_to_time_now_when_time_zone_default_not_set
Time.zone_default = nil
......@@ -43,10 +43,10 @@ def test_since_and_ago_anchored_to_time_now_when_time_zone_default_not_set
assert_equal Time.local(1999,12,31,23,59,55), 5.seconds.ago
end
end
def test_since_and_ago_anchored_to_time_zone_now_when_time_zone_default_set
silence_warnings do # silence warnings raised by tzinfo gem
Time.zone_default = TimeZone['Eastern Time (US & Canada)']
Time.zone_default = ActiveSupport::TimeZone['Eastern Time (US & Canada)']
with_env_tz 'US/Eastern' do
Time.stubs(:now).returns Time.local(2000)
# since
......@@ -63,7 +63,7 @@ def test_since_and_ago_anchored_to_time_zone_now_when_time_zone_default_set
Time.zone_default = nil
end
end
protected
def with_env_tz(new_tz = 'US/Eastern')
old_tz, ENV['TZ'] = ENV['TZ'], new_tz
......
......@@ -449,7 +449,7 @@ def test_to_s
assert_equal "17:44", time.to_s(:time)
assert_equal "February 21, 2005 17:44", time.to_s(:long)
assert_equal "February 21st, 2005 17:44", time.to_s(:long_ordinal)
with_env_tz "UTC" do
with_env_tz "UTC" do
assert_equal "Mon, 21 Feb 2005 17:44:30 +0000", time.to_s(:rfc822)
end
end
......@@ -505,13 +505,13 @@ def test_days_in_month_with_year
assert_equal 30, Time.days_in_month(11, 2005)
assert_equal 31, Time.days_in_month(12, 2005)
end
uses_mocha 'TestTimeDaysInMonthWithoutYearArg' do
def test_days_in_month_feb_in_common_year_without_year_arg
Time.stubs(:now).returns(Time.utc(2007))
assert_equal 28, Time.days_in_month(2)
end
def test_days_in_month_feb_in_leap_year_without_year_arg
Time.stubs(:now).returns(Time.utc(2008))
assert_equal 29, Time.days_in_month(2)
......@@ -559,13 +559,13 @@ def test_xmlschema_is_available
def test_acts_like_time
assert Time.new.acts_like_time?
end
def test_formatted_offset_with_utc
assert_equal '+00:00', Time.utc(2000).formatted_offset
assert_equal '+0000', Time.utc(2000).formatted_offset(false)
assert_equal 'UTC', Time.utc(2000).formatted_offset(true, 'UTC')
end
def test_formatted_offset_with_local
with_env_tz 'US/Eastern' do
assert_equal '-05:00', Time.local(2000).formatted_offset
......@@ -574,27 +574,27 @@ def test_formatted_offset_with_local
assert_equal '-0400', Time.local(2000, 7).formatted_offset(false)
end
end
def test_compare_with_time
assert_equal 1, Time.utc(2000) <=> Time.utc(1999, 12, 31, 23, 59, 59, 999)
assert_equal 0, Time.utc(2000) <=> Time.utc(2000, 1, 1, 0, 0, 0)
assert_equal(-1, Time.utc(2000) <=> Time.utc(2000, 1, 1, 0, 0, 0, 001))
end
def test_compare_with_datetime
assert_equal 1, Time.utc(2000) <=> DateTime.civil(1999, 12, 31, 23, 59, 59)
assert_equal 0, Time.utc(2000) <=> DateTime.civil(2000, 1, 1, 0, 0, 0)
assert_equal(-1, Time.utc(2000) <=> DateTime.civil(2000, 1, 1, 0, 0, 1))
end
def test_compare_with_time_with_zone
assert_equal 1, Time.utc(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(1999, 12, 31, 23, 59, 59), TimeZone['UTC'] )
assert_equal 0, Time.utc(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 0), TimeZone['UTC'] )
assert_equal(-1, Time.utc(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 1), TimeZone['UTC'] ))
assert_equal 1, Time.utc(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(1999, 12, 31, 23, 59, 59), ActiveSupport::TimeZone['UTC'] )
assert_equal 0, Time.utc(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 0), ActiveSupport::TimeZone['UTC'] )
assert_equal(-1, Time.utc(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 1), ActiveSupport::TimeZone['UTC'] ))
end
def test_minus_with_time_with_zone
assert_equal 86_400.0, Time.utc(2000, 1, 2) - ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1), TimeZone['UTC'] )
assert_equal 86_400.0, Time.utc(2000, 1, 2) - ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1), ActiveSupport::TimeZone['UTC'] )
end
def test_time_created_with_local_constructor_cannot_represent_times_during_hour_skipped_by_dst
......@@ -608,7 +608,7 @@ def test_time_created_with_local_constructor_cannot_represent_times_during_hour_
def test_case_equality
assert Time === Time.utc(2000)
assert Time === ActiveSupport::TimeWithZone.new(Time.utc(2000), TimeZone['UTC'])
assert Time === ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone['UTC'])
assert_equal false, Time === DateTime.civil(2000)
end
......
......@@ -24,6 +24,11 @@ def c; end
def d; end
def e; end
deprecate :a, :b, :c => :e, :d => "you now need to do something extra for this one"
module B
C = 1
end
A = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('Deprecatee::A', 'Deprecatee::B::C')
end
......@@ -83,6 +88,11 @@ def test_deprecated_instance_variable_proxy_shouldnt_warn_on_inspect
assert_not_deprecated { assert_equal @dtc.request.inspect, @dtc.old_request.inspect }
end
def test_deprecated_constant_proxy
assert_not_deprecated { Deprecatee::B::C }
assert_deprecated('Deprecatee::A') { assert_equal Deprecatee::B::C, Deprecatee::A }
end
def test_assert_deprecation_without_match
assert_deprecated do
@dtc.partially
......
require 'abstract_unit'
class GzipTest < Test::Unit::TestCase
def test_compress_should_decompress_to_the_same_value
assert_equal "Hello World", ActiveSupport::Gzip.decompress(ActiveSupport::Gzip.compress("Hello World"))
end
end
\ No newline at end of file
......@@ -42,4 +42,23 @@ def test_delete
assert_nil @ordered_hash.delete(bad_key)
end
def test_has_key
assert_equal true, @ordered_hash.has_key?('blue')
assert_equal true, @ordered_hash.key?('blue')
assert_equal true, @ordered_hash.include?('blue')
assert_equal true, @ordered_hash.member?('blue')
assert_equal false, @ordered_hash.has_key?('indigo')
assert_equal false, @ordered_hash.key?('indigo')
assert_equal false, @ordered_hash.include?('indigo')
assert_equal false, @ordered_hash.member?('indigo')
end
def test_has_value
assert_equal true, @ordered_hash.has_value?('000099')
assert_equal true, @ordered_hash.value?('000099')
assert_equal false, @ordered_hash.has_value?('ABCABC')
assert_equal false, @ordered_hash.value?('ABCABC')
end
end
......@@ -2,7 +2,7 @@
class OrderedOptionsTest < Test::Unit::TestCase
def test_usage
a = OrderedOptions.new
a = ActiveSupport::OrderedOptions.new
assert_nil a[:not_set]
......@@ -20,7 +20,7 @@ def test_usage
end
def test_looping
a = OrderedOptions.new
a = ActiveSupport::OrderedOptions.new
a[:allow_concurreny] = true
a["else_where"] = 56
......@@ -34,7 +34,7 @@ def test_looping
end
def test_method_access
a = OrderedOptions.new
a = ActiveSupport::OrderedOptions.new
assert_nil a.not_set
......
require 'abstract_unit'
class StringQuestioneerTest < Test::Unit::TestCase
def test_match
assert StringQuestioneer.new("production").production?
end
def test_miss
assert !StringQuestioneer.new("production").development?
end
def test_missing_question_mark
assert_raises(NoMethodError) { StringQuestioneer.new("production").production }
end
end
\ No newline at end of file
*SVN*
*Edge*
* Consolidate error messages for missing gems, and skip them when running rake gems:* tasks. [rick]
* Wrapped Rails.env in StringQuestioneer so you can do Rails.env.development? [DHH]
* Use a system command to install gems, since GemRunner exits the ruby process. #210 [Tim Morgan]
* Fixed that RailsInfoController wasn't considering all requests local in development mode (Edgard Castro) [#310 state:resolved]
*2.1.0 RC1 (May 11th, 2008)*
*2.1.0 (May 31st, 2008)*
* script/dbconsole fires up the command-line database client. #102 [Steve Purcell]
......
......@@ -304,11 +304,11 @@ spec = Gem::Specification.new do |s|
EOF
s.add_dependency('rake', '>= 0.8.1')
s.add_dependency('activesupport', '= 2.0.991' + PKG_BUILD)
s.add_dependency('activerecord', '= 2.0.991' + PKG_BUILD)
s.add_dependency('actionpack', '= 2.0.991' + PKG_BUILD)
s.add_dependency('actionmailer', '= 2.0.991' + PKG_BUILD)
s.add_dependency('activeresource', '= 2.0.991' + PKG_BUILD)
s.add_dependency('activesupport', '= 2.1.0' + PKG_BUILD)
s.add_dependency('activerecord', '= 2.1.0' + PKG_BUILD)
s.add_dependency('actionpack', '= 2.1.0' + PKG_BUILD)
s.add_dependency('actionmailer', '= 2.1.0' + PKG_BUILD)
s.add_dependency('activeresource', '= 2.1.0' + PKG_BUILD)
s.rdoc_options << '--exclude' << '.'
s.has_rdoc = false
......
class Rails::InfoController < ActionController::Base
def properties
if local_request?
if consider_all_requests_local || local_request?
render :inline => Rails::Info.to_html
else
render :text => '<p>For security purposes, this information is only available to local requests.</p>', :status => 500
......
# These settings change the behavior of Rails 2 apps and will be defaults
# for Rails 3. You can remove this initializer when Rails 3 is released.
# Include Active Record class name as root for JSON serialized output.
ActiveRecord::Base.include_root_in_json = true
if defined?(ActiveRecord)
# Include Active Record class name as root for JSON serialized output.
ActiveRecord::Base.include_root_in_json = true
# Store the full class name (including module namespace) in STI type column.
ActiveRecord::Base.store_full_sti_class = true
# Store the full class name (including module namespace) in STI type column.
ActiveRecord::Base.store_full_sti_class = true
end
# Use ISO 8601 format for JSON serialized times and dates.
ActiveSupport.use_standard_json_time_format = true
......
......@@ -8,6 +8,7 @@
require 'rails/plugin/locator'
require 'rails/plugin/loader'
require 'rails/gem_dependency'
require 'rails/rack'
RAILS_ENV = (ENV['RAILS_ENV'] || 'development').dup unless defined?(RAILS_ENV)
......@@ -36,7 +37,7 @@ def root
end
def env
RAILS_ENV
StringQuestioneer.new(RAILS_ENV)
end
def cache
......@@ -78,7 +79,10 @@ class Initializer
# The set of loaded plugins.
attr_reader :loaded_plugins
# Whether or not all the gem dependencies have been met
attr_reader :gems_dependencies_loaded
# Runs the initializer. By default, this will invoke the #process method,
# which simply executes all of the initialization routines. Alternately,
# you can specify explicitly which initialization routine you want:
......@@ -306,7 +310,7 @@ def load_environment
end
def load_observers
if @gems_dependencies_loaded && configuration.frameworks.include?(:active_record)
if gems_dependencies_loaded && configuration.frameworks.include?(:active_record)
ActiveRecord::Base.instantiate_observers
end
end
......@@ -462,7 +466,7 @@ def initialize_framework_settings
# Fires the user-supplied after_initialize block (Configuration#after_initialize)
def after_initialize
if @gems_dependencies_loaded
if gems_dependencies_loaded
configuration.after_initialize_blocks.each do |block|
block.call
end
......@@ -470,7 +474,7 @@ def after_initialize
end
def load_application_initializers
if @gems_dependencies_loaded
if gems_dependencies_loaded
Dir["#{configuration.root_path}/config/initializers/**/*.rb"].sort.each do |initializer|
load(initializer)
end
......
module Rails
module Rack
autoload :Static, "rails/rack/static"
end
end
module Rails
module Rack
class Static
FILE_METHODS = %w(GET HEAD).freeze
def initialize(app)
@app = app
@file_server = ::Rack::File.new(File.join(RAILS_ROOT, "public"))
end
def call(env)
path = env['PATH_INFO'].chomp('/')
method = env['REQUEST_METHOD']
cached_path = (path.empty? ? 'index' : path) + ::ActionController::Base.page_cache_extension
if FILE_METHODS.include?(method)
if file_exist?(path)
return @file_server.call(env)
elsif file_exist?(cached_path)
env['PATH_INFO'] = cached_path
return @file_server.call(env)
end
end
@app.call(env)
end
private
def file_exist?(path)
full_path = File.join(@file_server.root, ::Rack::Utils.unescape(path))
File.file?(full_path) && File.readable?(full_path)
end
end
end
end
module Rails
module VERSION #:nodoc:
MAJOR = 2
MINOR = 0
TINY = 991
MINOR = 1
TINY = 0
STRING = [MAJOR, MINOR, TINY].join('.')
end
......
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册