Skip to content

Commit

Permalink
Merge branch 'marines-db-table-seeding-fix' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Oct 11, 2016
2 parents 26ea4bd + 6002192 commit b25b56f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Factory/DatabaseFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ class DatabaseFactory {
*/
* create (rows, values) {
const self = this
this.binding = this.binding.table(this.dbTable)
const binding = this.binding.table(this.dbTable)
rows = rows || 1
const range = _.range(rows)
const ids = yield cf.mapSerial(function * (iterator) {
return yield self.binding.insert(self._callBlueprint(iterator + 1, values)).returning(self.returningField)
return yield binding.insert(self._callBlueprint(iterator + 1, values)).returning(self.returningField)
}, range)
return _.flatten(ids)
}
Expand All @@ -99,7 +99,7 @@ class DatabaseFactory {
* @public
*/
reset () {
return this.binding.truncate()
return this.binding.table(this.dbTable).truncate()
}
}

Expand Down
14 changes: 14 additions & 0 deletions test/unit/factory.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,20 @@ describe('Factory', function () {
yield modelFixtures.truncate(Database)
})

it('should be able to truncat the database table using the reset method', function * () {
Factory.blueprint('users', function (fake) {
return {
username: fake.username(),
firstname: fake.first()
}
})
yield Factory.get('users').create(10)
yield Factory.get('users').reset()
const ids = yield Database.table('users').pluck('ids')
expect(ids).to.be.an('array')
expect(ids.length).to.equal(0)
})

it('should get the iteration count when making multiple instances', function * () {
class User extends Model {}
Ioc.bind('App/Model/User', function () {
Expand Down

0 comments on commit b25b56f

Please sign in to comment.