ember-data-factory-guy 0.7.3 → 0.7.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gruntfile.js +4 -2
- data/README.md +59 -12
- data/bower.json +3 -2
- data/dist/ember-data-factory-guy.js +826 -97
- 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 +11 -10
- data/src/factory_guy_test_mixin.js +91 -62
- data/src/store.js +33 -26
- data/tests/active_model_adapter_factory_test.js +38 -54
- data/tests/factory_guy_test.js +4 -4
- data/tests/factory_guy_test_mixin_test.js +217 -22
- data/tests/index.html +4 -4
- data/tests/rest_adapter_factory_test.js +38 -39
- data/tests/support/factories/hat_factory.js +8 -0
- data/tests/support/factories/outfit_factory.js +8 -0
- data/tests/support/factories/profile_factory.js +5 -0
- data/tests/support/factories/project_factory.js +2 -0
- data/tests/support/factories/user_factory.js +43 -29
- data/tests/support/models/hat.js +1 -0
- data/tests/support/models/outfit.js +4 -0
- data/tests/support/models/user.js +1 -0
- data/tests/support/test_helper.js +4 -192
- data/tests/test_setup.js +74 -29
- data/vendor/assets/javascripts/ember_data_factory_guy.js +826 -97
- metadata +4 -2
@@ -1,7 +1,10 @@
|
|
1
1
|
FactoryGuy.define('user', {
|
2
|
+
sequences: {
|
3
|
+
name: function(num) {return 'User' + num}
|
4
|
+
},
|
2
5
|
// default values for 'user' attributes
|
3
6
|
default: {
|
4
|
-
name: '
|
7
|
+
name: FactoryGuy.generate('name')
|
5
8
|
},
|
6
9
|
// named 'user' type with custom attributes
|
7
10
|
admin: {
|
@@ -16,36 +19,47 @@ FactoryGuy.define('user', {
|
|
16
19
|
},
|
17
20
|
with_hats: {
|
18
21
|
hats: FactoryGuy.hasMany('big_hat', 2)
|
22
|
+
},
|
23
|
+
with_hats_belonging_to_user: {
|
24
|
+
hats: FactoryGuy.hasMany('big_hat', 2, 'belonging_to_user')
|
25
|
+
},
|
26
|
+
with_hats_belonging_to_outfit: {
|
27
|
+
hats: FactoryGuy.hasMany('big_hat', 2, 'belonging_to_outfit')
|
19
28
|
}
|
20
29
|
}
|
21
30
|
});
|
22
31
|
|
32
|
+
Progress = DS.Model.extend({});
|
33
|
+
Unit = DS.Model.extend({
|
34
|
+
lesson: DS.belongsTo('lesson')
|
35
|
+
})
|
36
|
+
|
37
|
+
Lesson = DS.Model.extend({
|
38
|
+
steps: DS.hasMany('step'),
|
39
|
+
progress: DS.belongsTo('progress')
|
40
|
+
})
|
23
41
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
//
|
49
|
-
//FactoryGuy.define('step', {
|
50
|
-
// default: {}
|
51
|
-
//})
|
42
|
+
Step = DS.Model.extend({
|
43
|
+
progress: DS.belongsTo('progress')
|
44
|
+
})
|
45
|
+
|
46
|
+
|
47
|
+
FactoryGuy.define( 'progress', {
|
48
|
+
default: {}
|
49
|
+
});
|
50
|
+
FactoryGuy.define( 'step', {
|
51
|
+
default: {
|
52
|
+
progress: FactoryGuy.belongsTo('progress')
|
53
|
+
}
|
54
|
+
});
|
55
|
+
FactoryGuy.define( 'lesson', {
|
56
|
+
default: {
|
57
|
+
steps: FactoryGuy.hasMany('step', 2),
|
58
|
+
progress: FactoryGuy.belongsTo('progress')
|
59
|
+
}
|
60
|
+
});
|
61
|
+
FactoryGuy.define( 'unit', {
|
62
|
+
default: {
|
63
|
+
lesson: FactoryGuy.belongsTo('lesson')
|
64
|
+
}
|
65
|
+
});
|
data/tests/support/models/hat.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
Hat = DS.Model.extend({
|
2
2
|
type: DS.attr('string'),
|
3
3
|
user: DS.belongsTo('user'),
|
4
|
+
outfit: DS.belongsTo('outfit'),
|
4
5
|
hat: DS.belongsTo('hat', {inverse: 'hats', polymorphic: true}),
|
5
6
|
hats: DS.hasMany('hat', {inverse: 'hat', polymorphic: true}),
|
6
7
|
fluffy_materials: DS.hasMany('fluffy_materials')
|
@@ -15,7 +15,9 @@ TestHelper = Ember.Object.createWithMixins(FactoryGuyTestMixin,{
|
|
15
15
|
small_hat: SmallHat,
|
16
16
|
big_hat: BigHat,
|
17
17
|
soft_material: SoftMaterial,
|
18
|
+
softMaterial: SoftMaterial,
|
18
19
|
fluffy_material: FluffyMaterial,
|
20
|
+
fluffyMaterial: FluffyMaterial,
|
19
21
|
profile: Profile,
|
20
22
|
user: User,
|
21
23
|
company: Company,
|
@@ -24,7 +26,8 @@ TestHelper = Ember.Object.createWithMixins(FactoryGuyTestMixin,{
|
|
24
26
|
project: Project,
|
25
27
|
group: Group,
|
26
28
|
big_group: BigGroup,
|
27
|
-
small_group: SmallGroup
|
29
|
+
small_group: SmallGroup,
|
30
|
+
outfit: Outfit
|
28
31
|
})
|
29
32
|
|
30
33
|
if (adapter instanceof DS.FixtureAdapter) {
|
@@ -36,52 +39,7 @@ TestHelper = Ember.Object.createWithMixins(FactoryGuyTestMixin,{
|
|
36
39
|
});
|
37
40
|
|
38
41
|
|
39
|
-
/* globals ENV, QUnit */
|
40
|
-
|
41
42
|
(function (){
|
42
|
-
window.Ember = window.Ember || {};
|
43
|
-
|
44
|
-
Ember.config = {};
|
45
|
-
Ember.testing = true;
|
46
|
-
Ember.LOG_VERSION = false;
|
47
|
-
|
48
|
-
window.ENV = { TESTING: true, LOG_VERSION: false };
|
49
|
-
|
50
|
-
var extendPrototypes = QUnit.urlParams.extendprototypes;
|
51
|
-
ENV['EXTEND_PROTOTYPES'] = !!extendPrototypes;
|
52
|
-
|
53
|
-
window.async = function(callback, timeout) {
|
54
|
-
stop();
|
55
|
-
|
56
|
-
timeout = setTimeout(function() {
|
57
|
-
start();
|
58
|
-
ok(false, "Timeout was reached");
|
59
|
-
}, timeout || 200);
|
60
|
-
|
61
|
-
return function() {
|
62
|
-
clearTimeout(timeout);
|
63
|
-
|
64
|
-
start();
|
65
|
-
|
66
|
-
var args = arguments;
|
67
|
-
return Ember.run(function() {
|
68
|
-
return callback.apply(this, args);
|
69
|
-
});
|
70
|
-
};
|
71
|
-
};
|
72
|
-
|
73
|
-
window.asyncEqual = function(a, b, message) {
|
74
|
-
Ember.RSVP.all([ Ember.RSVP.resolve(a), Ember.RSVP.resolve(b) ]).then(async(function(array) {
|
75
|
-
/*globals QUnit*/
|
76
|
-
QUnit.push(array[0] === array[1], array[0], array[1], message);
|
77
|
-
}));
|
78
|
-
};
|
79
|
-
|
80
|
-
window.invokeAsync = function(callback, timeout) {
|
81
|
-
timeout = timeout || 1;
|
82
|
-
|
83
|
-
setTimeout(async(callback, timeout+100), timeout);
|
84
|
-
};
|
85
43
|
|
86
44
|
window.setupStore = function(options) {
|
87
45
|
var env = {};
|
@@ -108,9 +66,7 @@ TestHelper = Ember.Object.createWithMixins(FactoryGuyTestMixin,{
|
|
108
66
|
}
|
109
67
|
|
110
68
|
container.register('serializer:-default', serializer);
|
111
|
-
|
112
69
|
container.register('transform:string', DS.StringTransform);
|
113
|
-
|
114
70
|
container.injection('serializer', 'store', 'store:main');
|
115
71
|
|
116
72
|
env.store = container.lookup('store:main');
|
@@ -123,148 +79,4 @@ TestHelper = Ember.Object.createWithMixins(FactoryGuyTestMixin,{
|
|
123
79
|
return setupStore(options).store;
|
124
80
|
};
|
125
81
|
|
126
|
-
var async = window.async = function(callback, timeout) {
|
127
|
-
stop();
|
128
|
-
|
129
|
-
timeout = setTimeout(function() {
|
130
|
-
start();
|
131
|
-
ok(false, "Timeout was reached");
|
132
|
-
}, timeout || 200);
|
133
|
-
|
134
|
-
return function() {
|
135
|
-
clearTimeout(timeout);
|
136
|
-
|
137
|
-
start();
|
138
|
-
|
139
|
-
var args = arguments;
|
140
|
-
return Ember.run(function() {
|
141
|
-
return callback.apply(this, args);
|
142
|
-
});
|
143
|
-
};
|
144
|
-
};
|
145
|
-
|
146
|
-
var syncForTest = window.syncForTest = function(fn) {
|
147
|
-
var callSuper;
|
148
|
-
|
149
|
-
if (typeof fn !== "function") { callSuper = true; }
|
150
|
-
|
151
|
-
return function() {
|
152
|
-
var override = false, ret;
|
153
|
-
|
154
|
-
if (Ember.run && !Ember.run.currentRunLoop) {
|
155
|
-
Ember.run.begin();
|
156
|
-
override = true;
|
157
|
-
}
|
158
|
-
|
159
|
-
try {
|
160
|
-
if (callSuper) {
|
161
|
-
ret = this._super.apply(this, arguments);
|
162
|
-
} else {
|
163
|
-
ret = fn.apply(this, arguments);
|
164
|
-
}
|
165
|
-
} finally {
|
166
|
-
if (override) {
|
167
|
-
Ember.run.end();
|
168
|
-
}
|
169
|
-
}
|
170
|
-
|
171
|
-
return ret;
|
172
|
-
};
|
173
|
-
};
|
174
|
-
|
175
|
-
Ember.config.overrideAccessors = function() {
|
176
|
-
Ember.set = syncForTest(Ember.set);
|
177
|
-
Ember.get = syncForTest(Ember.get);
|
178
|
-
};
|
179
|
-
|
180
|
-
Ember.config.overrideClassMixin = function(ClassMixin) {
|
181
|
-
ClassMixin.reopen({
|
182
|
-
create: syncForTest()
|
183
|
-
});
|
184
|
-
};
|
185
|
-
|
186
|
-
Ember.config.overridePrototypeMixin = function(PrototypeMixin) {
|
187
|
-
PrototypeMixin.reopen({
|
188
|
-
destroy: syncForTest()
|
189
|
-
});
|
190
|
-
};
|
191
|
-
|
192
|
-
QUnit.begin(function(){
|
193
|
-
Ember.RSVP.configure('onerror', function(reason) {
|
194
|
-
// only print error messages if they're exceptions;
|
195
|
-
// otherwise, let a future turn of the event loop
|
196
|
-
// handle the error.
|
197
|
-
if (reason && reason instanceof Error) {
|
198
|
-
Ember.Logger.log(reason, reason.stack);
|
199
|
-
throw reason;
|
200
|
-
}
|
201
|
-
});
|
202
|
-
|
203
|
-
Ember.RSVP.resolve = syncForTest(Ember.RSVP.resolve);
|
204
|
-
|
205
|
-
Ember.View.reopen({
|
206
|
-
_insertElementLater: syncForTest()
|
207
|
-
});
|
208
|
-
|
209
|
-
DS.Store.reopen({
|
210
|
-
save: syncForTest(),
|
211
|
-
createRecord: syncForTest(),
|
212
|
-
deleteRecord: syncForTest(),
|
213
|
-
push: syncForTest(),
|
214
|
-
pushMany: syncForTest(),
|
215
|
-
filter: syncForTest(),
|
216
|
-
find: syncForTest(),
|
217
|
-
findMany: syncForTest(),
|
218
|
-
findByIds: syncForTest(),
|
219
|
-
didSaveRecord: syncForTest(),
|
220
|
-
didSaveRecords: syncForTest(),
|
221
|
-
didUpdateAttribute: syncForTest(),
|
222
|
-
didUpdateAttributes: syncForTest(),
|
223
|
-
didUpdateRelationship: syncForTest(),
|
224
|
-
didUpdateRelationships: syncForTest(),
|
225
|
-
scheduleFetch: syncForTest(),
|
226
|
-
scheduleFetchMany: syncForTest()
|
227
|
-
});
|
228
|
-
|
229
|
-
DS.Model.reopen({
|
230
|
-
save: syncForTest(),
|
231
|
-
reload: syncForTest(),
|
232
|
-
deleteRecord: syncForTest(),
|
233
|
-
dataDidChange: Ember.observer(syncForTest(), 'data'),
|
234
|
-
updateRecordArraysLater: syncForTest(),
|
235
|
-
updateRecordArrays: syncForTest()
|
236
|
-
});
|
237
|
-
|
238
|
-
DS.Errors.reopen({
|
239
|
-
add: syncForTest(),
|
240
|
-
remove: syncForTest(),
|
241
|
-
clear: syncForTest()
|
242
|
-
});
|
243
|
-
|
244
|
-
DS.Relationship.prototype.addRecord = syncForTest(DS.Relationship.prototype.addRecord);
|
245
|
-
DS.Relationship.prototype.removeRecord = syncForTest(DS.Relationship.prototype.removeRecord);
|
246
|
-
DS.Relationship.prototype.removeRecordFromInverse = syncForTest(DS.Relationship.prototype.removeRecordFromInverse);
|
247
|
-
DS.Relationship.prototype.removeRecordFromOwn = syncForTest(DS.Relationship.prototype.removeRecordFromOwn);
|
248
|
-
|
249
|
-
var transforms = {
|
250
|
-
'boolean': DS.BooleanTransform.create(),
|
251
|
-
'date': DS.DateTransform.create(),
|
252
|
-
'number': DS.NumberTransform.create(),
|
253
|
-
'string': DS.StringTransform.create()
|
254
|
-
};
|
255
|
-
|
256
|
-
// Prevent all tests involving serialization to require a container
|
257
|
-
DS.JSONSerializer.reopen({
|
258
|
-
transformFor: function(attributeType) {
|
259
|
-
return this._super(attributeType, true) || transforms[attributeType];
|
260
|
-
}
|
261
|
-
});
|
262
|
-
|
263
|
-
Ember.RSVP.Promise.prototype.then = syncForTest(Ember.RSVP.Promise.prototype.then);
|
264
|
-
});
|
265
|
-
|
266
|
-
// Generate the jQuery expando on window ahead of time
|
267
|
-
// to make the QUnit global check run clean
|
268
|
-
jQuery(window).data('testing', true);
|
269
|
-
|
270
82
|
})();
|
data/tests/test_setup.js
CHANGED
@@ -52,6 +52,14 @@ FactoryGuy.define('hat', {
|
|
52
52
|
},
|
53
53
|
big_hat: {
|
54
54
|
type: 'BigHat'
|
55
|
+
},
|
56
|
+
traits: {
|
57
|
+
belonging_to_user: {
|
58
|
+
user: FactoryGuy.belongsTo('user')
|
59
|
+
},
|
60
|
+
belonging_to_outfit: {
|
61
|
+
outfit: FactoryGuy.belongsTo('outfit')
|
62
|
+
}
|
55
63
|
}
|
56
64
|
})
|
57
65
|
FactoryGuy.define('soft_material', {
|
@@ -71,9 +79,23 @@ FactoryGuy.define('fluffy_material', {
|
|
71
79
|
name: 'fluff'
|
72
80
|
}
|
73
81
|
})
|
82
|
+
FactoryGuy.define("outfit", {
|
83
|
+
sequences: {
|
84
|
+
name: function(num) {return 'Outfit' + num}
|
85
|
+
},
|
86
|
+
default: {
|
87
|
+
name: FactoryGuy.generate('name')
|
88
|
+
}
|
89
|
+
});
|
90
|
+
|
74
91
|
FactoryGuy.define('profile', {
|
75
92
|
default: {
|
76
93
|
description: 'Text goes here'
|
94
|
+
},
|
95
|
+
traits: {
|
96
|
+
goofy_description: {
|
97
|
+
description: 'goofy'
|
98
|
+
}
|
77
99
|
}
|
78
100
|
})
|
79
101
|
FactoryGuy.define("project", {
|
@@ -85,6 +107,8 @@ FactoryGuy.define("project", {
|
|
85
107
|
with_title_sequence: { title: FactoryGuy.generate('title') },
|
86
108
|
with_user: { user: {} },
|
87
109
|
with_user_having_hats: { user: FactoryGuy.belongsTo('user', 'with_hats') },
|
110
|
+
with_user_having_hats_belonging_to_user: { user: FactoryGuy.belongsTo('user', 'with_hats_belonging_to_user') },
|
111
|
+
with_user_having_hats_belonging_to_outfit: { user: FactoryGuy.belongsTo('user', 'with_hats_belonging_to_outfit') },
|
88
112
|
with_dude: { user: {name: 'Dude'} },
|
89
113
|
with_admin: { user: FactoryGuy.belongsTo('admin') }
|
90
114
|
},
|
@@ -126,9 +150,12 @@ FactoryGuy.define('property', {
|
|
126
150
|
}
|
127
151
|
})
|
128
152
|
FactoryGuy.define('user', {
|
153
|
+
sequences: {
|
154
|
+
name: function(num) {return 'User' + num}
|
155
|
+
},
|
129
156
|
// default values for 'user' attributes
|
130
157
|
default: {
|
131
|
-
name: '
|
158
|
+
name: FactoryGuy.generate('name')
|
132
159
|
},
|
133
160
|
// named 'user' type with custom attributes
|
134
161
|
admin: {
|
@@ -143,39 +170,50 @@ FactoryGuy.define('user', {
|
|
143
170
|
},
|
144
171
|
with_hats: {
|
145
172
|
hats: FactoryGuy.hasMany('big_hat', 2)
|
173
|
+
},
|
174
|
+
with_hats_belonging_to_user: {
|
175
|
+
hats: FactoryGuy.hasMany('big_hat', 2, 'belonging_to_user')
|
176
|
+
},
|
177
|
+
with_hats_belonging_to_outfit: {
|
178
|
+
hats: FactoryGuy.hasMany('big_hat', 2, 'belonging_to_outfit')
|
146
179
|
}
|
147
180
|
}
|
148
181
|
});
|
149
182
|
|
183
|
+
Progress = DS.Model.extend({});
|
184
|
+
Unit = DS.Model.extend({
|
185
|
+
lesson: DS.belongsTo('lesson')
|
186
|
+
})
|
150
187
|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
188
|
+
Lesson = DS.Model.extend({
|
189
|
+
steps: DS.hasMany('step'),
|
190
|
+
progress: DS.belongsTo('progress')
|
191
|
+
})
|
192
|
+
|
193
|
+
Step = DS.Model.extend({
|
194
|
+
progress: DS.belongsTo('progress')
|
195
|
+
})
|
196
|
+
|
197
|
+
|
198
|
+
FactoryGuy.define( 'progress', {
|
199
|
+
default: {}
|
200
|
+
});
|
201
|
+
FactoryGuy.define( 'step', {
|
202
|
+
default: {
|
203
|
+
progress: FactoryGuy.belongsTo('progress')
|
204
|
+
}
|
205
|
+
});
|
206
|
+
FactoryGuy.define( 'lesson', {
|
207
|
+
default: {
|
208
|
+
steps: FactoryGuy.hasMany('step', 2),
|
209
|
+
progress: FactoryGuy.belongsTo('progress')
|
210
|
+
}
|
211
|
+
});
|
212
|
+
FactoryGuy.define( 'unit', {
|
213
|
+
default: {
|
214
|
+
lesson: FactoryGuy.belongsTo('lesson')
|
215
|
+
}
|
216
|
+
});
|
179
217
|
|
180
218
|
Company = DS.Model.extend({
|
181
219
|
name: DS.attr('string'),
|
@@ -205,6 +243,7 @@ SmallGroup = Group.extend({
|
|
205
243
|
Hat = DS.Model.extend({
|
206
244
|
type: DS.attr('string'),
|
207
245
|
user: DS.belongsTo('user'),
|
246
|
+
outfit: DS.belongsTo('outfit'),
|
208
247
|
hat: DS.belongsTo('hat', {inverse: 'hats', polymorphic: true}),
|
209
248
|
hats: DS.hasMany('hat', {inverse: 'hat', polymorphic: true}),
|
210
249
|
fluffy_materials: DS.hasMany('fluffy_materials')
|
@@ -227,6 +266,11 @@ FluffyMaterial = DS.Model.extend({
|
|
227
266
|
hat: DS.belongsTo('hat', {polymorphic: true})
|
228
267
|
})
|
229
268
|
|
269
|
+
Outfit = DS.Model.extend({
|
270
|
+
name: DS.attr('string'),
|
271
|
+
hats: DS.hasMany('hat', {polymorphic: true})
|
272
|
+
})
|
273
|
+
|
230
274
|
Profile = DS.Model.extend({
|
231
275
|
description: DS.attr('string'),
|
232
276
|
camelCaseDescription: DS.attr('string'),
|
@@ -259,6 +303,7 @@ User = DS.Model.extend({
|
|
259
303
|
hats: DS.hasMany('hat', {polymorphic: true})
|
260
304
|
});
|
261
305
|
|
306
|
+
|
262
307
|
/*!
|
263
308
|
* MockJax - jQuery Plugin to Mock Ajax requests
|
264
309
|
*
|