angularjs-rails-resource 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
@@ -205,6 +205,25 @@ describe("railsResourceFactory", function () {
|
|
205
205
|
expect(data).toEqualData({id: 123, abcDef: 'xyz'});
|
206
206
|
}));
|
207
207
|
|
208
|
+
it("should return a promise when calling save", inject(function($httpBackend) {
|
209
|
+
var promise, data;
|
210
|
+
|
211
|
+
data = new Test({abc_def: 'xyz'});
|
212
|
+
$httpBackend.expectPOST('/test', {test: {abc_def: 'xyz'}}).respond(200, {test: {id: 123, abc_def: 'xyz'}});
|
213
|
+
expect(promise = data.save()).toBeDefined();
|
214
|
+
$httpBackend.flush()
|
215
|
+
}));
|
216
|
+
|
217
|
+
it('should be able to create new instance and save it using save', inject(function($httpBackend) {
|
218
|
+
var data = new Test({abcDef: 'xyz'});
|
219
|
+
|
220
|
+
$httpBackend.expectPOST('/test', {test: {abc_def: 'xyz'}}).respond(200, {test: {id: 123, abc_def: 'xyz'}});
|
221
|
+
data.save();
|
222
|
+
$httpBackend.flush();
|
223
|
+
|
224
|
+
expect(data).toEqualData({id: 123, abcDef: 'xyz'});
|
225
|
+
}));
|
226
|
+
|
208
227
|
it('should be able to create new instance and update it', inject(function($httpBackend) {
|
209
228
|
var data = new Test({abcDef: 'xyz'});
|
210
229
|
|
@@ -222,6 +241,23 @@ describe("railsResourceFactory", function () {
|
|
222
241
|
expect(data).toEqualData({id: 123, abcDef: 'xyz', xyz: 'abc', extra: 'test'});
|
223
242
|
}));
|
224
243
|
|
244
|
+
it('should be able to create new instance and update it using save', inject(function($httpBackend) {
|
245
|
+
var data = new Test({abcDef: 'xyz'});
|
246
|
+
|
247
|
+
$httpBackend.expectPOST('/test', {test: {abc_def: 'xyz'}}).respond(200, {test: {id: 123, abc_def: 'xyz'}});
|
248
|
+
data.save();
|
249
|
+
$httpBackend.flush(1);
|
250
|
+
|
251
|
+
expect(data).toEqualData({id: 123, abcDef: 'xyz'});
|
252
|
+
|
253
|
+
$httpBackend.expectPUT('/test/123', {test: {id: 123, xyz: 'abc', abc_def: 'xyz'}}).respond(200, {test: {id: 123, abc_def: 'xyz', xyz: 'abc', extra: 'test'}});
|
254
|
+
data.xyz = 'abc';
|
255
|
+
data.save();
|
256
|
+
$httpBackend.flush();
|
257
|
+
|
258
|
+
expect(data).toEqualData({id: 123, abcDef: 'xyz', xyz: 'abc', extra: 'test'});
|
259
|
+
}));
|
260
|
+
|
225
261
|
it('create with default params should add parameter abc=1', inject(function($httpBackend) {
|
226
262
|
var promise, Resource, data, defaultParamsConfig = {};
|
227
263
|
|
@@ -327,6 +327,18 @@
|
|
327
327
|
return this.$put(this.$url(), this);
|
328
328
|
};
|
329
329
|
|
330
|
+
RailsResource.prototype.isNew = function () {
|
331
|
+
return this.id == null;
|
332
|
+
}
|
333
|
+
|
334
|
+
RailsResource.prototype.save = function () {
|
335
|
+
if (this.isNew()) {
|
336
|
+
return this.create();
|
337
|
+
} else {
|
338
|
+
return this.update();
|
339
|
+
}
|
340
|
+
}
|
341
|
+
|
330
342
|
RailsResource['$delete'] = function (url) {
|
331
343
|
return RailsResource.processResponse($http['delete'](url, RailsResource.getHttpConfig()));
|
332
344
|
};
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: angularjs-rails-resource
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-06
|
13
|
+
date: 2013-07-06 00:00:00.000000000 Z
|
14
14
|
dependencies: []
|
15
15
|
description: A small AngularJS add-on for integrating with Rails via JSON more easily.
|
16
16
|
email:
|