ashikawa-core 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +3 -3
- data/CHANGELOG.md +49 -0
- data/Gemfile +3 -2
- data/Gemfile.devtools +14 -22
- data/Guardfile +3 -2
- data/README.md +37 -6
- data/Rakefile +2 -1
- data/ashikawa-core.gemspec +2 -2
- data/cache/Mac_applications +1 -0
- data/config/devtools.yml +5 -0
- data/config/flay.yml +1 -1
- data/config/flog.yml +1 -2
- data/config/reek.yml +1 -1
- data/config/rubocop.yml +23 -25
- data/lib/ashikawa-core.rb +6 -5
- data/lib/ashikawa-core/collection.rb +142 -165
- data/lib/ashikawa-core/configuration.rb +41 -2
- data/lib/ashikawa-core/connection.rb +17 -16
- data/lib/ashikawa-core/cursor.rb +18 -12
- data/lib/ashikawa-core/database.rb +69 -59
- data/lib/ashikawa-core/document.rb +22 -20
- data/lib/ashikawa-core/edge.rb +8 -6
- data/lib/ashikawa-core/exceptions/client_error.rb +1 -0
- data/lib/ashikawa-core/exceptions/client_error/authentication_failed.rb +25 -0
- data/lib/ashikawa-core/exceptions/client_error/bad_syntax.rb +3 -2
- data/lib/ashikawa-core/exceptions/client_error/resource_not_found.rb +3 -2
- data/lib/ashikawa-core/exceptions/client_error/resource_not_found/collection_not_found.rb +3 -2
- data/lib/ashikawa-core/exceptions/client_error/resource_not_found/document_not_found.rb +3 -2
- data/lib/ashikawa-core/exceptions/client_error/resource_not_found/index_not_found.rb +3 -2
- data/lib/ashikawa-core/exceptions/no_collection_provided.rb +1 -0
- data/lib/ashikawa-core/exceptions/server_error.rb +1 -0
- data/lib/ashikawa-core/exceptions/server_error/json_error.rb +3 -2
- data/lib/ashikawa-core/figure.rb +18 -17
- data/lib/ashikawa-core/index.rb +15 -5
- data/lib/ashikawa-core/key_options.rb +5 -4
- data/lib/ashikawa-core/query.rb +38 -27
- data/lib/ashikawa-core/request_preprocessor.rb +4 -3
- data/lib/ashikawa-core/response_preprocessor.rb +64 -24
- data/lib/ashikawa-core/status.rb +1 -0
- data/lib/ashikawa-core/transaction.rb +12 -11
- data/lib/ashikawa-core/version.rb +2 -1
- data/spec/acceptance/basic_spec.rb +117 -116
- data/spec/acceptance/index_spec.rb +18 -15
- data/spec/acceptance/query_spec.rb +61 -64
- data/spec/acceptance/spec_helper.rb +26 -3
- data/spec/acceptance/transactions_spec.rb +12 -16
- data/spec/setup/arangodb.sh +2 -2
- data/spec/unit/collection_spec.rb +224 -242
- data/spec/unit/configuration_spec.rb +64 -0
- data/spec/unit/connection_spec.rb +121 -111
- data/spec/unit/cursor_spec.rb +78 -65
- data/spec/unit/database_spec.rb +112 -163
- data/spec/unit/document_spec.rb +74 -70
- data/spec/unit/edge_spec.rb +45 -33
- data/spec/unit/exception_spec.rb +28 -38
- data/spec/unit/figure_spec.rb +44 -47
- data/spec/unit/index_spec.rb +27 -24
- data/spec/unit/key_options_spec.rb +19 -17
- data/spec/unit/query_spec.rb +186 -135
- data/spec/unit/spec_helper.rb +14 -3
- data/spec/unit/status_spec.rb +37 -37
- data/spec/unit/transaction_spec.rb +71 -74
- data/tasks/adjustments.rake +10 -34
- metadata +11 -13
- data/spec/acceptance/arango_helper.rb +0 -27
- data/spec/acceptance_auth/arango_helper.rb +0 -30
- data/spec/acceptance_auth/auth_spec.rb +0 -40
- data/spec/acceptance_auth/spec_helper.rb +0 -6
@@ -0,0 +1,64 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'unit/spec_helper'
|
3
|
+
require 'ashikawa-core/configuration'
|
4
|
+
|
5
|
+
describe Ashikawa::Core::Configuration do
|
6
|
+
let(:url) { double }
|
7
|
+
let(:logger) { double }
|
8
|
+
let(:adapter) { double }
|
9
|
+
let(:connection) { double }
|
10
|
+
let(:username) { double }
|
11
|
+
let(:password) { double }
|
12
|
+
|
13
|
+
its(:url) { should be_nil }
|
14
|
+
its(:logger) { should be_nil }
|
15
|
+
its(:adapter) { should be_nil }
|
16
|
+
|
17
|
+
it 'should raise an Argument error if the URL is missing' do
|
18
|
+
expect do
|
19
|
+
subject.connection
|
20
|
+
end.to raise_error(ArgumentError, /either an url or a connection/)
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'provided with connection' do
|
24
|
+
before { subject.connection = connection }
|
25
|
+
its(:connection) { should be connection }
|
26
|
+
end
|
27
|
+
|
28
|
+
describe 'provided with url, logger and adapter' do
|
29
|
+
before do
|
30
|
+
subject.url = url
|
31
|
+
subject.logger = logger
|
32
|
+
subject.adapter = adapter
|
33
|
+
end
|
34
|
+
|
35
|
+
its(:url) { should be url }
|
36
|
+
its(:logger) { should be logger }
|
37
|
+
its(:adapter) { should be adapter }
|
38
|
+
|
39
|
+
it 'should construct a connection' do
|
40
|
+
expect(Ashikawa::Core::Connection).to receive(:new)
|
41
|
+
.with(url, { logger: logger, adapter: adapter })
|
42
|
+
.and_return(connection)
|
43
|
+
expect(subject.connection).to be connection
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe 'set up authentication' do
|
48
|
+
before do
|
49
|
+
subject.url = url
|
50
|
+
allow(Ashikawa::Core::Connection).to receive(:new)
|
51
|
+
.and_return(connection)
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should setup authentication' do
|
55
|
+
expect(connection).to receive(:authenticate_with)
|
56
|
+
.with({ username: username, password: password })
|
57
|
+
.and_return(connection)
|
58
|
+
|
59
|
+
subject.username = username
|
60
|
+
subject.password = password
|
61
|
+
subject.connection
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -1,248 +1,258 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
1
2
|
require 'unit/spec_helper'
|
2
3
|
require 'ashikawa-core/connection'
|
3
4
|
|
4
5
|
describe Ashikawa::Core::Connection do
|
5
6
|
let(:request_stub) { Faraday::Adapter::Test::Stubs.new }
|
6
|
-
let(:response_headers) { {
|
7
|
-
subject { Ashikawa::Core::Connection.new(ARANGO_HOST, :
|
7
|
+
let(:response_headers) { { 'content-type' => 'application/json; charset=utf-8' } }
|
8
|
+
subject { Ashikawa::Core::Connection.new(ARANGO_HOST, adapter: [:test, request_stub]) }
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
subject.port.should == 8529
|
13
|
-
end
|
10
|
+
its(:scheme) { should eq('http') }
|
11
|
+
its(:host) { should eq('localhost') }
|
12
|
+
its(:port) { should eq(8529) }
|
14
13
|
|
15
|
-
it
|
16
|
-
request_stub.get(
|
17
|
-
[200, response_headers, JSON.generate({
|
14
|
+
it 'should send a get request' do
|
15
|
+
request_stub.get('/_api/my/path') do
|
16
|
+
[200, response_headers, JSON.generate({ 'name' => 'dude' })]
|
18
17
|
end
|
19
18
|
|
20
|
-
subject.send_request
|
19
|
+
subject.send_request 'my/path'
|
21
20
|
|
22
21
|
request_stub.verify_stubbed_calls
|
23
22
|
end
|
24
23
|
|
25
|
-
it
|
26
|
-
request_stub.post(
|
27
|
-
request[:body].
|
28
|
-
[200, response_headers, JSON.generate({
|
24
|
+
it 'should send a post request' do
|
25
|
+
request_stub.post('/_api/my/path') do |request|
|
26
|
+
expect(request[:body]).to eq("{\"name\":\"new_collection\"}")
|
27
|
+
[200, response_headers, JSON.generate({ 'name' => 'dude' })]
|
29
28
|
end
|
30
29
|
|
31
|
-
subject.send_request
|
32
|
-
|
30
|
+
subject.send_request 'my/path', post: { name: 'new_collection' }
|
33
31
|
request_stub.verify_stubbed_calls
|
34
32
|
end
|
35
33
|
|
36
|
-
it
|
37
|
-
request_stub.put(
|
38
|
-
request[:body].
|
39
|
-
[200, response_headers, JSON.generate({
|
34
|
+
it 'should send a put request' do
|
35
|
+
request_stub.put('/_api/my/path') do |request|
|
36
|
+
expect(request[:body]).to eq('{"name":"new_collection"}')
|
37
|
+
[200, response_headers, JSON.generate({ 'name' => 'dude' })]
|
40
38
|
end
|
41
39
|
|
42
|
-
subject.send_request
|
43
|
-
|
40
|
+
subject.send_request 'my/path', put: { name: 'new_collection' }
|
44
41
|
request_stub.verify_stubbed_calls
|
45
42
|
end
|
46
43
|
|
47
|
-
it
|
48
|
-
request_stub.delete(
|
49
|
-
[200, response_headers, JSON.generate({
|
44
|
+
it 'should send a delete request' do
|
45
|
+
request_stub.delete('/_api/my/path') do |request|
|
46
|
+
[200, response_headers, JSON.generate({ 'name' => 'dude' })]
|
50
47
|
end
|
51
48
|
|
52
|
-
subject.send_request
|
53
|
-
|
49
|
+
subject.send_request 'my/path', delete: { }
|
54
50
|
request_stub.verify_stubbed_calls
|
55
51
|
end
|
56
52
|
|
57
|
-
it
|
58
|
-
request_stub.post(
|
59
|
-
req[:body].
|
60
|
-
[200, response_headers, JSON.generate({
|
53
|
+
it 'should write JSON request' do
|
54
|
+
request_stub.post('/_api/my/path') do |req|
|
55
|
+
expect(req[:body]).to eq('{"test":1}')
|
56
|
+
[200, response_headers, JSON.generate({ 'name' => 'dude' })]
|
61
57
|
end
|
62
58
|
|
63
|
-
subject.send_request(
|
59
|
+
subject.send_request('my/path', post: { 'test' => 1 })
|
64
60
|
request_stub.verify_stubbed_calls
|
65
61
|
end
|
66
62
|
|
67
|
-
it
|
68
|
-
request_stub.get(
|
69
|
-
[200, response_headers,
|
63
|
+
it 'should parse JSON response' do
|
64
|
+
request_stub.get('/_api/my/path') do
|
65
|
+
[200, response_headers, '{"name":"dude"}']
|
70
66
|
end
|
71
67
|
|
72
|
-
subject.send_request(
|
68
|
+
expect(subject.send_request('my/path')).to eq({ 'name' => 'dude' })
|
73
69
|
request_stub.verify_stubbed_calls
|
74
70
|
end
|
75
71
|
|
76
|
-
describe
|
77
|
-
it
|
78
|
-
subject.authentication
|
72
|
+
describe 'authentication' do
|
73
|
+
it 'should have authentication turned off by default' do
|
74
|
+
expect(subject.authentication?).to be_false
|
79
75
|
end
|
80
76
|
|
81
|
-
it
|
82
|
-
subject.authenticate_with
|
83
|
-
subject.authentication
|
77
|
+
it 'should tell if authentication is enabled' do
|
78
|
+
subject.authenticate_with(username: 'testuser', password: 'testpassword')
|
79
|
+
expect(subject.authentication?).to be_true
|
84
80
|
end
|
85
81
|
|
86
|
-
it
|
87
|
-
expect
|
88
|
-
subject.authenticate_with
|
89
|
-
|
82
|
+
it 'should only accept username & password pairs' do
|
83
|
+
expect do
|
84
|
+
subject.authenticate_with(username: 'kitty')
|
85
|
+
end.to raise_error(ArgumentError)
|
90
86
|
|
91
|
-
expect
|
92
|
-
subject.authenticate_with
|
93
|
-
|
87
|
+
expect do
|
88
|
+
subject.authenticate_with(password: 'cheezburger?')
|
89
|
+
end.to raise_error(ArgumentError)
|
94
90
|
end
|
95
91
|
|
96
|
-
it
|
97
|
-
subject.authenticate_with(:
|
92
|
+
it 'should allow chaining' do
|
93
|
+
expect(subject.authenticate_with(username: 'a', password: 'b')).to eq(subject)
|
98
94
|
end
|
99
95
|
|
100
|
-
it
|
101
|
-
pending
|
96
|
+
it 'should send the authentication data with every GET request' do
|
97
|
+
pending 'Find out how to check for basic auth via Faraday Stubs'
|
102
98
|
|
103
|
-
request_stub.get(
|
104
|
-
[200, response_headers, JSON.generate({
|
99
|
+
request_stub.get('/_api/my/path') do |request|
|
100
|
+
[200, response_headers, JSON.generate({ 'name' => 'dude' })]
|
105
101
|
end
|
106
102
|
|
107
|
-
subject.authenticate_with :
|
108
|
-
subject.send_request
|
103
|
+
subject.authenticate_with username: 'user', password: 'pass'
|
104
|
+
subject.send_request 'my/path'
|
109
105
|
|
110
106
|
request_stub.verify_stubbed_calls
|
111
107
|
end
|
112
108
|
end
|
113
109
|
|
114
|
-
describe
|
115
|
-
let(:error_message) {
|
110
|
+
describe 'exception handling' do
|
111
|
+
let(:error_message) { 'cannot write file' }
|
116
112
|
let(:error_num) { 15 }
|
117
113
|
|
118
114
|
it "should throw a general client error for I'm a teapot" do
|
119
|
-
request_stub.get(
|
115
|
+
request_stub.get('/_api/bad/request') do
|
120
116
|
[
|
121
117
|
418,
|
122
118
|
response_headers,
|
123
|
-
JSON.generate({
|
119
|
+
JSON.generate({ 'error' => true, 'errorNum' => error_num, 'errorMessage' => error_message })
|
124
120
|
]
|
125
121
|
end
|
126
122
|
|
127
123
|
expect do
|
128
|
-
subject.send_request(
|
124
|
+
subject.send_request('bad/request')
|
129
125
|
end.to raise_error(Ashikawa::Core::ClientError, "#{error_num}: #{error_message}")
|
130
126
|
|
131
127
|
request_stub.verify_stubbed_calls
|
132
128
|
end
|
133
129
|
|
134
|
-
it
|
135
|
-
request_stub.get(
|
136
|
-
[400, response_headers,
|
130
|
+
it 'should throw its own exception when doing a bad request' do
|
131
|
+
request_stub.get('/_api/bad/request') do
|
132
|
+
[400, response_headers, '']
|
137
133
|
end
|
138
134
|
|
139
135
|
expect do
|
140
|
-
subject.send_request(
|
136
|
+
subject.send_request('bad/request')
|
141
137
|
end.to raise_error(Ashikawa::Core::BadSyntax)
|
142
138
|
|
143
139
|
request_stub.verify_stubbed_calls
|
144
140
|
end
|
145
141
|
|
146
|
-
it
|
147
|
-
request_stub.get(
|
142
|
+
it 'should throw its own exception when doing a bad request' do
|
143
|
+
request_stub.get('/_api/secret') do
|
144
|
+
[401, response_headers, '']
|
145
|
+
end
|
146
|
+
|
147
|
+
expect do
|
148
|
+
subject.send_request('secret')
|
149
|
+
end.to raise_error(Ashikawa::Core::AuthenticationFailed)
|
150
|
+
|
151
|
+
request_stub.verify_stubbed_calls
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'should throw a general server error for the generic server error' do
|
155
|
+
request_stub.get('/_api/bad/request') do
|
148
156
|
[
|
149
157
|
500,
|
150
158
|
response_headers,
|
151
|
-
JSON.generate({
|
159
|
+
JSON.generate({ 'error' => true, 'errorNum' => error_num, 'errorMessage' => error_message })
|
152
160
|
]
|
153
161
|
end
|
154
162
|
|
155
163
|
expect do
|
156
|
-
subject.send_request(
|
164
|
+
subject.send_request('bad/request')
|
157
165
|
end.to raise_error(Ashikawa::Core::ServerError, "#{error_num}: #{error_message}")
|
158
166
|
|
159
167
|
request_stub.verify_stubbed_calls
|
160
168
|
end
|
161
169
|
|
162
|
-
it
|
163
|
-
request_stub.get(
|
164
|
-
[404, response_headers,
|
170
|
+
it 'should raise an exception if a document is not found' do
|
171
|
+
request_stub.get('/_api/document/4590/333') do
|
172
|
+
[404, response_headers, '']
|
165
173
|
end
|
166
174
|
|
167
|
-
expect { subject.send_request
|
175
|
+
expect { subject.send_request 'document/4590/333' }.to raise_error(Ashikawa::Core::DocumentNotFoundException)
|
168
176
|
|
169
177
|
request_stub.verify_stubbed_calls
|
170
178
|
end
|
171
179
|
|
172
|
-
it
|
173
|
-
request_stub.get(
|
174
|
-
[404, response_headers,
|
180
|
+
it 'should raise an exception if a collection is not found' do
|
181
|
+
request_stub.get('/_api/collection/4590') do
|
182
|
+
[404, response_headers, '']
|
175
183
|
end
|
176
184
|
|
177
|
-
expect { subject.send_request
|
185
|
+
expect { subject.send_request 'collection/4590' }.to raise_error(Ashikawa::Core::CollectionNotFoundException)
|
178
186
|
|
179
187
|
request_stub.verify_stubbed_calls
|
180
188
|
end
|
181
189
|
|
182
|
-
it
|
183
|
-
request_stub.get(
|
184
|
-
[404, response_headers,
|
190
|
+
it 'should raise an exception if an index is not found' do
|
191
|
+
request_stub.get('/_api/index/4590/333') do
|
192
|
+
[404, response_headers, '']
|
185
193
|
end
|
186
194
|
|
187
|
-
expect { subject.send_request
|
195
|
+
expect { subject.send_request 'index/4590/333' }.to raise_error(Ashikawa::Core::IndexNotFoundException)
|
188
196
|
|
189
197
|
request_stub.verify_stubbed_calls
|
190
198
|
end
|
191
199
|
|
192
|
-
it
|
193
|
-
request_stub.get(
|
194
|
-
[404, response_headers,
|
200
|
+
it 'should raise an exception for unknown pathes' do
|
201
|
+
request_stub.get('/_api/unknown_path/4590/333') do
|
202
|
+
[404, response_headers, '']
|
195
203
|
end
|
196
204
|
|
197
|
-
expect { subject.send_request
|
205
|
+
expect { subject.send_request 'unknown_path/4590/333' }.to raise_error(Ashikawa::Core::ResourceNotFound)
|
198
206
|
|
199
207
|
request_stub.verify_stubbed_calls
|
200
208
|
end
|
201
209
|
|
202
|
-
it
|
203
|
-
request_stub.get(
|
204
|
-
[200, response_headers,
|
210
|
+
it 'should raise an error if a malformed JSON was returned from the server' do
|
211
|
+
request_stub.get('/_api/document/4590/333') do
|
212
|
+
[200, response_headers, '{"a":1']
|
205
213
|
end
|
206
214
|
|
207
|
-
expect { subject.send_request
|
215
|
+
expect { subject.send_request 'document/4590/333' }.to raise_error(Ashikawa::Core::JsonError)
|
208
216
|
|
209
217
|
request_stub.verify_stubbed_calls
|
210
218
|
end
|
211
219
|
|
212
|
-
it
|
213
|
-
request_stub.get(
|
214
|
-
[200, {
|
220
|
+
it 'should raise an error if the content type of the response is not JSON' do
|
221
|
+
request_stub.get('/_api/document/4590/333') do
|
222
|
+
[200, { 'content-type' => 'text/html; charset=utf-8' }, '']
|
215
223
|
end
|
216
224
|
|
217
|
-
expect { subject.send_request
|
225
|
+
expect { subject.send_request 'document/4590/333' }.to raise_error(Ashikawa::Core::JsonError)
|
218
226
|
|
219
227
|
request_stub.verify_stubbed_calls
|
220
228
|
end
|
221
229
|
end
|
222
230
|
|
223
|
-
describe
|
231
|
+
describe 'logging' do
|
224
232
|
let(:request_stub) { Faraday::Adapter::Test::Stubs.new }
|
225
233
|
let(:logger) { double }
|
226
|
-
subject
|
227
|
-
Ashikawa::Core::Connection.new(ARANGO_HOST, :
|
228
|
-
|
234
|
+
subject do
|
235
|
+
Ashikawa::Core::Connection.new(ARANGO_HOST, adapter: [:test, request_stub], logger: logger)
|
236
|
+
end
|
229
237
|
|
230
|
-
it
|
231
|
-
request_stub.get(
|
232
|
-
[200, response_headers, JSON.generate({:
|
238
|
+
it 'should log a get request' do
|
239
|
+
request_stub.get('/_api/test') do
|
240
|
+
[200, response_headers, JSON.generate({ a: 1 })]
|
233
241
|
end
|
234
|
-
logger.
|
235
|
-
logger.
|
236
|
-
|
242
|
+
expect(logger).to receive(:info).with("GET #{ARANGO_HOST}/_api/test ")
|
243
|
+
expect(logger).to receive(:info).with('200 {"a":1}')
|
244
|
+
|
245
|
+
subject.send_request('test')
|
237
246
|
end
|
238
247
|
|
239
|
-
it
|
240
|
-
request_stub.post(
|
241
|
-
[201, response_headers, JSON.generate({:
|
248
|
+
it 'should log a post request' do
|
249
|
+
request_stub.post('/_api/test') do
|
250
|
+
[201, response_headers, JSON.generate({ b: 2 })]
|
242
251
|
end
|
243
|
-
logger.
|
244
|
-
logger.
|
245
|
-
|
252
|
+
expect(logger).to receive(:info).with("POST #{ARANGO_HOST}/_api/test {:a=>2}")
|
253
|
+
expect(logger).to receive(:info).with('201 {"b":2}')
|
254
|
+
|
255
|
+
subject.send_request('test', post: { a: 2 })
|
246
256
|
end
|
247
257
|
end
|
248
258
|
end
|
data/spec/unit/cursor_spec.rb
CHANGED
@@ -1,65 +1,76 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
1
2
|
require 'unit/spec_helper'
|
2
3
|
require 'ashikawa-core/cursor'
|
3
4
|
|
4
5
|
describe Ashikawa::Core::Cursor do
|
5
6
|
subject { Ashikawa::Core::Cursor }
|
7
|
+
let(:database) { double }
|
8
|
+
|
9
|
+
describe 'cursor for a non-complete batch' do
|
10
|
+
let(:response) { server_response('cursor/26011191') }
|
11
|
+
let(:cursor_containing_string) do
|
12
|
+
{
|
13
|
+
'hasMore' => false,
|
14
|
+
'error' => false,
|
15
|
+
'result' => [
|
16
|
+
'test'
|
17
|
+
],
|
18
|
+
'code' => 200,
|
19
|
+
'count' => 1
|
20
|
+
}
|
21
|
+
end
|
22
|
+
subject { Ashikawa::Core::Cursor.new(database, response) }
|
6
23
|
|
7
|
-
|
8
|
-
|
9
|
-
double Ashikawa::Core::Document
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should create a cursor for a non-complete batch" do
|
13
|
-
my_cursor = subject.new @database, server_response("cursor/26011191")
|
14
|
-
my_cursor.id.should == "26011191"
|
15
|
-
my_cursor.length.should == 5
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should create a cursor for the last batch" do
|
19
|
-
my_cursor = subject.new @database, server_response("cursor/26011191-3")
|
20
|
-
my_cursor.id.should be_nil
|
21
|
-
my_cursor.length.should == 5
|
22
|
-
end
|
24
|
+
its(:id) { should eq('26011191') }
|
25
|
+
its(:length) { should eq(5) }
|
23
26
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
27
|
+
it 'should be deletable' do
|
28
|
+
expect(database).to receive(:send_request).with('cursor/26011191', delete: {})
|
29
|
+
subject.delete
|
30
|
+
end
|
28
31
|
|
29
|
-
it
|
32
|
+
it 'should iterate over all documents of a cursor when given a block' do
|
30
33
|
first = true
|
31
34
|
|
32
|
-
|
35
|
+
allow(database).to receive(:send_request).with('cursor/26011191', put: {}) do
|
33
36
|
if first
|
34
37
|
first = false
|
35
|
-
server_response(
|
38
|
+
server_response('cursor/26011191-2')
|
36
39
|
else
|
37
|
-
server_response(
|
40
|
+
server_response('cursor/26011191-3')
|
38
41
|
end
|
39
42
|
end
|
40
|
-
|
43
|
+
expect(database).to receive(:send_request)
|
44
|
+
.twice
|
45
|
+
expect(Ashikawa::Core::Document).to receive(:new)
|
46
|
+
.exactly(5).times
|
47
|
+
|
48
|
+
subject.each { }
|
49
|
+
end
|
41
50
|
|
42
|
-
|
43
|
-
|
51
|
+
it 'should return the raw string when the response consists of strings' do
|
52
|
+
allow(database).to receive(:send_request)
|
53
|
+
.with('cursor/26011191', put: {})
|
54
|
+
.and_return(cursor_containing_string)
|
44
55
|
|
45
|
-
subject.
|
56
|
+
expect(subject.to_a).to include 'test'
|
46
57
|
end
|
47
58
|
|
48
|
-
it
|
59
|
+
it 'should return an enumerator to go over all documents of a cursor when given no block' do
|
49
60
|
first = true
|
50
61
|
|
51
|
-
|
62
|
+
allow(database).to receive(:send_request).with('cursor/26011191', put: {}) do
|
52
63
|
if first
|
53
64
|
first = false
|
54
|
-
server_response(
|
65
|
+
server_response('cursor/26011191-2')
|
55
66
|
else
|
56
|
-
server_response(
|
67
|
+
server_response('cursor/26011191-3')
|
57
68
|
end
|
58
69
|
end
|
59
|
-
|
60
|
-
|
61
|
-
Ashikawa::Core::Document.
|
62
|
-
|
70
|
+
expect(database).to receive(:send_request)
|
71
|
+
.twice
|
72
|
+
expect(Ashikawa::Core::Document).to receive(:new)
|
73
|
+
.exactly(5).times
|
63
74
|
|
64
75
|
enumerator = subject.each
|
65
76
|
enumerator.next
|
@@ -70,44 +81,46 @@ describe Ashikawa::Core::Cursor do
|
|
70
81
|
expect { enumerator.next }.to raise_exception(StopIteration)
|
71
82
|
end
|
72
83
|
|
73
|
-
it
|
74
|
-
@database.stub(:send_request)
|
75
|
-
@database.should_receive(:send_request).with("cursor/26011191",
|
76
|
-
:delete => {})
|
77
|
-
|
78
|
-
subject.delete
|
79
|
-
end
|
80
|
-
|
81
|
-
it "should be enumerable" do
|
84
|
+
it 'should be enumerable' do
|
82
85
|
first = true
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
86
|
+
result = double
|
87
|
+
|
88
|
+
expect(database).to receive(:send_request)
|
89
|
+
.twice
|
90
|
+
.with('cursor/26011191', put: {}) do
|
91
|
+
if first
|
92
|
+
first = false
|
93
|
+
server_response('cursor/26011191-2')
|
94
|
+
else
|
95
|
+
server_response('cursor/26011191-3')
|
96
|
+
end
|
90
97
|
end
|
91
|
-
end
|
92
|
-
@database.should_receive(:send_request).twice
|
93
98
|
|
94
|
-
Ashikawa::Core::Document.
|
95
|
-
|
99
|
+
expect(Ashikawa::Core::Document).to receive(:new)
|
100
|
+
.exactly(5).times
|
101
|
+
.and_return(result)
|
96
102
|
|
97
|
-
subject.map{|i| i}[0].
|
103
|
+
expect(subject.map { |i| i }[0]).to eq(result)
|
98
104
|
end
|
99
105
|
|
100
|
-
it
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
106
|
+
it 'should return edge objects when recieving data from an edge collection' do
|
107
|
+
expect(database).to receive(:send_request)
|
108
|
+
.once
|
109
|
+
.with('cursor/26011191', put: {})
|
110
|
+
.and_return(server_response('cursor/edges'))
|
105
111
|
|
106
|
-
Ashikawa::Core::Edge.
|
107
|
-
|
112
|
+
expect(Ashikawa::Core::Edge).to receive(:new)
|
113
|
+
.exactly(2).times
|
108
114
|
|
109
|
-
subject.each {
|
115
|
+
subject.each { }
|
110
116
|
end
|
117
|
+
end
|
118
|
+
|
119
|
+
describe 'cursor for the last batch' do
|
120
|
+
let(:response) { server_response('cursor/26011191-3') }
|
121
|
+
subject { Ashikawa::Core::Cursor.new(database, response) }
|
111
122
|
|
123
|
+
its(:id) { should be_nil }
|
124
|
+
its(:length) { should eq(5) }
|
112
125
|
end
|
113
126
|
end
|