test and implementation for empty collections

This commit is contained in:
Hunter Loftis 2014-05-05 14:27:31 -07:00
parent f700016023
commit ffdb548c9d
14 changed files with 44 additions and 2 deletions

View file

@ -40,6 +40,14 @@ function plugin(opts){
});
});
/**
* Ensure that a default empty collection exists.
*/
keys.forEach(function(key) {
metadata[key] = metadata[key] || [];
});
/**
* Sort the collections.
*/
@ -139,4 +147,4 @@ function matcher(cols){
}
return unique(matches);
};
}
}

View file

@ -1 +1,2 @@
one

View file

@ -1 +1,2 @@
two

2
test/fixtures/empty/build/one.md vendored Normal file
View file

@ -0,0 +1,2 @@
one

5
test/fixtures/empty/src/one.md vendored Normal file
View file

@ -0,0 +1,5 @@
---
title: No collection here
---
one

View file

@ -1 +1,2 @@
one

View file

@ -1 +1,2 @@
two

View file

@ -1 +1,2 @@
one

View file

@ -1 +1,2 @@
three

View file

@ -1 +1,2 @@
two

View file

@ -1 +1,2 @@
one

View file

@ -1 +1,2 @@
three

View file

@ -1 +1,2 @@
two

View file

@ -128,4 +128,21 @@ describe('metalsmith-collections', function(){
done();
});
});
});
it('should not fail with empty collections', function(done) {
var metalsmith = Metalsmith('test/fixtures/empty');
metalsmith
.use(collections({
articles: {
sortBy: 'date',
reverse: true
}
}))
.build(function(err) {
if (err) return done(err);
var articles = metalsmith.metadata().articles;
assert.equal(articles.length, 0);
done();
});
});
});