Created
          April 19, 2013 22:17 
        
      - 
      
- 
        Save thatmarvin/5423601 to your computer and use it in GitHub Desktop. 
    Setter isn't invoked when value === null
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | var mongoose = require('mongoose'); | |
| var Schema = mongoose.Schema; | |
| var assert = require('assert'); | |
| mongoose.connect('mongodb://localhost/test'); | |
| var OrderSchema = new Schema({ | |
| total: { | |
| type: Number, | |
| default: 0, | |
| set: function (value) { | |
| return (value || 0) + 10; | |
| } | |
| } | |
| }); | |
| var Order = mongoose.model('offer', OrderSchema); | |
| var TEST_VALUE = null; // Works fine when value !== null | |
| var order = new Order({ | |
| total: TEST_VALUE | |
| }); | |
| order.save(function (err, order) { | |
| if (err) { | |
| return console.error(err.message); | |
| process.exit(1); | |
| } | |
| assert.equal(order.total, TEST_VALUE + 10, 'Setter is run'); | |
| process.exit(0); | |
| }); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment