Skip to content
Browse files

Merge pull request #9774 from senny/9772_reraise_no_method_error_in_p…

…roper_context

`TimeWithZone` raises `NoMethodError` in proper context.
  • Loading branch information...
2 parents eb32b36 + 836ea9f commit 341f9a079957d61afc5c05aec23a1efc9d608020 @pixeltrix pixeltrix committed Mar 18, 2013
View
5 activesupport/CHANGELOG.md
@@ -1,5 +1,10 @@
## Rails 4.0.0 (unreleased) ##
+* `ActiveSupport::TimeWithZone` raises `NoMethodError` in proper context.
+ Fixes #9772.
+
+ *Yves Senn*
+
* Fix deletion of empty directories in `ActiveSupport::Cache::FileStore`.
*Charles Jones*
View
2 activesupport/lib/active_support/time_with_zone.rb
@@ -366,6 +366,8 @@ def respond_to_missing?(sym, include_priv)
# TimeWithZone with the existing +time_zone+.
def method_missing(sym, *args, &block)
wrap_with_time_zone time.__send__(sym, *args, &block)
+ rescue NoMethodError => e
+ raise e, e.message.sub(time.inspect, self.inspect), e.backtrace
end
private
View
8 activesupport/test/core_ext/time_with_zone_test.rb
@@ -779,6 +779,14 @@ def test_advance_1_year_during_dst
assert_equal "Sun, 15 Jul 2007 10:30:00 EDT -04:00", (twz - 1.year).inspect
end
+ def test_no_method_error_has_proper_context
+ e = assert_raises(NoMethodError) {
+ @twz.this_method_does_not_exist
+ }
+ assert_equal "undefined method `this_method_does_not_exist' for Fri, 31 Dec 1999 19:00:00 EST -05:00:Time", e.message
+ assert_no_match "rescue", e.backtrace.first
+ end
+
protected
def with_env_tz(new_tz = 'US/Eastern')
old_tz, ENV['TZ'] = ENV['TZ'], new_tz

0 comments on commit 341f9a0

Please sign in to comment.
Something went wrong with that request. Please try again.