angularjs-rails-resource 2.1.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3f99d3285acce5e56b23fb1afcb9f9441f2bbc00
4
- data.tar.gz: d23f60d6f53df27985752e40129329d9a740d585
3
+ metadata.gz: b3fc1e98484eeb10fb8787bb5e9fea02f275494d
4
+ data.tar.gz: 2f2d703fbcba895214a994521b52b1aabb84f46b
5
5
  SHA512:
6
- metadata.gz: 79ae6274c9fe790e75ce17fc06b8f9d116dfee01d6a49e253fc685f4aa08736f0c4ace185250a038e5866c8fb02c539924935cb1429fe54e6f75b6a3082396aa
7
- data.tar.gz: 9c0721c4f9be00b5cddba762a8869e1c7cfbc0ee7c1cd3c31e121551787529c99e6c9413af94c5c9f85c4337a258acd3e394f8495f7270b3f5afcb2ab94743b6
6
+ metadata.gz: 8e3448779115e0f61e4489397f9b17f732789c3a05d1e84256712821b0800091fce895ee7b464688d43dfa6d087d6bc71b6f40c53a585fd954f2d0000137755a
7
+ data.tar.gz: 8083d8f0411916e2cf1adcd5e5d4832369994c19e323d83d6ae6909bed85b8c4f632eef898b553e420e64ef69aca165cb5170211767b60246c78c444f0c297df
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ <a name="2.2.0"></a>
2
+ # 2.2.0
3
+ ## Features
4
+ - Allow queryParams for $post, $put and $patch - #197 (@herumtreiber )
5
+
1
6
  <a name="2.1.0"></a>
2
7
  # 2.1.0
3
8
  ## Features
data/README.md CHANGED
@@ -303,10 +303,11 @@ RailsResources have the following class methods available.
303
303
  * **queryParams** {object} (optional) - The set of query parameters to include in the GET request
304
304
  * **returns** {promise} A promise that will be resolved with a new Resource instance (or instances in the case of an array response).
305
305
 
306
- * $post/$put/$patch(customUrl, data, resourceConfigOverrides) - Serializes the data parameter using the Resource's normal serialization process and submits the result as a POST / PUT / PATCH to the given URL.
306
+ * $post/$put/$patch(customUrl, data, resourceConfigOverrides, queryParams) - Serializes the data parameter using the Resource's normal serialization process and submits the result as a POST / PUT / PATCH to the given URL.
307
307
  * **customUrl** {string} - The url to POST / PUT / PATCH to
308
308
  * **data** {object} - The data to serialize and POST / PUT / PATCH
309
309
  * **resourceConfigOverrides** {object} (optional) - An optional set of RailsResource configuration option overrides to use for this request. Root wrapping and serialization for the request data can be bypassed using the `skipRequestProcessing` flag. This also bypasses the entire pre-request [interceptor](#interceptors) chain.
310
+ * **queryParams** {object} (optional) - The set of query parameters to include in the request
310
311
  * **returns** {promise} A promise that will be resolved with a new Resource instance (or instances in the case of an array response).
311
312
 
312
313
  * $delete(customUrl, queryParams) - Executes a DELETE to a custom URL. The main difference between this and $http.delete is that a server response that contains a body will be deserialized using the normal Resource deserialization process.
@@ -375,8 +376,10 @@ All of the instance methods will update the instance in-place on response and wi
375
376
 
376
377
  * $http(httpConfig, resourceConfigOverrides) - Executes class method $http with the resource instance as the operation context.
377
378
 
378
- * $post(customUrl), $put(customUrl), $patch(customUrl) - Serializes and submits the instance using an HTTP POST/PUT/PATCH to the given URL.
379
+ * $post(customUrl, context, queryParams), $put(customUrl, context, queryParams), $patch(customUrl, context, queryParams) - Serializes and submits the instance using an HTTP POST/PUT/PATCH to the given URL.
379
380
  * **customUrl** {string} - The url to POST / PUT / PATCH to
381
+ * **context** {object} - The instance that the operation is being run against.
382
+ * **queryParams** {object} (optional) - The set of query parameters to include in the POST / PUT / PATCH request
380
383
  * **returns** {promise} - A promise that will be resolved with the instance itself
381
384
 
382
385
  * $delete(customUrl, queryParams) - Executes a DELETE to a custom URL. The main difference between this and $http.delete is that a server response that contains a body will be deserialized using the normal Resource deserialization process.
data/bower.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "angularjs-rails-resource",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "main": "angularjs-rails-resource.js",
5
5
  "description": "A resource factory inspired by $resource from AngularJS",
6
6
  "repository": {
@@ -1,7 +1,7 @@
1
1
  module Angularjs
2
2
  module Rails
3
3
  module Resource
4
- VERSION = '2.1.0'
4
+ VERSION = '2.2.0'
5
5
  end
6
6
  end
7
7
  end
data/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "angularjs-rails-resource",
3
3
  "description" : "A resource factory inspired by $resource from AngularJS",
4
- "version": "2.1.0",
4
+ "version": "2.2.0",
5
5
  "main" : "angularjs-rails-resource.min.js",
6
6
  "homepage" : "https://github.com/FineLinePrototyping/angularjs-rails-resource.git",
7
7
  "author" : "",
@@ -484,6 +484,19 @@ describe('railsResourceFactory', function () {
484
484
  expect(result).toEqualData({id: 123, abc: 'xyz', xyz: 'abc', extra: 'test'});
485
485
  });
486
486
 
487
+ it('should be able to ' + method + ' to arbitrary url with query params', function () {
488
+ var promise, result = {};
489
+
490
+ promise = Test['$' + method]('/xyz', {abc: 'xyz', xyz: 'abc'}, {}, {def: 'ghi'});
491
+ $httpBackend['expect' + angular.uppercase(method)]('/xyz?def=ghi', {test: {abc: 'xyz', xyz: 'abc'}}).respond(200, {test: {abc: 'xyz', xyz: 'abc', extra: 'test'}});
492
+
493
+ promise.then(function (response) {
494
+ result = response;
495
+ });
496
+
497
+ $httpBackend.flush();
498
+ });
499
+
487
500
  it('should be able to ' + method + ' instance to arbitrary url', function () {
488
501
  var test = new Test({id: 123, abc: 'xyz', xyz: 'abc'});
489
502
  $httpBackend['expect' + angular.uppercase(method)]('/xyz', {test: {id: 123, abc: 'xyz', xyz: 'abc'}}).respond(200, {test: {id: 123, abc: 'xyz', xyz: 'abc', extra: 'test'}});
@@ -493,6 +506,13 @@ describe('railsResourceFactory', function () {
493
506
  // abc was originally set on the object so it should still be there after the update
494
507
  expect(test).toEqualData({id: 123, abc: 'xyz', xyz: 'abc', extra: 'test'});
495
508
  });
509
+
510
+ it('should be able to ' + method + ' instance to arbitrary url with query params', function () {
511
+ var test = new Test({abc: 'xyz', xyz: 'abc'});
512
+ $httpBackend['expect' + angular.uppercase(method)]('/xyz?def=ghi', {test: {abc: 'xyz', xyz: 'abc'}}).respond(200, {test: {abc: 'xyz', xyz: 'abc', extra: 'test'}});
513
+ test['$' + method]('/xyz', {}, {def: 'ghi'});
514
+ $httpBackend.flush();
515
+ });
496
516
  });
497
517
 
498
518
  it('should be able to $post an array of resources', function () {
@@ -454,6 +454,48 @@ describe('railsSerializer', function () {
454
454
  });
455
455
  });
456
456
 
457
+ describe('multiple levels of nested attributes', function () {
458
+ module('rails');
459
+
460
+ angular.module('rails').factory('Campaign', function (railsResourceFactory, railsSerializer) {
461
+ return railsResourceFactory({
462
+ name: 'campaign',
463
+ serializer: railsSerializer(function() {
464
+ this.resource('emails', 'Email');
465
+ this.nestedAttribute('emails');
466
+ })
467
+ });
468
+ });
469
+ angular.module('rails').factory('Email', function (railsResourceFactory, railsSerializer) {
470
+ return railsResourceFactory({
471
+ name: 'email',
472
+ serializer: railsSerializer(function() {
473
+ this.resource('emailTemplate', 'EmailTemplate');
474
+ this.nestedAttribute('emailTemplate');
475
+ })
476
+ });
477
+ });
478
+ angular.module('rails').factory('EmailTemplate', function (railsResourceFactory) {
479
+ return railsResourceFactory({name: 'emailTemplate'});
480
+ });
481
+
482
+ it('should add email template as nested attribute', inject(function(Campaign, Email, EmailTemplate) {
483
+ var campaign = new Campaign({
484
+ id: 1,
485
+ name: 'Test',
486
+ emails: [
487
+ new Email({id: 1, name: '50% off', emailTemplate: new EmailTemplate({id: 1, name: 'Discount'})})
488
+ ]
489
+ });
490
+ var serializedCampaign = {
491
+ id: 1, name: 'Test',
492
+ emails_attributes: [
493
+ {id: 1, name: '50% off', email_template_attributes: { id: 1, name: 'Discount' }}],
494
+ };
495
+
496
+ expect(Campaign.config.serializer.serialize(campaign)).toEqual(serializedCampaign);
497
+ }));
498
+ });
457
499
  describe('nested resource collection serialization', function () {
458
500
  module('rails');
459
501
 
@@ -476,13 +518,11 @@ describe('railsSerializer', function () {
476
518
  serializer: railsSerializer(function() {
477
519
  this.resource('user', 'User');
478
520
  this.resource('slot', 'Slot');
521
+ this.nestedAttribute('slot');
479
522
  this.add('user_id', function(member) {
480
523
  return member.user.id;
481
524
  });
482
- this.add('slot_id', function(member) {
483
- return member.slot.id;
484
- });
485
- this.exclude('user', 'slot');
525
+ this.exclude('user');
486
526
  })
487
527
  });
488
528
  });
@@ -509,7 +549,7 @@ describe('railsSerializer', function () {
509
549
  });
510
550
  var serializedTeam1 = {
511
551
  id: 1, name: 'Team 1', vehicle_id: 123,
512
- members_attributes: [{id: 352435, user_id: 100500, slot_id: 200425}, {id: 235433, user_id: 100501, slot_id: 200426}],
552
+ members_attributes: [{id: 352435, user_id: 100500, slot_attributes: { id: 200425, rank_id: 1 }}, {id: 235433, user_id: 100501, slot_attributes: { id: 200426, rank_id: 2 }}],
513
553
  };
514
554
 
515
555
  expect(Team.config.serializer.serialize(team1)).toEqual(serializedTeam1);
@@ -720,17 +720,16 @@
720
720
  };
721
721
 
722
722
  angular.forEach(['post', 'put', 'patch'], function (method) {
723
- RailsResource['$' + method] = function (url, data, resourceConfigOverrides) {
723
+ RailsResource['$' + method] = function (url, data, resourceConfigOverrides, queryParams) {
724
724
  // clone so we can manipulate w/o modifying the actual instance
725
725
  data = angular.copy(data);
726
- return this.$http(angular.extend({method: method, url: url, data: data}, this.getHttpConfig()), null, resourceConfigOverrides);
726
+ return this.$http(angular.extend({method: method, url: url, data: data}, this.getHttpConfig(queryParams)), null, resourceConfigOverrides);
727
727
  };
728
728
 
729
- RailsResource.prototype['$' + method] = function (url) {
729
+ RailsResource.prototype['$' + method] = function (url, context, queryParams) {
730
730
  // clone so we can manipulate w/o modifying the actual instance
731
731
  var data = angular.copy(this, {});
732
- return this.constructor.$http(angular.extend({method: method, url: url, data: data}, this.constructor.getHttpConfig()), this);
733
-
732
+ return this.constructor.$http(angular.extend({method: method, url: url, data: data}, this.constructor.getHttpConfig(queryParams)), this);
734
733
  };
735
734
  });
736
735
 
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: 2.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tommy Odom
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-03-20 00:00:00.000000000 Z
12
+ date: 2016-04-19 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: