test/unit/angularjs/rails/resourceSpec.js in angularjs-rails-resource-0.1.6 vs test/unit/angularjs/rails/resourceSpec.js in angularjs-rails-resource-0.1.7
- old
+ new
@@ -203,10 +203,29 @@
$httpBackend.flush();
expect(data).toEqualData({id: 123, abcDef: 'xyz'});
}));
+ it("should return a promise when calling save", inject(function($httpBackend) {
+ var promise, data;
+
+ data = new Test({abc_def: 'xyz'});
+ $httpBackend.expectPOST('/test', {test: {abc_def: 'xyz'}}).respond(200, {test: {id: 123, abc_def: 'xyz'}});
+ expect(promise = data.save()).toBeDefined();
+ $httpBackend.flush()
+ }));
+
+ it('should be able to create new instance and save it using save', inject(function($httpBackend) {
+ var data = new Test({abcDef: 'xyz'});
+
+ $httpBackend.expectPOST('/test', {test: {abc_def: 'xyz'}}).respond(200, {test: {id: 123, abc_def: 'xyz'}});
+ data.save();
+ $httpBackend.flush();
+
+ expect(data).toEqualData({id: 123, abcDef: 'xyz'});
+ }));
+
it('should be able to create new instance and update it', inject(function($httpBackend) {
var data = new Test({abcDef: 'xyz'});
$httpBackend.expectPOST('/test', {test: {abc_def: 'xyz'}}).respond(200, {test: {id: 123, abc_def: 'xyz'}});
data.create();
@@ -215,9 +234,26 @@
expect(data).toEqualData({id: 123, abcDef: 'xyz'});
$httpBackend.expectPUT('/test/123', {test: {id: 123, xyz: 'abc', abc_def: 'xyz'}}).respond(200, {test: {id: 123, abc_def: 'xyz', xyz: 'abc', extra: 'test'}});
data.xyz = 'abc';
data.update();
+ $httpBackend.flush();
+
+ expect(data).toEqualData({id: 123, abcDef: 'xyz', xyz: 'abc', extra: 'test'});
+ }));
+
+ it('should be able to create new instance and update it using save', inject(function($httpBackend) {
+ var data = new Test({abcDef: 'xyz'});
+
+ $httpBackend.expectPOST('/test', {test: {abc_def: 'xyz'}}).respond(200, {test: {id: 123, abc_def: 'xyz'}});
+ data.save();
+ $httpBackend.flush(1);
+
+ expect(data).toEqualData({id: 123, abcDef: 'xyz'});
+
+ $httpBackend.expectPUT('/test/123', {test: {id: 123, xyz: 'abc', abc_def: 'xyz'}}).respond(200, {test: {id: 123, abc_def: 'xyz', xyz: 'abc', extra: 'test'}});
+ data.xyz = 'abc';
+ data.save();
$httpBackend.flush();
expect(data).toEqualData({id: 123, abcDef: 'xyz', xyz: 'abc', extra: 'test'});
}));