axiom-arango-adapter 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/.rspec +5 -0
- data/.travis.yml +25 -0
- data/Gemfile +9 -0
- data/Gemfile.devtools +57 -0
- data/Guardfile +18 -0
- data/LICENSE +20 -0
- data/README.md +92 -0
- data/Rakefile +2 -0
- data/TODO +1 -0
- data/axiom-arango-adapter.gemspec +26 -0
- 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 +102 -0
- data/config/yardstick.yml +2 -0
- data/lib/axiom-arango-adapter.rb +2 -0
- data/lib/axiom/adapter/arango.rb +40 -0
- data/lib/axiom/adapter/arango/adapter.rb +68 -0
- data/lib/axiom/adapter/arango/gateway.rb +356 -0
- data/lib/axiom/adapter/arango/reader.rb +98 -0
- data/lib/axiom/adapter/arango/visitor.rb +100 -0
- data/lib/axiom/adapter/arango/visitor/aggregate.rb +132 -0
- data/lib/axiom/adapter/arango/visitor/attribute.rb +26 -0
- data/lib/axiom/adapter/arango/visitor/binary.rb +77 -0
- data/lib/axiom/adapter/arango/visitor/for.rb +75 -0
- data/lib/axiom/adapter/arango/visitor/for/base.rb +40 -0
- data/lib/axiom/adapter/arango/visitor/for/binary.rb +108 -0
- data/lib/axiom/adapter/arango/visitor/for/binary/join.rb +131 -0
- data/lib/axiom/adapter/arango/visitor/for/binary/product.rb +48 -0
- data/lib/axiom/adapter/arango/visitor/for/summarization.rb +113 -0
- data/lib/axiom/adapter/arango/visitor/for/unary.rb +29 -0
- data/lib/axiom/adapter/arango/visitor/for/unary/extension.rb +72 -0
- data/lib/axiom/adapter/arango/visitor/for/unary/limit.rb +31 -0
- data/lib/axiom/adapter/arango/visitor/for/unary/offset.rb +34 -0
- data/lib/axiom/adapter/arango/visitor/for/unary/order.rb +63 -0
- data/lib/axiom/adapter/arango/visitor/for/unary/projection.rb +32 -0
- data/lib/axiom/adapter/arango/visitor/for/unary/rename.rb +88 -0
- data/lib/axiom/adapter/arango/visitor/for/unary/restriction.rb +42 -0
- data/lib/axiom/adapter/arango/visitor/function.rb +33 -0
- data/lib/axiom/adapter/arango/visitor/header.rb +55 -0
- data/lib/axiom/adapter/arango/visitor/literal.rb +26 -0
- data/lib/axiom/adapter/arango/visitor/reverse.rb +27 -0
- data/spec/fuzzer.rb +53 -0
- data/spec/integration/arango/read_spec.rb +166 -0
- data/spec/setup/arangodb.sh +61 -0
- data/spec/setup/run.sh +23 -0
- data/spec/shared/aql_behavior.rb +7 -0
- data/spec/shared/binary_relation_method_behaviour.rb +53 -0
- data/spec/shared/unary_relation_method_behaviour.rb +21 -0
- data/spec/spec_helper.rb +51 -0
- data/spec/support/ice_nine_config.rb +6 -0
- data/spec/unit/axiom/adapter/arango/adapter/class_methods/new_spec.rb +24 -0
- data/spec/unit/axiom/adapter/arango/adapter/gateway_spec.rb +11 -0
- data/spec/unit/axiom/adapter/arango/adapter/reader_spec.rb +12 -0
- data/spec/unit/axiom/adapter/arango/gateway/class_methods/new_spec.rb +15 -0
- data/spec/unit/axiom/adapter/arango/gateway/difference_spec.rb +16 -0
- data/spec/unit/axiom/adapter/arango/gateway/drop_spec.rb +20 -0
- data/spec/unit/axiom/adapter/arango/gateway/each_spec.rb +78 -0
- data/spec/unit/axiom/adapter/arango/gateway/extend_spec.rb +26 -0
- data/spec/unit/axiom/adapter/arango/gateway/intersect_spec.rb +16 -0
- data/spec/unit/axiom/adapter/arango/gateway/join_spec.rb +43 -0
- data/spec/unit/axiom/adapter/arango/gateway/materialize_spec.rb +26 -0
- data/spec/unit/axiom/adapter/arango/gateway/optimize_spec.rb +22 -0
- data/spec/unit/axiom/adapter/arango/gateway/product_spec.rb +16 -0
- data/spec/unit/axiom/adapter/arango/gateway/project_spec.rb +20 -0
- data/spec/unit/axiom/adapter/arango/gateway/remove_spec.rb +20 -0
- data/spec/unit/axiom/adapter/arango/gateway/rename_spec.rb +20 -0
- data/spec/unit/axiom/adapter/arango/gateway/respond_to_predicate_spec.rb +28 -0
- data/spec/unit/axiom/adapter/arango/gateway/restrict_spec.rb +26 -0
- data/spec/unit/axiom/adapter/arango/gateway/reverse_spec.rb +20 -0
- data/spec/unit/axiom/adapter/arango/gateway/sort_by_spec.rb +26 -0
- data/spec/unit/axiom/adapter/arango/gateway/summarize_spec.rb +150 -0
- data/spec/unit/axiom/adapter/arango/gateway/take_spec.rb +20 -0
- data/spec/unit/axiom/adapter/arango/gateway/unhandled_message_spec.rb +17 -0
- data/spec/unit/axiom/adapter/arango/gateway/union_spec.rb +16 -0
- data/spec/unit/axiom/adapter/arango/reader/each_spec.rb +43 -0
- data/spec/unit/axiom/adapter/arango/visitor/aggregate/count/root_spec.rb +15 -0
- data/spec/unit/axiom/adapter/arango/visitor/aggregate/count_spec.rb +15 -0
- data/spec/unit/axiom/adapter/arango/visitor/aggregate/maximum/root_spec.rb +15 -0
- data/spec/unit/axiom/adapter/arango/visitor/aggregate/maximum_spec.rb +15 -0
- data/spec/unit/axiom/adapter/arango/visitor/aggregate/minimum/root_spec.rb +15 -0
- data/spec/unit/axiom/adapter/arango/visitor/aggregate/minimum_spec.rb +15 -0
- data/spec/unit/axiom/adapter/arango/visitor/aggregate/sum/root_spec.rb +15 -0
- data/spec/unit/axiom/adapter/arango/visitor/aggregate/sum_spec.rb +15 -0
- data/spec/unit/axiom/adapter/arango/visitor/attribute/root_spec.rb +12 -0
- data/spec/unit/axiom/adapter/arango/visitor/binary/root_spec.rb +15 -0
- data/spec/unit/axiom/adapter/arango/visitor/class_methods/build_spec.rb +37 -0
- data/spec/unit/axiom/adapter/arango/visitor/class_methods/run_spec.rb +26 -0
- data/spec/unit/axiom/adapter/arango/visitor/for/base/root_spec.rb +13 -0
- data/spec/unit/axiom/adapter/arango/visitor/for/binary/join/local_name_spec.rb +20 -0
- data/spec/unit/axiom/adapter/arango/visitor/for/binary/join/right/root_spec.rb +14 -0
- data/spec/unit/axiom/adapter/arango/visitor/for/binary/join/root_spec.rb +14 -0
- data/spec/unit/axiom/adapter/arango/visitor/for/binary/join_spec.rb +14 -0
- data/spec/unit/axiom/adapter/arango/visitor/for/binary/local_name_spec.rb +14 -0
- data/spec/unit/axiom/adapter/arango/visitor/for/binary/product/right/root_spec.rb +13 -0
- data/spec/unit/axiom/adapter/arango/visitor/for/binary/product/root_spec.rb +13 -0
- data/spec/unit/axiom/adapter/arango/visitor/for/binary/product_spec.rb +13 -0
- data/spec/unit/axiom/adapter/arango/visitor/for/binary/right/join_spec.rb +14 -0
- data/spec/unit/axiom/adapter/arango/visitor/for/binary/right/local_name_spec.rb +13 -0
- data/spec/unit/axiom/adapter/arango/visitor/for/binary/right/product_spec.rb +13 -0
- data/spec/unit/axiom/adapter/arango/visitor/for/local_name_spec.rb +21 -0
- data/spec/unit/axiom/adapter/arango/visitor/for/root_spec.rb +29 -0
- data/spec/unit/axiom/adapter/arango/visitor/for/summarization/root_spec.rb +53 -0
- data/spec/unit/axiom/adapter/arango/visitor/for/unary/extension/root_spec.rb +13 -0
- data/spec/unit/axiom/adapter/arango/visitor/for/unary/extension_spec.rb +13 -0
- data/spec/unit/axiom/adapter/arango/visitor/for/unary/limit/root_spec.rb +17 -0
- data/spec/unit/axiom/adapter/arango/visitor/for/unary/limit_spec.rb +17 -0
- data/spec/unit/axiom/adapter/arango/visitor/for/unary/offset/root_spec.rb +17 -0
- data/spec/unit/axiom/adapter/arango/visitor/for/unary/offset_spec.rb +17 -0
- data/spec/unit/axiom/adapter/arango/visitor/for/unary/order/root_spec.rb +14 -0
- data/spec/unit/axiom/adapter/arango/visitor/for/unary/order_spec.rb +14 -0
- data/spec/unit/axiom/adapter/arango/visitor/for/unary/projection/root_spec.rb +13 -0
- data/spec/unit/axiom/adapter/arango/visitor/for/unary/projection_spec.rb +13 -0
- data/spec/unit/axiom/adapter/arango/visitor/for/unary/rename/root_spec.rb +13 -0
- data/spec/unit/axiom/adapter/arango/visitor/for/unary/rename_spec.rb +13 -0
- data/spec/unit/axiom/adapter/arango/visitor/for/unary/restriction/root_spec.rb +14 -0
- data/spec/unit/axiom/adapter/arango/visitor/for/unary/restriction_spec.rb +14 -0
- data/spec/unit/axiom/adapter/arango/visitor/header/root_spec.rb +12 -0
- data/spec/unit/axiom/adapter/arango/visitor/literal/root_spec.rb +10 -0
- data/spec/unit/axiom/adapter/arango/visitor/static/root_spec.rb +19 -0
- data/spec/unit/axiom/adapter/arango/visitor/visit_spec.rb +52 -0
- data/spec/unit/axiom/adapter/arango/visitor/visitor_spec.rb +39 -0
- metadata +379 -0
@@ -0,0 +1,150 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Axiom::Adapter::Arango::Gateway, '#summarize' do
|
6
|
+
let(:summarization) { mock('Summarization', :kind_of? => true) }
|
7
|
+
let(:adapter) { mock('Adapter') }
|
8
|
+
let(:relation) { mock('Relation', :summarize => summarization) }
|
9
|
+
let!(:object) { described_class.new(adapter, relation) }
|
10
|
+
let(:block) { lambda { |context| } }
|
11
|
+
|
12
|
+
context 'with no arguments' do
|
13
|
+
subject { object.summarize(&block) }
|
14
|
+
|
15
|
+
let(:gateway) { mock('New Gateway') }
|
16
|
+
|
17
|
+
before do
|
18
|
+
described_class.stub!(:new).and_return(gateway)
|
19
|
+
end
|
20
|
+
|
21
|
+
it { should equal(gateway) }
|
22
|
+
|
23
|
+
it 'forwards the default summarize_with relation to relation#summarize' do
|
24
|
+
relation.should_receive(:summarize) do |other|
|
25
|
+
other.should equal(Axiom::TABLE_DEE)
|
26
|
+
end
|
27
|
+
subject
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'forwards the block to relation#summarize' do
|
31
|
+
relation.stub!(:summarize) do |_summarize_with, &proc|
|
32
|
+
proc.should equal(block)
|
33
|
+
end
|
34
|
+
subject
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'initializes the gateway with the adapter and summarization' do
|
38
|
+
described_class.should_receive(:new).with(adapter, summarization)
|
39
|
+
subject
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'with a header' do
|
44
|
+
subject { object.summarize(header, &block) }
|
45
|
+
|
46
|
+
let(:gateway) { mock('New Gateway') }
|
47
|
+
let(:header) { mock('Header') }
|
48
|
+
|
49
|
+
before do
|
50
|
+
described_class.stub!(:new).and_return(gateway)
|
51
|
+
end
|
52
|
+
|
53
|
+
it { should equal(gateway) }
|
54
|
+
|
55
|
+
it 'forwards the header to relation#summarize' do
|
56
|
+
relation.should_receive(:summarize) do |other|
|
57
|
+
other.should equal(header)
|
58
|
+
end
|
59
|
+
subject
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'forwards the block to relation#summarize' do
|
63
|
+
relation.stub!(:summarize) do |_summarize_with, &proc|
|
64
|
+
proc.should equal(block)
|
65
|
+
end
|
66
|
+
subject
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'initializes the gateway with the adapter and summarization' do
|
70
|
+
described_class.should_receive(:new).with(adapter, summarization)
|
71
|
+
subject
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'when summarize_with has the same adapter' do
|
76
|
+
subject { object.summarize(other, &block) }
|
77
|
+
|
78
|
+
let(:header) { mock('Header') }
|
79
|
+
let(:other_relation) { mock('Other Relation', :header => header) }
|
80
|
+
let!(:other) { described_class.new(adapter, other_relation) }
|
81
|
+
let(:gateway) { mock('New Gateway') }
|
82
|
+
|
83
|
+
before do
|
84
|
+
described_class.stub!(:new).and_return(gateway)
|
85
|
+
end
|
86
|
+
|
87
|
+
it { should equal(gateway) }
|
88
|
+
|
89
|
+
it 'forwards the other relation to relation#summarize' do
|
90
|
+
relation.should_receive(:summarize) do |other|
|
91
|
+
other.should equal(other_relation)
|
92
|
+
end
|
93
|
+
subject
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'forwards the block to relation#summarize' do
|
97
|
+
relation.stub!(:summarize) do |_summarize_with, &proc|
|
98
|
+
proc.should equal(block)
|
99
|
+
end
|
100
|
+
subject
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'initializes the gateway with the adapter and summarization' do
|
104
|
+
described_class.should_receive(:new).with(adapter, summarization)
|
105
|
+
subject
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
context 'with a relation' do
|
110
|
+
subject { object.summarize(summarize_with, &block) }
|
111
|
+
|
112
|
+
let(:context_header) { mock('Context Header') }
|
113
|
+
let(:header) { mock('Header', :- => context_header) }
|
114
|
+
let(:summarize_header) { mock('Summarize With Header') }
|
115
|
+
let(:summarize_with) { mock('Other Relation', :header => summarize_header) }
|
116
|
+
let(:functions) { mock('Functions') }
|
117
|
+
let(:context) { mock('Context', :functions => functions) }
|
118
|
+
|
119
|
+
before do
|
120
|
+
relation.stub!(:header).and_return(header)
|
121
|
+
Axiom::Algebra::Summarization.stub!(:new).and_return(summarization)
|
122
|
+
Axiom::Evaluator::Context.stub!(:new).with(context_header, &block).and_return(context)
|
123
|
+
end
|
124
|
+
|
125
|
+
it { should equal(summarization) }
|
126
|
+
|
127
|
+
it 'gets the context header' do
|
128
|
+
header.should_receive(:-).with(summarize_header)
|
129
|
+
subject
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'passes the context header into the context' do
|
133
|
+
Axiom::Evaluator::Context.should_receive(:new).with(context_header)
|
134
|
+
subject
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'forwards the block to the context' do
|
138
|
+
Axiom::Evaluator::Context.should_receive(:new) do |_header, &proc|
|
139
|
+
proc.should equal(block)
|
140
|
+
context
|
141
|
+
end
|
142
|
+
subject
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'initializes the summarization with the gateway, the relation and the functions' do
|
146
|
+
Axiom::Algebra::Summarization.should_receive(:new).with(object, summarize_with, functions)
|
147
|
+
subject
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Axiom::Adapter::Arango::Gateway, '#take' do
|
6
|
+
subject { object.take(args) }
|
7
|
+
|
8
|
+
let(:adapter) { mock('Adapter') }
|
9
|
+
let(:relation) { mock('Relation', :take => response) }
|
10
|
+
let(:response) { mock('New Relation', :kind_of? => true) }
|
11
|
+
let!(:object) { described_class.new(adapter, relation) }
|
12
|
+
let(:args) { stub }
|
13
|
+
|
14
|
+
it_should_behave_like 'a unary relation method'
|
15
|
+
|
16
|
+
it 'forwards the arguments to relation#take' do
|
17
|
+
relation.should_receive(:take).with(args)
|
18
|
+
subject
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Axiom::Adapter::Arango::Gateway, '#unhandled_message' do
|
6
|
+
subject { object.unhandled_message }
|
7
|
+
|
8
|
+
let(:adapter) { mock('Adapter') }
|
9
|
+
let(:relation) { mock('Relation', :drop => response) }
|
10
|
+
let(:response) { mock('New Relation', :kind_of? => true) }
|
11
|
+
let(:object) { described_class.new(adapter, relation) }
|
12
|
+
let(:args) { stub }
|
13
|
+
|
14
|
+
it 'raises no method error' do
|
15
|
+
expect { subject }.to raise_error(NoMethodError)
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Axiom::Adapter::Arango::Gateway, '#union' do
|
6
|
+
subject { object.union(other) }
|
7
|
+
|
8
|
+
let(:adapter) { mock('Adapter') }
|
9
|
+
let(:relation) { mock('Relation') }
|
10
|
+
let(:object) { described_class.new(adapter, relation) }
|
11
|
+
let(:operation) { :union }
|
12
|
+
let(:factory) { Axiom::Algebra::Union }
|
13
|
+
let(:binary_relation) { mock(factory) }
|
14
|
+
|
15
|
+
it_should_behave_like 'a binary relation method'
|
16
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Axiom::Adapter::Arango::Reader, '#each' do
|
4
|
+
let(:object) { described_class.new(adapter, relation) }
|
5
|
+
let(:adapter) { mock('Adapter', :database => database, :logger => logger) }
|
6
|
+
let(:aql_node) { mock('AQL Node', :aql => aql) }
|
7
|
+
let(:aql) { mock('AQL') }
|
8
|
+
let(:logger) { mock('Logger') }
|
9
|
+
let(:header) { Axiom::Relation::Header.coerce([[:id, Integer], [:name, String]]) }
|
10
|
+
let(:relation) { mock('Relation', :header => header) }
|
11
|
+
let(:database) { mock('Database', :query => query) }
|
12
|
+
let(:query) { mock('Query') }
|
13
|
+
let(:yields) { [] }
|
14
|
+
let(:cursor) { [document_a, document_b] }
|
15
|
+
let(:document_a) { mock('Document A', :to_hash => hash_a) }
|
16
|
+
let(:document_b) { mock('Document B', :to_hash => hash_b) }
|
17
|
+
let(:hash_a) { { 'id' => 1, 'name' => 'Markus Schirp' } }
|
18
|
+
let(:hash_b) { { 'id' => 2, 'name' => 'John Doe' } }
|
19
|
+
let(:tuple_a) { Axiom::Tuple.new(header, document_a.to_hash.values_at('id', 'name')) }
|
20
|
+
let(:tuple_b) { Axiom::Tuple.new(header, document_b.to_hash.values_at('id', 'name')) }
|
21
|
+
|
22
|
+
subject { object.each { |item| yields << item } }
|
23
|
+
|
24
|
+
before do
|
25
|
+
logger.stub(:debug)
|
26
|
+
Axiom::Adapter::Arango::Visitor.stub(:run).with(relation).and_return(aql_node)
|
27
|
+
query.stub(:execute).with(aql).and_return(cursor)
|
28
|
+
end
|
29
|
+
|
30
|
+
it_should_behave_like 'an #each method'
|
31
|
+
|
32
|
+
it 'should yield expected tuples' do
|
33
|
+
expect { subject }.to change { yields }.from([]).to([tuple_a, tuple_b])
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should log aql' do
|
37
|
+
logger.should_receive(:debug) do |&block|
|
38
|
+
block.call.should eql("AQL: #{aql}")
|
39
|
+
end
|
40
|
+
subject
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Axiom::Adapter::Arango::Visitor::Aggregate::Count, '#root' do
|
4
|
+
|
5
|
+
let(:object) { described_class.new(relation, context) }
|
6
|
+
let(:context) { AQL.name_node('collect') }
|
7
|
+
|
8
|
+
subject { object.root }
|
9
|
+
|
10
|
+
let(:relation) { base.summarize([:bar]) { |r| r.add(:count, r.foo.count) }.summarizers.values.first }
|
11
|
+
|
12
|
+
expect_aql <<-AQL
|
13
|
+
LENGTH((FOR `aggregate` IN `collect` FILTER (`aggregate`.`summarization`.`foo` != null) RETURN `aggregate`.`summarization`.`foo`))
|
14
|
+
AQL
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Axiom::Adapter::Arango::Visitor::Aggregate::Count, '#root' do
|
4
|
+
|
5
|
+
let(:object) { described_class.new(relation, context) }
|
6
|
+
let(:context) { AQL.name_node('collect') }
|
7
|
+
|
8
|
+
subject { object.root }
|
9
|
+
|
10
|
+
let(:relation) { base.summarize([:bar]) { |r| r.add(:count, r.foo.count) }.summarizers.values.first }
|
11
|
+
|
12
|
+
expect_aql <<-AQL
|
13
|
+
LENGTH((FOR `aggregate` IN `collect` FILTER (`aggregate`.`summarization`.`foo` != null) RETURN `aggregate`.`summarization`.`foo`))
|
14
|
+
AQL
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Axiom::Adapter::Arango::Visitor::Aggregate::Maximum, '#root' do
|
4
|
+
|
5
|
+
let(:object) { described_class.new(relation, context) }
|
6
|
+
let(:context) { AQL.name_node('collect') }
|
7
|
+
|
8
|
+
subject { object.root }
|
9
|
+
|
10
|
+
let(:relation) { base.summarize([:bar]) { |r| r.add(:max, r.foo.max) }.summarizers.values.first }
|
11
|
+
|
12
|
+
expect_aql <<-AQL
|
13
|
+
MAX((FOR `aggregate` IN `collect` FILTER (`aggregate`.`summarization`.`foo` != null) RETURN `aggregate`.`summarization`.`foo`))
|
14
|
+
AQL
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Axiom::Adapter::Arango::Visitor::Aggregate::Maximum, '#root' do
|
4
|
+
|
5
|
+
let(:object) { described_class.new(relation, context) }
|
6
|
+
let(:context) { AQL.name_node('collect') }
|
7
|
+
|
8
|
+
subject { object.root }
|
9
|
+
|
10
|
+
let(:relation) { base.summarize([:bar]) { |r| r.add(:max, r.foo.max) }.summarizers.values.first }
|
11
|
+
|
12
|
+
expect_aql <<-AQL
|
13
|
+
MAX((FOR `aggregate` IN `collect` FILTER (`aggregate`.`summarization`.`foo` != null) RETURN `aggregate`.`summarization`.`foo`))
|
14
|
+
AQL
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Axiom::Adapter::Arango::Visitor::Aggregate::Minimum, '#root' do
|
4
|
+
|
5
|
+
let(:object) { described_class.new(relation, context) }
|
6
|
+
let(:context) { AQL.name_node('collect') }
|
7
|
+
|
8
|
+
subject { object.root }
|
9
|
+
|
10
|
+
let(:relation) { base.summarize([:bar]) { |r| r.add(:min, r.foo.min) }.summarizers.values.first }
|
11
|
+
|
12
|
+
expect_aql <<-AQL
|
13
|
+
MIN((FOR `aggregate` IN `collect` FILTER (`aggregate`.`summarization`.`foo` != null) RETURN `aggregate`.`summarization`.`foo`))
|
14
|
+
AQL
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Axiom::Adapter::Arango::Visitor::Aggregate::Minimum, '#root' do
|
4
|
+
|
5
|
+
let(:object) { described_class.new(relation, context) }
|
6
|
+
let(:context) { AQL.name_node('collect') }
|
7
|
+
|
8
|
+
subject { object.root }
|
9
|
+
|
10
|
+
let(:relation) { base.summarize([:bar]) { |r| r.add(:min, r.foo.min) }.summarizers.values.first }
|
11
|
+
|
12
|
+
expect_aql <<-AQL
|
13
|
+
MIN((FOR `aggregate` IN `collect` FILTER (`aggregate`.`summarization`.`foo` != null) RETURN `aggregate`.`summarization`.`foo`))
|
14
|
+
AQL
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Axiom::Adapter::Arango::Visitor::Aggregate::Sum, '#sum' do
|
4
|
+
|
5
|
+
let(:object) { described_class.new(relation, context) }
|
6
|
+
let(:context) { AQL.name_node('collect') }
|
7
|
+
|
8
|
+
subject { object.root }
|
9
|
+
|
10
|
+
let(:relation) { base.summarize([:foo]) { |r| r.add(:count, r.bar.sum) }.summarizers.values.first }
|
11
|
+
|
12
|
+
expect_aql <<-AQL
|
13
|
+
SUM((FOR `aggregate` IN `collect` FILTER (`aggregate`.`summarization`.`bar` != null) RETURN `aggregate`.`summarization`.`bar`))
|
14
|
+
AQL
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Axiom::Adapter::Arango::Visitor::Aggregate::Sum, '#sum' do
|
4
|
+
|
5
|
+
let(:object) { described_class.new(relation, context) }
|
6
|
+
let(:context) { AQL.name_node('collect') }
|
7
|
+
|
8
|
+
subject { object.root }
|
9
|
+
|
10
|
+
let(:relation) { base.summarize([:foo]) { |r| r.add(:count, r.bar.sum) }.summarizers.values.first }
|
11
|
+
|
12
|
+
expect_aql <<-AQL
|
13
|
+
SUM((FOR `aggregate` IN `collect` FILTER (`aggregate`.`summarization`.`bar` != null) RETURN `aggregate`.`summarization`.`bar`))
|
14
|
+
AQL
|
15
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Axiom::Adapter::Arango::Visitor::Attribute, '#root' do
|
4
|
+
let(:relation) { base.header[:foo] }
|
5
|
+
let(:context) { mock('Visitor Context', :local_name => AQL::Node::Name.new('local_name')) }
|
6
|
+
|
7
|
+
subject { object.root }
|
8
|
+
|
9
|
+
it_should_behave_like 'an idempotent method'
|
10
|
+
|
11
|
+
expect_aql('`local_name`.`foo`')
|
12
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Axiom::Adapter::Arango::Visitor::Binary, '#root' do
|
4
|
+
|
5
|
+
let(:relation) { base.restrict { |r| r.foo.eq('bar') }.predicate }
|
6
|
+
let(:context) { mock('Visitor Context', :local_name => AQL::Node::Name.new('local_name')) }
|
7
|
+
|
8
|
+
subject { object.root }
|
9
|
+
|
10
|
+
expect_aql <<-AQL
|
11
|
+
(`local_name`.`foo` == "bar")
|
12
|
+
AQL
|
13
|
+
|
14
|
+
end
|
15
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Axiom::Adapter::Arango::Visitor, '.build' do
|
4
|
+
let(:object) { described_class }
|
5
|
+
|
6
|
+
let(:relation) { mock('Axiom Node') }
|
7
|
+
let(:aql_node) { mock('AQL Node') }
|
8
|
+
let(:context) { mock('Context') }
|
9
|
+
let(:build) { mock('Visitor', :root => aql_node) }
|
10
|
+
|
11
|
+
class Dummy
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:dummy) { Dummy.new }
|
15
|
+
|
16
|
+
let!(:test_visitor) do
|
17
|
+
aql_node = self.aql_node
|
18
|
+
Class.new(described_class) do
|
19
|
+
handle(Dummy)
|
20
|
+
define_method :root do
|
21
|
+
aql_node
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'with explicit context' do
|
27
|
+
subject { object.build(dummy, context) }
|
28
|
+
|
29
|
+
it { should eql(test_visitor.new(dummy, context)) }
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'with implicit context' do
|
33
|
+
subject { object.build(dummy) }
|
34
|
+
|
35
|
+
it { should eql(test_visitor.new(dummy, nil)) }
|
36
|
+
end
|
37
|
+
end
|