Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Ruby 1.9 compat, consistent load paths

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7719 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 0ee1cb2cd32bfaf47deaf5440dd5b9cf0915ab6a 1 parent 9264bdc
Jeremy Kemper jeremy authored
Showing with 304 additions and 275 deletions.
  1. +4 −4 actionmailer/lib/action_mailer/helpers.rb
  2. +2 −2 actionpack/lib/action_controller/assertions.rb
  3. +9 −9 actionpack/lib/action_controller/base.rb
  4. +6 −6 actionpack/lib/action_controller/caching.rb
  5. +3 −3 actionpack/lib/action_controller/cgi_process.rb
  6. +11 −11 actionpack/lib/action_controller/components.rb
  7. +9 −4 actionpack/lib/action_controller/dispatcher.rb
  8. +8 −6 actionpack/lib/action_controller/filters.rb
  9. +2 −3 actionpack/lib/action_controller/flash.rb
  10. +10 −8 actionpack/lib/action_controller/helpers.rb
  11. +3 −3 actionpack/lib/action_controller/http_authentication.rb
  12. +8 −8 actionpack/lib/action_controller/integration.rb
  13. +6 −4 actionpack/lib/action_controller/layout.rb
  14. +4 −2 actionpack/lib/action_controller/mime_responds.rb
  15. +3 −3 actionpack/lib/action_controller/mime_type.rb
  16. +8 −8 actionpack/lib/action_controller/polymorphic_routes.rb
  17. +13 −10 actionpack/lib/action_controller/request.rb
  18. +2 −2 actionpack/lib/action_controller/rescue.rb
  19. +8 −6 actionpack/lib/action_controller/resources.rb
  20. +11 −9 actionpack/lib/action_controller/routing.rb
  21. +5 −4 actionpack/lib/action_controller/session_management.rb
  22. +9 −9 actionpack/lib/action_controller/test_process.rb
  23. +2 −2 actionpack/lib/action_controller/verification.rb
  24. +5 −5 actionpack/lib/action_view/helpers/number_helper.rb
  25. +1 −1  actionpack/lib/action_view/helpers/text_helper.rb
  26. +4 −4 actionpack/test/controller/base_test.rb
  27. +6 −6 actionpack/test/controller/dispatcher_test.rb
  28. +1 −1  actionpack/test/controller/filters_test.rb
  29. +1 −1  actionpack/test/controller/integration_test.rb
  30. +8 −8 actionpack/test/controller/layout_test.rb
  31. +19 −17 actionpack/test/controller/mime_responds_test.rb
  32. +2 −1  actionpack/test/controller/mime_type_test.rb
  33. +3 −3 actionpack/test/controller/render_test.rb
  34. +1 −1  actionpack/test/controller/request_forgery_protection_test.rb
  35. +2 −3 activerecord/test/abstract_unit.rb
  36. +2 −2 activeresource/lib/active_resource/base.rb
  37. +11 −13 activeresource/lib/active_resource/custom_methods.rb
  38. +1 −1  activeresource/lib/active_resource/http_mock.rb
  39. +4 −4 activeresource/test/authorization_test.rb
  40. +3 −3 activeresource/test/base/load_test.rb
  41. +3 −3 activeresource/test/base_errors_test.rb
  42. +8 −5 activeresource/test/base_test.rb
  43. +2 −2 activeresource/test/connection_test.rb
  44. +1 −1  activeresource/test/fixtures/person.rb
  45. +1 −1  activesupport/lib/active_support/clean_logger.rb
  46. +4 −1 activesupport/lib/active_support/core_ext.rb
  47. +4 −4 activesupport/lib/active_support/core_ext/array.rb
  48. +1 −2  activesupport/lib/active_support/core_ext/bigdecimal.rb
  49. +1 −2  activesupport/lib/active_support/core_ext/bigdecimal/{formatting.rb → conversions.rb}
  50. +2 −2 activesupport/lib/active_support/core_ext/cgi.rb
  51. +3 −3 activesupport/lib/active_support/core_ext/class.rb
  52. +3 −3 activesupport/lib/active_support/core_ext/date.rb
  53. +3 −3 activesupport/lib/active_support/core_ext/date_time.rb
  54. +1 −1  activesupport/lib/active_support/core_ext/float.rb
  55. +1 −1  activesupport/lib/active_support/core_ext/hash.rb
  56. +2 −2 activesupport/lib/active_support/core_ext/integer.rb
  57. +5 −5 activesupport/lib/active_support/core_ext/kernel.rb
  58. +8 −8 activesupport/lib/active_support/core_ext/module.rb
  59. +2 −2 activesupport/lib/active_support/core_ext/numeric.rb
  60. +3 −3 activesupport/lib/active_support/core_ext/object.rb
  61. +1 −1  activesupport/lib/active_support/core_ext/pathname.rb
  62. +1 −1  activesupport/lib/active_support/core_ext/range.rb
  63. +6 −6 activesupport/lib/active_support/core_ext/string.rb
  64. +1 −2  activesupport/lib/active_support/core_ext/test.rb
  65. 0  activesupport/lib/active_support/core_ext/test/{difference.rb → unit/assertions.rb}
  66. +3 −3 activesupport/lib/active_support/core_ext/time.rb
  67. +3 −3 activesupport/lib/active_support/dependencies.rb
  68. +3 −3 activesupport/test/core_ext/hash_ext_test.rb
  69. +8 −2 activesupport/test/inflector_test.rb
8 actionmailer/lib/action_mailer/helpers.rb
View
@@ -49,7 +49,7 @@ def helper(*args, &block)
begin
require_dependency(file_name)
rescue LoadError => load_error
- requiree = / -- (.*?)(\.rb)?$/.match(load_error).to_a[1]
+ requiree = / -- (.*?)(\.rb)?$/.match(load_error.message).to_a[1]
msg = (requiree == file_name) ? "Missing helper file helpers/#{file_name}.rb" : "Can't load file: #{requiree}"
raise LoadError.new(msg).copy_blame!(load_error)
end
@@ -72,7 +72,7 @@ def helper_method(*methods)
methods.flatten.each do |method|
master_helper_module.module_eval <<-end_eval
def #{method}(*args, &block)
- controller.send(%(#{method}), *args, &block)
+ controller.send!(%(#{method}), *args, &block)
end
end_eval
end
@@ -92,7 +92,7 @@ def inherited_with_helper(child)
inherited_without_helper(child)
begin
child.master_helper_module = Module.new
- child.master_helper_module.send :include, master_helper_module
+ child.master_helper_module.send! :include, master_helper_module
child.helper child.name.underscore
rescue MissingSourceFile => e
raise unless e.is_missing?("helpers/#{child.name.underscore}_helper")
@@ -108,4 +108,4 @@ def initialize_template_class_with_helper(assigns)
end
end
end
-end
+end
4 actionpack/lib/action_controller/assertions.rb
View
@@ -46,7 +46,7 @@ module Assertions
def self.included(klass)
%w(response selector tag dom routing model).each do |kind|
require "action_controller/assertions/#{kind}_assertions"
- klass.send :include, const_get("#{kind.camelize}Assertions")
+ klass.module_eval { include const_get("#{kind.camelize}Assertions") }
end
end
@@ -66,4 +66,4 @@ class TestCase #:nodoc:
include ActionController::Assertions
end
end
-end
+end
18 actionpack/lib/action_controller/base.rb
View
@@ -392,7 +392,7 @@ def controller_path
# More methods can be hidden using <tt>hide_actions</tt>.
def hidden_actions
unless read_inheritable_attribute(:hidden_actions)
- write_inheritable_attribute(:hidden_actions, ActionController::Base.public_instance_methods)
+ write_inheritable_attribute(:hidden_actions, ActionController::Base.public_instance_methods.map(&:to_s))
end
read_inheritable_attribute(:hidden_actions)
@@ -400,12 +400,12 @@ def hidden_actions
# Hide each of the given methods from being callable as actions.
def hide_action(*names)
- write_inheritable_attribute(:hidden_actions, hidden_actions | names.collect { |n| n.to_s })
+ write_inheritable_attribute(:hidden_actions, hidden_actions | names.map(&:to_s))
end
-
+
@@view_paths = {}
-
+
# View load paths determine the bases from which template references can be made. So a call to
# render("test/template") will be looked up in the view load paths array and the closest match will be
# returned.
@@ -844,19 +844,19 @@ def render(options = nil, &block) #:doc:
if collection = options[:collection]
render_for_text(
- @template.send(:render_partial_collection, partial, collection,
+ @template.send!(:render_partial_collection, partial, collection,
options[:spacer_template], options[:locals]), options[:status]
)
else
render_for_text(
- @template.send(:render_partial, partial,
+ @template.send!(:render_partial, partial,
ActionView::Base::ObjectWrapper.new(options[:object]), options[:locals]), options[:status]
)
end
elsif options[:update]
add_variables_to_assigns
- @template.send :evaluate_assigns
+ @template.send! :evaluate_assigns
generator = ActionView::Helpers::PrototypeHelper::JavaScriptGenerator.new(@template, &block)
response.content_type = Mime::JS
@@ -1104,7 +1104,7 @@ def perform_action
send(action_name)
render unless performed?
elsif respond_to? :method_missing
- send(:method_missing, action_name)
+ method_missing action_name
render unless performed?
elsif template_exists? && template_public?
render
@@ -1135,7 +1135,7 @@ def action_methods
end
def self.action_methods
- @action_methods ||= Set.new(public_instance_methods - hidden_actions)
+ @action_methods ||= Set.new(public_instance_methods.map(&:to_s)) - hidden_actions
end
def add_variables_to_assigns
12 actionpack/lib/action_controller/caching.rb
View
@@ -238,7 +238,7 @@ 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)
+ controller.send!(:render_for_text, cache)
false
else
controller.action_cache_path = cache_path
@@ -470,7 +470,7 @@ def initialize #:nodoc:
super
if ActionController::Base.allow_concurrency
@mutex = Mutex.new
- MemoryStore.send(:include, ThreadSafety)
+ MemoryStore.module_eval { include ThreadSafety }
end
end
end
@@ -560,7 +560,7 @@ def initialize(cache_path)
super(cache_path)
if ActionController::Base.allow_concurrency
@mutex = Mutex.new
- FileStore.send(:include, ThreadSafety)
+ FileStore.module_eval { include ThreadSafety }
end
end
end
@@ -642,13 +642,13 @@ def callback(timing)
controller_callback_method_name = "#{timing}_#{controller.controller_name.underscore}"
action_callback_method_name = "#{controller_callback_method_name}_#{controller.action_name}"
- send(controller_callback_method_name) if respond_to?(controller_callback_method_name)
- send(action_callback_method_name) if respond_to?(action_callback_method_name)
+ send!(controller_callback_method_name) if respond_to?(controller_callback_method_name, true)
+ send!(action_callback_method_name) if respond_to?(action_callback_method_name, true)
end
def method_missing(method, *arguments)
return if @controller.nil?
- @controller.send(method, *arguments)
+ @controller.send!(method, *arguments)
end
end
end
6 actionpack/lib/action_controller/cgi_process.rb
View
@@ -42,7 +42,7 @@ class CgiRequest < AbstractRequest #:nodoc:
def initialize(cgi, session_options = {})
@cgi = cgi
@session_options = session_options
- @env = @cgi.send(:env_table)
+ @env = @cgi.send!(:env_table)
super()
end
@@ -138,7 +138,7 @@ def reset_session
end
def method_missing(method_id, *arguments)
- @cgi.send(method_id, *arguments) rescue super
+ @cgi.send!(method_id, *arguments) rescue super
end
private
@@ -191,7 +191,7 @@ def out(output = $stdout)
begin
output.write(@cgi.header(@headers))
- if @cgi.send(:env_table)['REQUEST_METHOD'] == 'HEAD'
+ if @cgi.send!(:env_table)['REQUEST_METHOD'] == 'HEAD'
return
elsif @body.respond_to?(:call)
# Flush the output now in case the @body Proc uses
22 actionpack/lib/action_controller/components.rb
View
@@ -36,20 +36,20 @@ module ActionController #:nodoc:
# So to repeat: Components are a special-purpose approach that can often be replaced with better use of partials and filters.
module Components
def self.included(base) #:nodoc:
- base.send :include, InstanceMethods
- base.extend(ClassMethods)
+ base.class_eval do
+ include InstanceMethods
+ extend ClassMethods
- base.helper do
- def render_component(options)
- @controller.send(:render_component_as_string, options)
+ helper do
+ def render_component(options)
+ @controller.send!(:render_component_as_string, options)
+ end
end
- end
- # If this controller was instantiated to process a component request,
- # +parent_controller+ points to the instantiator of this controller.
- base.send :attr_accessor, :parent_controller
+ # If this controller was instantiated to process a component request,
+ # +parent_controller+ points to the instantiator of this controller.
+ attr_accessor :parent_controller
- base.class_eval do
alias_method_chain :process_cleanup, :components
alias_method_chain :set_session_options, :components
alias_method_chain :flash, :components
@@ -162,4 +162,4 @@ def process_cleanup_with_components
end
end
end
-end
+end
13 actionpack/lib/action_controller/dispatcher.rb
View
@@ -71,7 +71,7 @@ def failsafe_response_body(status)
end
def log_failsafe_exception(status, exception)
- message = "/!\ FAILSAFE /!\ #{Time.now}\n Status: #{status}\n"
+ message = "/!\\ FAILSAFE /!\\ #{Time.now}\n Status: #{status}\n"
message << " #{exception}\n #{exception.backtrace.join("\n ")}" if exception
failsafe_logger.fatal message
end
@@ -136,7 +136,12 @@ def reload_application
end
def prepare_application(force = false)
- require_dependency 'application' unless defined?(::ApplicationController)
+ begin
+ require_dependency 'application' unless defined?(::ApplicationController)
+ rescue LoadError => error
+ raise unless error.message =~ /application\.rb/
+ end
+
ActiveRecord::Base.verify_active_connections! if defined?(ActiveRecord)
if unprepared || force
@@ -166,10 +171,10 @@ def handle_request
end
def run_callbacks(kind, enumerator = :each)
- callbacks[kind].send(enumerator) do |callback|
+ callbacks[kind].send!(enumerator) do |callback|
case callback
when Proc; callback.call(self)
- when String, Symbol; send(callback)
+ when String, Symbol; send!(callback)
when Array; callback[1].call(self)
else raise ArgumentError, "Unrecognized callback #{callback.inspect}"
end
14 actionpack/lib/action_controller/filters.rb
View
@@ -1,8 +1,10 @@
module ActionController #:nodoc:
module Filters #:nodoc:
def self.included(base)
- base.extend(ClassMethods)
- base.send(:include, ActionController::Filters::InstanceMethods)
+ base.class_eval do
+ extend ClassMethods
+ include ActionController::Filters::InstanceMethods
+ end
end
# Filters enable controllers to run shared pre and post processing code for its actions. These filters can be used to do
@@ -440,7 +442,7 @@ def type
def run(controller)
# only filters returning false are halted.
if false == @filter.call(controller)
- controller.send :halt_filter_chain, @filter, :returned_false
+ controller.send! :halt_filter_chain, @filter, :returned_false
end
end
@@ -466,7 +468,7 @@ def call(controller)
class SymbolFilter < Filter #:nodoc:
def call(controller, &block)
- controller.send(@filter, &block)
+ controller.send!(@filter, &block)
end
end
@@ -656,7 +658,7 @@ def proxy_before_and_after_filter(filter) #:nodoc:
return filter unless filter_responds_to_before_and_after(filter)
Proc.new do |controller, action|
if filter.before(controller) == false
- controller.send :halt_filter_chain, filter, :returned_false
+ controller.send! :halt_filter_chain, filter, :returned_false
else
begin
action.call
@@ -754,4 +756,4 @@ def halt_filter_chain(filter, reason)
end
end
end
-end
+end
5 actionpack/lib/action_controller/flash.rb
View
@@ -25,9 +25,8 @@ module ActionController #:nodoc:
# See docs on the FlashHash class for more details about the flash.
module Flash
def self.included(base)
- base.send :include, InstanceMethods
-
base.class_eval do
+ include InstanceMethods
alias_method_chain :assign_shortcuts, :flash
alias_method_chain :process_cleanup, :flash
alias_method_chain :reset_session, :flash
@@ -175,4 +174,4 @@ def process_cleanup_with_flash
end
end
end
-end
+end
18 actionpack/lib/action_controller/helpers.rb
View
@@ -68,7 +68,7 @@ module ClassMethods
# See ActionView::Helpers (link:classes/ActionView/Helpers.html) for more about making your own helper modules
# available to the templates.
def add_template_helper(helper_module) #:nodoc:
- master_helper_module.send(:include, helper_module)
+ master_helper_module.module_eval { include helper_module }
end
# The +helper+ class method can take a series of helper module names, a block, or both.
@@ -169,10 +169,12 @@ def helper_attr(*attrs)
private
def default_helper_module!
- module_name = name.sub(/Controller$|$/, 'Helper')
- module_path = module_name.split('::').map { |m| m.underscore }.join('/')
- require_dependency module_path
- helper module_name.constantize
+ unless name.blank?
+ module_name = name.sub(/Controller$|$/, 'Helper')
+ module_path = module_name.split('::').map { |m| m.underscore }.join('/')
+ require_dependency module_path
+ helper module_name.constantize
+ end
rescue MissingSourceFile => e
raise unless e.is_missing? module_path
logger.debug("#{name}: missing default helper path #{module_path}") if logger
@@ -186,8 +188,8 @@ def inherited_with_helper(child)
begin
child.master_helper_module = Module.new
- child.master_helper_module.send :include, master_helper_module
- child.send :default_helper_module!
+ child.master_helper_module.send! :include, master_helper_module
+ child.send! :default_helper_module!
rescue MissingSourceFile => e
raise unless e.is_missing?("helpers/#{child.controller_path}_helper")
end
@@ -200,4 +202,4 @@ def all_application_helpers
end
end
end
-end
+end
6 actionpack/lib/action_controller/http_authentication.rb
View
@@ -121,9 +121,9 @@ def encode_credentials(user_name, password)
def authentication_request(controller, realm)
controller.headers["WWW-Authenticate"] = %(Basic realm="#{realm.gsub(/"/, "")}")
- controller.send :render, :text => "HTTP Basic: Access denied.\n", :status => :unauthorized
- return false
+ controller.send! :render, :text => "HTTP Basic: Access denied.\n", :status => :unauthorized
+ return false
end
end
end
-end
+end
16 actionpack/lib/action_controller/integration.rb
View
@@ -83,7 +83,7 @@ def reset!
# the helpers are made protected by default--we make them public for
# easier access during testing and troubleshooting.
- klass.send(:public, *Routing::Routes.named_routes.helpers)
+ klass.module_eval { public *Routing::Routes.named_routes.helpers }
@named_routes_configured = true
end
end
@@ -252,7 +252,7 @@ def process(method, path, parameters = nil, headers = nil)
end
unless ActionController::Base.respond_to?(:clear_last_instantiation!)
- ActionController::Base.send(:include, ControllerCapture)
+ ActionController::Base.module_eval { include ControllerCapture }
end
ActionController::Base.clear_last_instantiation!
@@ -498,7 +498,7 @@ def reset!
reset! unless @integration_session
# reset the html_document variable, but only for new get/post calls
@html_document = nil unless %w(cookies assigns).include?(method)
- returning @integration_session.send(method, *args) do
+ returning @integration_session.send!(method, *args) do
copy_session_variables!
end
end
@@ -522,11 +522,11 @@ def open_session
self.class.fixture_table_names.each do |table_name|
name = table_name.tr(".", "_")
next unless respond_to?(name)
- extras.send(:define_method, name) { |*args| delegate.send(name, *args) }
+ extras.send!(:define_method, name) { |*args| delegate.send(name, *args) }
end
# delegate add_assertion to the test case
- extras.send(:define_method, :add_assertion) { test_result.add_assertion }
+ extras.send!(:define_method, :add_assertion) { test_result.add_assertion }
session.extend(extras)
session.delegate = self
session.test_result = @_result
@@ -540,16 +540,16 @@ def open_session
def copy_session_variables! #:nodoc:
return unless @integration_session
%w(controller response request).each do |var|
- instance_variable_set("@#{var}", @integration_session.send(var))
+ instance_variable_set("@#{var}", @integration_session.send!(var))
end
end
# Delegate unhandled messages to the current session instance.
def method_missing(sym, *args, &block)
reset! unless @integration_session
- returning @integration_session.send(sym, *args, &block) do
+ returning @integration_session.send!(sym, *args, &block) do
copy_session_variables!
end
end
end
-end
+end
10 actionpack/lib/action_controller/layout.rb
View
@@ -194,8 +194,10 @@ def layout_list #:nodoc:
private
def inherited_with_layout(child)
inherited_without_layout(child)
- layout_match = child.name.underscore.sub(/_controller$/, '').sub(/^controllers\//, '')
- child.layout(layout_match, {}, true) unless child.layout_list.grep(%r{layouts/#{layout_match}(\.[a-z][0-9a-z]*)+$}).empty?
+ unless child.name.blank?
+ layout_match = child.name.underscore.sub(/_controller$/, '').sub(/^controllers\//, '')
+ child.layout(layout_match, {}, true) unless child.layout_list.grep(%r{layouts/#{layout_match}(\.[a-z][0-9a-z]*)+$}).empty?
+ end
end
def add_layout_conditions(conditions)
@@ -230,7 +232,7 @@ def active_layout(passed_layout = nil)
layout = passed_layout || self.class.default_layout(response.template.template_format)
active_layout = case layout
when String then layout
- when Symbol then send(layout)
+ when Symbol then send!(layout)
when Proc then layout.call(self)
end
@@ -316,7 +318,7 @@ def action_has_layout?
def layout_directory?(layout_name)
view_paths.find do |path|
next unless template_path = Dir[File.join(path, 'layouts', layout_name) + ".*"].first
- self.class.send(:layout_directory_exists_cache)[File.dirname(template_path)]
+ self.class.send!(:layout_directory_exists_cache)[File.dirname(template_path)]
end
end
end
6 actionpack/lib/action_controller/mime_responds.rb
View
@@ -1,7 +1,9 @@
module ActionController #:nodoc:
module MimeResponds #:nodoc:
def self.included(base)
- base.send(:include, ActionController::MimeResponds::InstanceMethods)
+ base.module_eval do
+ include ActionController::MimeResponds::InstanceMethods
+ end
end
module InstanceMethods
@@ -176,4 +178,4 @@ def respond
end
end
end
-end
+end
6 actionpack/lib/action_controller/mime_type.rb
View
@@ -59,9 +59,9 @@ def register_alias(string, symbol, extension_synonyms = [])
end
def register(string, symbol, mime_type_synonyms = [], extension_synonyms = [], skip_lookup = false)
- Mime.send :const_set, symbol.to_s.upcase, Type.new(string, symbol, mime_type_synonyms)
+ Mime.instance_eval { const_set symbol.to_s.upcase, Type.new(string, symbol, mime_type_synonyms) }
- SET << Mime.send(:const_get, symbol.to_s.upcase)
+ SET << Mime.const_get(symbol.to_s.upcase)
([string] + mime_type_synonyms).each { |string| LOOKUP[string] = SET.last } unless skip_lookup
([symbol.to_s] + extension_synonyms).each { |ext| EXTENSION_LOOKUP[ext] = SET.last }
@@ -160,4 +160,4 @@ def method_missing(method, *args)
end
end
-require 'action_controller/mime_types'
+require 'action_controller/mime_types'
16 actionpack/lib/action_controller/polymorphic_routes.rb
View
@@ -6,8 +6,8 @@ def polymorphic_url(record_or_hash_or_array, options = {})
namespace = extract_namespace(record_or_hash_or_array)
args = case record_or_hash_or_array
- when Hash: [ record_or_hash_or_array ]
- when Array: record_or_hash_or_array.dup
+ when Hash; [ record_or_hash_or_array ]
+ when Array; record_or_hash_or_array.dup
else [ record_or_hash_or_array ]
end
@@ -24,7 +24,7 @@ def polymorphic_url(record_or_hash_or_array, options = {})
end
named_route = build_named_route_call(record_or_hash_or_array, namespace, inflection, options)
- send(named_route, *args)
+ send!(named_route, *args)
end
def polymorphic_path(record_or_hash_or_array)
@@ -55,10 +55,10 @@ def routing_type(options)
def build_named_route_call(records, namespace, inflection, options = {})
records = Array.new([extract_record(records)]) unless records.is_a?(Array)
- base_segment = "#{RecordIdentifier.send("#{inflection}_class_name", records.pop)}_"
+ base_segment = "#{RecordIdentifier.send!("#{inflection}_class_name", records.pop)}_"
method_root = records.reverse.inject(base_segment) do |string, name|
- segment = "#{RecordIdentifier.send("singular_class_name", name)}_"
+ segment = "#{RecordIdentifier.send!("singular_class_name", name)}_"
segment << string
end
@@ -67,8 +67,8 @@ def build_named_route_call(records, namespace, inflection, options = {})
def extract_record(record_or_hash_or_array)
case record_or_hash_or_array
- when Array: record_or_hash_or_array.last
- when Hash: record_or_hash_or_array[:id]
+ when Array; record_or_hash_or_array.last
+ when Hash; record_or_hash_or_array[:id]
else record_or_hash_or_array
end
end
@@ -85,4 +85,4 @@ def extract_namespace(record_or_hash_or_array)
end
end
end
-end
+end
23 actionpack/lib/action_controller/request.rb
View
@@ -109,7 +109,7 @@ def format=(extension)
# "XMLHttpRequest". (The Prototype Javascript library sends this header with
# every Ajax request.)
def xml_http_request?
- not /XMLHttpRequest/i.match(@env['HTTP_X_REQUESTED_WITH']).nil?
+ !(@env['HTTP_X_REQUESTED_WITH'] !~ /XMLHttpRequest/i)
end
alias xhr? :xml_http_request?
@@ -120,13 +120,10 @@ def xml_http_request?
# delimited list in the case of multiple chained proxies; the first is
# the originating IP.
#
- # Security note: Be aware that since remote_ip will check regular HTTP headers,
- # it can be tricked by anyone setting those manually. In other words, people can
- # pose as whatever IP address they like to this method. That doesn't matter if
- # all your doing is using IP addresses for statistical or geographical information,
- # but if you want to, for example, limit access to an administrative area by IP,
- # you should instead use Request#remote_addr, which can't be spoofed (but also won't
- # survive proxy forwards).
+ # Security note: do not use if IP spoofing is a concern for your
+ # application. Since remote_ip checks HTTP headers for addresses forwarded
+ # by proxies, the client may send any IP. remote_addr can't be spoofed but
+ # also doesn't work behind a proxy, since it's always the proxy's IP.
def remote_ip
return @env['HTTP_CLIENT_IP'] if @env.include? 'HTTP_CLIENT_IP'
@@ -222,7 +219,13 @@ def request_uri
unless (env_qs = @env['QUERY_STRING']).nil? || env_qs.empty?
uri << '?' << env_qs
end
- @env['REQUEST_URI'] = uri
+
+ if uri.nil?
+ @env.delete('REQUEST_URI')
+ uri
+ else
+ @env['REQUEST_URI'] = uri
+ end
end
end
@@ -682,4 +685,4 @@ def type_conflict!(klass, value)
raise TypeError, "Conflicting types for parameter containers. Expected an instance of #{klass} but found an instance of #{value.class}. This can be caused by colliding Array and Hash parameters like qs[]=value&qs[key]=value."
end
end
-end
+end
4 actionpack/lib/action_controller/rescue.rb
View
@@ -150,7 +150,7 @@ def rescue_action_locally(exception)
add_variables_to_assigns
@template.instance_variable_set("@exception", exception)
@template.instance_variable_set("@rescues_path", File.dirname(rescues_path("stub")))
- @template.send(:assign_variables_from_controller)
+ @template.send!(:assign_variables_from_controller)
@template.instance_variable_set("@contents", @template.render_file(template_path_for_local_rescue(exception), false))
@@ -207,4 +207,4 @@ def clean_backtrace(exception)
end
end
end
-end
+end
14 actionpack/lib/action_controller/resources.rb
View
@@ -513,15 +513,17 @@ def action_options_for(action, resource, method = nil)
default_options = { :action => action.to_s }
require_id = !resource.kind_of?(SingletonResource)
case default_options[:action]
- when "index", "new" : default_options.merge(add_conditions_for(resource.conditions, method || :get)).merge(resource.requirements)
- when "create" : default_options.merge(add_conditions_for(resource.conditions, method || :post)).merge(resource.requirements)
- when "show", "edit" : default_options.merge(add_conditions_for(resource.conditions, method || :get)).merge(resource.requirements(require_id))
- when "update" : default_options.merge(add_conditions_for(resource.conditions, method || :put)).merge(resource.requirements(require_id))
- when "destroy" : default_options.merge(add_conditions_for(resource.conditions, method || :delete)).merge(resource.requirements(require_id))
+ when "index", "new"; default_options.merge(add_conditions_for(resource.conditions, method || :get)).merge(resource.requirements)
+ when "create"; default_options.merge(add_conditions_for(resource.conditions, method || :post)).merge(resource.requirements)
+ when "show", "edit"; default_options.merge(add_conditions_for(resource.conditions, method || :get)).merge(resource.requirements(require_id))
+ when "update"; default_options.merge(add_conditions_for(resource.conditions, method || :put)).merge(resource.requirements(require_id))
+ when "destroy"; default_options.merge(add_conditions_for(resource.conditions, method || :delete)).merge(resource.requirements(require_id))
else default_options.merge(add_conditions_for(resource.conditions, method)).merge(resource.requirements)
end
end
end
end
-ActionController::Routing::RouteSet::Mapper.send :include, ActionController::Resources
+class ActionController::Routing::RouteSet::Mapper
+ include ActionController::Resources
+end
20 actionpack/lib/action_controller/routing.rb
View
@@ -1092,7 +1092,7 @@ def clear!
@module ||= Module.new
@module.instance_methods.each do |selector|
- @module.send :remove_method, selector
+ @module.class_eval { remove_method selector }
end
end
@@ -1132,7 +1132,9 @@ def reset!
def install(destinations = [ActionController::Base, ActionView::Base], regenerate = false)
reset! if regenerate
- Array(destinations).each { |dest| dest.send :include, @module }
+ Array(destinations).each do |dest|
+ dest.send! :include, @module
+ end
end
private
@@ -1154,12 +1156,12 @@ def define_named_route_methods(name, route)
def define_hash_access(route, name, kind, options)
selector = hash_access_name(name, kind)
- @module.send :module_eval, <<-end_eval # We use module_eval to avoid leaks
+ @module.module_eval <<-end_eval # We use module_eval to avoid leaks
def #{selector}(options = nil)
options ? #{options.inspect}.merge(options) : #{options.inspect}
end
+ protected :#{selector}
end_eval
- @module.send(:protected, selector)
helpers << selector
end
@@ -1182,7 +1184,7 @@ def define_url_helper(route, name, kind, options)
#
# foo_url(bar, baz, bang, :sort_by => 'baz')
#
- @module.send :module_eval, <<-end_eval # We use module_eval to avoid leaks
+ @module.module_eval <<-end_eval # We use module_eval to avoid leaks
def #{selector}(*args)
#{generate_optimisation_block(route, kind)}
@@ -1199,8 +1201,8 @@ def #{selector}(*args)
url_for(#{hash_access_method}(opts))
end
+ protected :#{selector}
end_eval
- @module.send(:protected, selector)
helpers << selector
end
end
@@ -1232,7 +1234,7 @@ def clear!
end
def install_helpers(destinations = [ActionController::Base, ActionView::Base], regenerate_code = false)
- Array(destinations).each { |d| d.send :include, Helpers }
+ Array(destinations).each { |d| d.module_eval { include Helpers } }
named_routes.install(destinations, regenerate_code)
end
@@ -1362,7 +1364,7 @@ def generate(options, recall = {}, method=:generate)
if generate_all
# Used by caching to expire all paths for a resource
return routes.collect do |route|
- route.send(method, options, merged, expire_on)
+ route.send!(method, options, merged, expire_on)
end.compact
end
@@ -1370,7 +1372,7 @@ def generate(options, recall = {}, method=:generate)
routes = routes_by_controller[controller][action][options.keys.sort_by { |x| x.object_id }]
routes.each do |route|
- results = route.send(method, options, merged, expire_on)
+ results = route.send!(method, options, merged, expire_on)
return results if results && (!results.is_a?(Array) || results.first)
end
end
9 actionpack/lib/action_controller/session_management.rb
View
@@ -8,10 +8,11 @@
module ActionController #:nodoc:
module SessionManagement #:nodoc:
def self.included(base)
- base.extend(ClassMethods)
-
- base.send :alias_method_chain, :process, :session_management_support
- base.send :alias_method_chain, :process_cleanup, :session_management_support
+ base.class_eval do
+ extend ClassMethods
+ alias_method_chain :process, :session_management_support
+ alias_method_chain :process_cleanup, :session_management_support
+ end
end
module ClassMethods
18 actionpack/lib/action_controller/test_process.rb
View
@@ -357,7 +357,7 @@ def path #:nodoc:
alias local_path path
def method_missing(method_name, *args, &block) #:nodoc:
- @tempfile.send(method_name, *args, &block)
+ @tempfile.send!(method_name, *args, &block)
end
end
@@ -379,7 +379,7 @@ def process(action, parameters = nil, session = nil, flash = nil)
# Sanity check for required instance variables so we can give an
# understandable error message.
%w(@controller @request @response).each do |iv_name|
- if !instance_variables.include?(iv_name) || instance_variable_get(iv_name).nil?
+ if !(instance_variables.include?(iv_name) || instance_variables.include?(iv_name.to_sym)) || instance_variable_get(iv_name).nil?
raise "#{iv_name} is nil: make sure you set it in your test's setup method."
end
end
@@ -402,7 +402,7 @@ def process(action, parameters = nil, session = nil, flash = nil)
def xml_http_request(request_method, action, parameters = nil, session = nil, flash = nil)
@request.env['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
@request.env['HTTP_ACCEPT'] = 'text/javascript, text/html, application/xml, text/xml, */*'
- returning self.send(request_method, action, parameters, session, flash) do
+ returning send!(request_method, action, parameters, session, flash) do
@request.env.delete 'HTTP_X_REQUESTED_WITH'
@request.env.delete 'HTTP_ACCEPT'
end
@@ -444,7 +444,7 @@ def redirect_to_url
def build_request_uri(action, parameters)
unless @request.env['REQUEST_URI']
- options = @controller.send(:rewrite_options, parameters)
+ options = @controller.send!(:rewrite_options, parameters)
options.update(:only_path => true, :action => action)
url = ActionController::UrlRewriter.new(@request, parameters)
@@ -466,7 +466,7 @@ def find_all_tag(conditions)
end
def method_missing(selector, *args)
- return @controller.send(selector, *args) if ActionController::Routing::Routes.named_routes.helpers.include?(selector)
+ return @controller.send!(selector, *args) if ActionController::Routing::Routes.named_routes.helpers.include?(selector)
return super
end
@@ -502,15 +502,15 @@ def fixture_file_upload(path, mime_type = nil, binary = false)
#
def with_routing
real_routes = ActionController::Routing::Routes
- ActionController::Routing.send :remove_const, :Routes
+ ActionController::Routing.module_eval { remove_const :Routes }
temporary_routes = ActionController::Routing::RouteSet.new
- ActionController::Routing.send :const_set, :Routes, temporary_routes
-
+ ActionController::Routing.module_eval { const_set :Routes, temporary_routes }
+
yield temporary_routes
ensure
if ActionController::Routing.const_defined? :Routes
- ActionController::Routing.send(:remove_const, :Routes)
+ ActionController::Routing.module_eval { remove_const :Routes }
end
ActionController::Routing.const_set(:Routes, real_routes) if real_routes
end
4 actionpack/lib/action_controller/verification.rb
View
@@ -72,7 +72,7 @@ module ClassMethods
def verify(options={})
filter_opts = { :only => options[:only], :except => options[:except] }
before_filter(filter_opts) do |c|
- c.send :verify_action, options
+ c.send! :verify_action, options
end
end
end
@@ -95,7 +95,7 @@ def verify_action(options) #:nodoc:
response.headers.update(options[:add_headers]) if options[:add_headers]
unless performed?
render(options[:render]) if options[:render]
- options[:redirect_to] = self.send(options[:redirect_to]) if options[:redirect_to].is_a? Symbol
+ options[:redirect_to] = self.send!(options[:redirect_to]) if options[:redirect_to].is_a? Symbol
redirect_to(options[:redirect_to]) if options[:redirect_to]
end
return false
10 actionpack/lib/action_view/helpers/number_helper.rb
View
@@ -164,11 +164,11 @@ def number_with_precision(number, precision=3)
def number_to_human_size(size, precision=1)
size = Kernel.Float(size)
case
- when size.to_i == 1 : "1 Byte"
- when size < 1.kilobyte: "%d Bytes" % size
- when size < 1.megabyte: "%.#{precision}f KB" % (size / 1.0.kilobyte)
- when size < 1.gigabyte: "%.#{precision}f MB" % (size / 1.0.megabyte)
- when size < 1.terabyte: "%.#{precision}f GB" % (size / 1.0.gigabyte)
+ when size.to_i == 1; "1 Byte"
+ when size < 1.kilobyte; "%d Bytes" % size
+ when size < 1.megabyte; "%.#{precision}f KB" % (size / 1.0.kilobyte)
+ when size < 1.gigabyte; "%.#{precision}f MB" % (size / 1.0.megabyte)
+ when size < 1.terabyte; "%.#{precision}f GB" % (size / 1.0.gigabyte)
else "%.#{precision}f TB" % (size / 1.0.terabyte)
end.sub(/([0-9])\.?0+ /, '\1 ' )
rescue
2  actionpack/lib/action_view/helpers/text_helper.rb
View
@@ -580,7 +580,7 @@ def to_s
# Specifies a Set of 'bad' tags that the #sanitize helper will remove completely, as opposed
# to just escaping harmless tags like &lt;font&gt;
- @@sanitized_bad_tags = Set.new('script')
+ @@sanitized_bad_tags = Set.new(%w(script))
mattr_reader :sanitized_bad_tags
# Specifies the default Set of tags that the #sanitize helper will allow unscathed.
8 actionpack/test/controller/base_test.rb
View
@@ -75,11 +75,11 @@ def setup
def test_action_methods
@empty_controllers.each do |c|
hide_mocha_methods_from_controller(c)
- assert_equal Set.new, c.send(:action_methods), "#{c.controller_path} should be empty!"
+ assert_equal Set.new, c.send!(:action_methods), "#{c.controller_path} should be empty!"
end
@non_empty_controllers.each do |c|
hide_mocha_methods_from_controller(c)
- assert_equal Set.new('public_action'), c.send(:action_methods), "#{c.controller_path} should not be empty!"
+ assert_equal Set.new(%w(public_action)), c.send!(:action_methods), "#{c.controller_path} should not be empty!"
end
end
@@ -88,7 +88,7 @@ def test_action_methods
# considered actions, so explicitly hide_action them.
def hide_mocha_methods_from_controller(controller)
mocha_methods = [:expects, :metaclass, :mocha, :mocha_inspect, :reset_mocha, :stubba_object, :stubba_method, :stubs, :verify, :__metaclass__, :__is_a__]
- controller.class.send(:hide_action, *mocha_methods)
+ controller.class.send!(:hide_action, *mocha_methods)
end
end
@@ -116,7 +116,7 @@ def test_get_on_priv_should_show_selector
def test_method_missing_is_not_an_action_name
use_controller MethodMissingController
- assert ! @controller.send(:action_methods).include?('method_missing')
+ assert ! @controller.send!(:action_methods).include?('method_missing')
get :method_missing
assert_response :success
12 actionpack/test/controller/dispatcher_test.rb
View
@@ -52,12 +52,12 @@ def test_reload_application_sets_unprepared_if_loading_dependencies
Dependencies.stubs(:load?).returns(false)
ActionController::Routing::Routes.expects(:reload).never
@dispatcher.unprepared = false
- @dispatcher.send(:reload_application)
+ @dispatcher.send!(:reload_application)
assert !@dispatcher.unprepared
Dependencies.stubs(:load?).returns(true)
ActionController::Routing::Routes.expects(:reload).once
- @dispatcher.send(:reload_application)
+ @dispatcher.send!(:reload_application)
assert @dispatcher.unprepared
end
@@ -69,19 +69,19 @@ def test_prepare_application_runs_callbacks_if_unprepared
# Skip the callbacks when already prepared.
@dispatcher.unprepared = false
- @dispatcher.send :prepare_application
+ @dispatcher.send! :prepare_application
assert_nil a || b || c
# Perform the callbacks when unprepared.
@dispatcher.unprepared = true
- @dispatcher.send :prepare_application
+ @dispatcher.send! :prepare_application
assert_equal 1, a
assert_equal 2, b
assert_equal 3, c
# But when not :load, make sure they are only run once
a = b = c = nil
- @dispatcher.send :prepare_application
+ @dispatcher.send! :prepare_application
assert_nil a || b || c
end
@@ -91,7 +91,7 @@ def test_to_prepare_with_identifier_replaces
Dispatcher.to_prepare(:unique_id) { a = 2 }
@dispatcher.unprepared = true
- @dispatcher.send :prepare_application
+ @dispatcher.send! :prepare_application
assert_equal 2, a
assert_equal nil, b
end
2  actionpack/test/controller/filters_test.rb
View
@@ -332,7 +332,7 @@ def filter(controller)
begin
yield
rescue ErrorToRescue => ex
- controller.send :render, :text => "I rescued this: #{ex.inspect}"
+ controller.send! :render, :text => "I rescued this: #{ex.inspect}"
end
end
end
2  actionpack/test/controller/integration_test.rb
View
@@ -212,7 +212,7 @@ def self.fixture_table_names
def test_integration_methods_called
%w( get post head put delete ).each do |verb|
- assert_nothing_raised("'#{verb}' should use integration test methods") { send(verb, '/') }
+ assert_nothing_raised("'#{verb}' should use integration test methods") { send!(verb, '/') }
end
end
16 actionpack/test/controller/layout_test.rb
View
@@ -93,16 +93,16 @@ def setup
end
def test_rjs_exempt_from_layout
- assert @controller.send(:template_exempt_from_layout?, 'test.rjs')
+ assert @controller.send!(:template_exempt_from_layout?, 'test.rjs')
end
def test_rhtml_and_rxml_not_exempt_from_layout
- assert !@controller.send(:template_exempt_from_layout?, 'test.rhtml')
- assert !@controller.send(:template_exempt_from_layout?, 'test.rxml')
+ assert !@controller.send!(:template_exempt_from_layout?, 'test.rhtml')
+ assert !@controller.send!(:template_exempt_from_layout?, 'test.rxml')
end
def test_other_extension_not_exempt_from_layout
- assert !@controller.send(:template_exempt_from_layout?, 'test.random')
+ assert !@controller.send!(:template_exempt_from_layout?, 'test.random')
end
def test_add_extension_to_exempt_from_layout
@@ -110,20 +110,20 @@ def test_add_extension_to_exempt_from_layout
assert_nothing_raised do
ActionController::Base.exempt_from_layout ext
end
- assert @controller.send(:template_exempt_from_layout?, "test.#{ext}")
+ assert @controller.send!(:template_exempt_from_layout?, "test.#{ext}")
end
end
def test_add_regexp_to_exempt_from_layout
ActionController::Base.exempt_from_layout /\.rdoc/
- assert @controller.send(:template_exempt_from_layout?, 'test.rdoc')
+ assert @controller.send!(:template_exempt_from_layout?, 'test.rdoc')
end
def test_rhtml_exempt_from_layout_status_should_prevent_layout_render
ActionController::Base.exempt_from_layout :rhtml
- assert @controller.send(:template_exempt_from_layout?, 'test.rhtml')
- assert @controller.send(:template_exempt_from_layout?, 'hello.rhtml')
+ assert @controller.send!(:template_exempt_from_layout?, 'test.rhtml')
+ assert @controller.send!(:template_exempt_from_layout?, 'hello.rhtml')
get :hello
assert_equal 'hello.rhtml', @response.body
36 actionpack/test/controller/mime_responds_test.rb
View
@@ -85,8 +85,8 @@ def custom_constant_handling
type.html { render :text => "HTML" }
type.mobile { render :text => "Mobile" }
end
-
- Mime.send :remove_const, :MOBILE
+ ensure
+ Mime.module_eval { remove_const :MOBILE if const_defined?(:MOBILE) }
end
def custom_constant_handling_without_block
@@ -97,7 +97,8 @@ def custom_constant_handling_without_block
type.mobile
end
- Mime.send :remove_const, :MOBILE
+ ensure
+ Mime.module_eval { remove_const :MOBILE if const_defined?(:MOBILE) }
end
def handle_any
@@ -123,7 +124,8 @@ def iphone_with_html_response_type
type.iphone { @type = "iPhone" }
end
- Mime.send :remove_const, :IPHONE
+ ensure
+ Mime.module_eval { remove_const :IPHONE if const_defined?(:IPHONE) }
end
def iphone_with_html_response_type_without_layout
@@ -135,7 +137,8 @@ def iphone_with_html_response_type_without_layout
type.iphone { @type = "iPhone" ; render :action => "iphone_with_html_response_type" }
end
- Mime.send :remove_const, :IPHONE
+ ensure
+ Mime.module_eval { remove_const :IPHONE if const_defined?(:IPHONE) }
end
def rescue_action(e)
@@ -444,24 +447,23 @@ def view_paths
# For testing layouts which are set automatically
class PostController < AbstractPostController
around_filter :with_iphone
-
+
def index
respond_to do |type|
type.html
type.iphone
end
end
-
+
protected
-
- def with_iphone
- Mime::Type.register_alias("text/html", :iphone)
- request.format = "iphone" if request.env["HTTP_ACCEPT"] == "text/iphone"
- yield
- Mime.send :remove_const, :IPHONE
- end
-
-end
+ def with_iphone
+ Mime::Type.register_alias("text/html", :iphone)
+ request.format = "iphone" if request.env["HTTP_ACCEPT"] == "text/iphone"
+ yield
+ ensure
+ Mime.module_eval { remove_const :IPHONE if const_defined?(:IPHONE) }
+ end
+end
class SuperPostController < PostController
def index
@@ -501,4 +503,4 @@ def test_format_with_inherited_layouts
assert_equal '<html><div id="super_iphone">Super iPhone</div></html>', @response.body
end
end
-
+
3  actionpack/test/controller/mime_type_test.rb
View
@@ -35,7 +35,8 @@ def test_custom_type
Mime::GIF
assert_equal Mime::GIF, Mime::SET.last
end
- Mime.send :remove_const, :GIF
+ ensure
+ Mime.module_eval { remove_const :GIF if const_defined?(:GIF) }
end
def test_type_convenience_methods
6 actionpack/test/controller/render_test.rb
View
@@ -157,9 +157,9 @@ def rescue_action(e) raise end
private
def determine_layout
case action_name
- when "layout_test": "layouts/standard"
- when "builder_layout_test": "layouts/builder"
- when "render_symbol_json": "layouts/standard" # to make sure layouts don't interfere
+ when "layout_test"; "layouts/standard"
+ when "builder_layout_test"; "layouts/builder"
+ when "render_symbol_json"; "layouts/standard" # to make sure layouts don't interfere
end
end
end
2  actionpack/test/controller/request_forgery_protection_test.rb
View
@@ -214,4 +214,4 @@ def test_should_allow_all_methods_without_token
assert_nothing_raised { send(method, :index)}
end
end
-end
+end
5 activerecord/test/abstract_unit.rb
View
@@ -60,9 +60,8 @@ def uses_mocha(test_name)
$stderr.puts "Skipping #{test_name} tests. `gem install mocha` and try again."
end
-ActiveRecord::Base.connection.class.class_eval do
-
- if not (const_get('IGNORED_SQL') rescue nil)
+ActiveRecord::Base.connection.class.class_eval do
+ unless defined? IGNORED_SQL
IGNORED_SQL = [/^PRAGMA/, /^SELECT currval/, /^SELECT CAST/, /^SELECT @@IDENTITY/]
def execute_with_counting(sql, name = nil, &block)
4 activeresource/lib/active_resource/base.rb
View
@@ -604,7 +604,7 @@ def hash
# next_invoice.customer
# # => That Company
def dup
- returning new do |resource|
+ returning self.class.new do |resource|
resource.attributes = @attributes
resource.prefix_options = @prefix_options
end
@@ -848,7 +848,7 @@ def find_or_create_resource_for(name)
end
def split_options(options = {})
- self.class.send(:split_options, options)
+ self.class.send!(:split_options, options)
end
def method_missing(method_symbol, *arguments) #:nodoc:
24 activeresource/lib/active_resource/custom_methods.rb
View
@@ -33,23 +33,24 @@ module ActiveResource
module CustomMethods
def self.included(within)
within.class_eval do
+ extend ActiveResource::CustomMethods::ClassMethods
+ include ActiveResource::CustomMethods::InstanceMethods
+
class << self
- include ActiveResource::CustomMethods::ClassMethods
-
alias :orig_delete :delete
-
+
def get(method_name, options = {})
connection.get(custom_method_collection_url(method_name, options), headers)
end
-
+
def post(method_name, options = {}, body = '')
connection.post(custom_method_collection_url(method_name, options), body, headers)
end
-
+
def put(method_name, options = {}, body = '')
connection.put(custom_method_collection_url(method_name, options), body, headers)
end
-
+
# Need to jump through some hoops to retain the original class 'delete' method
def delete(custom_method_name, options = {})
if (custom_method_name.is_a?(Symbol))
@@ -59,12 +60,9 @@ def delete(custom_method_name, options = {})
end
end
end
-
end
-
- within.send(:include, ActiveResource::CustomMethods::InstanceMethods)
end
-
+
module ClassMethods
def custom_method_collection_url(method_name, options = {})
prefix_options, query_options = split_options(options)
@@ -96,12 +94,12 @@ def delete(method_name, options = {})
private
def custom_method_element_url(method_name, options = {})
- "#{self.class.prefix(prefix_options)}#{self.class.collection_name}/#{id}/#{method_name}.xml#{self.class.send(:query_string, options)}"
+ "#{self.class.prefix(prefix_options)}#{self.class.collection_name}/#{id}/#{method_name}.xml#{self.class.send!(:query_string, options)}"
end
def custom_method_new_element_url(method_name, options = {})
- "#{self.class.prefix(prefix_options)}#{self.class.collection_name}/new/#{method_name}.xml#{self.class.send(:query_string, options)}"
+ "#{self.class.prefix(prefix_options)}#{self.class.collection_name}/new/#{method_name}.xml#{self.class.send!(:query_string, options)}"
end
end
end
-end
+end
2  activeresource/lib/active_resource/http_mock.rb
View
@@ -75,7 +75,7 @@ class Request
attr_accessor :path, :method, :body, :headers
def initialize(method, path, body = nil, headers = {})
- @method, @path, @body, @headers = method, path, body, headers
+ @method, @path, @body, @headers = method, path, body, headers.dup
@headers.update('Content-Type' => 'application/xml')
end
8 activeresource/test/authorization_test.rb
View
@@ -20,7 +20,7 @@ def setup
end
def test_authorization_header
- authorization_header = @authenticated_conn.send(:authorization_header)
+ authorization_header = @authenticated_conn.send!(:authorization_header)
assert_equal @authorization_request_header['Authorization'], authorization_header['Authorization']
authorization = authorization_header["Authorization"].to_s.split
@@ -30,7 +30,7 @@ def test_authorization_header
def test_authorization_header_with_username_but_no_password
@conn = ActiveResource::Connection.new("http://david:@localhost")
- authorization_header = @conn.send(:authorization_header)
+ authorization_header = @conn.send!(:authorization_header)
authorization = authorization_header["Authorization"].to_s.split
assert_equal "Basic", authorization[0]
@@ -39,7 +39,7 @@ def test_authorization_header_with_username_but_no_password
def test_authorization_header_with_password_but_no_username
@conn = ActiveResource::Connection.new("http://:test123@localhost")
- authorization_header = @conn.send(:authorization_header)
+ authorization_header = @conn.send!(:authorization_header)
authorization = authorization_header["Authorization"].to_s.split
assert_equal "Basic", authorization[0]
@@ -76,7 +76,7 @@ def test_raises_invalid_request_on_unauthorized_requests
protected
def assert_response_raises(klass, code)
assert_raise(klass, "Expected response code #{code} to raise #{klass}") do
- @conn.send(:handle_response, Response.new(code))
+ @conn.send!(:handle_response, Response.new(code))
end
end
end
6 activeresource/test/base/load_test.rb
View
@@ -61,7 +61,7 @@ def test_load_collection_with_existing_resource
end
def test_load_collection_with_unknown_resource
- Person.send(:remove_const, :Address) if Person.const_defined?(:Address)
+ Person.send!(:remove_const, :Address) if Person.const_defined?(:Address)
assert !Person.const_defined?(:Address), "Address shouldn't exist until autocreated"
addresses = silence_warnings { @person.load(:addresses => @addresses).addresses }
assert Person.const_defined?(:Address), "Address should have been autocreated"
@@ -77,7 +77,7 @@ def test_load_collection_with_single_existing_resource
end
def test_load_collection_with_single_unknown_resource
- Person.send(:remove_const, :Address) if Person.const_defined?(:Address)
+ Person.send!(:remove_const, :Address) if Person.const_defined?(:Address)
assert !Person.const_defined?(:Address), "Address shouldn't exist until autocreated"
addresses = silence_warnings { @person.load(:addresses => [ @first_address ]).addresses }
assert Person.const_defined?(:Address), "Address should have been autocreated"
@@ -108,4 +108,4 @@ def test_nested_collections_within_the_same_namespace
n = Highrise::Note.new(:comments => [{ :name => "1" }])
assert_kind_of Highrise::Comment, n.comments.first
end
-end
+end
6 activeresource/test/base_errors_test.rb
View
@@ -29,13 +29,13 @@ def test_should_parse_errors_to_individual_attributes
def test_should_iterate_over_errors
errors = []
@person.errors.each { |attribute, message| errors << [attribute, message] }
- assert_equal ["name", "can't be blank"], errors.first
+ assert errors.include?(["name", "can't be blank"])
end
def test_should_iterate_over_full_errors
errors = []
@person.errors.each_full { |message| errors << message }
- assert_equal "Name can't be blank", errors.first
+ assert errors.include?("Name can't be blank")
end
def test_should_format_full_errors
@@ -45,4 +45,4 @@ def test_should_format_full_errors
assert full.include?("Name must start with a letter")
assert full.include?("Person quota full for today.")
end
-end
+end
13 activeresource/test/base_test.rb
View
@@ -181,7 +181,7 @@ def test_custom_collection_name
def test_prefix
assert_equal "/", Person.prefix
- assert_equal Set.new, Person.send(:prefix_parameters)
+ assert_equal Set.new, Person.send!(:prefix_parameters)
end
def test_set_prefix
@@ -208,7 +208,7 @@ def test_set_prefix_with_default_value
def test_custom_prefix
assert_equal '/people//', StreetAddress.prefix
assert_equal '/people/1/', StreetAddress.prefix(:person_id => 1)
- assert_equal [:person_id].to_set, StreetAddress.send(:prefix_parameters)
+ assert_equal [:person_id].to_set, StreetAddress.send!(:prefix_parameters)
end
def test_find_by_id
@@ -305,10 +305,10 @@ def test_save
def test_id_from_response
p = Person.new
resp = {'Location' => '/foo/bar/1'}
- assert_equal '1', p.send(:id_from_response, resp)
+ assert_equal '1', p.send!(:id_from_response, resp)
resp['Location'] << '.xml'
- assert_equal '1', p.send(:id_from_response, resp)
+ assert_equal '1', p.send!(:id_from_response, resp)
end
def test_create_with_custom_prefix
@@ -439,6 +439,9 @@ def test_exists
def test_to_xml
matz = Person.find(1)
- assert_equal "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<person>\n <name>Matz</name>\n <id type=\"integer\">1</id>\n</person>\n", matz.to_xml
+ xml = matz.to_xml
+ assert xml.starts_with?('<?xml version="1.0" encoding="UTF-8"?>')
+ assert xml.include?('<name>Matz</name>')
+ assert xml.include?('<id type="integer">1</id>')
end
end
4 activeresource/test/connection_test.rb
View
@@ -13,7 +13,7 @@ def setup
@people_empty = [ ].to_xml(:root => 'people-empty-elements')
@matz = @matz.to_xml(:root => 'person')
@david = @david.to_xml(:root => 'person')
- @header = {'key' => 'value'}
+ @header = {'key' => 'value'}.freeze
@default_request_headers = { 'Content-Type' => 'application/xml' }
ActiveResource::HttpMock.respond_to do |mock|
@@ -156,6 +156,6 @@ def assert_response_raises(klass, code)
end
def handle_response(response)
- @conn.send(:handle_response, response)
+ @conn.send!(:handle_response, response)
end
end
2  activeresource/test/fixtures/person.rb
View
@@ -1,3 +1,3 @@
class Person < ActiveResource::Base
self.site = "http://37s.sunrise.i:3000"
-end
+end
2  activesupport/lib/active_support/clean_logger.rb
View
@@ -1,5 +1,5 @@
require 'logger'
-require File.dirname(__FILE__) + '/core_ext/class/attribute_accessors'
+require 'active_support/core_ext/class/attribute_accessors'
# Extensions to the built in Ruby logger.
#
5 activesupport/lib/active_support/core_ext.rb
View
@@ -1 +1,4 @@
-Dir[File.dirname(__FILE__) + "/core_ext/*.rb"].sort.each { |file| require(file) }
+Dir[File.dirname(__FILE__) + "/core_ext/*.rb"].sort.each do |path|
+ filename = File.basename(path)
+ require "active_support/core_ext/#{filename}"
+end
8 activesupport/lib/active_support/core_ext/array.rb
View
@@ -1,7 +1,7 @@
-require File.dirname(__FILE__) + '/array/conversions'
-require File.dirname(__FILE__) + '/array/extract_options'
-require File.dirname(__FILE__) + '/array/grouping'
-require File.dirname(__FILE__) + '/array/random_access'
+require 'active_support/core_ext/array/conversions'
+require 'active_support/core_ext/array/extract_options'
+require 'active_support/core_ext/array/grouping'
+require 'active_support/core_ext/array/random_access'
class Array #:nodoc:
include ActiveSupport::CoreExtensions::Array::Conversions
3  activesupport/lib/active_support/core_ext/bigdecimal.rb
View
@@ -1,3 +1,2 @@
require 'bigdecimal'
-
-require File.dirname(__FILE__) + '/bigdecimal/formatting.rb'
+require 'active_support/core_ext/bigdecimal/conversions'
3  .../active_support/core_ext/bigdecimal/formatting.rb → ...active_support/core_ext/bigdecimal/conversions.rb
View
@@ -1,7 +1,6 @@
class BigDecimal #:nodoc:
-
alias :_original_to_s :to_s
def to_s(format="F")
_original_to_s(format)
end
-end
+end
4 activesupport/lib/active_support/core_ext/cgi.rb
View
@@ -1,5 +1,5 @@
-require File.dirname(__FILE__) + '/cgi/escape_skipping_slashes'
+require 'active_support/core_ext/cgi/escape_skipping_slashes'
class CGI #:nodoc:
- extend(ActiveSupport::CoreExtensions::CGI::EscapeSkippingSlashes)
+ extend ActiveSupport::CoreExtensions::CGI::EscapeSkippingSlashes
end
6 activesupport/lib/active_support/core_ext/class.rb
View
@@ -1,3 +1,3 @@
-require File.dirname(__FILE__) + '/class/attribute_accessors'
-require File.dirname(__FILE__) + '/class/inheritable_attributes'
-require File.dirname(__FILE__) + '/class/removal'
+require 'active_support/core_ext/class/attribute_accessors'
+require 'active_support/core_ext/class/inheritable_attributes'
+require 'active_support/core_ext/class/removal'
6 activesupport/lib/active_support/core_ext/date.rb
View
@@ -1,7 +1,7 @@
require 'date'
-require File.dirname(__FILE__) + '/date/behavior'
-require File.dirname(__FILE__) + '/date/calculations'
-require File.dirname(__FILE__) + '/date/conversions'
+require 'active_support/core_ext/date/behavior'
+require 'active_support/core_ext/date/calculations'
+require 'active_support/core_ext/date/conversions'
class Date#:nodoc:
include ActiveSupport::CoreExtensions::Date::Behavior
6 activesupport/lib/active_support/core_ext/date_time.rb
View
@@ -1,7 +1,7 @@
require 'date'
-require "#{File.dirname(__FILE__)}/time/behavior"
-require "#{File.dirname(__FILE__)}/date_time/calculations"
-require "#{File.dirname(__FILE__)}/date_time/conversions"
+require 'active_support/core_ext/time/behavior'
+require 'active_support/core_ext/date_time/calculations'
+require 'active_support/core_ext/date_time/conversions'
class DateTime
include ActiveSupport::CoreExtensions::Time::Behavior
2  activesupport/lib/active_support/core_ext/float.rb
View
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/float/rounding'
+require 'active_support/core_ext/float/rounding'
class Float #:nodoc:
include ActiveSupport::CoreExtensions::Float::Rounding
2  activesupport/lib/active_support/core_ext/hash.rb
View
@@ -1,5 +1,5 @@
%w(keys indifferent_access reverse_merge conversions diff slice except).each do |ext|
- require "#{File.dirname(__FILE__)}/hash/#{ext}"
+ require "active_support/core_ext/hash/#{ext}"
end
class Hash #:nodoc:
4 activesupport/lib/active_support/core_ext/integer.rb
View
@@ -1,5 +1,5 @@
-require File.dirname(__FILE__) + '/integer/even_odd'
-require File.dirname(__FILE__) + '/integer/inflections'
+require 'active_support/core_ext/integer/even_odd'
+require 'active_support/core_ext/integer/inflections'
class Integer #:nodoc:
include ActiveSupport::CoreExtensions::Integer::EvenOdd
10 activesupport/lib/active_support/core_ext/kernel.rb
View
@@ -1,5 +1,5 @@
-require File.dirname(__FILE__) + '/kernel/daemonizing'
-require File.dirname(__FILE__) + '/kernel/reporting'
-require File.dirname(__FILE__) + '/kernel/agnostics'
-require File.dirname(__FILE__) + '/kernel/requires'
-require File.dirname(__FILE__) + '/kernel/debugger'
+require 'active_support/core_ext/kernel/daemonizing'
+require 'active_support/core_ext/kernel/reporting'
+require 'active_support/core_ext/kernel/agnostics'
+require 'active_support/core_ext/kernel/requires'
+require 'active_support/core_ext/kernel/debugger'
16 activesupport/lib/active_support/core_ext/module.rb
View
@@ -1,8 +1,8 @@
-require File.dirname(__FILE__) + '/module/inclusion'
-require File.dirname(__FILE__) + '/module/attribute_accessors'
-require File.dirname(__FILE__) + '/module/attr_internal'
-require File.dirname(__FILE__) + '/module/attr_accessor_with_default'
-require File.dirname(__FILE__) + '/module/delegation'
-require File.dirname(__FILE__) + '/module/introspection'
-require File.dirname(__FILE__) + '/module/loading'
-require File.dirname(__FILE__) + '/module/aliasing'
+require 'active_support/core_ext/module/inclusion'
+require 'active_support/core_ext/module/attribute_accessors'
+require 'active_support/core_ext/module/attr_internal'
+require 'active_support/core_ext/module/attr_accessor_with_default'
+require 'active_support/core_ext/module/delegation'
+require 'active_support/core_ext/module/introspection'
+require 'active_support/core_ext/module/loading'
+require 'active_support/core_ext/module/aliasing'
4 activesupport/lib/active_support/core_ext/numeric.rb
View
@@ -1,5 +1,5 @@
-require File.dirname(__FILE__) + '/numeric/time'
-require File.dirname(__FILE__) + '/numeric/bytes'
+require 'active_support/core_ext/numeric/time'
+require 'active_support/core_ext/numeric/bytes'
class Numeric #:nodoc:
include ActiveSupport::CoreExtensions::Numeric::Time
6 activesupport/lib/active_support/core_ext/object.rb
View
@@ -1,3 +1,3 @@
-require File.dirname(__FILE__) + '/object/extending'
-require File.dirname(__FILE__) + '/object/instance_variables'
-require File.dirname(__FILE__) + '/object/misc'
+require 'active_support/core_ext/object/extending'
+require 'active_support/core_ext/object/instance_variables'
+require 'active_support/core_ext/object/misc'
2  activesupport/lib/active_support/core_ext/pathname.rb
View
@@ -1,5 +1,5 @@
require 'pathname'
-require File.dirname(__FILE__) + '/pathname/clean_within'
+require 'active_support/core_ext/pathname/clean_within'
class Pathname#:nodoc:
extend ActiveSupport::CoreExtensions::Pathname::CleanWithin
2  activesupport/lib/active_support/core_ext/range.rb
View
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/range/conversions'
+require 'active_support/core_ext/range/conversions'
class Range #:nodoc:
include ActiveSupport::CoreExtensions::Range::Conversions
12 activesupport/lib/active_support/core_ext/string.rb
View
@@ -1,9 +1,9 @@
-require File.dirname(__FILE__) + '/string/inflections'
-require File.dirname(__FILE__) + '/string/conversions'
-require File.dirname(__FILE__) + '/string/access'
-require File.dirname(__FILE__) + '/string/starts_ends_with'
-require File.dirname(__FILE__) + '/string/iterators' unless 'test'.respond_to?(:each_char)
-require File.dirname(__FILE__) + '/string/unicode'
+require 'active_support/core_ext/string/inflections'
+require 'active_support/core_ext/string/conversions'
+require 'active_support/core_ext/string/access'
+require 'active_support/core_ext/string/starts_ends_with'
+require 'active_support/core_ext/string/iterators' unless 'test'.respond_to?(:each_char)
+require 'active_support/core_ext/string/unicode'
class String #:nodoc:
include ActiveSupport::CoreExtensions::String::Access
3  activesupport/lib/active_support/core_ext/test.rb
View
@@ -1,2 +1 @@
-require File.dirname(__FILE__) + '/test/difference'
-
+require 'active_support/core_ext/test/unit/assertions'
0  ...rt/lib/active_support/core_ext/test/difference.rb → ...b/active_support/core_ext/test/unit/assertions.rb
View
File renamed without changes
6 activesupport/lib/active_support/core_ext/time.rb
View
@@ -8,9 +8,9 @@ class Time
end
end
-require File.dirname(__FILE__) + '/time/behavior'
-require File.dirname(__FILE__) + '/time/calculations'
-require File.dirname(__FILE__) + '/time/conversions'
+require 'active_support/core_ext/time/behavior'
+require 'active_support/core_ext/time/calculations'
+require 'active_support/core_ext/time/conversions'
class Time#:nodoc:
include ActiveSupport::CoreExtensions::Time::Behavior
6 activesupport/lib/active_support/dependencies.rb
View
@@ -1,7 +1,7 @@
require 'set'
-require File.dirname(__FILE__) + '/core_ext/module/attribute_accessors'
-require File.dirname(__FILE__) + '/core_ext/load_error'
-require File.dirname(__FILE__) + '/core_ext/kernel'
+require 'active_support/core_ext/module/attribute_accessors'
+require 'active_support/core_ext/load_error'
+require 'active_support/core_ext/kernel'
module Dependencies #:nodoc:
extend self
6 activesupport/test/core_ext/hash_ext_test.rb
View
@@ -63,9 +63,9 @@ def test_indifferent_assorted
hashes.each do |name, hash|
method_map.sort_by { |m| m.to_s }.each do |meth, expected|
- assert_equal(expected, hash.send(meth, 'a'),
+ assert_equal(expected, hash.send!(meth, 'a'),
"Calling #{name}.#{meth} 'a'")
- assert_equal(expected, hash.send(meth, :a),
+ assert_equal(expected, hash.send!(meth, :a),
"Calling #{name}.#{meth} :a")
end
end
@@ -640,7 +640,7 @@ def test_kernel_method_names_to_xml
def test_empty_string_works_for_typecast_xml_value
assert_nothing_raised do
- Hash.send(:typecast_xml_value, "")
+ Hash.send!(:typecast_xml_value, "")
end
end
10 activesupport/test/inflector_test.rb
View
@@ -120,8 +120,14 @@ def test_constantize
assert_raises(NameError) { Inflector.constantize("InvalidClass\n") }
end
- def test_constantize_doesnt_look_in_parent
- assert_raises(NameError) { Inflector.constantize("Ace::Base::InflectorTest") }
+ if RUBY_VERSION < '1.9.0'
+ def test_constantize_does_lexical_lookup
+ assert_raises(NameError) { Inflector.constantize("Ace::Base::InflectorTest") }
+ end
+ else
+ def test_constantize_does_dynamic_lookup
+ assert_equal self.class, Inflector.constantize("Ace::Base::InflectorTest")
+ end
end
def test_ordinal
Please sign in to comment.
Something went wrong with that request. Please try again.