Skip to content

Commit

Permalink
added another test for orpheus.connect; comment for orpheus.connect
Browse files Browse the repository at this point in the history
  • Loading branch information
Radagaisus committed Apr 25, 2014
1 parent 53612d9 commit 4e2ce6c
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 4 deletions.
5 changes: 5 additions & 0 deletions history.md
@@ -1,5 +1,10 @@
# Changelog

## 0.6.1 (Not released)

- Added a test for `Orpheus.connect()` when the models are passed as an array instead of an object.


## 0.6.0

- The `delete()` command is now chainable. It does not execute immediately and doesn't expect to receive a callback function. Use `.delete().exec()` from now on. This change was made to make the API more consistent.
Expand Down
32 changes: 29 additions & 3 deletions lib/orpheus.coffee
Expand Up @@ -34,9 +34,35 @@ class Orpheus
@unique_id: -> @id_counter++





# Connects lazy commands from several Orpheus models into one big MULTI
# command. This is convenient, for example, for updating denomralized data
# across several models.
#
# Example usage:
#
# Orpheus.connect
#
# user:
# user('some-user')
# .points.set(200)
# .name.set('Snir')
#
# app:
# app('some-app')
# .points.set(1000)
# .name.set('Super App')
#
# , (err, res) ->
# # `res` is {user: [1,1], app: [1,1]}
#
#
# @param models - {Object|Array} An object or an array of Orpheus models.
# the keys in the object are the names we want to assign to the
# response we return from Redis.
# @param callback - {Function} a callback function, with the signature of
# `(error, results)`. The results will be the parsed results from
# redis.
#
@connect: (models, callback) ->
# Holds a small schema, so we'll know how to return the results
schema = {}
Expand Down
35 changes: 34 additions & 1 deletion test/orpheus.spec.coffee
Expand Up @@ -1290,7 +1290,7 @@ describe 'Defaults', ->
# -----------------------------------------------------------------
describe 'Connect', ->

it 'Connects commands from two operations', (done) ->
it 'Connects commands from two operations, using an object', (done) ->

class User extends Orpheus
constructor: ->
Expand Down Expand Up @@ -1327,6 +1327,39 @@ describe 'Connect', ->
done()


it 'Connects commands from two operations, using an array', (done) ->

class User extends Orpheus
constructor: ->
@str 'name'
@num 'points'

class App extends Orpheus
constructor: ->
@str 'name'
@num 'points'

user = User.create()
app = App.create()

Orpheus.connect [
user('some-user')
.points.set(200)
.name.set('Snir')
,
app('some-app')
.points.set(1000)
.name.set('Super App')
], (err, res) ->
expect(err).toBe null
expect(res[0][0]).toEqual 1
expect(res[0][1]).toEqual 1
expect(res[1][0]).toEqual 1
expect(res[1][1]).toEqual 1

done()



# Bugs & Regressions
# ---------------------------------------
Expand Down

0 comments on commit 4e2ce6c

Please sign in to comment.