Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 34 lines (29 sloc) 0.981 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
require 'rails/test_help'

DataMapper.auto_migrate!

class ActiveSupport::TestCase
  setup do
    User.all.destroy!
    Admin.all.destroy!
  end
end

if VALIDATION_LIB == 'dm-validations'
  module DataMapper
    module Validations
      class ValidationErrors

        # ActiveModel prepends field names in +#full_messages+, and so the
        # expected result of calling errors[field_name] will not include the
        # field name in the message. However, DM expects the field name to be
        # included in the original message. Assuming that the field name will
        # begin the message, just strip it out (plus the following space) for
        # testing purposes. This has no effect on #full_messages.
        def [](property_name)
          if property_errors = errors[property_name.to_sym]
            property_errors.collect do |message|
              message[(property_name.to_s.length + 1)..-1]
            end
          end
        end
      end
    end
  end
end
Something went wrong with that request. Please try again.