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

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

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

      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.

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

              Created:
              Updated:
              Resolved: