diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-01-11 17:57:02 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-01-11 17:57:02 -0800 |
commit | f8700038afdaea80cad34a4fca005e1ef068b53e (patch) | |
tree | 0a8c99108b6f7a52bc134bc63e7c8bd1d5f32bee /activerecord/lib/active_record | |
parent | fcd8925f236b391d562dc504bcd901f501140c11 (diff) | |
download | rails-f8700038afdaea80cad34a4fca005e1ef068b53e.tar.gz rails-f8700038afdaea80cad34a4fca005e1ef068b53e.tar.bz2 rails-f8700038afdaea80cad34a4fca005e1ef068b53e.zip |
adding a test for no method error
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/associations/association_proxy.rb | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/activerecord/lib/active_record/associations/association_proxy.rb b/activerecord/lib/active_record/associations/association_proxy.rb index 844d30c3f5..e4a449d4f4 100644 --- a/activerecord/lib/active_record/associations/association_proxy.rb +++ b/activerecord/lib/active_record/associations/association_proxy.rb @@ -286,19 +286,13 @@ module ActiveRecord private # Forwards any missing method call to the \target. - def method_missing(method, *args) + def method_missing(method, *args, &block) if load_target - unless @target.respond_to?(method) - message = "undefined method `#{method.to_s}' for \"#{@target}\":#{@target.class.to_s}" - raise NoMethodError, message - end - - if block_given? - @target.send(method, *args) { |*block_args| yield(*block_args) } - else - @target.send(method, *args) - end + return super unless @target.respond_to?(method) + @target.send(method, *args, &block) end + rescue NoMethodError => e + raise e, e.message.sub(/ for #<.*$/, " via proxy for #{@target}") end # Should be true if there is a foreign key present on the @owner which |