Permalink
Browse files

moved definition of extenisions outside of beforeEach

  • Loading branch information...
1 parent 243a934 commit b07d03128a0dc6bf45f51046cdea9a919b533367 @bn1 committed May 8, 2012
Showing with 41 additions and 41 deletions.
  1. +41 −41 test/queryset.coffee
View
@@ -24,62 +24,62 @@ describe "Queryset", ->
Product = undefined
- beforeEach ->
- Spine.Model.extend
- delete: (options={}) ->
- unless @is_queryset
- @destroyAll options
- @deleteAll()
+ Spine.Model.extend
+ delete: (options={}) ->
+ unless @is_queryset
+ @destroyAll options
+ @deleteAll()
- else
- for item in @
- item.destroy()
- delete @records[item.id]
- delete @crecords[item.cid]
+ else
+ for item in @
+ item.destroy()
+ delete @records[item.id]
+ delete @crecords[item.cid]
- __filter: (args, revert=false) ->
- (rec) ->
- f = !!revert
+ __filter: (args, revert=false) ->
+ (rec) ->
+ f = !!revert
- for key, value of args
- return f unless rec[key] is value
+ for key, value of args
+ return f unless rec[key] is value
- return !f
+ return !f
- filter: (args) -> @select @__filter args, false
- exclude: (args) -> @select @__filter args, true
+ filter: (args) -> @select @__filter args, false
+ exclude: (args) -> @select @__filter args, true
- order_by: (keys...) ->
- if keys.length > 1
- ref = @
- for key in keys.reverse()
- ref = ref.order_by(key)
+ order_by: (keys...) ->
+ if keys.length > 1
+ ref = @
+ for key in keys.reverse()
+ ref = ref.order_by(key)
- ref
+ ref
- else
- @all().sort((x, y) ->
- key = keys[0]
- result = 1
- rev = false
+ else
+ @all().sort((x, y) ->
+ key = keys[0]
+ result = 1
+ rev = false
- if key[0] is '-'
- key = key[1..]
- rev = true
+ if key[0] is '-'
+ key = key[1..]
+ rev = true
- result *= -1 if x[key] < y[key]
- result = 1 if x[key] is null
- result = -1 if y[key] is null
- result = 0 if x[key] is y[key]
+ result *= -1 if x[key] < y[key]
+ result = 1 if x[key] is null
+ result = -1 if y[key] is null
+ result = 0 if x[key] is y[key]
- result *= -1 if rev
+ result *= -1 if rev
- return result
- )
+ return result
+ )
+ beforeEach ->
Product = Spine.Model.setup('Product', ["name", "price"])
Product.refresh([
{name: 'product1', price: 5}
@@ -92,7 +92,7 @@ describe "Queryset", ->
it 'should recognize queryset', ->
Product.is_queryset.should.equal false
Product.all().is_queryset.should.equal true
-
+
it 'should filter results', ->
Product.filter(price: 3).length.should.equal 2
Product.filter(price: 1).length.should.equal 1

0 comments on commit b07d031

Please sign in to comment.