Skip to content

Commit

Permalink
implementing include? on AM::Errors
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Feb 9, 2011
1 parent 39310f7 commit f48d32c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions activemodel/lib/active_model/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ def clear
messages.clear
end

# Do the error messages include an error with key +error+?
def include?(error)
messages.include? error
end

# Get messages for +key+
def get(key)
messages[key]
Expand Down
6 changes: 6 additions & 0 deletions activemodel/test/cases/errors_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ def self.lookup_ancestors
end
end

def test_include?
errors = ActiveModel::Errors.new(self)
errors[:foo] = 'omg'
assert errors.include?(:foo), 'errors should include :foo'
end

test "should return true if no errors" do
person = Person.new
person.errors[:foo]
Expand Down

0 comments on commit f48d32c

Please sign in to comment.