ember-data-factory-guy 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -9
- data/bower.json +1 -1
- data/dist/ember-data-factory-guy.js +65 -12
- data/dist/ember-data-factory-guy.min.js +1 -1
- data/dist/factory_guy_has_many.js +7 -7
- data/ember-data-factory-guy.gemspec +1 -1
- data/package.json +1 -1
- data/src/has_many.js +7 -7
- data/src/store.js +65 -12
- data/tests/active_model_adapter_factory_test.js +52 -37
- data/tests/factory_guy_test_mixin_test.js +9 -15
- data/tests/fixture_adapter_factory_test.js +11 -8
- data/tests/index.html +4 -3
- data/tests/rest_adapter_factory_test.js +63 -47
- data/tests/store_test.js +8 -11
- data/tests/support/factories/group_factory.js +29 -0
- data/tests/support/factories/material_factory.js +9 -0
- data/tests/support/factories/project_factory.js +11 -0
- data/tests/support/models/group.js +12 -0
- data/tests/support/models/hat.js +2 -1
- data/tests/support/models/material.js +5 -0
- data/tests/support/models/project.js +5 -0
- data/tests/support/test_helper.js +253 -23
- data/tests/test_setup.js +74 -1
- data/vendor/assets/javascripts/ember_data_factory_guy.js +65 -13
- data/vendor/assets/javascripts/factory_guy_has_many.js +7 -7
- metadata +8 -6
@@ -503,7 +503,7 @@ DS.Store.reopen({
|
|
503
503
|
modelType = store.modelFor(modelName);
|
504
504
|
}
|
505
505
|
model = store.push(modelName, fixture);
|
506
|
-
|
506
|
+
store.setAssociationsForRESTAdapter(modelType, modelName, model);
|
507
507
|
});
|
508
508
|
return model;
|
509
509
|
}
|
@@ -551,14 +551,14 @@ DS.Store.reopen({
|
|
551
551
|
@param {String} modelName model name like 'user'
|
552
552
|
@param {Object} fixture to check for needed association assignments
|
553
553
|
*/
|
554
|
-
setAssociationsForFixtureAdapter: function(modelType, modelName, fixture) {
|
554
|
+
setAssociationsForFixtureAdapter: function (modelType, modelName, fixture) {
|
555
555
|
var self = this;
|
556
556
|
var adapter = this.adapterFor('application');
|
557
557
|
Ember.get(modelType, 'relationshipsByName').forEach(function (name, relationship) {
|
558
558
|
if (relationship.kind == 'hasMany') {
|
559
559
|
var hasManyRelation = fixture[relationship.key];
|
560
560
|
if (hasManyRelation) {
|
561
|
-
$.each(fixture[relationship.key], function(index,object) {
|
561
|
+
$.each(fixture[relationship.key], function (index, object) {
|
562
562
|
// used to require that the relationship was set by id,
|
563
563
|
// but now, you can set it as the json object, and this will
|
564
564
|
// normalize that back to the id
|
@@ -581,7 +581,6 @@ DS.Store.reopen({
|
|
581
581
|
FactoryGuy.pushFixture(relationship.type, belongsToRecord);
|
582
582
|
fixture[relationship.key] = belongsToRecord.id;
|
583
583
|
}
|
584
|
-
console.log('belongsToRecord',belongsToRecord)
|
585
584
|
var hasManyName = self.findHasManyRelationshipNameForFixtureAdapter(relationship.type, relationship.parentType);
|
586
585
|
var belongsToFixtures = adapter.fixturesForType(relationship.type);
|
587
586
|
var belongsTofixture = adapter.findFixtureById(belongsToFixtures, fixture[relationship.key]);
|
@@ -598,8 +597,8 @@ DS.Store.reopen({
|
|
598
597
|
Before pushing the fixture to the store, do some preprocessing.
|
599
598
|
|
600
599
|
If its a belongs to association, and the fixture has an object there,
|
601
|
-
|
602
|
-
|
600
|
+
then push that model to the store and set the id of that new model
|
601
|
+
as the attribute value in the fixture
|
603
602
|
|
604
603
|
@param modelType
|
605
604
|
@param fixture
|
@@ -618,18 +617,71 @@ DS.Store.reopen({
|
|
618
617
|
var hasManyRecords = fixture[relationship.key];
|
619
618
|
// if the records are objects and not instances they need to be converted to
|
620
619
|
// instances
|
621
|
-
if (Ember.typeOf(hasManyRecords) == 'array'
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
620
|
+
if (Ember.typeOf(hasManyRecords) == 'array') {
|
621
|
+
if (Ember.typeOf(hasManyRecords[0]) == 'object') {
|
622
|
+
var records = Em.A()
|
623
|
+
hasManyRecords.map(function (object) {
|
624
|
+
var record = store.push(relationship.type, object);
|
625
|
+
records.push(record);
|
626
|
+
return record;
|
627
|
+
})
|
628
|
+
fixture[relationship.key] = records;
|
629
|
+
}
|
628
630
|
}
|
629
631
|
}
|
630
632
|
})
|
631
633
|
},
|
632
634
|
|
635
|
+
/**
|
636
|
+
For the REST type models:
|
637
|
+
|
638
|
+
For example if a user hasMany projects, then set the user
|
639
|
+
on each project that the user hasMany of, so that the project
|
640
|
+
now has the belongsTo user association setup. As in this scenario:
|
641
|
+
|
642
|
+
```js
|
643
|
+
var project = store.makeFixture('project');
|
644
|
+
var user = store.makeFixture('user', {projects: [project]});
|
645
|
+
```
|
646
|
+
|
647
|
+
Or if you make a user, then a project with that user, then set the project
|
648
|
+
in the users list of 'projects' it hasMany of. As in this scenario:
|
649
|
+
|
650
|
+
```js
|
651
|
+
var user = store.makeFixture('user');
|
652
|
+
var project = store.makeFixture('project', {user: user});
|
653
|
+
```
|
654
|
+
|
655
|
+
NOTE:
|
656
|
+
As of ember-data-1.0.0-beta.10, this method is only needed because the belongsTo
|
657
|
+
is not assigned when there is a self referential polymorphic has many association.
|
658
|
+
|
659
|
+
@param {DS.Model} modelType model type like 'User'
|
660
|
+
@param {String} modelName model name like 'user'
|
661
|
+
@param {DS.Model} model model to check for needed association assignments
|
662
|
+
*/
|
663
|
+
setAssociationsForRESTAdapter: function (modelType, modelName, model) {
|
664
|
+
var self = this;
|
665
|
+
Ember.get(modelType, 'relationshipsByName').forEach(function (name, relationship) {
|
666
|
+
if (relationship.kind == 'hasMany') {
|
667
|
+
var children = model.get(name) || [];
|
668
|
+
children.forEach(function (child) {
|
669
|
+
var belongsToName = self.findRelationshipName(
|
670
|
+
'belongsTo',
|
671
|
+
child.constructor,
|
672
|
+
model
|
673
|
+
);
|
674
|
+
var inverseName = (relationship.options && relationship.options.inverse)
|
675
|
+
if (belongsToName || inverseName) {
|
676
|
+
child.set(belongsToName || inverseName, model);
|
677
|
+
}
|
678
|
+
})
|
679
|
+
}
|
680
|
+
|
681
|
+
})
|
682
|
+
},
|
683
|
+
|
684
|
+
|
633
685
|
findRelationshipName: function (kind, belongToModelType, childModel) {
|
634
686
|
var relationshipName;
|
635
687
|
Ember.get(belongToModelType, 'relationshipsByName').forEach(
|
@@ -179,11 +179,11 @@
|
|
179
179
|
@param {Object} options a hash of options
|
180
180
|
@return {Ember.computed} relationship
|
181
181
|
*/
|
182
|
-
DS.hasMany = function(type, options) {
|
183
|
-
if (typeof type === 'object') {
|
184
|
-
options = type;
|
185
|
-
type = undefined;
|
186
|
-
}
|
187
|
-
return hasRelationship(type, options);
|
188
|
-
}
|
182
|
+
// DS.hasMany = function(type, options) {
|
183
|
+
// if (typeof type === 'object') {
|
184
|
+
// options = type;
|
185
|
+
// type = undefined;
|
186
|
+
// }
|
187
|
+
// return hasRelationship(type, options);
|
188
|
+
// }
|
189
189
|
}).call();
|
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.7.
|
4
|
+
version: 0.7.1
|
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: 2014-
|
12
|
+
date: 2014-10-04 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Easily create Fixtures for Ember Data
|
15
15
|
email:
|
@@ -19,8 +19,8 @@ executables: []
|
|
19
19
|
extensions: []
|
20
20
|
extra_rdoc_files: []
|
21
21
|
files:
|
22
|
-
- .gitignore
|
23
|
-
- .travis.yml
|
22
|
+
- ".gitignore"
|
23
|
+
- ".travis.yml"
|
24
24
|
- Gruntfile.js
|
25
25
|
- LICENSE
|
26
26
|
- README.md
|
@@ -45,6 +45,7 @@ files:
|
|
45
45
|
- tests/rest_adapter_factory_test.js
|
46
46
|
- tests/store_test.js
|
47
47
|
- tests/support/factories/company_factory.js
|
48
|
+
- tests/support/factories/group_factory.js
|
48
49
|
- tests/support/factories/hat_factory.js
|
49
50
|
- tests/support/factories/material_factory.js
|
50
51
|
- tests/support/factories/profile_factory.js
|
@@ -54,6 +55,7 @@ files:
|
|
54
55
|
- tests/support/libs/mockjax.js
|
55
56
|
- tests/support/libs/sinon.js
|
56
57
|
- tests/support/models/company.js
|
58
|
+
- tests/support/models/group.js
|
57
59
|
- tests/support/models/hat.js
|
58
60
|
- tests/support/models/material.js
|
59
61
|
- tests/support/models/profile.js
|
@@ -74,12 +76,12 @@ require_paths:
|
|
74
76
|
- lib
|
75
77
|
required_ruby_version: !ruby/object:Gem::Requirement
|
76
78
|
requirements:
|
77
|
-
- -
|
79
|
+
- - ">="
|
78
80
|
- !ruby/object:Gem::Version
|
79
81
|
version: '0'
|
80
82
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
83
|
requirements:
|
82
|
-
- -
|
84
|
+
- - ">="
|
83
85
|
- !ruby/object:Gem::Version
|
84
86
|
version: 1.3.6
|
85
87
|
requirements: []
|