Created
October 17, 2016 17:48
-
-
Save gabmontes/4a439e4d94fcc2aab60aeccf91454a29 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const config = { | |
| client: 'pg', | |
| connection: { | |
| host: 'localhost', | |
| port: 5432, | |
| user: 'user', | |
| password: 'pass', | |
| database: 'test' | |
| }, | |
| debug: false | |
| } | |
| const waterfall = require('promise-waterfall') | |
| const expect = require('chai').expect | |
| const knex = require('knex')(config) | |
| const bookshelf = require('bookshelf')(knex) | |
| function createTable(name, columnsBuilder) { | |
| return bookshelf.knex.schema.createTable(name, columnsBuilder) | |
| } | |
| function dropTable(name) { | |
| return bookshelf.knex.schema.dropTableIfExists(name) | |
| } | |
| waterfall([ | |
| function () { | |
| return dropTable('test_entities') | |
| }, | |
| function () { | |
| return createTable('test_entities', function (table) { | |
| table.increments('id').primary() | |
| table.string('prop_1') | |
| table.string('prop_2') | |
| }) | |
| }, | |
| function () { | |
| const Entity = bookshelf.Model.extend({ | |
| tableName: 'test_entities' | |
| }) | |
| return waterfall([ | |
| function () { | |
| return Entity.forge({ prop_1: 'foo', prop_2: 'bar' }).save() | |
| }, | |
| function (entity) { | |
| return Entity.forge({ id: entity.get('id') }).fetch() | |
| }, | |
| function (entity) { | |
| entity.set('prop_1', 'FOO') | |
| entity.unset('prop_2') | |
| return entity.save() | |
| }, | |
| function (entity) { | |
| return Entity.forge({ id: entity.get('id') }).fetch() | |
| }, | |
| function (entity) { | |
| expect(entity.get('prop_1')).to.equals('FOO') | |
| expect(entity.get('prop_2')).to.not.exist // Fails here as prop_2 does exist!! | |
| } | |
| ]) | |
| } | |
| ]).then(function () { | |
| console.log('Done') | |
| process.exit(0) | |
| }).catch(function (err) { | |
| console.log('Err: %s', err) | |
| process.exit(1) | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment