Skip to content

Commit

Permalink
Merge pull request #9774 from senny/9772_reraise_no_method_error_in_p…
Browse files Browse the repository at this point in the history
…roper_context

`TimeWithZone` raises `NoMethodError` in proper context.
  • Loading branch information
pixeltrix committed Mar 18, 2013
2 parents eb32b36 + 836ea9f commit 341f9a0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions 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*
Expand Down
2 changes: 2 additions & 0 deletions activesupport/lib/active_support/time_with_zone.rb
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions activesupport/test/core_ext/time_with_zone_test.rb
Expand Up @@ -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
Expand Down

0 comments on commit 341f9a0

Please sign in to comment.