Permalink
Browse files

added dao and dao_test modules

  • Loading branch information...
1 parent cdc3f0d commit d22b128f0fcd19270c120e43ad93a1a0fc7abee6 @yesobo committed Nov 30, 2012
Showing with 93 additions and 47 deletions.
  1. +23 −16 daos/dao.coffee
  2. +30 −21 daos/dao.js
  3. +18 −5 daos/dao_test.coffee
  4. +22 −5 daos/dao_test.js
View
@@ -72,22 +72,29 @@ module.exports = class MongoDBConnector
collection.insert pattern, (err, doc) ->
callback err, doc
- #call: callback parameters are (err, pattern)
+ #call: callback parameters are (err)
update: (pattern, callback) ->
- initTransaction (err, collection) ->
- collection.update id:pattern.id,
- $set:
- name: pattern.name
- category: pattern.category
- intent: pattern.intent
- motivation: pattern.motivation
- applicability: pattern.applicability
- structure: pattern.structure,
- (err) ->
- callback err, pattern
+ initTransaction.call this, (err, collection) ->
+ if err?
+ console.log "ERROR!"
+ callback err, null
+ else
+ collection.update id:pattern.id,
+ $set:
+ name: pattern.name
+ category: pattern.category
+ intent: pattern.intent
+ motivation: pattern.motivation
+ applicability: pattern.applicability
+ structure: pattern.structure,
+ (err) ->
+ callback err
- #call: callback parameters are (err, removed)
+ #call: callback parameters are (err)
delete: (pId, callback) ->
- initTransaction (err, collection) ->
- collection.remove id:pId, (err, removed) ->
- callback err, removed
+ initTransaction.call this, (err, collection) ->
+ if err?
+ console.log "ERROR!"
+ else
+ collection.remove id:pId, (err) ->
+ callback err
View
Oops, something went wrong.
View
@@ -39,8 +39,21 @@ describe 'Tests for MongoDBConnector', ->
daoObj.findById 2, (err, item) ->
item.should.have.property 'name', 'Prototype'
done()
- it.only "insert new pattern (Factory Method) must the pattern", (done) ->
- daoObj.insert new_pattern, (err, item) ->
- doc = item[0]
- doc.should.have.property 'name', 'Factory Method'
- done()
+ it "insert new_pattern (Factory Method) returns the pattern", (done) ->
+ daoObj.insert new_pattern, (err, docs) ->
+ docs[0].should.have.property 'name', new_pattern.name
+ done()
+
+ it "update new_pattern returns the pattern updated", (done) ->
+ new_name = "Modified Name"
+ new_pattern.name = new_name;
+ daoObj.update new_pattern, (err) ->
+ daoObj.findById new_pattern.id, (err, item) ->
+ item.should.have.property 'name', new_name
+ done()
+
+ it "delete new_pattern returns the removed alement", (done) ->
+ daoObj.delete new_pattern.id, (err) ->
+ daoObj.count (err, count) ->
+ should.strictEqual count, 2
+ done()
View
Oops, something went wrong.

0 comments on commit d22b128

Please sign in to comment.