Skip to content

Commit

Permalink
Merge branch 'release-3.0.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Aug 12, 2016
2 parents 7a0b7aa + 31b1cf3 commit b7f2927
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
<a name="3.0.3"></a>
## [3.0.3](https://github.com/adonisjs/adonis-lucid/compare/v3.0.2...v3.0.3) (2016-08-12)


### Bug Fixes

* **lucid:** consider dirty values after beforeHooks ([b22d904](https://github.com/adonisjs/adonis-lucid/commit/b22d904)), closes [#44](https://github.com/adonisjs/adonis-lucid/issues/44)



<a name="3.0.2"></a>
## [3.0.2](https://github.com/adonisjs/adonis-lucid/compare/v3.0.0...v3.0.2) (2016-07-28)

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"directories": {
"test": "test"
},
"version": "3.0.2",
"version": "3.0.3",
"scripts": {
"test": "npm run lint && node --harmony_proxies ./node_modules/.bin/istanbul cover _mocha --report lcovonly -- -R spec test/unit test/acceptance && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage",
"lint": "standard src/**/*.js src/**/**/*.js src/**/**/**/*.js lib/*.js test/**/*.js providers/*.js",
Expand All @@ -16,7 +16,7 @@
"author": "adonisjs",
"license": "MIT",
"devDependencies": {
"adonis-ace": "git+https://github.com/adonisjs/ace.git#develop",
"adonis-ace": "^3.0.1",
"adonis-fold": "^3.0.2",
"bluebird": "^3.3.1",
"chai": "^3.5.0",
Expand Down
3 changes: 2 additions & 1 deletion src/Lucid/Model/Mixins/Persistance.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,14 @@ Peristance.insert = function * () {
*
* @public
*/
Peristance.update = function * (dirtyValues) {
Peristance.update = function * () {
/**
* update handler is sent to hooks execution method
* and will be called there itself.
*/
const updateHandler = function * () {
const query = this.constructor.query()
const dirtyValues = this.$dirty
if (!_.size(dirtyValues)) {
return 0
}
Expand Down
2 changes: 1 addition & 1 deletion src/Lucid/Model/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ class Model {
if (this.isNew()) {
return yield this.insert()
}
return yield this.update(this.$dirty)
return yield this.update()
}

/**
Expand Down
14 changes: 14 additions & 0 deletions test/unit/lucid.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1575,5 +1575,19 @@ describe('Lucid', function () {
User.query().active()
expect(new Ref() instanceof User).to.equal(true)
})

it('should consider attributes chaned inside before update as dirty values when updating', function * () {
class User extends Model {}
User.bootIfNotBooted()
User.addHook('beforeUpdate', function * (next) {
this.lastname = 'foo'
yield next
})
const user = yield User.find(3)
expect(user instanceof User).to.equal(true)
yield user.save()
const reFetchUser = yield User.find(3)
expect(reFetchUser.lastname).to.equal('foo')
})
})
})

0 comments on commit b7f2927

Please sign in to comment.