Changeset 4666
- Timestamp:
- 08/05/06 06:33:28 (2 years ago)
- Files:
-
- trunk/activesupport/lib/active_support/deprecation.rb (modified) (2 diffs)
- trunk/activesupport/test/deprecation_test.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activesupport/lib/active_support/deprecation.rb
r4647 r4666 49 49 50 50 module Assertions 51 def assert_deprecated( regexp= nil, &block)51 def assert_deprecated(match = nil, &block) 52 52 last = with_last_message_tracking_deprecation_behavior(&block) 53 53 assert last, "Expected a deprecation warning within the block but received none" 54 if regexp 55 assert_match regexp, last, "Deprecation warning didn't match #{regexp}: #{last}" 56 end 54 match = Regexp.new(match) unless match.is_a?(Regexp) 55 assert_match match, last, "Deprecation warning didn't match #{match}: #{last}" 57 56 end 58 57 … … 73 72 end 74 73 end 74 75 # Stand-in for @request, @attributes, etc. 76 class DeprecatedInstanceVariableProxy 77 instance_methods.each { |m| undef_method m unless m =~ /^__/ } 78 79 def initialize(instance, method, var = "@#{method}") 80 @instance, @method, @var = instance, method, var 81 deprecation_warning :initialize, caller 82 end 83 84 private 85 def deprecation_warning(called, callstack) 86 ActiveSupport::Deprecation.warn("Using #{@var} directly is deprecated - call #{@method} instead.", callstack) 87 end 88 89 def method_missing(called, *args, &block) 90 deprecation_warning called, caller 91 @instance.__send__(@method).__send__(called, *args, &block) 92 end 93 end 75 94 end 76 95 end trunk/activesupport/test/deprecation_test.rb
r4647 r4666 2 2 3 3 class Deprecatee 4 def initialize 5 @request = ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new(self, :request) 6 @_request = 'there we go' 7 end 8 def request; @_request end 9 def old_request; @request end 10 4 11 def partially(foo = nil) 5 12 ActiveSupport::Deprecation.warn 'calling with foo=nil is out' if foo.nil? … … 58 65 assert_deprecated(/foo=nil/) { @dtc.partially } 59 66 end 67 68 def test_deprecated_instance_variable_proxy 69 assert_not_deprecated { @dtc.request.size } 70 71 assert_deprecated('Using @request directly is deprecated - call request instead.') do 72 assert_equal @dtc.request.size, @dtc.old_request.size 73 assert_equal @dtc.request.to_s, @dtc.old_request.to_s 74 end 75 end 60 76 end