ember-data-factory-guy 0.6.3 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -495,7 +495,7 @@ DS.Store.reopen({
495
495
 
496
496
  var model;
497
497
  Em.run(function () {
498
- store.findEmbeddedBelongsToAssociationsForRESTAdapter(modelType, fixture);
498
+ store.findEmbeddedAssociationsForRESTAdapter(modelType, fixture);
499
499
  if (fixture.type) {
500
500
  // assuming its polymorphic if there is a type attribute
501
501
  // is this too bold an assumption?
@@ -503,7 +503,7 @@ DS.Store.reopen({
503
503
  modelType = store.modelFor(modelName);
504
504
  }
505
505
  model = store.push(modelName, fixture);
506
- store.setAssociationsForRESTAdapter(modelType, modelName, model);
506
+ // store.setAssociationsForRESTAdapter(modelType, modelName, model);
507
507
  });
508
508
  return model;
509
509
  }
@@ -581,6 +581,7 @@ DS.Store.reopen({
581
581
  FactoryGuy.pushFixture(relationship.type, belongsToRecord);
582
582
  fixture[relationship.key] = belongsToRecord.id;
583
583
  }
584
+ console.log('belongsToRecord',belongsToRecord)
584
585
  var hasManyName = self.findHasManyRelationshipNameForFixtureAdapter(relationship.type, relationship.parentType);
585
586
  var belongsToFixtures = adapter.fixturesForType(relationship.type);
586
587
  var belongsTofixture = adapter.findFixtureById(belongsToFixtures, fixture[relationship.key]);
@@ -603,7 +604,7 @@ DS.Store.reopen({
603
604
  @param modelType
604
605
  @param fixture
605
606
  */
606
- findEmbeddedBelongsToAssociationsForRESTAdapter: function (modelType, fixture) {
607
+ findEmbeddedAssociationsForRESTAdapter: function (modelType, fixture) {
607
608
  var store = this;
608
609
  Ember.get(modelType, 'relationshipsByName').forEach(function (name, relationship) {
609
610
  if (relationship.kind == 'belongsTo') {
@@ -629,94 +630,6 @@ DS.Store.reopen({
629
630
  })
630
631
  },
631
632
 
632
- /**
633
- For the REST type models:
634
-
635
- For example if a user hasMany projects, then set the user
636
- on each project that the user hasMany of, so that the project
637
- now has the belongsTo user association setup. As in this scenario:
638
-
639
- ```js
640
- var project = store.makeFixture('project');
641
- var user = store.makeFixture('user', {projects: [project]});
642
- ```
643
-
644
- Or if you make a user, then a project with that user, then set the project
645
- in the users list of 'projects' it hasMany of. As in this scenario:
646
-
647
- ```js
648
- var user = store.makeFixture('user');
649
- var project = store.makeFixture('project', {user: user});
650
- ```
651
-
652
- @param {DS.Model} modelType model type like 'User'
653
- @param {String} modelName model name like 'user'
654
- @param {DS.Model} model model to check for needed association assignments
655
- */
656
- setAssociationsForRESTAdapter: function (modelType, modelName, model) {
657
- var self = this;
658
-
659
- Ember.get(modelType, 'relationshipsByName').forEach(function (name, relationship) {
660
- if (relationship.kind == 'hasMany') {
661
- var children = model.get(name) || [];
662
- children.forEach(function (child) {
663
- var belongsToName = self.findRelationshipName(
664
- 'belongsTo',
665
- child.constructor,
666
- model
667
- );
668
- var hasManyName = self.findRelationshipName(
669
- 'hasMany',
670
- child.constructor,
671
- model
672
- );
673
- var inverseName = (relationship.options && relationship.options.inverse)
674
- if (belongsToName) {
675
- child.set(belongsToName || inverseName, model);
676
- } else if (hasManyName) {
677
- relation = child.get(hasManyName || inverseName) || [];
678
- relation.pushObject(model)
679
- }
680
- })
681
- }
682
-
683
- if (relationship.kind == 'belongsTo') {
684
- var belongsToRecord = model.get(name);
685
- if (belongsToRecord) {
686
- var setAssociations = function() {
687
- var hasManyName = self.findRelationshipName(
688
- 'hasMany',
689
- belongsToRecord.constructor,
690
- model
691
- );
692
- if (hasManyName) {
693
- belongsToRecord.get(hasManyName).addObject(model);
694
- return;
695
- }
696
- var oneToOneName = self.findRelationshipName(
697
- 'belongsTo',
698
- belongsToRecord.constructor,
699
- model
700
- );
701
- // Guard against a situation where a model can belong to itself.
702
- // Do not want to set the belongsTo on this case.
703
- if (oneToOneName && !(belongsToRecord.constructor == model.constructor)) {
704
- belongsToRecord.set(oneToOneName, model);
705
- }
706
- }
707
- if (belongsToRecord.then) {
708
- belongsToRecord.then(function(record) {
709
- belongsToRecord = record;
710
- setAssociations();
711
- })
712
- } else {
713
- setAssociations();
714
- }
715
- }
716
- }
717
- })
718
- },
719
-
720
633
  findRelationshipName: function (kind, belongToModelType, childModel) {
721
634
  var relationshipName;
722
635
  Ember.get(belongToModelType, 'relationshipsByName').forEach(
@@ -761,95 +674,6 @@ DS.Store.reopen({
761
674
  }
762
675
  });
763
676
 
764
-
765
- DS.FixtureAdapter.reopen({
766
-
767
- /**
768
- Overriding createRecord to add the record created to the
769
- hashMany records for all of the records that this record belongsTo.
770
-
771
- For example:
772
-
773
- If models are defined like so:
774
-
775
- User = DS.Model.extend({
776
- projects: DS.hasMany('project')
777
- })
778
-
779
- Project = DS.Model.extend({
780
- user: DS.belongsTo('user')
781
- })
782
-
783
- and you create a project record with a user defined:
784
- store.createRecord('project', {user: user})
785
-
786
- this method will take the new project created and add it to the user's 'projects'
787
- hasMany array.
788
-
789
- And a full code example:
790
-
791
- var userJson = store.makeFixture('user');
792
-
793
- store.find('user', userJson.id).then(function(user) {
794
- store.createRecord('project', {user: user}).save()
795
- .then( function(project) {
796
- // user.get('projects.length') == 1;
797
- })
798
- })
799
-
800
- @method createRecord
801
- @param {DS.Store} store
802
- @param {subclass of DS.Model} type
803
- @param {DS.Model} record
804
- @return {Promise} promise
805
- */
806
- createRecord: function (store, type, record) {
807
- var promise = this._super(store, type, record);
808
- promise.then(function () {
809
- Em.RSVP.Promise.resolve(Ember.get(type, 'relationshipNames')).then(function (relationShips){
810
- if (relationShips.belongsTo) {
811
- relationShips.belongsTo.forEach(function (relationship) {
812
- Em.RSVP.Promise.resolve(record.get(relationship)).then(function(belongsToRecord){
813
- if (belongsToRecord) {
814
- var hasManyName = store.findRelationshipName(
815
- 'hasMany',
816
- belongsToRecord.constructor,
817
- record
818
- );
819
- if (hasManyName) {
820
- Ember.RSVP.resolve(belongsToRecord.get(hasManyName)).then (function(relationship){
821
- relationship.addObject(record);
822
- });
823
- }
824
- }
825
- });
826
- });
827
- }
828
- if (relationShips.hasMany) {
829
- relationShips.hasMany.forEach(function (relationship) {
830
- Em.RSVP.Promise.resolve(record.get(relationship)).then(function(belongsToRecord){
831
- if (belongsToRecord && belongsToRecord.get('length') > 0) {
832
- var hasManyName = store.findRelationshipName(
833
- 'hasMany',
834
- belongsToRecord.get('firstObject').constructor,
835
- record
836
- );
837
- belongsToRecord.forEach(function (child){
838
- Em.RSVP.resolve(child.get(hasManyName)).then( function(value) {
839
- value.addObjects(record);
840
- });
841
- });
842
- }
843
- });
844
- })
845
- }
846
- });
847
- });
848
-
849
- return promise;
850
- }
851
- })
852
-
853
677
  FactoryGuyTestMixin = Em.Mixin.create({
854
678
 
855
679
  // Pass in the app root, which typically is App.
@@ -976,11 +800,18 @@ FactoryGuyTestMixin = Em.Mixin.create({
976
800
  },
977
801
 
978
802
 
979
- handleSideLoadFind: function (modelName, json) {
980
- var responseJson = this.buildAjaxHttpResponse(name, opts);
981
- var id = responseJson[modelName].id
803
+ handleSideloadFind: function (modelName, json, sideload) {
804
+ var id = json.id
982
805
  var url = this.buildURL(modelName, id);
806
+ var responseJson = {};
807
+ responseJson[modelName] = json;
808
+ $.extend(responseJson, sideload)
983
809
 
810
+ this.stubEndpointForHttpRequest(
811
+ url,
812
+ responseJson,
813
+ {type: 'GET', status: (status || 200)}
814
+ )
984
815
  },
985
816
 
986
817
 
@@ -78,18 +78,19 @@
78
78
  // cache the promise so we can use it
79
79
  // when we come back and don't need to rebuild
80
80
  // the relationship.
81
- set(rel, 'promise', resolver.promise);
82
- return rel;
81
+ // set(rel, 'promise', resolver.promise);
82
+ return relationship;
83
+ // return rel;
83
84
  });
84
85
  }
85
-
86
- var promise = relationship.get('promise').then(function() {
87
- return relationship;
88
- }, null, "DS: Async hasMany records received");
89
-
90
- return DS.PromiseArray.create({
91
- promise: promise
92
- });
86
+ return relationship;
87
+ // var promise = relationship.get('promise').then(function() {
88
+ // return relationship;
89
+ // }, null, "DS: Async hasMany records received");
90
+ //
91
+ // return DS.PromiseArray.create({
92
+ // promise: promise
93
+ // });
93
94
  }
94
95
 
95
96
  return buildRelationship(this, key, options, function(store, data) {
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.6.3
4
+ version: 0.7.0
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-09-10 00:00:00.000000000 Z
12
+ date: 2014-09-15 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Easily create Fixtures for Ember Data
15
15
  email: