sequelize-fixtures
Advanced tools
Comparing version 0.4.8 to 0.4.9
@@ -97,2 +97,8 @@ var Promise = require('bluebird'); | ||
many2many = {}; | ||
// Allows an external caller to modify the data | ||
// before it is evaluated | ||
if (this.options.modifyFixtureDataFn) { | ||
data = this.options.modifyFixtureDataFn(data, Model); | ||
} | ||
@@ -99,0 +105,0 @@ // Allows an external caller to do some transforms to the data |
{ | ||
"name": "sequelize-fixtures", | ||
"version": "0.4.8", | ||
"version": "0.4.9", | ||
"description": "sequelize fixture loader", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -68,2 +68,14 @@ [![Build Status](https://travis-ci.org/domasx2/sequelize-fixtures.svg?branch=master)](https://travis-ci.org/domasx2/sequelize-fixtures) | ||
//modify each model being loaded | ||
sequelize_fixtures.loadFile('fixtures/*.json', models, { | ||
modifyFixtureDataFn: function (data) { | ||
if(!data.createdAt) { | ||
data.createdAt = new Date(); | ||
} | ||
return data; | ||
} | ||
}).then(function() { | ||
doStuffAfterLoad(); | ||
}); | ||
//from array | ||
@@ -70,0 +82,0 @@ var fixtures = [ |
@@ -513,2 +513,38 @@ var sf = require('../index'), | ||
}); | ||
it('should load fixtures and then transform their values', function() { | ||
return sf.loadFile('tests/fixtures/fixture1.json', models, { | ||
transformFixtureDataFn: function (data, model) { | ||
if (model.name === 'bar') { | ||
data.propB = 99; | ||
} | ||
return data; | ||
} | ||
}).then(function() { | ||
return models.Bar.findAll(); | ||
}).then(function(bars){ | ||
bars.forEach(function(bar) { | ||
bar.propB.should.equal(99); | ||
}); | ||
}); | ||
}); | ||
it('should load user modified fixtures', function() { | ||
return sf.loadFile('tests/fixtures/fixture1.json', models, { | ||
modifyFixtureDataFn: function (data, model) { | ||
if (model.name === 'foo') { | ||
delete data.propB; | ||
data.status = true; | ||
} | ||
return data; | ||
} | ||
}).then(function() { | ||
return models.Foo.findAll(); | ||
}).then(function(foos){ | ||
foos.forEach(function(foo) { | ||
(foo.propB === null).should.equal(true); | ||
foo.status.should.equal(true); | ||
}); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
44935
922
366