Skip to content

Commit

Permalink
some additional cleanup and documenting.
Browse files Browse the repository at this point in the history
  • Loading branch information
mgan59 committed Apr 4, 2014
1 parent ecdd38b commit ded7c93
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 50 deletions.
17 changes: 2 additions & 15 deletions lib/BaseFixtureLoader.js
Expand Up @@ -26,22 +26,9 @@ colors.setTheme({
module.exports = function(fixtureConfig, mongoose, conn, rootCallback){
//console.log('fired ', fixtureConfig);
//unpack fixtureConfig
var fixtureItem = fixtureConfig.itemName;
var fixtureSchemaKey = fixtureConfig.schema;
var fixtureDataKey = fixtureConfig.data;

// need to pass our mongoose-db conn to the schema include so that it exports, will throw
// an error if you dont have mongoose available
var fixtureSchema = null;
var schemaKey = capitalizeFirstLetter(fixtureSchemaKey);
// may need to check conn for schema instead of mongoose
if(_.has(mongoose.modelSchemas, schemaKey)){
fixtureSchema = mongoose.modelSchemas[schemaKey];
} else {
// If schema not present in mongoose.models then open schema file and load it
fixtureSchema = require(fixtureConfig.schemaPath+fixtureSchemaKey)(mongoose, conn);
}

// data-fixtures now accept a callback that must be returned
// this callback allows one to add internal/additional async branches
// within a fixture, specifically to load embeddable documents
Expand Down Expand Up @@ -79,8 +66,8 @@ module.exports = function(fixtureConfig, mongoose, conn, rootCallback){
// given collection
// and by collection that will be determind by the correspoding model/schema

// Create a mongoose model using the fixureItem key and the fixtureSchema fetched earlier
var fixtureModel = conn.models[fixtureItem];
// Fetch our registered Schema as a mode from mongoose
var fixtureModel = conn.models[fixtureSchemaKey];

/*
* Insert - using the `create` method on the static-model class create new documents
Expand Down
16 changes: 8 additions & 8 deletions lib/BoilerPlates/config.js
Expand Up @@ -24,27 +24,27 @@ var fixtureConfig = FixtureConfig({
dataFixturePath:__dirname+'/fixtures/'
}
});


// Create a Listing of fixtures
var allFixtures = [
// just an example of a fixture listing
/*
{
// general name used in output log
itemName:'Product',
// name of the schema file (without the .js)
schema:'ProductSchema',
// Should be the model name you retrieve from mongoose for
// a bound schema
schema:'Product',
// name of the data-fixture file (without the .js)
data:'ProductData',
// collection name in for removal process
// collections in mongodb are lowercase (note mongoose will plurailize your schema)
// So 'Product' becomes 'products'
collection:'products'
},
*/
];

// load fixture listings
fixtureConfig.fixtureListings.set('all', allFixtures);
fixtureConfig.fixtureListings.set('all', allFixtures);

// export the config
module.exports = fixtureConfig;
Expand Down
18 changes: 9 additions & 9 deletions lib/FixtureConfig.js
Expand Up @@ -5,9 +5,9 @@
*/
module.exports = function(params){
var that = {};

that.mongoConnection = params.mongoConnection;

/*
* When setting path check if base path is set, if not then assume paths set for schema/data-fixture is abs
* Returns a diction of
Expand All @@ -31,31 +31,31 @@ module.exports = function(params){

return local;
}(params.paths);
/*

/*
* in charge of binding the fixtureListings into the config object based on the idicated key reference
*/
that.fixtureListings = function(){
var local={};
// going to store fixtures in this local key-obj store
// going to store fixtures in this local key-obj store
local._fixtures = {};

local.set = function(key, fixtures){

// check if the fixture has paths set, if not use default paths
local._fixtures[key] = [];
var fixture = {};
for (var i in fixtures){
fixture = fixtures[i];

// going to set our global paths if none are defined for the fixture
if(fixture.schemaPath === undefined || fixture.schemaPath === ''){
fixture.schemaPath = that.paths.schemaPath;
}
if(fixture.dataFixturePath === undefined || fixture.dataFixturePath === ''){
fixture.dataFixturePath = that.paths.dataFixturePath;
}

// add fixture
local._fixtures[key].push(fixture);
}
Expand All @@ -64,7 +64,7 @@ module.exports = function(params){
local.get = function(key){
return local._fixtures[key];
};

return local;
}();

Expand Down
24 changes: 6 additions & 18 deletions test/mongoose-fixture-config-mock.js
Expand Up @@ -48,19 +48,15 @@ var allFixtures = [
// just an example of a fixture listing
{
// general name used in output log
itemName:'Product',
schema:'Product',
// name of the schema file (without the .js)
schema:'ProductSchemaMock',
// name of the data-fixture file (without the .js)
data:'ProductsMock',
// collection name in for removal process
collection:'products'
},
{
// general name used in output log
itemName:'Product',
// name of the schema file (without the .js)
schema:'ProductSchemaMock',
schema:'Product',
// name of the data-fixture file (without the .js)
data:'ProductsObjectLiteralMock',
// collection name in for removal process
Expand All @@ -73,9 +69,7 @@ var bigFixtures = [
// just an example of a fixture listing
{
// general name used in output log
itemName:'Product',
// name of the schema file (without the .js)
schema:'ProductSchemaMock',
schema:'Product',
// name of the data-fixture file (without the .js)
data:'ProductsBigMock',
// collection name in for removal process
Expand All @@ -88,9 +82,7 @@ var objLitFixtures = [
// just an example of a fixture listing
{
// general name used in output log
itemName:'Product',
// name of the schema file (without the .js)
schema:'ProductSchemaMock',
schema:'Product',
// name of the data-fixture file (without the .js)
data:'ProductsObjectLiteralMock',
// collection name in for removal process
Expand All @@ -103,9 +95,7 @@ var brokenRemoveFixtures = [
// just an example of a fixture listing
{
// general name used in output log
itemName:'Product',
// name of the schema file (without the .js)
schema:'ProductSchemaMock',
schema:'Product',
// name of the data-fixture file (without the .js)
data:'ProductsMock',
// collection name in for removal process
Expand All @@ -117,9 +107,7 @@ var updateFixtures = [
// just an example of a fixture listing
{
// general name used in output log
itemName:'Product',
// name of the schema file (without the .js)
schema:'ProductSchemaMock',
schema:'Product',
// name of the data-fixture file (without the .js)
data:'ProductsUpdateMock',
// collection name in for removal process
Expand Down

0 comments on commit ded7c93

Please sign in to comment.