Skip to content
This repository
Browse code

add failing test for persisting empty arrays

  • Loading branch information...
commit 3c9c53589b937cfbd99aace0d553c02bd6bf2480 1 parent 3fbd072
Aaron Heckmann aheckmann authored

Showing 1 changed file with 33 additions and 20 deletions. Show diff stats Hide diff stats

  1. +33 20 test/model.test.js
53 test/model.test.js
@@ -2014,44 +2014,57 @@ module.exports = {
2014 2014
2015 2015 // array
2016 2016 var post2 = new BlogPost();
2017   - post2.mixed = [{foo: 'bar'}];
  2017 + post2.mixed = { name: "mr bungle", arr: [] };
2018 2018 post2.save(function (err) {
2019 2019 should.strictEqual(err, null);
2020 2020
2021 2021 BlogPost.findById(post2._id, function (err, doc){
2022 2022 should.strictEqual(err, null);
2023 2023
2024   - Array.isArray(doc.mixed).should.be.true;
2025   - doc.mixed.push({ hello: 'world' });
2026   - doc.commit('mixed');
  2024 + Array.isArray(doc.mixed.arr).should.be.true;
2027 2025
2028   - doc.save(function (err, doc) {
  2026 + doc.mixed = [{foo: 'bar'}];
  2027 + doc.save(function (err) {
2029 2028 should.strictEqual(err, null);
2030 2029
2031   - BlogPost.findById(post2._id, function (err, doc) {
  2030 + BlogPost.findById(doc._id, function (err, doc){
2032 2031 should.strictEqual(err, null);
2033 2032
2034   - doc.mixed[0].should.eql({ foo: 'bar' });
2035   - doc.mixed[1].should.eql({ hello: 'world' });
2036   - --count || db.close();
  2033 + Array.isArray(doc.mixed).should.be.true;
  2034 + doc.mixed.push({ hello: 'world' });
  2035 + doc.commit('mixed');
  2036 +
  2037 + doc.save(function (err, doc) {
  2038 + should.strictEqual(err, null);
  2039 +
  2040 + BlogPost.findById(post2._id, function (err, doc) {
  2041 + should.strictEqual(err, null);
  2042 +
  2043 + doc.mixed[0].should.eql({ foo: 'bar' });
  2044 + doc.mixed[1].should.eql({ hello: 'world' });
  2045 + --count || db.close();
  2046 + });
  2047 + });
2037 2048 });
2038   - });
2039   - });
2040 2049
2041   - // date
2042   - var post3 = new BlogPost();
2043   - post3.mixed = new Date;
2044   - post3.save(function (err) {
2045   - should.strictEqual(err, null);
  2050 + // date
  2051 + var post3 = new BlogPost();
  2052 + post3.mixed = new Date;
  2053 + post3.save(function (err) {
  2054 + should.strictEqual(err, null);
2046 2055
2047   - BlogPost.findById(post3._id, function (err, doc) {
2048   - should.strictEqual(err, null);
  2056 + BlogPost.findById(post3._id, function (err, doc) {
  2057 + should.strictEqual(err, null);
2049 2058
2050   - doc.mixed.should.be.an.instanceof(Date);
2051   - --count || db.close();
  2059 + doc.mixed.should.be.an.instanceof(Date);
  2060 + --count || db.close();
  2061 + });
  2062 + });
2052 2063 });
  2064 +
2053 2065 });
2054 2066 });
  2067 +
2055 2068 },
2056 2069
2057 2070 // GH-200

0 comments on commit 3c9c535

Please sign in to comment.
Something went wrong with that request. Please try again.