Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

Commit

Permalink
Implement #respond_to? in addition to #method_missing
Browse files Browse the repository at this point in the history
[#1419 state:resolved]
  • Loading branch information
snusnu committed Oct 27, 2010
1 parent 69b4b9a commit 8671442
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/dm-validations/validation_errors.rb
Expand Up @@ -109,6 +109,10 @@ def method_missing(meth, *args, &block)
errors.send(meth, *args, &block)
end

def respond_to?(method)
super || errors.respond_to?(method)
end

def [](property_name)
if property_errors = errors[property_name.to_sym]
property_errors
Expand Down
16 changes: 16 additions & 0 deletions spec/unit/validation_errors/respond_to_spec.rb
@@ -0,0 +1,16 @@
require 'spec_helper'

describe 'DataMapper::Validations::ValidationErrors#respond_to?' do

subject { DataMapper::Validations::ValidationErrors.new(Object.new) }

it 'should look for the method in self' do
subject.should respond_to(:full_messages)
end

it 'should delegate lookup to the underlying errors hash' do
subject.should respond_to(:size)
end

end

0 comments on commit 8671442

Please sign in to comment.