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.
@@ -29,4 +29,15 @@ FactoryGuy.define("project", {
29
29
  // differs from the model name
30
30
  parent: FactoryGuy.belongsTo('project')
31
31
  }
32
+ });
33
+
34
+
35
+ FactoryGuy.define("sub_project", {
36
+ sequences: {
37
+ title: function (num) { return 'SubProject' + num }
38
+ },
39
+ default: {
40
+ title: FactoryGuy.generate('title'),
41
+ type: "SubProject"
42
+ }
32
43
  });
@@ -0,0 +1,12 @@
1
+ Group = DS.Model.extend({
2
+ versions: DS.hasMany('group')
3
+ })
4
+
5
+ BigGroup = Group.extend({
6
+ group: DS.belongsTo('group')
7
+ })
8
+
9
+ SmallGroup = Group.extend({
10
+ group: DS.belongsTo('group')
11
+ })
12
+
@@ -2,7 +2,8 @@ Hat = DS.Model.extend({
2
2
  type: DS.attr('string'),
3
3
  user: DS.belongsTo('user'),
4
4
  hat: DS.belongsTo('hat', {inverse: 'hats', polymorphic: true}),
5
- hats: DS.hasMany('hat', {inverse: 'hat', polymorphic: true})
5
+ hats: DS.hasMany('hat', {inverse: 'hat', polymorphic: true}),
6
+ fluffy_materials: DS.hasMany('fluffy_materials')
6
7
  });
7
8
 
8
9
  BigHat = Hat.extend({
@@ -2,3 +2,8 @@ SoftMaterial = DS.Model.extend({
2
2
  name: DS.attr('string'),
3
3
  hat: DS.belongsTo('big_hat')
4
4
  })
5
+
6
+ FluffyMaterial = DS.Model.extend({
7
+ name: DS.attr('string'),
8
+ hat: DS.belongsTo('hat', {polymorphic: true})
9
+ })
@@ -4,3 +4,8 @@ Project = DS.Model.extend({
4
4
  parent: DS.belongsTo('project', {inverse: 'children'}),
5
5
  children: DS.hasMany('project', {inverse: 'parent'})
6
6
  });
7
+
8
+
9
+
10
+
11
+
@@ -8,32 +8,262 @@ TestHelper = Ember.Object.createWithMixins(FactoryGuyTestMixin,{
8
8
  setup: function(adapter) {
9
9
  $.mockjaxSettings.logging = false;
10
10
  $.mockjaxSettings.responseTime = 0;
11
- var container = new Ember.Container();
12
- this.set('container', container);
13
-
14
- container.register("model:hat", Hat);
15
- container.register("model:small_hat", SmallHat);
16
- container.register("model:big_hat", BigHat);
17
- container.register("model:soft_material", SoftMaterial);
18
- container.register("model:user", User);
19
- container.register("model:profile", Profile);
20
- container.register("model:company", Company);
21
- container.register("model:small_company", SmallCompany);
22
- container.register("model:property", Property);
23
- container.register("model:project", Project);
24
- container.register("store:main", DS.Store.extend({adapter: adapter}));
25
- if (adapter == DS.ActiveModelAdapter) {
26
- container.register("serializer:-default", DS.ActiveModelSerializer);
27
- } else if (adapter == DS.RESTAdapter) {
28
- container.register("serializer:-default", DS.RESTSerializer);
29
- } else {
30
- container.register("serializer:-default", DS.JSONSerializer);
31
- }
32
- container.register('transform:string', DS.StringTransform);
11
+
12
+ var env = setupStore({
13
+ adapter: adapter,
14
+ hat: Hat,
15
+ small_hat: SmallHat,
16
+ big_hat: BigHat,
17
+ soft_material: SoftMaterial,
18
+ fluffy_material: FluffyMaterial,
19
+ profile: Profile,
20
+ user: User,
21
+ company: Company,
22
+ property: Property,
23
+ project: Project,
24
+ group: Group,
25
+ big_group: BigGroup,
26
+ small_group: SmallGroup
27
+ })
33
28
 
34
29
  if (adapter instanceof DS.FixtureAdapter) {
35
30
  adapter.simulateRemoteResponse = false;
36
31
  }
32
+ this.set('container', env.container);
37
33
  return this;
38
34
  }
39
- });
35
+ });
36
+
37
+
38
+ /* globals ENV, QUnit */
39
+
40
+ (function (){
41
+ window.Ember = window.Ember || {};
42
+
43
+ Ember.config = {};
44
+ Ember.testing = true;
45
+ Ember.LOG_VERSION = false;
46
+
47
+ window.ENV = { TESTING: true, LOG_VERSION: false };
48
+
49
+ var extendPrototypes = QUnit.urlParams.extendprototypes;
50
+ ENV['EXTEND_PROTOTYPES'] = !!extendPrototypes;
51
+
52
+ window.async = function(callback, timeout) {
53
+ stop();
54
+
55
+ timeout = setTimeout(function() {
56
+ start();
57
+ ok(false, "Timeout was reached");
58
+ }, timeout || 200);
59
+
60
+ return function() {
61
+ clearTimeout(timeout);
62
+
63
+ start();
64
+
65
+ var args = arguments;
66
+ return Ember.run(function() {
67
+ return callback.apply(this, args);
68
+ });
69
+ };
70
+ };
71
+
72
+ window.asyncEqual = function(a, b, message) {
73
+ Ember.RSVP.all([ Ember.RSVP.resolve(a), Ember.RSVP.resolve(b) ]).then(async(function(array) {
74
+ /*globals QUnit*/
75
+ QUnit.push(array[0] === array[1], array[0], array[1], message);
76
+ }));
77
+ };
78
+
79
+ window.invokeAsync = function(callback, timeout) {
80
+ timeout = timeout || 1;
81
+
82
+ setTimeout(async(callback, timeout+100), timeout);
83
+ };
84
+
85
+ window.setupStore = function(options) {
86
+ var env = {};
87
+ options = options || {};
88
+
89
+ var container = env.container = new Ember.Container();
90
+
91
+ var adapter = env.adapter = (options.adapter || DS.Adapter);
92
+ delete options.adapter;
93
+
94
+ for (var prop in options) {
95
+ container.register('model:' + prop, options[prop]);
96
+ }
97
+
98
+ container.register('store:main', DS.Store.extend({
99
+ adapter: adapter
100
+ }));
101
+
102
+ var serializer = DS.JSONSerializer;
103
+ if (adapter == DS.ActiveModelAdapter) {
104
+ serializer = DS.ActiveModelSerializer;
105
+ } else if (adapter == DS.RESTAdapter) {
106
+ serializer = DS.RESTSerializer;
107
+ }
108
+
109
+ container.register('serializer:-default', serializer);
110
+
111
+ container.register('transform:string', DS.StringTransform);
112
+
113
+ container.injection('serializer', 'store', 'store:main');
114
+
115
+ env.store = container.lookup('store:main');
116
+ env.adapter = env.store.get('defaultAdapter');
117
+
118
+ return env;
119
+ };
120
+
121
+ window.createStore = function(options) {
122
+ return setupStore(options).store;
123
+ };
124
+
125
+ var async = window.async = function(callback, timeout) {
126
+ stop();
127
+
128
+ timeout = setTimeout(function() {
129
+ start();
130
+ ok(false, "Timeout was reached");
131
+ }, timeout || 200);
132
+
133
+ return function() {
134
+ clearTimeout(timeout);
135
+
136
+ start();
137
+
138
+ var args = arguments;
139
+ return Ember.run(function() {
140
+ return callback.apply(this, args);
141
+ });
142
+ };
143
+ };
144
+
145
+ var syncForTest = window.syncForTest = function(fn) {
146
+ var callSuper;
147
+
148
+ if (typeof fn !== "function") { callSuper = true; }
149
+
150
+ return function() {
151
+ var override = false, ret;
152
+
153
+ if (Ember.run && !Ember.run.currentRunLoop) {
154
+ Ember.run.begin();
155
+ override = true;
156
+ }
157
+
158
+ try {
159
+ if (callSuper) {
160
+ ret = this._super.apply(this, arguments);
161
+ } else {
162
+ ret = fn.apply(this, arguments);
163
+ }
164
+ } finally {
165
+ if (override) {
166
+ Ember.run.end();
167
+ }
168
+ }
169
+
170
+ return ret;
171
+ };
172
+ };
173
+
174
+ Ember.config.overrideAccessors = function() {
175
+ Ember.set = syncForTest(Ember.set);
176
+ Ember.get = syncForTest(Ember.get);
177
+ };
178
+
179
+ Ember.config.overrideClassMixin = function(ClassMixin) {
180
+ ClassMixin.reopen({
181
+ create: syncForTest()
182
+ });
183
+ };
184
+
185
+ Ember.config.overridePrototypeMixin = function(PrototypeMixin) {
186
+ PrototypeMixin.reopen({
187
+ destroy: syncForTest()
188
+ });
189
+ };
190
+
191
+ QUnit.begin(function(){
192
+ Ember.RSVP.configure('onerror', function(reason) {
193
+ // only print error messages if they're exceptions;
194
+ // otherwise, let a future turn of the event loop
195
+ // handle the error.
196
+ if (reason && reason instanceof Error) {
197
+ Ember.Logger.log(reason, reason.stack);
198
+ throw reason;
199
+ }
200
+ });
201
+
202
+ Ember.RSVP.resolve = syncForTest(Ember.RSVP.resolve);
203
+
204
+ Ember.View.reopen({
205
+ _insertElementLater: syncForTest()
206
+ });
207
+
208
+ DS.Store.reopen({
209
+ save: syncForTest(),
210
+ createRecord: syncForTest(),
211
+ deleteRecord: syncForTest(),
212
+ push: syncForTest(),
213
+ pushMany: syncForTest(),
214
+ filter: syncForTest(),
215
+ find: syncForTest(),
216
+ findMany: syncForTest(),
217
+ findByIds: syncForTest(),
218
+ didSaveRecord: syncForTest(),
219
+ didSaveRecords: syncForTest(),
220
+ didUpdateAttribute: syncForTest(),
221
+ didUpdateAttributes: syncForTest(),
222
+ didUpdateRelationship: syncForTest(),
223
+ didUpdateRelationships: syncForTest(),
224
+ scheduleFetch: syncForTest(),
225
+ scheduleFetchMany: syncForTest()
226
+ });
227
+
228
+ DS.Model.reopen({
229
+ save: syncForTest(),
230
+ reload: syncForTest(),
231
+ deleteRecord: syncForTest(),
232
+ dataDidChange: Ember.observer(syncForTest(), 'data'),
233
+ updateRecordArraysLater: syncForTest(),
234
+ updateRecordArrays: syncForTest()
235
+ });
236
+
237
+ DS.Errors.reopen({
238
+ add: syncForTest(),
239
+ remove: syncForTest(),
240
+ clear: syncForTest()
241
+ });
242
+
243
+ DS.Relationship.prototype.addRecord = syncForTest(DS.Relationship.prototype.addRecord);
244
+ DS.Relationship.prototype.removeRecord = syncForTest(DS.Relationship.prototype.removeRecord);
245
+ DS.Relationship.prototype.removeRecordFromInverse = syncForTest(DS.Relationship.prototype.removeRecordFromInverse);
246
+ DS.Relationship.prototype.removeRecordFromOwn = syncForTest(DS.Relationship.prototype.removeRecordFromOwn);
247
+
248
+ var transforms = {
249
+ 'boolean': DS.BooleanTransform.create(),
250
+ 'date': DS.DateTransform.create(),
251
+ 'number': DS.NumberTransform.create(),
252
+ 'string': DS.StringTransform.create()
253
+ };
254
+
255
+ // Prevent all tests involving serialization to require a container
256
+ DS.JSONSerializer.reopen({
257
+ transformFor: function(attributeType) {
258
+ return this._super(attributeType, true) || transforms[attributeType];
259
+ }
260
+ });
261
+
262
+ Ember.RSVP.Promise.prototype.then = syncForTest(Ember.RSVP.Promise.prototype.then);
263
+ });
264
+
265
+ // Generate the jQuery expando on window ahead of time
266
+ // to make the QUnit global check run clean
267
+ jQuery(window).data('testing', true);
268
+
269
+ })();
data/tests/test_setup.js CHANGED
@@ -3,6 +3,35 @@ FactoryGuy.define("company", {
3
3
  name: 'Silly corp'
4
4
  }
5
5
  })
6
+ FactoryGuy.define("group", {
7
+ sequences: {
8
+ name: function(num) {return 'Group' + num}
9
+ },
10
+ default: {
11
+ type: "Group",
12
+ name: FactoryGuy.generate('name')
13
+ }
14
+ });
15
+
16
+ FactoryGuy.define("big_group", {
17
+ sequences: {
18
+ name: function(num) {return 'Big Group' + num}
19
+ },
20
+ default: {
21
+ type: "BigGroup",
22
+ name: FactoryGuy.generate('name')
23
+ }
24
+ })
25
+
26
+ FactoryGuy.define("small_group", {
27
+ sequences: {
28
+ name: function(num) {return 'Small Group' + num}
29
+ },
30
+ default: {
31
+ type: "SmallGroup",
32
+ name: FactoryGuy.generate('name')
33
+ }
34
+ })
6
35
  FactoryGuy.define('hat', {
7
36
  default: {},
8
37
  small_hat: {
@@ -20,6 +49,15 @@ FactoryGuy.define('soft_material', {
20
49
  name: 'silk'
21
50
  }
22
51
  })
52
+
53
+ FactoryGuy.define('fluffy_material', {
54
+ default: {
55
+ name: 'fluffy material'
56
+ },
57
+ silk: {
58
+ name: 'fluff'
59
+ }
60
+ })
23
61
  FactoryGuy.define('profile', {
24
62
  default: {
25
63
  description: 'Text goes here'
@@ -57,6 +95,17 @@ FactoryGuy.define("project", {
57
95
  parent: FactoryGuy.belongsTo('project')
58
96
  }
59
97
  });
98
+
99
+
100
+ FactoryGuy.define("sub_project", {
101
+ sequences: {
102
+ title: function (num) { return 'SubProject' + num }
103
+ },
104
+ default: {
105
+ title: FactoryGuy.generate('title'),
106
+ type: "SubProject"
107
+ }
108
+ });
60
109
  FactoryGuy.define('property', {
61
110
  default: {
62
111
  name: 'Silly property'
@@ -91,11 +140,25 @@ SmallCompany = Company.extend({
91
140
  projects: DS.hasMany('project', {async: true})
92
141
  });
93
142
 
143
+ Group = DS.Model.extend({
144
+ versions: DS.hasMany('group')
145
+ })
146
+
147
+ BigGroup = Group.extend({
148
+ group: DS.belongsTo('group')
149
+ })
150
+
151
+ SmallGroup = Group.extend({
152
+ group: DS.belongsTo('group')
153
+ })
154
+
155
+
94
156
  Hat = DS.Model.extend({
95
157
  type: DS.attr('string'),
96
158
  user: DS.belongsTo('user'),
97
159
  hat: DS.belongsTo('hat', {inverse: 'hats', polymorphic: true}),
98
- hats: DS.hasMany('hat', {inverse: 'hat', polymorphic: true})
160
+ hats: DS.hasMany('hat', {inverse: 'hat', polymorphic: true}),
161
+ fluffy_materials: DS.hasMany('fluffy_materials')
99
162
  });
100
163
 
101
164
  BigHat = Hat.extend({
@@ -110,6 +173,11 @@ SoftMaterial = DS.Model.extend({
110
173
  hat: DS.belongsTo('big_hat')
111
174
  })
112
175
 
176
+ FluffyMaterial = DS.Model.extend({
177
+ name: DS.attr('string'),
178
+ hat: DS.belongsTo('hat', {polymorphic: true})
179
+ })
180
+
113
181
  Profile = DS.Model.extend({
114
182
  description: DS.attr('string'),
115
183
  camelCaseDescription: DS.attr('string'),
@@ -124,6 +192,11 @@ Project = DS.Model.extend({
124
192
  children: DS.hasMany('project', {inverse: 'parent'})
125
193
  });
126
194
 
195
+
196
+
197
+
198
+
199
+
127
200
  Property = DS.Model.extend({
128
201
  name: DS.attr('string'),
129
202
  company: DS.belongsTo('company', {async: true}),