gom-client 0.0.2
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 +7 -0
- data/.gitignore +22 -0
- data/.travis.yml +17 -0
- data/Gemfile +2 -0
- data/Guardfile +8 -0
- data/README.md +146 -0
- data/Rakefile +2 -0
- data/gom-client-ruby.gemspec +36 -0
- data/lib/gom/client/version.rb +6 -0
- data/lib/gom/client.rb +226 -0
- data/spec/fixtures/vcr_cassettes/127_0_0_1_3000.yml +4469 -0
- data/spec/fixtures/vcr_cassettes/gom_dev_artcom_de.yml +243 -0
- data/spec/lib/gom/client/version_spec.rb +8 -0
- data/spec/lib/gom/client_spec.rb +306 -0
- data/spec/spec_helper.rb +43 -0
- metadata +173 -0
@@ -0,0 +1,243 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: http://gom.dev.artcom.de/tests/1
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: <node/>
|
9
|
+
headers:
|
10
|
+
Content-Type:
|
11
|
+
- application/xml
|
12
|
+
Accept:
|
13
|
+
- ! '*/*'
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 303
|
19
|
+
message: See Other
|
20
|
+
headers:
|
21
|
+
Date:
|
22
|
+
- Tue, 25 Jun 2013 15:16:44 GMT
|
23
|
+
Server:
|
24
|
+
- Apache/2.2.16 (Debian)
|
25
|
+
X-Powered-By:
|
26
|
+
- Phusion Passenger (mod_rails/mod_rack) 3.0.19
|
27
|
+
Access-Control-Allow-Origin:
|
28
|
+
- ! '*'
|
29
|
+
Access-Control-Allow-Methods:
|
30
|
+
- POST, GET, PUT, DELETE, OPTIONS
|
31
|
+
Access-Control-Allow-Credentials:
|
32
|
+
- 'true'
|
33
|
+
Access-Control-Max-Age:
|
34
|
+
- '86400'
|
35
|
+
Access-Control-Allow-Headers:
|
36
|
+
- X-Requested-With, X-HTTP-Method-Override, Content-Type, Accept, X-Http-Method-Override
|
37
|
+
Access-Control-Expose-Headers:
|
38
|
+
- Location, Content-Length
|
39
|
+
X-Ua-Compatible:
|
40
|
+
- IE=Edge,chrome=1
|
41
|
+
Cache-Control:
|
42
|
+
- no-cache
|
43
|
+
X-Request-Id:
|
44
|
+
- a8edde73641c86168d4d61eb75bbc920
|
45
|
+
X-Runtime:
|
46
|
+
- '0.004594'
|
47
|
+
X-Rack-Cache:
|
48
|
+
- invalidate, pass
|
49
|
+
Location:
|
50
|
+
- http://gom.dev.artcom.de/tests/1/58ddce3a-9bd4-4d7a-9416-469fda0f6541
|
51
|
+
Status:
|
52
|
+
- '303'
|
53
|
+
Vary:
|
54
|
+
- Accept-Encoding
|
55
|
+
Content-Length:
|
56
|
+
- '135'
|
57
|
+
Content-Type:
|
58
|
+
- text/html; charset=utf-8
|
59
|
+
body:
|
60
|
+
encoding: US-ASCII
|
61
|
+
string: <html><body>You are being <a href="http://gom.dev.artcom.de/tests/1/58ddce3a-9bd4-4d7a-9416-469fda0f6541">redirected</a>.</body></html>
|
62
|
+
http_version:
|
63
|
+
recorded_at: Tue, 25 Jun 2013 14:56:53 GMT
|
64
|
+
- request:
|
65
|
+
method: get
|
66
|
+
uri: http://gom.dev.artcom.de/tests/1/58ddce3a-9bd4-4d7a-9416-469fda0f6541
|
67
|
+
body:
|
68
|
+
encoding: US-ASCII
|
69
|
+
string: ''
|
70
|
+
headers:
|
71
|
+
Accept:
|
72
|
+
- application/json
|
73
|
+
User-Agent:
|
74
|
+
- Ruby
|
75
|
+
response:
|
76
|
+
status:
|
77
|
+
code: 200
|
78
|
+
message: OK
|
79
|
+
headers:
|
80
|
+
Date:
|
81
|
+
- Tue, 25 Jun 2013 15:16:44 GMT
|
82
|
+
Server:
|
83
|
+
- Apache/2.2.16 (Debian)
|
84
|
+
X-Powered-By:
|
85
|
+
- Phusion Passenger (mod_rails/mod_rack) 3.0.19
|
86
|
+
Access-Control-Allow-Origin:
|
87
|
+
- ! '*'
|
88
|
+
Access-Control-Allow-Methods:
|
89
|
+
- POST, GET, PUT, DELETE, OPTIONS
|
90
|
+
Access-Control-Allow-Credentials:
|
91
|
+
- 'true'
|
92
|
+
Access-Control-Max-Age:
|
93
|
+
- '86400'
|
94
|
+
Access-Control-Allow-Headers:
|
95
|
+
- X-Requested-With, X-HTTP-Method-Override, Content-Type, Accept, X-Http-Method-Override
|
96
|
+
Access-Control-Expose-Headers:
|
97
|
+
- Location, Content-Length
|
98
|
+
X-Ua-Compatible:
|
99
|
+
- IE=Edge,chrome=1
|
100
|
+
Etag:
|
101
|
+
- ! '"a429961940b70f2c84aeaf795fa72122"'
|
102
|
+
Cache-Control:
|
103
|
+
- max-age=0, private, must-revalidate
|
104
|
+
X-Request-Id:
|
105
|
+
- 88c9ff41af2dc7505c191419b2ae94db
|
106
|
+
X-Runtime:
|
107
|
+
- '0.002257'
|
108
|
+
X-Rack-Cache:
|
109
|
+
- miss
|
110
|
+
Status:
|
111
|
+
- '200'
|
112
|
+
Content-Length:
|
113
|
+
- '193'
|
114
|
+
Content-Type:
|
115
|
+
- application/json; charset=utf-8
|
116
|
+
body:
|
117
|
+
encoding: US-ASCII
|
118
|
+
string: ! "{\n \"node\": {\n \"uri\": \"/tests/1/58ddce3a-9bd4-4d7a-9416-469fda0f6541\",\n
|
119
|
+
\ \"mtime\": \"2013-06-25T17:16:44+02:00\",\n \"ctime\": \"2013-06-25T17:16:44+02:00\",\n
|
120
|
+
\ \"entries\": [\n \n ]\n }\n}"
|
121
|
+
http_version:
|
122
|
+
recorded_at: Tue, 25 Jun 2013 14:56:53 GMT
|
123
|
+
- request:
|
124
|
+
method: post
|
125
|
+
uri: http://gom.dev.artcom.de/tests/2
|
126
|
+
body:
|
127
|
+
encoding: US-ASCII
|
128
|
+
string: <node><attribute name='x'>u</attribute><attribute name='a'>23</attribute></node>
|
129
|
+
headers:
|
130
|
+
Content-Type:
|
131
|
+
- application/xml
|
132
|
+
Accept:
|
133
|
+
- ! '*/*'
|
134
|
+
User-Agent:
|
135
|
+
- Ruby
|
136
|
+
response:
|
137
|
+
status:
|
138
|
+
code: 303
|
139
|
+
message: See Other
|
140
|
+
headers:
|
141
|
+
Date:
|
142
|
+
- Tue, 25 Jun 2013 15:16:44 GMT
|
143
|
+
Server:
|
144
|
+
- Apache/2.2.16 (Debian)
|
145
|
+
X-Powered-By:
|
146
|
+
- Phusion Passenger (mod_rails/mod_rack) 3.0.19
|
147
|
+
Access-Control-Allow-Origin:
|
148
|
+
- ! '*'
|
149
|
+
Access-Control-Allow-Methods:
|
150
|
+
- POST, GET, PUT, DELETE, OPTIONS
|
151
|
+
Access-Control-Allow-Credentials:
|
152
|
+
- 'true'
|
153
|
+
Access-Control-Max-Age:
|
154
|
+
- '86400'
|
155
|
+
Access-Control-Allow-Headers:
|
156
|
+
- X-Requested-With, X-HTTP-Method-Override, Content-Type, Accept, X-Http-Method-Override
|
157
|
+
Access-Control-Expose-Headers:
|
158
|
+
- Location, Content-Length
|
159
|
+
X-Ua-Compatible:
|
160
|
+
- IE=Edge,chrome=1
|
161
|
+
Cache-Control:
|
162
|
+
- no-cache
|
163
|
+
X-Request-Id:
|
164
|
+
- 9a5376ef2153701f9827fee6075e6f5d
|
165
|
+
X-Runtime:
|
166
|
+
- '0.005069'
|
167
|
+
X-Rack-Cache:
|
168
|
+
- invalidate, pass
|
169
|
+
Location:
|
170
|
+
- http://gom.dev.artcom.de/tests/2/994d460d-1e45-48fd-9b43-90069ba49dce
|
171
|
+
Status:
|
172
|
+
- '303'
|
173
|
+
Vary:
|
174
|
+
- Accept-Encoding
|
175
|
+
Content-Length:
|
176
|
+
- '135'
|
177
|
+
Content-Type:
|
178
|
+
- text/html; charset=utf-8
|
179
|
+
body:
|
180
|
+
encoding: US-ASCII
|
181
|
+
string: <html><body>You are being <a href="http://gom.dev.artcom.de/tests/2/994d460d-1e45-48fd-9b43-90069ba49dce">redirected</a>.</body></html>
|
182
|
+
http_version:
|
183
|
+
recorded_at: Tue, 25 Jun 2013 14:56:53 GMT
|
184
|
+
- request:
|
185
|
+
method: get
|
186
|
+
uri: http://gom.dev.artcom.de/tests/2/994d460d-1e45-48fd-9b43-90069ba49dce
|
187
|
+
body:
|
188
|
+
encoding: US-ASCII
|
189
|
+
string: ''
|
190
|
+
headers:
|
191
|
+
Accept:
|
192
|
+
- application/json
|
193
|
+
User-Agent:
|
194
|
+
- Ruby
|
195
|
+
response:
|
196
|
+
status:
|
197
|
+
code: 200
|
198
|
+
message: OK
|
199
|
+
headers:
|
200
|
+
Date:
|
201
|
+
- Tue, 25 Jun 2013 15:16:44 GMT
|
202
|
+
Server:
|
203
|
+
- Apache/2.2.16 (Debian)
|
204
|
+
X-Powered-By:
|
205
|
+
- Phusion Passenger (mod_rails/mod_rack) 3.0.19
|
206
|
+
Access-Control-Allow-Origin:
|
207
|
+
- ! '*'
|
208
|
+
Access-Control-Allow-Methods:
|
209
|
+
- POST, GET, PUT, DELETE, OPTIONS
|
210
|
+
Access-Control-Allow-Credentials:
|
211
|
+
- 'true'
|
212
|
+
Access-Control-Max-Age:
|
213
|
+
- '86400'
|
214
|
+
Access-Control-Allow-Headers:
|
215
|
+
- X-Requested-With, X-HTTP-Method-Override, Content-Type, Accept, X-Http-Method-Override
|
216
|
+
Access-Control-Expose-Headers:
|
217
|
+
- Location, Content-Length
|
218
|
+
X-Ua-Compatible:
|
219
|
+
- IE=Edge,chrome=1
|
220
|
+
Etag:
|
221
|
+
- ! '"2728e0d11d84ba0f39b99860defc063c"'
|
222
|
+
Cache-Control:
|
223
|
+
- max-age=0, private, must-revalidate
|
224
|
+
X-Request-Id:
|
225
|
+
- 343a7e53632116d872b3591f89eb444f
|
226
|
+
X-Runtime:
|
227
|
+
- '0.002261'
|
228
|
+
X-Rack-Cache:
|
229
|
+
- miss
|
230
|
+
Status:
|
231
|
+
- '200'
|
232
|
+
Content-Length:
|
233
|
+
- '193'
|
234
|
+
Content-Type:
|
235
|
+
- application/json; charset=utf-8
|
236
|
+
body:
|
237
|
+
encoding: US-ASCII
|
238
|
+
string: ! "{\n \"node\": {\n \"uri\": \"/tests/2/994d460d-1e45-48fd-9b43-90069ba49dce\",\n
|
239
|
+
\ \"mtime\": \"2013-06-25T17:16:44+02:00\",\n \"ctime\": \"2013-06-25T17:16:44+02:00\",\n
|
240
|
+
\ \"entries\": [\n \n ]\n }\n}"
|
241
|
+
http_version:
|
242
|
+
recorded_at: Tue, 25 Jun 2013 14:56:53 GMT
|
243
|
+
recorded_with: VCR 2.5.0
|
@@ -0,0 +1,306 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Gom::Client do
|
4
|
+
it 'exists' do
|
5
|
+
Gom::Client.should be_kind_of(Class)
|
6
|
+
end
|
7
|
+
|
8
|
+
context 'VCR cassette' do
|
9
|
+
#let(:gom) { Gom::Client.new('http://gom.dev.artcom.de') }
|
10
|
+
let(:gom) { Gom::Client.new('http://127.0.0.1:3000') }
|
11
|
+
#let(:prefix) { gom.create!("/tests", {}) }
|
12
|
+
#let(:prefix) { "/tests/08ec4b58-38b3-44ac-9ea9-62b42a62b061" }
|
13
|
+
|
14
|
+
before(:all) {
|
15
|
+
VCR.insert_cassette('127.0.0.1:3000', :record => :new_episodes)
|
16
|
+
# VCR.insert_cassette('gom.dev.artcom.de', :record => :new_episodes)
|
17
|
+
}
|
18
|
+
after(:all) {
|
19
|
+
VCR.eject_cassette
|
20
|
+
}
|
21
|
+
|
22
|
+
it 'creates and retrieves new node with no attributes' do
|
23
|
+
(uri = gom.create!("/tests/1", {})).should match(%r(/tests/1/\w+))
|
24
|
+
(hash = gom.retrieve uri).should be_kind_of(Hash)
|
25
|
+
(node = hash[:node]).should be_kind_of(Hash)
|
26
|
+
node[:uri].should eq(uri)
|
27
|
+
node[:entries].should eq([])
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'creates and retrieves new node with some attributes' do
|
31
|
+
values = {:x => :u, :a => 23}
|
32
|
+
(uri = gom.create!("/tests/2", values)).should match(%r(/tests/2/\w+))
|
33
|
+
(hash = gom.retrieve uri).should be_kind_of(Hash)
|
34
|
+
(node = hash[:node]).should be_kind_of(Hash)
|
35
|
+
node[:uri].should eq(uri)
|
36
|
+
node[:entries].size.should be(2)
|
37
|
+
|
38
|
+
(hash = gom.retrieve "#{uri}:x").should be_kind_of(Hash)
|
39
|
+
hash[:attribute].should be_kind_of(Hash)
|
40
|
+
hash[:attribute][:value].should eq('u')
|
41
|
+
|
42
|
+
(hash = gom.retrieve "#{uri}:a").should be_kind_of(Hash)
|
43
|
+
hash[:attribute].should be_kind_of(Hash)
|
44
|
+
hash[:attribute][:value].should eq('23')
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'with parent node' do
|
48
|
+
let(:nuri) { uniq_node_uri }
|
49
|
+
before(:each) { gom.update nuri }
|
50
|
+
|
51
|
+
it 'updates node with attributes' do
|
52
|
+
values = { "foo1" => "val1", "foo2" => "val2" }
|
53
|
+
(h = gom.update nuri, values).should be_kind_of(Hash)
|
54
|
+
h[:status].should eq(200)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'updates and retrieves attributes' do
|
59
|
+
uri = uniq_attr_uri
|
60
|
+
val = 'some text'
|
61
|
+
(gom.update uri, val).should eq(val)
|
62
|
+
(hash = gom.retrieve uri).should be_kind_of(Hash)
|
63
|
+
hash[:attribute].should be
|
64
|
+
hash[:attribute][:value].should eq(val)
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'updates attribute containing ampersand' do
|
68
|
+
uri = uniq_attr_uri
|
69
|
+
val = 'Hallo & Ciao'
|
70
|
+
(gom.update uri, val).should eq(val)
|
71
|
+
(hash = gom.retrieve uri).should be_kind_of(Hash)
|
72
|
+
hash[:attribute].should be
|
73
|
+
hash[:attribute][:value].should eq(val)
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'updates existing attribute to empty value' do
|
77
|
+
uri = uniq_attr_uri
|
78
|
+
gom.update(uri, "something")
|
79
|
+
|
80
|
+
gom.update uri, ""
|
81
|
+
(hash = gom.retrieve uri).should be_kind_of(Hash)
|
82
|
+
hash[:attribute].should be
|
83
|
+
hash[:attribute][:value].should eq('')
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'updates new attribute to empty value' do
|
87
|
+
uri = uniq_attr_uri
|
88
|
+
gom.update(uri, '')
|
89
|
+
(hash = gom.retrieve uri).should be_kind_of(Hash)
|
90
|
+
hash[:attribute].should be
|
91
|
+
hash[:attribute][:value].should eq('')
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'raises a 404 on retrieval of non-existing nodes' do
|
95
|
+
expect { gom.retrieve! "/no/such/node" }.to raise_error(
|
96
|
+
Gom::HttpError, %r(404 Not Found\s+while GETting /no/such/node)
|
97
|
+
)
|
98
|
+
end
|
99
|
+
|
100
|
+
context 'destroying things' do
|
101
|
+
let(:nuri) { uniq_node_uri }
|
102
|
+
let(:auri) { "#{nuri}:foo" }
|
103
|
+
let(:val) { "wello horld!" }
|
104
|
+
before(:each) { (gom.update auri, val).should eq(val) }
|
105
|
+
|
106
|
+
it 'destroys attributes' do
|
107
|
+
expect{gom.destroy auri}.to_not raise_error
|
108
|
+
gom.retrieve(auri).should be(nil)
|
109
|
+
expect { gom.retrieve!(auri) }.to raise_error(
|
110
|
+
Gom::HttpError, %r(404 Not Found\s+while GETting #{auri})
|
111
|
+
)
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'destroys nodes' do
|
115
|
+
expect{gom.destroy nuri}.to_not raise_error
|
116
|
+
gom.retrieve(nuri).should be(nil)
|
117
|
+
|
118
|
+
expect { gom.retrieve!(nuri) }.to raise_error(
|
119
|
+
Gom::HttpError, %r(404 Not Found\s+while GETting #{nuri})
|
120
|
+
)
|
121
|
+
expect { gom.retrieve!(auri) }.to raise_error(
|
122
|
+
Gom::HttpError, %r(404 Not Found\s+while GETting #{auri})
|
123
|
+
)
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'destroys non-existing node' do
|
127
|
+
expect { gom.destroy!(nuri) }.to_not raise_error
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'destroys non-existing attribute' do
|
131
|
+
expect { gom.destroy!(auri) }.to_not raise_error
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
context 'running server side scripts' do
|
136
|
+
it 'raises on script AND path over-specified request' do
|
137
|
+
expect {
|
138
|
+
gom.run_script(:script => "something", :path => "something else")
|
139
|
+
}.to raise_error(
|
140
|
+
ArgumentError, %r(must not provide script AND path)
|
141
|
+
)
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'raises on script NOR path under-specified request' do
|
145
|
+
expect { gom.run_script }.to raise_error(
|
146
|
+
ArgumentError, %r(must provide script OR path)
|
147
|
+
)
|
148
|
+
end
|
149
|
+
|
150
|
+
context 'posted script' do
|
151
|
+
it 'runs simple posted script' do
|
152
|
+
rc = gom.run_script(:script => '"hello"')
|
153
|
+
rc.body.should eq('hello')
|
154
|
+
rc.code.should eq('200')
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'passes parameter from request to the script' do
|
158
|
+
rc = gom.run_script(script: 'params.test', :params => {test: 'p1'})
|
159
|
+
rc.body.should eq('p1')
|
160
|
+
rc.code.should eq('200')
|
161
|
+
end
|
162
|
+
|
163
|
+
it 'passes multiple parameter to script' do
|
164
|
+
rc = gom.run_script(script: <<-JS, params: {p1: 'p1', p2: 'p2'})
|
165
|
+
params.p1 + ':' + params.p2
|
166
|
+
JS
|
167
|
+
rc.body.should eq('p1:p2')
|
168
|
+
rc.code.should eq('200')
|
169
|
+
end
|
170
|
+
|
171
|
+
it 'raises error on broken scripts' do
|
172
|
+
expect { gom.run_script script: 'intentional_error' }.to raise_error(
|
173
|
+
Gom::HttpError,
|
174
|
+
/400 Bad Request\s+.+intentional_error is not defined/m
|
175
|
+
)
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
context 'stored scripts' do
|
180
|
+
let(:script_uri) { uniq_attr_uri }
|
181
|
+
|
182
|
+
it 'runs a simple stored script' do
|
183
|
+
gom.update(script_uri, '"hello"')
|
184
|
+
rc = gom.run_script(path: script_uri)
|
185
|
+
rc.body.should eq('hello')
|
186
|
+
rc.code.should eq('200')
|
187
|
+
end
|
188
|
+
|
189
|
+
it 'passes parameter from request to the script' do
|
190
|
+
gom.update(script_uri, 'params.p1')
|
191
|
+
rc = gom.run_script(path: script_uri, :params => {p1: 'p1'})
|
192
|
+
rc.body.should eq('p1')
|
193
|
+
rc.code.should eq('200')
|
194
|
+
end
|
195
|
+
|
196
|
+
it 'passes multiple parameter to script' do
|
197
|
+
gom.update(script_uri, "params.p1 + ':' + params.p2")
|
198
|
+
rc = gom.run_script(path: script_uri, params: {p1: 'p1', p2: 'p2'})
|
199
|
+
rc.body.should eq('p1:p2')
|
200
|
+
rc.code.should eq('200')
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
context 'observer registrations' do
|
206
|
+
let(:cb_url) { 'http://localhost:4042/notification' }
|
207
|
+
|
208
|
+
it 'raises on no args at all' do
|
209
|
+
expect { gom.register_observer }.to raise_error(
|
210
|
+
ArgumentError, /callback_url must not be nil/
|
211
|
+
)
|
212
|
+
end
|
213
|
+
|
214
|
+
it 'raises on missing target node argument' do
|
215
|
+
expect { gom.register_observer(callback_url: cb_url) }.to raise_error(
|
216
|
+
ArgumentError, /node must not be nil/
|
217
|
+
)
|
218
|
+
end
|
219
|
+
|
220
|
+
it 'raises on invalid format' do
|
221
|
+
args = { callback_url: cb_url, node: '/some/node', format: 'Excel' }
|
222
|
+
expect { gom.register_observer(args) }.to raise_error(
|
223
|
+
ArgumentError, /invalid format: '#{args[:format]}'/
|
224
|
+
)
|
225
|
+
end
|
226
|
+
|
227
|
+
context 'anonymous oberserver' do
|
228
|
+
let(:target_uri) { uniq_node_uri }
|
229
|
+
|
230
|
+
it 'registers with node and callback' do
|
231
|
+
obs = gom.register_observer(node: target_uri, callback_url: cb_url)
|
232
|
+
obs.should match %r(/gom/observer#{target_uri}/\..+)
|
233
|
+
gom.retrieve_val("#{obs}:observed_uri").should eq(target_uri)
|
234
|
+
gom.retrieve_val("#{obs}:callback_url").should eq(cb_url)
|
235
|
+
gom.retrieve_val("#{obs}:accept").should eq("application/json")
|
236
|
+
gom.retrieve("#{obs}:operations").should be_nil
|
237
|
+
gom.retrieve("#{obs}:uri_regexp").should be_nil
|
238
|
+
gom.retrieve("#{obs}:condition_script").should be_nil
|
239
|
+
expect { gom.destroy obs }.to_not raise_error
|
240
|
+
end
|
241
|
+
|
242
|
+
it 'registers with filters, node and callback' do
|
243
|
+
obs = gom.register_observer(
|
244
|
+
node: target_uri, callback_url: cb_url, filters: {
|
245
|
+
'operations' => 'update,create',
|
246
|
+
'uri_regexp' => '*',
|
247
|
+
'condition_script' => '1 === 1;'
|
248
|
+
}
|
249
|
+
)
|
250
|
+
|
251
|
+
obs.should match %r(/gom/observer#{target_uri}/\..+)
|
252
|
+
gom.retrieve_val("#{obs}:observed_uri").should eq(target_uri)
|
253
|
+
gom.retrieve_val("#{obs}:callback_url").should eq(cb_url)
|
254
|
+
gom.retrieve_val("#{obs}:accept").should eq("application/json")
|
255
|
+
gom.retrieve_val("#{obs}:operations").should eq('update,create')
|
256
|
+
gom.retrieve_val("#{obs}:uri_regexp").should eq('*')
|
257
|
+
gom.retrieve_val("#{obs}:condition_script").should eq('1 === 1;')
|
258
|
+
|
259
|
+
expect { gom.destroy obs }.to_not raise_error
|
260
|
+
end
|
261
|
+
end # ~anonymous oberserver
|
262
|
+
|
263
|
+
context 'named observer' do
|
264
|
+
let(:target_uri) { uniq_node_uri }
|
265
|
+
let(:name) { "o1234" } ##{Time.now.tv_usec}" }
|
266
|
+
|
267
|
+
it 'supports filters' do
|
268
|
+
# with node, callback_url and filters
|
269
|
+
obs = gom.register_observer(
|
270
|
+
name: name, node: target_uri, callback_url: cb_url, filters: {
|
271
|
+
'operations' => 'update,create',
|
272
|
+
'uri_regexp' => '*',
|
273
|
+
'condition_script' => '1 === 1;'
|
274
|
+
}
|
275
|
+
)
|
276
|
+
|
277
|
+
obs.should eq("/gom/observer#{target_uri}/.#{name}")
|
278
|
+
gom.retrieve_val("#{obs}:observed_uri").should eq(target_uri)
|
279
|
+
gom.retrieve_val("#{obs}:callback_url").should eq(cb_url)
|
280
|
+
gom.retrieve_val("#{obs}:accept").should eq("application/json")
|
281
|
+
gom.retrieve_val("#{obs}:operations").should eq('update,create')
|
282
|
+
gom.retrieve_val("#{obs}:uri_regexp").should eq('*')
|
283
|
+
gom.retrieve_val("#{obs}:condition_script").should eq('1 === 1;')
|
284
|
+
|
285
|
+
expect { gom.destroy obs }.to_not raise_error
|
286
|
+
|
287
|
+
# register a second time with differnt name and changed optins to
|
288
|
+
# check whether the destroy clean-up really works
|
289
|
+
obs = gom.register_observer(
|
290
|
+
name: name, node: target_uri, callback_url: cb_url
|
291
|
+
)
|
292
|
+
|
293
|
+
obs.should eq("/gom/observer#{target_uri}/.#{name}")
|
294
|
+
gom.retrieve_val("#{obs}:observed_uri").should eq(target_uri)
|
295
|
+
gom.retrieve_val("#{obs}:callback_url").should eq(cb_url)
|
296
|
+
gom.retrieve_val("#{obs}:accept").should eq("application/json")
|
297
|
+
gom.retrieve_val("#{obs}:operations").should be(nil)
|
298
|
+
gom.retrieve_val("#{obs}:uri_regexp").should be(nil)
|
299
|
+
gom.retrieve_val("#{obs}:condition_script").should be(nil)
|
300
|
+
|
301
|
+
expect { gom.destroy obs }.to_not raise_error
|
302
|
+
end
|
303
|
+
end # ~ 'named observer'
|
304
|
+
end
|
305
|
+
end
|
306
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__))
|
2
|
+
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
|
4
|
+
require 'gom/client'
|
5
|
+
require 'webmock/rspec'
|
6
|
+
require 'vcr'
|
7
|
+
|
8
|
+
module SpecHelpers
|
9
|
+
|
10
|
+
def next_uniq_seq_no
|
11
|
+
$__uniq_seq_no += 1
|
12
|
+
end
|
13
|
+
def uniq_node_uri(seq_no = next_uniq_seq_no)
|
14
|
+
#t = Time.now
|
15
|
+
#uri = "/some/random/node/n#{t.tv_sec}_#{t.tv_usec}"
|
16
|
+
uri = "/test/node/n#{seq_no}"
|
17
|
+
end
|
18
|
+
def uniq_attr_uri(seq_no = next_uniq_seq_no)
|
19
|
+
#t = Time.now
|
20
|
+
#uri = "/some/random/node/n#{t.tv_usec}:a#{t.tv_usec}"
|
21
|
+
uri = "/test/node/n#{seq_no}:a#{seq_no}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
RSpec.configure do |config|
|
27
|
+
|
28
|
+
$__uniq_seq_no = 1
|
29
|
+
config.include SpecHelpers
|
30
|
+
|
31
|
+
VCR.configure do |c|
|
32
|
+
basedir = File.dirname(__FILE__)
|
33
|
+
c.cassette_library_dir = File.join(basedir, 'fixtures', 'vcr_cassettes')
|
34
|
+
c.allow_http_connections_when_no_cassette = true
|
35
|
+
c.hook_into :webmock # or :fakeweb
|
36
|
+
end
|
37
|
+
|
38
|
+
config.before :each do
|
39
|
+
end
|
40
|
+
|
41
|
+
config.after :each do
|
42
|
+
end
|
43
|
+
end
|