Skip to content

Instantly share code, notes, and snippets.

@hdemon
Created August 19, 2014 13:27
Show Gist options
  • Save hdemon/cee3606733404f992e6d to your computer and use it in GitHub Desktop.
Save hdemon/cee3606733404f992e6d to your computer and use it in GitHub Desktop.
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