collection-json-browser 0.0.9 → 0.0.10

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.
@@ -13,20 +13,42 @@ describe('ApiController', function(){
13
13
  rel: "My cat is cooler",
14
14
  render: "image"
15
15
  };
16
+
16
17
  var responseData = {
17
18
  collection: {
18
19
  version: "1.0",
19
20
  href: "/api",
20
21
  links: [ link, image ],
22
+ items: [ getItem(1), getItem(2) ],
21
23
  template: {
22
24
  data: [
23
- {name: ''},
24
- {age: 2}
25
+ {
26
+ name: "title",
27
+ prompt: "Post title",
28
+ value: ""
29
+ },
30
+ {
31
+ name: "tag",
32
+ value: ""
33
+ },
25
34
  ]
26
35
  }
27
36
  }
28
37
  }
29
38
 
39
+ function getItem(i){
40
+ return {
41
+ href: "/api/posts/" + i,
42
+ rel: "post",
43
+ prompt: "Post",
44
+ data: [{
45
+ name: "title",
46
+ prompt: "Post title",
47
+ value: "awesome post " + i
48
+ }]
49
+ }
50
+ }
51
+
30
52
  beforeEach(inject(function(_$httpBackend_, $location, $rootScope, $controller) {
31
53
  $httpBackend = _$httpBackend_;
32
54
  var root = "http://localhost:3000"
@@ -55,6 +77,47 @@ describe('ApiController', function(){
55
77
  expect(JSON.parse(scope.raw)).toEqual(responseData);
56
78
  });
57
79
 
80
+ describe('template', function(){
81
+ var t;
82
+ beforeEach(function(){
83
+ t = responseData.collection.template
84
+ })
85
+
86
+ it('sets the template from response data', function() {
87
+ expect(scope.template).toBeUndefined();
88
+ $httpBackend.flush();
89
+
90
+ expect(scope.template).toEqual(responseData.collection.template.data);
91
+ });
92
+
93
+ it('assigns undefined when response data does not contain template', function() {
94
+ responseData.collection.template = undefined
95
+ scope.template = t
96
+ $httpBackend.flush();
97
+
98
+ expect(scope.template).toBeUndefined();
99
+ });
100
+
101
+ afterEach(function(){
102
+ responseData.collection.template = t
103
+ })
104
+ })
105
+
106
+ it('sets the itemPaths from response data', function() {
107
+ expect(scope.itemPaths).toBeUndefined();
108
+ $httpBackend.flush();
109
+
110
+ var href1 = getItem(1).href
111
+ var href2 = getItem(2).href
112
+ expect(scope.itemPaths).toEqual(
113
+ [
114
+ {name: "-- None (POST create) --", value: ""},
115
+ {name: href1, value: href1},
116
+ {name: href2, value: href2}
117
+ ]
118
+ );
119
+ });
120
+
58
121
  it('sets location path', function(){
59
122
  expect(location.path()).toEqual('');
60
123
  $httpBackend.flush();
@@ -87,6 +150,7 @@ describe('ApiController', function(){
87
150
  it('post the form when fromRel is not edit-form', function(){
88
151
  $httpBackend.expectPOST('/api')
89
152
 
153
+ scope.template = responseData.collection.template.data
90
154
  scope.fromRel = 'some-stuff'
91
155
  scope.submit()
92
156
 
@@ -94,9 +158,9 @@ describe('ApiController', function(){
94
158
  })
95
159
 
96
160
  it('put the form when fromRel is edit-form', function(){
97
- spyOn(location, 'url').andReturn('/api/posts/1')
98
161
  $httpBackend.expectPUT('/api/posts/1')
99
162
 
163
+ scope.template = responseData.collection.template.data
100
164
  scope.fromRel = 'edit-form'
101
165
  scope.submit()
102
166
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: collection-json-browser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
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-08-25 00:00:00.000000000 Z
12
+ date: 2013-09-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails