Skip to content

Commit

Permalink
Impasse reached with tinytest.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpka committed Dec 26, 2012
1 parent 7fc8ed8 commit 64152f1
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 23 deletions.
8 changes: 4 additions & 4 deletions backbone.sync.coffee
Expand Up @@ -23,18 +23,18 @@ Backbone.miniMongoSync = (method, model, options, error) ->
# changed: (doc) ->
# callback()
delete model.attributes.id
coll.update {_id: model.id}, {$set: model.attributes}
callback()
coll.update model.id, {$set: model.attributes}, {}, callback
when "read"
if model.attributes
ret = coll.findOne(model.attributes)
ret = coll.findOne(model.attributes.id)
else
ret = coll.find().fetch()

error = null#if ret? not instanceof Array or ret.length > 0 then null else "Record not found"
callback error, ret
when "delete"
coll.remove {id: model.id}, callback
coll.remove model.id
callback()

catch error
options.error error
Expand Down
68 changes: 59 additions & 9 deletions backbone.sync.tests.coffee
Expand Up @@ -49,6 +49,11 @@ Book = Backbone.Model.extend
idAttribute: "id"
mCollection: mLibrary

mLibrary2 = new Meteor.Collection("library2")

Book2 = Backbone.Model.extend
mCollection: mLibrary2

setup = ->
mLibrary.remove {}

Expand Down Expand Up @@ -91,16 +96,15 @@ addAsyncTest "Backbone.miniMongoSync - invalid model fails to save", (test, done
done()

if Meteor.is_client
addAsyncTest "Backbone.miniMongoSync - save returns a promise", (test, done) ->
book = new Book()
book.save(attrs)
.done ->
test.ok(true)
done()
addAsyncTest "Backbone.miniMongoSync - create failure", (test, done) ->
book = new Book2(attrs)

book.save({_id: "1"})
.fail ->
test.ok(true)
book.save null,
success: ->
test.fail()
done()
error: (model, error) ->
test.notEqual error, undefined
done()

addAsyncTest "Backbone.miniMongoSync - update", (test, done) ->
Expand All @@ -118,6 +122,52 @@ addAsyncTest "Backbone.miniMongoSync - update", (test, done) ->
test.fail()
done()

if Meteor.is_client
addAsyncTest "Backbone.miniMongoSync - update failure", (test, done) ->
book = new Book2(attrs)
id = mLibrary2.insert attrs
book.set "id", id

debugger
book.save
success: ->
test.fail()
done()
error: (model, error) ->
test.notEqual error, undefined
done()

addAsyncTest "Backbone.miniMongoSync - fetch", (test, done) ->
book = new Book()
id = mLibrary.insert attrs
book.set "id", id
book.fetch
success: ->
test.equal book.get("title"), mLibrary.findOne().title
done()
error: ->
test.fail()
done()

addAsyncTest "Backbone.miniMongoSync - delete", (test, done) ->
book = new Book(attrs)
id = mLibrary.insert attrs
book.set "id", id
book.destroy
success: ->
test.equal mLibrary.findOne(), undefined
done()
error: ->
test.fail()
done()

# if Meteor.is_client
# addTest "Backbone.miniMongoSync - save, fetch and destroy returns promises", (test, done) ->
# book = new Book()
# test.equal typeof book.save().done, "function"
# test.equal typeof book.fetch().done, "function"
# test.equal typeof book.destroy().done, "function"

# addAsyncTest "Backbone.miniMongoSync - fetch", (test, done) ->
# mLibrary.insert attrs
# library = new Library()
Expand Down
7 changes: 1 addition & 6 deletions grunt.js
Expand Up @@ -6,12 +6,7 @@ module.exports = function(grunt) {
coffee: {
src: {
files: {
"build/backbone.sync.js": "backbone.sync.coffee"
}
},
tests: {
files: {
"build/backbone.sync.tests.js": "backbone.sync.tests.coffee"
"build/*.js": "*.coffee"
}
}
},
Expand Down
5 changes: 1 addition & 4 deletions smart.json
Expand Up @@ -4,8 +4,5 @@
"homepage": "https://github.com/jpka/meteor-backbone-sync",
"author": "Juan Pablo Kaniefsky",
"version": "0.0.1",
"git": "https://github.com/jpka/meteor-backbone-sync.git",
"meteor": {
"branch": "v0.5.2"
}
"git": "https://github.com/jpka/meteor-backbone-sync.git"
}

0 comments on commit 64152f1

Please sign in to comment.