Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge remote branch 'mainstream/master'

  • Loading branch information...
commit efd0bd3b7390ebb8526b981169025f2860f6a113 2 parents f4571e3 + 8ff2fb6
@lifo lifo authored
Showing with 1,632 additions and 2,525 deletions.
  1. +8 −6 actionmailer/lib/action_mailer/base.rb
  2. +4 −4 actionmailer/lib/action_mailer/railties/subscriber.rb
  3. +1 −1  actionmailer/lib/action_mailer/test_case.rb
  4. +2 −11 actionmailer/test/subscriber_test.rb
  5. +1 −0  actionpack/lib/abstract_controller.rb
  6. +1 −1  actionpack/lib/abstract_controller/localized_cache.rb
  7. +33 −4 actionpack/lib/abstract_controller/rendering.rb
  8. +1 −1  actionpack/lib/{action_controller → abstract_controller}/translation.rb
  9. +0 −2  actionpack/lib/action_controller.rb
  10. +8 −36 actionpack/lib/action_controller/base.rb
  11. +1 −0  actionpack/lib/action_controller/metal.rb
  12. +0 −71 actionpack/lib/action_controller/metal/filter_parameter_logging.rb
  13. +1 −1  actionpack/lib/action_controller/metal/helpers.rb
  14. +17 −18 actionpack/lib/action_controller/metal/instrumentation.rb
  15. +28 −15 actionpack/lib/action_controller/metal/rendering.rb
  16. +11 −3 actionpack/lib/action_controller/railties/subscriber.rb
  17. +1 −1  actionpack/lib/action_dispatch.rb
  18. +98 −0 actionpack/lib/action_dispatch/http/filter_parameters.rb
  19. +1 −2  actionpack/lib/action_dispatch/http/parameters.rb
  20. +1 −0  actionpack/lib/action_dispatch/http/request.rb
  21. +0 −24 actionpack/lib/action_dispatch/middleware/notifications.rb
  22. +3 −3 actionpack/lib/action_dispatch/middleware/params_parser.rb
  23. +1 −3 actionpack/lib/action_dispatch/middleware/stack.rb
  24. +0 −3  actionpack/lib/action_dispatch/railtie.rb
  25. +0 −17 actionpack/lib/action_dispatch/railties/subscriber.rb
  26. +32 −4 actionpack/lib/action_dispatch/routing/mapper.rb
  27. +6 −0 actionpack/lib/action_dispatch/routing/route.rb
  28. +9 −33 actionpack/lib/action_dispatch/testing/integration.rb
  29. +6 −8 actionpack/lib/action_view/base.rb
  30. +4 −4 actionpack/lib/action_view/helpers/asset_tag_helper.rb
  31. +1 −1  actionpack/lib/action_view/helpers/cache_helper.rb
  32. +6 −6 actionpack/lib/action_view/helpers/url_helper.rb
  33. +2 −0  actionpack/lib/action_view/render/rendering.rb
  34. +34 −0 actionpack/test/abstract/render_test.rb
  35. 0  actionpack/test/{controller → abstract}/translation_test.rb
  36. +6 −17 actionpack/test/activerecord/controller_runtime_test.rb
  37. +19 −2 actionpack/test/controller/base_test.rb
  38. +0 −51 actionpack/test/controller/filter_params_test.rb
  39. +3 −3 actionpack/test/controller/new_base/base_test.rb
  40. +34 −40 actionpack/test/controller/subscriber_test.rb
  41. +1 −1  actionpack/test/dispatch/request/json_params_parsing_test.rb
  42. +1 −1  actionpack/test/dispatch/request/xml_params_parsing_test.rb
  43. +50 −0 actionpack/test/dispatch/request_test.rb
  44. +11 −11 actionpack/test/dispatch/show_exceptions_test.rb
  45. +0 −112 actionpack/test/dispatch/subscriber_test.rb
  46. +2 −11 actionpack/test/template/subscriber_test.rb
  47. +2 −0  activemodel/lib/active_model/lint.rb
  48. +1 −26 activerecord/lib/active_record.rb
  49. +13 −14 activerecord/lib/active_record/association_preload.rb
  50. +0 −67 activerecord/lib/active_record/associations.rb
  51. +4 −3 activerecord/lib/active_record/associations/association_collection.rb
  52. +10 −3 activerecord/lib/active_record/attribute_methods/before_type_cast.rb
  53. +17 −3 activerecord/lib/active_record/attribute_methods/query.rb
  54. +45 −4 activerecord/lib/active_record/attribute_methods/read.rb
  55. +38 −10 activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb
  56. +7 −2 activerecord/lib/active_record/attribute_methods/write.rb
  57. +0 −37 activerecord/lib/active_record/attributes.rb
  58. +0 −42 activerecord/lib/active_record/attributes/aliasing.rb
  59. +0 −15 activerecord/lib/active_record/attributes/store.rb
  60. +0 −117 activerecord/lib/active_record/attributes/typecasting.rb
  61. +45 −393 activerecord/lib/active_record/base.rb
  62. +0 −173 activerecord/lib/active_record/calculations.rb
  63. +3 −3 activerecord/lib/active_record/locking/optimistic.rb
  64. +1 −18 activerecord/lib/active_record/named_scope.rb
  65. +184 −23 activerecord/lib/active_record/relation.rb
  66. +0 −172 activerecord/lib/active_record/relation/calculation_methods.rb
  67. +259 −0 activerecord/lib/active_record/relation/calculations.rb
  68. +192 −33 activerecord/lib/active_record/relation/finder_methods.rb
  69. +34 −23 activerecord/lib/active_record/relation/query_methods.rb
  70. +8 −25 activerecord/lib/active_record/relation/spawn_methods.rb
  71. +0 −38 activerecord/lib/active_record/types.rb
  72. +0 −30 activerecord/lib/active_record/types/number.rb
  73. +0 −37 activerecord/lib/active_record/types/object.rb
  74. +0 −33 activerecord/lib/active_record/types/serialize.rb
  75. +0 −20 activerecord/lib/active_record/types/time_with_zone.rb
  76. +0 −37 activerecord/lib/active_record/types/unknown.rb
  77. +0 −15 activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
  78. +0 −20 activerecord/test/cases/attributes/aliasing_test.rb
  79. +0 −120 activerecord/test/cases/attributes/typecasting_test.rb
  80. +0 −17 activerecord/test/cases/calculations_test.rb
  81. +11 −5 activerecord/test/cases/method_scoping_test.rb
  82. +15 −0 activerecord/test/cases/named_scope_test.rb
  83. +5 −0 activerecord/test/cases/relations_test.rb
  84. +2 −11 activerecord/test/cases/subscriber_test.rb
  85. +0 −30 activerecord/test/cases/types/number_test.rb
  86. +0 −24 activerecord/test/cases/types/object_test.rb
  87. +0 −20 activerecord/test/cases/types/serialize_test.rb
  88. +0 −42 activerecord/test/cases/types/time_with_zone_test.rb
  89. +0 −29 activerecord/test/cases/types/unknown_test.rb
  90. +0 −32 activerecord/test/cases/types_test.rb
  91. +5 −0 activerecord/test/models/post.rb
  92. +2 −11 activeresource/test/cases/subscriber_test.rb
  93. +16 −30 activesupport/lib/active_support/core_ext/load_error.rb
  94. +1 −1  activesupport/lib/active_support/dependencies.rb
  95. +3 −33 activesupport/lib/active_support/notifications/fanout.rb
  96. +4 −3 activesupport/lib/active_support/values/time_zone.rb
  97. +15 −0 activesupport/test/core_ext/load_error_test.rb
  98. +1 −17 activesupport/test/notifications_test.rb
  99. +6 −0 activesupport/test/time_zone_test.rb
  100. +1 −1  railties/builtin/rails_info/rails/info.rb
  101. +0 −1  railties/lib/generators/rails/app/templates/app/controllers/application_controller.rb
  102. +1 −1  railties/lib/generators/rails/app/templates/config.ru
  103. +3 −0  railties/lib/generators/rails/app/templates/config/application.rb
  104. +1 −1  railties/lib/generators/rails/app/templates/config/databases/ibm_db.yml
  105. +1 −1  railties/lib/generators/rails/app/templates/config/environments/development.rb.tt
  106. +1 −1  railties/lib/generators/rails/app/templates/config/environments/production.rb.tt
  107. +1 −1  railties/lib/generators/rails/app/templates/config/environments/test.rb.tt
  108. +1 −1  railties/lib/generators/rails/app/templates/config/initializers/backtrace_silencers.rb
  109. +1 −1  railties/lib/generators/rails/app/templates/config/locales/en.yml
  110. +1 −1  railties/lib/generators/rails/app/templates/db/seeds.rb
  111. +1 −1  railties/lib/generators/rails/app/templates/script/console.tt
  112. +1 −1  railties/lib/generators/rails/app/templates/script/dbconsole.tt
  113. +2 −2 railties/lib/generators/rails/metal/templates/metal.rb
  114. +0 −12 railties/lib/generators/rails/plugin/templates/Rakefile.tt
  115. +0 −1  railties/lib/generators/rails/stylesheets/templates/scaffold.css
  116. +15 −5 railties/lib/rails/application.rb
  117. +1 −10 railties/lib/rails/commands/server.rb
  118. +8 −7 railties/lib/rails/configuration.rb
  119. +39 −22 railties/lib/rails/generators.rb
  120. +1 −1  railties/lib/rails/plugin.rb
  121. +1 −0  railties/lib/rails/rack.rb
  122. +38 −0 railties/lib/rails/rack/logger.rb
  123. +15 −0 railties/lib/rails/railtie.rb
  124. +6 −7 railties/lib/rails/subscriber.rb
  125. +3 −23 railties/lib/rails/subscriber/test_helper.rb
  126. +1 −1  railties/lib/rails/tasks/middleware.rake
  127. +12 −0 railties/test/application/configuration_test.rb
  128. +2 −2 railties/test/application/middleware_test.rb
  129. +28 −0 railties/test/application/routing_test.rb
  130. +1 −0  railties/test/fixtures/lib/generators/model_generator.rb
  131. 0  railties/test/fixtures/lib/{generators → rails_generators}/foobar/foobar_generator.rb
  132. +1 −1  railties/test/generators/plugin_generator_test.rb
  133. +15 −0 railties/test/generators_test.rb
  134. +16 −0 railties/test/plugins/framework_extension_test.rb
  135. +15 −26 railties/test/subscriber_test.rb
View
14 actionmailer/lib/action_mailer/base.rb
@@ -524,14 +524,16 @@ def process(method_name, *args)
def deliver!(mail = @mail)
raise "no mail object available for delivery!" unless mail
- begin
- ActiveSupport::Notifications.instrument("action_mailer.deliver",
- :template => template, :mailer => self.class.name) do |payload|
- self.class.set_payload_for_mail(payload, mail)
+ ActiveSupport::Notifications.instrument("action_mailer.deliver",
+ :template => template, :mailer => self.class.name) do |payload|
+
+ self.class.set_payload_for_mail(payload, mail)
+
+ begin
self.delivery_method.perform_delivery(mail) if perform_deliveries
+ rescue Exception => e # Net::SMTP errors or sendmail pipe errors
+ raise e if raise_delivery_errors
end
- rescue Exception => e # Net::SMTP errors or sendmail pipe errors
- raise e if raise_delivery_errors
end
mail
View
8 actionmailer/lib/action_mailer/railties/subscriber.rb
@@ -3,13 +3,13 @@ module Railties
class Subscriber < Rails::Subscriber
def deliver(event)
recipients = Array(event.payload[:to]).join(', ')
- info("Sent mail to #{recipients} (%1.fms)" % event.duration)
- debug("\n#{event.payload[:mail]}")
+ info("\nSent mail to #{recipients} (%1.fms)" % event.duration)
+ debug(event.payload[:mail])
end
def receive(event)
- info("Received mail (%.1fms)" % event.duration)
- debug("\n#{event.payload[:mail]}")
+ info("\nReceived mail (%.1fms)" % event.duration)
+ debug(event.payload[:mail])
end
def logger
View
2  actionmailer/lib/action_mailer/test_case.rb
@@ -56,7 +56,7 @@ def encode(subject)
end
def read_fixture(action)
- IO.readlines(File.join(RAILS_ROOT, 'test', 'fixtures', self.class.mailer_class.name.underscore, action))
+ IO.readlines(File.join(Rails.root, 'test', 'fixtures', self.class.mailer_class.name.underscore, action))
end
end
end
View
13 actionmailer/test/subscriber_test.rb
@@ -2,7 +2,8 @@
require "rails/subscriber/test_helper"
require "action_mailer/railties/subscriber"
-module SubscriberTest
+class AMSubscriberTest < ActionMailer::TestCase
+ include Rails::Subscriber::TestHelper
Rails::Subscriber.add(:action_mailer, ActionMailer::Railties::Subscriber.new)
class TestMailer < ActionMailer::Base
@@ -40,14 +41,4 @@ def test_receive_is_notified
assert_equal 1, @logger.logged(:debug).size
assert_match /Jamis/, @logger.logged(:debug).first
end
-
- class SyncSubscriberTest < ActionMailer::TestCase
- include Rails::Subscriber::SyncTestHelper
- include SubscriberTest
- end
-
- class AsyncSubscriberTest < ActionMailer::TestCase
- include Rails::Subscriber::AsyncTestHelper
- include SubscriberTest
- end
end
View
1  actionpack/lib/abstract_controller.rb
@@ -15,5 +15,6 @@ module AbstractController
autoload :LocalizedCache
autoload :Logger
autoload :Rendering
+ autoload :Translation
autoload :UrlFor
end
View
2  actionpack/lib/abstract_controller/localized_cache.rb
@@ -34,7 +34,7 @@ def template_cache
end
end
- def render(options)
+ def render(*args)
Thread.current[:format_locale_key] = HashKey.get(self.class, formats, I18n.locale)
super
end
View
37 actionpack/lib/abstract_controller/rendering.rb
@@ -40,12 +40,13 @@ def view_context
# Mostly abstracts the fact that calling render twice is a DoubleRenderError.
# Delegates render_to_body and sticks the result in self.response_body.
- def render(*args)
+ def render(*args, &block)
if response_body
- raise AbstractController::DoubleRenderError, "OMG"
+ raise AbstractController::DoubleRenderError
end
- self.response_body = render_to_body(*args)
+ options = _normalize_options(*args, &block)
+ self.response_body = render_to_body(options)
end
# Raw rendering of a template to a Rack-compatible body.
@@ -69,7 +70,8 @@ def render_to_body(options = {})
# render_to_body into a String.
#
# :api: plugin
- def render_to_string(options = {})
+ def render_to_string(*args)
+ options = _normalize_options(*args)
AbstractController::Rendering.body_to_s(render_to_body(options))
end
@@ -96,6 +98,11 @@ def view_paths
_view_paths
end
+ # The prefix used in render "foo" shortcuts.
+ def _prefix
+ controller_path
+ end
+
# Return a string representation of a Rack-compatible response body.
def self.body_to_s(body)
if body.respond_to?(:to_str)
@@ -110,6 +117,28 @@ def self.body_to_s(body)
private
+ # Normalize options, by converting render "foo" to render :template => "prefix/foo"
+ # and render "/foo" to render :file => "/foo".
+ def _normalize_options(action=nil, options={})
+ case action
+ when Hash
+ options, action = action, nil
+ when String, Symbol
+ action = action.to_s
+ case action.index("/")
+ when NilClass
+ options[:_prefix] = _prefix
+ options[:_template_name] = action
+ when 0
+ options[:file] = action
+ else
+ options[:template] = action
+ end
+ end
+
+ options
+ end
+
# Take in a set of options and determine the template to render
#
# ==== Options
View
2  ...pack/lib/action_controller/translation.rb → ...ck/lib/abstract_controller/translation.rb
@@ -1,4 +1,4 @@
-module ActionController
+module AbstractController
module Translation
def translate(*args)
I18n.translate(*args)
View
2  actionpack/lib/action_controller.rb
@@ -8,7 +8,6 @@ module ActionController
autoload :Base
autoload :Caching
autoload :PolymorphicRoutes
- autoload :Translation
autoload :Metal
autoload :Middleware
@@ -17,7 +16,6 @@ module ActionController
autoload :ConditionalGet
autoload :Configuration
autoload :Cookies
- autoload :FilterParameterLogging
autoload :Flash
autoload :Head
autoload :Helpers
View
44 actionpack/lib/action_controller/base.rb
@@ -4,6 +4,7 @@ class Base < Metal
include AbstractController::Callbacks
include AbstractController::Layouts
+ include AbstractController::Translation
include ActionController::Helpers
helper :all # By default, all helpers should be included
@@ -32,12 +33,10 @@ class Base < Metal
include ActionController::Streaming
include ActionController::HttpAuthentication::Basic::ControllerMethods
include ActionController::HttpAuthentication::Digest::ControllerMethods
- include ActionController::Translation
# Add instrumentations hooks at the bottom, to ensure they instrument
# all the methods properly.
include ActionController::Instrumentation
- include ActionController::FilterParameterLogging
# TODO: Extract into its own module
# This should be moved together with other normalizing behavior
@@ -74,40 +73,13 @@ def self.subclasses
@subclasses ||= []
end
- def _normalize_options(action = nil, options = {}, &blk)
- if action.is_a?(Hash)
- options, action = action, nil
- elsif action.is_a?(String) || action.is_a?(Symbol)
- key = case action = action.to_s
- when %r{^/} then :file
- when %r{/} then :template
- else :action
- end
- options.merge! key => action
- elsif action
- options.merge! :partial => action
- end
-
- if options.key?(:action) && options[:action].to_s.index("/")
- options[:template] = options.delete(:action)
- end
-
- if options[:status]
- options[:status] = Rack::Utils.status_code(options[:status])
- end
-
- options[:update] = blk if block_given?
- options
- end
-
- def render(action = nil, options = {}, &blk)
- options = _normalize_options(action, options, &blk)
- super(options)
- end
-
- def render_to_string(action = nil, options = {}, &blk)
- options = _normalize_options(action, options, &blk)
- super(options)
+ # This method has been moved to ActionDispatch::Request.filter_parameters
+ def self.filter_parameter_logging(*args, &block)
+ ActiveSupport::Deprecation.warn("Setting filter_parameter_logging in ActionController is deprecated and has no longer effect, please set 'config.filter_parameters' in config/application.rb instead", caller)
+ filter = Rails.application.config.filter_parameters
+ filter.concat(args)
+ filter << block if block
+ filter
end
end
end
View
1  actionpack/lib/action_controller/metal.rb
@@ -60,6 +60,7 @@ def status=(status)
# :api: private
def dispatch(name, env)
@_env = env
+ @_env['action_controller.instance'] = self
process(name)
to_a
end
View
71 actionpack/lib/action_controller/metal/filter_parameter_logging.rb
@@ -1,71 +0,0 @@
-module ActionController
- module FilterParameterLogging
- extend ActiveSupport::Concern
-
- INTERNAL_PARAMS = %w(controller action format _method only_path)
-
- module ClassMethods
- # Replace sensitive parameter data from the request log.
- # Filters parameters that have any of the arguments as a substring.
- # Looks in all subhashes of the param hash for keys to filter.
- # If a block is given, each key and value of the parameter hash and all
- # subhashes is passed to it, the value or key
- # can be replaced using String#replace or similar method.
- #
- # Examples:
- #
- # filter_parameter_logging :password
- # => replaces the value to all keys matching /password/i with "[FILTERED]"
- #
- # filter_parameter_logging :foo, "bar"
- # => replaces the value to all keys matching /foo|bar/i with "[FILTERED]"
- #
- # filter_parameter_logging { |k,v| v.reverse! if k =~ /secret/i }
- # => reverses the value to all keys matching /secret/i
- #
- # filter_parameter_logging(:foo, "bar") { |k,v| v.reverse! if k =~ /secret/i }
- # => reverses the value to all keys matching /secret/i, and
- # replaces the value to all keys matching /foo|bar/i with "[FILTERED]"
- def filter_parameter_logging(*filter_words, &block)
- raise "You must filter at least one word from logging" if filter_words.empty?
-
- parameter_filter = Regexp.new(filter_words.join('|'), true)
-
- define_method(:filter_parameters) do |original_params|
- filtered_params = {}
-
- original_params.each do |key, value|
- if key =~ parameter_filter
- value = '[FILTERED]'
- elsif value.is_a?(Hash)
- value = filter_parameters(value)
- elsif value.is_a?(Array)
- value = value.map { |item| filter_parameters(item) }
- elsif block_given?
- key = key.dup
- value = value.dup if value.duplicable?
- yield key, value
- end
-
- filtered_params[key] = value
- end
-
- filtered_params.except!(*INTERNAL_PARAMS)
- end
- protected :filter_parameters
- end
- end
-
- protected
-
- def append_info_to_payload(payload)
- super
- payload[:params] = filter_parameters(request.params)
- end
-
- def filter_parameters(params)
- params.dup.except!(*INTERNAL_PARAMS)
- end
-
- end
-end
View
2  actionpack/lib/action_controller/metal/helpers.rb
@@ -100,7 +100,7 @@ def default_helper_module!
module_path = module_name.underscore
helper module_path
rescue MissingSourceFile => e
- raise e unless e.is_missing? "#{module_path}_helper"
+ raise e unless e.is_missing? "helpers/#{module_path}_helper"
rescue NameError => e
raise e unless e.missing_name? "#{module_name}Helper"
end
View
35 actionpack/lib/action_controller/metal/instrumentation.rb
@@ -9,35 +9,34 @@ module ActionController
module Instrumentation
extend ActiveSupport::Concern
- included do
- include AbstractController::Logger
- end
+ include AbstractController::Logger
attr_internal :view_runtime
def process_action(action, *args)
- ActiveSupport::Notifications.instrument("action_controller.process_action") do |payload|
+ raw_payload = {
+ :controller => self.class.name,
+ :action => self.action_name,
+ :params => request.filtered_parameters,
+ :formats => request.formats.map(&:to_sym)
+ }
+
+ ActiveSupport::Notifications.instrument("action_controller.start_processing", raw_payload.dup)
+
+ ActiveSupport::Notifications.instrument("action_controller.process_action", raw_payload) do |payload|
result = super
- payload[:controller] = self.class.name
- payload[:action] = self.action_name
- payload[:status] = response.status
+ payload[:status] = response.status
append_info_to_payload(payload)
result
end
end
- def render(*args, &block)
- if logger
- render_output = nil
-
- self.view_runtime = cleanup_view_runtime do
- Benchmark.ms { render_output = super }
- end
-
- render_output
- else
- super
+ def render(*args)
+ render_output = nil
+ self.view_runtime = cleanup_view_runtime do
+ Benchmark.ms { render_output = super }
end
+ render_output
end
def send_file(path, options={})
View
43 actionpack/lib/action_controller/metal/rendering.rb
@@ -12,9 +12,10 @@ def process_action(*)
super
end
- def render(options)
- super
- self.content_type ||= options[:_template].mime_type.to_s
+ def render(*args)
+ args << {} unless args.last.is_a?(Hash)
+ super(*args)
+ self.content_type ||= args.last[:_template].mime_type.to_s
response_body
end
@@ -24,18 +25,6 @@ def render_to_body(options)
end
private
- def _prefix
- controller_path
- end
-
- def _determine_template(options)
- if (options.keys & [:partial, :file, :template, :text, :inline]).empty?
- options[:_template_name] ||= options[:action]
- options[:_prefix] = _prefix
- end
-
- super
- end
def _render_partial(options)
options[:partial] = action_name if options[:partial] == true
@@ -53,5 +42,29 @@ def _process_options(options)
self.content_type = content_type if content_type
self.headers["Location"] = url_for(location) if location
end
+
+ def _normalize_options(action=nil, options={}, &blk)
+ case action
+ when NilClass
+ when Hash
+ options = super(action.delete(:action), action)
+ when String, Symbol
+ options = super
+ else
+ options.merge! :partial => action
+ end
+
+ if (options.keys & [:partial, :file, :template, :text, :inline]).empty?
+ options[:_template_name] ||= options[:action]
+ options[:_prefix] = _prefix
+ end
+
+ if options[:status]
+ options[:status] = Rack::Utils.status_code(options[:status])
+ end
+
+ options[:update] = blk if block_given?
+ options
+ end
end
end
View
14 actionpack/lib/action_controller/railties/subscriber.rb
@@ -1,15 +1,23 @@
module ActionController
module Railties
class Subscriber < Rails::Subscriber
- def process_action(event)
+ INTERNAL_PARAMS = %w(controller action format _method only_path)
+
+ def start_processing(event)
payload = event.payload
- info " Parameters: #{payload[:params].inspect}" unless payload[:params].blank?
+ params = payload[:params].except(*INTERNAL_PARAMS)
+ info " Processing by #{payload[:controller]}##{payload[:action]} as #{payload[:formats].first.to_s.upcase}"
+ info " Parameters: #{params.inspect}" unless params.empty?
+ end
+
+ def process_action(event)
+ payload = event.payload
additions = ActionController::Base.log_process_action(payload)
message = "Completed in %.0fms" % event.duration
message << " (#{additions.join(" | ")})" unless additions.blank?
- message << " by #{payload[:controller]}##{payload[:action]} [#{payload[:status]}]"
+ message << " with #{payload[:status]}"
info(message)
end
View
2  actionpack/lib/action_dispatch.rb
@@ -46,7 +46,6 @@ module ActionDispatch
autoload :Cookies
autoload :Flash
autoload :Head
- autoload :Notifications
autoload :ParamsParser
autoload :Rescue
autoload :ShowExceptions
@@ -63,6 +62,7 @@ module Http
autoload :Headers
autoload :MimeNegotiation
autoload :Parameters
+ autoload :FilterParameters
autoload :Upload
autoload :UploadedFile, 'action_dispatch/http/upload'
autoload :URL
View
98 actionpack/lib/action_dispatch/http/filter_parameters.rb
@@ -0,0 +1,98 @@
+require 'active_support/core_ext/object/blank'
+require 'active_support/core_ext/hash/keys'
+
+module ActionDispatch
+ module Http
+ # Allows you to specify sensitive parameters which will be replaced from
+ # the request log by looking in all subhashes of the param hash for keys
+ # to filter. If a block is given, each key and value of the parameter
+ # hash and all subhashes is passed to it, the value or key can be replaced
+ # using String#replace or similar method.
+ #
+ # Examples:
+ #
+ # env["action_dispatch.parameter_filter"] = [:password]
+ # => replaces the value to all keys matching /password/i with "[FILTERED]"
+ #
+ # env["action_dispatch.parameter_filter"] = [:foo, "bar"]
+ # => replaces the value to all keys matching /foo|bar/i with "[FILTERED]"
+ #
+ # env["action_dispatch.parameter_filter"] = lambda do |k,v|
+ # v.reverse! if k =~ /secret/i
+ # end
+ # => reverses the value to all keys matching /secret/i
+ #
+ module FilterParameters
+ extend ActiveSupport::Concern
+
+ # Return a hash of parameters with all sensitive data replaced.
+ def filtered_parameters
+ @filtered_parameters ||= process_parameter_filter(parameters)
+ end
+ alias :fitered_params :filtered_parameters
+
+ # Return a hash of request.env with all sensitive data replaced.
+ def filtered_env
+ filtered_env = @env.dup
+ filtered_env.each do |key, value|
+ if (key =~ /RAW_POST_DATA/i)
+ filtered_env[key] = '[FILTERED]'
+ elsif value.is_a?(Hash)
+ filtered_env[key] = process_parameter_filter(value)
+ end
+ end
+ filtered_env
+ end
+
+ protected
+
+ def compile_parameter_filter #:nodoc:
+ strings, regexps, blocks = [], [], []
+
+ Array(@env["action_dispatch.parameter_filter"]).each do |item|
+ case item
+ when NilClass
+ when Proc
+ blocks << item
+ when Regexp
+ regexps << item
+ else
+ strings << item.to_s
+ end
+ end
+
+ regexps << Regexp.new(strings.join('|'), true) unless strings.empty?
+ [regexps, blocks]
+ end
+
+ def filtering_parameters? #:nodoc:
+ @env["action_dispatch.parameter_filter"].present?
+ end
+
+ def process_parameter_filter(original_params) #:nodoc:
+ return original_params.dup unless filtering_parameters?
+
+ filtered_params = {}
+ regexps, blocks = compile_parameter_filter
+
+ original_params.each do |key, value|
+ if regexps.find { |r| key =~ r }
+ value = '[FILTERED]'
+ elsif value.is_a?(Hash)
+ value = process_parameter_filter(value)
+ elsif value.is_a?(Array)
+ value = value.map { |i| process_parameter_filter(i) }
+ elsif blocks.present?
+ key = key.dup
+ value = value.dup if value.duplicable?
+ blocks.each { |b| b.call(key, value) }
+ end
+
+ filtered_params[key] = value
+ end
+
+ filtered_params
+ end
+ end
+ end
+end
View
3  actionpack/lib/action_dispatch/http/parameters.rb
@@ -29,9 +29,8 @@ def symbolized_path_parameters
def path_parameters
@env["action_dispatch.request.path_parameters"] ||= {}
end
-
- private
+ private
# Convert nested Hashs to HashWithIndifferentAccess
def normalize_parameters(value)
case value
View
1  actionpack/lib/action_dispatch/http/request.rb
@@ -11,6 +11,7 @@ class Request < Rack::Request
include ActionDispatch::Http::Cache::Request
include ActionDispatch::Http::MimeNegotiation
include ActionDispatch::Http::Parameters
+ include ActionDispatch::Http::FilterParameters
include ActionDispatch::Http::Upload
include ActionDispatch::Http::URL
View
24 actionpack/lib/action_dispatch/middleware/notifications.rb
@@ -1,24 +0,0 @@
-module ActionDispatch
- # Provide notifications in the middleware stack. Notice that for the before_dispatch
- # and after_dispatch notifications, we just send the original env, so we don't pile
- # up large env hashes in the queue. However, in exception cases, the whole env hash
- # is actually useful, so we send it all.
- class Notifications
- def initialize(app)
- @app = app
- end
-
- def call(stack_env)
- env = stack_env.dup
- ActiveSupport::Notifications.instrument("action_dispatch.before_dispatch", :env => env)
-
- ActiveSupport::Notifications.instrument!("action_dispatch.after_dispatch", :env => env) do
- @app.call(stack_env)
- end
- rescue Exception => exception
- ActiveSupport::Notifications.instrument('action_dispatch.exception',
- :env => stack_env, :exception => exception)
- raise exception
- end
- end
-end
View
6 actionpack/lib/action_dispatch/middleware/params_parser.rb
@@ -35,14 +35,14 @@ def parse_formatted_parameters(env)
when Proc
strategy.call(request.raw_post)
when :xml_simple, :xml_node
- request.body.size == 0 ? {} : Hash.from_xml(request.body).with_indifferent_access
+ request.body.size == 0 ? {} : Hash.from_xml(request.raw_post).with_indifferent_access
when :yaml
- YAML.load(request.body)
+ YAML.load(request.raw_post)
when :json
if request.body.size == 0
{}
else
- data = ActiveSupport::JSON.decode(request.body)
+ data = ActiveSupport::JSON.decode(request.raw_post)
data = {:_json => data} unless data.is_a?(Hash)
data.with_indifferent_access
end
View
4 actionpack/lib/action_dispatch/middleware/stack.rb
@@ -60,9 +60,7 @@ def ==(middleware)
end
def inspect
- str = klass.to_s
- args.each { |arg| str += ", #{build_args.inspect}" }
- str
+ klass.to_s
end
def build(app)
View
3  actionpack/lib/action_dispatch/railtie.rb
@@ -5,9 +5,6 @@ module ActionDispatch
class Railtie < Rails::Railtie
plugin_name :action_dispatch
- require "action_dispatch/railties/subscriber"
- subscriber ActionDispatch::Railties::Subscriber.new
-
# Prepare dispatcher callbacks and run 'prepare' callbacks
initializer "action_dispatch.prepare_dispatcher" do |app|
# TODO: This used to say unless defined?(Dispatcher). Find out why and fix.
View
17 actionpack/lib/action_dispatch/railties/subscriber.rb
@@ -1,17 +0,0 @@
-module ActionDispatch
- module Railties
- class Subscriber < Rails::Subscriber
- def before_dispatch(event)
- request = Request.new(event.payload[:env])
- path = request.request_uri.inspect rescue "unknown"
-
- info "\n\nProcessing #{path} to #{request.formats.join(', ')} " <<
- "(for #{request.remote_ip} at #{event.time.to_s(:db)}) [#{request.method.to_s.upcase}]"
- end
-
- def logger
- ActionController::Base.logger
- end
- end
- end
-end
View
36 actionpack/lib/action_dispatch/routing/mapper.rb
@@ -375,6 +375,15 @@ def actions
end
end
+ def action_type(action)
+ case action
+ when :index, :create
+ :collection
+ when :show, :update, :destroy
+ :member
+ end
+ end
+
def name
options[:as] || plural
end
@@ -391,6 +400,15 @@ def collection_name
plural
end
+ def name_for_action(action)
+ case action_type(action)
+ when :collection
+ collection_name
+ when :member
+ member_name
+ end
+ end
+
def id_segment
":#{singular}_id"
end
@@ -405,6 +423,13 @@ def initialize(entity, options = {})
super
end
+ def action_type(action)
+ case action
+ when :show, :create, :update, :destroy
+ :member
+ end
+ end
+
def name
options[:as] || singular
end
@@ -428,7 +453,7 @@ def resource(*resources, &block)
with_scope_level(:resource, resource) do
yield if block_given?
- get :show, :as => resource.member_name if resource.actions.include?(:show)
+ get :show if resource.actions.include?(:show)
post :create if resource.actions.include?(:create)
put :update if resource.actions.include?(:update)
delete :destroy if resource.actions.include?(:destroy)
@@ -454,14 +479,14 @@ def resources(*resources, &block)
yield if block_given?
with_scope_level(:collection) do
- get :index, :as => resource.collection_name if resource.actions.include?(:index)
+ get :index if resource.actions.include?(:index)
post :create if resource.actions.include?(:create)
get :new, :as => resource.singular if resource.actions.include?(:new)
end
with_scope_level(:member) do
scope(':id') do
- get :show, :as => resource.member_name if resource.actions.include?(:show)
+ get :show if resource.actions.include?(:show)
put :update if resource.actions.include?(:update)
delete :destroy if resource.actions.include?(:destroy)
get :edit, :as => resource.singular if resource.actions.include?(:edit)
@@ -525,7 +550,10 @@ def match(*args)
begin
old_path = @scope[:path]
@scope[:path] = "#{@scope[:path]}(.:format)"
- return match(options.reverse_merge(:to => action))
+ return match(options.reverse_merge(
+ :to => action,
+ :as => parent_resource.name_for_action(action)
+ ))
ensure
@scope[:path] = old_path
end
View
6 actionpack/lib/action_dispatch/routing/route.rb
@@ -44,6 +44,12 @@ def segment_keys
def to_a
[@app, @conditions, @defaults, @name]
end
+
+ def to_s
+ @to_s ||= begin
+ "%-6s %-40s %s" % [(verb || :any).to_s.upcase, path, requirements.inspect]
+ end
+ end
end
end
end
View
42 actionpack/lib/action_dispatch/testing/integration.rb
@@ -240,9 +240,9 @@ def process(method, path, parameters = nil, rack_environment = nil)
path = location.query ? "#{location.path}?#{location.query}" : location.path
end
- [ControllerCapture, ActionController::Testing].each do |mod|
- unless ActionController::Base < mod
- ActionController::Base.class_eval { include mod }
+ unless ActionController::Base < ActionController::Testing
+ ActionController::Base.class_eval do
+ include ActionController::Testing
end
end
@@ -259,7 +259,9 @@ def process(method, path, parameters = nil, rack_environment = nil)
"HTTP_HOST" => host,
"REMOTE_ADDR" => remote_addr,
"CONTENT_TYPE" => "application/x-www-form-urlencoded",
- "HTTP_ACCEPT" => accept
+ "HTTP_ACCEPT" => accept,
+
+ "action_dispatch.show_exceptions" => false
}
(rack_environment || {}).each do |key, value|
@@ -267,16 +269,15 @@ def process(method, path, parameters = nil, rack_environment = nil)
end
session = Rack::Test::Session.new(@mock_session)
-
- @controller = ActionController::Base.capture_instantiation do
- session.request(path, env)
- end
+ session.request(path, env)
@request_count += 1
@request = ActionDispatch::Request.new(session.last_request.env)
@response = ActionDispatch::TestResponse.from_response(@mock_session.last_response)
@html_document = nil
+ @controller = session.last_request.env['action_controller.instance']
+
return response.status
end
@@ -294,31 +295,6 @@ def generic_url_rewriter
end
end
- # A module used to extend ActionController::Base, so that integration tests
- # can capture the controller used to satisfy a request.
- module ControllerCapture #:nodoc:
- extend ActiveSupport::Concern
-
- included do
- alias_method_chain :initialize, :capture
- end
-
- def initialize_with_capture(*args)
- initialize_without_capture
- self.class.last_instantiation ||= self
- end
-
- module ClassMethods #:nodoc:
- mattr_accessor :last_instantiation
-
- def capture_instantiation
- self.last_instantiation = nil
- yield
- return last_instantiation
- end
- end
- end
-
module Runner
def app
@app
View
14 actionpack/lib/action_view/base.rb
@@ -181,7 +181,6 @@ def config=(config)
extend ActiveSupport::Memoizable
attr_accessor :base_path, :assigns, :template_extension, :formats
- attr_accessor :controller
attr_internal :captures
def reset_formats(formats)
@@ -277,13 +276,13 @@ def initialize(view_paths = [], assigns_for_first_render = {}, controller = nil,
@config = nil
@formats = formats
@assigns = assigns_for_first_render.each { |key, value| instance_variable_set("@#{key}", value) }
- @controller = controller
+ @_controller = controller
@helpers = self.class.helpers || Module.new
@_content_for = Hash.new {|h,k| h[k] = ActionView::SafeBuffer.new }
self.view_paths = view_paths
end
- attr_internal :template
+ attr_internal :controller, :template
attr_reader :view_paths
def view_paths=(paths)
@@ -298,12 +297,11 @@ def punctuate_body!(part)
# Evaluates the local assigns and controller ivars, pushes them to the view.
def _evaluate_assigns_and_ivars #:nodoc:
- if @controller
- variables = @controller.instance_variable_names
- variables -= @controller.protected_instance_variables if @controller.respond_to?(:protected_instance_variables)
- variables.each { |name| instance_variable_set(name, @controller.instance_variable_get(name)) }
+ if controller
+ variables = controller.instance_variable_names
+ variables -= controller.protected_instance_variables if controller.respond_to?(:protected_instance_variables)
+ variables.each { |name| instance_variable_set(name, controller.instance_variable_get(name)) }
end
end
-
end
end
View
8 actionpack/lib/action_view/helpers/asset_tag_helper.rb
@@ -634,8 +634,8 @@ def self.cache_asset_timestamps=(value)
# Prefix with <tt>/dir/</tt> if lacking a leading +/+. Account for relative URL
# roots. Rewrite the asset path for cache-busting asset ids. Include
# asset host, if configured, with the correct request protocol.
- def compute_public_path(source, dir, ext = nil, include_host = true)
- has_request = @controller.respond_to?(:request)
+ def compute_public_path(source, dir, ext = nil, include_host = true)
+ has_request = controller.respond_to?(:request)
source_ext = File.extname(source)[1..-1]
if ext && !is_uri?(source) && (source_ext.blank? || (ext != source_ext && File.exist?(File.join(config.assets_dir, dir, "#{source}.#{ext}"))))
@@ -658,7 +658,7 @@ def compute_public_path(source, dir, ext = nil, include_host = true)
host = compute_asset_host(source)
if has_request && !host.blank? && !is_uri?(host)
- host = "#{@controller.request.protocol}#{host}"
+ host = "#{controller.request.protocol}#{host}"
end
"#{host}#{source}"
@@ -681,7 +681,7 @@ def compute_asset_host(source)
if host.is_a?(Proc) || host.respond_to?(:call)
case host.is_a?(Proc) ? host.arity : host.method(:call).arity
when 2
- request = @controller.respond_to?(:request) && @controller.request
+ request = controller.respond_to?(:request) && controller.request
host.call(source, request)
else
host.call(source)
View
2  actionpack/lib/action_view/helpers/cache_helper.rb
@@ -32,7 +32,7 @@ module CacheHelper
# <i>Topics listed alphabetically</i>
# <% end %>
def cache(name = {}, options = nil, &block)
- @controller.fragment_for(output_buffer, name, options, &block)
+ controller.fragment_for(output_buffer, name, options, &block)
end
end
end
View
12 actionpack/lib/action_view/helpers/url_helper.rb
@@ -13,7 +13,7 @@ module UrlHelper
# Need to map default url options to controller one.
def default_url_options(*args) #:nodoc:
- @controller.send(:default_url_options, *args)
+ controller.send(:default_url_options, *args)
end
# Returns the URL for the set of +options+ provided. This takes the
@@ -89,10 +89,10 @@ def url_for(options = {})
when Hash
options = { :only_path => options[:host].nil? }.update(options.symbolize_keys)
escape = options.key?(:escape) ? options.delete(:escape) : false
- @controller.send(:url_for, options)
+ controller.send(:url_for, options)
when :back
escape = false
- @controller.request.env["HTTP_REFERER"] || 'javascript:history.back()'
+ controller.request.env["HTTP_REFERER"] || 'javascript:history.back()'
else
escape = false
polymorphic_path(options)
@@ -546,10 +546,10 @@ def mail_to(email_address, name = nil, html_options = {})
# # => false
def current_page?(options)
url_string = CGI.unescapeHTML(url_for(options))
- request = @controller.request
- # We ignore any extra parameters in the request_uri if the
+ request = controller.request
+ # We ignore any extra parameters in the request_uri if the
# submitted url doesn't have any either. This lets the function
- # work with things like ?order=asc
+ # work with things like ?order=asc
if url_string.index("?")
request_uri = request.request_uri
else
View
2  actionpack/lib/action_view/render/rendering.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/object/try'
+
module ActionView
module Rendering
# Returns the result of a render that's dictated by the options hash. The primary options are:
View
34 actionpack/test/abstract/render_test.rb
@@ -6,9 +6,16 @@ module Testing
class ControllerRenderer < AbstractController::Base
include AbstractController::Rendering
+ def _prefix
+ "renderer"
+ end
+
self.view_paths = [ActionView::FixtureResolver.new(
"default.erb" => "With Default",
"template.erb" => "With Template",
+ "renderer/string.erb" => "With String",
+ "renderer/symbol.erb" => "With Symbol",
+ "string/with_path.erb" => "With String With Path",
"some/file.erb" => "With File",
"template_name.erb" => "With Template Name"
)]
@@ -33,6 +40,18 @@ def default
render
end
+ def string
+ render "string"
+ end
+
+ def string_with_path
+ render "string/with_path"
+ end
+
+ def symbol
+ render :symbol
+ end
+
def template_name
render :_template_name => :template_name
end
@@ -73,6 +92,21 @@ def test_render_default
assert_equal "With Default", @controller.response_body
end
+ def test_render_string
+ @controller.process(:string)
+ assert_equal "With String", @controller.response_body
+ end
+
+ def test_render_symbol
+ @controller.process(:symbol)
+ assert_equal "With Symbol", @controller.response_body
+ end
+
+ def test_render_string_with_path
+ @controller.process(:string_with_path)
+ assert_equal "With String With Path", @controller.response_body
+ end
+
def test_render_template_name
@controller.process(:template_name)
assert_equal "With Template Name", @controller.response_body
View
0  ...npack/test/controller/translation_test.rb → actionpack/test/abstract/translation_test.rb
File renamed without changes
View
23 actionpack/test/activerecord/controller_runtime_test.rb
@@ -6,16 +6,15 @@
ActionController::Base.send :include, ActiveRecord::Railties::ControllerRuntime
-module ControllerRuntimeSubscriberTest
+class ControllerRuntimeSubscriberTest < ActionController::TestCase
class SubscriberController < ActionController::Base
def show
render :inline => "<%= Project.all %>"
end
end
-
- def self.included(base)
- base.tests SubscriberController
- end
+
+ include Rails::Subscriber::TestHelper
+ tests SubscriberController
def setup
@old_logger = ActionController::Base.logger
@@ -37,17 +36,7 @@ def test_log_with_active_record
get :show
wait
- assert_equal 1, @logger.logged(:info).size
- assert_match /\(Views: [\d\.]+ms | ActiveRecord: [\d\.]+ms\)/, @logger.logged(:info)[0]
- end
-
- class SyncSubscriberTest < ActionController::TestCase
- include Rails::Subscriber::SyncTestHelper
- include ControllerRuntimeSubscriberTest
- end
-
- class AsyncSubscriberTest < ActionController::TestCase
- include Rails::Subscriber::AsyncTestHelper
- include ControllerRuntimeSubscriberTest
+ assert_equal 2, @logger.logged(:info).size
+ assert_match /\(Views: [\d\.]+ms | ActiveRecord: [\d\.]+ms\)/, @logger.logged(:info)[1]
end
end
View
21 actionpack/test/controller/base_test.rb
@@ -2,6 +2,9 @@
require 'logger'
require 'pp' # require 'pp' early to prevent hidden_methods from not picking up the pretty-print methods until too late
+module Rails
+end
+
# Provide some controller to run the tests on.
module Submodule
class ContainedEmptyController < ActionController::Base
@@ -63,7 +66,7 @@ def default_url_options(options = nil)
end
end
-class ControllerClassTests < Test::Unit::TestCase
+class ControllerClassTests < ActiveSupport::TestCase
def test_controller_path
assert_equal 'empty', EmptyController.controller_path
assert_equal EmptyController.controller_path, EmptyController.new.controller_path
@@ -74,7 +77,21 @@ def test_controller_path
def test_controller_name
assert_equal 'empty', EmptyController.controller_name
assert_equal 'contained_empty', Submodule::ContainedEmptyController.controller_name
- end
+ end
+
+ def test_filter_parameter_logging
+ parameters = []
+ config = mock(:config => mock(:filter_parameters => parameters))
+ Rails.expects(:application).returns(config)
+
+ assert_deprecated do
+ Class.new(ActionController::Base) do
+ filter_parameter_logging :password
+ end
+ end
+
+ assert_equal [:password], parameters
+ end
end
class ControllerInstanceTests < Test::Unit::TestCase
View
51 actionpack/test/controller/filter_params_test.rb
@@ -1,51 +0,0 @@
-require 'abstract_unit'
-
-class FilterParamController < ActionController::Base
- def payment
- head :ok
- end
-end
-
-class FilterParamTest < ActionController::TestCase
- tests FilterParamController
-
- def test_filter_parameters_must_have_one_word
- assert_raises RuntimeError do
- FilterParamController.filter_parameter_logging
- end
- end
-
- def test_filter_parameters
- assert FilterParamController.respond_to?(:filter_parameter_logging)
-
- test_hashes = [
- [{'foo'=>'bar'},{'foo'=>'bar'},%w'food'],
- [{'foo'=>'bar'},{'foo'=>'[FILTERED]'},%w'foo'],
- [{'foo'=>'bar', 'bar'=>'foo'},{'foo'=>'[FILTERED]', 'bar'=>'foo'},%w'foo baz'],
- [{'foo'=>'bar', 'baz'=>'foo'},{'foo'=>'[FILTERED]', 'baz'=>'[FILTERED]'},%w'foo baz'],
- [{'bar'=>{'foo'=>'bar','bar'=>'foo'}},{'bar'=>{'foo'=>'[FILTERED]','bar'=>'foo'}},%w'fo'],
- [{'foo'=>{'foo'=>'bar','bar'=>'foo'}},{'foo'=>'[FILTERED]'},%w'f banana'],
- [{'baz'=>[{'foo'=>'baz'}]}, {'baz'=>[{'foo'=>'[FILTERED]'}]}, %w(foo)]]
-
- test_hashes.each do |before_filter, after_filter, filter_words|
- FilterParamController.filter_parameter_logging(*filter_words)
- assert_equal after_filter, @controller.__send__(:filter_parameters, before_filter)
-
- filter_words.push('blah')
- FilterParamController.filter_parameter_logging(*filter_words) do |key, value|
- value.reverse! if key =~ /bargain/
- end
-
- before_filter['barg'] = {'bargain'=>'gain', 'blah'=>'bar', 'bar'=>{'bargain'=>{'blah'=>'foo'}}}
- after_filter['barg'] = {'bargain'=>'niag', 'blah'=>'[FILTERED]', 'bar'=>{'bargain'=>{'blah'=>'[FILTERED]'}}}
-
- assert_equal after_filter, @controller.__send__(:filter_parameters, before_filter)
- end
- end
-
- def test_filter_parameters_is_protected
- FilterParamController.filter_parameter_logging(:foo)
- assert !FilterParamController.action_methods.include?('filter_parameters')
- assert_raise(NoMethodError) { @controller.filter_parameters([{'password' => '[FILTERED]'}]) }
- end
-end
View
6 actionpack/test/controller/new_base/base_test.rb
@@ -22,7 +22,7 @@ def modify_response_headers
end
def show_actions
- render :text => "actions: #{action_methods.to_a.join(', ')}"
+ render :text => "actions: #{action_methods.to_a.sort.join(', ')}"
end
protected
@@ -77,9 +77,9 @@ class BaseTest < Rack::TestCase
test "action methods" do
assert_equal Set.new(%w(
+ index
modify_response_headers
modify_response_body_twice
- index
modify_response_body
show_actions
)), SimpleController.action_methods
@@ -88,7 +88,7 @@ class BaseTest < Rack::TestCase
assert_equal Set.new, Submodule::ContainedEmptyController.action_methods
get "/dispatching/simple/show_actions"
- assert_body "actions: modify_response_headers, modify_response_body_twice, index, modify_response_body, show_actions"
+ assert_body "actions: index, modify_response_body, modify_response_body_twice, modify_response_headers, show_actions"
end
end
end
View
74 actionpack/test/controller/subscriber_test.rb
@@ -35,11 +35,9 @@ def with_page_cache
end
end
-module ActionControllerSubscriberTest
-
- def self.included(base)
- base.tests Another::SubscribersController
- end
+class ACSubscriberTest < ActionController::TestCase
+ tests Another::SubscribersController
+ include Rails::Subscriber::TestHelper
def setup
@old_logger = ActionController::Base.logger
@@ -63,13 +61,19 @@ def set_logger(logger)
ActionController::Base.logger = logger
end
+ def test_start_processing
+ get :show
+ wait
+ assert_equal 2, logs.size
+ assert_equal "Processing by Another::SubscribersController#show as HTML", logs.first
+ end
+
def test_process_action
get :show
wait
- assert_equal 1, logs.size
- assert_match /Completed/, logs.first
- assert_match /\[200\]/, logs.first
- assert_match /Another::SubscribersController#show/, logs.first
+ assert_equal 2, logs.size
+ assert_match /Completed/, logs.last
+ assert_match /with 200/, logs.last
end
def test_process_action_without_parameters
@@ -82,23 +86,23 @@ def test_process_action_with_parameters
get :show, :id => '10'
wait
- assert_equal 2, logs.size
- assert_equal 'Parameters: {"id"=>"10"}', logs[0]
+ assert_equal 3, logs.size
+ assert_equal 'Parameters: {"id"=>"10"}', logs[1]
end
def test_process_action_with_view_runtime
get :show
wait
- assert_match /\(Views: [\d\.]+ms\)/, logs[0]
+ assert_match /\(Views: [\d\.]+ms\)/, logs[1]
end
def test_process_action_with_filter_parameters
- Another::SubscribersController.filter_parameter_logging(:lifo, :amount)
+ @request.env["action_dispatch.parameter_filter"] = [:lifo, :amount]
get :show, :lifo => 'Pratik', :amount => '420', :step => '1'
wait
- params = logs[0]
+ params = logs[1]
assert_match /"amount"=>"\[FILTERED\]"/, params
assert_match /"lifo"=>"\[FILTERED\]"/, params
assert_match /"step"=>"1"/, params
@@ -108,34 +112,34 @@ def test_redirect_to
get :redirector
wait
- assert_equal 2, logs.size
- assert_equal "Redirected to http://foo.bar/", logs[0]
+ assert_equal 3, logs.size
+ assert_equal "Redirected to http://foo.bar/", logs[1]
end
def test_send_data
get :data_sender
wait
- assert_equal 2, logs.size
- assert_match /Sent data omg\.txt/, logs[0]
+ assert_equal 3, logs.size
+ assert_match /Sent data omg\.txt/, logs[1]
end
def test_send_file
get :file_sender
wait
- assert_equal 2, logs.size
- assert_match /Sent file/, logs[0]
- assert_match /test\/fixtures\/company\.rb/, logs[0]
+ assert_equal 3, logs.size
+ assert_match /Sent file/, logs[1]
+ assert_match /test\/fixtures\/company\.rb/, logs[1]
end
def test_send_xfile
get :xfile_sender
wait
- assert_equal 2, logs.size
- assert_match /Sent X\-Sendfile header/, logs[0]
- assert_match /test\/fixtures\/company\.rb/, logs[0]
+ assert_equal 3, logs.size
+ assert_match /Sent X\-Sendfile header/, logs[1]
+ assert_match /test\/fixtures\/company\.rb/, logs[1]
end
def test_with_fragment_cache
@@ -143,9 +147,9 @@ def test_with_fragment_cache
get :with_fragment_cache
wait
- assert_equal 3, logs.size
- assert_match /Exist fragment\? views\/foo/, logs[0]
- assert_match /Write fragment views\/foo/, logs[1]
+ assert_equal 4, logs.size
+ assert_match /Exist fragment\? views\/foo/, logs[1]
+ assert_match /Write fragment views\/foo/, logs[2]
ensure
ActionController::Base.perform_caching = true
end
@@ -155,9 +159,9 @@ def test_with_page_cache
get :with_page_cache
wait
- assert_equal 2, logs.size
- assert_match /Write page/, logs[0]
- assert_match /\/index\.html/, logs[0]
+ assert_equal 3, logs.size
+ assert_match /Write page/, logs[1]
+ assert_match /\/index\.html/, logs[1]
ensure
ActionController::Base.perform_caching = true
end
@@ -165,14 +169,4 @@ def test_with_page_cache
def logs
@logs ||= @logger.logged(:info)
end
-
- class SyncSubscriberTest < ActionController::TestCase
- include Rails::Subscriber::SyncTestHelper
- include ActionControllerSubscriberTest
- end
-
- class AsyncSubscriberTest < ActionController::TestCase
- include Rails::Subscriber::AsyncTestHelper
- include ActionControllerSubscriberTest
- end
end
View
2  actionpack/test/dispatch/request/json_params_parsing_test.rb
@@ -35,7 +35,7 @@ def teardown
begin
$stderr = StringIO.new
json = "[\"person]\": {\"name\": \"David\"}}"
- post "/parse", json, {'CONTENT_TYPE' => 'application/json'}
+ post "/parse", json, {'CONTENT_TYPE' => 'application/json', 'action_dispatch.show_exceptions' => true}
assert_response :error
$stderr.rewind && err = $stderr.read
assert err =~ /Error occurred while parsing request parameters/
View
2  actionpack/test/dispatch/request/xml_params_parsing_test.rb
@@ -43,7 +43,7 @@ def teardown
begin
$stderr = StringIO.new
xml = "<person><name>David</name><avatar type='file' name='me.jpg' content_type='image/jpg'>#{ActiveSupport::Base64.encode64('ABC')}</avatar></pineapple>"
- post "/parse", xml, default_headers
+ post "/parse", xml, default_headers.merge('action_dispatch.show_exceptions' => true)
assert_response :error
$stderr.rewind && err = $stderr.read
assert err =~ /Error occurred while parsing request parameters/
View
50 actionpack/test/dispatch/request_test.rb
@@ -454,6 +454,56 @@ def teardown
assert_equal Mime::XML, request.negotiate_mime([Mime::XML, Mime::CSV])
end
+ test "process parameter filter" do
+ test_hashes = [
+ [{'foo'=>'bar'},{'foo'=>'bar'},%w'food'],
+ [{'foo'=>'bar'},{'foo'=>'[FILTERED]'},%w'foo'],
+ [{'foo'=>'bar', 'bar'=>'foo'},{'foo'=>'[FILTERED]', 'bar'=>'foo'},%w'foo baz'],
+ [{'foo'=>'bar', 'baz'=>'foo'},{'foo'=>'[FILTERED]', 'baz'=>'[FILTERED]'},%w'foo baz'],
+ [{'bar'=>{'foo'=>'bar','bar'=>'foo'}},{'bar'=>{'foo'=>'[FILTERED]','bar'=>'foo'}},%w'fo'],
+ [{'foo'=>{'foo'=>'bar','bar'=>'foo'}},{'foo'=>'[FILTERED]'},%w'f banana'],
+ [{'baz'=>[{'foo'=>'baz'}]}, {'baz'=>[{'foo'=>'[FILTERED]'}]}, [/foo/]]]
+
+ test_hashes.each do |before_filter, after_filter, filter_words|
+ request = stub_request('action_dispatch.parameter_filter' => filter_words)
+ assert_equal after_filter, request.send(:process_parameter_filter, before_filter)
+
+ filter_words << 'blah'
+ filter_words << lambda { |key, value|
+ value.reverse! if key =~ /bargain/
+ }
+
+ request = stub_request('action_dispatch.parameter_filter' => filter_words)
+ before_filter['barg'] = {'bargain'=>'gain', 'blah'=>'bar', 'bar'=>{'bargain'=>{'blah'=>'foo'}}}
+ after_filter['barg'] = {'bargain'=>'niag', 'blah'=>'[FILTERED]', 'bar'=>{'bargain'=>{'blah'=>'[FILTERED]'}}}
+
+ assert_equal after_filter, request.send(:process_parameter_filter, before_filter)
+ end
+ end
+
+ test "filtered_parameters returns params filtered" do
+ request = stub_request('action_dispatch.request.parameters' =>
+ { 'lifo' => 'Pratik', 'amount' => '420', 'step' => '1' },
+ 'action_dispatch.parameter_filter' => [:lifo, :amount])
+
+ params = request.filtered_parameters
+ assert_equal "[FILTERED]", params["lifo"]
+ assert_equal "[FILTERED]", params["amount"]
+ assert_equal "1", params["step"]
+ end
+
+ test "filtered_env filters env as a whole" do
+ request = stub_request('action_dispatch.request.parameters' =>
+ { 'amount' => '420', 'step' => '1' }, "RAW_POST_DATA" => "yada yada",
+ 'action_dispatch.parameter_filter' => [:lifo, :amount])
+
+ request = stub_request(request.filtered_env)
+
+ assert_equal "[FILTERED]", request.raw_post
+ assert_equal "[FILTERED]", request.params["amount"]
+ assert_equal "1", request.params["step"]
+ end
+
protected
def stub_request(env={})
View
22 actionpack/test/dispatch/show_exceptions_test.rb
@@ -38,15 +38,15 @@ class ShowExceptionsTest < ActionController::IntegrationTest
@app = ProductionApp
self.remote_addr = '208.77.188.166'
- get "/"
+ get "/", {}, {'action_dispatch.show_exceptions' => true}
assert_response 500
assert_equal "500 error fixture\n", body
- get "/not_found"
+ get "/not_found", {}, {'action_dispatch.show_exceptions' => true}
assert_response 404
assert_equal "404 error fixture\n", body
- get "/method_not_allowed"
+ get "/method_not_allowed", {}, {'action_dispatch.show_exceptions' => true}
assert_response 405
assert_equal "", body
end
@@ -56,15 +56,15 @@ class ShowExceptionsTest < ActionController::IntegrationTest
['127.0.0.1', '::1'].each do |ip_address|
self.remote_addr = ip_address
- get "/"
+ get "/", {}, {'action_dispatch.show_exceptions' => true}
assert_response 500
assert_match /puke/, body
- get "/not_found"
+ get "/not_found", {}, {'action_dispatch.show_exceptions' => true}
assert_response 404
assert_match /#{ActionController::UnknownAction.name}/, body
- get "/method_not_allowed"
+ get "/method_not_allowed", {}, {'action_dispatch.show_exceptions' => true}
assert_response 405
assert_match /ActionController::MethodNotAllowed/, body
end
@@ -78,11 +78,11 @@ class ShowExceptionsTest < ActionController::IntegrationTest
@app = ProductionApp
self.remote_addr = '208.77.188.166'
- get "/"
+ get "/", {}, {'action_dispatch.show_exceptions' => true}
assert_response 500
assert_equal "500 localized error fixture\n", body
- get "/not_found"
+ get "/not_found", {}, {'action_dispatch.show_exceptions' => true}
assert_response 404
assert_equal "404 error fixture\n", body
ensure
@@ -94,15 +94,15 @@ class ShowExceptionsTest < ActionController::IntegrationTest
@app = DevelopmentApp
self.remote_addr = '208.77.188.166'
- get "/"
+ get "/", {}, {'action_dispatch.show_exceptions' => true}
assert_response 500
assert_match /puke/, body
- get "/not_found"
+ get "/not_found", {}, {'action_dispatch.show_exceptions' => true}
assert_response 404
assert_match /#{ActionController::UnknownAction.name}/, body
- get "/method_not_allowed"
+ get "/method_not_allowed", {}, {'action_dispatch.show_exceptions' => true}
assert_response 405
assert_match /ActionController::MethodNotAllowed/, body
end
View
112 actionpack/test/dispatch/subscriber_test.rb
@@ -1,112 +0,0 @@
-require "abstract_unit"
-require "rails/subscriber/test_helper"
-require "action_dispatch/railties/subscriber"
-
-module DispatcherSubscriberTest
- Boomer = lambda do |env|
- req = ActionDispatch::Request.new(env)
- case req.path
- when "/"
- [200, {}, []]
- else
- raise "puke!"
- end
- end
-
- App = ActionDispatch::Notifications.new(Boomer)
-
- def setup
- Rails::Subscriber.add(:action_dispatch, ActionDispatch::Railties::Subscriber.new)
- @app = App
- super
-
- @events = []
- ActiveSupport::Notifications.subscribe do |*args|
- @events << args
- end
- end
-
- def set_logger(logger)
- ActionController::Base.logger = logger
- end
-
- def test_publishes_notifications
- get "/"
- wait
-
- assert_equal 2, @events.size
- before, after = @events
-
- assert_equal 'action_dispatch.before_dispatch', before[0]
- assert_kind_of Hash, before[4][:env]
- assert_equal 'GET', before[4][:env]["REQUEST_METHOD"]
-
- assert_equal 'action_dispatch.after_dispatch', after[0]
- assert_kind_of Hash, after[4][:env]
- assert_equal 'GET', after[4][:env]["REQUEST_METHOD"]
- end
-
- def test_publishes_notifications_even_on_failures
- begin
- get "/puke"
- rescue
- end
-
- wait
-
- assert_equal 3, @events.size
- before, after, exception = @events
-
- assert_equal 'action_dispatch.before_dispatch', before[0]
- assert_kind_of Hash, before[4][:env]
- assert_equal 'GET', before[4][:env]["REQUEST_METHOD"]
-
- assert_equal 'action_dispatch.after_dispatch', after[0]
- assert_kind_of Hash, after[4][:env]
- assert_equal 'GET', after[4][:env]["REQUEST_METHOD"]
-
- assert_equal 'action_dispatch.exception', exception[0]
- assert_kind_of Hash, exception[4][:env]
- assert_equal 'GET', exception[4][:env]["REQUEST_METHOD"]
- assert_kind_of RuntimeError, exception[4][:exception]
- end
-
- def test_subscriber_logs_notifications
- get "/"
- wait
-
- log = @logger.logged(:info).first
- assert_equal 1, @logger.logged(:info).size
-
- assert_match %r{^Processing "/" to text/html}, log
- assert_match %r{\(for 127\.0\.0\.1}, log
- assert_match %r{\[GET\]}, log
- end
-
- def test_subscriber_has_its_logged_flushed_after_request
- assert_equal 0, @logger.flush_count
- get "/"
- wait
- assert_equal 1, @logger.flush_count
- end
-
- def test_subscriber_has_its_logged_flushed_even_after_busted_requests
- assert_equal 0, @logger.flush_count
- begin
- get "/puke"
- rescue
- end
- wait
- assert_equal 1, @logger.flush_count
- end
-
- class SyncSubscriberTest < ActionController::IntegrationTest
- include Rails::Subscriber::SyncTestHelper
- include DispatcherSubscriberTest
- end
-
- class AsyncSubscriberTest < ActionController::IntegrationTest
- include Rails::Subscriber::AsyncTestHelper
- include DispatcherSubscriberTest
- end
-end
View
13 actionpack/test/template/subscriber_test.rb
@@ -3,7 +3,8 @@
require "action_view/railties/subscriber"
require "controller/fake_models"
-module ActionViewSubscriberTest
+class AVSubscriberTest < ActiveSupport::TestCase
+ include Rails::Subscriber::TestHelper
def setup
@old_logger = ActionController::Base.logger
@@ -89,14 +90,4 @@ def test_render_collection_template_without_path
assert_equal 1, @logger.logged(:info).size
assert_match /Rendered collection/, @logger.logged(:info).last
end
-
- class SyncSubscriberTest < ActiveSupport::TestCase
- include Rails::Subscriber::SyncTestHelper
- include ActionViewSubscriberTest
- end
-
- class AsyncSubscriberTest < ActiveSupport::TestCase
- include Rails::Subscriber::AsyncTestHelper
- include ActionViewSubscriberTest
- end
end
View
2  activemodel/lib/active_model/lint.rb
@@ -50,6 +50,8 @@ def test_model_naming
assert_kind_of String, model_name
assert_kind_of String, model_name.human
assert_kind_of String, model_name.partial_path
+ assert_kind_of String, model_name.singular
+ assert_kind_of String, model_name.plural
end
# == Errors Testing
View
27 activerecord/lib/active_record.rb
@@ -45,7 +45,6 @@ module ActiveRecord
autoload :AssociationPreload
autoload :Associations
autoload :AttributeMethods
- autoload :Attributes
autoload :AutosaveAssociation
autoload :Relation
@@ -53,14 +52,13 @@ module ActiveRecord
autoload_under 'relation' do
autoload :QueryMethods
autoload :FinderMethods
- autoload :CalculationMethods
+ autoload :Calculations
autoload :PredicateBuilder
autoload :SpawnMethods
end
autoload :Base
autoload :Batches
- autoload :Calculations
autoload :Callbacks
autoload :DynamicFinderMatch
autoload :DynamicScopeMatch
@@ -78,7 +76,6 @@ module ActiveRecord
autoload :StateMachine
autoload :Timestamp
autoload :Transactions
- autoload :Types
autoload :Validations
end
@@ -96,28 +93,6 @@ module AttributeMethods
end
end
- module Attributes
- extend ActiveSupport::Autoload
-
- eager_autoload do
- autoload :Aliasing
- autoload :Store
- autoload :Typecasting
- end
- end
-
- module Type
- extend ActiveSupport::Autoload
-