Created
August 19, 2014 13:27
-
-
Save hdemon/cee3606733404f992e6d to your computer and use it in GitHub Desktop.
This file contains 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
sinon = require('sinon') | |
chai = require('chai').use(require 'sinon-chai') | |
expect = chai.expect | |
PO = require '../../lib/part_one_movie.coffee' | |
knex = require('knex')(require '../../config/database_test') | |
describe "PartOneMovie", -> | |
describe "save", -> | |
context "when no error has caused during transaction", -> | |
beforeEach (done) -> | |
knex('part_one_movies').delete() | |
.then -> | |
knex.transaction (transacting) -> | |
array = [{video_id: "sm1", published_at: new Date}] | |
PO.save(array, transacting) | |
.then -> | |
done() | |
it "should save data into db", -> | |
knex.select().table('part_one_movies') | |
.then (collection) -> | |
expect(collection.length).to.eql 1 | |
context "when some error have caused during transaction", -> | |
beforeEach (done) -> | |
knex('part_one_movies').delete() | |
.then -> | |
knex.transaction (transacting) -> | |
array = [{video_id: "sm1", published_at: new Date}] | |
throw new Error | |
PO.save(array, transacting) | |
.then -> | |
done() | |
.catch -> | |
done() | |
it "should save no data into db", -> | |
knex.select().table('part_one_movies') | |
.then (collection) -> | |
expect(collection.length).to.eql 0 | |
afterEach (done) -> | |
knex('part_one_movies').delete().then -> done() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment