Last Updated: February 25, 2016
·
3.694K
· felipero

Messages translation for mongoid will help on fabrication/fixture investigation

Sometimes I get some errors on validation by the time I'm fabricating instances on rails specs. The error messages on the console were meaninless and didn't help at all to find the problem.
Something like that:

Failure/Error: Fabricate(:model_x)
    Mongoid::Errors::Validations:

      Problem:
        translation missing: en.mongoid.errors.messages.validations.message
      Summary:
        translation missing: en.mongoid.errors.messages.validations.summary
      Resolution:
        translation missing: en.mongoid.errors.messages.validations.resolution
    # ./spec/models/model_spec.rb:39:in `block (3 levels) in <top (required)>'

Then I whent out and added the fooloowing translations to my config/locales/en.yml

en:
  errors: &errors
    format:  '%{attribute} %{message}'
    messages:
      validations:
        message: There was validation errors on %{document}
        summary: "Errors:\n    %{errors}"
        resolution: Check the instances for this model looking for missing fields or wrong values.  
  activemodel:
    errors:
      <<: *errors
  mongoid:
    errors:
      <<: *errors

And now the messages tell me the model and the specific errors on validation.