angularjs-rails-resource 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  module Angularjs
2
2
  module Rails
3
3
  module Resource
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
6
6
  end
7
7
  end
@@ -1262,7 +1262,7 @@ function MockHttpExpectation(method, url, data, headers) {
1262
1262
  };
1263
1263
 
1264
1264
  this.matchData = function(d) {
1265
- if (angular.isUndefined(data)) return true;
1265
+ if (angular.isUndefined(data) && angular.isUndefined(d)) return true;
1266
1266
  if (data && angular.isFunction(data.test)) return data.test(d);
1267
1267
  if (data && !angular.isString(data)) return angular.toJson(data) == d;
1268
1268
  return data == d;
@@ -329,7 +329,7 @@ describe("js.rails", function () {
329
329
  it('should be able to create new instance and save it', inject(function($httpBackend) {
330
330
  var data = new Test({abcDef: 'xyz'});
331
331
 
332
- $httpBackend.expectPOST('/test').respond(200, {test: {id: 123, abc_def: 'xyz'}});
332
+ $httpBackend.expectPOST('/test', {test: {abc_def: 'xyz'}}).respond(200, {test: {id: 123, abc_def: 'xyz'}});
333
333
  data.create();
334
334
  $httpBackend.flush();
335
335
 
@@ -339,13 +339,13 @@ describe("js.rails", function () {
339
339
  it('should be able to create new instance and update it', inject(function($httpBackend) {
340
340
  var data = new Test({abcDef: 'xyz'});
341
341
 
342
- $httpBackend.expectPOST('/test').respond(200, {test: {id: 123, abc_def: 'xyz'}});
342
+ $httpBackend.expectPOST('/test', {test: {abc_def: 'xyz'}}).respond(200, {test: {id: 123, abc_def: 'xyz'}});
343
343
  data.create();
344
344
  $httpBackend.flush(1);
345
345
 
346
346
  expect(data).toEqualData({id: 123, abcDef: 'xyz'});
347
347
 
348
- $httpBackend.expectPUT('/test/123').respond(200, {test: {id: 123, abc_def: 'xyz', xyz: 'abc', extra: 'test'}});
348
+ $httpBackend.expectPUT('/test/123', {test: {id: 123, xyz: 'abc', abc_def: 'xyz'}}).respond(200, {test: {id: 123, abc_def: 'xyz', xyz: 'abc', extra: 'test'}});
349
349
  data.xyz = 'abc';
350
350
  data.update();
351
351
  $httpBackend.flush();
@@ -356,7 +356,7 @@ describe("js.rails", function () {
356
356
  it('create with default params should add parameter abc=1', inject(function($httpBackend) {
357
357
  var promise, Resource, data, defaultParamsConfig = {};
358
358
 
359
- $httpBackend.expectPOST('/test?abc=1').respond(200, {test: {abc: 'xyz'}});
359
+ $httpBackend.expectPOST('/test?abc=1', {test: {}}).respond(200, {test: {abc: 'xyz'}});
360
360
 
361
361
  angular.copy(config, defaultParamsConfig);
362
362
  defaultParamsConfig.defaultParams = {abc: '1'};
@@ -371,7 +371,7 @@ describe("js.rails", function () {
371
371
  it('should be able to get resource and update it', inject(function($httpBackend) {
372
372
  var promise, result;
373
373
 
374
- $httpBackend.expectGET('/test/123').respond(200, {test: {id: 123, abc: 'xyz'}});
374
+ $httpBackend.expectGET('/test/123').respond(200, {test: {id: 123, abc: 'xyz', xyz: 'abcd'}});
375
375
 
376
376
  expect(promise = Test.get(123)).toBeDefined();
377
377
 
@@ -382,15 +382,15 @@ describe("js.rails", function () {
382
382
  $httpBackend.flush();
383
383
 
384
384
  expect(result).toBeInstanceOf(Test);
385
- expect(result).toEqualData({id: 123, abc: 'xyz'});
385
+ expect(result).toEqualData({id: 123, abc: 'xyz', xyz: 'abcd'});
386
386
 
387
- $httpBackend.expectPUT('/test/123').respond(200, {test: {id: 123, abc_def: 'xyz', xyz: 'abc', extra: 'test'}});
387
+ $httpBackend.expectPUT('/test/123', {test: {id: 123, abc: 'xyz', xyz: 'abc'}}).respond(200, {test: {id: 123, abc: 'xyz', xyz: 'abc', extra: 'test'}});
388
388
  result.xyz = 'abc';
389
389
  result.update();
390
390
  $httpBackend.flush();
391
391
 
392
392
  // abc was originally set on the object so it should still be there after the update
393
- expect(result).toEqualData({id: 123, abc: 'xyz', abcDef: 'xyz', xyz: 'abc', extra: 'test'});
393
+ expect(result).toEqualData({id: 123, abc: 'xyz', xyz: 'abc', extra: 'test'});
394
394
  }));
395
395
 
396
396
  it('update should handle 204 response', inject(function($httpBackend) {
@@ -409,7 +409,7 @@ describe("js.rails", function () {
409
409
  expect(result).toBeInstanceOf(Test);
410
410
  expect(result).toEqualData({id: 123, abc: 'xyz'});
411
411
 
412
- $httpBackend.expectPUT('/test/123').respond(204);
412
+ $httpBackend.expectPUT('/test/123', {test: {id: 123, abc: 'xyz', xyz: 'abc'}}).respond(204);
413
413
  result.xyz = 'abc';
414
414
  result.update();
415
415
  $httpBackend.flush();
@@ -693,7 +693,7 @@ describe("js.rails", function () {
693
693
  it('should be able to create new instance and save it', inject(function($httpBackend) {
694
694
  var data = new NestedTest({nestedId: 1234, abcDef: 'xyz'});
695
695
 
696
- $httpBackend.expectPOST('/nested/1234/test').respond(200, {nested_test: {id: 123, nested_id: 1234, abc_def: 'xyz'}});
696
+ $httpBackend.expectPOST('/nested/1234/test', {nested_test: {nested_id: 1234, abc_def: 'xyz'}}).respond(200, {nested_test: {id: 123, nested_id: 1234, abc_def: 'xyz'}});
697
697
  data.nestedId = 1234;
698
698
  data.create();
699
699
  $httpBackend.flush();
@@ -704,14 +704,14 @@ describe("js.rails", function () {
704
704
  it('should be able to create new instance and update it', inject(function($httpBackend) {
705
705
  var data = new NestedTest({abcDef: 'xyz'});
706
706
 
707
- $httpBackend.expectPOST('/nested/1234/test').respond(200, {nested_test: {id: 123, nested_id: 1234, abc_def: 'xyz'}});
707
+ $httpBackend.expectPOST('/nested/1234/test', {nested_test: {abc_def: 'xyz', nested_id: 1234}}).respond(200, {nested_test: {id: 123, nested_id: 1234, abc_def: 'xyz'}});
708
708
  data.nestedId = 1234;
709
709
  data.create();
710
710
  $httpBackend.flush(1);
711
711
 
712
712
  expect(data).toEqualData({id: 123, nestedId: 1234, abcDef: 'xyz'});
713
713
 
714
- $httpBackend.expectPUT('/nested/1234/test/123').respond(200, {nested_test: {id: 123, nested_id: 1234, abc_def: 'xyz', xyz: 'abc', extra: 'test'}});
714
+ $httpBackend.expectPUT('/nested/1234/test/123', {nested_test: {id: 123, xyz: 'abc', abc_def: 'xyz', nested_id: 1234}}).respond(200, {nested_test: {id: 123, nested_id: 1234, abc_def: 'xyz', xyz: 'abc', extra: 'test'}});
715
715
  data.xyz = 'abc';
716
716
  data.update();
717
717
  $httpBackend.flush();
@@ -722,7 +722,7 @@ describe("js.rails", function () {
722
722
  it('create with default params should add parameter abc=1', inject(function($httpBackend) {
723
723
  var promise, Resource, data, defaultParamsConfig = {};
724
724
 
725
- $httpBackend.expectPOST('/nested/1234/test?abc=1').respond(200, {nested_test: {abc: 'xyz'}});
725
+ $httpBackend.expectPOST('/nested/1234/test?abc=1', {nested_test: {nested_id: 1234}}).respond(200, {nested_test: {id: 123, nested_id: 1234}});
726
726
 
727
727
  angular.copy(nestedConfig, defaultParamsConfig);
728
728
  defaultParamsConfig.defaultParams = {abc: '1'};
@@ -751,7 +751,7 @@ describe("js.rails", function () {
751
751
  expect(result).toBeInstanceOf(NestedTest);
752
752
  expect(result).toEqualData({id: 123, nestedId: 1234, abc: 'xyz'});
753
753
 
754
- $httpBackend.expectPUT('/nested/1234/test/123').respond(200, {nested_test: {id: 123, nested_id: 1234, abc_def: 'xyz', xyz: 'abc', extra: 'test'}});
754
+ $httpBackend.expectPUT('/nested/1234/test/123', {nested_test: {id: 123, abc: 'xyz', xyz: 'abc', nested_id: 1234}}).respond(200, {nested_test: {id: 123, nested_id: 1234, abc_def: 'xyz', xyz: 'abc', extra: 'test'}});
755
755
  result.xyz = 'abc';
756
756
  result.update();
757
757
  $httpBackend.flush();
@@ -776,7 +776,7 @@ describe("js.rails", function () {
776
776
  expect(result).toBeInstanceOf(NestedTest);
777
777
  expect(result).toEqualData({id: 123, nestedId: 1234, abc: 'xyz'});
778
778
 
779
- $httpBackend.expectPUT('/nested/1234/test/123').respond(204);
779
+ $httpBackend.expectPUT('/nested/1234/test/123', {nested_test: {id: 123, abc: 'xyz', xyz: 'abc', nested_id: 1234}}).respond(204);
780
780
  result.xyz = 'abc';
781
781
  result.update();
782
782
  $httpBackend.flush();
@@ -805,6 +805,22 @@ describe("js.rails", function () {
805
805
  $httpBackend.flush();
806
806
  }));
807
807
 
808
+ it('should be able to create new instance and update it', inject(function($httpBackend) {
809
+ var data = new NestedTest({abcDef: 'xyz'});
810
+
811
+ $httpBackend.expectPOST('/nested/1234/test', {nested_test: {abc_def: 'xyz', nested_id: 1234}}).respond(200, {nested_test: {id: 123, nested_id: 1234, abc_def: 'xyz'}});
812
+ data.nestedId = 1234;
813
+ data.create();
814
+ $httpBackend.flush(1);
815
+
816
+ expect(data).toEqualData({id: 123, nestedId: 1234, abcDef: 'xyz'});
817
+ expect(data).toBeInstanceOf(NestedTest);
818
+
819
+ $httpBackend.expectDELETE('/nested/1234/test/123').respond(204);
820
+ data.remove();
821
+ $httpBackend.flush();
822
+ }));
823
+
808
824
  it('delete with default params should add parameter abc=1', inject(function($httpBackend) {
809
825
  var Resource, data, defaultParamsConfig = {};
810
826
 
@@ -267,8 +267,9 @@
267
267
  return this.processResponse($http.put(RailsResource.resourceUrl(this), data, RailsResource.getHttpConfig()));
268
268
  };
269
269
 
270
- RailsResource.prototype.remove = RailsResource.prototype.delete = function () {
271
- return this.processResponse($http.delete(RailsResource.resourceUrl(this), RailsResource.getHttpConfig()));
270
+ //using ['delete'] instead of .delete for IE7/8 compatibility
271
+ RailsResource.prototype.remove = RailsResource.prototype['delete'] = function () {
272
+ return this.processResponse($http['delete'](RailsResource.resourceUrl(this), RailsResource.getHttpConfig()));
272
273
  };
273
274
 
274
275
  return RailsResource;
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.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-01 00:00:00.000000000 Z
12
+ date: 2013-03-06 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A small AngularJS add-on for integrating with Rails via JSON more easily.
15
15
  email: