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
data/tests/factory_guy_test.js
CHANGED
@@ -123,10 +123,10 @@ test("#build with traits", function() {
|
|
123
123
|
deepEqual(json, {id: 2, title: 'Project1', user: {id: 1, name: 'User1'}}, 'trait with belongsTo attributes');
|
124
124
|
|
125
125
|
var json = FactoryGuy.build('project', 'big', 'with_user');
|
126
|
-
deepEqual(json, {id: 3, title: 'Big Project', user: {id: 2, name: '
|
126
|
+
deepEqual(json, {id: 3, title: 'Big Project', user: {id: 2, name: 'User2'}}, 'more than one trait used together');
|
127
127
|
|
128
128
|
var json = FactoryGuy.build('project', 'big', 'with_user', {title: 'Crazy Project'});
|
129
|
-
deepEqual(json, {id: 4, title: 'Crazy Project', user: {id: 3, name: '
|
129
|
+
deepEqual(json, {id: 4, title: 'Crazy Project', user: {id: 3, name: 'User3'}}, 'more than one trait used together with custom attributes');
|
130
130
|
|
131
131
|
var json = FactoryGuy.build('project', 'big', 'with_dude');
|
132
132
|
deepEqual(json, {id: 5, title: 'Big Project', user: {id: 4, name: 'Dude'}}, 'trait with custom belongsTo association object');
|
@@ -140,7 +140,7 @@ test("#build with traits", function() {
|
|
140
140
|
var json = FactoryGuy.build('user', 'with_projects');
|
141
141
|
deepEqual(json, {
|
142
142
|
id: 6,
|
143
|
-
name: '
|
143
|
+
name: 'User4',
|
144
144
|
projects: [{id: 8, title: 'Project4'},{id: 9, title: 'Project5'}]
|
145
145
|
}, 'trait with hasMany association');
|
146
146
|
});
|
@@ -183,7 +183,7 @@ test("#build similar model type ids are created sequentially", function() {
|
|
183
183
|
test("#buildList creates list of fixtures", function() {
|
184
184
|
var userList = FactoryGuy.buildList('user', 2);
|
185
185
|
deepEqual(userList[0], {id: 1, name: 'User1'});
|
186
|
-
deepEqual(userList[1], {id: 2, name: '
|
186
|
+
deepEqual(userList[1], {id: 2, name: 'User2'});
|
187
187
|
|
188
188
|
var userList = FactoryGuy.buildList('user', 1, {name: 'Crazy'});
|
189
189
|
deepEqual(userList[0], {id: 3, name: 'Crazy'},'using custom attributes');
|
@@ -1,8 +1,6 @@
|
|
1
1
|
var testHelper, store;
|
2
2
|
|
3
|
-
module('FactoryGuyTestMixin with DS.RESTAdapter', {
|
4
|
-
});
|
5
|
-
|
3
|
+
module('FactoryGuyTestMixin with DS.RESTAdapter', {});
|
6
4
|
|
7
5
|
test("#buildURL without namespace", function () {
|
8
6
|
RestAdapter = DS.RESTAdapter.extend({
|
@@ -24,22 +22,219 @@ test("#buildURL with namespace and host", function () {
|
|
24
22
|
equal(testHelper.buildURL('project'), 'https://dude.com/api/v1/projects');
|
25
23
|
})
|
26
24
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
25
|
+
|
26
|
+
|
27
|
+
module('FactoryGuyTestMixin (using mockjax) with DS.RESTAdapter', {
|
28
|
+
setup: function () {
|
29
|
+
testHelper = TestHelper.setup(DS.RESTAdapter);
|
30
|
+
store = testHelper.getStore();
|
31
|
+
},
|
32
|
+
teardown: function () {
|
33
|
+
testHelper.teardown();
|
34
|
+
$.mockjaxClear();
|
35
|
+
}
|
36
|
+
});
|
37
|
+
|
38
|
+
/////// handleCreate //////////
|
39
|
+
|
40
|
+
asyncTest("#handleCreate the basic", function() {
|
41
|
+
testHelper.handleCreate('profile')
|
42
|
+
|
43
|
+
store.createRecord('profile').save().then(function(profile) {
|
44
|
+
ok(profile instanceof Profile)
|
45
|
+
ok(profile.get('description') == 'Text goes here')
|
46
|
+
start();
|
47
|
+
});
|
48
|
+
});
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
/////// handleFindMany //////////
|
53
|
+
|
54
|
+
asyncTest("#handleFindMany the basic", function () {
|
55
|
+
testHelper.handleFindMany('profile', 2);
|
56
|
+
|
57
|
+
store.find('profile').then(function (profiles) {
|
58
|
+
ok(profiles.get('length') == 2);
|
59
|
+
start();
|
60
|
+
});
|
61
|
+
});
|
62
|
+
|
63
|
+
asyncTest("#handleFindMany with fixture options", function () {
|
64
|
+
testHelper.handleFindMany('profile', 2, {description: 'dude'});
|
65
|
+
|
66
|
+
store.find('profile').then(function (profiles) {
|
67
|
+
ok(profiles.get('length') == 2);
|
68
|
+
ok(profiles.get('firstObject.description') == 'dude');
|
69
|
+
start();
|
70
|
+
});
|
71
|
+
});
|
72
|
+
|
73
|
+
asyncTest("#handleFindMany with traits", function () {
|
74
|
+
testHelper.handleFindMany('profile', 2, 'goofy_description');
|
75
|
+
|
76
|
+
store.find('profile').then(function (profiles) {
|
77
|
+
ok(profiles.get('length') == 2);
|
78
|
+
ok(profiles.get('firstObject.description') == 'goofy');
|
79
|
+
start();
|
80
|
+
});
|
81
|
+
});
|
82
|
+
|
83
|
+
asyncTest("#handleFindMany with traits and extra options", function () {
|
84
|
+
testHelper.handleFindMany('profile', 2, 'goofy_description', {description: 'dude'});
|
85
|
+
|
86
|
+
store.find('profile').then(function (profiles) {
|
87
|
+
ok(profiles.get('length') == 2);
|
88
|
+
ok(profiles.get('firstObject.description') == 'dude');
|
89
|
+
start();
|
90
|
+
});
|
91
|
+
});
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
module('FactoryGuyTestMixin (using mockjax) with DS.ActiveModelAdapter', {
|
97
|
+
setup: function () {
|
98
|
+
testHelper = TestHelper.setup(DS.ActiveModelAdapter);
|
99
|
+
store = testHelper.getStore();
|
100
|
+
},
|
101
|
+
teardown: function () {
|
102
|
+
testHelper.teardown();
|
103
|
+
$.mockjaxClear();
|
104
|
+
}
|
105
|
+
});
|
106
|
+
|
107
|
+
|
108
|
+
/////// handleCreate //////////
|
109
|
+
|
110
|
+
asyncTest("#handleCreate the basic", function() {
|
111
|
+
testHelper.handleCreate('profile')
|
112
|
+
|
113
|
+
store.createRecord('profile').save().then(function(profile) {
|
114
|
+
ok(profile instanceof Profile)
|
115
|
+
ok(profile.get('description') == 'Text goes here')
|
116
|
+
start();
|
117
|
+
});
|
118
|
+
});
|
119
|
+
|
120
|
+
asyncTest("#handleCreate with model that has camelCase attribute", function() {
|
121
|
+
testHelper.handleCreate('profile', {camelCaseDescription: 'description'})
|
122
|
+
|
123
|
+
store.createRecord('profile').save().then(function(profile) {
|
124
|
+
ok(profile.get('camelCaseDescription') == 'description')
|
125
|
+
start();
|
126
|
+
});
|
127
|
+
});
|
128
|
+
|
129
|
+
asyncTest("#handleCreate failure", function() {
|
130
|
+
testHelper.handleCreate('profile', false)
|
131
|
+
|
132
|
+
store.createRecord('profile').save()
|
133
|
+
.then(
|
134
|
+
function() {},
|
135
|
+
function() {
|
136
|
+
ok(true)
|
137
|
+
start();
|
138
|
+
}
|
139
|
+
)
|
140
|
+
});
|
141
|
+
|
142
|
+
|
143
|
+
|
144
|
+
/////// handleFindMany //////////
|
145
|
+
|
146
|
+
|
147
|
+
asyncTest("#handleFindMany the basic", function () {
|
148
|
+
testHelper.handleFindMany('profile', 2);
|
149
|
+
|
150
|
+
store.find('profile').then(function (profiles) {
|
151
|
+
ok(profiles.get('length') == 2);
|
152
|
+
ok(profiles.get('firstObject.description') == 'Text goes here');
|
153
|
+
start();
|
154
|
+
});
|
155
|
+
});
|
156
|
+
|
157
|
+
asyncTest("#handleFindMany with fixture options", function () {
|
158
|
+
testHelper.handleFindMany('profile', 2, {description: 'dude'});
|
159
|
+
|
160
|
+
store.find('profile').then(function (profiles) {
|
161
|
+
ok(profiles.get('length') == 2);
|
162
|
+
ok(profiles.get('firstObject.description') == 'dude');
|
163
|
+
start();
|
164
|
+
});
|
165
|
+
});
|
166
|
+
|
167
|
+
asyncTest("#handleFindMany with traits", function () {
|
168
|
+
testHelper.handleFindMany('profile', 2, 'goofy_description');
|
169
|
+
|
170
|
+
store.find('profile').then(function (profiles) {
|
171
|
+
ok(profiles.get('length') == 2);
|
172
|
+
ok(profiles.get('firstObject.description') == 'goofy');
|
173
|
+
start();
|
174
|
+
});
|
175
|
+
});
|
176
|
+
|
177
|
+
asyncTest("#handleFindMany with traits and fixture options", function () {
|
178
|
+
testHelper.handleFindMany('profile', 2, 'goofy_description', {description: 'dude'});
|
179
|
+
|
180
|
+
store.find('profile').then(function (profiles) {
|
181
|
+
ok(profiles.get('length') == 2);
|
182
|
+
ok(profiles.get('firstObject.description') == 'dude');
|
183
|
+
start();
|
184
|
+
});
|
185
|
+
});
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
/////// handleUpdate //////////
|
190
|
+
|
191
|
+
asyncTest("#handleUpdate the basic", function() {
|
192
|
+
var profile = store.makeFixture('profile');
|
193
|
+
testHelper.handleUpdate('profile', profile.id);
|
194
|
+
|
195
|
+
profile.set('description','new desc');
|
196
|
+
profile.save().then(function(profile) {
|
197
|
+
ok(profile.get('description') == 'new desc');
|
198
|
+
start();
|
199
|
+
});
|
200
|
+
});
|
201
|
+
|
202
|
+
asyncTest("#handleUpdate failure", function() {
|
203
|
+
var profile = store.makeFixture('profile');
|
204
|
+
testHelper.handleUpdate('profile', profile.id, false);
|
205
|
+
|
206
|
+
profile.set('description','new desc');
|
207
|
+
profile.save().then(
|
208
|
+
function() {},
|
209
|
+
function() {
|
210
|
+
ok(true)
|
211
|
+
start();
|
212
|
+
}
|
213
|
+
)
|
214
|
+
});
|
215
|
+
|
216
|
+
|
217
|
+
/////// handleDelete //////////
|
218
|
+
|
219
|
+
asyncTest("#handleDelete the basic", function() {
|
220
|
+
var profile = store.makeFixture('profile');
|
221
|
+
testHelper.handleDelete('profile', profile.id);
|
222
|
+
|
223
|
+
profile.destroyRecord().then(function() {
|
224
|
+
equal(store.all('profile').get('content.length'), 0);
|
225
|
+
start();
|
226
|
+
});
|
227
|
+
});
|
228
|
+
|
229
|
+
asyncTest("#handleDelete failure case", function() {
|
230
|
+
var profile = store.makeFixture('profile');
|
231
|
+
testHelper.handleDelete('profile', profile.id, false);
|
232
|
+
|
233
|
+
profile.destroyRecord().then(
|
234
|
+
function() {},
|
235
|
+
function() {
|
236
|
+
ok(true);
|
237
|
+
start();
|
238
|
+
}
|
239
|
+
);
|
240
|
+
});
|
data/tests/index.html
CHANGED
@@ -26,11 +26,11 @@
|
|
26
26
|
</head>
|
27
27
|
<body>
|
28
28
|
<div id="qunit"></div> <!-- QUnit fills this with results, etc -->
|
29
|
-
|
30
|
-
|
29
|
+
<!--<script src='active_model_adapter_factory_test.js'></script>-->
|
30
|
+
<!--<script src='rest_adapter_factory_test.js'></script>-->
|
31
31
|
<!--<script src='fixture_adapter_factory_test.js'></script>-->
|
32
|
-
|
33
|
-
|
32
|
+
<!--<script src='store_test.js'></script>-->
|
33
|
+
<!--<script src='factory_guy_test.js'></script>-->
|
34
34
|
<script src='factory_guy_test_mixin_test.js'></script>
|
35
35
|
<div id='qunit-fixture'>
|
36
36
|
|
@@ -44,21 +44,32 @@ module('DS.Store#makeFixture with RestAdapter', {
|
|
44
44
|
});
|
45
45
|
|
46
46
|
|
47
|
-
test("creates DS.Model instances", function() {
|
48
|
-
var user = store.makeFixture('user');
|
49
|
-
equal(user instanceof DS.Model, true);
|
50
|
-
});
|
51
|
-
|
52
|
-
|
53
47
|
asyncTest("creates records in the store", function() {
|
54
48
|
var user = store.makeFixture('user');
|
49
|
+
ok(user instanceof User);
|
55
50
|
|
56
|
-
store.find('user', user.id).then(
|
51
|
+
store.find('user', user.id).then(function(store_user) {
|
57
52
|
ok(store_user == user);
|
58
53
|
start()
|
59
54
|
});
|
60
55
|
});
|
61
56
|
|
57
|
+
test("makeFixture with fixture options", function() {
|
58
|
+
var profile = store.makeFixture('profile', {description: 'dude'});
|
59
|
+
ok(profile.get('description') == 'dude');
|
60
|
+
});
|
61
|
+
|
62
|
+
test("makeFixture with traits", function() {
|
63
|
+
var profile = store.makeFixture('profile', 'goofy_description');
|
64
|
+
ok(profile.get('description') == 'goofy');
|
65
|
+
});
|
66
|
+
|
67
|
+
test("makeFixture with traits and fixture options ", function() {
|
68
|
+
var profile = store.makeFixture('profile', 'goofy_description', {description: 'dude'});
|
69
|
+
ok(profile.get('description') == 'dude');
|
70
|
+
});
|
71
|
+
|
72
|
+
|
62
73
|
|
63
74
|
test("when hasMany associations assigned, belongTo parent is assigned", function() {
|
64
75
|
var project = store.makeFixture('project');
|
@@ -214,15 +225,6 @@ test("belongsTo associations defined as attributes in fixture", function() {
|
|
214
225
|
});
|
215
226
|
|
216
227
|
|
217
|
-
test("belongsTo with embedded hasMany associations", function() {
|
218
|
-
var project = store.makeFixture('project', 'with_user_having_hats');
|
219
|
-
var user = project.get('user');
|
220
|
-
var hats = user.get('hats');
|
221
|
-
|
222
|
-
ok(user.get('projects.firstObject') == project)
|
223
|
-
ok(hats.get('firstObject.user') == user)
|
224
|
-
});
|
225
|
-
|
226
228
|
|
227
229
|
test("hasMany associations defined as attributes in fixture", function() {
|
228
230
|
var user = store.makeFixture('user_with_projects');
|
@@ -240,6 +242,25 @@ test("hasMany associations defined with traits", function() {
|
|
240
242
|
})
|
241
243
|
|
242
244
|
|
245
|
+
test("with (nested json fixture) belongsTo has a hasMany association which has a belongsTo", function() {
|
246
|
+
var project = store.makeFixture('project', 'with_user_having_hats_belonging_to_outfit');
|
247
|
+
var user = project.get('user');
|
248
|
+
var hats = user.get('hats');
|
249
|
+
var firstHat = hats.get('firstObject');
|
250
|
+
var lastHat = hats.get('lastObject');
|
251
|
+
|
252
|
+
ok(user.get('projects.firstObject') == project)
|
253
|
+
ok(firstHat.get('user') == user)
|
254
|
+
ok(firstHat.get('outfit.id') == 1)
|
255
|
+
ok(firstHat.get('outfit.hats.length') == 1)
|
256
|
+
ok(firstHat.get('outfit.hats.firstObject') == firstHat)
|
257
|
+
|
258
|
+
ok(lastHat.get('user') == user)
|
259
|
+
ok(lastHat.get('outfit.id') == 2)
|
260
|
+
ok(lastHat.get('outfit.hats.length') == 1)
|
261
|
+
ok(lastHat.get('outfit.hats.firstObject') == lastHat)
|
262
|
+
});
|
263
|
+
|
243
264
|
|
244
265
|
module('DS.Store#makeList with DS.RESTAdapter', {
|
245
266
|
setup: function() {
|
@@ -265,26 +286,4 @@ test("creates records in the store", function() {
|
|
265
286
|
var storeUsers = store.all('user').get('content');
|
266
287
|
ok(storeUsers[0] == users[0]);
|
267
288
|
ok(storeUsers[1] == users[1]);
|
268
|
-
});
|
269
|
-
|
270
|
-
//test("creates records in the store", function() {
|
271
|
-
// var lesson = store.makeFixture('lesson');
|
272
|
-
// var unit = store.makeFixture('unit');
|
273
|
-
// var unit = store.makeFixture('unit', {lesson: lesson});
|
274
|
-
// console.log('@@###',unit+'', unit.get('lesson')+'')
|
275
|
-
|
276
|
-
// var unit = FactoryGuy.build('unit_with_lesson')
|
277
|
-
// store.push('unit' , unit)
|
278
|
-
// console.log(store.modelFor('lesson')+'')
|
279
|
-
// var relationshipsByName = Ember.get(Lesson, 'relationshipsByName');
|
280
|
-
// console.log(relationshipsByName)
|
281
|
-
|
282
|
-
// var unit = store.makeFixture('unit_with_lesson');
|
283
|
-
// console.log('@@###',unit+'', unit.get('lesson')+'')
|
284
|
-
|
285
|
-
// console.log(FactoryGuy.build('unit_with_lesson'));
|
286
|
-
// unit.get('lesson').then(function(lesson) {
|
287
|
-
// ok(lesson instanceof Lesson == true)
|
288
|
-
// })
|
289
|
-
|
290
|
-
//})
|
289
|
+
});
|
@@ -7,6 +7,8 @@ FactoryGuy.define("project", {
|
|
7
7
|
with_title_sequence: { title: FactoryGuy.generate('title') },
|
8
8
|
with_user: { user: {} },
|
9
9
|
with_user_having_hats: { user: FactoryGuy.belongsTo('user', 'with_hats') },
|
10
|
+
with_user_having_hats_belonging_to_user: { user: FactoryGuy.belongsTo('user', 'with_hats_belonging_to_user') },
|
11
|
+
with_user_having_hats_belonging_to_outfit: { user: FactoryGuy.belongsTo('user', 'with_hats_belonging_to_outfit') },
|
10
12
|
with_dude: { user: {name: 'Dude'} },
|
11
13
|
with_admin: { user: FactoryGuy.belongsTo('admin') }
|
12
14
|
},
|