Skip to content

Commit

Permalink
Stop using deprecated DataMapper::Validate constant
Browse files Browse the repository at this point in the history
  • Loading branch information
jm81 committed Jul 27, 2011
1 parent a8b65d2 commit 28b1ed4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
22 changes: 8 additions & 14 deletions lib/devise/orm/data_mapper/dm-validations.rb
@@ -1,5 +1,5 @@
module DataMapper
module Validate
module Validations

# Monkey-patch ValidationErrors to support generation of error message from
# a Symbol. This does not translate, consistent with normal DataMapper
Expand All @@ -16,13 +16,19 @@ def add(field_name, message)
end
original_add(field_name, message) unless errors[field_name].include?(message)
end

# Some devise controller actions expect resource#errors to respond to
# #to_xml. Otherwise, we get a Missing template error
def to_xml(options = {})
@errors.to_hash.to_xml(options.merge(:root => 'errors'))
end
end
end
end

# Default error messages consistent with ActiveModel messages and devise
# expectations.
DataMapper::Validate::ValidationErrors.default_error_messages = {
DataMapper::Validations::ValidationErrors.default_error_messages = {
:absent => '%s must be absent',
:inclusion => '%s is not included in the list',
:exclusion => '%s is reserved',
Expand Down Expand Up @@ -54,15 +60,3 @@ def add(field_name, message)
:not_locked => '%s was not locked',
:expired => '%s has expired, please request a new one'
}

module DataMapper
module Validations
class ValidationErrors
# Some devise controller actions expect resource#errors to respond to
# #to_xml. Otherwise, we get a Missing template error
def to_xml(options = {})
@errors.to_hash.to_xml(options.merge(:root => 'errors'))
end
end
end
end
2 changes: 1 addition & 1 deletion test/orm/data_mapper.rb
Expand Up @@ -10,7 +10,7 @@ class ActiveSupport::TestCase
end

module DataMapper
module Validate
module Validations
class ValidationErrors

# ActiveModel prepends field names in +#full_messages+, and so the
Expand Down

0 comments on commit 28b1ed4

Please sign in to comment.