influxdb-arel 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -0
  3. data/Gemfile +1 -0
  4. data/README.md +218 -124
  5. data/lib/influxdb/arel.rb +25 -16
  6. data/lib/influxdb/arel/builder.rb +209 -0
  7. data/lib/influxdb/arel/clauses.rb +6 -0
  8. data/lib/influxdb/arel/clauses/base.rb +34 -0
  9. data/lib/influxdb/arel/clauses/expressions.rb +75 -0
  10. data/lib/influxdb/arel/clauses/from_clause.rb +45 -0
  11. data/lib/influxdb/arel/clauses/group_clause.rb +34 -0
  12. data/lib/influxdb/arel/clauses/select_clause.rb +37 -0
  13. data/lib/influxdb/arel/clauses/where_clause.rb +102 -0
  14. data/lib/influxdb/arel/core_extensions.rb +5 -21
  15. data/lib/influxdb/arel/delete_manager.rb +50 -0
  16. data/lib/influxdb/arel/extensions.rb +6 -0
  17. data/lib/influxdb/arel/extensions/alias_predication.rb +11 -0
  18. data/lib/influxdb/arel/extensions/boolean_predications.rb +15 -0
  19. data/lib/influxdb/arel/extensions/expressions.rb +75 -0
  20. data/lib/influxdb/arel/extensions/joining_merging.rb +21 -0
  21. data/lib/influxdb/arel/extensions/math.rb +23 -0
  22. data/lib/influxdb/arel/extensions/predications.rb +144 -0
  23. data/lib/influxdb/arel/nodes.rb +7 -14
  24. data/lib/influxdb/arel/nodes/attribute.rb +20 -0
  25. data/lib/influxdb/arel/nodes/binary.rb +4 -3
  26. data/lib/influxdb/arel/nodes/delete_statement.rb +37 -0
  27. data/lib/influxdb/arel/nodes/duration.rb +3 -3
  28. data/lib/influxdb/arel/nodes/function.rb +2 -2
  29. data/lib/influxdb/arel/nodes/grouping.rb +3 -3
  30. data/lib/influxdb/arel/nodes/infix_operation.rb +11 -4
  31. data/lib/influxdb/arel/nodes/merge.rb +13 -0
  32. data/lib/influxdb/arel/nodes/node.rb +18 -6
  33. data/lib/influxdb/arel/nodes/now.rb +1 -1
  34. data/lib/influxdb/arel/nodes/ordering.rb +15 -0
  35. data/lib/influxdb/arel/nodes/select_statement.rb +10 -8
  36. data/lib/influxdb/arel/nodes/sql_literal.rb +5 -8
  37. data/lib/influxdb/arel/nodes/table.rb +19 -0
  38. data/lib/influxdb/arel/nodes/table_alias.rb +2 -4
  39. data/lib/influxdb/arel/nodes/unary.rb +6 -1
  40. data/lib/influxdb/arel/quoter.rb +85 -0
  41. data/lib/influxdb/arel/select_manager.rb +111 -64
  42. data/lib/influxdb/arel/tree_manager.rb +15 -5
  43. data/lib/influxdb/arel/version.rb +1 -1
  44. data/lib/influxdb/arel/visitor.rb +96 -126
  45. data/lib/influxdb/arel/visitor/delete_statement.rb +32 -0
  46. data/lib/influxdb/arel/visitor/select_statement.rb +59 -0
  47. data/lib/influxdb/arel/visitor/where_statement.rb +14 -0
  48. data/spec/lib/influxdb/arel/builder_spec.rb +173 -0
  49. data/spec/lib/influxdb/arel/core_extensions_spec.rb +0 -21
  50. data/spec/lib/influxdb/arel/nodes/and_spec.rb +6 -9
  51. data/spec/lib/influxdb/arel/nodes/attribute_spec.rb +21 -0
  52. data/spec/lib/influxdb/arel/nodes/binary_spec.rb +0 -4
  53. data/spec/lib/influxdb/arel/nodes/duration_spec.rb +1 -0
  54. data/spec/lib/influxdb/arel/nodes/in_spec.rb +1 -0
  55. data/spec/lib/influxdb/arel/nodes/infix_operation_spec.rb +17 -0
  56. data/spec/lib/influxdb/arel/nodes/merge_spec.rb +25 -0
  57. data/spec/lib/influxdb/arel/nodes/now_spec.rb +1 -0
  58. data/spec/lib/influxdb/arel/nodes/ordering_spec.rb +19 -0
  59. data/spec/lib/influxdb/arel/nodes/sql_literal_spec.rb +1 -5
  60. data/spec/lib/influxdb/arel/nodes/table_alias_spec.rb +3 -10
  61. data/spec/lib/influxdb/arel/nodes/table_spec.rb +8 -0
  62. data/spec/lib/influxdb/arel/nodes/unary_spec.rb +0 -4
  63. data/spec/lib/influxdb/arel/quoter/repository_spec.rb +10 -0
  64. data/spec/lib/influxdb/arel/quoter_spec.rb +33 -0
  65. data/spec/lib/influxdb/arel/select_manager_spec.rb +356 -156
  66. data/spec/lib/influxdb/arel_spec.rb +22 -0
  67. data/spec/spec_helper.rb +15 -0
  68. data/spec/support/examples/binary_node.rb +1 -0
  69. data/spec/support/examples/function_node.rb +1 -0
  70. data/spec/support/examples/infix_operation_node.rb +15 -0
  71. data/spec/support/examples/node_boolean_predications.rb +21 -0
  72. data/spec/support/examples/node_joining_merging.rb +53 -0
  73. data/spec/support/examples/unary_node.rb +1 -0
  74. data/spec/support/fabrics.rb +3 -3
  75. metadata +49 -11
  76. data/lib/influxdb/arel/alias_predication.rb +0 -9
  77. data/lib/influxdb/arel/attributes.rb +0 -1
  78. data/lib/influxdb/arel/attributes/attribute.rb +0 -74
  79. data/lib/influxdb/arel/expressions.rb +0 -73
  80. data/lib/influxdb/arel/math.rb +0 -21
  81. data/lib/influxdb/arel/predications.rb +0 -137
  82. data/lib/influxdb/arel/table.rb +0 -219
  83. data/spec/lib/influxdb/arel/table_spec.rb +0 -193
@@ -0,0 +1,32 @@
1
+ module Influxdb
2
+ module Arel
3
+ class Visitor
4
+ class DeleteStatement
5
+ include WhereStatement
6
+
7
+ attr_reader :visitor
8
+
9
+ def initialize(visitor)
10
+ @visitor = visitor
11
+ end
12
+
13
+ def visit(object)
14
+ build_from(object)
15
+ build_wheres(object)
16
+
17
+ result.strip
18
+ end
19
+
20
+ private
21
+
22
+ def build_from(object)
23
+ result << " FROM #{visitor.accept(object.table)}"
24
+ end
25
+
26
+ def result
27
+ @result ||= 'DELETE'
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,59 @@
1
+ module Influxdb
2
+ module Arel
3
+ class Visitor
4
+ class SelectStatement
5
+ include WhereStatement
6
+
7
+ attr_reader :visitor
8
+
9
+ def initialize(visitor)
10
+ @visitor = visitor
11
+ end
12
+
13
+ def visit(object)
14
+ build_attributes(object)
15
+ build_from(object)
16
+ build_wheres(object)
17
+ build_groups(object)
18
+ build_rest_of_clauses(object)
19
+
20
+ result.strip
21
+ end
22
+
23
+ private
24
+
25
+ def build_rest_of_clauses(object)
26
+ result << " #{visitor.accept(object.order)}" if object.order
27
+ result << " #{visitor.accept(object.limit)}" if object.limit
28
+ result << " #{visitor.accept(object.into)}" if object.into
29
+ end
30
+
31
+ def build_attributes(object)
32
+ unless object.attributes.empty?
33
+ result << SPACE
34
+ result << object.attributes.map{|attribute| visitor.accept(attribute) }.join(COMMA)
35
+ else
36
+ result << SPACE
37
+ result << Arel.star
38
+ end
39
+ end
40
+
41
+ def build_from(object)
42
+ result << " FROM #{visitor.accept(object.table)}"
43
+ end
44
+
45
+ def build_groups(object)
46
+ unless object.groups.empty?
47
+ result << GROUP_BY
48
+ result << object.groups.map{|group| visitor.accept(group) }.join(COMMA)
49
+ result << " #{visitor.accept(object.fill)}" if object.fill
50
+ end
51
+ end
52
+
53
+ def result
54
+ @result ||= 'SELECT'
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,14 @@
1
+ module Influxdb
2
+ module Arel
3
+ class Visitor
4
+ module WhereStatement
5
+ def build_wheres(object)
6
+ unless object.wheres.empty?
7
+ result << WHERE
8
+ result << object.wheres.map{|where| visitor.accept(where) }.join(AND)
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,173 @@
1
+ require 'spec_helper'
2
+
3
+ describe Influxdb::Arel::Builder do
4
+ describe '#from' do
5
+ subject{ builder(:events).from(:table) }
6
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
7
+ specify{ expect(subject.ast.tables).to eq([node(:Table, :table)]) }
8
+ specify{ expect(subject.to_sql).to eq('SELECT * FROM table') }
9
+ end
10
+
11
+ describe '#merge' do
12
+ subject{ builder(:events).merge(:errors) }
13
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
14
+ specify{ expect(subject.ast.merge).to eq(node(:Merge, node(:Table, :events), node(:Table, :errors))) }
15
+ specify{ expect(subject.to_sql).to eq('SELECT * FROM events MERGE errors') }
16
+
17
+ context 'when table as argument' do
18
+ subject{ builder(:events).merge(node(:Table, :errors)) }
19
+
20
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
21
+ specify{ expect(subject.ast.merge).to eq(node(:Merge, node(:Table, :events), node(:Table, :errors))) }
22
+ specify{ expect(subject.to_sql).to eq('SELECT * FROM events MERGE errors') }
23
+ end
24
+
25
+ context 'without argument' do
26
+ subject{ builder(:events).merge }
27
+ specify{ expect{ subject }.to raise_error }
28
+ end
29
+
30
+ context 'without argument with more than two tables' do
31
+ subject{ builder.from(:events, :errors, :logs).merge }
32
+ specify{ expect{ subject }.to raise_error }
33
+ end
34
+
35
+ context 'without argument with two tables' do
36
+ subject{ builder.from(:events, :errors).merge }
37
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
38
+ specify{ expect(subject.ast.merge).to eq(node(:Merge, node(:Table, :events), node(:Table, :errors))) }
39
+ specify{ expect(subject.to_sql).to eq('SELECT * FROM events MERGE errors') }
40
+ end
41
+ end
42
+
43
+ describe '#join' do
44
+ subject{ builder(:events).join(:errors) }
45
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
46
+ specify{ expect(subject.ast.join).to eq(node(:Join, node(:Table, :events), node(:Table, :errors))) }
47
+ specify{ expect(subject.to_sql).to eq('SELECT * FROM events INNER JOIN errors') }
48
+
49
+ context 'when table as argument' do
50
+ subject{ builder(:events).join(node(:Table, :errors)) }
51
+
52
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
53
+ specify{ expect(subject.ast.join).to eq(node(:Join, node(:Table, :events), node(:Table, :errors))) }
54
+ specify{ expect(subject.to_sql).to eq('SELECT * FROM events INNER JOIN errors') }
55
+ end
56
+
57
+ context 'without argument' do
58
+ subject{ builder(:events).join }
59
+ specify{ expect{ subject }.to raise_error }
60
+ end
61
+
62
+ context 'without argument with more than two tables' do
63
+ subject{ builder.from(:events, :errors, :logs).join }
64
+ specify{ expect{ subject }.to raise_error }
65
+ end
66
+
67
+ context 'without argument with two tables' do
68
+ subject{ builder.from(:events, :errors).join }
69
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
70
+ specify{ expect(subject.ast.join).to eq(node(:Join, node(:Table, :events), node(:Table, :errors))) }
71
+ specify{ expect(subject.to_sql).to eq('SELECT * FROM events INNER JOIN errors') }
72
+ end
73
+ end
74
+
75
+ describe '#order' do
76
+ context 'when sort by ascending order' do
77
+ subject{ builder(:events).order(:asc) }
78
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
79
+ specify{ expect(subject.order_value).to eq(node(:Ordering, 'asc')) }
80
+ specify{ expect(subject.to_sql).to eq('SELECT * FROM events ORDER ASC') }
81
+ end
82
+
83
+ context 'when sort by ascending order' do
84
+ subject{ builder(:events).order('asc') }
85
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
86
+ specify{ expect(subject.order_value).to eq(node(:Ordering, 'asc')) }
87
+ specify{ expect(subject.to_sql).to eq('SELECT * FROM events ORDER ASC') }
88
+ end
89
+
90
+ context 'when sort by descending order' do
91
+ subject{ builder(:events).order(:desc) }
92
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
93
+ specify{ expect(subject.order_value).to eq(node(:Ordering, 'desc')) }
94
+ specify{ expect(subject.to_sql).to eq('SELECT * FROM events ORDER DESC') }
95
+ end
96
+
97
+ context 'when sort by descending order' do
98
+ subject{ builder(:events).order('desc') }
99
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
100
+ specify{ expect(subject.order_value).to eq(node(:Ordering, 'desc')) }
101
+ specify{ expect(subject.to_sql).to eq('SELECT * FROM events ORDER DESC') }
102
+ end
103
+ end
104
+
105
+ describe '#asc' do
106
+ subject{ builder(:events).asc }
107
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
108
+ specify{ expect(subject.order_value).to eq(node(:Ordering, 'asc')) }
109
+ specify{ expect(subject.to_sql).to eq('SELECT * FROM events ORDER ASC') }
110
+ end
111
+
112
+ describe '#desc' do
113
+ subject{ builder(:events).desc }
114
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
115
+ specify{ expect(subject.order_value).to eq(node(:Ordering, 'desc')) }
116
+ specify{ expect(subject.to_sql).to eq('SELECT * FROM events ORDER DESC') }
117
+ end
118
+
119
+ describe '#limit' do
120
+ subject{ builder(:events).limit(100) }
121
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
122
+ specify{ expect(subject.limit_value).to eq(node(:Limit, 100)) }
123
+ specify{ expect(subject.to_sql).to eq('SELECT * FROM events LIMIT 100') }
124
+ end
125
+
126
+ describe '#group' do
127
+ subject{ builder(:events).group{ [time('1s'), 'name', :type] } }
128
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
129
+ specify{ expect(subject.group_values).to eq([
130
+ node(:Time, '1s'), node(:Attribute, 'name'), node(:Attribute, 'type')
131
+ ]) }
132
+ specify{ expect(subject.to_sql).to eq('SELECT * FROM events GROUP BY time(1s), name, type') }
133
+
134
+ context 'chaining' do
135
+ subject{ builder(:events).group{ time('1s') }.group('name', :type) }
136
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
137
+ specify{ expect(subject.ast.groups).to eq([
138
+ node(:Time, '1s'), node(:Attribute, 'name'), node(:Attribute, 'type')
139
+ ]) }
140
+ specify{ expect(subject.to_sql).to eq('SELECT * FROM events GROUP BY time(1s), name, type') }
141
+ end
142
+ end
143
+
144
+ describe '#where' do
145
+ subject{ builder(:events).where("name = 'Undr'") }
146
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
147
+ specify{ expect(subject.where_values).to eq([sql("name = 'Undr'")]) }
148
+ specify{ expect(subject.to_sql).to eq("SELECT * FROM events WHERE name = 'Undr'") }
149
+
150
+ context 'chaining' do
151
+ subject{ builder(:events).where("name = 'Undr'").where(sql("email = 'undr@gmail.com'")) }
152
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
153
+ specify{ expect(subject.where_values).to eq([sql("name = 'Undr'"), sql("email = 'undr@gmail.com'")]) }
154
+ specify{ expect(subject.to_sql).to eq("SELECT * FROM events WHERE name = 'Undr' AND email = 'undr@gmail.com'") }
155
+ end
156
+ end
157
+
158
+ describe '#select' do
159
+ subject{ builder('events').select('name', :type) }
160
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
161
+ specify{ expect(subject.select_values).to eq([node(:Attribute, 'name'), node(:Attribute, 'type')]) }
162
+ specify{ expect(subject.to_sql).to eq('SELECT name, type FROM events') }
163
+
164
+ context 'chaining' do
165
+ subject{ builder('events').select{ time }.select('name', :type) }
166
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
167
+ specify{ expect(subject.select_values).to eq(
168
+ [node(:Attribute, 'time'), node(:Attribute, 'name'), node(:Attribute, 'type')]
169
+ ) }
170
+ specify{ expect(subject.to_sql).to eq('SELECT time, name, type FROM events') }
171
+ end
172
+ end
173
+ end
@@ -26,24 +26,3 @@ describe Integer do
26
26
  specify{ expect(1.w).to eq(node(:Duration, 1, sql('w'))) }
27
27
  end
28
28
  end
29
-
30
-
31
- describe String do
32
- describe '#as' do
33
- specify{ expect('MEAN(value)'.as('mean')).to eq(node(:As, sql('MEAN(value)'), 'mean')) }
34
- end
35
-
36
- describe '#to_arel' do
37
- specify{ expect('events'.to_arel).to eq(sql('events')) }
38
- end
39
- end
40
-
41
- describe Symbol do
42
- describe '#as' do
43
- specify{ expect(:events.as('alias')).to eq(node(:TableAlias, table(:events), 'alias')) }
44
- end
45
-
46
- describe '#to_arel' do
47
- specify{ expect(:events.to_arel).to eq(table(:events)) }
48
- end
49
- end
@@ -1,17 +1,14 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Influxdb::Arel::Nodes::And do
4
- describe '#to_sql' do
5
- subject{ node(:And, ['first', sql('second'), 'third']).to_sql }
4
+ let(:described_node){ node(:And, ['first', sql('second'), 'third']) }
6
5
 
7
- specify{ expect(subject).to eq("'first' AND second AND 'third'") }
8
- end
6
+ it_should_behave_like :node_to_sql, "'first' AND second AND 'third'"
7
+ it_should_behave_like :node_boolean_predications, "'first' AND second AND 'third'"
9
8
 
10
9
  describe '#eql?' do
11
- subject{ node(:And, ['first', sql('second'), 'third']) }
12
-
13
- specify{ expect(subject.eql?(node(:And, ['first', sql('second'), 'third']))).to be_truthy }
14
- specify{ expect(subject.eql?(node(:And, ['first', 'second', 'third']))).to be_truthy }
15
- specify{ expect(subject.eql?(node(:And, ['first', 'second', 'third', 'fourth']))).to be_falsy }
10
+ specify{ expect(described_node.eql?(node(:And, ['first', sql('second'), 'third']))).to be_truthy }
11
+ specify{ expect(described_node.eql?(node(:And, ['first', 'second', 'third']))).to be_truthy }
12
+ specify{ expect(described_node.eql?(node(:And, ['first', 'second', 'third', 'fourth']))).to be_falsy }
16
13
  end
17
14
  end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe Influxdb::Arel::Nodes::Attribute do
4
+ let(:described_node){ node(:Attribute, 'value') }
5
+
6
+ it_should_behave_like :unary_node, :Attribute, 'value'
7
+ it_should_behave_like :node_as, 'value'
8
+ it_should_behave_like :node_expressions, 'value'
9
+ it_should_behave_like :node_predications, 'value'
10
+ it_should_behave_like :node_math, 'value'
11
+
12
+ describe '#time?' do
13
+ specify{ expect(node(:Attribute, 'value').time?).to be_falsy }
14
+ specify{ expect(node(:Attribute, 'time').time?).to be_truthy }
15
+ end
16
+
17
+ describe '#sequence_number?' do
18
+ specify{ expect(node(:Attribute, 'value').sequence_number?).to be_falsy }
19
+ specify{ expect(node(:Attribute, 'sequence_number').sequence_number?).to be_truthy }
20
+ end
21
+ end
@@ -36,10 +36,6 @@ describe Influxdb::Arel::Nodes::Matches do
36
36
  it_should_behave_like :binary_node, :Matches, 'left =~ right'
37
37
  end
38
38
 
39
- describe Influxdb::Arel::Nodes::Merge do
40
- it_should_behave_like :binary_node, :Merge, 'left MERGE right'
41
- end
42
-
43
39
  describe Influxdb::Arel::Nodes::NotEqual do
44
40
  it_should_behave_like :binary_node, :NotEqual, 'left <> right'
45
41
  end
@@ -4,6 +4,7 @@ describe Influxdb::Arel::Nodes::Duration do
4
4
  let(:described_node){ node(:Duration, 10, 'h') }
5
5
 
6
6
  it_should_behave_like :node_to_sql, '10h'
7
+ it_should_behave_like :node_boolean_predications, '10h'
7
8
 
8
9
  describe '#eql?' do
9
10
  specify{ expect(described_node.eql?(node(:Duration, 10, 'h'))).to be_truthy }
@@ -4,6 +4,7 @@ describe Influxdb::Arel::Nodes::In do
4
4
  let(:described_node){ node(:In, sql('left'), [1, 2, 3]) }
5
5
 
6
6
  it_should_behave_like :node_to_sql, 'left IN (1, 2, 3)'
7
+ it_should_behave_like :node_boolean_predications, 'left IN (1, 2, 3)'
7
8
 
8
9
  describe '#eql?' do
9
10
  specify{ expect(described_node.eql?(node(:In, sql('left'), [1, 2, 3]))).to be_truthy }
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe Influxdb::Arel::Nodes::Multiplication do
4
+ it_should_behave_like :infix_operation_node, :Multiplication, 'left * right'
5
+ end
6
+
7
+ describe Influxdb::Arel::Nodes::Division do
8
+ it_should_behave_like :infix_operation_node, :Division, 'left / right'
9
+ end
10
+
11
+ describe Influxdb::Arel::Nodes::Addition do
12
+ it_should_behave_like :infix_operation_node, :Addition, 'left + right'
13
+ end
14
+
15
+ describe Influxdb::Arel::Nodes::Subtraction do
16
+ it_should_behave_like :infix_operation_node, :Subtraction, 'left - right'
17
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Influxdb::Arel::Nodes::Merge do
4
+ describe 'initialization' do
5
+ let(:described_node){ node(:Merge, left, right) }
6
+
7
+ context 'with tables' do
8
+ let(:left){ node(:Table, 'left') }
9
+ let(:right){ node(:Table, 'right') }
10
+
11
+ specify{ expect(described_node.left).to be_instance_of(Influxdb::Arel::Nodes::Table) }
12
+ specify{ expect(described_node.right).to be_instance_of(Influxdb::Arel::Nodes::Table) }
13
+ end
14
+
15
+ context 'with aliases' do
16
+ let(:left){ node(:Table, 'left').as(:alias1) }
17
+ let(:right){ node(:Table, 'right').as(:alias2) }
18
+
19
+ specify{ expect(described_node.left).to be_instance_of(Influxdb::Arel::Nodes::Table) }
20
+ specify{ expect(described_node.right).to be_instance_of(Influxdb::Arel::Nodes::Table) }
21
+ end
22
+ end
23
+
24
+ it_should_behave_like :binary_node, :Merge, 'left MERGE right'
25
+ end
@@ -4,5 +4,6 @@ describe Influxdb::Arel::Nodes::Now do
4
4
  let(:described_node){ node(:Now) }
5
5
 
6
6
  it_should_behave_like :node_to_sql, 'now()'
7
+ it_should_behave_like :node_boolean_predications, 'now()'
7
8
  it_should_behave_like :node_math, 'now()'
8
9
  end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Influxdb::Arel::Nodes::Ordering do
4
+ it_should_behave_like :unary_node, :Ordering, 'ORDER VALUE'
5
+
6
+ describe '#invert' do
7
+ subject{ node(:Ordering, direction).invert }
8
+
9
+ context 'from ascending order' do
10
+ let(:direction){ :asc }
11
+ specify{ expect(subject).to eq(node(:Ordering, :desc)) }
12
+ end
13
+
14
+ context 'from descending order' do
15
+ let(:direction){ :desc }
16
+ specify{ expect(subject).to eq(node(:Ordering, :asc)) }
17
+ end
18
+ end
19
+ end