angularjs-rails-resource 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -54,7 +54,9 @@ The following options are available for the config object passed to the factory
54
54
  * **name** - This is the name used for root wrapping when dealing with singular instances.
55
55
  * **pluralName** *(optional)* - If specified this name will be used for unwrapping query results,
56
56
  if not specified the singular name with an appended 's' will be used.
57
- * **httpConfig** *(optional)* - Passed directly to $http.
57
+ * **httpConfig** *(optional)* - By default we will add the following headers to ensure that the request is processed as JSON by Rails. You can specify additional http config options or override any of the defaults by setting this property. See the [AngularJS $http API](http://docs.angularjs.org/api/ng.$http) for more information.
58
+ * **headers**
59
+ * **Accept** - application/json
58
60
  * **defaultParams** *(optional)* - If the resource expects a default set of query params on every call you can specify them here.
59
61
  * **requestTransformers** *(optional) - See [Transformers / Interceptors](#transformers--interceptors)
60
62
  * **responseInterceptors** *(optional)* - See [Transformers / Interceptors](#transformers--interceptors)
@@ -280,9 +282,9 @@ Or, if you say the user typed in the book id into a scope variable and you wante
280
282
  book.update();
281
283
 
282
284
  ## Tests
283
- The tests are written using [Jasmine](http://pivotal.github.com/jasmine/) and are run using [Testacular](http://vojtajina.github.com/testacular/).
285
+ The tests are written using [Jasmine](http://pivotal.github.com/jasmine/) and are run using [Karma](https://github.com/karma-runner/karma).
284
286
 
285
- Running the tests should be as simple as following the [instructions](https://github.com/vojtajina/testacular/blob/master/README.md)
287
+ Running the tests should be as simple as following the [instructions](https://github.com/karma-runner/karma)
286
288
 
287
289
  ## Contributing
288
290
 
@@ -2,11 +2,11 @@
2
2
  require File.expand_path('../lib/angularjs-rails-resource/version', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
- gem.authors = ["Tommy Odom"]
6
- gem.email = ["odom@finelineprototyping.com"]
5
+ gem.authors = ["Tommy Odom", "Chris Chase"]
6
+ gem.email = ["odom@finelineprototyping.com", "chris@finelineprototyping.com"]
7
7
  gem.description = %q{A small AngularJS add-on for integrating with Rails via JSON more easily.}
8
8
  gem.summary = %q{}
9
- gem.homepage = "https://github.com/tpodom/angularjs-rails-resource"
9
+ gem.homepage = "https://github.com/finelineprototyping/angularjs-rails-resource"
10
10
 
11
11
  gem.files = `git ls-files`.split($\)
12
12
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
File without changes
@@ -1,7 +1,7 @@
1
1
  module Angularjs
2
2
  module Rails
3
3
  module Resource
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.3"
5
5
  end
6
6
  end
7
7
  end
@@ -839,4 +839,207 @@ describe("js.rails", function () {
839
839
  }));
840
840
  });
841
841
 
842
+ describe('http settings', function() {
843
+ var $httpBackend, $rootScope, factory,
844
+ config = {
845
+ url: '/test',
846
+ name: 'test'
847
+ };
848
+
849
+ beforeEach(inject(function (_$httpBackend_, _$rootScope_, railsResourceFactory) {
850
+ $httpBackend = _$httpBackend_;
851
+ $rootScope = _$rootScope_;
852
+ factory = railsResourceFactory;
853
+ }));
854
+
855
+ afterEach(function() {
856
+ $httpBackend.verifyNoOutstandingExpectation();
857
+ $httpBackend.verifyNoOutstandingRequest();
858
+ });
859
+
860
+ function headerComparison(expectedHeaders) {
861
+ return function(headers) {
862
+ var matches = true;
863
+
864
+ angular.forEach(expectedHeaders, function (value, key) {
865
+ if (headers[key] !== value) {
866
+ matches = false;
867
+ }
868
+ });
869
+
870
+ return matches;
871
+ };
872
+ }
873
+
874
+ it('query should pass default $http options', inject(function($httpBackend) {
875
+ var promise, result, Test;
876
+
877
+ $httpBackend.expectGET('/test', headerComparison({'Accept': 'application/json'})).respond(200, {test: {abc: 'xyz'}});
878
+
879
+ Test = factory(config);
880
+ expect(promise = Test.query()).toBeDefined();
881
+
882
+ promise.then(function (response) {
883
+ result = response;
884
+ });
885
+
886
+ $httpBackend.flush();
887
+ }));
888
+
889
+ it('query should allow custom Accept', inject(function($httpBackend) {
890
+ var promise, result, Test;
891
+
892
+ $httpBackend.expectGET('/test', headerComparison({'Accept': 'text/plain'})).respond(200, {test: {abc: 'xyz'}});
893
+
894
+ Test = factory(angular.extend(angular.copy(config), {httpConfig: {headers: {'Accept': 'text/plain'}}}));
895
+ expect(promise = Test.query()).toBeDefined();
896
+
897
+ promise.then(function (response) {
898
+ result = response;
899
+ });
900
+
901
+ $httpBackend.flush();
902
+ }));
903
+
904
+ it('query should allow custom header', inject(function($httpBackend) {
905
+ var promise, result, Test;
906
+
907
+ $httpBackend.expectGET('/test', headerComparison({'Accept': 'application/json', 'X-Test': 'test'})).respond(200, {test: {abc: 'xyz'}});
908
+
909
+ Test = factory(angular.extend(angular.copy(config), {httpConfig: {headers: {'X-Test': 'test'}}}));
910
+ expect(promise = Test.query()).toBeDefined();
911
+
912
+ promise.then(function (response) {
913
+ result = response;
914
+ });
915
+
916
+ $httpBackend.flush();
917
+ }));
918
+
919
+ it('get should pass default $http options', inject(function($httpBackend) {
920
+ var promise, result, Test;
921
+
922
+ $httpBackend.expectGET('/test/123', headerComparison({'Accept': 'application/json'})).respond(200, {test: {abc: 'xyz'}});
923
+
924
+ Test = factory(config);
925
+ expect(promise = Test.get(123)).toBeDefined();
926
+
927
+ promise.then(function (response) {
928
+ result = response;
929
+ });
930
+
931
+ $httpBackend.flush();
932
+ }));
933
+
934
+ it('get should allow custom Accept', inject(function($httpBackend) {
935
+ var promise, result, Test;
936
+
937
+ $httpBackend.expectGET('/test/123', headerComparison({'Accept': 'text/plain'})).respond(200, {test: {abc: 'xyz'}});
938
+
939
+ Test = factory(angular.extend(angular.copy(config), {httpConfig: {headers: {'Accept': 'text/plain'}}}));
940
+ expect(promise = Test.get(123)).toBeDefined();
941
+
942
+ promise.then(function (response) {
943
+ result = response;
944
+ });
945
+
946
+ $httpBackend.flush();
947
+ }));
948
+
949
+ it('get should allow custom header', inject(function($httpBackend) {
950
+ var promise, result, Test;
951
+
952
+ $httpBackend.expectGET('/test/123', headerComparison({'Accept': 'application/json', 'X-Test': 'test'})).respond(200, {test: {abc: 'xyz'}});
953
+
954
+ Test = factory(angular.extend(angular.copy(config), {httpConfig: {headers: {'X-Test': 'test'}}}));
955
+ expect(promise = Test.get(123)).toBeDefined();
956
+
957
+ promise.then(function (response) {
958
+ result = response;
959
+ });
960
+
961
+ $httpBackend.flush();
962
+ }));
963
+
964
+ it('create should pass default $http options', inject(function($httpBackend) {
965
+ var Test;
966
+
967
+ $httpBackend.expectPOST('/test', {test: {xyz: '123'}}, headerComparison({'Accept': 'application/json'})).respond(200, {test: {id: 123, xyz: '123'}});
968
+
969
+ Test = factory(config);
970
+ var test = new Test();
971
+ test.xyz = '123';
972
+ test.create();
973
+
974
+ $httpBackend.flush();
975
+ }));
976
+
977
+ it('create should allow custom Accept', inject(function($httpBackend) {
978
+ var Test;
979
+
980
+ $httpBackend.expectPOST('/test', {test: {xyz: '123'}}, headerComparison({'Accept': 'text/plain'})).respond(200, {test: {id: 123, xyz: '123'}});
981
+
982
+ Test = factory(angular.extend(angular.copy(config), {httpConfig: {headers: {'Accept': 'text/plain'}}}));
983
+ var test = new Test();
984
+ test.xyz = '123';
985
+ test.create();
986
+
987
+ $httpBackend.flush();
988
+ }));
989
+
990
+ it('create should allow custom header', inject(function($httpBackend) {
991
+ var Test;
992
+
993
+ $httpBackend.expectPOST('/test', {test: {xyz: '123'}}, headerComparison({'Accept': 'application/json', 'X-Test': 'test'})).respond(200, {test: {id: 123, xyz: '123'}});
994
+
995
+ Test = factory(angular.extend(angular.copy(config), {httpConfig: {headers: {'X-Test': 'test'}}}));
996
+ var test = new Test();
997
+ test.xyz = '123';
998
+ test.create();
999
+
1000
+ $httpBackend.flush();
1001
+ }));
1002
+
1003
+ it('update should pass default $http options', inject(function($httpBackend) {
1004
+ var Test;
1005
+
1006
+ $httpBackend.expectPUT('/test/123', {test: {id: 123, xyz: '123'}}, headerComparison({'Accept': 'application/json'})).respond(200, {test: {id: 123, xyz: '123'}});
1007
+
1008
+ Test = factory(config);
1009
+ var test = new Test();
1010
+ test.id = 123;
1011
+ test.xyz = '123';
1012
+ test.update();
1013
+
1014
+ $httpBackend.flush();
1015
+ }));
1016
+
1017
+ it('update should allow custom Accept', inject(function($httpBackend) {
1018
+ var Test;
1019
+
1020
+ $httpBackend.expectPUT('/test/123', {test: {id: 123, xyz: '123'}}, headerComparison({'Accept': 'text/plain'})).respond(200, {test: {id: 123, xyz: '123'}});
1021
+
1022
+ Test = factory(angular.extend(angular.copy(config), {httpConfig: {headers: {'Accept': 'text/plain'}}}));
1023
+ var test = new Test();
1024
+ test.id = 123;
1025
+ test.xyz = '123';
1026
+ test.update();
1027
+
1028
+ $httpBackend.flush();
1029
+ }));
1030
+
1031
+ it('update should allow custom header', inject(function($httpBackend) {
1032
+ var Test;
1033
+
1034
+ $httpBackend.expectPUT('/test/123', {test: {id: 123, xyz: '123'}}, headerComparison({'Accept': 'application/json', 'X-Test': 'test'})).respond(200, {test: {id: 123, xyz: '123'}});
1035
+
1036
+ Test = factory(angular.extend(angular.copy(config), {httpConfig: {headers: {'X-Test': 'test'}}}));
1037
+ var test = new Test();
1038
+ test.id = 123;
1039
+ test.xyz = '123';
1040
+ test.update();
1041
+
1042
+ $httpBackend.flush();
1043
+ }));
1044
+ });
842
1045
  });
@@ -121,6 +121,7 @@
121
121
  RailsResource.rootName = config.name;
122
122
  RailsResource.rootPluralName = config.pluralName || config.name + 's';
123
123
  RailsResource.httpConfig = config.httpConfig || {};
124
+ RailsResource.httpConfig.headers = angular.extend({'Accept': 'application/json'}, RailsResource.httpConfig.headers || {});
124
125
  RailsResource.requestTransformers = [];
125
126
  RailsResource.responseInterceptors = [];
126
127
  RailsResource.defaultParams = config.defaultParams;
metadata CHANGED
@@ -1,19 +1,21 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: angularjs-rails-resource
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Tommy Odom
9
+ - Chris Chase
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2013-03-06 00:00:00.000000000 Z
13
+ date: 2013-04-09 00:00:00.000000000 Z
13
14
  dependencies: []
14
15
  description: A small AngularJS add-on for integrating with Rails via JSON more easily.
15
16
  email:
16
17
  - odom@finelineprototyping.com
18
+ - chris@finelineprototyping.com
17
19
  executables: []
18
20
  extensions: []
19
21
  extra_rdoc_files: []
@@ -24,6 +26,7 @@ files:
24
26
  - README.md
25
27
  - Rakefile
26
28
  - angularjs-rails-resource.gemspec
29
+ - karma.conf.js
27
30
  - lib/angularjs-rails-resource.rb
28
31
  - lib/angularjs-rails-resource/version.rb
29
32
  - test/lib/angular/angular-bootstrap-prettify.js
@@ -36,9 +39,8 @@ files:
36
39
  - test/lib/angular/angular.js
37
40
  - test/unit/angularjs/rails/resourceSpec.js
38
41
  - test/unit/helpers/spec_helper.js
39
- - testacular.conf.js
40
42
  - vendor/assets/javascripts/angularjs/rails/resource.js
41
- homepage: https://github.com/tpodom/angularjs-rails-resource
43
+ homepage: https://github.com/finelineprototyping/angularjs-rails-resource
42
44
  licenses: []
43
45
  post_install_message:
44
46
  rdoc_options: []
@@ -58,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
60
  version: '0'
59
61
  requirements: []
60
62
  rubyforge_project:
61
- rubygems_version: 1.8.23
63
+ rubygems_version: 1.8.25
62
64
  signing_key:
63
65
  specification_version: 3
64
66
  summary: ''