Permalink
Browse files

Impasse reached with tinytest.

  • Loading branch information...
1 parent 7fc8ed8 commit 64152f1310311df5e200ebd4219d5e00e78f7c4a @jpka committed Dec 26, 2012
Showing with 65 additions and 23 deletions.
  1. +4 −4 backbone.sync.coffee
  2. +59 −9 backbone.sync.tests.coffee
  3. +1 −6 grunt.js
  4. +1 −4 smart.json
View
@@ -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
View
@@ -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 {}
@@ -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) ->
@@ -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()
View
@@ -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"
}
}
},
View
@@ -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.