ember-data-factory-guy 0.9.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +30 -11
- data/bower.json +1 -1
- data/dist/amd/factory-guy.js +103 -56
- data/dist/ember-data-factory-guy.js +103 -56
- data/dist/ember-data-factory-guy.min.js +1 -1
- data/ember-data-factory-guy.gemspec +1 -1
- data/package.json +1 -1
- data/src/factory_guy.js +46 -12
- data/src/factory_guy_test_mixin.js +35 -6
- data/src/store.js +20 -36
- data/tests/active_model_adapter_factory_test.js +17 -5
- data/tests/factory_guy_test.js +0 -1
- data/tests/factory_guy_test_mixin_test.js +16 -0
- data/tests/rest_adapter_factory_test.js +20 -12
- data/vendor/assets/javascripts/ember_data_factory_guy.js +103 -56
- 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: 08b067285d7aad700359cc0468ef56c4271acb13
|
4
|
+
data.tar.gz: 5e25e40fc8e23190e91e47b122c02af21e57fd97
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf1b499ea9ce45d723aa60b966297b0136c3f617256b57f96aedaaac768b4f693acd9c5032cf7f8e4c0ab52c763c6ad47c6ca7c43ed1146e10149110181f96cc
|
7
|
+
data.tar.gz: fe67654d6644a3e6da62cd31015090deff2f970bfa5827d395c61273e9aac28bce3168db5cf66b6eb6528afd3270dccd1d7686885db6d40d6949938410aa7c6c
|
data/README.md
CHANGED
@@ -15,10 +15,9 @@ of ember-data-factory-guy.
|
|
15
15
|
**Support for fixture adapter is currently kinda broken.**
|
16
16
|
|
17
17
|
*Version 0.9.0 and up deprecates explicit call to store.makeFixture in your tests, in favor
|
18
|
-
of using the testHelper.make function from FactoryGuyTestHelperMixin instead.
|
19
|
-
doing this already ( using FactoryGuyTestHelperMixin ), add a
|
20
|
-
in your code before you start making fixtures.*
|
21
|
-
|
18
|
+
of using the FactoryGuy.make or testHelper.make function from FactoryGuyTestHelperMixin instead.
|
19
|
+
If your not currently doing this already ( using FactoryGuyTestHelperMixin ), add a call to
|
20
|
+
FactoryGuy.setStore(store) somewhere in your code before you start making fixtures.*
|
22
21
|
|
23
22
|
## Using with Ember Cli
|
24
23
|
- https://github.com/igorrKurr/ember-cli-factory-guy-example
|
@@ -228,8 +227,9 @@ the store is looking up the correct model type name
|
|
228
227
|
|
229
228
|
```javascript
|
230
229
|
// First set the store on FactoryGuy. You don't have to do this step manually if you use
|
231
|
-
// FactoryGuyTestHelperMixin since this is done for you in the setup method.
|
232
|
-
|
230
|
+
// FactoryGuyTestHelperMixin since this is done for you in the setup method. The following
|
231
|
+
// store lookup assumes you have a namespace for your Ember app named 'App'.
|
232
|
+
var store = App.__container__.lookup('store:main');
|
233
233
|
FactoryGuy.setStore(store);
|
234
234
|
|
235
235
|
// returns json
|
@@ -492,7 +492,7 @@ the reverse user hasMany 'projects' association is being setup for you on the us
|
|
492
492
|
user.get('projects.length') // => 2
|
493
493
|
|
494
494
|
// or
|
495
|
-
var projects =
|
495
|
+
var projects = FactoryGuy.makeList('project', 2);
|
496
496
|
var user = FactoryGuy.make('user', {projects: projects});
|
497
497
|
user.get('projects.length') // => 2
|
498
498
|
|
@@ -511,7 +511,7 @@ the reverse 'user' belongsTo association is being setup for you on the project
|
|
511
511
|
|
512
512
|
- FactoryGuy.buildList
|
513
513
|
- Builds an array of one or more json objects
|
514
|
-
-
|
514
|
+
- FactoryGuy.makeList
|
515
515
|
- Loads one or more instances into store
|
516
516
|
|
517
517
|
|
@@ -528,7 +528,7 @@ the reverse 'user' belongsTo association is being setup for you on the project
|
|
528
528
|
##### Building model instances
|
529
529
|
|
530
530
|
```javascript
|
531
|
-
var users =
|
531
|
+
var users = FactoryGuy.makeList('user', 2)
|
532
532
|
users.get('length') // => 2
|
533
533
|
users[0].toJSON({includeId: true}) // => {id: 3, name: 'User3', style: 'normal'}
|
534
534
|
users[1].toJSON({includeId: true}) // => {id: 4, name: 'User4', style: 'normal'}
|
@@ -593,7 +593,8 @@ test("make a user using your applications default adapter", function() {
|
|
593
593
|
- Uses mockjax
|
594
594
|
- Has helper methods
|
595
595
|
- handleFindMany
|
596
|
-
-
|
596
|
+
- handleFindQuery
|
597
|
+
- handleCreate
|
597
598
|
- handleUpdate
|
598
599
|
- handleDelete
|
599
600
|
|
@@ -619,7 +620,7 @@ tests run as shown in the previous section (Using FactoryGuyTestMixin)**
|
|
619
620
|
- for dealing with finding all records of a particular type
|
620
621
|
|
621
622
|
```javascript
|
622
|
-
// can use traits and extra fixture options here as you would with
|
623
|
+
// can use traits and extra fixture options here as you would with FactoryGuy#makeList
|
623
624
|
testHelper.handleFindMany('profile', 2);
|
624
625
|
|
625
626
|
store.find('profile').then(function (profiles) {
|
@@ -627,6 +628,24 @@ tests run as shown in the previous section (Using FactoryGuyTestMixin)**
|
|
627
628
|
});
|
628
629
|
```
|
629
630
|
|
631
|
+
|
632
|
+
##### handleFindQuery
|
633
|
+
- for dealing with finding all records for a type of model with query parameters.
|
634
|
+
|
635
|
+
```javascript
|
636
|
+
// First build json for the instances you want 'returned' in your query.
|
637
|
+
var usersJson = FactoryGuy.buildList('user', 2);
|
638
|
+
|
639
|
+
// Pass in the parameters you will search on ( in this case 'name' and 'age' )
|
640
|
+
// as an array, in the second argument.
|
641
|
+
testHelper.handleFindQuery('user', ['name', 'age'], usersJson);
|
642
|
+
|
643
|
+
store.findQuery('user', {name:'Bob', age: 10}}).then(function(userInstances){
|
644
|
+
/// userInstances are created from the usersJson that you passed in
|
645
|
+
})
|
646
|
+
```
|
647
|
+
|
648
|
+
|
630
649
|
##### handleCreate
|
631
650
|
- options
|
632
651
|
- match - attributes that must be in request json
|
data/bower.json
CHANGED
data/dist/amd/factory-guy.js
CHANGED
@@ -247,25 +247,13 @@ var FactoryGuy = {
|
|
247
247
|
*/
|
248
248
|
isAttributeRelationship: function(typeName, attribute) {
|
249
249
|
if (!this.store) {
|
250
|
-
|
250
|
+
Ember.debug("FactoryGuy does not have the application's store. Use FactoryGuy.setStore(store) before making any fixtures")
|
251
251
|
// The legacy value was true.
|
252
252
|
return true;
|
253
253
|
}
|
254
254
|
var model = this.store.modelFor(typeName);
|
255
255
|
return !!model.typeForRelationship(attribute);
|
256
256
|
},
|
257
|
-
/**
|
258
|
-
Make new fixture and save to store. Proxy to store#makeFixture method
|
259
|
-
|
260
|
-
@param {String} name fixture name
|
261
|
-
@param {String} trait optional trait names ( one or more )
|
262
|
-
@param {Object} opts optional fixture options that will override default fixture values
|
263
|
-
@returns {Object|DS.Model} json or record depending on the adapter type
|
264
|
-
*/
|
265
|
-
make: function() {
|
266
|
-
Ember.assert("FactoryGuy does not have the application's store. Use FactoryGuy.setStore(store) before making any fixtures", this.store);
|
267
|
-
return this.store.makeFixture.apply(this.store,arguments);
|
268
|
-
},
|
269
257
|
/**
|
270
258
|
Used in model definitions to declare use of a sequence. For example:
|
271
259
|
|
@@ -333,7 +321,7 @@ var FactoryGuy = {
|
|
333
321
|
};
|
334
322
|
},
|
335
323
|
association: function (fixtureName, opts) {
|
336
|
-
|
324
|
+
Ember.deprecate('DEPRECATION Warning: use FactoryGuy.belongsTo instead');
|
337
325
|
return this.belongsTo(fixtureName, opts);
|
338
326
|
},
|
339
327
|
/**
|
@@ -460,7 +448,53 @@ var FactoryGuy = {
|
|
460
448
|
}
|
461
449
|
return definition.buildList(name, number, traits, opts);
|
462
450
|
},
|
451
|
+
/**
|
452
|
+
Make new fixture and save to store.
|
453
|
+
|
454
|
+
@param {String} name fixture name
|
455
|
+
@param {String} trait optional trait names ( one or more )
|
456
|
+
@param {Object} options optional fixture options that will override default fixture values
|
457
|
+
@returns {Object|DS.Model} json or record depending on the adapter type
|
458
|
+
*/
|
459
|
+
make: function() {
|
460
|
+
var store = this.store;
|
461
|
+
Ember.assert("FactoryGuy does not have the application's store. Use FactoryGuy.setStore(store) before making any fixtures", store);
|
462
|
+
|
463
|
+
var fixture = this.build.apply(this, arguments);
|
464
|
+
var name = arguments[0];
|
465
|
+
var modelName = this.lookupModelForFixtureName(name);
|
466
|
+
var modelType = store.modelFor(modelName);
|
467
|
+
|
468
|
+
if (store.usingFixtureAdapter()) {
|
469
|
+
store.setAssociationsForFixtureAdapter(modelType, modelName, fixture);
|
470
|
+
return this.pushFixture(modelType, fixture);
|
471
|
+
} else {
|
472
|
+
return store.makeModel(modelType, fixture);
|
473
|
+
}
|
474
|
+
},
|
475
|
+
/**
|
476
|
+
Make a list of Fixtures
|
463
477
|
|
478
|
+
@param {String} name name of fixture
|
479
|
+
@param {Number} number number to create
|
480
|
+
@param {String} trait optional trait names ( one or more )
|
481
|
+
@param {Object} options optional fixture options that will override default fixture values
|
482
|
+
@returns {Array} list of json fixtures or records depending on the adapter type
|
483
|
+
*/
|
484
|
+
makeList: function() {
|
485
|
+
Ember.assert("FactoryGuy does not have the application's store. Use FactoryGuy.setStore(store) before making any fixtures", this.store);
|
486
|
+
|
487
|
+
var arr = [];
|
488
|
+
var args = Array.prototype.slice.call(arguments);
|
489
|
+
Ember.assert("makeList needs at least 2 arguments, a name and a number",args.length >= 2);
|
490
|
+
var number = args.splice(1,1)[0];
|
491
|
+
Ember.assert("Second argument to makeList should be a number (of fixtures to make.)",typeof number == 'number');
|
492
|
+
|
493
|
+
for (var i = 0; i < number; i++) {
|
494
|
+
arr.push(this.make.apply(this, args));
|
495
|
+
}
|
496
|
+
return arr;
|
497
|
+
},
|
464
498
|
/**
|
465
499
|
Clear model instances from FIXTURES array, and from store cache.
|
466
500
|
Reset the id sequence for the models back to zero.
|
@@ -548,30 +582,30 @@ var FactoryGuy = {
|
|
548
582
|
return adapter instanceof DS.FixtureAdapter;
|
549
583
|
},
|
550
584
|
/**
|
551
|
-
|
552
|
-
will push to FIXTURE array, otherwise will use push method on adapter to load
|
553
|
-
the record into the store
|
554
|
-
|
555
|
-
@param {String} name fixture name
|
556
|
-
@param {String} trait optional trait names ( one or more )
|
557
|
-
@param {Object} opts optional fixture options that will override default fixture values
|
558
|
-
@returns {Object|DS.Model} json or record depending on the adapter type
|
585
|
+
Deprecated in favor of FactoryGuy.make
|
559
586
|
*/
|
560
587
|
makeFixture: function () {
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
return store.makeModel(modelType, fixture);
|
571
|
-
}
|
588
|
+
Ember.deprecate('DEPRECATION Warning: use FactoryGuy.make instead');
|
589
|
+
FactoryGuy.make.call(FactoryGuy, arguments)
|
590
|
+
},
|
591
|
+
/**
|
592
|
+
Deprecated in favor of FactoryGuy.makeList
|
593
|
+
*/
|
594
|
+
makeList: function () {
|
595
|
+
Ember.deprecate('DEPRECATION Warning: use FactoryGuy.makeList instead');
|
596
|
+
FactoryGuy.makeList.call(FactoryGuy, arguments)
|
572
597
|
},
|
598
|
+
/**
|
599
|
+
* Most of the work of making the model from the json fixture is going on here.
|
600
|
+
* @param modelType
|
601
|
+
* @param fixture
|
602
|
+
* @returns {*}
|
603
|
+
*/
|
573
604
|
makeModel: function (modelType, fixture) {
|
574
|
-
var store = this,
|
605
|
+
var store = this,
|
606
|
+
modelName = store.modelFor(modelType).typeKey,
|
607
|
+
model;
|
608
|
+
|
575
609
|
Em.run(function () {
|
576
610
|
store.findEmbeddedAssociationsForRESTAdapter(modelType, fixture);
|
577
611
|
if (fixture.type) {
|
@@ -585,22 +619,6 @@ var FactoryGuy = {
|
|
585
619
|
});
|
586
620
|
return model;
|
587
621
|
},
|
588
|
-
/**
|
589
|
-
Make a list of Fixtures
|
590
|
-
|
591
|
-
@param {String} name name of fixture
|
592
|
-
@param {Number} number number to create
|
593
|
-
@param {Object} options fixture options
|
594
|
-
@returns {Array} list of json fixtures or records depending on the adapter type
|
595
|
-
*/
|
596
|
-
makeList: function () {
|
597
|
-
var arr = [];
|
598
|
-
var number = arguments[1];
|
599
|
-
for (var i = 0; i < number; i++) {
|
600
|
-
arr.push(this.makeFixture.apply(this, arguments));
|
601
|
-
}
|
602
|
-
return arr;
|
603
|
-
},
|
604
622
|
/**
|
605
623
|
Set the hasMany and belongsTo associations for FixtureAdapter.
|
606
624
|
|
@@ -817,11 +835,10 @@ var FactoryGuyTestMixin = Em.Mixin.create({
|
|
817
835
|
return this.getStore().find(type, id);
|
818
836
|
},
|
819
837
|
/**
|
820
|
-
Make new fixture and save to store. Proxy to
|
838
|
+
Make new fixture and save to store. Proxy to FactoryGuy#make method
|
821
839
|
*/
|
822
840
|
make: function () {
|
823
|
-
|
824
|
-
return store.makeFixture.apply(store, arguments);
|
841
|
+
return FactoryGuy.make.apply(FactoryGuy, arguments);
|
825
842
|
},
|
826
843
|
getStore: function () {
|
827
844
|
return this.get('container').lookup('store:main');
|
@@ -842,6 +859,9 @@ var FactoryGuyTestMixin = Em.Mixin.create({
|
|
842
859
|
type: options.type || 'GET',
|
843
860
|
status: options.status || 200
|
844
861
|
};
|
862
|
+
if (options.urlParams) {
|
863
|
+
request.urlParams = options.urlParams;
|
864
|
+
}
|
845
865
|
if (options.data) {
|
846
866
|
request.data = options.data;
|
847
867
|
}
|
@@ -868,9 +888,8 @@ var FactoryGuyTestMixin = Em.Mixin.create({
|
|
868
888
|
@param {Object} opts optional fixture options
|
869
889
|
*/
|
870
890
|
handleFindMany: function () {
|
871
|
-
var store = this.getStore();
|
872
891
|
// make the records and load them in the store
|
873
|
-
|
892
|
+
FactoryGuy.makeList.apply(FactoryGuy, arguments);
|
874
893
|
var name = arguments[0];
|
875
894
|
var modelName = FactoryGuy.lookupModelForFixtureName(name);
|
876
895
|
var responseJson = {};
|
@@ -878,7 +897,35 @@ var FactoryGuyTestMixin = Em.Mixin.create({
|
|
878
897
|
var url = this.buildURL(modelName);
|
879
898
|
// mock the ajax call, but return nothing, since the records will be
|
880
899
|
// retrieved from the store where they were just loaded above
|
881
|
-
this.stubEndpointForHttpRequest(url, responseJson
|
900
|
+
this.stubEndpointForHttpRequest(url, responseJson);
|
901
|
+
},
|
902
|
+
/**
|
903
|
+
Handling ajax GET for finding all records for a type of model with query parameters.
|
904
|
+
|
905
|
+
```js
|
906
|
+
// First build json for the instances you want 'returned' in your query.
|
907
|
+
var usersJson = FactoryGuy.buildList('user', 2);
|
908
|
+
|
909
|
+
// Pass in the parameters you will search on ( in this case 'name' and 'age' ) as an array,
|
910
|
+
// in the second argument.
|
911
|
+
testHelper.handleFindQuery('user', ['name', 'age'], usersJson);
|
912
|
+
|
913
|
+
store.findQuery('user', {name:'Bob', age: 10}}).then(function(userInstances){
|
914
|
+
/// userInstances were created from the usersJson that you passed in
|
915
|
+
})
|
916
|
+
```
|
917
|
+
|
918
|
+
The model instances will be created from the json you have passed in.
|
919
|
+
|
920
|
+
@param {String} modelName name of the mode like 'user' for User model type
|
921
|
+
@param {String} searchParams the parameters that will be queried
|
922
|
+
@param {Object} json fixture json used to build the resulting modelType instances
|
923
|
+
*/
|
924
|
+
handleFindQuery: function (modelName, searchParams, json) {
|
925
|
+
var responseJson = {};
|
926
|
+
responseJson[modelName.pluralize()] = json;
|
927
|
+
var url = this.buildURL(modelName);
|
928
|
+
this.stubEndpointForHttpRequest(url, responseJson, {urlParams: searchParams});
|
882
929
|
},
|
883
930
|
/**
|
884
931
|
Handling ajax POST ( create record ) for a model. You can mock
|
@@ -242,25 +242,13 @@ var FactoryGuy = {
|
|
242
242
|
*/
|
243
243
|
isAttributeRelationship: function(typeName, attribute) {
|
244
244
|
if (!this.store) {
|
245
|
-
|
245
|
+
Ember.debug("FactoryGuy does not have the application's store. Use FactoryGuy.setStore(store) before making any fixtures")
|
246
246
|
// The legacy value was true.
|
247
247
|
return true;
|
248
248
|
}
|
249
249
|
var model = this.store.modelFor(typeName);
|
250
250
|
return !!model.typeForRelationship(attribute);
|
251
251
|
},
|
252
|
-
/**
|
253
|
-
Make new fixture and save to store. Proxy to store#makeFixture method
|
254
|
-
|
255
|
-
@param {String} name fixture name
|
256
|
-
@param {String} trait optional trait names ( one or more )
|
257
|
-
@param {Object} opts optional fixture options that will override default fixture values
|
258
|
-
@returns {Object|DS.Model} json or record depending on the adapter type
|
259
|
-
*/
|
260
|
-
make: function() {
|
261
|
-
Ember.assert("FactoryGuy does not have the application's store. Use FactoryGuy.setStore(store) before making any fixtures", this.store);
|
262
|
-
return this.store.makeFixture.apply(this.store,arguments);
|
263
|
-
},
|
264
252
|
/**
|
265
253
|
Used in model definitions to declare use of a sequence. For example:
|
266
254
|
|
@@ -328,7 +316,7 @@ var FactoryGuy = {
|
|
328
316
|
};
|
329
317
|
},
|
330
318
|
association: function (fixtureName, opts) {
|
331
|
-
|
319
|
+
Ember.deprecate('DEPRECATION Warning: use FactoryGuy.belongsTo instead');
|
332
320
|
return this.belongsTo(fixtureName, opts);
|
333
321
|
},
|
334
322
|
/**
|
@@ -455,7 +443,53 @@ var FactoryGuy = {
|
|
455
443
|
}
|
456
444
|
return definition.buildList(name, number, traits, opts);
|
457
445
|
},
|
446
|
+
/**
|
447
|
+
Make new fixture and save to store.
|
448
|
+
|
449
|
+
@param {String} name fixture name
|
450
|
+
@param {String} trait optional trait names ( one or more )
|
451
|
+
@param {Object} options optional fixture options that will override default fixture values
|
452
|
+
@returns {Object|DS.Model} json or record depending on the adapter type
|
453
|
+
*/
|
454
|
+
make: function() {
|
455
|
+
var store = this.store;
|
456
|
+
Ember.assert("FactoryGuy does not have the application's store. Use FactoryGuy.setStore(store) before making any fixtures", store);
|
457
|
+
|
458
|
+
var fixture = this.build.apply(this, arguments);
|
459
|
+
var name = arguments[0];
|
460
|
+
var modelName = this.lookupModelForFixtureName(name);
|
461
|
+
var modelType = store.modelFor(modelName);
|
462
|
+
|
463
|
+
if (store.usingFixtureAdapter()) {
|
464
|
+
store.setAssociationsForFixtureAdapter(modelType, modelName, fixture);
|
465
|
+
return this.pushFixture(modelType, fixture);
|
466
|
+
} else {
|
467
|
+
return store.makeModel(modelType, fixture);
|
468
|
+
}
|
469
|
+
},
|
470
|
+
/**
|
471
|
+
Make a list of Fixtures
|
458
472
|
|
473
|
+
@param {String} name name of fixture
|
474
|
+
@param {Number} number number to create
|
475
|
+
@param {String} trait optional trait names ( one or more )
|
476
|
+
@param {Object} options optional fixture options that will override default fixture values
|
477
|
+
@returns {Array} list of json fixtures or records depending on the adapter type
|
478
|
+
*/
|
479
|
+
makeList: function() {
|
480
|
+
Ember.assert("FactoryGuy does not have the application's store. Use FactoryGuy.setStore(store) before making any fixtures", this.store);
|
481
|
+
|
482
|
+
var arr = [];
|
483
|
+
var args = Array.prototype.slice.call(arguments);
|
484
|
+
Ember.assert("makeList needs at least 2 arguments, a name and a number",args.length >= 2);
|
485
|
+
var number = args.splice(1,1)[0];
|
486
|
+
Ember.assert("Second argument to makeList should be a number (of fixtures to make.)",typeof number == 'number');
|
487
|
+
|
488
|
+
for (var i = 0; i < number; i++) {
|
489
|
+
arr.push(this.make.apply(this, args));
|
490
|
+
}
|
491
|
+
return arr;
|
492
|
+
},
|
459
493
|
/**
|
460
494
|
Clear model instances from FIXTURES array, and from store cache.
|
461
495
|
Reset the id sequence for the models back to zero.
|
@@ -543,30 +577,30 @@ var FactoryGuy = {
|
|
543
577
|
return adapter instanceof DS.FixtureAdapter;
|
544
578
|
},
|
545
579
|
/**
|
546
|
-
|
547
|
-
will push to FIXTURE array, otherwise will use push method on adapter to load
|
548
|
-
the record into the store
|
549
|
-
|
550
|
-
@param {String} name fixture name
|
551
|
-
@param {String} trait optional trait names ( one or more )
|
552
|
-
@param {Object} opts optional fixture options that will override default fixture values
|
553
|
-
@returns {Object|DS.Model} json or record depending on the adapter type
|
580
|
+
Deprecated in favor of FactoryGuy.make
|
554
581
|
*/
|
555
582
|
makeFixture: function () {
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
return store.makeModel(modelType, fixture);
|
566
|
-
}
|
583
|
+
Ember.deprecate('DEPRECATION Warning: use FactoryGuy.make instead');
|
584
|
+
FactoryGuy.make.call(FactoryGuy, arguments)
|
585
|
+
},
|
586
|
+
/**
|
587
|
+
Deprecated in favor of FactoryGuy.makeList
|
588
|
+
*/
|
589
|
+
makeList: function () {
|
590
|
+
Ember.deprecate('DEPRECATION Warning: use FactoryGuy.makeList instead');
|
591
|
+
FactoryGuy.makeList.call(FactoryGuy, arguments)
|
567
592
|
},
|
593
|
+
/**
|
594
|
+
* Most of the work of making the model from the json fixture is going on here.
|
595
|
+
* @param modelType
|
596
|
+
* @param fixture
|
597
|
+
* @returns {*}
|
598
|
+
*/
|
568
599
|
makeModel: function (modelType, fixture) {
|
569
|
-
var store = this,
|
600
|
+
var store = this,
|
601
|
+
modelName = store.modelFor(modelType).typeKey,
|
602
|
+
model;
|
603
|
+
|
570
604
|
Em.run(function () {
|
571
605
|
store.findEmbeddedAssociationsForRESTAdapter(modelType, fixture);
|
572
606
|
if (fixture.type) {
|
@@ -580,22 +614,6 @@ var FactoryGuy = {
|
|
580
614
|
});
|
581
615
|
return model;
|
582
616
|
},
|
583
|
-
/**
|
584
|
-
Make a list of Fixtures
|
585
|
-
|
586
|
-
@param {String} name name of fixture
|
587
|
-
@param {Number} number number to create
|
588
|
-
@param {Object} options fixture options
|
589
|
-
@returns {Array} list of json fixtures or records depending on the adapter type
|
590
|
-
*/
|
591
|
-
makeList: function () {
|
592
|
-
var arr = [];
|
593
|
-
var number = arguments[1];
|
594
|
-
for (var i = 0; i < number; i++) {
|
595
|
-
arr.push(this.makeFixture.apply(this, arguments));
|
596
|
-
}
|
597
|
-
return arr;
|
598
|
-
},
|
599
617
|
/**
|
600
618
|
Set the hasMany and belongsTo associations for FixtureAdapter.
|
601
619
|
|
@@ -812,11 +830,10 @@ var FactoryGuyTestMixin = Em.Mixin.create({
|
|
812
830
|
return this.getStore().find(type, id);
|
813
831
|
},
|
814
832
|
/**
|
815
|
-
Make new fixture and save to store. Proxy to
|
833
|
+
Make new fixture and save to store. Proxy to FactoryGuy#make method
|
816
834
|
*/
|
817
835
|
make: function () {
|
818
|
-
|
819
|
-
return store.makeFixture.apply(store, arguments);
|
836
|
+
return FactoryGuy.make.apply(FactoryGuy, arguments);
|
820
837
|
},
|
821
838
|
getStore: function () {
|
822
839
|
return this.get('container').lookup('store:main');
|
@@ -837,6 +854,9 @@ var FactoryGuyTestMixin = Em.Mixin.create({
|
|
837
854
|
type: options.type || 'GET',
|
838
855
|
status: options.status || 200
|
839
856
|
};
|
857
|
+
if (options.urlParams) {
|
858
|
+
request.urlParams = options.urlParams;
|
859
|
+
}
|
840
860
|
if (options.data) {
|
841
861
|
request.data = options.data;
|
842
862
|
}
|
@@ -863,9 +883,8 @@ var FactoryGuyTestMixin = Em.Mixin.create({
|
|
863
883
|
@param {Object} opts optional fixture options
|
864
884
|
*/
|
865
885
|
handleFindMany: function () {
|
866
|
-
var store = this.getStore();
|
867
886
|
// make the records and load them in the store
|
868
|
-
|
887
|
+
FactoryGuy.makeList.apply(FactoryGuy, arguments);
|
869
888
|
var name = arguments[0];
|
870
889
|
var modelName = FactoryGuy.lookupModelForFixtureName(name);
|
871
890
|
var responseJson = {};
|
@@ -873,7 +892,35 @@ var FactoryGuyTestMixin = Em.Mixin.create({
|
|
873
892
|
var url = this.buildURL(modelName);
|
874
893
|
// mock the ajax call, but return nothing, since the records will be
|
875
894
|
// retrieved from the store where they were just loaded above
|
876
|
-
this.stubEndpointForHttpRequest(url, responseJson
|
895
|
+
this.stubEndpointForHttpRequest(url, responseJson);
|
896
|
+
},
|
897
|
+
/**
|
898
|
+
Handling ajax GET for finding all records for a type of model with query parameters.
|
899
|
+
|
900
|
+
```js
|
901
|
+
// First build json for the instances you want 'returned' in your query.
|
902
|
+
var usersJson = FactoryGuy.buildList('user', 2);
|
903
|
+
|
904
|
+
// Pass in the parameters you will search on ( in this case 'name' and 'age' ) as an array,
|
905
|
+
// in the second argument.
|
906
|
+
testHelper.handleFindQuery('user', ['name', 'age'], usersJson);
|
907
|
+
|
908
|
+
store.findQuery('user', {name:'Bob', age: 10}}).then(function(userInstances){
|
909
|
+
/// userInstances were created from the usersJson that you passed in
|
910
|
+
})
|
911
|
+
```
|
912
|
+
|
913
|
+
The model instances will be created from the json you have passed in.
|
914
|
+
|
915
|
+
@param {String} modelName name of the mode like 'user' for User model type
|
916
|
+
@param {String} searchParams the parameters that will be queried
|
917
|
+
@param {Object} json fixture json used to build the resulting modelType instances
|
918
|
+
*/
|
919
|
+
handleFindQuery: function (modelName, searchParams, json) {
|
920
|
+
var responseJson = {};
|
921
|
+
responseJson[modelName.pluralize()] = json;
|
922
|
+
var url = this.buildURL(modelName);
|
923
|
+
this.stubEndpointForHttpRequest(url, responseJson, {urlParams: searchParams});
|
877
924
|
},
|
878
925
|
/**
|
879
926
|
Handling ajax POST ( create record ) for a model. You can mock
|