@@ -13,7 +13,7 @@ beforeEach(function() {
13
13
describe ( 'Scope' , function ( ) {
14
14
describe ( '#page()' , function ( ) {
15
15
it ( 'sets correct pagination information' , function ( ) {
16
- scope . page ( 2 ) ;
16
+ scope = scope . page ( 2 ) ;
17
17
expect ( scope . _pagination ) . to . eql ( { number : 2 } ) ;
18
18
} ) ;
19
19
@@ -24,7 +24,7 @@ describe('Scope', function() {
24
24
25
25
describe ( '#per()' , function ( ) {
26
26
it ( 'sets correct pagination information' , function ( ) {
27
- scope . per ( 10 ) ;
27
+ scope = scope . per ( 10 ) ;
28
28
expect ( scope . _pagination ) . to . eql ( { size : 10 } ) ;
29
29
} ) ;
30
30
@@ -35,9 +35,9 @@ describe('Scope', function() {
35
35
36
36
describe ( '#where()' , function ( ) {
37
37
it ( 'updates filter criteria' , function ( ) {
38
- scope . where ( { foo : 'bar' } )
39
- scope . where ( { bar : 'baz' } )
40
- scope . where ( { foo : 'bar2' } )
38
+ scope = scope . where ( { foo : 'bar' } )
39
+ . where ( { bar : 'baz' } )
40
+ . where ( { foo : 'bar2' } )
41
41
expect ( scope . _filter ) . to . eql ( {
42
42
foo : 'bar2' ,
43
43
bar : 'baz'
@@ -51,8 +51,8 @@ describe('Scope', function() {
51
51
52
52
describe ( '#stats()' , function ( ) {
53
53
it ( 'updates stats request' , function ( ) {
54
- scope . stats ( { total : 'count' } ) ;
55
- scope . stats ( { average : 'cost' } ) ;
54
+ scope = scope . stats ( { total : 'count' } )
55
+ . stats ( { average : 'cost' } ) ;
56
56
57
57
expect ( scope . _stats ) . to . eql ( {
58
58
total : 'count' ,
@@ -67,8 +67,8 @@ describe('Scope', function() {
67
67
68
68
describe ( '#order()' , function ( ) {
69
69
it ( 'updates sort criteria' , function ( ) {
70
- scope . order ( 'foo' ) ;
71
- scope . order ( { bar : 'desc' } ) ;
70
+ scope = scope . order ( 'foo' )
71
+ . order ( { bar : 'desc' } ) ;
72
72
expect ( scope . _sort ) . to . eql ( {
73
73
foo : 'asc' ,
74
74
bar : 'desc'
@@ -82,8 +82,8 @@ describe('Scope', function() {
82
82
83
83
describe ( '#select()' , function ( ) {
84
84
it ( 'updates fields criteria' , function ( ) {
85
- scope . select ( { people : [ 'foo' , 'bar' ] } ) ;
86
- scope . select ( { things : [ 'baz' ] } )
85
+ scope = scope . select ( { people : [ 'foo' , 'bar' ] } )
86
+ . select ( { things : [ 'baz' ] } )
87
87
expect ( scope . _fields ) . to . eql ( {
88
88
people : [ 'foo' , 'bar' ] ,
89
89
things : [ 'baz' ]
@@ -98,7 +98,7 @@ describe('Scope', function() {
98
98
describe ( '#includes()' , function ( ) {
99
99
describe ( 'when passed a string' , function ( ) {
100
100
it ( 'updates include criteria' , function ( ) {
101
- scope . includes ( 'foo' )
101
+ scope = scope . includes ( 'foo' )
102
102
expect ( scope . _include ) . to . eql ( {
103
103
foo : { }
104
104
} ) ;
@@ -107,7 +107,7 @@ describe('Scope', function() {
107
107
108
108
describe ( 'when passed an array' , function ( ) {
109
109
it ( 'updates include criteria' , function ( ) {
110
- scope . includes ( [ 'foo' , 'bar' ] ) ;
110
+ scope = scope . includes ( [ 'foo' , 'bar' ] ) ;
111
111
expect ( scope . _include ) . to . eql ( {
112
112
foo : { } ,
113
113
bar : { }
@@ -117,7 +117,7 @@ describe('Scope', function() {
117
117
118
118
describe ( 'when passed a nested object' , function ( ) {
119
119
it ( 'updates include criteria' , function ( ) {
120
- scope . includes ( { a : [ 'b' , { c : 'd' } ] } ) ;
120
+ scope = scope . includes ( { a : [ 'b' , { c : 'd' } ] } ) ;
121
121
expect ( scope . _include ) . to . eql ( {
122
122
a : {
123
123
b : { } ,
@@ -142,7 +142,7 @@ describe('Scope', function() {
142
142
143
143
describe ( '#asQueryParams()' , function ( ) {
144
144
it ( 'transforms all scoping criteria into a jsonapi-compatible query param object' , function ( ) {
145
- scope
145
+ scope = scope
146
146
. page ( 2 )
147
147
. per ( 10 )
148
148
. where ( { foo : 'bar' } )
@@ -183,7 +183,7 @@ describe('Scope', function() {
183
183
184
184
describe ( '#toQueryParams' , function ( ) {
185
185
it ( 'transforms nested query parameter object to query string' , function ( ) {
186
- scope
186
+ scope = scope
187
187
. page ( 2 )
188
188
. per ( 10 )
189
189
. where ( { foo : 'bar' } )
@@ -196,7 +196,7 @@ describe('Scope', function() {
196
196
} ) ;
197
197
198
198
it ( 'does not include empty objects' , function ( ) {
199
- scope . page ( 2 ) ;
199
+ scope = scope . page ( 2 ) ;
200
200
expect ( scope . toQueryParams ( ) . match ( / f i e l d / ) === null ) . to . eq ( true ) ;
201
201
} ) ;
202
202
@@ -206,4 +206,22 @@ describe('Scope', function() {
206
206
} )
207
207
} ) ;
208
208
} ) ;
209
+
210
+ describe ( '#copy' , function ( ) {
211
+ it ( 'should make a copy of the scope' , function ( ) {
212
+ expect ( scope . copy ( ) ) . not . to . eq ( scope )
213
+ } )
214
+
215
+ it ( 'should make a copy of scope attributes' , function ( ) {
216
+ let original = scope . order ( { foo : 'asc' } ) . page ( 1 ) . per ( 20 )
217
+
218
+ let copy = original . copy ( )
219
+
220
+ expect ( original . _pagination ) . not . to . eq ( copy . _pagination )
221
+ expect ( original . _pagination ) . to . deep . eq ( copy . _pagination )
222
+
223
+ expect ( original . _sort ) . not . to . eq ( copy . _sort )
224
+ expect ( original . _sort ) . to . deep . eq ( copy . _sort )
225
+ } )
226
+ } )
209
227
} ) ;
0 commit comments