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
data/spec/unit/edge_spec.rb
CHANGED
@@ -1,54 +1,66 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
1
2
|
require 'unit/spec_helper'
|
2
3
|
require 'ashikawa-core/edge'
|
3
4
|
|
4
5
|
describe Ashikawa::Core::Edge do
|
5
6
|
let(:database) { double }
|
6
|
-
let(:
|
7
|
+
let(:id) { 412 }
|
8
|
+
let(:path) { 'edge/412' }
|
9
|
+
let(:key) { double }
|
10
|
+
let(:revision) { double }
|
11
|
+
let(:from_id) { double }
|
12
|
+
let(:to_id) { double }
|
13
|
+
let(:first_name) { double }
|
14
|
+
let(:last_name) { double }
|
15
|
+
let(:raw_data) do
|
7
16
|
{
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
17
|
+
'_id' => id,
|
18
|
+
'_key' => key,
|
19
|
+
'_rev' => revision,
|
20
|
+
'_from' => from_id,
|
21
|
+
'_to' => to_id,
|
22
|
+
'first_name' => first_name,
|
23
|
+
'last_name' => last_name
|
15
24
|
}
|
16
|
-
}
|
17
|
-
subject { Ashikawa::Core::Edge }
|
18
|
-
|
19
|
-
it "should initialize data" do
|
20
|
-
document = subject.new(database, raw_data)
|
21
|
-
document.id.should == "1234567/2345678"
|
22
|
-
document.key.should == "2345678"
|
23
|
-
document.revision.should == "3456789"
|
24
25
|
end
|
26
|
+
let(:new_last_name) { double }
|
27
|
+
let(:raw_data_without_meta_data_and_new_last_name) do
|
28
|
+
{
|
29
|
+
'first_name' => first_name,
|
30
|
+
'last_name' => new_last_name
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
describe 'initialized edge' do
|
35
|
+
subject { Ashikawa::Core::Edge.new(database, raw_data) }
|
25
36
|
|
26
|
-
|
27
|
-
|
37
|
+
its(:id) { should be(id) }
|
38
|
+
its(:key) { should be(key) }
|
39
|
+
its(:revision) { should be(revision) }
|
40
|
+
its(:from_id) { should eq(from_id) }
|
41
|
+
its(:to_id) { should eq(to_id) }
|
28
42
|
|
29
|
-
it
|
30
|
-
database.
|
31
|
-
{ :
|
32
|
-
)
|
43
|
+
it 'should be deletable' do
|
44
|
+
expect(database).to receive(:send_request)
|
45
|
+
.with(path, { delete: {} })
|
33
46
|
|
34
47
|
subject.delete
|
35
48
|
end
|
36
49
|
|
37
|
-
it
|
38
|
-
database.
|
39
|
-
{ :
|
40
|
-
)
|
50
|
+
it 'should store changes to the database' do
|
51
|
+
expect(database).to receive(:send_request)
|
52
|
+
.with(path, { put: raw_data_without_meta_data_and_new_last_name })
|
41
53
|
|
42
|
-
subject[
|
54
|
+
subject['last_name'] = new_last_name
|
43
55
|
subject.save
|
44
56
|
end
|
57
|
+
end
|
45
58
|
|
46
|
-
|
47
|
-
|
48
|
-
|
59
|
+
describe 'initializing edge with additional data' do
|
60
|
+
let(:more_info) { double }
|
61
|
+
let(:additional_data) {{ more_info: more_info }}
|
62
|
+
subject { Ashikawa::Core::Edge.new(database, raw_data, additional_data) }
|
49
63
|
|
50
|
-
|
51
|
-
subject.to_id.should == "7848004/9355332"
|
52
|
-
end
|
64
|
+
its(['more_info']) { should eq(more_info) }
|
53
65
|
end
|
54
66
|
end
|
data/spec/unit/exception_spec.rb
CHANGED
@@ -1,65 +1,55 @@
|
|
1
|
-
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'ashikawa-core/exceptions/no_collection_provided'
|
3
|
+
require 'ashikawa-core/exceptions/client_error'
|
4
|
+
require 'ashikawa-core/exceptions/client_error/authentication_failed'
|
5
|
+
require 'ashikawa-core/exceptions/client_error/bad_syntax'
|
6
|
+
require 'ashikawa-core/exceptions/client_error/resource_not_found'
|
7
|
+
require 'ashikawa-core/exceptions/client_error/resource_not_found/document_not_found'
|
8
|
+
require 'ashikawa-core/exceptions/client_error/resource_not_found/collection_not_found'
|
9
|
+
require 'ashikawa-core/exceptions/client_error/resource_not_found/index_not_found'
|
10
|
+
require 'ashikawa-core/exceptions/server_error'
|
11
|
+
require 'ashikawa-core/exceptions/server_error/json_error'
|
10
12
|
|
11
13
|
describe Ashikawa::Core::NoCollectionProvidedException do
|
12
|
-
|
13
|
-
subject.to_s.should include "without a collection"
|
14
|
-
end
|
14
|
+
its(:to_s) { should include 'without a collection' }
|
15
15
|
end
|
16
16
|
|
17
17
|
describe Ashikawa::Core::ClientError do
|
18
|
-
let(:error_message) {
|
19
|
-
|
20
|
-
|
21
|
-
end
|
18
|
+
let(:error_message) { double }
|
19
|
+
subject { Ashikawa::Core::ClientError.new(error_message) }
|
20
|
+
its(:to_s) { should be(error_message) }
|
22
21
|
end
|
23
22
|
|
24
23
|
describe Ashikawa::Core::BadSyntax do
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
its(:to_s) { should include 'syntax' }
|
25
|
+
end
|
26
|
+
|
27
|
+
describe Ashikawa::Core::AuthenticationFailed do
|
28
|
+
its(:to_s) { should include 'Authentication failed' }
|
28
29
|
end
|
29
30
|
|
30
31
|
describe Ashikawa::Core::ResourceNotFound do
|
31
|
-
|
32
|
-
subject.to_s.should include "was not found"
|
33
|
-
end
|
32
|
+
its(:to_s) { should include 'was not found' }
|
34
33
|
end
|
35
34
|
|
36
35
|
describe Ashikawa::Core::DocumentNotFoundException do
|
37
|
-
|
38
|
-
subject.to_s.should include "does not exist"
|
39
|
-
end
|
36
|
+
its(:to_s) { should include 'does not exist' }
|
40
37
|
end
|
41
38
|
|
42
39
|
describe Ashikawa::Core::CollectionNotFoundException do
|
43
|
-
|
44
|
-
subject.to_s.should include "does not exist"
|
45
|
-
end
|
40
|
+
its(:to_s) { should include 'does not exist' }
|
46
41
|
end
|
47
42
|
|
48
43
|
describe Ashikawa::Core::IndexNotFoundException do
|
49
|
-
|
50
|
-
subject.to_s.should include "does not exist"
|
51
|
-
end
|
44
|
+
its(:to_s) { should include 'does not exist' }
|
52
45
|
end
|
53
46
|
|
54
47
|
describe Ashikawa::Core::ServerError do
|
55
|
-
let(:error_message) {
|
56
|
-
|
57
|
-
|
58
|
-
end
|
48
|
+
let(:error_message) { double }
|
49
|
+
subject { Ashikawa::Core::ServerError.new(error_message) }
|
50
|
+
its(:to_s) { should be(error_message) }
|
59
51
|
end
|
60
52
|
|
61
53
|
describe Ashikawa::Core::JsonError do
|
62
|
-
|
63
|
-
subject.to_s.should include "JSON from the server"
|
64
|
-
end
|
54
|
+
its(:to_s) { should include 'JSON from the server' }
|
65
55
|
end
|
data/spec/unit/figure_spec.rb
CHANGED
@@ -1,61 +1,58 @@
|
|
1
|
-
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'ashikawa-core/figure'
|
2
3
|
|
3
4
|
describe Ashikawa::Core::Figure do
|
4
|
-
let(:
|
5
|
+
let(:alive_size) { double }
|
6
|
+
let(:alive_count) { double }
|
7
|
+
let(:dead_size) { double }
|
8
|
+
let(:dead_count) { double }
|
9
|
+
let(:dead_deletion) { double }
|
10
|
+
let(:datafiles_count) { double }
|
11
|
+
let(:datafiles_file_size) { double }
|
12
|
+
let(:journals_count) { double }
|
13
|
+
let(:journals_file_size) { double }
|
14
|
+
let(:shapes_count) { double }
|
15
|
+
let(:attributes_count) { double }
|
16
|
+
|
17
|
+
let(:raw_figures) do
|
5
18
|
{
|
6
|
-
|
7
|
-
|
8
|
-
|
19
|
+
'alive' => {
|
20
|
+
'size' => alive_size,
|
21
|
+
'count' => alive_count
|
9
22
|
},
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
23
|
+
'dead' => {
|
24
|
+
'size' => dead_size,
|
25
|
+
'count' => dead_count,
|
26
|
+
'deletion' => dead_deletion
|
14
27
|
},
|
15
|
-
|
16
|
-
|
17
|
-
|
28
|
+
'datafiles' => {
|
29
|
+
'count' => datafiles_count,
|
30
|
+
'fileSize' => datafiles_file_size
|
18
31
|
},
|
19
|
-
|
20
|
-
|
21
|
-
|
32
|
+
'journals' => {
|
33
|
+
'count' => journals_count,
|
34
|
+
'fileSize' => journals_file_size
|
22
35
|
},
|
23
|
-
|
24
|
-
|
36
|
+
'shapes' => {
|
37
|
+
'count' => shapes_count
|
25
38
|
},
|
26
|
-
|
27
|
-
|
39
|
+
'attributes' => {
|
40
|
+
'count' => attributes_count
|
28
41
|
}
|
29
42
|
}
|
30
|
-
}
|
31
|
-
subject { Ashikawa::Core::Figure.new(raw_figures) }
|
32
|
-
|
33
|
-
it "should check for the alive figures" do
|
34
|
-
subject.alive_size.should == 0
|
35
|
-
subject.alive_count.should == 0
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should check for the dead figures" do
|
39
|
-
subject.dead_size.should == 2384
|
40
|
-
subject.dead_count.should == 149
|
41
|
-
subject.dead_deletion.should == 0
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should check for the datafiles figures" do
|
45
|
-
subject.datafiles_count.should == 1
|
46
|
-
subject.datafiles_file_size.should == 124
|
47
|
-
end
|
48
|
-
|
49
|
-
it "should check for the journal figures" do
|
50
|
-
subject.journals_count.should == 1
|
51
|
-
subject.journals_file_size.should == 124
|
52
43
|
end
|
53
44
|
|
54
|
-
|
55
|
-
subject.shapes_count.should == 2
|
56
|
-
end
|
45
|
+
subject { Ashikawa::Core::Figure.new(raw_figures) }
|
57
46
|
|
58
|
-
|
59
|
-
|
60
|
-
|
47
|
+
its(:alive_size) { should be(alive_size) }
|
48
|
+
its(:alive_count) { should be(alive_count) }
|
49
|
+
its(:dead_size) { should be(dead_size) }
|
50
|
+
its(:dead_count) { should be(dead_count) }
|
51
|
+
its(:dead_deletion) { should be(dead_deletion) }
|
52
|
+
its(:datafiles_count) { should be(datafiles_count) }
|
53
|
+
its(:datafiles_file_size) { should be(datafiles_file_size) }
|
54
|
+
its(:journals_count) { should be(journals_count) }
|
55
|
+
its(:journals_file_size) { should be(journals_file_size) }
|
56
|
+
its(:shapes_count) { should be(shapes_count) }
|
57
|
+
its(:attributes_count) { should be(attributes_count) }
|
61
58
|
end
|
data/spec/unit/index_spec.rb
CHANGED
@@ -1,37 +1,40 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
1
2
|
require 'unit/spec_helper'
|
2
3
|
require 'ashikawa-core/index'
|
3
4
|
|
4
5
|
describe Ashikawa::Core::Index do
|
5
6
|
let(:collection) { double }
|
6
|
-
let(:
|
7
|
+
let(:id) { '167137465/168054969' }
|
8
|
+
let(:path) { 'index/167137465/168054969' }
|
9
|
+
let(:delete_payload) {{ delete: {} }}
|
10
|
+
let(:type_as_sym) { double }
|
11
|
+
let(:type) { double(to_sym: type_as_sym) }
|
12
|
+
let(:field_as_sym) { double }
|
13
|
+
let(:field) { double(to_sym: field_as_sym) }
|
14
|
+
let(:unique) { double }
|
15
|
+
let(:raw_data) do
|
7
16
|
{
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
"unique" => true,
|
16
|
-
"error" => false
|
17
|
+
'code' => 201,
|
18
|
+
'fields' => [field],
|
19
|
+
'id' => id,
|
20
|
+
'type' => type,
|
21
|
+
'isNewlyCreated' => true,
|
22
|
+
'unique' => unique,
|
23
|
+
'error' => false
|
17
24
|
}
|
18
|
-
}
|
19
|
-
subject { Ashikawa::Core::Index }
|
20
|
-
|
21
|
-
it "should initialize an Index" do
|
22
|
-
index = subject.new collection, raw_data
|
23
|
-
index.id.should == "167137465/168054969"
|
24
|
-
index.type.should == :hash
|
25
|
-
index.on.should == [:something]
|
26
|
-
index.unique.should == true
|
27
25
|
end
|
28
26
|
|
29
|
-
describe
|
30
|
-
subject { Ashikawa::Core::Index.new
|
27
|
+
describe 'initialized index' do
|
28
|
+
subject { Ashikawa::Core::Index.new(collection, raw_data) }
|
29
|
+
|
30
|
+
its(:id) { should be(id) }
|
31
|
+
its(:type) { should be(type_as_sym) }
|
32
|
+
its(:on) { should include(field_as_sym) }
|
33
|
+
its(:unique) { should be(unique) }
|
31
34
|
|
32
|
-
it
|
33
|
-
collection.
|
34
|
-
|
35
|
+
it 'should be deletable' do
|
36
|
+
expect(collection).to receive(:send_request)
|
37
|
+
.with(path, delete_payload)
|
35
38
|
|
36
39
|
subject.delete
|
37
40
|
end
|
@@ -1,25 +1,27 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
1
2
|
require 'unit/spec_helper'
|
2
3
|
require 'ashikawa-core/key_options'
|
3
4
|
|
4
5
|
describe Ashikawa::Core::KeyOptions do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
let(:type) { double }
|
7
|
+
let(:offset) { double }
|
8
|
+
let(:increment) { double }
|
9
|
+
let(:allow_user_keys) { double }
|
10
|
+
let(:raw_key_options) do
|
11
|
+
{
|
12
|
+
'type' => type,
|
13
|
+
'offset' => offset,
|
14
|
+
'increment' => increment,
|
15
|
+
'allowUserKeys' => allow_user_keys
|
16
|
+
}
|
17
|
+
end
|
12
18
|
|
13
|
-
|
14
|
-
|
15
|
-
"offset" => offset,
|
16
|
-
"increment" => increment,
|
17
|
-
"allowUserKeys" => allow_user_keys
|
18
|
-
})
|
19
|
+
describe 'initialized key options' do
|
20
|
+
subject { Ashikawa::Core::KeyOptions.new(raw_key_options) }
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
22
|
+
its(:type) { should eq(type) }
|
23
|
+
its(:offset) { should eq(offset) }
|
24
|
+
its(:increment) { should eq(increment) }
|
25
|
+
its(:allow_user_keys) { should eq(allow_user_keys) }
|
24
26
|
end
|
25
27
|
end
|
data/spec/unit/query_spec.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
1
2
|
require 'unit/spec_helper'
|
2
3
|
require 'ashikawa-core/query'
|
3
4
|
|
@@ -5,210 +6,260 @@ describe Ashikawa::Core::Query do
|
|
5
6
|
let(:collection) { double }
|
6
7
|
let(:database) { double }
|
7
8
|
|
8
|
-
describe
|
9
|
-
subject { Ashikawa::Core::Query.new
|
9
|
+
describe 'initialized with collection' do
|
10
|
+
subject { Ashikawa::Core::Query.new(collection) }
|
11
|
+
let(:name) { double }
|
10
12
|
|
11
13
|
before do
|
12
|
-
collection.
|
13
|
-
collection.
|
14
|
+
allow(collection).to receive(:name).and_return(name)
|
15
|
+
allow(collection).to receive(:database).and_return(double)
|
14
16
|
end
|
15
17
|
|
16
|
-
describe
|
17
|
-
|
18
|
-
|
19
|
-
collection.should_receive(:send_request).with("simple/all", :put => {"collection" => "example_1"})
|
18
|
+
describe 'get all' do
|
19
|
+
let(:limit) { double }
|
20
|
+
let(:skip) { double }
|
20
21
|
|
21
|
-
|
22
|
+
it 'should list all documents' do
|
23
|
+
expect(collection).to receive(:send_request)
|
24
|
+
.with('simple/all', put: { 'collection' => name })
|
25
|
+
.and_return { server_response('simple-queries/all') }
|
26
|
+
expect(Ashikawa::Core::Cursor).to receive(:new)
|
22
27
|
|
23
28
|
subject.all
|
24
29
|
end
|
25
30
|
|
26
|
-
it
|
27
|
-
collection.
|
28
|
-
|
31
|
+
it 'should be able to limit the number of documents' do
|
32
|
+
expect(collection).to receive(:send_request)
|
33
|
+
.with('simple/all', put: { 'collection' => name, 'limit' => limit })
|
34
|
+
.and_return { server_response('simple-queries/all_skip') }
|
35
|
+
expect(Ashikawa::Core::Cursor).to receive(:new)
|
29
36
|
|
30
|
-
|
31
|
-
|
32
|
-
subject.all :limit => 1
|
37
|
+
subject.all(limit: limit)
|
33
38
|
end
|
34
39
|
|
35
|
-
it
|
36
|
-
collection.
|
37
|
-
|
38
|
-
|
39
|
-
Ashikawa::Core::Cursor.
|
40
|
+
it 'should be able to skip documents' do
|
41
|
+
expect(collection).to receive(:send_request)
|
42
|
+
.with('simple/all', put: { 'collection' => name, 'skip' => skip })
|
43
|
+
.and_return { server_response('simple-queries/all_limit') }
|
44
|
+
expect(Ashikawa::Core::Cursor).to receive(:new)
|
40
45
|
|
41
|
-
subject.all
|
46
|
+
subject.all(skip: skip)
|
42
47
|
end
|
43
48
|
end
|
44
49
|
|
45
|
-
describe
|
46
|
-
let(:example) {
|
47
|
-
|
48
|
-
it "should find exactly one fitting document" do
|
49
|
-
collection.stub(:database).and_return { double }
|
50
|
+
describe 'first by example' do
|
51
|
+
let(:example) { double }
|
52
|
+
let(:response) { server_response('simple-queries/example') }
|
50
53
|
|
51
|
-
|
52
|
-
collection.
|
53
|
-
|
54
|
+
it 'should find exactly one fitting document' do
|
55
|
+
allow(collection).to receive(:database)
|
56
|
+
.and_return(double)
|
57
|
+
expect(collection).to receive(:send_request)
|
58
|
+
.with('simple/first-example', put: { 'collection' => name, 'example' => example })
|
59
|
+
.and_return(response)
|
60
|
+
expect(Ashikawa::Core::Document).to receive(:new)
|
54
61
|
|
55
|
-
|
56
|
-
|
57
|
-
subject.first_example example
|
62
|
+
subject.first_example(example)
|
58
63
|
end
|
59
64
|
end
|
60
65
|
|
61
|
-
describe
|
62
|
-
let(:example) {
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
collection.should_receive(:send_request).with("simple/by-example", :put =>
|
67
|
-
{"collection" => "example_1", "example" => { :hello => "world"}})
|
66
|
+
describe 'all by example' do
|
67
|
+
let(:example) {{ hello: 'world' }}
|
68
|
+
let(:response) { server_response('simple-queries/example') }
|
69
|
+
let(:limit) { double }
|
70
|
+
let(:skip) { double }
|
68
71
|
|
69
|
-
|
72
|
+
it 'should find all fitting documents' do
|
73
|
+
expect(collection).to receive(:send_request)
|
74
|
+
.with('simple/by-example', put: { 'collection' => name, 'example' => example })
|
75
|
+
.and_return(response)
|
76
|
+
expect(Ashikawa::Core::Cursor).to receive(:new)
|
70
77
|
|
71
|
-
subject.by_example
|
78
|
+
subject.by_example(example)
|
72
79
|
end
|
73
80
|
|
74
|
-
it
|
75
|
-
collection.
|
76
|
-
|
81
|
+
it 'should be able to limit the number of documents' do
|
82
|
+
expect(collection).to receive(:send_request)
|
83
|
+
.with('simple/by-example', put: { 'collection' => name, 'limit' => limit, 'example' => example })
|
84
|
+
.and_return(response)
|
85
|
+
expect(Ashikawa::Core::Cursor).to receive(:new)
|
77
86
|
|
78
|
-
|
79
|
-
|
80
|
-
subject.by_example example, :limit => 2
|
87
|
+
subject.by_example(example, limit: limit)
|
81
88
|
end
|
82
89
|
|
83
|
-
it
|
84
|
-
collection.
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
Ashikawa::Core::Cursor.should_receive(:new)
|
90
|
+
it 'should be able to skip documents' do
|
91
|
+
expect(collection).to receive(:send_request)
|
92
|
+
.with('simple/by-example', put: { 'collection' => name, 'skip' => skip, 'example' => example })
|
93
|
+
.and_return(response)
|
94
|
+
expect(Ashikawa::Core::Cursor).to receive(:new)
|
89
95
|
|
90
|
-
subject.by_example
|
96
|
+
subject.by_example(example, skip: skip)
|
91
97
|
end
|
92
98
|
end
|
93
99
|
|
94
|
-
describe
|
95
|
-
|
96
|
-
|
97
|
-
|
100
|
+
describe 'near a geolocation' do
|
101
|
+
let(:latitude) { double }
|
102
|
+
let(:longitude) { double }
|
103
|
+
let(:arguments) do
|
104
|
+
{
|
105
|
+
'collection' => name,
|
106
|
+
'latitude' => latitude,
|
107
|
+
'longitude' => longitude
|
108
|
+
}
|
109
|
+
end
|
110
|
+
let(:response) { server_response('simple-queries/near') }
|
98
111
|
|
99
|
-
|
112
|
+
it 'should find documents based on latitude/longitude' do
|
113
|
+
expect(collection).to receive(:send_request)
|
114
|
+
.with('simple/near', put: arguments)
|
115
|
+
.and_return { response }
|
116
|
+
expect(Ashikawa::Core::Cursor).to receive(:new)
|
100
117
|
|
101
|
-
subject.near
|
118
|
+
subject.near(latitude: latitude, longitude: longitude)
|
102
119
|
end
|
103
120
|
end
|
104
121
|
|
105
|
-
describe
|
106
|
-
|
107
|
-
|
108
|
-
|
122
|
+
describe 'within a radius of a geolocation' do
|
123
|
+
let(:latitude) { double }
|
124
|
+
let(:longitude) { double }
|
125
|
+
let(:radius) { double }
|
126
|
+
let(:arguments) do
|
127
|
+
{
|
128
|
+
'collection' => name,
|
129
|
+
'latitude' => latitude,
|
130
|
+
'longitude' => longitude,
|
131
|
+
'radius' => radius
|
132
|
+
}
|
133
|
+
end
|
134
|
+
let(:response) { server_response('simple-queries/within') }
|
109
135
|
|
110
|
-
|
136
|
+
it 'should look for documents based on latidude/longitude' do
|
137
|
+
expect(collection).to receive(:send_request)
|
138
|
+
.with('simple/within' , put: arguments)
|
139
|
+
.and_return { response }
|
140
|
+
expect(Ashikawa::Core::Cursor).to receive(:new)
|
111
141
|
|
112
|
-
subject.within
|
142
|
+
subject.within(latitude: latitude, longitude: longitude, radius: radius)
|
113
143
|
end
|
114
144
|
end
|
115
145
|
|
116
|
-
describe
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
146
|
+
describe 'in a certain range' do
|
147
|
+
let(:attribute) { double }
|
148
|
+
let(:left) { double }
|
149
|
+
let(:right) { double }
|
150
|
+
let(:closed) { double }
|
151
|
+
let(:arguments) do
|
152
|
+
{
|
153
|
+
'collection' => name,
|
154
|
+
'attribute' => attribute,
|
155
|
+
'left' => left,
|
156
|
+
'right' => right,
|
157
|
+
'closed' => closed
|
158
|
+
}
|
159
|
+
end
|
160
|
+
let(:response) { server_response('simple-queries/range') }
|
121
161
|
|
122
|
-
|
162
|
+
it 'should look for documents with an attribute in that range' do
|
163
|
+
expect(collection).to receive(:send_request)
|
164
|
+
.with('simple/range' , put: arguments)
|
165
|
+
.and_return { response }
|
166
|
+
expect(Ashikawa::Core::Cursor).to receive(:new)
|
123
167
|
|
124
|
-
subject.in_range
|
168
|
+
subject.in_range(attribute: attribute, left: left, right: right, closed: closed)
|
125
169
|
end
|
126
170
|
end
|
127
171
|
|
128
|
-
describe
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
172
|
+
describe 'with an AQL query' do
|
173
|
+
let(:query) { double }
|
174
|
+
let(:count) { double }
|
175
|
+
let(:batch_size) { double }
|
176
|
+
let(:arguments) do
|
177
|
+
{
|
178
|
+
'query' => query,
|
179
|
+
'count' => count,
|
180
|
+
'batchSize' => batch_size
|
181
|
+
}
|
182
|
+
end
|
183
|
+
let(:response) { server_response('cursor/query') }
|
184
|
+
|
185
|
+
it 'should be able to execute it' do
|
186
|
+
allow(collection).to receive(:database)
|
187
|
+
.and_return(double)
|
188
|
+
expect(collection).to receive(:send_request)
|
189
|
+
.with('cursor', post: arguments)
|
190
|
+
.and_return(response)
|
191
|
+
expect(Ashikawa::Core::Cursor).to receive(:new)
|
192
|
+
.with(collection.database, response)
|
193
|
+
|
194
|
+
subject.execute(query, count: count, batch_size: batch_size)
|
140
195
|
end
|
141
196
|
|
142
|
-
it
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
collection.should_receive(:send_request).with("query", :post => {
|
147
|
-
"query" => query
|
148
|
-
})
|
197
|
+
it 'should return true when asked if a valid query is valid' do
|
198
|
+
expect(collection).to receive(:send_request)
|
199
|
+
.with('query', post: { 'query' => query })
|
200
|
+
.and_return { server_response('query/valid') }
|
149
201
|
|
150
|
-
subject.valid?(query).
|
202
|
+
expect(subject.valid?(query)).to be_true
|
151
203
|
end
|
152
204
|
|
153
|
-
it
|
154
|
-
|
155
|
-
|
156
|
-
collection.
|
157
|
-
|
158
|
-
end
|
159
|
-
collection.should_receive(:send_request).with("query", :post => {
|
160
|
-
"query" => query
|
161
|
-
})
|
205
|
+
it 'should return false when asked if an invalid query is valid' do
|
206
|
+
allow(collection).to receive(:send_request)
|
207
|
+
.and_raise(Ashikawa::Core::BadSyntax)
|
208
|
+
expect(collection).to receive(:send_request)
|
209
|
+
.with('query', post: { 'query' => query })
|
162
210
|
|
163
|
-
subject.valid?(query).
|
211
|
+
expect(subject.valid?(query)).to be_false
|
164
212
|
end
|
165
213
|
end
|
166
214
|
end
|
167
215
|
|
168
|
-
describe
|
169
|
-
subject { Ashikawa::Core::Query.new
|
216
|
+
describe 'initialized with database' do
|
217
|
+
subject { Ashikawa::Core::Query.new(database) }
|
170
218
|
|
171
|
-
it
|
219
|
+
it 'should throw an exception when a simple query is executed' do
|
172
220
|
[:all, :by_example, :first_example, :near, :within, :in_range].each do |method|
|
173
|
-
expect { subject.send method }.to raise_error
|
221
|
+
expect { subject.send method }.to raise_error(Ashikawa::Core::NoCollectionProvidedException)
|
174
222
|
end
|
175
223
|
end
|
176
224
|
|
177
|
-
describe
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
subject.execute "FOR u IN users LIMIT 2 RETURN u", :count => true, :batch_size => 2
|
225
|
+
describe 'with an AQL query' do
|
226
|
+
let(:query) { double }
|
227
|
+
let(:count) { double }
|
228
|
+
let(:batch_size) { double }
|
229
|
+
let(:arguments) do
|
230
|
+
{
|
231
|
+
'query' => query,
|
232
|
+
'count' => count,
|
233
|
+
'batchSize' => batch_size
|
234
|
+
}
|
188
235
|
end
|
236
|
+
let(:query_response) { server_response('cursor/query') }
|
237
|
+
let(:valid_response) { server_response('cursor/query') }
|
189
238
|
|
190
|
-
it
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
})
|
239
|
+
it 'should be able to execute it' do
|
240
|
+
expect(database).to receive(:send_request)
|
241
|
+
.with('cursor', post: arguments)
|
242
|
+
.and_return(query_response)
|
243
|
+
expect(Ashikawa::Core::Cursor).to receive(:new)
|
244
|
+
.with(database, query_response)
|
197
245
|
|
198
|
-
subject.
|
246
|
+
subject.execute(query, count: count, batch_size: batch_size)
|
199
247
|
end
|
200
248
|
|
201
|
-
it
|
202
|
-
|
249
|
+
it 'should return true when asked if a valid query is valid' do
|
250
|
+
expect(database).to receive(:send_request)
|
251
|
+
.with('query', post: { 'query' => query })
|
252
|
+
.and_return { valid_response }
|
253
|
+
|
254
|
+
expect(subject.valid?(query)).to be_true
|
255
|
+
end
|
203
256
|
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
"query" => query
|
209
|
-
})
|
257
|
+
it 'should return false when asked if an invalid query is valid' do
|
258
|
+
expect(database).to receive(:send_request)
|
259
|
+
.with('query', post: { 'query' => query })
|
260
|
+
.and_raise(Ashikawa::Core::BadSyntax)
|
210
261
|
|
211
|
-
subject.valid?(query).
|
262
|
+
expect(subject.valid?(query)).to be_false
|
212
263
|
end
|
213
264
|
end
|
214
265
|
end
|