提交 b587bfd5 编写于 作者: X Xavier Noria

Merge remote branch 'rails/master'

......@@ -11,7 +11,7 @@ gem "rails", :path => File.dirname(__FILE__)
gem "rake", ">= 0.8.7"
gem "mocha", ">= 0.9.8"
gem "rdoc", ">= 2.5.10"
gem "horo", ">= 1.0.1"
gem "horo", ">= 1.0.2"
# AS
gem "memcache-client", ">= 1.8.5"
......
== Welcome to Rails
== Welcome to \Rails
Rails is a web-application framework that includes everything needed to create
\Rails is a web-application framework that includes everything needed to create
database-backed web applications according to the Model-View-Control pattern.
This pattern splits the view (also called the presentation) into "dumb"
......@@ -11,7 +11,7 @@ persist themselves to a database. The controller handles the incoming requests
(such as Save New Account, Update Product, Show Post) by manipulating the model
and directing data to the view.
In Rails, the model is handled by what's called an object-relational mapping
In \Rails, the model is handled by what's called an object-relational mapping
layer entitled Active Record. This layer allows you to present the data from
database rows as objects and embellish these data objects with business logic
methods. You can read more about Active Record in
......@@ -22,17 +22,17 @@ layers by its two parts: Action View and Action Controller. These two layers
are bundled in a single package due to their heavy interdependence. This is
unlike the relationship between the Active Record and Action Pack that is much
more separate. Each of these packages can be used independently outside of
Rails. You can read more about Action Pack in
\Rails. You can read more about Action Pack in
link:files/vendor/rails/actionpack/README.html.
== Getting Started
1. Install Rails at the command prompt if you haven't yet:
1. Install \Rails at the command prompt if you haven't yet:
gem install rails
2. At the command prompt, create a new Rails application:
2. At the command prompt, create a new \Rails application:
rails new myapp
......@@ -58,10 +58,10 @@ the following resources handy:
== Contributing
We encourage you to contribute to Ruby on Rails! Please check out the {Contributing to Rails
We encourage you to contribute to Ruby on \Rails! Please check out the {Contributing to \Rails
guide}[http://edgeguides.rubyonrails.org/contributing_to_rails.html] for guidelines about how
to proceed. {Join us}[http://contributors.rubyonrails.org]!
== License
Ruby on Rails is released under the MIT license.
Ruby on \Rails is released under the MIT license.
......@@ -11,8 +11,18 @@
$VERBOSE = old
end
require 'active_support/core_ext/kernel/reporting'
require 'active_support/core_ext/string/encoding'
if "ruby".encoding_aware?
# These are the normal settings that will be set up by Railties
# TODO: Have these tests support other combinations of these values
silence_warnings do
Encoding.default_internal = "UTF-8"
Encoding.default_external = "UTF-8"
end
end
silence_warnings do
# These external dependencies have warnings :/
require 'text/format'
......@@ -67,4 +77,4 @@ def set_delivery_method(method)
def restore_delivery_method
ActionMailer::Base.delivery_method = @old_delivery_method
end
\ No newline at end of file
end
......@@ -15,14 +15,14 @@ def parameters
alias :params :parameters
def path_parameters=(parameters) #:nodoc:
@env.delete("action_dispatch.request.symbolized_path_parameters")
@_symbolized_path_params = nil
@env.delete("action_dispatch.request.parameters")
@env["action_dispatch.request.path_parameters"] = parameters
end
# The same as <tt>path_parameters</tt> with explicitly symbolized keys.
def symbolized_path_parameters
@env["action_dispatch.request.symbolized_path_parameters"] ||= path_parameters.symbolize_keys
@_symbolized_path_params ||= path_parameters.symbolize_keys
end
# Returns a hash with the \parameters used to form the \path of the request.
......
......@@ -26,13 +26,18 @@ def call(env)
@constraints.each { |constraint|
if constraint.respond_to?(:matches?) && !constraint.matches?(req)
return [ 404, {'X-Cascade' => 'pass'}, [] ]
elsif constraint.respond_to?(:call) && !constraint.call(req)
elsif constraint.respond_to?(:call) && !constraint.call(*constraint_args(constraint, req))
return [ 404, {'X-Cascade' => 'pass'}, [] ]
end
}
@app.call(env)
end
private
def constraint_args(constraint, request)
constraint.arity == 1 ? [request] : [request.symbolized_path_parameters, request]
end
end
class Mapping #:nodoc:
......@@ -774,7 +779,7 @@ def apply_common_behavior_for(method, resources, options, &block)
return true
end
options.each do |k,v|
options.keys.each do |k|
(options[:constraints] ||= {})[k] = options.delete(k) if options[k].is_a?(Regexp)
end
......
......@@ -494,7 +494,7 @@ def call(env)
def recognize_path(path, environment = {})
method = (environment[:method] || "GET").to_s.upcase
path = Rack::Mount::Utils.normalize_path(path)
path = Rack::Mount::Utils.normalize_path(path) unless path =~ %r{://}
begin
env = Rack::MockRequest.env_for(path, {:method => method})
......@@ -502,7 +502,7 @@ def recognize_path(path, environment = {})
raise ActionController::RoutingError, e.message
end
req = Rack::Request.new(env)
req = @request_class.new(env)
@set.recognize(req) do |route, matches, params|
params.each do |key, value|
if value.is_a?(String)
......
require 'uri'
require 'active_support/core_ext/hash/diff'
require 'active_support/core_ext/hash/indifferent_access'
......@@ -40,14 +41,7 @@ module RoutingAssertions
# # Check a Simply RESTful generated route
# assert_recognizes list_items_url, 'items/list'
def assert_recognizes(expected_options, path, extras={}, message=nil)
if path.is_a? Hash
request_method = path[:method]
path = path[:path]
else
request_method = nil
end
request = recognized_request_for(path, request_method)
request = recognized_request_for(path)
expected_options = expected_options.clone
extras.each_key { |key| expected_options.delete key } unless extras.nil?
......@@ -77,7 +71,16 @@ def assert_recognizes(expected_options, path, extras={}, message=nil)
# # Asserts that the generated route gives us our custom route
# assert_generates "changesets/12", { :controller => 'scm', :action => 'show_diff', :revision => "12" }
def assert_generates(expected_path, options, defaults={}, extras = {}, message=nil)
expected_path = "/#{expected_path}" unless expected_path[0] == ?/
if expected_path =~ %r{://}
begin
uri = URI.parse(expected_path)
expected_path = uri.path.to_s.empty? ? "/" : uri.path
rescue URI::InvalidURIError => e
raise ActionController::RoutingError, e.message
end
else
expected_path = "/#{expected_path}" unless expected_path.first == '/'
end
# Load routes.rb if it hasn't been loaded.
generated_path, extra_keys = @routes.generate_extras(options, defaults)
......@@ -177,15 +180,35 @@ def method_missing(selector, *args, &block)
private
# Recognizes the route for a given path.
def recognized_request_for(path, request_method = nil)
path = "/#{path}" unless path.first == '/'
def recognized_request_for(path)
if path.is_a?(Hash)
method = path[:method]
path = path[:path]
else
method = :get
end
# Assume given controller
request = ActionController::TestRequest.new
request.env["REQUEST_METHOD"] = request_method.to_s.upcase if request_method
request.path = path
params = @routes.recognize_path(path, { :method => request.method })
if path =~ %r{://}
begin
uri = URI.parse(path)
request.env["rack.url_scheme"] = uri.scheme || "http"
request.host = uri.host if uri.host
request.port = uri.port if uri.port
request.path = uri.path.to_s.empty? ? "/" : uri.path
rescue URI::InvalidURIError => e
raise ActionController::RoutingError, e.message
end
else
path = "/#{path}" unless path.first == "/"
request.path = path
end
request.request_method = method if method
params = @routes.recognize_path(path, { :method => method })
request.path_parameters = params.with_indifferent_access
request
......
......@@ -12,8 +12,16 @@
ENV['TMPDIR'] = File.join(File.dirname(__FILE__), 'tmp')
if defined?(Encoding.default_internal)
Encoding.default_internal = "UTF-8"
require 'active_support/core_ext/kernel/reporting'
require 'active_support/core_ext/string/encoding'
if "ruby".encoding_aware?
# These are the normal settings that will be set up by Railties
# TODO: Have these tests support other combinations of these values
silence_warnings do
Encoding.default_internal = "UTF-8"
Encoding.default_external = "UTF-8"
end
end
require 'test/unit'
......
......@@ -956,7 +956,7 @@ def test_recognize_with_conditions
params = set.recognize_path("/people", :method => :put)
assert_equal("update", params[:action])
assert_raise(ActionController::RoutingError) {
assert_raise(ActionController::UnknownHttpMethod) {
set.recognize_path("/people", :method => :bacon)
}
......
......@@ -427,6 +427,13 @@ def self.matches?(request)
get :preview, :on => :member
end
scope '/countries/:country', :constraints => lambda { |params, req| %[all France].include?(params[:country]) } do
match '/', :to => 'countries#index'
match '/cities', :to => 'countries#cities'
end
match '/countries/:country/(*other)', :to => redirect{ |params, req| params[:other] ? "/countries/all/#{params[:other]}" : '/countries/all' }
match '/:locale/*file.:format', :to => 'files#show', :file => /path\/to\/existing\/file/
end
end
......@@ -2013,6 +2020,20 @@ def test_redirect_https
end
end
def test_symbolized_path_parameters_is_not_stale
get '/countries/France'
assert_equal 'countries#index', @response.body
get '/countries/France/cities'
assert_equal 'countries#cities', @response.body
get '/countries/UK'
verify_redirect 'http://www.example.com/countries/all'
get '/countries/UK/cities'
verify_redirect 'http://www.example.com/countries/all/cities'
end
private
def with_test_routes
yield
......
require "abstract_unit"
if "ruby".encoding_aware?
# These are the normal settings that will be set up by Railties
# TODO: Have these tests support other combinations of these values
Encoding.default_internal = "UTF-8"
Encoding.default_external = "UTF-8"
end
class TestERBTemplate < ActiveSupport::TestCase
ERBHandler = ActionView::Template::Handlers::ERB
......@@ -136,4 +129,4 @@ def with_external_encoding(encoding)
Encoding.default_external = old
end
end
end
\ No newline at end of file
end
......@@ -6,6 +6,11 @@ module ActiveRecord
class Base
def self.mysql2_connection(config)
config[:username] = 'root' if config[:username].nil?
if Mysql2::Client.const_defined? :FOUND_ROWS
config[:flags] = Mysql2::Client::FOUND_ROWS
end
client = Mysql2::Client.new(config.symbolize_keys)
options = [config[:host], config[:username], config[:password], config[:database], config[:port], config[:socket], 0]
ConnectionAdapters::Mysql2Adapter.new(client, logger, options, config)
......
......@@ -16,7 +16,11 @@ class Railtie < Rails::Railtie
config.generators.orm :active_record, :migration => true,
:timestamps => true
config.app_middleware.insert_after "::ActionDispatch::Callbacks", "ActiveRecord::QueryCache"
config.app_middleware.insert_after "::ActionDispatch::Callbacks",
"ActiveRecord::QueryCache"
config.app_middleware.insert_after "::ActionDispatch::Callbacks",
"ActiveRecord::ConnectionAdapters::ConnectionManagement"
rake_tasks do
load "active_record/railties/databases.rake"
......@@ -74,13 +78,6 @@ class Railtie < Rails::Railtie
end
end
initializer "active_record.add_concurrency_middleware" do |app|
if app.config.allow_concurrency
app.config.middleware.insert_after "::ActionDispatch::Callbacks",
"ActiveRecord::ConnectionAdapters::ConnectionManagement"
end
end
config.after_initialize do
ActiveSupport.on_load(:active_record) do
instantiate_observers
......
......@@ -566,6 +566,7 @@ def test_native_types
if bob.moment_of_truth.is_a?(DateTime)
with_env_tz 'US/Eastern' do
bob.reload
assert_equal DateTime.local_offset, bob.moment_of_truth.offset
assert_not_equal 0, bob.moment_of_truth.offset
assert_not_equal "Z", bob.moment_of_truth.zone
......
......@@ -10,8 +10,19 @@
lib = File.expand_path("#{File.dirname(__FILE__)}/../lib")
$:.unshift(lib) unless $:.include?('lib') || $:.include?(lib)
require 'test/unit'
require 'active_support/core_ext/kernel/reporting'
require 'active_support/core_ext/string/encoding'
if "ruby".encoding_aware?
# These are the normal settings that will be set up by Railties
# TODO: Have these tests support other combinations of these values
silence_warnings do
Encoding.default_internal = "UTF-8"
Encoding.default_external = "UTF-8"
end
end
require 'test/unit'
require 'empty_bool'
silence_warnings { require 'mocha' }
......
......@@ -54,14 +54,14 @@ class << o; @x = 1; end
end
end
class KernelSupressTest < Test::Unit::TestCase
class KernelSuppressTest < Test::Unit::TestCase
def test_reraise
assert_raise(LoadError) do
suppress(ArgumentError) { raise LoadError }
end
end
def test_supression
def test_suppression
suppress(ArgumentError) { raise ArgumentError }
suppress(LoadError) { raise LoadError }
suppress(LoadError, ArgumentError) { raise LoadError }
......
......@@ -375,7 +375,7 @@ def options
"Enables updating but does not add a svn:externals entry.") { |v| @method = :checkout }
o.on( "-e", "--export",
"Use svn export to grab the plugin.",
"Exports the plugin, allowing you to check it into your local repository. Does not enable updates, or add an svn:externals entry.") { |v| @method = :export }
"Exports the plugin, allowing you to check it into your local repository. Does not enable updates or add an svn:externals entry.") { |v| @method = :export }
o.on( "-q", "--quiet",
"Suppresses the output from installation.",
"Ignored if -v is passed (rails plugin -v install ...)") { |v| @options[:quiet] = true }
......
......@@ -218,11 +218,11 @@ def self.help(command = 'generate')
puts "Usage: rails #{command} GENERATOR [args] [options]"
puts
puts "General options:"
puts " -h, [--help] # Print generators options and usage"
puts " -h, [--help] # Print generator's options and usage"
puts " -p, [--pretend] # Run but do not make any changes"
puts " -f, [--force] # Overwrite files that already exist"
puts " -s, [--skip] # Skip files that already exist"
puts " -q, [--quiet] # Supress status output"
puts " -q, [--quiet] # Suppress status output"
puts
puts "Please choose a generator below."
puts
......
......@@ -98,17 +98,7 @@ def notify
require "#{app_path}/config/environment"
expects = [ActiveRecord::QueryCache, ActiveRecord::SessionStore]
middleware = Rails.application.config.middleware.map { |m| m.klass }
assert_equal expects, middleware & expects
end
test "database middleware initializes when allow concurrency is true" do
add_to_config "config.threadsafe!"
require "#{app_path}/config/environment"
expects = [ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache]
expects = [ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache, ActiveRecord::SessionStore]
middleware = Rails.application.config.middleware.map { |m| m.klass }
assert_equal expects, middleware & expects
end
......
......@@ -28,6 +28,7 @@ def app
"ActionDispatch::RemoteIp",
"Rack::Sendfile",
"ActionDispatch::Callbacks",
"ActiveRecord::ConnectionAdapters::ConnectionManagement",
"ActiveRecord::QueryCache",
"ActionDispatch::Cookies",
"ActionDispatch::Session::CookieStore",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册