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,32 +1,35 @@
1
+ # -*- encoding : utf-8 -*-
1
2
  require 'acceptance/spec_helper'
2
3
 
3
- describe "Indices" do
4
- let(:database) {
5
- Ashikawa::Core::Database.new do |config|
6
- config.url = ARANGO_HOST
7
- end
8
- }
9
- subject { database["documenttest"] }
10
- let(:index) { subject.add_index(:skiplist, :on => [:identifier]) }
4
+ describe 'Indices' do
5
+ let(:database) { DATABASE }
6
+ subject { database['documenttest'] }
7
+ let(:index) { subject.add_index(:skiplist, on: [:identifier]) }
11
8
 
12
- it "should be possible to set indices" do
9
+ it 'should be possible to set indices' do
13
10
  index.delete
14
11
 
15
12
  expect {
16
- subject.add_index :skiplist, :on => [:identifier]
13
+ subject.add_index :skiplist, on: [:identifier]
17
14
  }.to change { subject.indices.length }.by(1)
18
15
  end
19
16
 
20
- it "should be possible to get an index by ID" do
17
+ it 'should be possible to get an index by ID' do
21
18
  # This is temporary until Index has a key
22
19
  index_key = index.id.split('/')[1]
23
20
 
24
- subject.index(index_key).id.should == index.id
25
- subject.indices[0].class.should == Ashikawa::Core::Index
21
+ expect(subject.index(index_key).id).to eq(index.id)
22
+ expect(subject.indices[0].class).to eq(Ashikawa::Core::Index)
26
23
  end
27
24
 
28
- it "should be possible to remove indices" do
29
- pending "See Bug #34"
25
+ it 'should be possible to create an unique index' do
26
+ index = subject.add_index :skiplist, on: [:identifier], unique: true
27
+
28
+ expect(index.unique).to be_true
29
+ end
30
+
31
+ it 'should be possible to remove indices' do
32
+ pending 'See Bug #34'
30
33
 
31
34
  expect {
32
35
  index.delete
@@ -1,98 +1,95 @@
1
+ # -*- encoding : utf-8 -*-
1
2
  require 'acceptance/spec_helper'
2
3
 
3
- describe "Queries" do
4
- let(:database) {
5
- Ashikawa::Core::Database.new do |config|
6
- config.url = ARANGO_HOST
7
- end
8
- }
9
- let(:collection) { database["my_collection"] }
10
-
11
- describe "AQL query via the database" do
12
- it "should return the documents" do
13
- query = "FOR u IN my_collection FILTER u.bowling == true RETURN u"
14
- options = { :batch_size => 2, :count => true }
15
-
16
- collection.create_document({ "name" => "Jeff Lebowski", "bowling" => true })
17
- collection.create_document({ "name" => "Walter Sobchak", "bowling" => true })
18
- collection.create_document({ "name" => "Donny Kerabatsos", "bowling" => true })
19
- collection.create_document({ "name" => "Jeffrey Lebowski", "bowling" => false })
20
-
21
- names = database.query.execute(query, options).map { |person| person["name"] }
22
- names.should include "Jeff Lebowski"
23
- names.should_not include "Jeffrey Lebowski"
4
+ describe 'Queries' do
5
+ let(:database) { DATABASE }
6
+ let(:collection) { database['my_collection'] }
7
+
8
+ describe 'AQL query via the database' do
9
+ it 'should return the documents' do
10
+ query = 'FOR u IN my_collection FILTER u.bowling == true RETURN u'
11
+ options = { batch_size: 2, count: true }
12
+
13
+ collection.create_document({ 'name' => 'Jeff Lebowski', 'bowling' => true })
14
+ collection.create_document({ 'name' => 'Walter Sobchak', 'bowling' => true })
15
+ collection.create_document({ 'name' => 'Donny Kerabatsos', 'bowling' => true })
16
+ collection.create_document({ 'name' => 'Jeffrey Lebowski', 'bowling' => false })
17
+
18
+ names = database.query.execute(query, options).map { |person| person['name'] }
19
+ expect(names).to include 'Jeff Lebowski'
20
+ expect(names).not_to include 'Jeffrey Lebowski'
24
21
  end
25
22
 
26
- it "should be possible to validate" do
27
- valid_query = "FOR u IN my_collection FILTER u.bowling == true RETURN u"
28
- database.query.valid?(valid_query).should be_true
23
+ it 'should be possible to validate' do
24
+ valid_query = 'FOR u IN my_collection FILTER u.bowling == true RETURN u'
25
+ expect(database.query.valid?(valid_query)).to be_true
29
26
 
30
- invalid_query = "FOR u IN my_collection FILTER u.bowling == true"
31
- database.query.valid?(invalid_query).should be_false
27
+ invalid_query = 'FOR u IN my_collection FILTER u.bowling == true'
28
+ expect(database.query.valid?(invalid_query)).to be_false
32
29
  end
33
30
  end
34
31
 
35
- describe "simple query via collection object" do
32
+ describe 'simple query via collection object' do
36
33
  subject { collection }
37
34
  before(:each) { subject.truncate! }
38
35
 
39
- it "should return all documents of a collection" do
40
- subject.create_document({ :name => "testname", :age => 27})
41
- subject.query.all.first["name"].should == "testname"
36
+ it 'should return all documents of a collection' do
37
+ subject.create_document({ name: 'testname', age: 27 })
38
+ expect(subject.query.all.first['name']).to eq('testname')
42
39
  end
43
40
 
44
- it "should be possible to limit and skip results" do
45
- subject.create_document({ :name => "test1"})
46
- subject.create_document({ :name => "test2"})
47
- subject.create_document({ :name => "test3"})
41
+ it 'should be possible to limit and skip results' do
42
+ subject.create_document({ name: 'test1' })
43
+ subject.create_document({ name: 'test2' })
44
+ subject.create_document({ name: 'test3' })
48
45
 
49
- subject.query.all(:limit => 2).length.should == 2
50
- subject.query.all(:skip => 2).length.should == 1
46
+ expect(subject.query.all(limit: 2).length).to eq(2)
47
+ expect(subject.query.all(skip: 2).length).to eq(1)
51
48
  end
52
49
 
53
- it "should be possible to query documents by example" do
54
- subject.create_document({ "name" => "Random Document" })
55
- result = subject.query.by_example :name => "Random Document"
56
- result.length.should == 1
50
+ it 'should be possible to query documents by example' do
51
+ subject.create_document({ 'name' => 'Random Document' })
52
+ result = subject.query.by_example name: 'Random Document'
53
+ expect(result.length).to eq(1)
57
54
  end
58
55
 
59
- it "should be possible to query first document by example" do
60
- subject.create_document({ "name" => "Single Document" })
61
- result = subject.query.first_example :name => "Single Document"
62
- result["name"].should == "Single Document"
56
+ it 'should be possible to query first document by example' do
57
+ subject.create_document({ 'name' => 'Single Document' })
58
+ result = subject.query.first_example name: 'Single Document'
59
+ expect(result['name']).to eq('Single Document')
63
60
  end
64
61
 
65
- describe "query by geo coordinates" do
62
+ describe 'query by geo coordinates' do
66
63
  before :each do
67
- subject.add_index :geo, :on => [:latitude, :longitude]
68
- subject.create_document({ "name" => "cologne", "latitude" => 50.948045, "longitude" => 6.961212 })
69
- subject.create_document({ "name" => "san francisco", "latitude" => -122.395899, "longitude" => 37.793621 })
64
+ subject.add_index :geo, on: [:latitude, :longitude]
65
+ subject.create_document({ 'name' => 'cologne', 'latitude' => 50.948045, 'longitude' => 6.961212 })
66
+ subject.create_document({ 'name' => 'san francisco', 'latitude' => -122.395899, 'longitude' => 37.793621 })
70
67
  end
71
68
 
72
- it "should be possible to query documents near a certain location" do
73
- found_places = subject.query.near :latitude => 50, :longitude => 6
74
- found_places.first["name"].should == "cologne"
69
+ it 'should be possible to query documents near a certain location' do
70
+ found_places = subject.query.near latitude: 50, longitude: 6
71
+ expect(found_places.first['name']).to eq('cologne')
75
72
  end
76
73
 
77
- it "should be possible to query documents within a certain range" do
78
- found_places = subject.query.within :latitude => 50.948040, :longitude => 6.961210, :radius => 2
79
- found_places.length.should == 1
80
- found_places.first["name"].should == "cologne"
74
+ it 'should be possible to query documents within a certain range' do
75
+ found_places = subject.query.within latitude: 50.948040, longitude: 6.961210, radius: 2
76
+ expect(found_places.length).to eq(1)
77
+ expect(found_places.first['name']).to eq('cologne')
81
78
  end
82
79
  end
83
80
 
84
- describe "queries by integer ranges" do
81
+ describe 'queries by integer ranges' do
85
82
  before :each do
86
- subject.add_index :skiplist, :on => [:age]
87
- subject.create_document({ "name" => "Georg", "age" => 12 })
88
- subject.create_document({ "name" => "Anne", "age" => 21 })
89
- subject.create_document({ "name" => "Jens", "age" => 49 })
83
+ subject.add_index :skiplist, on: [:age]
84
+ subject.create_document({ 'name' => 'Georg', 'age' => 12 })
85
+ subject.create_document({ 'name' => 'Anne', 'age' => 21 })
86
+ subject.create_document({ 'name' => 'Jens', 'age' => 49 })
90
87
  end
91
88
 
92
- it "should be possible to query documents for numbers in a certain range" do
93
- found_people = subject.query.in_range :attribute => "age", :left => 20, :right => 30, :closed => true
94
- found_people.length.should == 1
95
- found_people.first["name"].should == "Anne"
89
+ it 'should be possible to query documents for numbers in a certain range' do
90
+ found_people = subject.query.in_range attribute: 'age', left: 20, right: 30, closed: true
91
+ expect(found_people.length).to eq(1)
92
+ expect(found_people.first['name']).to eq('Anne')
96
93
  end
97
94
  end
98
95
  end
@@ -1,6 +1,29 @@
1
+ # -*- encoding : utf-8 -*-
1
2
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
4
 
4
- require "ashikawa-core"
5
+ RSpec.configure do |config|
6
+ config.expect_with :rspec do |c|
7
+ c.syntax = :expect
8
+ end
5
9
 
6
- ARANGO_HOST = "http://localhost:8529"
10
+ config.mock_with :rspec do |c|
11
+ c.syntax = :expect
12
+ end
13
+ end
14
+
15
+ require 'ashikawa-core'
16
+
17
+ port = ENV['ARANGODB_PORT'] || 8529
18
+ username = ENV['ARANGODB_USERNAME'] || 'root'
19
+ password = ENV['ARANGODB_PASSWORD'] || ''
20
+
21
+ # The database instance to use for all specs
22
+ DATABASE = Ashikawa::Core::Database.new do |config|
23
+ config.url = "http://localhost:#{port}"
24
+
25
+ unless ENV['ARANGODB_DISABLE_AUTHENTIFICATION']
26
+ config.username = username
27
+ config.password = password
28
+ end
29
+ end
@@ -1,30 +1,26 @@
1
+ # -*- encoding : utf-8 -*-
1
2
  require 'acceptance/spec_helper'
2
3
 
3
- describe "Transactions" do
4
- subject {
5
- Ashikawa::Core::Database.new do |config|
6
- config.url = ARANGO_HOST
7
- end
8
- }
4
+ describe 'Transactions' do
5
+ subject { DATABASE }
9
6
 
10
7
  before :each do
11
8
  subject.collections.each { |collection| collection.delete }
12
- subject["collection_1"]
13
- subject["collection_2"]
14
- subject["collection_3"]
9
+ subject['collection_1']
10
+ subject['collection_2']
11
+ subject['collection_3']
15
12
  end
16
13
 
17
- let(:js_function) { "function (x) { return x.a; }" }
14
+ let(:js_function) { 'function (x) { return x.a; }' }
15
+ let(:write_collections) { %w{collection_1 collection_2} }
16
+ let(:read_collections) { %w{collection_2} }
18
17
 
19
- it "should create and execute a transaction" do
20
- transaction = subject.create_transaction(js_function,
21
- :write => ["collection_1", "collection_2"],
22
- :read => ["collection_3"]
23
- )
18
+ it 'should create and execute a transaction' do
19
+ transaction = subject.create_transaction js_function, write: write_collections, read: read_collections
24
20
 
25
21
  transaction.wait_for_sync = true
26
22
  transaction.lock_timeout = 14
27
23
 
28
- transaction.execute({ :a => 5 }).should == 5
24
+ expect(transaction.execute({ a: 5 })).to eq(5)
29
25
  end
30
26
  end
@@ -3,7 +3,7 @@
3
3
  DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
4
4
  cd $DIR
5
5
 
6
- VERSION=1.3.0
6
+ # VERSION=1.4.devel
7
7
  NAME=ArangoDB-$VERSION
8
8
 
9
9
  if [ ! -d "$DIR/$NAME" ]; then
@@ -40,7 +40,7 @@ ${ARANGOD} \
40
40
  --javascript.package-path ${ARANGODB_DIR}/js/npm:${ARANGODB_DIR}/js/common/test-data/modules \
41
41
  --javascript.action-directory ${ARANGODB_DIR}/js/actions \
42
42
  --database.maximal-journal-size 1048576 \
43
- --server.disable-admin-interface true \
43
+ --server.disable-admin-interface ${ARANGODB_DISABLE_AUTHENTIFICATION} \
44
44
  --server.disable-authentication true \
45
45
  --javascript.gc-interval 1 &
46
46
 
@@ -1,338 +1,320 @@
1
+ # -*- encoding : utf-8 -*-
1
2
  require 'unit/spec_helper'
2
3
  require 'ashikawa-core/collection'
3
4
 
4
5
  describe Ashikawa::Core::Collection do
5
- subject { Ashikawa::Core::Collection }
6
-
7
- before :each do
8
- @database = double
6
+ let(:database) { double }
7
+ let(:raw_document_collection) { server_response('collections/60768679') }
8
+ let(:raw_edge_collection) do
9
+ {
10
+ 'id' => '60768679',
11
+ 'name' => 'example_1',
12
+ 'type' => 3
13
+ }
9
14
  end
10
15
 
11
- it "should have a name" do
12
- my_collection = subject.new @database, server_response("collections/60768679")
13
- my_collection.name.should == "example_1"
14
- end
16
+ describe 'an initialized collection' do
17
+ subject { Ashikawa::Core::Collection.new(database, raw_document_collection) }
15
18
 
16
- it "should accept an ID" do
17
- my_collection = subject.new @database, server_response("collections/60768679")
18
- my_collection.id.should == "60768679"
19
- end
19
+ let(:raw_key_options) { double }
20
+ let(:key_options) { double }
21
+ let(:response) { double }
22
+ let(:value) { double }
23
+ let(:figure) { double }
20
24
 
21
- it "should create a query" do
22
- collection = subject.new @database, server_response("collections/60768679")
25
+ its(:name) { should eq('example_1') }
26
+ its(:id) { should eq('60768679') }
23
27
 
24
- double Ashikawa::Core::Query
25
- Ashikawa::Core::Query.stub(:new)
26
- Ashikawa::Core::Query.should_receive(:new).exactly(1).times.with(collection)
28
+ it 'should know how many documents the collection has' do
29
+ allow(response).to receive(:[])
30
+ .with('count')
31
+ .and_return(value)
32
+ expect(database).to receive(:send_request)
33
+ .with('collection/60768679/count', {})
34
+ .and_return(response)
27
35
 
28
- collection.query
29
- end
30
-
31
- describe "attributes of a collection" do
32
- it "should check if the collection waits for sync" do
33
- @database.stub(:send_request).with("collection/60768679/properties", {}).and_return { server_response("collections/60768679-properties") }
34
- @database.should_receive(:send_request).with("collection/60768679/properties", {})
35
-
36
- my_collection = subject.new @database, { "id" => "60768679" }
37
- my_collection.wait_for_sync?.should be_true
36
+ expect(subject.length).to be(value)
38
37
  end
39
38
 
40
- it "should know how many documents the collection has" do
41
- @database.stub(:send_request).with("collection/60768679/count", {}).and_return { server_response("collections/60768679-count") }
42
- @database.should_receive(:send_request).with("collection/60768679/count", {})
39
+ it 'should check for the figures' do
40
+ allow(response).to receive(:[])
41
+ .with('figures')
42
+ .and_return(value)
43
+ expect(database).to receive(:send_request)
44
+ .with('collection/60768679/figures', {})
45
+ .and_return(response)
43
46
 
44
- my_collection = subject.new @database, { "id" => "60768679" }
45
- my_collection.length.should == 54
46
- end
47
+ expect(Ashikawa::Core::Figure).to receive(:new)
48
+ .exactly(1).times
49
+ .with(value)
50
+ .and_return(figure)
47
51
 
48
- it "should know if the collection is volatile" do
49
- @database.stub(:send_request).with("collection/60768679/properties", {}).and_return { server_response("collections/60768679-properties-volatile") }
50
- @database.should_receive(:send_request).with("collection/60768679/properties", {})
51
-
52
- my_collection = subject.new(@database, { "id" => "60768679" })
53
- my_collection.volatile?.should == true
54
- end
55
-
56
- it "should know if the collection is not volatile" do
57
- @database.stub(:send_request).with("collection/60768679/properties", {}).and_return { server_response("collections/60768679-properties") }
58
- @database.should_receive(:send_request).with("collection/60768679/properties", {})
59
-
60
- my_collection = subject.new(@database, { "id" => "60768679" })
61
- my_collection.volatile?.should == false
52
+ expect(subject.figure).to be(figure)
62
53
  end
63
54
 
64
- it "should know that a collection is from type 'document'" do
65
- my_collection = subject.new(@database, { "id" => "60768679", "type" => 2 })
66
- my_collection.content_type.should == :document
67
- end
55
+ it 'should create a query' do
56
+ expect(Ashikawa::Core::Query).to receive(:new)
57
+ .exactly(1).times
58
+ .with(subject)
68
59
 
69
- it "should know that a collection is from type 'edge'" do
70
- my_collection = subject.new(@database, { "id" => "60768679", "type" => 3 })
71
- my_collection.content_type.should == :edge
60
+ subject.query
72
61
  end
73
62
 
74
- it "should check for the figures" do
75
- @database.stub(:send_request).with("collection/60768679/figures", {}).and_return { server_response("collections/60768679-figures") }
76
- @database.should_receive(:send_request).with("collection/60768679/figures", {}).at_least(1).times
77
-
78
- double Ashikawa::Core::Figure
79
- Ashikawa::Core::Figure.stub(:new)
80
- Ashikawa::Core::Figure.should_receive(:new).exactly(1).times.with(server_response("collections/60768679-figures")["figures"])
81
-
82
- my_collection = subject.new @database, { "id" => "60768679" }
83
- my_collection.figure
84
- end
85
- end
86
-
87
- describe "an initialized collection" do
88
- subject { Ashikawa::Core::Collection.new @database, { "id" => "60768679", "name" => "example_1" } }
89
-
90
- it "should get deleted" do
91
- @database.stub(:send_request).with("collection/60768679/", :delete => {})
92
- @database.should_receive(:send_request).with("collection/60768679/", :delete => {})
63
+ it 'should get deleted' do
64
+ expect(database).to receive(:send_request)
65
+ .with('collection/60768679/', delete: {})
93
66
 
94
67
  subject.delete
95
68
  end
96
69
 
97
- it "should get loaded" do
98
- @database.stub(:send_request).with("collection/60768679/load", :put => {})
99
- @database.should_receive(:send_request).with("collection/60768679/load", :put => {})
70
+ it 'should get loaded' do
71
+ expect(database).to receive(:send_request)
72
+ .with('collection/60768679/load', put: {})
100
73
 
101
74
  subject.load
102
75
  end
103
76
 
104
- it "should get unloaded" do
105
- @database.stub(:send_request).with("collection/60768679/unload", :put => {})
106
- @database.should_receive(:send_request).with("collection/60768679/unload", :put => {})
77
+ it 'should get unloaded' do
78
+ expect(database).to receive(:send_request)
79
+ .with('collection/60768679/unload', put: {})
107
80
 
108
81
  subject.unload
109
82
  end
110
83
 
111
- it "should get truncated" do
112
- @database.stub(:send_request).with("collection/60768679/truncate", :put => {})
113
- @database.should_receive(:send_request).with("collection/60768679/truncate", :put => {})
84
+ it 'should get truncated' do
85
+ expect(database).to receive(:send_request)
86
+ .with('collection/60768679/truncate', put: {})
114
87
 
115
88
  subject.truncate!
116
89
  end
117
90
 
118
- it "should change if it waits for sync" do
119
- @database.stub(:send_request).with("collection/60768679/properties", :put => {"waitForSync" => true})
120
- @database.should_receive(:send_request).with("collection/60768679/properties", :put => {"waitForSync" => true})
91
+ it 'should change its name' do
92
+ expect(database).to receive(:send_request)
93
+ .with('collection/60768679/rename', put: { 'name' => value })
121
94
 
122
- subject.wait_for_sync = true
95
+ subject.name = value
123
96
  end
124
97
 
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 }
98
+ it 'should change if it waits for sync' do
99
+ expect(database).to receive(:send_request)
100
+ .with('collection/60768679/properties', put: { 'waitForSync' => value })
131
101
 
132
- subject.key_options.should == key_options
102
+ subject.wait_for_sync = value
133
103
  end
134
104
 
135
- it "should change its name" do
136
- @database.stub(:send_request).with("collection/60768679/rename", :put => {"name" => "my_new_name"})
137
- @database.should_receive(:send_request).with("collection/60768679/rename", :put => {"name" => "my_new_name"})
105
+ describe 'properties' do
106
+ before do
107
+ expect(database).to receive(:send_request)
108
+ .with('collection/60768679/properties', {})
109
+ .and_return(response)
110
+ end
138
111
 
139
- subject.name = "my_new_name"
140
- end
112
+ it 'should check if the collection waits for sync' do
113
+ allow(response).to receive(:[])
114
+ .with('waitForSync')
115
+ .and_return(value)
141
116
 
142
- describe "add and get single documents" 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", {})
117
+ expect(subject.wait_for_sync?).to be(value)
118
+ end
146
119
 
147
- # Documents need to get initialized:
148
- Ashikawa::Core::Document.should_receive(:new)
120
+ it 'should know if the collection is volatile' do
121
+ allow(response).to receive(:[])
122
+ .with('isVolatile')
123
+ .and_return(value)
149
124
 
150
- subject.fetch(333)
125
+ expect(subject.volatile?).to be(value)
151
126
  end
152
127
 
153
- it "should receive a document by ID via []" do
154
- @database.stub(:send_request).with("document/60768679/333", {}).and_return { server_response('documents/example_1-137249191') }
155
- @database.should_receive(:send_request).with("document/60768679/333", {})
128
+ it 'should check for the key options' do
129
+ allow(response).to receive(:[])
130
+ .with('keyOptions')
131
+ .and_return(value)
132
+ expect(Ashikawa::Core::KeyOptions).to receive(:new)
133
+ .with(value)
134
+ .and_return(key_options)
156
135
 
157
- # Documents need to get initialized:
158
- Ashikawa::Core::Document.should_receive(:new)
159
-
160
- subject[333]
136
+ expect(subject.key_options).to eq(key_options)
161
137
  end
138
+ end
162
139
 
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
- }
140
+ describe 'non-existing documents' do
141
+ before do
142
+ allow(database).to receive(:send_request)
143
+ .and_raise(Ashikawa::Core::DocumentNotFoundException)
144
+ end
167
145
 
168
- expect {
146
+ it 'should throw an exception when using fetch' do
147
+ expect do
169
148
  subject.fetch(123)
170
- }.to raise_exception Ashikawa::Core::DocumentNotFoundException
149
+ end.to raise_exception Ashikawa::Core::DocumentNotFoundException
171
150
  end
172
151
 
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
- }
152
+ it 'should return nil when using []' do
153
+ expect(subject[123]).to be_nil
154
+ end
155
+ end
177
156
 
178
- subject[123].should == nil
157
+ describe 'indexes' do
158
+ let(:index_response) { double }
159
+
160
+ it 'should add a new index' do
161
+ expect(database).to receive(:send_request)
162
+ .with('index?collection=60768679', post: {
163
+ 'type' => 'hash', 'fields' => %w{a b}, 'unique' => false
164
+ })
165
+ .and_return(index_response)
166
+ expect(Ashikawa::Core::Index).to receive(:new)
167
+ .with(subject, index_response)
168
+
169
+ subject.add_index(:hash, on: [:a, :b])
179
170
  end
180
171
 
181
- it "should replace a document by ID" do
182
- @database.stub(:send_request).with("document/60768679/333", :put => {"name" => "The Dude"})
183
- @database.should_receive(:send_request).with("document/60768679/333", :put => {"name" => "The Dude"})
172
+ it 'should add a new unique index' do
173
+ expect(database).to receive(:send_request)
174
+ .with('index?collection=60768679', post: {
175
+ 'type' => 'hash', 'fields' => %w{a b}, 'unique' => true
176
+ })
177
+ .and_return(index_response)
178
+ expect(Ashikawa::Core::Index).to receive(:new)
179
+ .with(subject, index_response)
184
180
 
185
- subject.replace(333, {"name" => "The Dude"})
181
+ subject.add_index(:hash, on: [:a, :b], unique: true)
186
182
  end
187
183
 
188
- it "should create a new document" do
189
- @database.stub(:send_request).with("document?collection=60768679", :post => { "name" => "The Dude" }).and_return do
190
- server_response('documents/new-example_1-137249191')
191
- end
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') }
202
-
203
- # Documents need to get initialized:
204
- Ashikawa::Core::Document.should_receive(:new).and_return {
205
- document = double
206
- document.should_receive(:refresh!)
207
- document
208
- }
209
-
210
- subject.create_document({"name" => "The Dude"})
184
+ it 'should get an index by ID' do
185
+ allow(database).to receive(:send_request)
186
+ .with('index/example_1/168054969')
187
+ .and_return(index_response)
188
+ expect(Ashikawa::Core::Index).to receive(:new)
189
+ .with(subject, index_response)
190
+
191
+ subject.index(168_054_969)
211
192
  end
212
193
 
213
- it "should create a new document" do
214
- @database.stub(:send_request).with("document?collection=60768679", :post => { "name" => "The Dude" }).and_return do
215
- server_response('documents/example_1-137249191')
216
- end
217
- @database.stub(:send_request).with("document/60768679/333").and_return { server_response('documents/example_1-137249191') }
194
+ it 'should get all indexes' do
195
+ multi_index_response = double
196
+ allow(multi_index_response).to receive(:map)
197
+ .and_yield(index_response)
218
198
 
219
- # Documents need to get initialized:
220
- Ashikawa::Core::Document.should_receive(:new).and_return {
221
- document = double
222
- document.should_receive(:refresh!)
223
- document
224
- }
199
+ cursor = double
200
+ allow(cursor).to receive(:[])
201
+ .with('indexes')
202
+ .and_return(multi_index_response)
225
203
 
226
- subject.create_document("name" => "The Dude")
227
- end
204
+ allow(database).to receive(:send_request)
205
+ .with('index?collection=60768679')
206
+ .and_return(cursor)
207
+
208
+ expect(Ashikawa::Core::Index).to receive(:new)
209
+ .with(subject, index_response)
228
210
 
229
- it "should not create a new document" do
230
- expect {
231
- subject.create_edge(nil, nil, {"quote" => "D'ya have to use s'many cuss words?"})
232
- }.to raise_exception(RuntimeError, "Can't create an edge in a document collection")
211
+ subject.indices
233
212
  end
213
+ end
214
+ end
234
215
 
235
- describe "indices" do
236
- it "should add a new index" do
237
- @database.stub(:send_request).with("index?collection=60768679", :post => {
238
- "type" => "hash", "fields" => [ "a", "b" ]
239
- }).and_return { server_response('indices/new-hash-index') }
240
- @database.should_receive(:send_request).with("index?collection=60768679", :post => {
241
- "type" => "hash", "fields" => [ "a", "b" ]
242
- })
216
+ describe 'an initialized document collection' do
217
+ subject { Ashikawa::Core::Collection.new database, raw_document_collection }
243
218
 
244
- Ashikawa::Core::Index.should_receive(:new).with(subject,
245
- server_response('indices/new-hash-index'))
219
+ let(:document) { double }
220
+ let(:response) { double }
221
+ let(:raw_document) { double }
222
+ let(:value) { double }
246
223
 
247
- subject.add_index :hash, :on => [ :a, :b ]
248
- end
224
+ its(:content_type) { should be(:document) }
249
225
 
250
- it "should get an index by ID" do
251
- @database.stub(:send_request).with(
252
- "index/example_1/168054969"
253
- ).and_return { server_response('indices/hash-index') }
226
+ it 'should receive a document by ID via fetch' do
227
+ expect(database).to receive(:send_request)
228
+ .with('document/60768679/333', {})
229
+ .and_return(double)
230
+ expect(Ashikawa::Core::Document).to receive(:new)
254
231
 
255
- Ashikawa::Core::Index.should_receive(:new).with(subject,
256
- server_response('indices/hash-index'))
232
+ subject.fetch(333)
233
+ end
257
234
 
258
- subject.index 168054969
259
- end
235
+ it 'should receive a document by ID via []' do
236
+ expect(database).to receive(:send_request)
237
+ .with('document/60768679/333', {})
238
+ .and_return(double)
239
+ expect(Ashikawa::Core::Document).to receive(:new)
260
240
 
261
- it "should get all indices" do
262
- @database.stub(:send_request).with(
263
- "index?collection=60768679"
264
- ).and_return { server_response('indices/all') }
241
+ subject[333]
242
+ end
265
243
 
266
- Ashikawa::Core::Index.should_receive(:new).exactly(1).times
244
+ it 'should replace a document by ID' do
245
+ expect(database).to receive(:send_request)
246
+ .with('document/60768679/333', put: { 'name' => value })
267
247
 
268
- indices = subject.indices
269
- indices.length.should == 1
270
- end
271
- end
248
+ subject.replace(333, { 'name' => value })
249
+ end
250
+
251
+ it 'should create a new document' do
252
+ allow(database).to receive(:send_request)
253
+ .with('document?collection=60768679', post: raw_document)
254
+ .and_return(response)
255
+ expect(Ashikawa::Core::Document).to receive(:new)
256
+ .with(database, response, raw_document)
257
+ .and_return(document)
258
+
259
+ subject.create_document(raw_document)
260
+ end
261
+
262
+ it 'should not create a new edge' do
263
+ expect do
264
+ subject.create_edge(double, double, { 'quote' => "D'ya have to use s'many cuss words?" })
265
+ end.to raise_exception(RuntimeError, "Can't create an edge in a document collection")
272
266
  end
273
267
  end
274
268
 
275
- describe "an initialized edge collection" do
276
- subject { Ashikawa::Core::Collection.new @database, { "id" => "60768679", "name" => "example_1", "type" => 3 } }
269
+ describe 'an initialized edge collection' do
270
+ subject { Ashikawa::Core::Collection.new database, raw_edge_collection }
271
+
272
+ let(:document) { double }
273
+ let(:response) { double }
274
+ let(:raw_document) { double }
277
275
 
278
- it "should receive an edge by ID" do
279
- @database.stub(:send_request).with("edge/60768679/333", {}).and_return { server_response('documents/example_1-137249191') }
280
- @database.should_receive(:send_request).with("edge/60768679/333", {})
276
+ its(:content_type) { should be(:edge) }
281
277
 
282
- # Documents need to get initialized:
283
- Ashikawa::Core::Edge.should_receive(:new)
278
+ it 'should receive an edge by ID via fetch' do
279
+ expect(database).to receive(:send_request)
280
+ .with('edge/60768679/333', {})
281
+ .and_return(double)
282
+ expect(Ashikawa::Core::Edge).to receive(:new)
284
283
 
285
284
  subject.fetch(333)
286
285
  end
287
286
 
288
- it "should replace an edge by ID" do
289
- @database.stub(:send_request).with("edge/60768679/333", :put => {"name" => "The Dude"})
290
- @database.should_receive(:send_request).with("edge/60768679/333", :put => {"name" => "The Dude"})
287
+ it 'should receive an edge by ID via []' do
288
+ expect(database).to receive(:send_request)
289
+ .with('edge/60768679/333', {})
290
+ .and_return(double)
291
+ expect(Ashikawa::Core::Edge).to receive(:new)
291
292
 
292
- subject.replace(333, {"name" => "The Dude"})
293
+ subject[333]
293
294
  end
294
295
 
295
- it "should create a new edge" do
296
- @database.stub(:send_request).with("edge?collection=60768679&from=1&to=2", :post => { "name" => "The Dude" }).and_return do
297
- server_response('documents/new-example_1-137249191')
298
- end
299
- @database.stub(:send_request).with("edge?collection=60768679&from=1&to=2", :post => { "name" => "The Dude" }).and_return { server_response('documents/example_1-137249191') }
300
- from_double = double
301
- from_double.stub(:id => "1")
302
- to_double = double
303
- to_double.stub(:id => "2")
304
-
305
- # Documents need to get initialized:
306
- Ashikawa::Core::Edge.should_receive(:new).and_return {
307
- document = double
308
- document.should_receive(:refresh!)
309
- document
310
- }
311
-
312
- subject.create_edge(from_double, to_double, {"name" => "The Dude"})
313
- end
296
+ it 'should replace an edge by ID' do
297
+ expect(database).to receive(:send_request)
298
+ .with('edge/60768679/333', put: { 'name' => 'The Dude' })
314
299
 
315
- it "should not create a new document" do
316
- expect {
317
- subject.create_document({"quote" => "D'ya have to use s'many cuss words?"})
318
- }.to raise_exception(RuntimeError, "Can't create a document in an edge collection")
300
+ subject.replace(333, { 'name' => 'The Dude' })
319
301
  end
320
- end
321
302
 
322
- describe "Deprecated methods" do
323
- subject { Ashikawa::Core::Collection.new @database, { "id" => "60768679", "name" => "example_1" } }
324
- let(:attributes) { { "test" => 123 } }
303
+ it 'should create a new edge' do
304
+ allow(database).to receive(:send_request)
305
+ .with('edge?collection=60768679&from=1&to=2', post: raw_document)
306
+ .and_return(response)
307
+ expect(Ashikawa::Core::Edge).to receive(:new)
308
+ .with(database, response, raw_document)
309
+ .and_return(document)
325
310
 
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
311
+ subject.create_edge(double(id: '1'), double(id: '2'), raw_document)
330
312
  end
331
313
 
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
314
+ it 'should not create a new document' do
315
+ expect do
316
+ subject.create_document({ 'quote' => "D'ya have to use s'many cuss words?" })
317
+ end.to raise_exception(RuntimeError, "Can't create a document in an edge collection")
336
318
  end
337
319
  end
338
320
  end