first_or_create doesn't pass validation when used with a block

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Done
    • 3.1.4
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      mongoid-3.1.3, email and password fields in the following examples are required.

      user = User.where(email: 'user1@example.com').first_or_create do |u|
      u.password = '12345678'
      end

      Expected user.persisted? to be true
      Got false

      Raising validation error when using with a bang:

      Mongoid::Errors::Validations:
      Problem:
      Validation of Referrer failed.
      Summary:
      The following errors were found: Password can't be blank
      Resolution:
      Try persisting the document with valid data or remove the validations.

      While the following works as expected:

      r = User.create do |u|
      u.email = 'user1@example.com'
      u.password = '12345678'
      end

      User.where(email: 'user1@example.com').first_or_create(password: '12345678')

              Assignee:
              Unassigned
              Reporter:
              yevgenko
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved: