ashikawa-core 0.7.2 → 0.8.0
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/.coveralls.yml +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +0 -4
- data/Gemfile +1 -1
- data/Gemfile.devtools +24 -18
- data/README.md +6 -11
- data/ashikawa-core.gemspec +7 -6
- data/config/flay.yml +2 -2
- data/config/flog.yml +2 -1
- data/config/reek.yml +68 -84
- data/config/rubocop.yml +99 -0
- data/config/yardstick.yml +1 -1
- data/lib/ashikawa-core/collection.rb +74 -21
- data/lib/ashikawa-core/configuration.rb +26 -0
- data/lib/ashikawa-core/connection.rb +5 -2
- data/lib/ashikawa-core/cursor.rb +28 -16
- data/lib/ashikawa-core/database.rb +89 -12
- data/lib/ashikawa-core/document.rb +32 -5
- data/lib/ashikawa-core/edge.rb +3 -0
- data/lib/ashikawa-core/exceptions/client_error.rb +3 -3
- data/lib/ashikawa-core/exceptions/server_error.rb +3 -3
- data/lib/ashikawa-core/figure.rb +17 -5
- data/lib/ashikawa-core/index.rb +4 -0
- data/lib/ashikawa-core/key_options.rb +54 -0
- data/lib/ashikawa-core/query.rb +39 -74
- data/lib/ashikawa-core/request_preprocessor.rb +2 -2
- data/lib/ashikawa-core/response_preprocessor.rb +21 -12
- data/lib/ashikawa-core/transaction.rb +113 -0
- data/lib/ashikawa-core/version.rb +1 -1
- data/spec/acceptance/basic_spec.rb +40 -12
- data/spec/acceptance/index_spec.rb +2 -1
- data/spec/acceptance/query_spec.rb +18 -17
- data/spec/acceptance/transactions_spec.rb +30 -0
- data/spec/fixtures/collections/all.json +90 -30
- data/spec/fixtures/cursor/edges.json +23 -0
- data/spec/setup/arangodb.sh +7 -6
- data/spec/unit/collection_spec.rb +89 -13
- data/spec/unit/connection_spec.rb +23 -14
- data/spec/unit/cursor_spec.rb +15 -4
- data/spec/unit/database_spec.rb +58 -17
- data/spec/unit/document_spec.rb +24 -4
- data/spec/unit/edge_spec.rb +1 -1
- data/spec/unit/exception_spec.rb +4 -2
- data/spec/unit/figure_spec.rb +17 -10
- data/spec/unit/index_spec.rb +1 -1
- data/spec/unit/key_options_spec.rb +25 -0
- data/spec/unit/query_spec.rb +1 -1
- data/spec/unit/spec_helper.rb +20 -2
- data/spec/unit/transaction_spec.rb +153 -0
- data/tasks/adjustments.rake +23 -14
- metadata +31 -41
- data/.rvmrc +0 -1
- data/config/roodi.yml +0 -17
- data/spec/spec_helper.rb +0 -27
@@ -0,0 +1,23 @@
|
|
1
|
+
{
|
2
|
+
"hasMore": false,
|
3
|
+
"error": false,
|
4
|
+
"id": "26011191",
|
5
|
+
"result": [
|
6
|
+
{
|
7
|
+
"n": 0,
|
8
|
+
"_rev": 25880119,
|
9
|
+
"_id": "23914039/25880119",
|
10
|
+
"_from": "23914039/25880119",
|
11
|
+
"_to": "23914039/25880119"
|
12
|
+
},
|
13
|
+
{
|
14
|
+
"n": 1,
|
15
|
+
"_rev": 25880119,
|
16
|
+
"_id": "23914039/25880119",
|
17
|
+
"_from": "23914039/25880119",
|
18
|
+
"_to": "23914039/25880119"
|
19
|
+
}
|
20
|
+
],
|
21
|
+
"code": 201,
|
22
|
+
"count": 2
|
23
|
+
}
|
data/spec/setup/arangodb.sh
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
4
4
|
cd $DIR
|
5
5
|
|
6
|
-
VERSION=1.
|
6
|
+
VERSION=1.3.0
|
7
7
|
NAME=ArangoDB-$VERSION
|
8
8
|
|
9
9
|
if [ ! -d "$DIR/$NAME" ]; then
|
@@ -11,7 +11,7 @@ if [ ! -d "$DIR/$NAME" ]; then
|
|
11
11
|
echo "wget http://www.arangodb.org/travisCI/$NAME.tar.gz"
|
12
12
|
wget http://www.arangodb.org/travisCI/$NAME.tar.gz
|
13
13
|
echo "tar zxf $NAME.tar.gz"
|
14
|
-
tar
|
14
|
+
tar zvxf $NAME.tar.gz
|
15
15
|
fi
|
16
16
|
|
17
17
|
ARCH=$(arch)
|
@@ -25,8 +25,7 @@ if [ "$ARCH" == "x86_64" ]; then
|
|
25
25
|
ARANGOD="${ARANGOD}_x86_64"
|
26
26
|
fi
|
27
27
|
|
28
|
-
#
|
29
|
-
rm -rf ${TMP_DIR}
|
28
|
+
# create database directory
|
30
29
|
mkdir ${TMP_DIR}
|
31
30
|
|
32
31
|
echo "Starting arangodb '${ARANGOD}'"
|
@@ -36,8 +35,10 @@ ${ARANGOD} \
|
|
36
35
|
--configuration none \
|
37
36
|
--server.endpoint tcp://127.0.0.1:8529 \
|
38
37
|
--javascript.startup-directory ${ARANGODB_DIR}/js \
|
39
|
-
--
|
40
|
-
--javascript.
|
38
|
+
--server.admin-directory ${ARANGODB_DIR}/html/admin \
|
39
|
+
--javascript.modules-path ${ARANGODB_DIR}/js/server/modules:${ARANGODB_DIR}/js/common/modules:${ARANGODB_DIR}/js/node \
|
40
|
+
--javascript.package-path ${ARANGODB_DIR}/js/npm:${ARANGODB_DIR}/js/common/test-data/modules \
|
41
|
+
--javascript.action-directory ${ARANGODB_DIR}/js/actions \
|
41
42
|
--database.maximal-journal-size 1048576 \
|
42
43
|
--server.disable-admin-interface true \
|
43
44
|
--server.disable-authentication true \
|
@@ -5,7 +5,7 @@ describe Ashikawa::Core::Collection do
|
|
5
5
|
subject { Ashikawa::Core::Collection }
|
6
6
|
|
7
7
|
before :each do
|
8
|
-
@database = double
|
8
|
+
@database = double
|
9
9
|
end
|
10
10
|
|
11
11
|
it "should have a name" do
|
@@ -21,7 +21,7 @@ describe Ashikawa::Core::Collection do
|
|
21
21
|
it "should create a query" do
|
22
22
|
collection = subject.new @database, server_response("collections/60768679")
|
23
23
|
|
24
|
-
|
24
|
+
double Ashikawa::Core::Query
|
25
25
|
Ashikawa::Core::Query.stub(:new)
|
26
26
|
Ashikawa::Core::Query.should_receive(:new).exactly(1).times.with(collection)
|
27
27
|
|
@@ -75,7 +75,7 @@ describe Ashikawa::Core::Collection do
|
|
75
75
|
@database.stub(:send_request).with("collection/60768679/figures", {}).and_return { server_response("collections/60768679-figures") }
|
76
76
|
@database.should_receive(:send_request).with("collection/60768679/figures", {}).at_least(1).times
|
77
77
|
|
78
|
-
|
78
|
+
double Ashikawa::Core::Figure
|
79
79
|
Ashikawa::Core::Figure.stub(:new)
|
80
80
|
Ashikawa::Core::Figure.should_receive(:new).exactly(1).times.with(server_response("collections/60768679-figures")["figures"])
|
81
81
|
|
@@ -122,6 +122,16 @@ describe Ashikawa::Core::Collection do
|
|
122
122
|
subject.wait_for_sync = true
|
123
123
|
end
|
124
124
|
|
125
|
+
it "should check for the key options" do
|
126
|
+
raw_key_options = double
|
127
|
+
@database.should_receive(:send_request).with("collection/60768679/properties", {}).and_return { { "keyOptions" => raw_key_options } }
|
128
|
+
|
129
|
+
key_options = double
|
130
|
+
Ashikawa::Core::KeyOptions.stub(:new).with(raw_key_options).and_return { key_options }
|
131
|
+
|
132
|
+
subject.key_options.should == key_options
|
133
|
+
end
|
134
|
+
|
125
135
|
it "should change its name" do
|
126
136
|
@database.stub(:send_request).with("collection/60768679/rename", :put => {"name" => "my_new_name"})
|
127
137
|
@database.should_receive(:send_request).with("collection/60768679/rename", :put => {"name" => "my_new_name"})
|
@@ -130,7 +140,17 @@ describe Ashikawa::Core::Collection do
|
|
130
140
|
end
|
131
141
|
|
132
142
|
describe "add and get single documents" do
|
133
|
-
it "should receive a document by ID" do
|
143
|
+
it "should receive a document by ID via fetch" do
|
144
|
+
@database.stub(:send_request).with("document/60768679/333", {}).and_return { server_response('documents/example_1-137249191') }
|
145
|
+
@database.should_receive(:send_request).with("document/60768679/333", {})
|
146
|
+
|
147
|
+
# Documents need to get initialized:
|
148
|
+
Ashikawa::Core::Document.should_receive(:new)
|
149
|
+
|
150
|
+
subject.fetch(333)
|
151
|
+
end
|
152
|
+
|
153
|
+
it "should receive a document by ID via []" do
|
134
154
|
@database.stub(:send_request).with("document/60768679/333", {}).and_return { server_response('documents/example_1-137249191') }
|
135
155
|
@database.should_receive(:send_request).with("document/60768679/333", {})
|
136
156
|
|
@@ -140,35 +160,70 @@ describe Ashikawa::Core::Collection do
|
|
140
160
|
subject[333]
|
141
161
|
end
|
142
162
|
|
163
|
+
it "should throw an exception when the document was not found during a fetch" do
|
164
|
+
@database.stub(:send_request).and_return {
|
165
|
+
raise Ashikawa::Core::DocumentNotFoundException
|
166
|
+
}
|
167
|
+
|
168
|
+
expect {
|
169
|
+
subject.fetch(123)
|
170
|
+
}.to raise_exception Ashikawa::Core::DocumentNotFoundException
|
171
|
+
end
|
172
|
+
|
173
|
+
it "should return nil when the document was not found when using []" do
|
174
|
+
@database.stub(:send_request).and_return {
|
175
|
+
raise Ashikawa::Core::DocumentNotFoundException
|
176
|
+
}
|
177
|
+
|
178
|
+
subject[123].should == nil
|
179
|
+
end
|
180
|
+
|
143
181
|
it "should replace a document by ID" do
|
144
182
|
@database.stub(:send_request).with("document/60768679/333", :put => {"name" => "The Dude"})
|
145
183
|
@database.should_receive(:send_request).with("document/60768679/333", :put => {"name" => "The Dude"})
|
146
184
|
|
147
|
-
subject
|
185
|
+
subject.replace(333, {"name" => "The Dude"})
|
148
186
|
end
|
149
187
|
|
150
188
|
it "should create a new document" do
|
151
189
|
@database.stub(:send_request).with("document?collection=60768679", :post => { "name" => "The Dude" }).and_return do
|
152
190
|
server_response('documents/new-example_1-137249191')
|
153
191
|
end
|
154
|
-
@database.stub(:send_request).with("document/60768679/333", :post => {
|
192
|
+
@database.stub(:send_request).with("document/60768679/333", :post => {
|
193
|
+
"name" => "The Dude"
|
194
|
+
}).and_return {
|
195
|
+
{
|
196
|
+
"_id" => "example_1/137249191",
|
197
|
+
"_rev" => "137249191",
|
198
|
+
"_key" => "137249191"
|
199
|
+
}
|
200
|
+
}
|
201
|
+
@database.stub(:send_request).with("document/60768679/333", {}).and_return { server_response('documents/example_1-137249191') }
|
155
202
|
|
156
203
|
# Documents need to get initialized:
|
157
|
-
Ashikawa::Core::Document.should_receive(:new)
|
204
|
+
Ashikawa::Core::Document.should_receive(:new).and_return {
|
205
|
+
document = double
|
206
|
+
document.should_receive(:refresh!)
|
207
|
+
document
|
208
|
+
}
|
158
209
|
|
159
210
|
subject.create_document({"name" => "The Dude"})
|
160
211
|
end
|
161
212
|
|
162
|
-
it "should create a new document
|
213
|
+
it "should create a new document" do
|
163
214
|
@database.stub(:send_request).with("document?collection=60768679", :post => { "name" => "The Dude" }).and_return do
|
164
215
|
server_response('documents/example_1-137249191')
|
165
216
|
end
|
166
217
|
@database.stub(:send_request).with("document/60768679/333").and_return { server_response('documents/example_1-137249191') }
|
167
218
|
|
168
219
|
# Documents need to get initialized:
|
169
|
-
Ashikawa::Core::Document.should_receive(:new)
|
220
|
+
Ashikawa::Core::Document.should_receive(:new).and_return {
|
221
|
+
document = double
|
222
|
+
document.should_receive(:refresh!)
|
223
|
+
document
|
224
|
+
}
|
170
225
|
|
171
|
-
subject
|
226
|
+
subject.create_document("name" => "The Dude")
|
172
227
|
end
|
173
228
|
|
174
229
|
it "should not create a new document" do
|
@@ -227,14 +282,14 @@ describe Ashikawa::Core::Collection do
|
|
227
282
|
# Documents need to get initialized:
|
228
283
|
Ashikawa::Core::Edge.should_receive(:new)
|
229
284
|
|
230
|
-
subject
|
285
|
+
subject.fetch(333)
|
231
286
|
end
|
232
287
|
|
233
288
|
it "should replace an edge by ID" do
|
234
289
|
@database.stub(:send_request).with("edge/60768679/333", :put => {"name" => "The Dude"})
|
235
290
|
@database.should_receive(:send_request).with("edge/60768679/333", :put => {"name" => "The Dude"})
|
236
291
|
|
237
|
-
subject
|
292
|
+
subject.replace(333, {"name" => "The Dude"})
|
238
293
|
end
|
239
294
|
|
240
295
|
it "should create a new edge" do
|
@@ -248,7 +303,11 @@ describe Ashikawa::Core::Collection do
|
|
248
303
|
to_double.stub(:id => "2")
|
249
304
|
|
250
305
|
# Documents need to get initialized:
|
251
|
-
Ashikawa::Core::Edge.should_receive(:new)
|
306
|
+
Ashikawa::Core::Edge.should_receive(:new).and_return {
|
307
|
+
document = double
|
308
|
+
document.should_receive(:refresh!)
|
309
|
+
document
|
310
|
+
}
|
252
311
|
|
253
312
|
subject.create_edge(from_double, to_double, {"name" => "The Dude"})
|
254
313
|
end
|
@@ -259,4 +318,21 @@ describe Ashikawa::Core::Collection do
|
|
259
318
|
}.to raise_exception(RuntimeError, "Can't create a document in an edge collection")
|
260
319
|
end
|
261
320
|
end
|
321
|
+
|
322
|
+
describe "Deprecated methods" do
|
323
|
+
subject { Ashikawa::Core::Collection.new @database, { "id" => "60768679", "name" => "example_1" } }
|
324
|
+
let(:attributes) { { "test" => 123 } }
|
325
|
+
|
326
|
+
it "should mark `<<` as deprecated" do
|
327
|
+
subject.should_receive(:create_document).with(attributes).and_return nil
|
328
|
+
subject.should_receive(:warn).with("`<<` is deprecated, please use `create_document`")
|
329
|
+
subject << attributes
|
330
|
+
end
|
331
|
+
|
332
|
+
it "should mark `[]=` as deprecated" do
|
333
|
+
subject.should_receive(:replace).with(121, attributes).and_return nil
|
334
|
+
subject.should_receive(:warn).with("`[]=` is deprecated, please use `replace`")
|
335
|
+
subject[121] = attributes
|
336
|
+
end
|
337
|
+
end
|
262
338
|
end
|
@@ -14,7 +14,7 @@ describe Ashikawa::Core::Connection do
|
|
14
14
|
|
15
15
|
it "should send a get request" do
|
16
16
|
request_stub.get("/_api/my/path") do
|
17
|
-
[200, response_headers,
|
17
|
+
[200, response_headers, JSON.generate({ "name" => "dude" })]
|
18
18
|
end
|
19
19
|
|
20
20
|
subject.send_request "my/path"
|
@@ -25,7 +25,7 @@ describe Ashikawa::Core::Connection do
|
|
25
25
|
it "should send a post request" do
|
26
26
|
request_stub.post("/_api/my/path") do |request|
|
27
27
|
request[:body].should == "{\"name\":\"new_collection\"}"
|
28
|
-
[200, response_headers,
|
28
|
+
[200, response_headers, JSON.generate({ "name" => "dude" })]
|
29
29
|
end
|
30
30
|
|
31
31
|
subject.send_request "my/path", :post => { :name => 'new_collection' }
|
@@ -36,7 +36,7 @@ describe Ashikawa::Core::Connection do
|
|
36
36
|
it "should send a put request" do
|
37
37
|
request_stub.put("/_api/my/path") do |request|
|
38
38
|
request[:body].should == '{"name":"new_collection"}'
|
39
|
-
[200, response_headers,
|
39
|
+
[200, response_headers, JSON.generate({ "name" => "dude" })]
|
40
40
|
end
|
41
41
|
|
42
42
|
subject.send_request "my/path", :put => { :name => 'new_collection' }
|
@@ -46,7 +46,7 @@ describe Ashikawa::Core::Connection do
|
|
46
46
|
|
47
47
|
it "should send a delete request" do
|
48
48
|
request_stub.delete("/_api/my/path") do |request|
|
49
|
-
[200, response_headers,
|
49
|
+
[200, response_headers, JSON.generate({ "name" => "dude" })]
|
50
50
|
end
|
51
51
|
|
52
52
|
subject.send_request "my/path", :delete => { }
|
@@ -57,7 +57,7 @@ describe Ashikawa::Core::Connection do
|
|
57
57
|
it "should write JSON request" do
|
58
58
|
request_stub.post("/_api/my/path") do |req|
|
59
59
|
req[:body].should == "{\"test\":1}"
|
60
|
-
[200, response_headers,
|
60
|
+
[200, response_headers, JSON.generate({ "name" => "dude" })]
|
61
61
|
end
|
62
62
|
|
63
63
|
subject.send_request("my/path", :post => { "test" => 1})
|
@@ -101,7 +101,7 @@ describe Ashikawa::Core::Connection do
|
|
101
101
|
pending "Find out how to check for basic auth via Faraday Stubs"
|
102
102
|
|
103
103
|
request_stub.get("/_api/my/path") do |request|
|
104
|
-
[200, response_headers,
|
104
|
+
[200, response_headers, JSON.generate({ "name" => "dude" })]
|
105
105
|
end
|
106
106
|
|
107
107
|
subject.authenticate_with :username => "user", :password => "pass"
|
@@ -112,14 +112,21 @@ describe Ashikawa::Core::Connection do
|
|
112
112
|
end
|
113
113
|
|
114
114
|
describe "exception handling" do
|
115
|
+
let(:error_message) { "cannot write file" }
|
116
|
+
let(:error_num) { 15 }
|
117
|
+
|
115
118
|
it "should throw a general client error for I'm a teapot" do
|
116
119
|
request_stub.get("/_api/bad/request") do
|
117
|
-
[
|
120
|
+
[
|
121
|
+
418,
|
122
|
+
response_headers,
|
123
|
+
JSON.generate({ "error" => true, "errorNum" => error_num, "errorMessage" => error_message })
|
124
|
+
]
|
118
125
|
end
|
119
126
|
|
120
127
|
expect do
|
121
128
|
subject.send_request("bad/request")
|
122
|
-
end.to raise_error(Ashikawa::Core::ClientError,
|
129
|
+
end.to raise_error(Ashikawa::Core::ClientError, "#{error_num}: #{error_message}")
|
123
130
|
|
124
131
|
request_stub.verify_stubbed_calls
|
125
132
|
end
|
@@ -138,12 +145,16 @@ describe Ashikawa::Core::Connection do
|
|
138
145
|
|
139
146
|
it "should throw a general server error for the generic server error" do
|
140
147
|
request_stub.get("/_api/bad/request") do
|
141
|
-
[
|
148
|
+
[
|
149
|
+
500,
|
150
|
+
response_headers,
|
151
|
+
JSON.generate({ "error" => true, "errorNum" => error_num, "errorMessage" => error_message })
|
152
|
+
]
|
142
153
|
end
|
143
154
|
|
144
155
|
expect do
|
145
156
|
subject.send_request("bad/request")
|
146
|
-
end.to raise_error(Ashikawa::Core::ServerError,
|
157
|
+
end.to raise_error(Ashikawa::Core::ServerError, "#{error_num}: #{error_message}")
|
147
158
|
|
148
159
|
request_stub.verify_stubbed_calls
|
149
160
|
end
|
@@ -218,7 +229,7 @@ describe Ashikawa::Core::Connection do
|
|
218
229
|
|
219
230
|
it "should log a get request" do
|
220
231
|
request_stub.get("/_api/test") do
|
221
|
-
[200, response_headers,
|
232
|
+
[200, response_headers, JSON.generate({:a => 1})]
|
222
233
|
end
|
223
234
|
logger.should_receive(:info).with("GET #{ARANGO_HOST}/_api/test ")
|
224
235
|
logger.should_receive(:info).with("200 {\"a\":1}")
|
@@ -226,10 +237,8 @@ describe Ashikawa::Core::Connection do
|
|
226
237
|
end
|
227
238
|
|
228
239
|
it "should log a post request" do
|
229
|
-
pending "This fails on 1.8.7 for unknown reasons. Will investigate." if RUBY_VERSION == "1.8.7"
|
230
|
-
|
231
240
|
request_stub.post("/_api/test") do
|
232
|
-
[201, response_headers,
|
241
|
+
[201, response_headers, JSON.generate({:b => 2})]
|
233
242
|
end
|
234
243
|
logger.should_receive(:info).with("POST #{ARANGO_HOST}/_api/test {:a=>2}")
|
235
244
|
logger.should_receive(:info).with("201 {\"b\":2}")
|
data/spec/unit/cursor_spec.rb
CHANGED
@@ -5,8 +5,8 @@ describe Ashikawa::Core::Cursor do
|
|
5
5
|
subject { Ashikawa::Core::Cursor }
|
6
6
|
|
7
7
|
before :each do
|
8
|
-
@database = double
|
9
|
-
|
8
|
+
@database = double
|
9
|
+
double Ashikawa::Core::Document
|
10
10
|
end
|
11
11
|
|
12
12
|
it "should create a cursor for a non-complete batch" do
|
@@ -46,8 +46,6 @@ describe Ashikawa::Core::Cursor do
|
|
46
46
|
end
|
47
47
|
|
48
48
|
it "should return an enumerator to go over all documents of a cursor when given no block" do
|
49
|
-
pending "This fails on 1.8.7 because of an old backports version" if RUBY_VERSION == "1.8.7"
|
50
|
-
|
51
49
|
first = true
|
52
50
|
|
53
51
|
@database.stub(:send_request).with("cursor/26011191", :put => {}) do
|
@@ -98,5 +96,18 @@ describe Ashikawa::Core::Cursor do
|
|
98
96
|
|
99
97
|
subject.map{|i| i}[0].should == 1
|
100
98
|
end
|
99
|
+
|
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
|
105
|
+
|
106
|
+
Ashikawa::Core::Edge.stub(:new).and_return { 1 }
|
107
|
+
Ashikawa::Core::Edge.should_receive(:new).exactly(2).times
|
108
|
+
|
109
|
+
subject.each { |document| }
|
110
|
+
end
|
111
|
+
|
101
112
|
end
|
102
113
|
end
|
data/spec/unit/database_spec.rb
CHANGED
@@ -5,10 +5,11 @@ describe Ashikawa::Core::Database do
|
|
5
5
|
subject { Ashikawa::Core::Database }
|
6
6
|
|
7
7
|
before :each do
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
double(Ashikawa::Core::Connection)
|
9
|
+
double(Ashikawa::Core::Collection)
|
10
|
+
double(Ashikawa::Core::Cursor)
|
11
|
+
double(Ashikawa::Core::Transaction)
|
12
|
+
@connection = double("connection", :host => "localhost", :port => 8529, :scheme => "http")
|
12
13
|
end
|
13
14
|
|
14
15
|
it "should initialize with a connection" do
|
@@ -26,13 +27,13 @@ describe Ashikawa::Core::Database do
|
|
26
27
|
Ashikawa::Core::Connection.stub(:new).with("http://localhost:8529", {
|
27
28
|
:logger => nil,
|
28
29
|
:adapter => nil
|
29
|
-
}).and_return(double
|
30
|
+
}).and_return(double)
|
30
31
|
Ashikawa::Core::Connection.should_receive(:new).with("http://localhost:8529", {
|
31
32
|
:logger => nil,
|
32
33
|
:adapter => nil
|
33
34
|
})
|
34
35
|
|
35
|
-
|
36
|
+
subject.new do |config|
|
36
37
|
config.url = "http://localhost:8529"
|
37
38
|
end
|
38
39
|
end
|
@@ -42,13 +43,13 @@ describe Ashikawa::Core::Database do
|
|
42
43
|
Ashikawa::Core::Connection.stub(:new).with("http://localhost:8529", {
|
43
44
|
:logger => logger,
|
44
45
|
:adapter => nil
|
45
|
-
}).and_return(double
|
46
|
+
}).and_return(double)
|
46
47
|
Ashikawa::Core::Connection.should_receive(:new).with("http://localhost:8529", {
|
47
48
|
:logger => logger,
|
48
49
|
:adapter => nil
|
49
50
|
})
|
50
51
|
|
51
|
-
|
52
|
+
subject.new do |config|
|
52
53
|
config.url = "http://localhost:8529"
|
53
54
|
config.logger = logger
|
54
55
|
end
|
@@ -59,13 +60,13 @@ describe Ashikawa::Core::Database do
|
|
59
60
|
Ashikawa::Core::Connection.stub(:new).with("http://localhost:8529", {
|
60
61
|
:logger => nil,
|
61
62
|
:adapter => adapter
|
62
|
-
}).and_return(double
|
63
|
+
}).and_return(double)
|
63
64
|
Ashikawa::Core::Connection.should_receive(:new).with("http://localhost:8529", {
|
64
65
|
:logger => nil,
|
65
66
|
:adapter => adapter
|
66
67
|
})
|
67
68
|
|
68
|
-
|
69
|
+
subject.new do |config|
|
69
70
|
config.url = "http://localhost:8529"
|
70
71
|
config.adapter = adapter
|
71
72
|
end
|
@@ -76,7 +77,7 @@ describe Ashikawa::Core::Database do
|
|
76
77
|
logger = double
|
77
78
|
|
78
79
|
expect {
|
79
|
-
|
80
|
+
subject.new do |config|
|
80
81
|
config.adapter = adapter
|
81
82
|
config.logger = logger
|
82
83
|
end
|
@@ -88,7 +89,7 @@ describe Ashikawa::Core::Database do
|
|
88
89
|
config.connection = @connection
|
89
90
|
end
|
90
91
|
|
91
|
-
|
92
|
+
double Ashikawa::Core::Query
|
92
93
|
Ashikawa::Core::Query.stub(:new)
|
93
94
|
Ashikawa::Core::Query.should_receive(:new).exactly(1).times.with(database)
|
94
95
|
|
@@ -96,7 +97,8 @@ describe Ashikawa::Core::Database do
|
|
96
97
|
end
|
97
98
|
|
98
99
|
describe "initialized database" do
|
99
|
-
subject {
|
100
|
+
subject {
|
101
|
+
Ashikawa::Core::Database.new do |config|
|
100
102
|
config.connection = @connection
|
101
103
|
end
|
102
104
|
}
|
@@ -107,16 +109,26 @@ describe Ashikawa::Core::Database do
|
|
107
109
|
subject.authenticate_with :username => "user", :password => "password"
|
108
110
|
end
|
109
111
|
|
110
|
-
it "should fetch all available collections" do
|
112
|
+
it "should fetch all available non-system collections" do
|
111
113
|
@connection.stub(:send_request) {|path| server_response("collections/all") }
|
112
114
|
@connection.should_receive(:send_request).with("collection")
|
113
115
|
|
114
|
-
|
115
|
-
|
116
|
+
(0..1).each do |k|
|
117
|
+
Ashikawa::Core::Collection.should_receive(:new).with(subject, server_response("collections/all")["collections"][k])
|
118
|
+
end
|
116
119
|
|
117
120
|
subject.collections.length.should == 2
|
118
121
|
end
|
119
122
|
|
123
|
+
it "should fetch all available non-system collections" do
|
124
|
+
@connection.stub(:send_request) {|path| server_response("collections/all") }
|
125
|
+
@connection.should_receive(:send_request).with("collection")
|
126
|
+
|
127
|
+
Ashikawa::Core::Collection.should_receive(:new).exactly(5).times
|
128
|
+
|
129
|
+
subject.system_collections.length.should == 5
|
130
|
+
end
|
131
|
+
|
120
132
|
it "should create a non volatile collection by default" do
|
121
133
|
@connection.stub(:send_request) { |path| server_response("collections/60768679") }
|
122
134
|
@connection.should_receive(:send_request).with("collection",
|
@@ -137,6 +149,26 @@ describe Ashikawa::Core::Database do
|
|
137
149
|
subject.create_collection("volatile_collection", :is_volatile => true)
|
138
150
|
end
|
139
151
|
|
152
|
+
it "should create an autoincrement collection when asked" do
|
153
|
+
@connection.should_receive(:send_request).with("collection",
|
154
|
+
:post => { :name => "autoincrement_collection", :keyOptions => {
|
155
|
+
:type => "autoincrement",
|
156
|
+
:offset => 0,
|
157
|
+
:increment => 10,
|
158
|
+
:allowUserKeys => false
|
159
|
+
}
|
160
|
+
})
|
161
|
+
|
162
|
+
Ashikawa::Core::Collection.should_receive(:new)
|
163
|
+
|
164
|
+
subject.create_collection("autoincrement_collection", :key_options => {
|
165
|
+
:type => :autoincrement,
|
166
|
+
:offset => 0,
|
167
|
+
:increment => 10,
|
168
|
+
:allow_user_keys => false
|
169
|
+
})
|
170
|
+
end
|
171
|
+
|
140
172
|
it "should create an edge collection when asked" do
|
141
173
|
@connection.stub(:send_request) { |path| server_response("collections/60768679") }
|
142
174
|
@connection.should_receive(:send_request).with("collection",
|
@@ -175,7 +207,7 @@ describe Ashikawa::Core::Database do
|
|
175
207
|
end
|
176
208
|
end
|
177
209
|
@connection.should_receive(:send_request).with("collection/new_collection")
|
178
|
-
@connection.should_receive(:send_request).with("collection", :post => { :name => "new_collection"}
|
210
|
+
@connection.should_receive(:send_request).with("collection", :post => { :name => "new_collection"})
|
179
211
|
|
180
212
|
Ashikawa::Core::Collection.should_receive(:new).with(subject, server_response("collections/60768679"))
|
181
213
|
|
@@ -187,5 +219,14 @@ describe Ashikawa::Core::Database do
|
|
187
219
|
|
188
220
|
subject.send_request "my/path", :post => { :data => "mydata" }
|
189
221
|
end
|
222
|
+
|
223
|
+
let(:js_function) { double }
|
224
|
+
let(:collections) { double }
|
225
|
+
let(:transaction) { double }
|
226
|
+
|
227
|
+
it "should create a transaction" do
|
228
|
+
Ashikawa::Core::Transaction.should_receive(:new).with(subject, js_function, collections).and_return { transaction }
|
229
|
+
subject.create_transaction(js_function, collections).should == transaction
|
230
|
+
end
|
190
231
|
end
|
191
232
|
end
|