ashikawa-core 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +11 -9
- data/.rspec +4 -0
- data/.travis.yml +8 -3
- data/CONTRIBUTING.md +5 -5
- data/Gemfile +5 -1
- data/Gemfile.devtools +65 -0
- data/Guardfile +1 -11
- data/README.md +14 -8
- data/Rakefile +5 -103
- data/ashikawa-core.gemspec +3 -29
- data/config/flay.yml +3 -0
- data/config/flog.yml +2 -0
- data/config/mutant.yml +3 -0
- data/config/roodi.yml +18 -0
- data/config/site.reek +95 -0
- data/config/yardstick.yml +2 -0
- data/lib/ashikawa-core/collection.rb +138 -178
- data/lib/ashikawa-core/connection.rb +74 -26
- data/lib/ashikawa-core/cursor.rb +30 -9
- data/lib/ashikawa-core/database.rb +23 -19
- data/lib/ashikawa-core/document.rb +33 -8
- data/lib/ashikawa-core/exceptions/collection_not_found.rb +15 -0
- data/lib/ashikawa-core/exceptions/document_not_found.rb +4 -0
- data/lib/ashikawa-core/exceptions/index_not_found.rb +15 -0
- data/lib/ashikawa-core/exceptions/no_collection_provided.rb +4 -0
- data/lib/ashikawa-core/exceptions/unknown_path.rb +15 -0
- data/lib/ashikawa-core/figure.rb +73 -0
- data/lib/ashikawa-core/index.rb +25 -7
- data/lib/ashikawa-core/query.rb +68 -55
- data/lib/ashikawa-core/status.rb +77 -0
- data/lib/ashikawa-core/version.rb +1 -1
- data/spec/acceptance/basic_spec.rb +14 -18
- data/spec/acceptance/index_spec.rb +4 -2
- data/spec/acceptance/query_spec.rb +18 -19
- data/spec/acceptance_auth/auth_spec.rb +2 -2
- data/spec/setup/arangodb.sh +34 -39
- data/spec/spec_helper.rb +27 -0
- data/spec/unit/collection_spec.rb +25 -73
- data/spec/unit/connection_spec.rb +46 -15
- data/spec/unit/cursor_spec.rb +3 -3
- data/spec/unit/database_spec.rb +8 -7
- data/spec/unit/document_spec.rb +2 -2
- data/spec/unit/exception_spec.rb +21 -0
- data/spec/unit/figure_spec.rb +28 -0
- data/spec/unit/index_spec.rb +1 -1
- data/spec/unit/query_spec.rb +25 -25
- data/spec/unit/spec_helper.rb +6 -4
- data/spec/unit/status_spec.rb +51 -0
- data/tasks/adjustments.rake +46 -0
- metadata +31 -203
@@ -0,0 +1,77 @@
|
|
1
|
+
module Ashikawa
|
2
|
+
module Core
|
3
|
+
# Wrapper around the status of a collection
|
4
|
+
class Status
|
5
|
+
STATUS_NEW_BORN = 1
|
6
|
+
STATUS_UNLOADED = 2
|
7
|
+
STATUS_LOADED = 3
|
8
|
+
STATUS_BEING_UNLOADED = 4
|
9
|
+
MAX_UNCORRUPTED = 5
|
10
|
+
|
11
|
+
# Create a wrapper around a given status
|
12
|
+
#
|
13
|
+
# @param [Fixnum] code
|
14
|
+
# @api public
|
15
|
+
# @example Create a new status
|
16
|
+
# status = Ashikawa::Core::Status.new(3)
|
17
|
+
def initialize(code)
|
18
|
+
@code = code
|
19
|
+
end
|
20
|
+
|
21
|
+
# Checks if the collection is new born
|
22
|
+
#
|
23
|
+
# @return [Boolean]
|
24
|
+
# @api public
|
25
|
+
# @example Is the collection new born?
|
26
|
+
# status = Ashikawa::Core::Status.new(3)
|
27
|
+
# status.new_born? #=> false
|
28
|
+
def new_born?
|
29
|
+
@code == STATUS_NEW_BORN
|
30
|
+
end
|
31
|
+
|
32
|
+
# Checks if the collection is unloaded
|
33
|
+
#
|
34
|
+
# @return [Boolean]
|
35
|
+
# @api public
|
36
|
+
# @example Is the collection unloaded?
|
37
|
+
# status = Ashikawa::Core::Status.new(3)
|
38
|
+
# status.unloaded? #=> false
|
39
|
+
def unloaded?
|
40
|
+
@code == STATUS_UNLOADED
|
41
|
+
end
|
42
|
+
|
43
|
+
# Checks if the collection is loaded
|
44
|
+
#
|
45
|
+
# @return [Boolean]
|
46
|
+
# @api public
|
47
|
+
# @example Is the collection loaded?
|
48
|
+
# status = Ashikawa::Core::Status.new(3)
|
49
|
+
# status.loaded? #=> true
|
50
|
+
def loaded?
|
51
|
+
@code == STATUS_LOADED
|
52
|
+
end
|
53
|
+
|
54
|
+
# Checks if the collection is in the process of being unloaded
|
55
|
+
#
|
56
|
+
# @return [Boolean]
|
57
|
+
# @api public
|
58
|
+
# @example Is the collection unloaded?
|
59
|
+
# status = Ashikawa::Core::Status.new(3)
|
60
|
+
# status.being_unloaded? #=> false
|
61
|
+
def being_unloaded?
|
62
|
+
@code == STATUS_BEING_UNLOADED
|
63
|
+
end
|
64
|
+
|
65
|
+
# Checks if the collection is corrupted
|
66
|
+
#
|
67
|
+
# @return [Boolean]
|
68
|
+
# @api public
|
69
|
+
# @example Is the collection corrupted?
|
70
|
+
# status = Ashikawa::Core::Status.new(3)
|
71
|
+
# status.corrupted? #=> false
|
72
|
+
def corrupted?
|
73
|
+
@code > MAX_UNCORRUPTED
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -3,10 +3,6 @@ require 'acceptance/spec_helper'
|
|
3
3
|
describe "Basics" do
|
4
4
|
subject { ARANGO_HOST }
|
5
5
|
|
6
|
-
# it "should have booted up an ArangoDB instance" do
|
7
|
-
# expect { RestClient.get(subject) }.to_not raise_error
|
8
|
-
# end
|
9
|
-
|
10
6
|
describe "initialized database" do
|
11
7
|
subject { Ashikawa::Core::Database.new ARANGO_HOST }
|
12
8
|
|
@@ -21,7 +17,7 @@ describe "Basics" do
|
|
21
17
|
end
|
22
18
|
|
23
19
|
it "should create and delete collections" do
|
24
|
-
subject.collections.should ==[]
|
20
|
+
subject.collections.should == []
|
25
21
|
subject["collection_1"]
|
26
22
|
subject["collection_2"]
|
27
23
|
subject["collection_3"]
|
@@ -44,20 +40,20 @@ describe "Basics" do
|
|
44
40
|
|
45
41
|
it "should be possible to load and unload collections" do
|
46
42
|
my_collection = subject["test_collection"]
|
47
|
-
my_collection.loaded?.should be_true
|
43
|
+
my_collection.status.loaded?.should be_true
|
48
44
|
my_collection.unload
|
49
45
|
my_id = my_collection.id
|
50
46
|
my_collection = subject[my_id]
|
51
|
-
subject[my_id].loaded?.should be_false
|
47
|
+
subject[my_id].status.loaded?.should be_false
|
52
48
|
end
|
53
49
|
|
54
50
|
it "should be possible to get figures" do
|
55
51
|
my_collection = subject["test_collection"]
|
56
|
-
my_collection.figure
|
57
|
-
my_collection.figure
|
58
|
-
my_collection.figure
|
59
|
-
my_collection.figure
|
60
|
-
my_collection.figure
|
52
|
+
my_collection.figure.datafiles_count.class.should == Fixnum
|
53
|
+
my_collection.figure.alive_size.class.should == Fixnum
|
54
|
+
my_collection.figure.alive_count.class.should == Fixnum
|
55
|
+
my_collection.figure.dead_size.class.should == Fixnum
|
56
|
+
my_collection.figure.dead_count.class.should == Fixnum
|
61
57
|
end
|
62
58
|
|
63
59
|
it "should change and receive information about waiting for sync" do
|
@@ -71,8 +67,8 @@ describe "Basics" do
|
|
71
67
|
it "should be possible to get information about the number of documents" do
|
72
68
|
empty_collection = subject["empty_collection"]
|
73
69
|
empty_collection.length.should == 0
|
74
|
-
empty_collection << { name
|
75
|
-
empty_collection << { name
|
70
|
+
empty_collection << { :name => "testname", :age => 27}
|
71
|
+
empty_collection << { :name => "anderer name", :age => 28}
|
76
72
|
empty_collection.length.should == 2
|
77
73
|
empty_collection.truncate!
|
78
74
|
empty_collection.length.should == 0
|
@@ -81,7 +77,7 @@ describe "Basics" do
|
|
81
77
|
it "should be possible to update the attributes of a document" do
|
82
78
|
collection = subject["documenttests"]
|
83
79
|
|
84
|
-
document = collection.create name
|
80
|
+
document = collection.create :name => "The Dude", :bowling => true
|
85
81
|
document_id = document.id
|
86
82
|
document["name"] = "Other Dude"
|
87
83
|
document.save
|
@@ -92,11 +88,11 @@ describe "Basics" do
|
|
92
88
|
it "should be possible to access and create documents from a collection" do
|
93
89
|
collection = subject["documenttests"]
|
94
90
|
|
95
|
-
document = collection.create name
|
91
|
+
document = collection.create :name => "The Dude", :bowling => true
|
96
92
|
document_id = document.id
|
97
93
|
collection[document_id]["name"].should == "The Dude"
|
98
94
|
|
99
|
-
collection[document_id] = { name
|
95
|
+
collection[document_id] = { :name => "Other Dude", :bowling => true }
|
100
96
|
collection[document_id]["name"].should == "Other Dude"
|
101
97
|
end
|
102
98
|
end
|
@@ -104,7 +100,7 @@ describe "Basics" do
|
|
104
100
|
describe "created document" do
|
105
101
|
let(:database) { Ashikawa::Core::Database.new ARANGO_HOST }
|
106
102
|
let(:collection) { database["documenttests"] }
|
107
|
-
subject { collection.create name
|
103
|
+
subject { collection.create :name => "The Dude" }
|
108
104
|
let(:document_id) { subject.id }
|
109
105
|
|
110
106
|
it "should be possible to manipulate documents and save them" do
|
@@ -3,13 +3,13 @@ require 'acceptance/spec_helper'
|
|
3
3
|
describe "Indices" do
|
4
4
|
let(:database) { Ashikawa::Core::Database.new ARANGO_HOST }
|
5
5
|
subject { database["documenttest"] }
|
6
|
-
let(:index) { subject.add_index :skiplist, on
|
6
|
+
let(:index) { subject.add_index :skiplist, :on => [:identifier] }
|
7
7
|
|
8
8
|
it "should be possible to set indices" do
|
9
9
|
index.delete
|
10
10
|
|
11
11
|
expect {
|
12
|
-
subject.add_index :skiplist, on
|
12
|
+
subject.add_index :skiplist, :on => [:identifier]
|
13
13
|
}.to change { subject.indices.length }.by(1)
|
14
14
|
end
|
15
15
|
|
@@ -19,6 +19,8 @@ describe "Indices" do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should be possible to remove indices" do
|
22
|
+
pending "Delete doesn't work at random"
|
23
|
+
|
22
24
|
expect {
|
23
25
|
index.delete
|
24
26
|
}.to change { subject.indices.length }.by(-1)
|
@@ -6,18 +6,17 @@ describe "Queries" do
|
|
6
6
|
|
7
7
|
describe "AQL query via the database" do
|
8
8
|
it "should return the documents" do
|
9
|
+
query = "FOR u IN my_collection FILTER u.bowling == true RETURN u"
|
10
|
+
options = { :batch_size => 2, :count => true }
|
11
|
+
|
9
12
|
collection << { "name" => "Jeff Lebowski", "bowling" => true }
|
10
13
|
collection << { "name" => "Walter Sobchak", "bowling" => true }
|
11
14
|
collection << { "name" => "Donny Kerabatsos", "bowling" => true }
|
12
15
|
collection << { "name" => "Jeffrey Lebowski", "bowling" => false }
|
13
16
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
results.length.should == 3
|
18
|
-
results = results.map { |person| person["name"] }
|
19
|
-
results.should include "Jeff Lebowski"
|
20
|
-
results.should_not include "Jeffrey Lebowski"
|
17
|
+
names = database.query.execute(query, options).map { |person| person["name"] }
|
18
|
+
names.should include "Jeff Lebowski"
|
19
|
+
names.should_not include "Jeffrey Lebowski"
|
21
20
|
end
|
22
21
|
|
23
22
|
it "should be possible to validate" do
|
@@ -34,39 +33,39 @@ describe "Queries" do
|
|
34
33
|
before(:each) { subject.truncate! }
|
35
34
|
|
36
35
|
it "should return all documents of a collection" do
|
37
|
-
subject << { name
|
36
|
+
subject << { :name => "testname", :age => 27}
|
38
37
|
subject.query.all.first["name"].should == "testname"
|
39
38
|
end
|
40
39
|
|
41
40
|
it "should be possible to limit and skip results" do
|
42
|
-
subject << { name
|
43
|
-
subject << { name
|
44
|
-
subject << { name
|
41
|
+
subject << { :name => "test1"}
|
42
|
+
subject << { :name => "test2"}
|
43
|
+
subject << { :name => "test3"}
|
45
44
|
|
46
|
-
subject.query.all(limit
|
47
|
-
subject.query.all(skip
|
45
|
+
subject.query.all(:limit => 2).length.should == 2
|
46
|
+
subject.query.all(:skip => 2).length.should == 1
|
48
47
|
end
|
49
48
|
|
50
49
|
it "should be possible to query documents by example" do
|
51
50
|
subject << { "name" => "Random Document" }
|
52
|
-
result = subject.query.by_example name
|
51
|
+
result = subject.query.by_example :name => "Random Document"
|
53
52
|
result.length.should == 1
|
54
53
|
end
|
55
54
|
|
56
55
|
describe "query by geo coordinates" do
|
57
56
|
before :each do
|
58
|
-
subject.add_index :geo, on
|
57
|
+
subject.add_index :geo, :on => [:latitude, :longitude]
|
59
58
|
subject << { "name" => "cologne", "latitude" => 50.948045, "longitude" => 6.961212 }
|
60
59
|
subject << { "name" => "san francisco", "latitude" => -122.395899, "longitude" => 37.793621 }
|
61
60
|
end
|
62
61
|
|
63
62
|
it "should be possible to query documents near a certain location" do
|
64
|
-
found_places = subject.query.near latitude
|
63
|
+
found_places = subject.query.near :latitude => 50, :longitude => 6
|
65
64
|
found_places.first["name"].should == "cologne"
|
66
65
|
end
|
67
66
|
|
68
67
|
it "should be possible to query documents within a certain range" do
|
69
|
-
found_places = subject.query.within latitude
|
68
|
+
found_places = subject.query.within :latitude => 50.948040, :longitude => 6.961210, :radius => 2
|
70
69
|
found_places.length.should == 1
|
71
70
|
found_places.first["name"].should == "cologne"
|
72
71
|
end
|
@@ -74,14 +73,14 @@ describe "Queries" do
|
|
74
73
|
|
75
74
|
describe "queries by integer ranges" do
|
76
75
|
before :each do
|
77
|
-
subject.add_index :skiplist, on
|
76
|
+
subject.add_index :skiplist, :on => [:age]
|
78
77
|
subject << { "name" => "Georg", "age" => 12 }
|
79
78
|
subject << { "name" => "Anne", "age" => 21 }
|
80
79
|
subject << { "name" => "Jens", "age" => 49 }
|
81
80
|
end
|
82
81
|
|
83
82
|
it "should be possible to query documents for numbers in a certain range" do
|
84
|
-
found_people = subject.query.in_range attribute
|
83
|
+
found_people = subject.query.in_range :attribute => "age", :left => 20, :right => 30, :closed => true
|
85
84
|
found_people.length.should == 1
|
86
85
|
found_people.first["name"].should == "Anne"
|
87
86
|
end
|
@@ -20,7 +20,7 @@ describe "authenticated database" do
|
|
20
20
|
|
21
21
|
context "with user and password" do
|
22
22
|
it "should allow acces to DB" do
|
23
|
-
subject.authenticate_with username
|
23
|
+
subject.authenticate_with :username => 'testuser', :password => 'testpassword'
|
24
24
|
|
25
25
|
expect do
|
26
26
|
subject["new_collection"]
|
@@ -29,7 +29,7 @@ describe "authenticated database" do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should deny acces if username and password are wrong" do
|
32
|
-
subject.authenticate_with username
|
32
|
+
subject.authenticate_with :username => 'ruffy', :password => 'three_headed_monkey'
|
33
33
|
|
34
34
|
expect do
|
35
35
|
subject["denied"]
|
data/spec/setup/arangodb.sh
CHANGED
@@ -3,60 +3,55 @@
|
|
3
3
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
4
4
|
cd $DIR
|
5
5
|
|
6
|
-
|
7
|
-
VERSION=1.1.beta1
|
8
|
-
|
6
|
+
VERSION=1.1.2
|
9
7
|
NAME=ArangoDB-$VERSION
|
10
8
|
|
11
9
|
if [ ! -d "$DIR/$NAME" ]; then
|
12
10
|
# download ArangoDB
|
11
|
+
echo "wget http://www.arangodb.org/travisCI/$NAME.tar.gz"
|
13
12
|
wget http://www.arangodb.org/travisCI/$NAME.tar.gz
|
13
|
+
echo "tar zxf $NAME.tar.gz"
|
14
14
|
tar zxf $NAME.tar.gz
|
15
15
|
fi
|
16
16
|
|
17
|
-
|
17
|
+
ARCH=$(arch)
|
18
18
|
PID=$(echo $PPID)
|
19
19
|
TMP_DIR="/tmp/arangodb.$PID"
|
20
20
|
PID_FILE="/tmp/arangodb.$PID.pid"
|
21
21
|
ARANGODB_DIR="$DIR/$NAME"
|
22
|
-
UPDATE_SCRIPT="${ARANGODB_DIR}/js/server/arango-upgrade.js"
|
23
22
|
|
24
|
-
|
25
|
-
|
23
|
+
ARANGOD="${ARANGODB_DIR}/bin/arangod"
|
24
|
+
if [ "$ARCH" == "x86_64" ]; then
|
25
|
+
ARANGOD="${ARANGOD}_x86_64"
|
26
|
+
fi
|
26
27
|
|
27
|
-
#
|
28
|
-
|
29
|
-
|
30
|
-
# version 1.1
|
31
|
-
${ARANGODB_DIR}/bin/arangod \
|
32
|
-
--database.directory ${TMP_DIR} \
|
33
|
-
--configuration none \
|
34
|
-
--server.endpoint tcp://127.0.0.1:8529 \
|
35
|
-
--javascript.startup-directory ${ARANGODB_DIR}/js \
|
36
|
-
--javascript.modules-path ${ARANGODB_DIR}/js/server/modules:${ARANGODB_DIR}/js/common/modules \
|
37
|
-
--javascript.script "$UPDATE_SCRIPT"
|
28
|
+
# (re-)create database directory
|
29
|
+
rm -rf ${TMP_DIR}
|
30
|
+
mkdir ${TMP_DIR}
|
38
31
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
32
|
+
echo "Starting arangodb '${ARANGOD}'"
|
33
|
+
|
34
|
+
${ARANGOD} \
|
35
|
+
--database.directory ${TMP_DIR} \
|
36
|
+
--configuration none \
|
37
|
+
--server.endpoint tcp://127.0.0.1:8529 \
|
38
|
+
--javascript.startup-directory ${ARANGODB_DIR}/js \
|
39
|
+
--javascript.modules-path ${ARANGODB_DIR}/js/server/modules:${ARANGODB_DIR}/js/common/modules \
|
40
|
+
--javascript.action-directory ${ARANGODB_DIR}/js/actions/system \
|
41
|
+
--database.maximal-journal-size 1048576 \
|
42
|
+
--server.disable-admin-interface true \
|
43
|
+
--server.disable-authentication true \
|
44
|
+
--javascript.gc-interval 1 &
|
45
|
+
|
46
|
+
sleep 2
|
47
|
+
|
48
|
+
echo "Check for arangod process"
|
49
|
+
process=$(ps auxww | grep "bin/arangod" | grep -v grep)
|
50
|
+
|
51
|
+
if [ "x$process" == "x" ]; then
|
52
|
+
echo "no 'arangod' process found"
|
53
|
+
echo "ARCH = $ARCH"
|
54
|
+
exit 1
|
60
55
|
fi
|
61
56
|
|
62
57
|
echo "Waiting until ArangoDB is ready on port 8529"
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
if ENV['COVERAGE'] == 'true'
|
4
|
+
require 'simplecov'
|
5
|
+
|
6
|
+
SimpleCov.start do
|
7
|
+
command_name 'spec:unit'
|
8
|
+
add_filter 'config'
|
9
|
+
add_filter 'spec'
|
10
|
+
minimum_coverage 100
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
require 'ashikawa-core'
|
15
|
+
require 'rspec'
|
16
|
+
|
17
|
+
if RUBY_VERSION < '1.9'
|
18
|
+
require 'rspec/autorun'
|
19
|
+
end
|
20
|
+
|
21
|
+
# require spec support files and shared behavior
|
22
|
+
Dir[File.expand_path('../{support,shared}/**/*.rb', __FILE__)].each do |file|
|
23
|
+
require file
|
24
|
+
end
|
25
|
+
|
26
|
+
RSpec.configure do |config|
|
27
|
+
end
|
@@ -28,45 +28,6 @@ describe Ashikawa::Core::Collection do
|
|
28
28
|
collection.query
|
29
29
|
end
|
30
30
|
|
31
|
-
describe "the status code" do
|
32
|
-
it "should know if the collection is new born" do
|
33
|
-
my_collection = subject.new @database, { "status" => "1" }
|
34
|
-
my_collection.new_born?.should == true
|
35
|
-
|
36
|
-
my_collection = subject.new @database, { "status" => "200" }
|
37
|
-
my_collection.new_born?.should == false
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should know if the collection is unloaded" do
|
41
|
-
my_collection = subject.new @database, { "status" => "2" }
|
42
|
-
my_collection.unloaded?.should == true
|
43
|
-
|
44
|
-
my_collection = subject.new @database, { "status" => "200" }
|
45
|
-
my_collection.unloaded?.should == false
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should know if the collection is loaded" do
|
49
|
-
my_collection = subject.new @database, { "status" => "3" }
|
50
|
-
my_collection.loaded?.should == true
|
51
|
-
|
52
|
-
my_collection = subject.new @database, { "status" => "200" }
|
53
|
-
my_collection.loaded?.should == false
|
54
|
-
end
|
55
|
-
|
56
|
-
it "should know if the collection is being unloaded" do
|
57
|
-
my_collection = subject.new @database, { "status" => "4" }
|
58
|
-
my_collection.being_unloaded?.should == true
|
59
|
-
|
60
|
-
my_collection = subject.new @database, { "status" => "200" }
|
61
|
-
my_collection.being_unloaded?.should == false
|
62
|
-
end
|
63
|
-
|
64
|
-
it "should know if the collection is corrupted" do
|
65
|
-
my_collection = subject.new @database, { "status" => "6" }
|
66
|
-
my_collection.corrupted?.should == true
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
31
|
describe "attributes of a collection" do
|
71
32
|
it "should check if the collection waits for sync" do
|
72
33
|
@database.stub(:send_request).with("/collection/4590/properties", {}).and_return { server_response("/collections/4590") }
|
@@ -88,12 +49,12 @@ describe Ashikawa::Core::Collection do
|
|
88
49
|
@database.stub(:send_request).with("/collection/73482/figures", {}).and_return { server_response("/collections/73482-figures") }
|
89
50
|
@database.should_receive(:send_request).with("/collection/73482/figures", {}).at_least(1).times
|
90
51
|
|
52
|
+
mock Ashikawa::Core::Figure
|
53
|
+
Ashikawa::Core::Figure.stub(:new)
|
54
|
+
Ashikawa::Core::Figure.should_receive(:new).exactly(1).times.with(server_response("/collections/73482-figures")["figures"])
|
55
|
+
|
91
56
|
my_collection = subject.new @database, { "id" => "73482" }
|
92
|
-
my_collection.figure
|
93
|
-
my_collection.figure(:alive_size).should == 0
|
94
|
-
my_collection.figure(:alive_count).should == 0
|
95
|
-
my_collection.figure(:dead_size).should == 2384
|
96
|
-
my_collection.figure(:dead_count).should == 149
|
57
|
+
my_collection.figure
|
97
58
|
end
|
98
59
|
end
|
99
60
|
|
@@ -101,43 +62,43 @@ describe Ashikawa::Core::Collection do
|
|
101
62
|
subject { Ashikawa::Core::Collection.new @database, { "id" => "4590", "name" => "example_1" } }
|
102
63
|
|
103
64
|
it "should get deleted" do
|
104
|
-
@database.stub(:send_request).with("/collection/4590", delete
|
105
|
-
@database.should_receive(:send_request).with("/collection/4590", delete
|
65
|
+
@database.stub(:send_request).with("/collection/4590", :delete => {})
|
66
|
+
@database.should_receive(:send_request).with("/collection/4590", :delete => {})
|
106
67
|
|
107
68
|
subject.delete
|
108
69
|
end
|
109
70
|
|
110
71
|
it "should get loaded" do
|
111
|
-
@database.stub(:send_request).with("/collection/4590/load", put
|
112
|
-
@database.should_receive(:send_request).with("/collection/4590/load", put
|
72
|
+
@database.stub(:send_request).with("/collection/4590/load", :put => {})
|
73
|
+
@database.should_receive(:send_request).with("/collection/4590/load", :put => {})
|
113
74
|
|
114
75
|
subject.load
|
115
76
|
end
|
116
77
|
|
117
78
|
it "should get unloaded" do
|
118
|
-
@database.stub(:send_request).with("/collection/4590/unload", put
|
119
|
-
@database.should_receive(:send_request).with("/collection/4590/unload", put
|
79
|
+
@database.stub(:send_request).with("/collection/4590/unload", :put => {})
|
80
|
+
@database.should_receive(:send_request).with("/collection/4590/unload", :put => {})
|
120
81
|
|
121
82
|
subject.unload
|
122
83
|
end
|
123
84
|
|
124
85
|
it "should get truncated" do
|
125
|
-
@database.stub(:send_request).with("/collection/4590/truncate", put
|
126
|
-
@database.should_receive(:send_request).with("/collection/4590/truncate", put
|
86
|
+
@database.stub(:send_request).with("/collection/4590/truncate", :put => {})
|
87
|
+
@database.should_receive(:send_request).with("/collection/4590/truncate", :put => {})
|
127
88
|
|
128
89
|
subject.truncate!
|
129
90
|
end
|
130
91
|
|
131
92
|
it "should change if it waits for sync" do
|
132
|
-
@database.stub(:send_request).with("/collection/4590/properties", put
|
133
|
-
@database.should_receive(:send_request).with("/collection/4590/properties", put
|
93
|
+
@database.stub(:send_request).with("/collection/4590/properties", :put => {"waitForSync" => true})
|
94
|
+
@database.should_receive(:send_request).with("/collection/4590/properties", :put => {"waitForSync" => true})
|
134
95
|
|
135
96
|
subject.wait_for_sync = true
|
136
97
|
end
|
137
98
|
|
138
99
|
it "should change its name" do
|
139
|
-
@database.stub(:send_request).with("/collection/4590/rename", put
|
140
|
-
@database.should_receive(:send_request).with("/collection/4590/rename", put
|
100
|
+
@database.stub(:send_request).with("/collection/4590/rename", :put => {"name" => "my_new_name"})
|
101
|
+
@database.should_receive(:send_request).with("/collection/4590/rename", :put => {"name" => "my_new_name"})
|
141
102
|
|
142
103
|
subject.name = "my_new_name"
|
143
104
|
end
|
@@ -154,17 +115,17 @@ describe Ashikawa::Core::Collection do
|
|
154
115
|
end
|
155
116
|
|
156
117
|
it "should replace a document by ID" do
|
157
|
-
@database.stub(:send_request).with("/document/4590/333", put
|
158
|
-
@database.should_receive(:send_request).with("/document/4590/333", put
|
118
|
+
@database.stub(:send_request).with("/document/4590/333", :put => {"name" => "The Dude"})
|
119
|
+
@database.should_receive(:send_request).with("/document/4590/333", :put => {"name" => "The Dude"})
|
159
120
|
|
160
121
|
subject[333] = {"name" => "The Dude"}
|
161
122
|
end
|
162
123
|
|
163
124
|
it "should create a new document" do
|
164
|
-
@database.stub(:send_request).with("/document?collection=4590", post
|
125
|
+
@database.stub(:send_request).with("/document?collection=4590", :post => { "name" => "The Dude" }).and_return do
|
165
126
|
server_response('documents/new-4590-333')
|
166
127
|
end
|
167
|
-
@database.stub(:send_request).with("/document/4590/333", post
|
128
|
+
@database.stub(:send_request).with("/document/4590/333", :post => { "name" => "The Dude" }).and_return { server_response('documents/4590-333') }
|
168
129
|
|
169
130
|
# Documents need to get initialized:
|
170
131
|
Ashikawa::Core::Document.should_receive(:new)
|
@@ -173,7 +134,7 @@ describe Ashikawa::Core::Collection do
|
|
173
134
|
end
|
174
135
|
|
175
136
|
it "should create a new document with `<<`" do
|
176
|
-
@database.stub(:send_request).with("/document?collection=4590", post
|
137
|
+
@database.stub(:send_request).with("/document?collection=4590", :post => { "name" => "The Dude" }).and_return do
|
177
138
|
server_response('documents/new-4590-333')
|
178
139
|
end
|
179
140
|
@database.stub(:send_request).with("/document/4590/333").and_return { server_response('documents/4590-333') }
|
@@ -184,28 +145,19 @@ describe Ashikawa::Core::Collection do
|
|
184
145
|
subject << {"name" => "The Dude"}
|
185
146
|
end
|
186
147
|
|
187
|
-
it "should raise an exception if a document is not found" do
|
188
|
-
@database.stub(:send_request).with("/document/4590/333") do
|
189
|
-
raise RestClient::ResourceNotFound
|
190
|
-
end
|
191
|
-
@database.should_receive(:send_request).with("/document/4590/333")
|
192
|
-
|
193
|
-
expect { subject[333] }.to raise_error(Ashikawa::Core::DocumentNotFoundException)
|
194
|
-
end
|
195
|
-
|
196
148
|
describe "indices" do
|
197
149
|
it "should add a new index" do
|
198
|
-
@database.stub(:send_request).with("/index?collection=4590", post
|
150
|
+
@database.stub(:send_request).with("/index?collection=4590", :post => {
|
199
151
|
"type" => "hash", "fields" => [ "a", "b" ]
|
200
152
|
}).and_return { server_response('indices/new-hash-index') }
|
201
|
-
@database.should_receive(:send_request).with("/index?collection=4590", post
|
153
|
+
@database.should_receive(:send_request).with("/index?collection=4590", :post => {
|
202
154
|
"type" => "hash", "fields" => [ "a", "b" ]
|
203
155
|
})
|
204
156
|
|
205
157
|
Ashikawa::Core::Index.should_receive(:new).with(subject,
|
206
158
|
server_response('indices/new-hash-index'))
|
207
159
|
|
208
|
-
subject.add_index :hash, on
|
160
|
+
subject.add_index :hash, :on => [ :a, :b ]
|
209
161
|
end
|
210
162
|
|
211
163
|
it "should get an index by ID" do
|