ashikawa-core 0.8.0 → 0.9.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.
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
@@ -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(:raw_data) {
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
- "_id" => "1234567/2345678",
9
- "_key" => "2345678",
10
- "_rev" => "3456789",
11
- "_from" => "7848004/9289796",
12
- "_to" => "7848004/9355332",
13
- "first_name" => "The",
14
- "last_name" => "Dude"
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
- describe "initialized edge" do
27
- subject { Ashikawa::Core::Edge.new(database, raw_data)}
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 "should be deletable" do
30
- database.should_receive(:send_request).with("edge/#{raw_data['_id']}",
31
- { :delete => {} }
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 "should store changes to the database" do
38
- database.should_receive(:send_request).with("edge/#{raw_data['_id']}",
39
- { :put => { "first_name" => "The", "last_name" => "Other" } }
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["last_name"] = "Other"
54
+ subject['last_name'] = new_last_name
43
55
  subject.save
44
56
  end
57
+ end
45
58
 
46
- it "should know the ID of the 'from' document" do
47
- subject.from_id.should == "7848004/9289796"
48
- end
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
- it "should know the ID of the 'to' document" do
51
- subject.to_id.should == "7848004/9355332"
52
- end
64
+ its(['more_info']) { should eq(more_info) }
53
65
  end
54
66
  end
@@ -1,65 +1,55 @@
1
- require "ashikawa-core/exceptions/no_collection_provided"
2
- require "ashikawa-core/exceptions/client_error"
3
- require "ashikawa-core/exceptions/client_error/bad_syntax"
4
- require "ashikawa-core/exceptions/client_error/resource_not_found"
5
- require "ashikawa-core/exceptions/client_error/resource_not_found/document_not_found"
6
- require "ashikawa-core/exceptions/client_error/resource_not_found/collection_not_found"
7
- require "ashikawa-core/exceptions/client_error/resource_not_found/index_not_found"
8
- require "ashikawa-core/exceptions/server_error"
9
- require "ashikawa-core/exceptions/server_error/json_error"
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
- it "should have a good explanation" do
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) { "error message" }
19
- it "should have a good explanation" do
20
- Ashikawa::Core::ClientError.new(error_message).to_s.should == error_message
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
- it "should have a good explanation" do
26
- subject.to_s.should include "syntax"
27
- end
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
- it "should have a good explanation" do
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
- it "should have a good explanation" do
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
- it "should have a good explanation" do
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
- it "should have a good explanation" do
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) { "error message" }
56
- it "should have a good explanation" do
57
- Ashikawa::Core::ServerError.new(error_message).to_s.should == error_message
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
- it "should have a good explanation" do
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
@@ -1,61 +1,58 @@
1
- require "ashikawa-core/figure"
1
+ # -*- encoding : utf-8 -*-
2
+ require 'ashikawa-core/figure'
2
3
 
3
4
  describe Ashikawa::Core::Figure do
4
- let(:raw_figures) {
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
- "alive" => {
7
- "size" => 0,
8
- "count" => 0
19
+ 'alive' => {
20
+ 'size' => alive_size,
21
+ 'count' => alive_count
9
22
  },
10
- "dead" => {
11
- "size" => 2384,
12
- "count" => 149,
13
- "deletion" => 0
23
+ 'dead' => {
24
+ 'size' => dead_size,
25
+ 'count' => dead_count,
26
+ 'deletion' => dead_deletion
14
27
  },
15
- "datafiles" => {
16
- "count" => 1,
17
- "fileSize" => 124
28
+ 'datafiles' => {
29
+ 'count' => datafiles_count,
30
+ 'fileSize' => datafiles_file_size
18
31
  },
19
- "journals" => {
20
- "count" => 1,
21
- "fileSize" => 124
32
+ 'journals' => {
33
+ 'count' => journals_count,
34
+ 'fileSize' => journals_file_size
22
35
  },
23
- "shapes" => {
24
- "count" => 2
36
+ 'shapes' => {
37
+ 'count' => shapes_count
25
38
  },
26
- "attributes" => {
27
- "count" => 12
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
- it "should check for the shapes figure" do
55
- subject.shapes_count.should == 2
56
- end
45
+ subject { Ashikawa::Core::Figure.new(raw_figures) }
57
46
 
58
- it "should check for the attributes_count figure" do
59
- subject.attributes_count.should == 12
60
- end
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
@@ -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(:raw_data) {
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
- "code" => 201,
9
- "fields" => [
10
- "something"
11
- ],
12
- "id" => "167137465/168054969",
13
- "type" => "hash",
14
- "isNewlyCreated" => true,
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 "initialized index" do
30
- subject { Ashikawa::Core::Index.new collection, raw_data }
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 "should be deletable" do
33
- collection.should_receive(:send_request).with("index/167137465/168054969",
34
- :delete => {})
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
- subject { Ashikawa::Core::KeyOptions }
6
-
7
- it "should parse the key options" do
8
- type = double
9
- offset = double
10
- increment = double
11
- allow_user_keys = double
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
- key_options = subject.new({
14
- "type" => type,
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
- key_options.type.should == type
21
- key_options.offset.should == offset
22
- key_options.increment.should == increment
23
- key_options.allow_user_keys.should == allow_user_keys
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
@@ -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 "initialized with collection" do
9
- subject { Ashikawa::Core::Query.new collection }
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.stub(:name).and_return "example_1"
13
- collection.stub(:database).and_return double
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 "get all" do
17
- it "should list all documents" do
18
- collection.stub(:send_request).and_return { server_response('simple-queries/all') }
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
- Ashikawa::Core::Cursor.should_receive(:new)
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 "should be able to limit the number of documents" do
27
- collection.stub(:send_request).and_return { server_response('simple-queries/all_skip') }
28
- collection.should_receive(:send_request).with("simple/all", :put => {"collection" => "example_1", "limit" => 1})
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
- Ashikawa::Core::Cursor.should_receive(:new)
31
-
32
- subject.all :limit => 1
37
+ subject.all(limit: limit)
33
38
  end
34
39
 
35
- it "should be able to skip documents" do
36
- collection.stub(:send_request).and_return { server_response('simple-queries/all_limit') }
37
- collection.should_receive(:send_request).with("simple/all", :put => {"collection" => "example_1", "skip" => 1})
38
-
39
- Ashikawa::Core::Cursor.should_receive(:new)
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 :skip => 1
46
+ subject.all(skip: skip)
42
47
  end
43
48
  end
44
49
 
45
- describe "first by example" do
46
- let(:example) { {:hello => "world"} }
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
- collection.stub(:send_request).and_return { server_response('simple-queries/example') }
52
- collection.should_receive(:send_request).with("simple/first-example", :put =>
53
- {"collection" => "example_1", "example" => { :hello => "world"}})
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
- Ashikawa::Core::Document.should_receive(:new)
56
-
57
- subject.first_example example
62
+ subject.first_example(example)
58
63
  end
59
64
  end
60
65
 
61
- describe "all by example" do
62
- let(:example) { {:hello => "world"} }
63
-
64
- it "should find all fitting documents" do
65
- collection.stub(:send_request).and_return { server_response('simple-queries/example') }
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
- Ashikawa::Core::Cursor.should_receive(:new)
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 example
78
+ subject.by_example(example)
72
79
  end
73
80
 
74
- it "should be able to limit the number of documents" do
75
- collection.stub(:send_request).and_return { server_response('simple-queries/example') }
76
- collection.should_receive(:send_request).with("simple/by-example", :put => {"collection" => "example_1", "limit" => 2, "example" => { :hello => "world"}})
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
- Ashikawa::Core::Cursor.should_receive(:new)
79
-
80
- subject.by_example example, :limit => 2
87
+ subject.by_example(example, limit: limit)
81
88
  end
82
89
 
83
- it "should be able to skip documents" do
84
- collection.stub(:send_request).and_return { server_response('simple-queries/example') }
85
- collection.should_receive(:send_request).with("simple/by-example", :put =>
86
- {"collection" => "example_1", "skip" => 1, "example" => { :hello => "world"}})
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 example, :skip => 1
96
+ subject.by_example(example, skip: skip)
91
97
  end
92
98
  end
93
99
 
94
- describe "near a geolocation" do
95
- it "should find documents based on latitude/longitude" do
96
- collection.stub(:send_request).and_return { server_response('simple-queries/near') }
97
- collection.should_receive(:send_request).with("simple/near", :put => { "collection" => "example_1", "latitude" => 0, "longitude" => 0 })
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
- Ashikawa::Core::Cursor.should_receive(:new)
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 :latitude => 0, :longitude => 0
118
+ subject.near(latitude: latitude, longitude: longitude)
102
119
  end
103
120
  end
104
121
 
105
- describe "within a radious of a geolocation" do
106
- it "should look for documents based on latidude/longitude" do
107
- collection.stub(:send_request).and_return { server_response('simple-queries/within') }
108
- collection.should_receive(:send_request).with("simple/within" , :put => { "collection" => "example_1", "latitude" => 0, "longitude" => 0, "radius" => 2 })
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
- Ashikawa::Core::Cursor.should_receive(:new)
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 :latitude => 0, :longitude => 0, :radius => 2
142
+ subject.within(latitude: latitude, longitude: longitude, radius: radius)
113
143
  end
114
144
  end
115
145
 
116
- describe "in a certain range" do
117
- it "should look for documents with an attribute in that range" do
118
- arguments = { "collection" => "example_1", "attribute" => "age", "left" => 50, "right" => 60, "closed" => false}
119
- collection.stub(:send_request).and_return { server_response('simple-queries/range') }
120
- collection.should_receive(:send_request).with("simple/range" , :put => arguments)
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
- Ashikawa::Core::Cursor.should_receive(:new)
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 :attribute => "age", :left => 50, :right => 60, :closed => false
168
+ subject.in_range(attribute: attribute, left: left, right: right, closed: closed)
125
169
  end
126
170
  end
127
171
 
128
- describe "with an AQL query" do
129
- it "should be able to execute it" do
130
- collection.stub(:database).and_return double
131
- collection.stub(:send_request).and_return { server_response("cursor/query") }
132
- collection.should_receive(:send_request).with("cursor", :post => {
133
- "query" => "FOR u IN users LIMIT 2 RETURN u",
134
- "count" => true,
135
- "batchSize" => 2
136
- })
137
- Ashikawa::Core::Cursor.should_receive(:new).with(collection.database, server_response("cursor/query"))
138
-
139
- subject.execute "FOR u IN users LIMIT 2 RETURN u", :count => true, :batch_size => 2
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 "should return true when asked if a valid query is valid" do
143
- query = "FOR u IN users LIMIT 2 RETURN u"
144
-
145
- collection.stub(:send_request).and_return { server_response("query/valid") }
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).should be_true
202
+ expect(subject.valid?(query)).to be_true
151
203
  end
152
204
 
153
- it "should return false when asked if an invalid query is valid" do
154
- query = "FOR u IN users LIMIT 2"
155
-
156
- collection.stub(:send_request) do
157
- raise Ashikawa::Core::BadSyntax
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).should be_false
211
+ expect(subject.valid?(query)).to be_false
164
212
  end
165
213
  end
166
214
  end
167
215
 
168
- describe "initialized with database" do
169
- subject { Ashikawa::Core::Query.new database}
216
+ describe 'initialized with database' do
217
+ subject { Ashikawa::Core::Query.new(database) }
170
218
 
171
- it "should throw an exception when a simple query is executed" do
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 Ashikawa::Core::NoCollectionProvidedException
221
+ expect { subject.send method }.to raise_error(Ashikawa::Core::NoCollectionProvidedException)
174
222
  end
175
223
  end
176
224
 
177
- describe "with an AQL query" do
178
- it "should be able to execute it" do
179
- database.stub(:send_request).and_return { server_response("cursor/query") }
180
- database.should_receive(:send_request).with("cursor", :post => {
181
- "query" => "FOR u IN users LIMIT 2 RETURN u",
182
- "count" => true,
183
- "batchSize" => 2
184
- })
185
- Ashikawa::Core::Cursor.should_receive(:new).with(database, server_response("cursor/query"))
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 "should return true when asked if a valid query is valid" do
191
- query = "FOR u IN users LIMIT 2 RETURN u"
192
-
193
- database.stub(:send_request).and_return { server_response("query/valid") }
194
- database.should_receive(:send_request).with("query", :post => {
195
- "query" => query
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.valid?(query).should be_true
246
+ subject.execute(query, count: count, batch_size: batch_size)
199
247
  end
200
248
 
201
- it "should return false when asked if an invalid query is valid" do
202
- query = "FOR u IN users LIMIT 2"
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
- database.stub(:send_request) do
205
- raise Ashikawa::Core::BadSyntax
206
- end
207
- database.should_receive(:send_request).with("query", :post => {
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).should be_false
262
+ expect(subject.valid?(query)).to be_false
212
263
  end
213
264
  end
214
265
  end