Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #8063 from nikitug/deprecation_caller_context

Provide a call stack for deprecation warnings where needed.
  • Loading branch information...
commit d1c95d912ec39e7e374aee605a1d6fb11f8521d7 2 parents 72e6fb0 + 0b7067d
@carlosantoniodasilva carlosantoniodasilva authored
Showing with 88 additions and 55 deletions.
  1. +2 −2 actionpack/lib/action_controller/record_identifier.rb
  2. +3 −3 actionpack/lib/action_controller/test_case.rb
  3. +2 −2 actionpack/lib/action_dispatch/http/mime_type.rb
  4. +1 −1  actionpack/lib/action_view/helpers/asset_tag_helper.rb
  5. +2 −2 actionpack/lib/action_view/helpers/form_helper.rb
  6. +3 −1 actionpack/lib/action_view/helpers/form_options_helper.rb
  7. +15 −5 actionpack/lib/action_view/helpers/form_tag_helper.rb
  8. +2 −2 actionpack/lib/action_view/helpers/javascript_helper.rb
  9. +6 −2 actionpack/lib/action_view/helpers/url_helper.rb
  10. +2 −1  actionpack/lib/action_view/template.rb
  11. +7 −1 actionpack/lib/action_view/template/resolver.rb
  12. +5 −6 activemodel/lib/active_model/attribute_methods.rb
  13. +1 −1  activemodel/lib/active_model/observing.rb
  14. +1 −1  activerecord/lib/active_record/associations/association.rb
  15. +2 −1  activerecord/lib/active_record/attribute_methods/serialization.rb
  16. +4 −3 activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
  17. +3 −2 activerecord/lib/active_record/connection_adapters/column.rb
  18. +3 −4 activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb
  19. +2 −3 activerecord/lib/active_record/migration.rb
  20. +2 −1  activerecord/lib/active_record/readonly_attributes.rb
  21. +2 −1  activerecord/lib/active_record/scoping/default.rb
  22. +2 −1  activerecord/lib/active_record/scoping/named.rb
  23. +2 −1  activesupport/lib/active_support/benchmarkable.rb
  24. +5 −2 activesupport/lib/active_support/callbacks.rb
  25. +3 −2 activesupport/lib/active_support/json/variable.rb
  26. +2 −1  activesupport/lib/active_support/test_case.rb
  27. +4 −3 railties/lib/rails/application/configuration.rb
View
4 actionpack/lib/action_controller/record_identifier.rb
@@ -8,12 +8,12 @@ module RecordIdentifier
'ActionView::RecodIdentifier module.'
def dom_id(record, prefix = nil)
- ActiveSupport::Deprecation.warn 'dom_id ' + MESSAGE
+ ActiveSupport::Deprecation.warn('dom_id ' + MESSAGE, caller)
ActionView::RecordIdentifier.dom_id(record, prefix)
end
def dom_class(record, prefix = nil)
- ActiveSupport::Deprecation.warn 'dom_class ' + MESSAGE
+ ActiveSupport::Deprecation.warn('dom_class ' + MESSAGE, caller)
ActionView::RecordIdentifier.dom_class(record, prefix)
end
end
View
6 actionpack/lib/action_controller/test_case.rb
@@ -476,7 +476,7 @@ def paramify_values(hash_or_array_or_value)
def process(action, http_method = 'GET', *args)
check_required_ivars
- http_method, args = handle_old_process_api(http_method, args)
+ http_method, args = handle_old_process_api(http_method, args, caller)
if args.first.is_a?(String) && http_method != 'HEAD'
@request.env['RAW_POST_DATA'] = args.shift
@@ -579,10 +579,10 @@ def check_required_ivars
end
end
- def handle_old_process_api(http_method, args)
+ def handle_old_process_api(http_method, args, callstack)
# 4.0: Remove this method.
if http_method.is_a?(Hash)
- ActiveSupport::Deprecation.warn("TestCase#process now expects the HTTP method as second argument: process(action, http_method, params, session, flash)")
+ ActiveSupport::Deprecation.warn("TestCase#process now expects the HTTP method as second argument: process(action, http_method, params, session, flash)", callstack)
args.unshift(http_method)
http_method = args.last.is_a?(String) ? args.last : "GET"
end
View
4 actionpack/lib/action_dispatch/http/mime_type.rb
@@ -275,12 +275,12 @@ def =~(mime_type)
# Returns true if Action Pack should check requests using this Mime Type for possible request forgery. See
# ActionController::RequestForgeryProtection.
def verify_request?
- ActiveSupport::Deprecation.warn "Mime::Type#verify_request? is deprecated and will be removed in Rails 4.1"
+ ActiveSupport::Deprecation.warn("Mime::Type#verify_request? is deprecated and will be removed in Rails 4.1", caller)
@@browser_generated_types.include?(to_sym)
end
def self.browser_generated_types
- ActiveSupport::Deprecation.warn "Mime::Type.browser_generated_types is deprecated and will be removed in Rails 4.1"
+ ActiveSupport::Deprecation.warn("Mime::Type.browser_generated_types is deprecated and will be removed in Rails 4.1", caller)
@@browser_generated_types
end
View
2  actionpack/lib/action_view/helpers/asset_tag_helper.rb
@@ -125,7 +125,7 @@ def auto_discovery_link_tag(type = :rss, url_options = {}, tag_options = {})
"the :type option key. This behavior is deprecated and will be remove in Rails 4.1. You should pass " +
":type option explicitly if you want to use other types, for example: " +
"auto_discovery_link_tag(:xml, '/feed.xml', :type => 'application/xml')"
- ActiveSupport::Deprecation.warn message
+ ActiveSupport::Deprecation.warn(message, caller)
end
tag(
View
4 actionpack/lib/action_view/helpers/form_helper.rb
@@ -1181,8 +1181,8 @@ def to_model
def initialize(object_name, object, template, options, block=nil)
if block
- ActiveSupport::Deprecation.warn(
- "Giving a block to FormBuilder is deprecated and has no effect anymore.")
+ message = "Giving a block to FormBuilder is deprecated and has no effect anymore."
+ ActiveSupport::Deprecation.warn(message, caller)
end
@nested_child_index = {}
View
4 actionpack/lib/action_view/helpers/form_options_helper.rb
@@ -519,7 +519,9 @@ def grouped_options_for_select(grouped_options, selected_key = nil, options = {}
else
prompt = options
options = {}
- ActiveSupport::Deprecation.warn "Passing the prompt to grouped_options_for_select as an argument is deprecated. Please use an options hash like `{ prompt: #{prompt.inspect} }`."
+ message = "Passing the prompt to grouped_options_for_select as an argument is deprecated. " /
+ "Please use an options hash like `{ prompt: #{prompt.inspect} }`."
+ ActiveSupport::Deprecation.warn(message, caller)
end
body = "".html_safe
View
20 actionpack/lib/action_view/helpers/form_tag_helper.rb
@@ -425,13 +425,17 @@ def submit_tag(value = "Save changes", options = {})
options = options.stringify_keys
if disable_with = options.delete("disable_with")
- ActiveSupport::Deprecation.warn ":disable_with option is deprecated and will be removed from Rails 4.1. Use ':data => { :disable_with => \'Text\' }' instead"
+ message = ":disable_with option is deprecated and will be removed from Rails 4.1. " /
+ "Use ':data => { :disable_with => \'Text\' }' instead."
+ ActiveSupport::Deprecation.warn(message, caller)
options["data-disable-with"] = disable_with
end
if confirm = options.delete("confirm")
- ActiveSupport::Deprecation.warn ":confirm option is deprecated and will be removed from Rails 4.1. Use ':data => { :confirm => \'Text\' }' instead'"
+ message = ":confirm option is deprecated and will be removed from Rails 4.1. " /
+ "Use ':data => { :confirm => \'Text\' }' instead'."
+ ActiveSupport::Deprecation.warn(message, caller)
options["data-confirm"] = confirm
end
@@ -483,13 +487,17 @@ def button_tag(content_or_options = nil, options = nil, &block)
options = options.stringify_keys
if disable_with = options.delete("disable_with")
- ActiveSupport::Deprecation.warn ":disable_with option is deprecated and will be removed from Rails 4.1. Use ':data => { :disable_with => \'Text\' }' instead"
+ message = ":disable_with option is deprecated and will be removed from Rails 4.1. " /
+ "Use ':data => { :disable_with => \'Text\' }' instead."
+ ActiveSupport::Deprecation.warn(message, caller)
options["data-disable-with"] = disable_with
end
if confirm = options.delete("confirm")
- ActiveSupport::Deprecation.warn ":confirm option is deprecated and will be removed from Rails 4.1. Use ':data => { :confirm => \'Text\' }' instead'"
+ message = ":confirm option is deprecated and will be removed from Rails 4.1. " /
+ "Use ':data => { :confirm => \'Text\' }' instead'."
+ ActiveSupport::Deprecation.warn(message, caller)
options["data-confirm"] = confirm
end
@@ -533,7 +541,9 @@ def image_submit_tag(source, options = {})
options = options.stringify_keys
if confirm = options.delete("confirm")
- ActiveSupport::Deprecation.warn ":confirm option is deprecated and will be removed from Rails 4.1. Use ':data => { :confirm => \'Text\' }' instead'"
+ message = ":confirm option is deprecated and will be removed from Rails 4.1. " /
+ "Use ':data => { :confirm => \'Text\' }' instead'."
+ ActiveSupport::Deprecation.warn(message, caller)
options["data-confirm"] = confirm
end
View
4 actionpack/lib/action_view/helpers/javascript_helper.rb
@@ -80,7 +80,7 @@ def javascript_cdata_section(content) #:nodoc:
def button_to_function(name, function=nil, html_options={})
message = "button_to_function is deprecated and will be removed from Rails 4.1. We recomend to use Unobtrusive JavaScript instead. " +
"See http://guides.rubyonrails.org/working_with_javascript_in_rails.html#unobtrusive-javascript"
- ActiveSupport::Deprecation.warn message
+ ActiveSupport::Deprecation.warn(message, caller)
onclick = "#{"#{html_options[:onclick]}; " if html_options[:onclick]}#{function};"
@@ -102,7 +102,7 @@ def button_to_function(name, function=nil, html_options={})
def link_to_function(name, function, html_options={})
message = "link_to_function is deprecated and will be removed from Rails 4.1. We recomend to use Unobtrusive JavaScript instead. " +
"See http://guides.rubyonrails.org/working_with_javascript_in_rails.html#unobtrusive-javascript"
- ActiveSupport::Deprecation.warn message
+ ActiveSupport::Deprecation.warn(message, caller)
onclick = "#{"#{html_options[:onclick]}; " if html_options[:onclick]}#{function}; return false;"
href = html_options[:href] || '#'
View
8 actionpack/lib/action_view/helpers/url_helper.rb
@@ -577,7 +577,9 @@ def convert_options_to_data_attributes(options, html_options)
method = html_options.delete('method')
if confirm
- ActiveSupport::Deprecation.warn ":confirm option is deprecated and will be removed from Rails 4.1. Use ':data => { :confirm => \'Text\' }' instead"
+ message = ":confirm option is deprecated and will be removed from Rails 4.1. " /
+ "Use ':data => { :confirm => \'Text\' }' instead."
+ ActiveSupport::Deprecation.warn(message, caller)
html_options["data-confirm"] = confirm
end
@@ -585,7 +587,9 @@ def convert_options_to_data_attributes(options, html_options)
add_method_to_attributes!(html_options, method) if method
if disable_with
- ActiveSupport::Deprecation.warn ":disable_with option is deprecated and will be removed from Rails 4.1. Use ':data => { :disable_with => \'Text\' }' instead"
+ message = ":disable_with option is deprecated and will be removed from Rails 4.1. " /
+ "Use ':data => { :disable_with => \'Text\' }' instead."
+ ActiveSupport::Deprecation.warn(message, caller)
html_options["data-disable-with"] = disable_with
end
View
3  actionpack/lib/action_view/template.rb
@@ -149,7 +149,8 @@ def render(view, locals, buffer=nil, &block)
end
def mime_type
- ActiveSupport::Deprecation.warn 'Template#mime_type is deprecated and will be removed in Rails 4.1. Please use type method instead.'
+ message = 'Template#mime_type is deprecated and will be removed in Rails 4.1. Please use type method instead.'
+ ActiveSupport::Deprecation.warn(message, caller)
@mime_type ||= Mime::Type.lookup_by_extension(@formats.first.to_s) if @formats.first
end
View
8 actionpack/lib/action_view/template/resolver.rb
@@ -232,8 +232,14 @@ def mtime(p)
def extract_handler_and_format(path, default_formats)
pieces = File.basename(path).split(".")
pieces.shift
+
extension = pieces.pop
- ActiveSupport::Deprecation.warn "The file #{path} did not specify a template handler. The default is currently ERB, but will change to RAW in the future." unless extension
+ unless extension
+ message = "The file #{path} did not specify a template handler. The default is currently ERB, " /
+ "but will change to RAW in the future."
+ ActiveSupport::Deprecation.warn(message, caller)
+ end
+
handler = Template.handler_for_extension(extension)
format = pieces.last && Template::Types[pieces.last]
[handler, format]
View
11 activemodel/lib/active_model/attribute_methods.rb
@@ -383,12 +383,11 @@ class AttributeMethodMatcher #:nodoc:
def initialize(options = {})
if options[:prefix] == '' || options[:suffix] == ''
- ActiveSupport::Deprecation.warn(
- "Specifying an empty prefix/suffix for an attribute method is no longer " \
- "necessary. If the un-prefixed/suffixed version of the method has not been " \
- "defined when `define_attribute_methods` is called, it will be defined " \
- "automatically."
- )
+ message = "Specifying an empty prefix/suffix for an attribute method is no longer " \
+ "necessary. If the un-prefixed/suffixed version of the method has not been " \
+ "defined when `define_attribute_methods` is called, it will be defined " \
+ "automatically."
+ ActiveSupport::Deprecation.warn(message, caller)
end
@prefix, @suffix = options.fetch(:prefix, ''), options.fetch(:suffix, '')
View
2  activemodel/lib/active_model/observing.rb
@@ -172,7 +172,7 @@ def observers_count
# <tt>count_observers</tt> is deprecated. Use #observers_count.
def count_observers
msg = "count_observers is deprecated in favor of observers_count"
- ActiveSupport::Deprecation.warn(msg)
+ ActiveSupport::Deprecation.warn(msg, caller)
observers_count
end
View
2  activerecord/lib/active_record/associations/association.rb
@@ -85,7 +85,7 @@ def scope
end
def scoped
- ActiveSupport::Deprecation.warn("#scoped is deprecated. use #scope instead.")
+ ActiveSupport::Deprecation.warn("#scoped is deprecated. use #scope instead.", caller)
scope
end
View
3  activerecord/lib/active_record/attribute_methods/serialization.rb
@@ -45,7 +45,8 @@ def serialize(attr_name, class_name = Object)
end
def serialized_attributes
- ActiveSupport::Deprecation.warn("Instance level serialized_attributes method is deprecated, please use class level method.")
+ message = "Instance level serialized_attributes method is deprecated, please use class level method."
+ ActiveSupport::Deprecation.warn(message, caller)
defined?(@serialized_attributes) ? @serialized_attributes : self.class.serialized_attributes
end
View
7 activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
@@ -255,15 +255,16 @@ def open_transactions
end
def increment_open_transactions
- ActiveSupport::Deprecation.warn "#increment_open_transactions is deprecated and has no effect"
+ ActiveSupport::Deprecation.warn("#increment_open_transactions is deprecated and has no effect", caller)
end
def decrement_open_transactions
- ActiveSupport::Deprecation.warn "#decrement_open_transactions is deprecated and has no effect"
+ ActiveSupport::Deprecation.warn("#decrement_open_transactions is deprecated and has no effect", caller)
end
def transaction_joinable=(joinable)
- ActiveSupport::Deprecation.warn "#transaction_joinable= is deprecated. Please pass the :joinable option to #begin_transaction instead."
+ message = "#transaction_joinable= is deprecated. Please pass the :joinable option to #begin_transaction instead."
+ ActiveSupport::Deprecation.warn(message, caller)
@transaction.joinable = joinable
end
View
5 activerecord/lib/active_record/connection_adapters/column.rb
@@ -107,8 +107,9 @@ def type_cast(value)
end
def type_cast_code(var_name)
- ActiveSupport::Deprecation.warn("Column#type_cast_code is deprecated in favor of" \
- "using Column#type_cast only, and it is going to be removed in future Rails versions.")
+ message = "Column#type_cast_code is deprecated in favor of using Column#type_cast only, " \
+ "and it is going to be removed in future Rails versions."
+ ActiveSupport::Deprecation.warn(message, caller)
klass = self.class.name
View
7 activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb
@@ -221,10 +221,9 @@ def rollback_db_transaction
end
def outside_transaction?
- ActiveSupport::Deprecation.warn(
- "#outside_transaction? is deprecated. This method was only really used " \
- "internally, but you can use #transaction_open? instead."
- )
+ message = "#outside_transaction? is deprecated. This method was only really used " \
+ "internally, but you can use #transaction_open? instead."
+ ActiveSupport::Deprecation.warn(message, caller)
@connection.transaction_status == PGconn::PQTRANS_IDLE
end
View
5 activerecord/lib/active_record/migration.rb
@@ -732,9 +732,8 @@ def migrate
running = runnable
if block_given?
- ActiveSupport::Deprecation.warn(<<-eomsg)
-block argument to migrate is deprecated, please filter migrations before constructing the migrator
- eomsg
+ message = "block argument to migrate is deprecated, please filter migrations before constructing the migrator"
+ ActiveSupport::Deprecation.warn(message, caller)
running.select! { |m| yield m }
end
View
3  activerecord/lib/active_record/readonly_attributes.rb
@@ -22,7 +22,8 @@ def readonly_attributes
end
def _attr_readonly
- ActiveSupport::Deprecation.warn("Instance level _attr_readonly method is deprecated, please use class level method.")
+ message = "Instance level _attr_readonly method is deprecated, please use class level method."
+ ActiveSupport::Deprecation.warn(message, caller)
defined?(@_attr_readonly) ? @_attr_readonly : self.class._attr_readonly
end
end
View
3  activerecord/lib/active_record/scoping/default.rb
@@ -95,7 +95,8 @@ def default_scope(scope = nil)
"Calling #default_scope without a block is deprecated. For example instead " \
"of `default_scope where(color: 'red')`, please use " \
"`default_scope { where(color: 'red') }`. (Alternatively you can just redefine " \
- "self.default_scope.)"
+ "self.default_scope.)",
+ caller
)
end
View
3  activerecord/lib/active_record/scoping/named.rb
@@ -156,7 +156,8 @@ def scope(name, body, &block)
"`scope :red, -> { where(color: 'red') }`. There are numerous gotchas " \
"in the former usage and it makes the implementation more complicated " \
"and buggy. (If you prefer, you can just define a class method named " \
- "`self.red`.)"
+ "`self.red`.)",
+ caller
)
end
View
3  activesupport/lib/active_support/benchmarkable.rb
@@ -48,7 +48,8 @@ def benchmark(message = "Benchmarking", options = {})
# Silence the logger during the execution of the block.
def silence
- ActiveSupport::Deprecation.warn "ActiveSupport::Benchmarkable#silence is deprecated. It will be removed from Rails 4.1."
+ message = "ActiveSupport::Benchmarkable#silence is deprecated. It will be removed from Rails 4.1."
+ ActiveSupport::Deprecation.warn(message, caller)
old_logger_level, logger.level = logger.level, ::Logger::ERROR if logger
yield
ensure
View
7 activesupport/lib/active_support/callbacks.rb
@@ -282,12 +282,15 @@ def #{method_name}(&blk)
def _normalize_legacy_filter(kind, filter)
if !filter.respond_to?(kind) && filter.respond_to?(:filter)
- ActiveSupport::Deprecation.warn("Filter object with #filter method is deprecated. Define method corresponding to filter type (#before, #after or #around).")
+ message = "Filter object with #filter method is deprecated. Define method corresponding " \
+ "to filter type (#before, #after or #around)."
+ ActiveSupport::Deprecation.warn(message, caller)
filter.singleton_class.class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
def #{kind}(context, &block) filter(context, &block) end
RUBY_EVAL
elsif filter.respond_to?(:before) && filter.respond_to?(:after) && kind == :around && !filter.respond_to?(:around)
- ActiveSupport::Deprecation.warn("Filter object with #before and #after methods is deprecated. Define #around method instead.")
+ message = "Filter object with #before and #after methods is deprecated. Define #around method instead."
+ ActiveSupport::Deprecation.warn(message, caller)
def filter.around(context)
should_continue = before(context)
yield if should_continue
View
5 activesupport/lib/active_support/json/variable.rb
@@ -5,8 +5,9 @@ module JSON
# Deprecated: A string that returns itself as its JSON-encoded form.
class Variable < String
def initialize(*args)
- ActiveSupport::Deprecation.warn 'ActiveSupport::JSON::Variable is deprecated and will be removed in Rails 4.1. ' \
- 'For your own custom JSON literals, define #as_json and #encode_json yourself.'
+ message = 'ActiveSupport::JSON::Variable is deprecated and will be removed in Rails 4.1. ' \
+ 'For your own custom JSON literals, define #as_json and #encode_json yourself.'
+ ActiveSupport::Deprecation.warn(message, caller)
super
end
View
3  activesupport/lib/active_support/test_case.rb
@@ -43,7 +43,8 @@ def self.describe(text)
if block_given?
super
else
- ActiveSupport::Deprecation.warn("`describe` without a block is deprecated, please switch to: `def self.name; #{text.inspect}; end`\n")
+ message = "`describe` without a block is deprecated, please switch to: `def self.name; #{text.inspect}; end`\n"
+ ActiveSupport::Deprecation.warn(message, caller)
class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
def self.name
View
7 railties/lib/rails/application/configuration.rb
@@ -88,9 +88,10 @@ def paths
end
def threadsafe!
- ActiveSupport::Deprecation.warn "config.threadsafe! is deprecated. Rails applications " \
- "behave by default as thread safe in production as long as config.cache_classes and " \
- "config.eager_load are set to true"
+ message = "config.threadsafe! is deprecated. Rails applications " \
+ "behave by default as thread safe in production as long as config.cache_classes and " \
+ "config.eager_load are set to true"
+ ActiveSupport::Deprecation.warn(message, caller)
@cache_classes = true
@eager_load = true
self
Please sign in to comment.
Something went wrong with that request. Please try again.