Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-4083

Don't throw exception on empty localized fields when calling valid?

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 5.0.2
    • Affects Version/s: None
    • Component/s: None
    • None

      I have came across an issue when trying to persists localized documents:

      I have a model with:

      field :name, type: String, localize: true
      validates_uniqueness_of :name

      And when I run Model.new.valid?

      I get:

      Unable to find source-code formatter for language: nomethoderror. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      : undefined method `inject' for nil:NilClass` in `lib/mongoid/validatable/uniqueness.rb:126:in `criterion'

      `

      I have wrote a small test for it and changed the behaviour of the method so that valid? would return false in this case. Feel free to merge if it's any useful.
      Thanks for the library.
      cheers

            Assignee:
            Unassigned Unassigned
            Reporter:
            cammellos andrea maria piana
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: