Ticket #11450: deprecation_warnings_for_the_masses.diff
| File deprecation_warnings_for_the_masses.diff, 3.8 kB (added by thechrisoshow, 8 months ago) |
|---|
-
activesupport/test/deprecation_test.rb
old new 24 24 def d; end 25 25 def e; end 26 26 deprecate :a, :b, :c => :e, :d => "you now need to do something extra for this one" 27 28 def custom 29 ActiveSupport::Deprecation.warn("Don't go using this method") 30 end 27 31 end 28 32 29 33 … … 148 152 assert_not_deprecated { error.message } 149 153 assert_nil @last_message 150 154 end 155 156 def test_deprecated_warning_with_custom_details_message 157 ActiveSupport::Deprecation.detail_message = "This message is so 90s" 158 assert_deprecated(/This message is so 90s/) {@dtc.custom} 159 ensure 160 ActiveSupport::Deprecation.detail_message = ActiveSupport::Deprecation.detail_message = ActiveSupport::Deprecation::DEFAULT_DETAIL_MESSAGE 161 end 162 163 def test_oldskool_deprecation_details 164 assert_deprecated(/#{ActiveSupport::Deprecation::DEFAULT_DETAIL_MESSAGE}/) {@dtc.custom} 165 end 166 151 167 end -
activesupport/lib/active_support/deprecation.rb
old new 1 1 require 'yaml' 2 2 3 3 module ActiveSupport 4 module Deprecation #:nodoc: 5 mattr_accessor :debug 4 # 5 # ActiveSupport::Deprecation is used by the Rails code to create deprecation warnings. 6 # You can add deprecation warnings to your own code by calling 7 # ActiveSupport::Deprecation.warn(message, callstack) 8 # Every deprecation message includes a standard detail message. You can change this by putting something like the following at the bottom of environment.rb: 9 # ActiveSupport::Deprecation.detail_message = "For more deprecation details see our webpage" 10 module Deprecation 11 mattr_accessor :debug #:nodoc: 6 12 self.debug = false 13 14 mattr_accessor :detail_message 15 16 # 17 # This is the default message that Rails adds to all of its deprecation messages. 18 # You can override it with your own message using ActiveSupport.Deprecation.detail_message 19 # This can be handy if you have a particular webpage or document that details all the deprecations. 20 DEFAULT_DETAIL_MESSAGE = "See http://www.rubyonrails.org/deprecation for details." 21 self.detail_message = DEFAULT_DETAIL_MESSAGE 7 22 8 23 # Choose the default warn behavior according to RAILS_ENV. 9 24 # Ignore deprecation warnings in production. … … 18 33 logger.debug callstack.join("\n ") if debug 19 34 } 20 35 } 21 36 22 37 class << self 38 # Use warn to mark your methods as deprecated with a message. 39 # Pass in an appropriate <tt>message</tt> detailing what the user of the method should do instead. 23 40 def warn(message = nil, callstack = caller) 24 41 behavior.call(deprecation_message(callstack, message), callstack) if behavior && !silenced? 25 42 end 26 43 27 def default_behavior 44 def default_behavior #:nodoc: 28 45 if defined?(RAILS_ENV) 29 46 DEFAULT_BEHAVIORS[RAILS_ENV.to_s] 30 47 else … … 50 67 51 68 52 69 private 53 def deprecation_message(callstack, message = nil )70 def deprecation_message(callstack, message = nil, details_message = nil) 54 71 message ||= "You are using deprecated behavior which will be removed from Rails 2.0." 55 "DEPRECATION WARNING: #{message} See http://www.rubyonrails.org/deprecation for details.#{deprecation_caller_message(callstack)}"72 "DEPRECATION WARNING: #{message} #{self.detail_message} #{deprecation_caller_message(callstack)}" 56 73 end 57 74 58 75 def deprecation_caller_message(callstack)