ember-data-factory-guy 0.8.7 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gruntfile.js +1 -1
- data/README.md +83 -68
- data/bower.json +1 -1
- data/dist/amd/factory-guy.js +75 -13
- data/dist/ember-data-factory-guy.js +75 -13
- 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 +38 -0
- data/src/factory_guy_test_mixin.js +25 -11
- data/src/model_definition.js +12 -2
- data/tests/active_model_adapter_factory_test.js +61 -52
- data/tests/factory_guy_test.js +52 -3
- data/tests/factory_guy_test_mixin_test.js +46 -11
- data/tests/rest_adapter_factory_test.js +58 -50
- data/tests/support/models/user.js +1 -0
- data/tests/support/test_helper.js +14 -0
- data/tests/test_setup.js +104 -103
- data/vendor/assets/javascripts/ember_data_factory_guy.js +78 -17
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0f49b633dc4e0517c3f1ad408bdd1db344c57a3
|
4
|
+
data.tar.gz: e4eded2ac3ad0442f84e6baef55f3f15fe465126
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 685ca7f54f663260a32f07803e616a774314917f17dd50fd8f95233b4712deaabb6dca324237ac1cd7a742fd3f4a64b1aa16d9d65ce1ca01d00097afca66bfaa
|
7
|
+
data.tar.gz: 41939f3df2b268972abfaa53f42c2eb7a6fcf73205631af9b9ea06b775d5d2dfd2d34c08da15965f893e12b315646e3016265c54f2f8f2e6e949383842e01b0c
|
data/Gruntfile.js
CHANGED
data/README.md
CHANGED
@@ -2,24 +2,22 @@
|
|
2
2
|
|
3
3
|
*NOTE*
|
4
4
|
|
5
|
-
ember-data is changing the way they are doing relationships in 1.0.0-beta.10 and above
|
6
|
-
so, if you are using ember-data-1.0.0-beta.8 and earlier, then be sure to use version 0.6.4
|
7
|
-
of ember-data-factory-guy.
|
5
|
+
ember-data is changing the way they are doing relationships in 1.0.0-beta.10 and above
|
6
|
+
so, if you are using ember-data-1.0.0-beta.8 and earlier, then be sure to use version 0.6.4
|
7
|
+
of ember-data-factory-guy.
|
8
8
|
|
9
9
|
- Versions:
|
10
10
|
- 0.6.4 -> ember-data-1.0.0-beta.8 and under
|
11
11
|
- 0.7.1.1 -> ember-data-1.0.0-beta.10
|
12
12
|
- 0.8.6 -> ember-data-1.0.0-beta.11
|
13
|
-
- 0.
|
13
|
+
- 0.9.0 -> ember-data-1.0.0-beta.12
|
14
14
|
|
15
|
-
**
|
15
|
+
**Support for fixture adapter is currently kinda broken.**
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
and fix the older version you are using.*
|
17
|
+
**Version 0.9.0 expects you to no longer use store.makeFixture explicitly in your tests
|
18
|
+
but rather use the testHelper.make from FactoryGuyTestHelperMixin instead. If this is not the case,
|
19
|
+
just add a FactoryGuy.setStore(store) somewhere in your code before you start making fixtures.**
|
21
20
|
|
22
|
-
**Version 0.8.0 introduces amd and commonjs support**
|
23
21
|
|
24
22
|
## Using with Ember Cli
|
25
23
|
- https://github.com/igorrKurr/ember-cli-factory-guy-example
|
@@ -41,7 +39,7 @@ gem 'ember-data-factory-guy', group: test
|
|
41
39
|
or for particular version:
|
42
40
|
|
43
41
|
```ruby
|
44
|
-
gem 'ember-data-factory-guy', '0.
|
42
|
+
gem 'ember-data-factory-guy', '0.9.0', group: test
|
45
43
|
```
|
46
44
|
|
47
45
|
then:
|
@@ -76,7 +74,7 @@ or for particular version:
|
|
76
74
|
"dependencies": {
|
77
75
|
"foo-dependency": "latest",
|
78
76
|
"other-foo-dependency": "latest",
|
79
|
-
"ember-data-factory-guy": "0.
|
77
|
+
"ember-data-factory-guy": "0.9.0"
|
80
78
|
}
|
81
79
|
```
|
82
80
|
|
@@ -218,28 +216,34 @@ the store is looking up the correct model type name
|
|
218
216
|
|
219
217
|
|
220
218
|
### Using Factories
|
219
|
+
- FactorGuy.setStore
|
220
|
+
- pass in the store instance to FactoryGuy before making fixtures.
|
221
221
|
- FactoryGuy.build
|
222
222
|
- Builds json
|
223
|
-
-
|
223
|
+
- FactoryGuy.make
|
224
224
|
- Loads model instance into the store
|
225
225
|
- Can override default attributes by passing in a hash
|
226
226
|
- Can add attributes with traits ( see traits section )
|
227
227
|
|
228
228
|
```javascript
|
229
|
-
|
229
|
+
// First set the store on FactoryGuy. You don't have to do this step manually if you use
|
230
|
+
// FactoryGuyTestHelperMixin since this is done for you in the setup method.
|
231
|
+
var store = this.get('container').lookup('store:main');
|
232
|
+
FactoryGuy.setStore(store);
|
233
|
+
|
230
234
|
// returns json
|
231
235
|
var json = FactoryGuy.build('user');
|
232
236
|
json // => {id: 1, name: 'Dude', style: 'normal'}
|
233
237
|
|
234
238
|
// returns a User instance that is loaded into your application's store
|
235
|
-
var user =
|
236
|
-
user.toJSON() // => {id: 2, name: 'Dude', style: 'normal'}
|
239
|
+
var user = FactoryGuy.make('user');
|
240
|
+
user.toJSON({includeId: true}) // => {id: 2, name: 'Dude', style: 'normal'}
|
237
241
|
|
238
242
|
var json = FactoryGuy.build('admin');
|
239
243
|
json // => {id: 3, name: 'Admin', style: 'super'}
|
240
244
|
|
241
|
-
var user =
|
242
|
-
user.toJSON() // => {id: 4, name: 'Admin', style: 'super'}
|
245
|
+
var user = FactoryGuy.make('admin');
|
246
|
+
user.toJSON({includeId: true}) // => {id: 4, name: 'Admin', style: 'super'}
|
243
247
|
|
244
248
|
```
|
245
249
|
|
@@ -281,7 +285,7 @@ You can override the default attributes by passing in a hash
|
|
281
285
|
var json = FactoryGuy.build('user');
|
282
286
|
json.name // => 'User1'
|
283
287
|
|
284
|
-
var user =
|
288
|
+
var user = FactoryGuy.make('user');
|
285
289
|
user.get('name') // => 'User2'
|
286
290
|
|
287
291
|
```
|
@@ -299,7 +303,7 @@ You can override the default attributes by passing in a hash
|
|
299
303
|
var json = FactoryGuy.build('special_project');
|
300
304
|
json.title // => 'Project #1'
|
301
305
|
|
302
|
-
var project =
|
306
|
+
var project = FactoryGuy.make('special_project');
|
303
307
|
project.get('title') // => 'Project #2'
|
304
308
|
|
305
309
|
```
|
@@ -324,7 +328,7 @@ You can override the default attributes by passing in a hash
|
|
324
328
|
json.name // => 'User1'
|
325
329
|
json.style // => 'funny User1'
|
326
330
|
|
327
|
-
var user =
|
331
|
+
var user = FactoryGuy.make('funny_user');
|
328
332
|
user.get('name') // => 'User2'
|
329
333
|
user.get('style') // => 'funny User2'
|
330
334
|
|
@@ -353,7 +357,7 @@ You can override the default attributes by passing in a hash
|
|
353
357
|
json.name // => 'Big Guy'
|
354
358
|
json.style // => 'Friendly'
|
355
359
|
|
356
|
-
var user =
|
360
|
+
var user = FactoryGuy.make('user', 'big', 'friendly');
|
357
361
|
user.get('name') // => 'Big Guy'
|
358
362
|
user.get('style') // => 'Friendly'
|
359
363
|
|
@@ -364,7 +368,7 @@ attributes will override any trait attributes or default attributes
|
|
364
368
|
|
365
369
|
```javascript
|
366
370
|
|
367
|
-
var user =
|
371
|
+
var user = FactoryGuy.make('user', 'big', 'friendly', {name: 'Dave'});
|
368
372
|
user.get('name') // => 'Dave'
|
369
373
|
user.get('style') // => 'Friendly'
|
370
374
|
|
@@ -391,7 +395,7 @@ attributes will override any trait attributes or default attributes
|
|
391
395
|
// create user model with default attributes
|
392
396
|
user: {}
|
393
397
|
},
|
394
|
-
|
398
|
+
project_with_bob: {
|
395
399
|
// create user model with custom attributes
|
396
400
|
user: {name: 'Bob'}
|
397
401
|
},
|
@@ -404,10 +408,10 @@ attributes will override any trait attributes or default attributes
|
|
404
408
|
var json = FactoryGuy.build('project_with_user');
|
405
409
|
json.user // => {id:1, name: 'Dude', style: 'normal'}
|
406
410
|
|
407
|
-
var json = FactoryGuy.build('
|
408
|
-
json.user // => {id:1, name: '
|
411
|
+
var json = FactoryGuy.build('project_with_bob');
|
412
|
+
json.user // => {id:1, name: 'Bob', style: 'normal'}
|
409
413
|
|
410
|
-
var project =
|
414
|
+
var project = FactoryGuy.make('project_with_admin');
|
411
415
|
project.get('user.name') // => 'Admin'
|
412
416
|
project.get('user.style') // => 'super'
|
413
417
|
|
@@ -424,8 +428,8 @@ attributes will override any trait attributes or default attributes
|
|
424
428
|
}
|
425
429
|
});
|
426
430
|
|
427
|
-
var user =
|
428
|
-
project.get('user').toJSON() // => {id:1, name: 'Dude', style: 'normal'}
|
431
|
+
var user = FactoryGuy.make('project', 'with_user');
|
432
|
+
project.get('user').toJSON({includeId: true}) // => {id:1, name: 'Dude', style: 'normal'}
|
429
433
|
|
430
434
|
```
|
431
435
|
|
@@ -433,10 +437,10 @@ attributes will override any trait attributes or default attributes
|
|
433
437
|
##### Setup belongsTo associations manually
|
434
438
|
|
435
439
|
```javascript
|
436
|
-
var user =
|
437
|
-
var project =
|
440
|
+
var user = FactoryGuy.make('user');
|
441
|
+
var project = FactoryGuy.make('project', {user: user});
|
438
442
|
|
439
|
-
project.get('user').toJSON() // => {id:1, name: 'Dude', style: 'normal'}
|
443
|
+
project.get('user').toJSON({includeId: true}) // => {id:1, name: 'Dude', style: 'normal'}
|
440
444
|
```
|
441
445
|
|
442
446
|
*Note that though you are setting the 'user' belongsTo association on a project,
|
@@ -456,7 +460,7 @@ the reverse user hasMany 'projects' association is being setup for you on the us
|
|
456
460
|
user_with_projects: { FactoryGuy.hasMany('project', 2) }
|
457
461
|
});
|
458
462
|
|
459
|
-
var user =
|
463
|
+
var user = FactoryGuy.make('user_with_projects');
|
460
464
|
user.get('projects.length') // => 2
|
461
465
|
|
462
466
|
```
|
@@ -473,7 +477,7 @@ the reverse user hasMany 'projects' association is being setup for you on the us
|
|
473
477
|
}
|
474
478
|
});
|
475
479
|
|
476
|
-
var user =
|
480
|
+
var user = FactoryGuy.make('user', 'with_projects');
|
477
481
|
user.get('projects.length') // => 2
|
478
482
|
|
479
483
|
```
|
@@ -481,14 +485,14 @@ the reverse user hasMany 'projects' association is being setup for you on the us
|
|
481
485
|
##### Setup hasMany associations manually
|
482
486
|
|
483
487
|
```javascript
|
484
|
-
var project1 =
|
485
|
-
var project2 =
|
486
|
-
var user =
|
488
|
+
var project1 = FactoryGuy.make('project');
|
489
|
+
var project2 = FactoryGuy.make('project');
|
490
|
+
var user = FactoryGuy.make('user', {projects: [project1,project2]});
|
487
491
|
user.get('projects.length') // => 2
|
488
492
|
|
489
493
|
// or
|
490
494
|
var projects = store.makeList('project', 2);
|
491
|
-
var user =
|
495
|
+
var user = FactoryGuy.make('user', {projects: projects});
|
492
496
|
user.get('projects.length') // => 2
|
493
497
|
|
494
498
|
```
|
@@ -525,8 +529,8 @@ the reverse 'user' belongsTo association is being setup for you on the project
|
|
525
529
|
```javascript
|
526
530
|
var users = store.makeList('user', 2)
|
527
531
|
users.get('length') // => 2
|
528
|
-
users[0].toJSON() // => {id: 3, name: 'User3', style: 'normal'}
|
529
|
-
users[1].toJSON() // => {id: 4, name: 'User4', style: 'normal'}
|
532
|
+
users[0].toJSON({includeId: true}) // => {id: 3, name: 'User3', style: 'normal'}
|
533
|
+
users[1].toJSON({includeId: true}) // => {id: 4, name: 'User4', style: 'normal'}
|
530
534
|
|
531
535
|
```
|
532
536
|
|
@@ -550,21 +554,23 @@ TestHelper = Ember.Object.createWithMixins(FactoryGuyTestMixin);
|
|
550
554
|
|
551
555
|
// Then in your tests you can use it like so:
|
552
556
|
|
553
|
-
var testHelper, store;
|
557
|
+
var testHelper, store, make;
|
554
558
|
|
555
559
|
module('User Model', {
|
556
560
|
setup: function() {
|
557
561
|
testHelper = TestHelper.setup(App);
|
558
562
|
store = testHelper.getStore();
|
563
|
+
// You could at this point, make fixtures with testHelper.make,
|
564
|
+
// but to be even more concise try this shortcut method to your tests
|
565
|
+
make = testHelper.make.bind(testHelper)
|
566
|
+
// or if your running in phantomjs and it does not support bind method try this:
|
567
|
+
// make = function() {return testHelper.make.apply(testHelper,arguments)}
|
559
568
|
},
|
560
569
|
teardown: function() {
|
561
570
|
Em.run(function() { testHelper.teardown(); });
|
562
571
|
}
|
563
572
|
});
|
564
573
|
|
565
|
-
// You could at this point, make fixtures with testHelper.make('user'), but
|
566
|
-
// to be even more concise in tests you could add this method to your tests
|
567
|
-
var make = function(name, opts) { return testHelper.make(name, opts); }
|
568
574
|
|
569
575
|
// assuming your default adapter is ActiveModelAdapter or RESTAdapter
|
570
576
|
test("make a user using your applications default adapter", function() {
|
@@ -685,12 +691,19 @@ match and or returns options.
|
|
685
691
|
|
686
692
|
|
687
693
|
##### handleUpdate
|
694
|
+
- handleUpdate(model)
|
695
|
+
- handleUpdate(modelType, id)
|
688
696
|
|
689
697
|
*success case is the default*
|
690
698
|
|
691
699
|
```javascript
|
692
|
-
var profile =
|
693
|
-
|
700
|
+
var profile = FactoryGuy.make('profile');
|
701
|
+
|
702
|
+
// Simplest way is to pass in the model that will be updated ( if you have it available )
|
703
|
+
testHelper.handleUpdate(profile);
|
704
|
+
|
705
|
+
// If the model is not available, pass in the modelType and the id ( if you know it )
|
706
|
+
testHelper.handleUpdate('profile', 1);
|
694
707
|
|
695
708
|
profile.set('description', 'good value');
|
696
709
|
profile.save() //=> will succeed
|
@@ -699,9 +712,12 @@ match and or returns options.
|
|
699
712
|
*mocking a failed update*
|
700
713
|
|
701
714
|
```javascript
|
702
|
-
var profile =
|
715
|
+
var profile = FactoryGuy.make('profile');
|
716
|
+
|
703
717
|
// set the succeed flag to 'false'
|
704
718
|
testHelper.handleUpdate('profile', profile.id, false);
|
719
|
+
// or
|
720
|
+
testHelper.handleUpdate(profile, false);
|
705
721
|
|
706
722
|
profile.set('description', 'bad value');
|
707
723
|
profile.save() //=> will fail
|
@@ -714,7 +730,7 @@ match and or returns options.
|
|
714
730
|
*success case is the default*
|
715
731
|
|
716
732
|
```javascript
|
717
|
-
var profile =
|
733
|
+
var profile = FactoryGuy.make('profile');
|
718
734
|
testHelper.handleDelete('profile', profile.id);
|
719
735
|
|
720
736
|
profile.destroyRecord() // => will succeed
|
@@ -723,7 +739,7 @@ match and or returns options.
|
|
723
739
|
*mocking a failed delete*
|
724
740
|
|
725
741
|
```javascript
|
726
|
-
var profile =
|
742
|
+
var profile = FactoryGuy.make('profile');
|
727
743
|
// set the succeed flag to 'false'
|
728
744
|
testHelper.handleDelete('profile', profile.id, false);
|
729
745
|
|
@@ -746,12 +762,12 @@ ViewTestHelper = Ember.Object.createWithMixins(FactoryGuyTestMixin,{
|
|
746
762
|
}
|
747
763
|
}
|
748
764
|
|
749
|
-
var viewHelper;
|
765
|
+
var viewHelper, user;
|
750
766
|
|
751
767
|
module('User View', {
|
752
768
|
setup: function() {
|
753
769
|
viewHelper = ViewTestHelper.setup(App); // set up helper
|
754
|
-
|
770
|
+
user = viewHelper.make('user'); // create a user in the store
|
755
771
|
visit('/users/'+user.id); // visit the users route
|
756
772
|
},
|
757
773
|
teardown: function() {
|
@@ -766,10 +782,9 @@ test("Creates new project", function() {
|
|
766
782
|
click('.add-div div:contains(New Project)')
|
767
783
|
fillIn('.add-project input', newProjectName)
|
768
784
|
|
769
|
-
// Remember,
|
770
|
-
//
|
771
|
-
|
772
|
-
viewHelper.handleCreate('project', {name: newProjectName})
|
785
|
+
// Remember, this is for handling an exact match, if you did not care about
|
786
|
+
// matching attributes, you could just do: viewHelper.handleCreate('project')
|
787
|
+
viewHelper.handleCreate('project', {match:{name: newProjectName, user:user}})
|
773
788
|
|
774
789
|
/**
|
775
790
|
Let's say that clicking this '.add-project .link', triggers action in the view to
|
@@ -796,9 +811,9 @@ test("Creates new project", function() {
|
|
796
811
|
### Using DS.Fixture adapter
|
797
812
|
|
798
813
|
- Not recommended
|
799
|
-
-
|
814
|
+
- FactoryGuy.make ... creates model in the store and returns json
|
800
815
|
|
801
|
-
Technically when you call
|
816
|
+
Technically when you call FactoryGuy.make with a store using the DS.FixtureAdapter,
|
802
817
|
the fixture is actually added to the models FIXTURE array. It just seems to be added
|
803
818
|
to the store because when you call store.find to get that record, the adapter looks
|
804
819
|
in that FIXTURE array to find it and then puts it in the store.
|
@@ -806,26 +821,26 @@ in that FIXTURE array to find it and then puts it in the store.
|
|
806
821
|
```javascript
|
807
822
|
|
808
823
|
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
824
|
+
FactoryGuy.make('user'); // user.FIXTURES = [{id: 1, name: 'User1', style: 'normal'}]
|
825
|
+
FactoryGuy.make('user', {name: 'bob'}); // user.FIXTURES = [{id: 2, name: 'bob', style: 'normal'}]
|
826
|
+
FactoryGuy.make('admin'); // user.FIXTURES = [{id: 3, name: 'Admin', style: 'super'}]
|
827
|
+
FactoryGuy.make('admin', {name: 'Fred'}); // user.FIXTURES = [{id: 4, name: 'Fred', style: 'super'}]
|
813
828
|
|
814
829
|
|
815
830
|
// Use store.find to get the model instance ( Remember this is the Fixture adapter, if
|
816
831
|
// you use the ActiveModelAdapter or RESTAdapter the record is returned so you don't
|
817
832
|
// have to then go and find it )
|
818
|
-
var userJson =
|
833
|
+
var userJson = FactoryGuy.make('user');
|
819
834
|
store.find('user', userJson.id).then(function(user) {
|
820
|
-
user.toJSON() ( pretty much equals ) userJson;
|
835
|
+
user.toJSON({includeId: true}) ( pretty much equals ) userJson;
|
821
836
|
});
|
822
837
|
|
823
838
|
// and to setup associations ...
|
824
|
-
var projectJson =
|
825
|
-
var userJson =
|
839
|
+
var projectJson = FactoryGuy.make('project');
|
840
|
+
var userJson = FactoryGuy.make('user', {projects: [projectJson.id]});
|
826
841
|
// OR
|
827
|
-
var userJson =
|
828
|
-
var projectJson =
|
842
|
+
var userJson = FactoryGuy.make('user');
|
843
|
+
var projectJson = FactoryGuy.make('project', {user: userJson.id});
|
829
844
|
|
830
845
|
// will give you the same result, but with fixture adapter all associations
|
831
846
|
// are treated as async ( by factory_guy_has_many.js fix ), so it's
|
@@ -833,7 +848,7 @@ var projectJson = store.makeFixture('project', {user: userJson.id});
|
|
833
848
|
// in view specs though, this clunk is dealt with for you. But remember,
|
834
849
|
// you DON'T have to use the Fixture adapter.
|
835
850
|
store.find('user', 1).then(function(user) {
|
836
|
-
user.toJSON() (pretty much equals) userJson;
|
851
|
+
user.toJSON({includeId: true}) (pretty much equals) userJson;
|
837
852
|
user.get('projects').then(function(projects) {
|
838
853
|
projects.length == 1;
|
839
854
|
});
|
data/bower.json
CHANGED
data/dist/amd/factory-guy.js
CHANGED
@@ -95,9 +95,19 @@ var ModelDefinition = function (model, config) {
|
|
95
95
|
// function might be a sequence of a named association
|
96
96
|
fixture[attribute] = fixture[attribute].call(this, fixture);
|
97
97
|
} else if (Ember.typeOf(fixture[attribute]) == 'object') {
|
98
|
-
//
|
98
|
+
// If it's an object and it's a model association attribute, build the json
|
99
99
|
// for the association and replace the attribute with that json
|
100
|
-
|
100
|
+
if (FactoryGuy.getStore()) {
|
101
|
+
if (FactoryGuy.isAttributeRelationship(this.model, attribute)) {
|
102
|
+
fixture[attribute] = FactoryGuy.build(attribute, fixture[attribute]);
|
103
|
+
}
|
104
|
+
} else {
|
105
|
+
// For legacy reasons, if the store is not set in FactoryGuy, keep
|
106
|
+
// this code the way it is ( though it will cause failures when the object is actually
|
107
|
+
// a custom attribute and not a relationship ), while users start setting the store
|
108
|
+
// in FactoryGuy, or using testHelper.make instead of store.makeFixture
|
109
|
+
fixture[attribute] = FactoryGuy.build(attribute, fixture[attribute]);
|
110
|
+
}
|
101
111
|
}
|
102
112
|
}
|
103
113
|
// set the id, unless it was already set in opts
|
@@ -218,6 +228,44 @@ var FactoryGuy = {
|
|
218
228
|
this.modelDefinitions[model] = new ModelDefinition(model, config);
|
219
229
|
}
|
220
230
|
},
|
231
|
+
/**
|
232
|
+
Setting the store so FactoryGuy can do some model introspection.
|
233
|
+
*/
|
234
|
+
setStore: function(store) {
|
235
|
+
Ember.assert("FactoryGuy#setStore needs a valid store instance.You passed in ["+store+"]",store instanceof DS.Store)
|
236
|
+
this.store = store;
|
237
|
+
},
|
238
|
+
getStore: function() {
|
239
|
+
return this.store;
|
240
|
+
},
|
241
|
+
/**
|
242
|
+
Checks a model's attribute to determine if it's a relationship.
|
243
|
+
|
244
|
+
@param {String} typeName model type name like 'user' for User model class
|
245
|
+
@param {String} attribute attribute you want to check
|
246
|
+
@returns {Boolean} true if the attribute is a relationship, false if not
|
247
|
+
*/
|
248
|
+
isAttributeRelationship: function(typeName, attribute) {
|
249
|
+
if (!this.store) {
|
250
|
+
console.log("FactoryGuy does not have the application's store. Use FactoryGuy.setStore(store) before making any fixtures")
|
251
|
+
// The legacy value was true.
|
252
|
+
return true;
|
253
|
+
}
|
254
|
+
var model = this.store.modelFor(typeName);
|
255
|
+
return !!model.typeForRelationship(attribute);
|
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
|
+
},
|
221
269
|
/**
|
222
270
|
Used in model definitions to declare use of a sequence. For example:
|
223
271
|
|
@@ -741,6 +789,7 @@ var FactoryGuyTestMixin = Em.Mixin.create({
|
|
741
789
|
// Pass in the app root, which typically is App.
|
742
790
|
setup: function (app) {
|
743
791
|
this.set('container', app.__container__);
|
792
|
+
FactoryGuy.setStore(this.getStore());
|
744
793
|
return this;
|
745
794
|
},
|
746
795
|
useFixtureAdapter: function (app) {
|
@@ -768,8 +817,7 @@ var FactoryGuyTestMixin = Em.Mixin.create({
|
|
768
817
|
return this.getStore().find(type, id);
|
769
818
|
},
|
770
819
|
/**
|
771
|
-
Proxy to store
|
772
|
-
|
820
|
+
Make new fixture and save to store. Proxy to store#makeFixture method
|
773
821
|
*/
|
774
822
|
make: function () {
|
775
823
|
var store = this.getStore();
|
@@ -778,12 +826,6 @@ var FactoryGuyTestMixin = Em.Mixin.create({
|
|
778
826
|
getStore: function () {
|
779
827
|
return this.get('container').lookup('store:main');
|
780
828
|
},
|
781
|
-
pushPayload: function (type, hash) {
|
782
|
-
return this.getStore().pushPayload(type, hash);
|
783
|
-
},
|
784
|
-
pushRecord: function (type, hash) {
|
785
|
-
return this.getStore().push(type, hash);
|
786
|
-
},
|
787
829
|
/**
|
788
830
|
Using mockjax to stub an http request.
|
789
831
|
|
@@ -860,7 +902,10 @@ var FactoryGuyTestMixin = Em.Mixin.create({
|
|
860
902
|
so you don't need to include them in the returns hash as well.
|
861
903
|
|
862
904
|
2) If you don't use match options for exact match, there will be no id returned to the model.
|
863
|
-
|
905
|
+
The reason being, that this method purposely returns an empty hash response with a 'don't match'
|
906
|
+
style handleCreate, because if the responseJson returns a non empty data hash ( with even only
|
907
|
+
the id), this essentially empty hash of attributes will override ( and nullify ) all the attributes
|
908
|
+
that set when you created the record.
|
864
909
|
3) If you match on a belongsTo association, you don't have to include that in the
|
865
910
|
returns hash.
|
866
911
|
|
@@ -913,8 +958,25 @@ var FactoryGuyTestMixin = Em.Mixin.create({
|
|
913
958
|
@param {Boolean} succeed optional flag to indicate if the request
|
914
959
|
should succeed ( default is true )
|
915
960
|
*/
|
916
|
-
handleUpdate: function (
|
917
|
-
|
961
|
+
handleUpdate: function () {
|
962
|
+
var args = Array.prototype.slice.call(arguments)
|
963
|
+
Ember.assert("To handleUpdate pass in a model instance or a type and an id", args.length>0)
|
964
|
+
var succeed = true;
|
965
|
+
if (typeof args[args.length-1] == 'boolean') {
|
966
|
+
args.pop()
|
967
|
+
succeed = false;
|
968
|
+
}
|
969
|
+
Ember.assert("To handleUpdate pass in a model instance or a type and an id",args.length>0)
|
970
|
+
var type, id;
|
971
|
+
if (args[0] instanceof DS.Model) {
|
972
|
+
var model = args[0];
|
973
|
+
type = model.constructor.typeKey;
|
974
|
+
id = model.id;
|
975
|
+
} else if (typeof args[0] == "string" && typeof parseInt(args[1]) == "number") {
|
976
|
+
type = args[0];
|
977
|
+
id = args[1];
|
978
|
+
}
|
979
|
+
Ember.assert("To handleUpdate pass in a model instance or a type and an id",type && id)
|
918
980
|
this.stubEndpointForHttpRequest(this.buildURL(type, id), {}, {
|
919
981
|
type: 'PUT',
|
920
982
|
status: succeed ? 200 : 500
|