ember-data-factory-guy 0.9.8 → 0.9.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +37 -33
- data/bower.json +2 -2
- data/package.json +1 -1
- data/tests/active_model_adapter_factory_test.js +16 -14
- data/tests/factory_guy_test_mixin_test.js +297 -240
- data/tests/fixture_adapter_factory_test.js +3 -1
- data/tests/index.html +2 -4
- data/tests/rest_adapter_factory_test.js +16 -14
- data/tests/store_test.js +87 -79
- data/tests/support/models/group.js +1 -1
- data/tests/support/test_helper.js +2 -0
- data/tests/test_setup.js +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e4648a11858529bb5355b440b02b0ca24a7f8bf
|
4
|
+
data.tar.gz: 423900ef7416682118d3c180677af2f8fcf77468
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 611b82bee5d7602ed3d0294fe0d4cc1e66061ab0c98f103de3250a9be83b9e082652505dccd4c6b5bf33ee45f3008b4c9a62bac5f131741f4ab95b9a85c7d970
|
7
|
+
data.tar.gz: 9efc3f1265f49dc5ebec18410d018e67077132be6298b9aaa547acab83fe839c70d961c6771d81e6bab0c97cd3711c65ed6ef01a86d9b477c26290414dd67c21
|
data/README.md
CHANGED
@@ -14,12 +14,10 @@ of ember-data-factory-guy.
|
|
14
14
|
- 0.6.4 -> ember-data-1.0.0-beta.8 and under
|
15
15
|
- 0.7.1.1 -> ember-data-1.0.0-beta.10
|
16
16
|
- 0.8.6 -> ember-data-1.0.0-beta.11
|
17
|
-
- 0.9.
|
17
|
+
- 0.9.8 -> ember-data-1.0.0-beta.12
|
18
|
+
- 0.9.9 -> ember-data-1.0.0-beta.15
|
18
19
|
|
19
|
-
**
|
20
|
-
ember-data-1.0.0-beta.14.1 that make it difficult to use**
|
21
|
-
|
22
|
-
**Support for fixture adapter is back in business as of version 0.9.3**
|
20
|
+
**Support for fixture adapter is working for versions 0.9.3 -> 0.9.8**
|
23
21
|
|
24
22
|
*Version 0.9.0 and up deprecates explicit call to store.makeFixture in your tests, in favor
|
25
23
|
of using the FactoryGuy.make or testHelper.make function from FactoryGuyTestHelperMixin instead.
|
@@ -46,7 +44,7 @@ gem 'ember-data-factory-guy', group: test
|
|
46
44
|
or for particular version:
|
47
45
|
|
48
46
|
```ruby
|
49
|
-
gem 'ember-data-factory-guy', '0.9.
|
47
|
+
gem 'ember-data-factory-guy', '0.9.9', group: test
|
50
48
|
```
|
51
49
|
|
52
50
|
then:
|
@@ -81,7 +79,7 @@ or for particular version:
|
|
81
79
|
"dependencies": {
|
82
80
|
"foo-dependency": "latest",
|
83
81
|
"other-foo-dependency": "latest",
|
84
|
-
"ember-data-factory-guy": "0.9.
|
82
|
+
"ember-data-factory-guy": "0.9.9"
|
85
83
|
}
|
86
84
|
```
|
87
85
|
|
@@ -713,6 +711,8 @@ tests run as shown in the previous section (Using FactoryGuyTestMixin)**
|
|
713
711
|
- succeed - flag to indicate if the request should succeed ( default is true )
|
714
712
|
- this style will eventually be deprecated
|
715
713
|
|
714
|
+
- need to wrap tests using handleCreate with: Ember.run.function() { 'your test' })
|
715
|
+
|
716
716
|
**Note**
|
717
717
|
|
718
718
|
*Any attributes in match will be added to the response json automatically,
|
@@ -816,6 +816,7 @@ chainable methods, or options hash.
|
|
816
816
|
##### handleUpdate
|
817
817
|
- handleUpdate(model)
|
818
818
|
- handleUpdate(modelType, id)
|
819
|
+
- need to wrap tests using handleUpdate with: Ember.run.function() { 'your test' })
|
819
820
|
|
820
821
|
*success case is the default*
|
821
822
|
|
@@ -850,6 +851,7 @@ chainable methods, or options hash.
|
|
850
851
|
|
851
852
|
|
852
853
|
##### handleDelete
|
854
|
+
- need to wrap tests using handleDelete with: Ember.run.function() { 'your test' })
|
853
855
|
|
854
856
|
*success case is the default*
|
855
857
|
|
@@ -900,32 +902,34 @@ module('User View', {
|
|
900
902
|
});
|
901
903
|
|
902
904
|
test("Creates new project", function() {
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
905
|
+
Em.run(function() {
|
906
|
+
andThen(function() {
|
907
|
+
var newProjectName = "Gonzo Project"
|
908
|
+
|
909
|
+
click('.add-div div:contains(New Project)')
|
910
|
+
fillIn('.add-project input', newProjectName)
|
911
|
+
|
912
|
+
// Remember, this is for handling an exact match, if you did not care about
|
913
|
+
// matching attributes, you could just do: viewHelper.handleCreate('project')
|
914
|
+
viewHelper.handleCreate('project', {match:{name: newProjectName, user:user}})
|
915
|
+
|
916
|
+
/**
|
917
|
+
Let's say that clicking this '.add-project .link', triggers action in the view to
|
918
|
+
create project record and looks something like this:
|
919
|
+
|
920
|
+
actions: {
|
921
|
+
addProject: function (user) {
|
922
|
+
var name = this.$('.add-project input').val();
|
923
|
+
var store = this.get('controller.store');
|
924
|
+
store.createRecord('project', {name: name, user: user}).save();
|
925
|
+
}
|
926
|
+
|
927
|
+
*/
|
928
|
+
click('.add-project .link')
|
929
|
+
|
930
|
+
var newProjectDiv = find('.project:contains('+newProjectName+')')
|
931
|
+
equal(newProjectDiv[0] != undefined, true)
|
932
|
+
})
|
929
933
|
})
|
930
934
|
})
|
931
935
|
|
data/bower.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "ember-data-factory-guy",
|
3
|
-
"version": "0.9.
|
3
|
+
"version": "0.9.9",
|
4
4
|
"authors": [
|
5
5
|
"Daniel Sudol <dansudol@yahoo.com>",
|
6
6
|
"Opak Alex <opak.alexandr@gmail.com>"
|
@@ -15,7 +15,7 @@
|
|
15
15
|
],
|
16
16
|
"license": "MIT",
|
17
17
|
"dependencies": {
|
18
|
-
"ember-data": "1.0.0-beta.
|
18
|
+
"ember-data": "1.0.0-beta.15",
|
19
19
|
"jquery-mockjax": "latest"
|
20
20
|
},
|
21
21
|
"ignore": [
|
data/package.json
CHANGED
@@ -14,24 +14,26 @@ module('FactoryGuy with ActiveModelAdapter', {
|
|
14
14
|
|
15
15
|
|
16
16
|
test("#resetModels clears the store of models, and resets the model definition", function() {
|
17
|
-
|
18
|
-
|
17
|
+
Em.run(function() {
|
18
|
+
var project = make('project');
|
19
|
+
var user = make('user', {projects: [project]});
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
for (model in FactoryGuy.modelDefinitions) {
|
22
|
+
var definition = FactoryGuy.modelDefinitions[model];
|
23
|
+
sinon.spy(definition, 'reset');
|
24
|
+
}
|
24
25
|
|
25
|
-
|
26
|
+
FactoryGuy.resetModels(store);
|
26
27
|
|
27
|
-
|
28
|
-
|
28
|
+
equal(store.all('user').get('content.length'),0)
|
29
|
+
equal(store.all('project').get('content.length'),0)
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
31
|
+
for (model in FactoryGuy.modelDefinitions) {
|
32
|
+
var definition = FactoryGuy.modelDefinitions[model];
|
33
|
+
ok(definition.reset.calledOnce);
|
34
|
+
definition.reset.restore();
|
35
|
+
}
|
36
|
+
});
|
35
37
|
});
|
36
38
|
|
37
39
|
|
@@ -31,26 +31,30 @@ module('FactoryGuyTestMixin (using mockjax) with DS.RESTAdapter', {
|
|
31
31
|
make = function() {return FactoryGuy.make.apply(FactoryGuy,arguments)}
|
32
32
|
},
|
33
33
|
teardown: function () {
|
34
|
-
|
34
|
+
Em.run(function() {
|
35
|
+
testHelper.teardown();
|
36
|
+
});
|
35
37
|
}
|
36
38
|
});
|
37
39
|
|
38
40
|
/////// handleCreate //////////
|
39
41
|
|
40
42
|
asyncTest("#handleCreate the basic", function() {
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
43
|
+
Em.run(function() {
|
44
|
+
var customDescription = "special description"
|
45
|
+
|
46
|
+
testHelper.handleCreate('profile', {
|
47
|
+
match: {description: customDescription}
|
48
|
+
})
|
49
|
+
ok(store.all('profile').get('content.length') == 0)
|
50
|
+
store.createRecord('profile', {
|
51
|
+
description: customDescription
|
52
|
+
}).save().then(function(profile) {
|
53
|
+
ok(store.all('profile').get('content.length') == 1, 'No extra records created')
|
54
|
+
ok(profile instanceof Profile, 'Creates the correct type of record')
|
55
|
+
ok(profile.get('description') == customDescription, 'Passes along the match attributes')
|
56
|
+
start();
|
57
|
+
});
|
54
58
|
});
|
55
59
|
});
|
56
60
|
|
@@ -175,14 +179,15 @@ asyncTest("#handleFind with a record returns the record", function () {
|
|
175
179
|
});
|
176
180
|
|
177
181
|
asyncTest("#handleFind with a record handles reload", function () {
|
178
|
-
|
179
|
-
|
182
|
+
Em.run(function() {
|
183
|
+
var profile = FactoryGuy.make('profile')
|
184
|
+
testHelper.handleFind(profile);
|
180
185
|
|
181
|
-
|
182
|
-
|
183
|
-
|
186
|
+
profile.reload().then(function (profile2) {
|
187
|
+
ok(profile2.id == profile.id);
|
188
|
+
start();
|
189
|
+
});
|
184
190
|
});
|
185
|
-
|
186
191
|
});
|
187
192
|
|
188
193
|
asyncTest("#handleFind with options", function () {
|
@@ -237,7 +242,9 @@ module('FactoryGuyTestMixin (using mockjax) with DS.ActiveModelAdapter', {
|
|
237
242
|
make = function() {return FactoryGuy.make.apply(FactoryGuy,arguments)}
|
238
243
|
},
|
239
244
|
teardown: function () {
|
240
|
-
|
245
|
+
Em.run(function() {
|
246
|
+
testHelper.teardown();
|
247
|
+
});
|
241
248
|
}
|
242
249
|
});
|
243
250
|
|
@@ -246,274 +253,311 @@ module('FactoryGuyTestMixin (using mockjax) with DS.ActiveModelAdapter', {
|
|
246
253
|
|
247
254
|
/////// with hash of parameters ///////////////////
|
248
255
|
asyncTest("#handleCreate with no specific match", function() {
|
249
|
-
|
256
|
+
Em.run(function() {
|
257
|
+
testHelper.handleCreate('profile');
|
250
258
|
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
259
|
+
store.createRecord('profile', {description: 'whatever'}).save().then(function(profile) {
|
260
|
+
ok(profile.id == 1)
|
261
|
+
ok(profile.get('description') == 'whatever')
|
262
|
+
start();
|
263
|
+
});
|
255
264
|
});
|
256
265
|
});
|
257
266
|
|
258
267
|
asyncTest("#handleCreate match some attributes", function() {
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
268
|
+
Em.run(function() {
|
269
|
+
var customDescription = "special description"
|
270
|
+
var date = new Date();
|
271
|
+
|
272
|
+
testHelper.handleCreate('profile', {
|
273
|
+
match: {description: customDescription}
|
274
|
+
})
|
275
|
+
|
276
|
+
store.createRecord('profile', {
|
277
|
+
description: customDescription, created_at: date
|
278
|
+
}).save().then(function (profile) {
|
279
|
+
ok(profile instanceof Profile)
|
280
|
+
ok(profile.id == 1)
|
281
|
+
ok(profile.get('description') == customDescription)
|
282
|
+
start();
|
283
|
+
});
|
264
284
|
})
|
265
|
-
|
266
|
-
store.createRecord('profile', {
|
267
|
-
description: customDescription, created_at: date
|
268
|
-
}).save().then(function(profile) {
|
269
|
-
ok(profile instanceof Profile)
|
270
|
-
ok(profile.id == 1)
|
271
|
-
ok(profile.get('description') == customDescription)
|
272
|
-
start();
|
273
|
-
});
|
274
285
|
});
|
275
286
|
|
276
287
|
asyncTest("#handleCreate match all attributes", function() {
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
288
|
+
Em.run(function() {
|
289
|
+
var customDescription = "special description"
|
290
|
+
var date = new Date();
|
291
|
+
|
292
|
+
testHelper.handleCreate('profile', {
|
293
|
+
match: {description: customDescription, created_at: date}
|
294
|
+
})
|
295
|
+
|
296
|
+
store.createRecord('profile', {
|
297
|
+
description: customDescription, created_at: date
|
298
|
+
}).save().then(function(profile) {
|
299
|
+
ok(profile instanceof Profile)
|
300
|
+
ok(profile.id == 1)
|
301
|
+
ok(profile.get('description') == customDescription)
|
302
|
+
ok(profile.get('created_at') == date.toString())
|
303
|
+
start();
|
304
|
+
});
|
292
305
|
});
|
293
306
|
});
|
294
307
|
|
295
308
|
|
296
309
|
asyncTest("#handleCreate returns attributes", function() {
|
297
|
-
|
310
|
+
Em.run(function() {
|
311
|
+
var date = new Date()
|
298
312
|
|
299
|
-
|
300
|
-
|
301
|
-
|
313
|
+
testHelper.handleCreate('profile', {
|
314
|
+
returns: {created_at: date}
|
315
|
+
})
|
302
316
|
|
303
|
-
|
304
|
-
|
305
|
-
|
317
|
+
store.createRecord('profile').save().then(function(profile) {
|
318
|
+
ok(profile.get('created_at') == date.toString())
|
319
|
+
start();
|
320
|
+
});
|
306
321
|
});
|
307
322
|
});
|
308
323
|
|
309
324
|
asyncTest("#handleCreate returns camelCase attributes", function() {
|
310
|
-
|
325
|
+
Em.run(function() {
|
326
|
+
var customDescription = "special description"
|
311
327
|
|
312
|
-
|
313
|
-
|
314
|
-
|
328
|
+
testHelper.handleCreate('profile', {
|
329
|
+
returns: {camel_case_description: customDescription}
|
330
|
+
})
|
315
331
|
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
332
|
+
store.createRecord('profile', {
|
333
|
+
camel_case_description: 'description'
|
334
|
+
}).save().then(function(profile) {
|
335
|
+
ok(profile.get('camelCaseDescription') == customDescription)
|
336
|
+
start();
|
337
|
+
});
|
321
338
|
});
|
322
339
|
});
|
323
340
|
|
324
341
|
asyncTest("#handleCreate match belongsTo association", function() {
|
325
|
-
|
326
|
-
|
342
|
+
Em.run(function() {
|
343
|
+
var company = make('company')
|
344
|
+
testHelper.handleCreate('profile', {match:{ company: company}})
|
327
345
|
|
328
|
-
|
329
|
-
|
330
|
-
|
346
|
+
store.createRecord('profile', {company: company}).save().then(function(profile) {
|
347
|
+
ok(profile.get('company') == company)
|
348
|
+
start();
|
349
|
+
});
|
331
350
|
});
|
332
351
|
});
|
333
352
|
|
334
353
|
asyncTest("#handleCreate match belongsTo polymorphic association", function() {
|
335
|
-
|
336
|
-
|
354
|
+
Em.run(function() {
|
355
|
+
var group = make('group')
|
356
|
+
testHelper.handleCreate('profile', {match:{ group: group}})
|
337
357
|
|
338
|
-
|
339
|
-
|
340
|
-
|
358
|
+
store.createRecord('profile', {group: group}).save().then(function(profile) {
|
359
|
+
ok(profile.get('group') == group)
|
360
|
+
start();
|
361
|
+
});
|
341
362
|
});
|
342
363
|
});
|
343
364
|
|
344
365
|
|
345
366
|
asyncTest("#handleCreate match attributes and return attributes", function() {
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
367
|
+
Em.run(function() {
|
368
|
+
var date = new Date()
|
369
|
+
var customDescription = "special description"
|
370
|
+
var company = make('company')
|
371
|
+
var group = make('big_group')
|
372
|
+
|
373
|
+
testHelper.handleCreate('profile', {
|
374
|
+
match: {description: customDescription, company: company, group: group},
|
375
|
+
returns: {created_at: new Date()}
|
376
|
+
})
|
377
|
+
|
378
|
+
store.createRecord('profile', {
|
379
|
+
description: customDescription, company: company, group: group
|
380
|
+
}).save().then(function(profile) {
|
381
|
+
start();
|
382
|
+
ok(profile.get('created_at') == date.toString())
|
383
|
+
ok(profile.get('group') == group)
|
384
|
+
ok(profile.get('company') == company)
|
385
|
+
ok(profile.get('description') == customDescription)
|
386
|
+
});
|
364
387
|
});
|
365
388
|
});
|
366
389
|
|
367
390
|
|
368
391
|
asyncTest("#handleCreate failure", function() {
|
369
|
-
|
392
|
+
Em.run(function() {
|
393
|
+
testHelper.handleCreate('profile', { succeed: false } )
|
370
394
|
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
395
|
+
store.createRecord('profile').save()
|
396
|
+
.then(
|
397
|
+
function() {},
|
398
|
+
function() {
|
399
|
+
ok(true)
|
400
|
+
start();
|
401
|
+
}
|
402
|
+
)
|
403
|
+
});
|
379
404
|
});
|
380
405
|
|
381
406
|
|
382
407
|
asyncTest("#handleCreate match but still fail", function() {
|
383
|
-
|
408
|
+
Em.run(function() {
|
409
|
+
var description = "special description"
|
384
410
|
|
385
|
-
|
386
|
-
|
387
|
-
|
411
|
+
testHelper.handleCreate('profile', {
|
412
|
+
match: {description: description}, succeed: false
|
413
|
+
})
|
388
414
|
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
415
|
+
store.createRecord('profile', {description: description}).save()
|
416
|
+
.then(
|
417
|
+
function() {},
|
418
|
+
function() {
|
419
|
+
ok(true)
|
420
|
+
start();
|
421
|
+
}
|
422
|
+
)
|
423
|
+
});
|
397
424
|
});
|
398
425
|
|
399
426
|
/////// handleCreate //////////
|
400
427
|
/////// with chaining methods ///////////////////
|
401
428
|
|
402
429
|
asyncTest("#handleCreate match some attributes with match method", function() {
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
430
|
+
Em.run(function() {
|
431
|
+
var customDescription = "special description"
|
432
|
+
var date = new Date();
|
433
|
+
|
434
|
+
testHelper.handleCreate('profile').match({description: customDescription});
|
435
|
+
|
436
|
+
store.createRecord('profile', {
|
437
|
+
description: customDescription, created_at: date
|
438
|
+
}).save().then(function(profile) {
|
439
|
+
ok(profile instanceof Profile)
|
440
|
+
ok(profile.id == 1)
|
441
|
+
ok(profile.get('description') == customDescription)
|
442
|
+
start();
|
443
|
+
});
|
415
444
|
});
|
416
445
|
});
|
417
446
|
|
418
447
|
asyncTest("#handleCreate match all attributes with match method", function() {
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
448
|
+
Em.run(function() {
|
449
|
+
var customDescription = "special description"
|
450
|
+
var date = new Date();
|
451
|
+
|
452
|
+
testHelper.handleCreate('profile').match({description: customDescription, created_at: date});
|
453
|
+
|
454
|
+
store.createRecord('profile', {
|
455
|
+
description: customDescription, created_at: date
|
456
|
+
}).save().then(function(profile) {
|
457
|
+
ok(profile instanceof Profile)
|
458
|
+
ok(profile.id == 1)
|
459
|
+
ok(profile.get('description') == customDescription)
|
460
|
+
ok(profile.get('created_at') == date.toString())
|
461
|
+
start();
|
462
|
+
});
|
432
463
|
});
|
433
464
|
});
|
434
465
|
|
435
466
|
asyncTest("#handleCreate match belongsTo association with match method", function() {
|
436
|
-
|
437
|
-
|
467
|
+
Em.run(function() {
|
468
|
+
var company = make('company')
|
438
469
|
|
439
|
-
|
440
|
-
|
441
|
-
|
470
|
+
testHelper.handleCreate('profile').match({company: company})
|
471
|
+
|
472
|
+
store.createRecord('profile', {company: company}).save().then(function(profile) {
|
473
|
+
ok(profile.get('company') == company)
|
474
|
+
start();
|
475
|
+
});
|
442
476
|
});
|
443
477
|
});
|
444
478
|
|
445
479
|
asyncTest("#handleCreate match belongsTo polymorphic association with match method", function() {
|
446
|
-
|
447
|
-
|
480
|
+
Em.run(function() {
|
481
|
+
var group = make('group')
|
482
|
+
testHelper.handleCreate('profile').match({group: group})
|
448
483
|
|
449
|
-
|
450
|
-
|
451
|
-
|
484
|
+
store.createRecord('profile', {group: group}).save().then(function(profile) {
|
485
|
+
ok(profile.get('group') == group)
|
486
|
+
start();
|
487
|
+
});
|
452
488
|
});
|
453
489
|
});
|
454
490
|
|
455
491
|
|
456
492
|
|
457
493
|
asyncTest("#handleCreate returns attributes with andReturns method", function() {
|
458
|
-
|
494
|
+
Em.run(function() {
|
495
|
+
var date = new Date()
|
459
496
|
|
460
|
-
|
497
|
+
testHelper.handleCreate('profile').andReturn({created_at: date});
|
461
498
|
|
462
|
-
|
463
|
-
|
464
|
-
|
499
|
+
store.createRecord('profile').save().then(function(profile) {
|
500
|
+
ok(profile.get('created_at') == date.toString())
|
501
|
+
start();
|
502
|
+
});
|
465
503
|
});
|
466
504
|
});
|
467
505
|
|
468
506
|
asyncTest("#handleCreate match attributes and return attributes with match and andReturn methods", function() {
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
.
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
507
|
+
Em.run(function() {
|
508
|
+
var date = new Date()
|
509
|
+
var customDescription = "special description"
|
510
|
+
var company = make('company')
|
511
|
+
var group = make('big_group')
|
512
|
+
|
513
|
+
testHelper.handleCreate('profile')
|
514
|
+
.match({description: customDescription, company: company, group: group})
|
515
|
+
.andReturn({created_at: new Date()})
|
516
|
+
|
517
|
+
store.createRecord('profile', {
|
518
|
+
description: customDescription, company: company, group: group
|
519
|
+
}).save().then(function(profile) {
|
520
|
+
start();
|
521
|
+
ok(profile.get('created_at') == date.toString())
|
522
|
+
ok(profile.get('group') == group)
|
523
|
+
ok(profile.get('company') == company)
|
524
|
+
ok(profile.get('description') == customDescription)
|
525
|
+
});
|
486
526
|
});
|
487
527
|
});
|
488
528
|
|
489
529
|
|
490
530
|
asyncTest("#handleCreate failure with andFail method", function() {
|
491
|
-
|
531
|
+
Em.run(function() {
|
532
|
+
testHelper.handleCreate('profile').andFail();
|
492
533
|
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
534
|
+
store.createRecord('profile').save()
|
535
|
+
.then(
|
536
|
+
function() {},
|
537
|
+
function() {
|
538
|
+
ok(true)
|
539
|
+
start();
|
540
|
+
}
|
541
|
+
)
|
542
|
+
});
|
501
543
|
});
|
502
544
|
|
503
545
|
|
504
546
|
asyncTest("#handleCreate match but still fail with chaining methods", function() {
|
505
|
-
|
547
|
+
Em.run(function() {
|
548
|
+
var description = "special description"
|
506
549
|
|
507
|
-
|
550
|
+
testHelper.handleCreate('profile').match({description: description}).andFail();
|
508
551
|
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
552
|
+
store.createRecord('profile', {description: description}).save()
|
553
|
+
.then(
|
554
|
+
function() {},
|
555
|
+
function() {
|
556
|
+
ok(true)
|
557
|
+
start();
|
558
|
+
}
|
559
|
+
)
|
560
|
+
});
|
517
561
|
});
|
518
562
|
|
519
563
|
|
@@ -584,78 +628,91 @@ test("#handleUpdate with incorrect parameters", function(assert) {
|
|
584
628
|
});
|
585
629
|
|
586
630
|
asyncTest("#handleUpdate the with modelType and id", function() {
|
587
|
-
|
588
|
-
|
631
|
+
Em.run(function() {
|
632
|
+
var profile = make('profile');
|
633
|
+
testHelper.handleUpdate('profile', profile.id);
|
589
634
|
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
635
|
+
profile.set('description','new desc');
|
636
|
+
profile.save().then(function(profile) {
|
637
|
+
ok(profile.get('description') == 'new desc');
|
638
|
+
start();
|
639
|
+
});
|
594
640
|
});
|
595
641
|
});
|
596
642
|
|
597
643
|
|
598
644
|
asyncTest("#handleUpdate the with model", function() {
|
599
|
-
|
600
|
-
|
645
|
+
Em.run(function() {
|
646
|
+
var profile = make('profile');
|
647
|
+
testHelper.handleUpdate(profile, true, {e:1});
|
601
648
|
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
649
|
+
profile.set('description','new desc');
|
650
|
+
profile.save().then(function(profile) {
|
651
|
+
ok(profile.get('description') == 'new desc');
|
652
|
+
start();
|
653
|
+
});
|
606
654
|
});
|
607
655
|
});
|
608
656
|
|
609
657
|
asyncTest("#handleUpdate the with modelType and id that fails", function() {
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
profile.set('description','new desc');
|
614
|
-
profile.save().then(
|
615
|
-
function() {},
|
616
|
-
function() {
|
617
|
-
ok(true)
|
618
|
-
start();
|
619
|
-
}
|
620
|
-
)
|
621
|
-
});
|
622
|
-
|
623
|
-
asyncTest("#handleUpdate with model that fails", function() {
|
624
|
-
var profile = make('profile');
|
625
|
-
testHelper.handleUpdate(profile, false);
|
658
|
+
Em.run(function() {
|
659
|
+
var profile = make('profile');
|
660
|
+
testHelper.handleUpdate('profile', profile.id, false);
|
626
661
|
|
627
|
-
|
628
|
-
|
662
|
+
profile.set('description','new desc');
|
663
|
+
profile.save().then(
|
629
664
|
function() {},
|
630
665
|
function() {
|
631
666
|
ok(true)
|
632
667
|
start();
|
633
668
|
}
|
634
669
|
)
|
670
|
+
});
|
671
|
+
});
|
672
|
+
|
673
|
+
asyncTest("#handleUpdate with model that fails", function() {
|
674
|
+
Em.run(function() {
|
675
|
+
var profile = make('profile');
|
676
|
+
|
677
|
+
testHelper.handleUpdate(profile, false);
|
678
|
+
|
679
|
+
profile.set('description','new desc');
|
680
|
+
profile.save().then(
|
681
|
+
function() {},
|
682
|
+
function() {
|
683
|
+
ok(true)
|
684
|
+
start();
|
685
|
+
}
|
686
|
+
)
|
687
|
+
});
|
635
688
|
});
|
636
689
|
|
637
690
|
|
638
691
|
/////// handleDelete //////////
|
639
692
|
|
640
693
|
asyncTest("#handleDelete the basic", function() {
|
641
|
-
|
642
|
-
|
694
|
+
Em.run(function() {
|
695
|
+
var profile = make('profile');
|
696
|
+
testHelper.handleDelete('profile', profile.id);
|
643
697
|
|
644
|
-
|
645
|
-
|
646
|
-
|
698
|
+
profile.destroyRecord().then(function() {
|
699
|
+
equal(store.all('profile').get('content.length'), 0);
|
700
|
+
start();
|
701
|
+
});
|
647
702
|
});
|
648
703
|
});
|
649
704
|
|
650
705
|
asyncTest("#handleDelete failure case", function() {
|
651
|
-
|
652
|
-
|
706
|
+
Em.run(function() {
|
707
|
+
var profile = make('profile');
|
708
|
+
testHelper.handleDelete('profile', profile.id, false);
|
653
709
|
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
710
|
+
profile.destroyRecord().then(
|
711
|
+
function() {},
|
712
|
+
function() {
|
713
|
+
ok(true);
|
714
|
+
start();
|
715
|
+
}
|
716
|
+
);
|
717
|
+
});
|
661
718
|
});
|
@@ -51,7 +51,9 @@ test("#resetModels clears the store of models, clears the FIXTURES arrays for ea
|
|
51
51
|
equal(store.all('user').get('length'), 1);
|
52
52
|
equal(store.all('project').get('length'), 1);
|
53
53
|
|
54
|
-
|
54
|
+
Em.run(function() {
|
55
|
+
FactoryGuy.resetModels(store);
|
56
|
+
});
|
55
57
|
|
56
58
|
equal(User.FIXTURES.length, 0);
|
57
59
|
equal(Project.FIXTURES.length, 0);
|
data/tests/index.html
CHANGED
@@ -24,20 +24,18 @@
|
|
24
24
|
<script src='../tests/test_setup.js'></script>
|
25
25
|
<script src='../tests/support/test_helper.js'></script>
|
26
26
|
|
27
|
-
|
28
|
-
|
29
27
|
</head>
|
30
28
|
<body>
|
31
29
|
<div id="qunit"></div> <!-- QUnit fills this with results, etc -->
|
32
30
|
<script src='active_model_adapter_factory_test.js'></script>
|
33
31
|
<script src='rest_adapter_factory_test.js'></script>
|
34
|
-
|
32
|
+
<!--<script src='fixture_adapter_factory_test.js'></script>-->
|
35
33
|
<script src='store_test.js'></script>
|
36
34
|
<script src='factory_guy_test.js'></script>
|
37
35
|
<script src='factory_guy_test_mixin_test.js'></script>
|
38
36
|
<div id='qunit-fixture'>
|
39
37
|
|
40
|
-
|
38
|
+
<!-- any HTML you want to be present in each test (will be reset for each test) -->
|
41
39
|
|
42
40
|
</div>
|
43
41
|
</body>
|
@@ -13,24 +13,26 @@ module('FactoryGuy with DS.RESTAdapter', {
|
|
13
13
|
|
14
14
|
|
15
15
|
test("#resetModels clears the store of models, and resets the model definition", function() {
|
16
|
-
|
17
|
-
|
16
|
+
Em.run(function() {
|
17
|
+
var project = make('project');
|
18
|
+
var user = make('user', {projects: [project]});
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
for (model in FactoryGuy.modelDefinitions) {
|
21
|
+
var definition = FactoryGuy.modelDefinitions[model];
|
22
|
+
sinon.spy(definition, 'reset');
|
23
|
+
}
|
23
24
|
|
24
|
-
|
25
|
+
FactoryGuy.resetModels(store);
|
25
26
|
|
26
|
-
|
27
|
-
|
27
|
+
equal(store.all('user').get('content.length'), 0)
|
28
|
+
equal(store.all('project').get('content.length'), 0)
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
for (model in FactoryGuy.modelDefinitions) {
|
31
|
+
var definition = FactoryGuy.modelDefinitions[model];
|
32
|
+
ok(definition.reset.calledOnce);
|
33
|
+
definition.reset.restore();
|
34
|
+
}
|
35
|
+
});
|
34
36
|
});
|
35
37
|
|
36
38
|
|
data/tests/store_test.js
CHANGED
@@ -52,18 +52,20 @@ testFixtureEquality = function(models, json, num){
|
|
52
52
|
}
|
53
53
|
|
54
54
|
asyncTest("no root", function() {
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
55
|
+
Em.run(function() {
|
56
|
+
var userJson = {
|
57
|
+
id: '1',
|
58
|
+
name: 'monkey'
|
59
|
+
};
|
60
|
+
|
61
|
+
store.pushPayload('user', userJson);
|
62
|
+
store.find('user').then(function(users){
|
63
|
+
equal(users.get('length'), 1, 'Expected one user in the data store');
|
64
|
+
|
65
|
+
equal(users.get('firstObject.id'), userJson.id);
|
66
|
+
equal(users.get('firstObject.name'), userJson.name);
|
67
|
+
start();
|
68
|
+
});
|
67
69
|
});
|
68
70
|
});
|
69
71
|
|
@@ -94,86 +96,92 @@ asyncTest("no root replace data", function(){
|
|
94
96
|
});
|
95
97
|
|
96
98
|
asyncTest("single root", function() {
|
97
|
-
|
98
|
-
|
99
|
-
|
99
|
+
Em.run(function() {
|
100
|
+
var userJson = {
|
101
|
+
users: [{ id:'1', name:'monkey' }, { id:'2', name:'banana' }]
|
102
|
+
};
|
100
103
|
|
101
|
-
|
102
|
-
|
104
|
+
store.pushPayload(userJson);
|
105
|
+
store.find('user').then(function(users) {
|
103
106
|
|
104
|
-
|
107
|
+
testFixtureEquality(users, userJson['users'], 2);
|
105
108
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
109
|
+
users.forEach(function(user) {
|
110
|
+
var u = userJson['users'].findBy('id', user.get('id'));
|
111
|
+
equal(user.get('name'), u.name, 'Got unexpected name ' + user.get('name'));
|
112
|
+
});
|
110
113
|
|
111
|
-
|
114
|
+
start();
|
115
|
+
});
|
112
116
|
});
|
113
117
|
});
|
114
118
|
|
115
119
|
asyncTest("multiple roots", function() {
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
120
|
+
Em.run(function() {
|
121
|
+
var json = {
|
122
|
+
companies: [{ id: '1', name: 'Google', projects: ['1', '2'] }],
|
123
|
+
projects: [
|
124
|
+
{ id:'1', title: 'Docs', user: '1' },
|
125
|
+
{ id:'2', title: 'Gmail' }
|
126
|
+
],
|
127
|
+
users: [{ id: '1', name: 'monkey', projects: ['1'] }],
|
128
|
+
profiles: [
|
129
|
+
{ id: '1', created_at: new Date(), description: 'banana' },
|
130
|
+
{ id: '2', created_at: new Date(), description: 'monkey' }
|
131
|
+
],
|
132
|
+
hats: [
|
133
|
+
{ id: '2', type: 'Trilby' }
|
134
|
+
],
|
135
|
+
};
|
131
136
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
137
|
+
store.pushPayload(json);
|
138
|
+
Ember.RSVP.Promise.all([
|
139
|
+
store.find('company'), store.find('project'),
|
140
|
+
store.find('user'), store.find('profile'), store.find('hat')
|
141
|
+
]).then(function(data) {
|
142
|
+
var companies = data[0],
|
143
|
+
projects = data[1],
|
144
|
+
users = data[2],
|
145
|
+
profiles = data[3],
|
146
|
+
hats = data[4];
|
147
|
+
|
148
|
+
testFixtureEquality(companies, json['companies'], 1);
|
149
|
+
testFixtureEquality(projects, json['projects'], 2);
|
150
|
+
testFixtureEquality(users, json['users'], 1);
|
151
|
+
testFixtureEquality(profiles, json['profiles'], 2);
|
152
|
+
testFixtureEquality(hats, json['hats'], 1);
|
153
|
+
|
154
|
+
start();
|
155
|
+
});
|
150
156
|
});
|
151
157
|
});
|
152
158
|
|
153
159
|
asyncTest("multiple roots with type specified", function() {
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
160
|
+
Em.run(function() {
|
161
|
+
var json = {
|
162
|
+
companies: [{ id: '1', name: 'Google', projects: ['1', '2'] }],
|
163
|
+
projects: [
|
164
|
+
{ id:'1', title: 'Docs', user: '1' },
|
165
|
+
{ id:'2', title: 'Gmail' }
|
166
|
+
],
|
167
|
+
users: [{ id: '1', name: 'monkey', projects: ['1'] }],
|
168
|
+
}
|
169
|
+
|
170
|
+
store.pushPayload('company', json);
|
171
|
+
|
172
|
+
Ember.RSVP.Promise.all([
|
173
|
+
store.find('company'), store.find('project'), store.find('user')
|
174
|
+
]).then(function(data) {
|
175
|
+
var companies = data[0],
|
176
|
+
projects = data[1],
|
177
|
+
users = data[2];
|
178
|
+
|
179
|
+
testFixtureEquality(companies, json['companies'], 1);
|
180
|
+
testFixtureEquality(projects, json['projects'], 2);
|
181
|
+
testFixtureEquality(users, json['users'], 1);
|
182
|
+
|
183
|
+
start();
|
184
|
+
});
|
177
185
|
});
|
178
186
|
});
|
179
187
|
|
@@ -85,6 +85,8 @@ TestHelper = Ember.Object.createWithMixins(FactoryGuy.testMixin,{
|
|
85
85
|
container.register('transform:object', ObjectTransform);
|
86
86
|
container.injection('serializer', 'store', 'store:main');
|
87
87
|
|
88
|
+
Ember.setupForTesting()
|
89
|
+
|
88
90
|
env.store = container.lookup('store:main');
|
89
91
|
env.adapter = env.store.get('defaultAdapter');
|
90
92
|
|
data/tests/test_setup.js
CHANGED
@@ -15,7 +15,7 @@ SmallCompany = Company.extend({
|
|
15
15
|
Group = DS.Model.extend({
|
16
16
|
type: DS.attr('string', {defaultValue: 'Group'}),
|
17
17
|
name: DS.attr('string'),
|
18
|
-
versions: DS.hasMany('group'),
|
18
|
+
versions: DS.hasMany('group', {inverse: null}),
|
19
19
|
profiles: DS.hasMany('profile')
|
20
20
|
})
|
21
21
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ember-data-factory-guy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Sudol
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-02-
|
12
|
+
date: 2015-02-20 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Easily create Fixtures for Ember Data
|
15
15
|
email:
|