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

type: Boolean is not enforced

    • Type: Icon: Task Task
    • Resolution: Done
    • 12_01_17
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      I'm using Rails 4.0beta1, mongoid from git and Ruby 2.0.

      I have this in my User model:

       field :admin, type: Boolean, default: false
      

      Problem is checkboxes return a string "0" which is type cast to an integer 0. When an integer 0 is stored for the field, it is treated as true:

      [1] pry(main)> user = User.first
      [2] pry(main)> user.admin = 123
      => 123
      [5] pry(main)> user.admin = 0
      => 0
      [6] pry(main)> user.admin?
      => true
      

      Shouldn't Mongoid enforce booleans and not just let you store any integer you want?

            Assignee:
            Unassigned Unassigned
            Reporter:
            hackeron Roman Gaufman
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: