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

Validation on non-fields raises undefined method `*_before_type_cast'

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Resolution: Done
    • Affects Version/s: None
    • Fix Version/s: 3.1.0
    • Component/s: None
    • Labels:

      Description

      on HEAD

      require 'spec_helper'
       
      class Princess
        include Mongoid::Document
        field :primary_color
       
        def color
          primary_color.to_s
        end
       
        validates_presence_of :color
      end
       
       
      describe "Mongoid" do
       
        it "issue" do
          Princess.create! # raises NoMethodError:  undefined method `color_before_type_cast' for #<Princess _id: 511a4e853b5552f1dd00001b, primary_color: nil>
        end
       
      end
      

      Looks like Mongoid overrides ActiveModel validation and expects everything being validated to be a field.

        Attachments

          Activity

            People

            Assignee:
            durran Durran Jordan
            Reporter:
            dblock Daniel Doubrovkine
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: