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.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/.travis.yml +3 -3
  4. data/CHANGELOG.md +49 -0
  5. data/Gemfile +3 -2
  6. data/Gemfile.devtools +14 -22
  7. data/Guardfile +3 -2
  8. data/README.md +37 -6
  9. data/Rakefile +2 -1
  10. data/ashikawa-core.gemspec +2 -2
  11. data/cache/Mac_applications +1 -0
  12. data/config/devtools.yml +5 -0
  13. data/config/flay.yml +1 -1
  14. data/config/flog.yml +1 -2
  15. data/config/reek.yml +1 -1
  16. data/config/rubocop.yml +23 -25
  17. data/lib/ashikawa-core.rb +6 -5
  18. data/lib/ashikawa-core/collection.rb +142 -165
  19. data/lib/ashikawa-core/configuration.rb +41 -2
  20. data/lib/ashikawa-core/connection.rb +17 -16
  21. data/lib/ashikawa-core/cursor.rb +18 -12
  22. data/lib/ashikawa-core/database.rb +69 -59
  23. data/lib/ashikawa-core/document.rb +22 -20
  24. data/lib/ashikawa-core/edge.rb +8 -6
  25. data/lib/ashikawa-core/exceptions/client_error.rb +1 -0
  26. data/lib/ashikawa-core/exceptions/client_error/authentication_failed.rb +25 -0
  27. data/lib/ashikawa-core/exceptions/client_error/bad_syntax.rb +3 -2
  28. data/lib/ashikawa-core/exceptions/client_error/resource_not_found.rb +3 -2
  29. data/lib/ashikawa-core/exceptions/client_error/resource_not_found/collection_not_found.rb +3 -2
  30. data/lib/ashikawa-core/exceptions/client_error/resource_not_found/document_not_found.rb +3 -2
  31. data/lib/ashikawa-core/exceptions/client_error/resource_not_found/index_not_found.rb +3 -2
  32. data/lib/ashikawa-core/exceptions/no_collection_provided.rb +1 -0
  33. data/lib/ashikawa-core/exceptions/server_error.rb +1 -0
  34. data/lib/ashikawa-core/exceptions/server_error/json_error.rb +3 -2
  35. data/lib/ashikawa-core/figure.rb +18 -17
  36. data/lib/ashikawa-core/index.rb +15 -5
  37. data/lib/ashikawa-core/key_options.rb +5 -4
  38. data/lib/ashikawa-core/query.rb +38 -27
  39. data/lib/ashikawa-core/request_preprocessor.rb +4 -3
  40. data/lib/ashikawa-core/response_preprocessor.rb +64 -24
  41. data/lib/ashikawa-core/status.rb +1 -0
  42. data/lib/ashikawa-core/transaction.rb +12 -11
  43. data/lib/ashikawa-core/version.rb +2 -1
  44. data/spec/acceptance/basic_spec.rb +117 -116
  45. data/spec/acceptance/index_spec.rb +18 -15
  46. data/spec/acceptance/query_spec.rb +61 -64
  47. data/spec/acceptance/spec_helper.rb +26 -3
  48. data/spec/acceptance/transactions_spec.rb +12 -16
  49. data/spec/setup/arangodb.sh +2 -2
  50. data/spec/unit/collection_spec.rb +224 -242
  51. data/spec/unit/configuration_spec.rb +64 -0
  52. data/spec/unit/connection_spec.rb +121 -111
  53. data/spec/unit/cursor_spec.rb +78 -65
  54. data/spec/unit/database_spec.rb +112 -163
  55. data/spec/unit/document_spec.rb +74 -70
  56. data/spec/unit/edge_spec.rb +45 -33
  57. data/spec/unit/exception_spec.rb +28 -38
  58. data/spec/unit/figure_spec.rb +44 -47
  59. data/spec/unit/index_spec.rb +27 -24
  60. data/spec/unit/key_options_spec.rb +19 -17
  61. data/spec/unit/query_spec.rb +186 -135
  62. data/spec/unit/spec_helper.rb +14 -3
  63. data/spec/unit/status_spec.rb +37 -37
  64. data/spec/unit/transaction_spec.rb +71 -74
  65. data/tasks/adjustments.rake +10 -34
  66. metadata +11 -13
  67. data/spec/acceptance/arango_helper.rb +0 -27
  68. data/spec/acceptance_auth/arango_helper.rb +0 -30
  69. data/spec/acceptance_auth/auth_spec.rb +0 -40
  70. 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) { {"content-type" => "application/json; charset=utf-8" } }
7
- subject { Ashikawa::Core::Connection.new(ARANGO_HOST, :adapter => [:test, request_stub]) }
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
- it "should have a scheme, hostname and port" do
10
- subject.scheme.should == "http"
11
- subject.host.should == "localhost"
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 "should send a get request" do
16
- request_stub.get("/_api/my/path") do
17
- [200, response_headers, JSON.generate({ "name" => "dude" })]
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 "my/path"
19
+ subject.send_request 'my/path'
21
20
 
22
21
  request_stub.verify_stubbed_calls
23
22
  end
24
23
 
25
- it "should send a post request" do
26
- request_stub.post("/_api/my/path") do |request|
27
- request[:body].should == "{\"name\":\"new_collection\"}"
28
- [200, response_headers, JSON.generate({ "name" => "dude" })]
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 "my/path", :post => { :name => 'new_collection' }
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 "should send a put request" do
37
- request_stub.put("/_api/my/path") do |request|
38
- request[:body].should == '{"name":"new_collection"}'
39
- [200, response_headers, JSON.generate({ "name" => "dude" })]
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 "my/path", :put => { :name => 'new_collection' }
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 "should send a delete request" do
48
- request_stub.delete("/_api/my/path") do |request|
49
- [200, response_headers, JSON.generate({ "name" => "dude" })]
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 "my/path", :delete => { }
53
-
49
+ subject.send_request 'my/path', delete: { }
54
50
  request_stub.verify_stubbed_calls
55
51
  end
56
52
 
57
- it "should write JSON request" do
58
- request_stub.post("/_api/my/path") do |req|
59
- req[:body].should == "{\"test\":1}"
60
- [200, response_headers, JSON.generate({ "name" => "dude" })]
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("my/path", :post => { "test" => 1})
59
+ subject.send_request('my/path', post: { 'test' => 1 })
64
60
  request_stub.verify_stubbed_calls
65
61
  end
66
62
 
67
- it "should parse JSON response" do
68
- request_stub.get("/_api/my/path") do
69
- [200, response_headers, "{\"name\":\"dude\"}"]
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("my/path").should == {"name" => "dude"}
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 "authentication" do
77
- it "should have authentication turned off by default" do
78
- subject.authentication?.should be_false
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 "should tell if authentication is enabled" do
82
- subject.authenticate_with :username => "testuser", :password => "testpassword"
83
- subject.authentication?.should be_true
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 "should only accept username & password pairs" do
87
- expect {
88
- subject.authenticate_with :username => "kitty"
89
- }.to raise_error(ArgumentError)
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 :password => "cheezburger?"
93
- }.to raise_error(ArgumentError)
87
+ expect do
88
+ subject.authenticate_with(password: 'cheezburger?')
89
+ end.to raise_error(ArgumentError)
94
90
  end
95
91
 
96
- it "should allow chaining" do
97
- subject.authenticate_with(:username => "a", :password => "b").should == subject
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 "should send the authentication data with every GET request" do
101
- pending "Find out how to check for basic auth via Faraday Stubs"
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("/_api/my/path") do |request|
104
- [200, response_headers, JSON.generate({ "name" => "dude" })]
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 :username => "user", :password => "pass"
108
- subject.send_request "my/path"
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 "exception handling" do
115
- let(:error_message) { "cannot write file" }
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("/_api/bad/request") do
115
+ request_stub.get('/_api/bad/request') do
120
116
  [
121
117
  418,
122
118
  response_headers,
123
- JSON.generate({ "error" => true, "errorNum" => error_num, "errorMessage" => error_message })
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("bad/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 "should throw its own exception when doing a bad request" do
135
- request_stub.get("/_api/bad/request") do
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("bad/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 "should throw a general server error for the generic server error" do
147
- request_stub.get("/_api/bad/request") do
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({ "error" => true, "errorNum" => error_num, "errorMessage" => error_message })
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("bad/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 "should raise an exception if a document is not found" do
163
- request_stub.get("/_api/document/4590/333") do
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 "document/4590/333" }.to raise_error(Ashikawa::Core::DocumentNotFoundException)
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 "should raise an exception if a collection is not found" do
173
- request_stub.get("/_api/collection/4590") do
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 "collection/4590" }.to raise_error(Ashikawa::Core::CollectionNotFoundException)
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 "should raise an exception if an index is not found" do
183
- request_stub.get("/_api/index/4590/333") do
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 "index/4590/333" }.to raise_error(Ashikawa::Core::IndexNotFoundException)
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 "should raise an exception for unknown pathes" do
193
- request_stub.get("/_api/unknown_path/4590/333") do
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 "unknown_path/4590/333" }.to raise_error(Ashikawa::Core::ResourceNotFound)
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 "should raise an error if a malformed JSON was returned from the server" do
203
- request_stub.get("/_api/document/4590/333") do
204
- [200, response_headers, "{\"a\":1"]
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 "document/4590/333" }.to raise_error(Ashikawa::Core::JsonError)
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 "should raise an error if the content type of the response is not JSON" do
213
- request_stub.get("/_api/document/4590/333") do
214
- [200, {"content-type" => "text/html; charset=utf-8"}, ""]
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 "document/4590/333" }.to raise_error(Ashikawa::Core::JsonError)
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 "logging" do
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, :adapter => [:test, request_stub], :logger => logger)
228
- }
234
+ subject do
235
+ Ashikawa::Core::Connection.new(ARANGO_HOST, adapter: [:test, request_stub], logger: logger)
236
+ end
229
237
 
230
- it "should log a get request" do
231
- request_stub.get("/_api/test") do
232
- [200, response_headers, JSON.generate({:a => 1})]
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.should_receive(:info).with("GET #{ARANGO_HOST}/_api/test ")
235
- logger.should_receive(:info).with("200 {\"a\":1}")
236
- subject.send_request("test")
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 "should log a post request" do
240
- request_stub.post("/_api/test") do
241
- [201, response_headers, JSON.generate({:b => 2})]
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.should_receive(:info).with("POST #{ARANGO_HOST}/_api/test {:a=>2}")
244
- logger.should_receive(:info).with("201 {\"b\":2}")
245
- subject.send_request("test", :post => { :a => 2})
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
@@ -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
- before :each do
8
- @database = double
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
- describe "existing cursor" do
25
- subject { Ashikawa::Core::Cursor.new @database,
26
- server_response("cursor/26011191")
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 "should iterate over all documents of a cursor when given a block" do
32
+ it 'should iterate over all documents of a cursor when given a block' do
30
33
  first = true
31
34
 
32
- @database.stub(:send_request).with("cursor/26011191", :put => {}) do
35
+ allow(database).to receive(:send_request).with('cursor/26011191', put: {}) do
33
36
  if first
34
37
  first = false
35
- server_response("cursor/26011191-2")
38
+ server_response('cursor/26011191-2')
36
39
  else
37
- server_response("cursor/26011191-3")
40
+ server_response('cursor/26011191-3')
38
41
  end
39
42
  end
40
- @database.should_receive(:send_request).twice
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
- Ashikawa::Core::Document.stub(:new)
43
- Ashikawa::Core::Document.should_receive(:new).exactly(5).times
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.each { |document| }
56
+ expect(subject.to_a).to include 'test'
46
57
  end
47
58
 
48
- it "should return an enumerator to go over all documents of a cursor when given no block" do
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
- @database.stub(:send_request).with("cursor/26011191", :put => {}) do
62
+ allow(database).to receive(:send_request).with('cursor/26011191', put: {}) do
52
63
  if first
53
64
  first = false
54
- server_response("cursor/26011191-2")
65
+ server_response('cursor/26011191-2')
55
66
  else
56
- server_response("cursor/26011191-3")
67
+ server_response('cursor/26011191-3')
57
68
  end
58
69
  end
59
- @database.should_receive(:send_request).twice
60
-
61
- Ashikawa::Core::Document.stub(:new)
62
- Ashikawa::Core::Document.should_receive(:new).exactly(5).times
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 "should be deletable" do
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
- @database.stub(:send_request).with("cursor/26011191", :put => {}) do
85
- if first
86
- first = false
87
- server_response("cursor/26011191-2")
88
- else
89
- server_response("cursor/26011191-3")
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.stub(:new).and_return { 1 }
95
- Ashikawa::Core::Document.should_receive(:new).exactly(5).times
99
+ expect(Ashikawa::Core::Document).to receive(:new)
100
+ .exactly(5).times
101
+ .and_return(result)
96
102
 
97
- subject.map{|i| i}[0].should == 1
103
+ expect(subject.map { |i| i }[0]).to eq(result)
98
104
  end
99
105
 
100
- it "should return edge objects when recieving data from an edge collection" do
101
- @database.stub(:send_request).with("cursor/26011191", :put => {}) do
102
- server_response("cursor/edges")
103
- end
104
- @database.should_receive(:send_request).once
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.stub(:new).and_return { 1 }
107
- Ashikawa::Core::Edge.should_receive(:new).exactly(2).times
112
+ expect(Ashikawa::Core::Edge).to receive(:new)
113
+ .exactly(2).times
108
114
 
109
- subject.each { |document| }
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