Skip to content

Commit

Permalink
Merge branch 'release-3.0.14'
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Feb 25, 2017
2 parents 9ecfd59 + d6988f8 commit cb40b80
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 27 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,15 @@
<a name="3.0.14"></a>
## [3.0.14](https://github.com/adonisjs/adonis-lucid/compare/v3.0.13...v3.0.14) (2017-02-25)


### Bug Fixes

* **hooks:** improve defineHooks signature ([ca614e0](https://github.com/adonisjs/adonis-lucid/commit/ca614e0)), closes [#94](https://github.com/adonisjs/adonis-lucid/issues/94)
* **migration:** ignore prefixing inside migrations ([5aebc5b](https://github.com/adonisjs/adonis-lucid/commit/5aebc5b)), closes [#105](https://github.com/adonisjs/adonis-lucid/issues/105)
* **util:** filter .js files before requiring them ([a21d6fc](https://github.com/adonisjs/adonis-lucid/commit/a21d6fc)), closes [#96](https://github.com/adonisjs/adonis-lucid/issues/96)



<a name="3.0.13"></a>
## [3.0.13](https://github.com/adonisjs/adonis-lucid/compare/v3.0.12...v3.0.13) (2017-01-26)

Expand Down
24 changes: 13 additions & 11 deletions lib/util.js
Expand Up @@ -11,7 +11,7 @@

const i = require('inflect')
const _ = require('lodash')
const autoLoader = require('auto-loader')
const requireAll = require('require-all')
const prettyHrtime = require('pretty-hrtime')
const util = exports = module.exports = {}
const isolatedLodash = _.runInContext()
Expand Down Expand Up @@ -283,17 +283,19 @@ util.timeDiff = function (start) {
* @public
*/
util.loadJsFiles = function (fromPath, onlyFiles) {
return _(autoLoader.load(fromPath))
.map(function (file, name) {
if (name.endsWith('.js') && !_.size(onlyFiles)) {
return [name.replace('.js', ''), file]
} else if (name.endsWith('.js') && onlyFiles.indexOf(name) > -1) {
return [name.replace('.js', ''), file]
}
return requireAll({
dirname: fromPath,
filter: function (name) {
if (!name.endsWith('.js')) {
return false
}

if (!_.size(onlyFiles) || onlyFiles.indexOf(name) > -1) {
return name.replace('.js', '')
}
},
recursive: true
})
.compact()
.fromPairs()
.value()
}

/**
Expand Down
22 changes: 11 additions & 11 deletions package.json
Expand Up @@ -5,7 +5,7 @@
"directories": {
"test": "test"
},
"version": "3.0.13",
"version": "3.0.14",
"scripts": {
"lint": "standard",
"test:all": "DB=sqlite3 npm run test && DB=mysql npm run test && DB=pg npm run test",
Expand All @@ -27,18 +27,18 @@
"author": "adonisjs",
"license": "MIT",
"devDependencies": {
"adonis-ace": "^3.0.5",
"adonis-ace": "^3.0.6",
"adonis-fold": "^3.0.3",
"bluebird": "^3.4.7",
"chai": "^3.5.0",
"co-fs-extra": "^1.2.1",
"co-mocha": "^1.1.3",
"coveralls": "^2.11.15",
"cz-conventional-changelog": "^1.2.0",
"co-mocha": "^1.2.0",
"coveralls": "^2.11.16",
"cz-conventional-changelog": "^2.0.0",
"istanbul": "^0.4.5",
"mocha": "^3.2.0",
"mocha-lcov-reporter": "^1.2.0",
"mysql": "^2.12.0",
"mocha-lcov-reporter": "^1.3.0",
"mysql": "^2.13.0",
"pg": "^6.1.2",
"semantic-release": "^6.3.2",
"semver": "^5.3.0",
Expand All @@ -56,20 +56,20 @@
},
"dependencies": {
"adonis-binding-resolver": "^1.0.1",
"auto-loader": "git+https://github.com/thetutlage/node-auto-loader.git",
"cat-log": "^1.0.2",
"chance": "^1.0.4",
"chance": "^1.0.6",
"co": "^4.6.0",
"co-functional": "^0.2.1",
"cz-conventional-changelog": "^1.2.0",
"es6-class-mixin": "^1.0.5",
"harmony-reflect": "^1.5.1",
"inflect": "^0.3.0",
"knex": "^0.12.6",
"knex": "^0.12.7",
"lodash": "^4.17.4",
"moment": "^2.17.1",
"node-exceptions": "^1.0.3",
"pretty-hrtime": "^1.0.3"
"pretty-hrtime": "^1.0.3",
"require-all": "^2.2.0"
},
"repository": {
"type": "git",
Expand Down
6 changes: 2 additions & 4 deletions src/Lucid/Model/index.js
Expand Up @@ -205,11 +205,9 @@ class Model {
*
* @public
*/
static defineHooks () {
static defineHooks (type, hooks) {
this.$modelHooks = {}
const args = _.toArray(arguments)
const type = args[0]
const hooks = _.tail(args)
hooks = _.isArray(hooks) ? hooks : _.tail(arguments)
_.each(hooks, (hook) => {
this.addHook(type, hook)
})
Expand Down
2 changes: 1 addition & 1 deletion src/Migrations/Mixins/Migrate.js
Expand Up @@ -244,7 +244,7 @@ Migrate._mapMigrationsToActions = function (migrationsList, direction) {
* @private
*/
Migrate._getMigratedFiles = function () {
return this.database.select('name as name').from(this.migrationsTable).orderBy('name').pluck('name')
return this.database.select('name as name').withoutPrefix().from(this.migrationsTable).orderBy('name').pluck('name')
}

/**
Expand Down
1 change: 1 addition & 0 deletions test/unit/autoload/readme.md
@@ -0,0 +1 @@
# Hello Dude
12 changes: 12 additions & 0 deletions test/unit/lucid.spec.js
Expand Up @@ -1420,6 +1420,18 @@ describe('Lucid', function () {
expect(User.$modelHooks['beforeCreate'][1].handler).to.have.property('method')
})

it('should be able to define multiple hooks as an array', function () {
class User extends Model {}
User.bootIfNotBooted()
User.defineHooks('beforeCreate', ['Users.validate', 'Users.log'])
expect(User.$modelHooks['beforeCreate']).to.be.an('array')
expect(User.$modelHooks['beforeCreate'].length).to.equal(2)
expect(User.$modelHooks['beforeCreate'][0].handler).to.have.property('instance')
expect(User.$modelHooks['beforeCreate'][0].handler).to.have.property('method')
expect(User.$modelHooks['beforeCreate'][1].handler).to.have.property('instance')
expect(User.$modelHooks['beforeCreate'][1].handler).to.have.property('method')
})

it('should override existing hooks when calling defineHooks', function () {
class User extends Model {}
User.bootIfNotBooted()
Expand Down
20 changes: 20 additions & 0 deletions test/unit/migrations.spec.js
Expand Up @@ -843,4 +843,24 @@ describe('Migrations', function () {
yield runner.database.schema.dropTable('adonis_migrations')
yield runner.database.schema.dropTable('my_users')
})

it('should ignore prefix when selecting migrations table', function * () {
Database._setConfigProvider(config.withPrefix)
const Runner = new Migrations(Database, Config)
const runner = new Runner()
class Users extends Schema {
up () {
this.create('ad_users', (table) => {
table.increments()
})
}
}
const migrations = {'2016-04-21': Users}
yield runner.up(migrations)
yield runner.up(migrations)
const myUsersInfo = yield runner.database.table('users').columnInfo()
expect(myUsersInfo.id).be.an('object')
yield runner.database.schema.dropTable('adonis_migrations')
yield runner.database.schema.dropTable('ad_users')
})
})

0 comments on commit cb40b80

Please sign in to comment.