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

Merge branch 'master' of git@github.com:rails/rails

......@@ -998,7 +998,7 @@ def rewrite_options(options) #:nodoc:
# As you can infer from the example, this is mostly useful for situations where you want to centralize dynamic decisions about the
# urls as they stem from the business domain. Please note that any individual url_for call can always override the defaults set
# by this method.
def default_url_options(options) #:doc:
def default_url_options(options = nil)
end
# Redirects the browser to the target specified in +options+. This parameter can take one of three forms:
......
......@@ -61,9 +61,9 @@ def guard_condition
# if they're using foo_url(:id=>2) it's one
# argument, but we don't want to generate /foos/id2
if number_of_arguments == 1
"(!defined?(default_url_options) || default_url_options(nil).blank?) && defined?(request) && request && args.size == 1 && !args.first.is_a?(Hash)"
"(!defined?(default_url_options) || default_url_options.blank?) && defined?(request) && request && args.size == 1 && !args.first.is_a?(Hash)"
else
"(!defined?(default_url_options) || default_url_options(nil).blank?) && defined?(request) && request && args.size == #{number_of_arguments}"
"(!defined?(default_url_options) || default_url_options.blank?) && defined?(request) && request && args.size == #{number_of_arguments}"
end
end
......@@ -98,7 +98,7 @@ def generation_code
# argument
class PositionalArgumentsWithAdditionalParams < PositionalArguments
def guard_condition
"(!defined?(default_url_options) || default_url_options(nil).blank?) && defined?(request) && request && args.size == #{route.segment_keys.size + 1} && !args.last.has_key?(:anchor) && !args.last.has_key?(:port) && !args.last.has_key?(:host)"
"(!defined?(default_url_options) || default_url_options.blank?) && defined?(request) && request && args.size == #{route.segment_keys.size + 1} && !args.last.has_key?(:anchor) && !args.last.has_key?(:port) && !args.last.has_key?(:host)"
end
# This case uses almost the same code as positional arguments,
......
......@@ -614,23 +614,27 @@ def add_default_name_and_id(options)
end
def tag_name
"#{@object_name}[#{@method_name}]"
"#{@object_name}[#{sanitized_method_name}]"
end
def tag_name_with_index(index)
"#{@object_name}[#{index}][#{@method_name}]"
"#{@object_name}[#{index}][#{sanitized_method_name}]"
end
def tag_id
"#{sanitized_object_name}_#{@method_name}"
"#{sanitized_object_name}_#{sanitized_method_name}"
end
def tag_id_with_index(index)
"#{sanitized_object_name}_#{index}_#{@method_name}"
"#{sanitized_object_name}_#{index}_#{sanitized_method_name}"
end
def sanitized_object_name
@object_name.gsub(/[^-a-zA-Z0-9:.]/, "_").sub(/_$/, "")
@sanitized_object_name ||= @object_name.gsub(/[^-a-zA-Z0-9:.]/, "_").sub(/_$/, "")
end
def sanitized_method_name
@sanitized_method_name ||= @method_name.sub(/\?$/,"")
end
end
......
......@@ -52,7 +52,7 @@ class DefaultUrlOptionsController < ActionController::Base
def default_url_options_action
end
def default_url_options(options)
def default_url_options(options = nil)
{ :host => 'www.override.com', :action => 'new', :bacon => 'chunky' }
end
end
......@@ -167,4 +167,17 @@ def test_default_url_options_are_used_if_set
ensure
ActionController::Routing::Routes.load!
end
end
class EnsureNamedRoutesWorksTicket22BugTest < Test::Unit::TestCase
def test_named_routes_still_work
ActionController::Routing::Routes.draw do |map|
map.resources :things
end
EmptyController.send :include, ActionController::UrlWriter
assert_equal '/things', EmptyController.new.send(:things_path)
ensure
ActionController::Routing::Routes.load!
end
end
\ No newline at end of file
......@@ -6,6 +6,7 @@
alias_method :title_before_type_cast, :title unless respond_to?(:title_before_type_cast)
alias_method :body_before_type_cast, :body unless respond_to?(:body_before_type_cast)
alias_method :author_name_before_type_cast, :author_name unless respond_to?(:author_name_before_type_cast)
alias_method :secret?, :secret
def new_record=(boolean)
@new_record = boolean
......@@ -71,10 +72,12 @@ def test_label
'<label class="title_label" for="post_title">Title</label>',
label("post", "title", nil, :class => 'title_label')
)
assert_dom_equal('<label for="post_secret">Secret?</label>', label("post", "secret?"))
end
def test_label_with_symbols
assert_dom_equal('<label for="post_title">Title</label>', label(:post, :title))
assert_dom_equal('<label for="post_secret">Secret?</label>', label(:post, :secret?))
end
def test_label_with_for_attribute_as_symbol
......@@ -140,6 +143,8 @@ def test_text_field_doesnt_change_param_values
def test_hidden_field
assert_dom_equal '<input id="post_title" name="post[title]" type="hidden" value="Hello World" />',
hidden_field("post", "title")
assert_dom_equal '<input id="post_secret" name="post[secret]" type="hidden" value="1" />',
hidden_field("post", "secret?")
end
def test_hidden_field_with_escapes
......@@ -172,6 +177,10 @@ def test_check_box
'<input checked="checked" id="post_secret" name="post[secret]" type="checkbox" value="1" /><input name="post[secret]" type="hidden" value="0" />',
check_box("post", "secret")
)
assert_dom_equal(
'<input checked="checked" id="post_secret" name="post[secret]" type="checkbox" value="1" /><input name="post[secret]" type="hidden" value="0" />',
check_box("post", "secret?")
)
end
def test_check_box_with_explicit_checked_and_unchecked_values
......
......@@ -295,6 +295,12 @@ def index_name(table_name, options) #:nodoc:
def structure_dump
end
def dump_schema_information #:nodoc:
sm_table = ActiveRecord::Migrator.schema_migrations_table_name
migrated = select_values("SELECT version FROM #{sm_table}")
migrated.map { |v| "INSERT INTO #{sm_table} (version) VALUES ('#{v}');" }.join("\n")
end
# Should not be called normally, but this operation is non-destructive.
# The migrations module handles this automatically.
def initialize_schema_migrations_table
......
*SVN*
* Added Ruby 1.8 implementation of Process.daemon
* Duration #since and #ago with no argument (e.g., 5.days.ago) return TimeWithZone when config.time_zone is set. Introducing Time.current, which returns Time.zone.now if config.time_zone is set, otherwise just returns Time.now [Geoff Buesing]
* Time#since behaves correctly when passed a Duration. Closes #11527 [kemiller]
......
......@@ -2,14 +2,6 @@ module Kernel
# Turns the current script into a daemon process that detaches from the console.
# It can be shut down with a TERM signal.
def daemonize
exit if fork # Parent exits, child continues.
Process.setsid # Become session leader.
exit if fork # Zap session leader. See [1].
Dir.chdir "/" # Release old working directory.
File.umask 0000 # Ensure sensible umask. Adjust as needed.
STDIN.reopen "/dev/null" # Free file descriptors and
STDOUT.reopen "/dev/null", "a" # point them somewhere sensible.
STDERR.reopen STDOUT # STDOUT/ERR should better go to a logfile.
trap("TERM") { exit }
Process.daemon
end
end
\ No newline at end of file
end
require 'active_support/core_ext/process/daemon'
if RUBY_VERSION < "1.9"
module Process
def self.daemon(nochdir = nil, noclose = nil)
exit if fork # Parent exits, child continues.
Process.setsid # Become session leader.
exit if fork # Zap session leader. See [1].
unless nochdir
Dir.chdir "/" # Release old working directory.
end
File.umask 0000 # Ensure sensible umask. Adjust as needed.
unless noclose
STDIN.reopen "/dev/null" # Free file descriptors and
STDOUT.reopen "/dev/null", "a" # point them somewhere sensible.
STDERR.reopen '/dev/null', 'a'
end
trap("TERM") { exit }
return 0
end
end
end
......@@ -18,6 +18,12 @@ def [](key)
pair = assoc(key)
pair ? pair.last : nil
end
def delete(key)
pair = assoc(key)
pair ? array_index = index(pair) : nil
array_index ? delete_at(array_index).last : nil
end
def keys
collect { |key, value| key }
......
......@@ -28,12 +28,12 @@ class NilClass
WHINERS = [::Array]
WHINERS << ::ActiveRecord::Base if defined? ::ActiveRecord
@@method_class_map = Hash.new
METHOD_CLASS_MAP = Hash.new
WHINERS.each do |klass|
methods = klass.public_instance_methods - public_instance_methods
class_name = klass.name
methods.each { |method| @@method_class_map[method.to_sym] = class_name }
methods.each { |method| METHOD_CLASS_MAP[method.to_sym] = class_name }
end
# Raises a RuntimeError when you attempt to call +id+ on +nil+.
......@@ -43,7 +43,7 @@ def id
private
def method_missing(method, *args, &block)
raise_nil_warning_for @@method_class_map[method], method, caller
raise_nil_warning_for METHOD_CLASS_MAP[method], method, caller
end
# Raises a NoMethodError when you attempt to call a method on +nil+.
......
......@@ -29,6 +29,19 @@ def test_assignment
assert_equal value, @ordered_hash.values.last
assert_equal value, @ordered_hash[key]
end
def test_delete
key, value = 'white', 'ffffff'
bad_key = 'black'
@ordered_hash[key] = value
assert_equal @keys.length + 1, @ordered_hash.length
assert_equal value, @ordered_hash.delete(key)
assert_equal @keys.length, @ordered_hash.length
assert_nil @ordered_hash.delete(bad_key)
end
end
class OrderedOptionsTest < Test::Unit::TestCase
......
*SVN*
* Fix bug where plugin init.rb files from frozen gem specs weren't being run. (pjb3) [#122 state:resolved]
* Made the location of the routes file configurable with config.routes_configuration_file (Scott Fleckenstein) [#88]
* Rails Edge info returns the latest git commit hash [Francesc Esplugas]
......
......@@ -78,7 +78,8 @@ def locate_plugins_under(base_path)
# a <tt>rails/init.rb</tt> file.
class GemLocator < Locator
def plugins
specs = Gem.loaded_specs.values.select do |spec|
specs = initializer.configuration.gems.map(&:specification)
specs + Gem.loaded_specs.values.select do |spec|
spec.loaded_from && # prune stubs
File.exist?(File.join(spec.full_gem_path, "rails", "init.rb"))
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册