Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Support database option in DB.add

  • Loading branch information...
commit e868735331a94964494a5ea4a97e561391885a14 1 parent c344f6e
Wesley Moore authored April 04, 2011
13  src/db.coffee
@@ -124,17 +124,18 @@ class DB
124 124
   # Add a record if it doesn't already exist
125 125
   add: (key, value, args...) ->
126 126
     switch args.length
127  
-      when 1 then callback = args[0]
  127
+      when 1
  128
+        options  = {}
  129
+        callback = args[0]
128 130
       when 2
129  
-        database = args[0]
  131
+        options  = args[0]
130 132
         callback = args[1]
131 133
       else
132 134
         throw new Error("Invalid number of arguments (#{args.length}) to add");
133 135
 
134  
-    rpc_args =
135  
-      key: key
136  
-      value: value
137  
-    rpc_args.DB = database if database?
  136
+    rpc_args       = this._initRpcArgs options
  137
+    rpc_args.key   = key
  138
+    rpc_args.value = value
138 139
     @rpcClient.call 'add', rpc_args, (error, status, output) ->
139 140
       if error?
140 141
         callback error, output
15  test/db_test.coffee
@@ -7,8 +7,11 @@ db = new kt.Db testDb
7 7
 db.open('localhost', 1979)
8 8
 
9 9
 dbClear = (callback) ->
  10
+  # Clear default db (tests that behaviour)
10 11
   db.clear (error, output) ->
11  
-    callback()
  12
+    # Clear alternate db (tests specifying the db)
  13
+    db.clear {database: 'test2.kct'}, (error, output) ->
  14
+      callback()
12 15
 
13 16
 module.exports =
14 17
   defaultDatabase: testCase
@@ -120,6 +123,16 @@ module.exports =
120 123
           test.equal error.message, "Record exists"
121 124
           test.done()
122 125
 
  126
+    'allows the database to be specified': (test) ->
  127
+      test.expect 2
  128
+      db.add 'test', 'other db', {database: 'test2.kct'}, (error, output) ->
  129
+        test.ifError error
  130
+
  131
+        # Check that the value wasn't set on the default db
  132
+        db.get 'test', (error, value) ->
  133
+          test.ok value == null
  134
+          test.done()
  135
+
123 136
   replace: testCase
124 137
     setUp: dbClear
125 138
 

0 notes on commit e868735

Please sign in to comment.
Something went wrong with that request. Please try again.