Skip to content

Commit

Permalink
Formtastic uses [] method on Errors, added alias to support this (Bod…
Browse files Browse the repository at this point in the history
…aniel Jeanes and Les Hill)
  • Loading branch information
jnunemaker committed Oct 2, 2009
1 parent e276e3c commit 2c6ac7d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/errors.rb
Expand Up @@ -28,6 +28,8 @@ def on(attribute)
return nil if errors[attribute.to_sym].nil?
errors[attribute.to_sym].size == 1 ? errors[attribute.to_sym].first : errors[attribute.to_sym]
end

alias [] on

def add(attribute, message) #:nodoc:
errors[attribute.to_sym] = [] if errors[attribute.to_sym].nil?
Expand Down
8 changes: 7 additions & 1 deletion test/unit/test_errors.rb
Expand Up @@ -60,5 +60,11 @@
errors.add(:attribute1, "message1")
errors.add(:attribute2, "message2")
errors.count
end
end

expect "message" do
errors = Validatable::Errors.new
errors.add(:attribute, "message")
errors[:attribute]
end
end

0 comments on commit 2c6ac7d

Please sign in to comment.