Permalink
Browse files

Merge commit 'mainstream/master'

  • Loading branch information...
2 parents 2037cdd + 04f5221 commit 4a0118d7278687b534edf1e1184d6858cb4d29b8 @lifo lifo committed May 6, 2008
@@ -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
@@ -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
View
@@ -1,5 +1,7 @@
*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
+end
@@ -0,0 +1 @@
+require 'active_support/core_ext/process/daemon'
@@ -0,0 +1,25 @@
+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 }
Oops, something went wrong.

0 comments on commit 4a0118d

Please sign in to comment.