veritas-sql-generator 0.0.3
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.
- data/Gemfile +33 -0
- data/LICENSE +20 -0
- data/README.rdoc +27 -0
- data/Rakefile +25 -0
- data/TODO +17 -0
- data/config/flay.yml +3 -0
- data/config/flog.yml +2 -0
- data/config/roodi.yml +16 -0
- data/config/site.reek +124 -0
- data/config/yardstick.yml +2 -0
- data/lib/veritas-sql-generator.rb +3 -0
- data/lib/veritas/base_relation.rb +36 -0
- data/lib/veritas/sql/generator.rb +35 -0
- data/lib/veritas/sql/generator/attribute.rb +25 -0
- data/lib/veritas/sql/generator/direction.rb +36 -0
- data/lib/veritas/sql/generator/identifier.rb +27 -0
- data/lib/veritas/sql/generator/literal.rb +160 -0
- data/lib/veritas/sql/generator/logic.rb +349 -0
- data/lib/veritas/sql/generator/relation.rb +111 -0
- data/lib/veritas/sql/generator/relation/base.rb +14 -0
- data/lib/veritas/sql/generator/relation/binary.rb +184 -0
- data/lib/veritas/sql/generator/relation/set.rb +99 -0
- data/lib/veritas/sql/generator/relation/unary.rb +326 -0
- data/lib/veritas/sql/generator/version.rb +9 -0
- data/lib/veritas/sql/generator/visitor.rb +121 -0
- data/spec/rcov.opts +6 -0
- data/spec/shared/command_method_behavior.rb +7 -0
- data/spec/shared/generated_sql_behavior.rb +15 -0
- data/spec/shared/idempotent_method_behavior.rb +7 -0
- data/spec/spec.opts +3 -0
- data/spec/spec_helper.rb +15 -0
- data/spec/unit/veritas/base_relation/name_spec.rb +45 -0
- data/spec/unit/veritas/sql/generator/attribute/visit_veritas_attribute_spec.rb +15 -0
- data/spec/unit/veritas/sql/generator/direction/visit_veritas_relation_operation_order_ascending_spec.rb +15 -0
- data/spec/unit/veritas/sql/generator/direction/visit_veritas_relation_operation_order_descending_spec.rb +15 -0
- data/spec/unit/veritas/sql/generator/identifier/visit_identifier_spec.rb +26 -0
- data/spec/unit/veritas/sql/generator/literal/class_methods/dup_frozen_spec.rb +23 -0
- data/spec/unit/veritas/sql/generator/literal/visit_class_spec.rb +31 -0
- data/spec/unit/veritas/sql/generator/literal/visit_date_spec.rb +15 -0
- data/spec/unit/veritas/sql/generator/literal/visit_date_time_spec.rb +61 -0
- data/spec/unit/veritas/sql/generator/literal/visit_enumerable_spec.rb +15 -0
- data/spec/unit/veritas/sql/generator/literal/visit_false_class_spec.rb +14 -0
- data/spec/unit/veritas/sql/generator/literal/visit_nil_class_spec.rb +14 -0
- data/spec/unit/veritas/sql/generator/literal/visit_numeric_spec.rb +34 -0
- data/spec/unit/veritas/sql/generator/literal/visit_string_spec.rb +26 -0
- data/spec/unit/veritas/sql/generator/literal/visit_time_spec.rb +97 -0
- data/spec/unit/veritas/sql/generator/literal/visit_true_class_spec.rb +14 -0
- data/spec/unit/veritas/sql/generator/logic/visit_veritas_logic_connective_conjunction_spec.rb +16 -0
- data/spec/unit/veritas/sql/generator/logic/visit_veritas_logic_connective_disjunction_spec.rb +16 -0
- data/spec/unit/veritas/sql/generator/logic/visit_veritas_logic_connective_negation_spec.rb +16 -0
- data/spec/unit/veritas/sql/generator/logic/visit_veritas_logic_predicate_equality_spec.rb +27 -0
- data/spec/unit/veritas/sql/generator/logic/visit_veritas_logic_predicate_exclusion_spec.rb +43 -0
- data/spec/unit/veritas/sql/generator/logic/visit_veritas_logic_predicate_greater_than_or_equal_to_spec.rb +15 -0
- data/spec/unit/veritas/sql/generator/logic/visit_veritas_logic_predicate_greater_than_spec.rb +15 -0
- data/spec/unit/veritas/sql/generator/logic/visit_veritas_logic_predicate_inclusion_spec.rb +43 -0
- data/spec/unit/veritas/sql/generator/logic/visit_veritas_logic_predicate_inequality_spec.rb +55 -0
- data/spec/unit/veritas/sql/generator/logic/visit_veritas_logic_predicate_less_than_or_equal_to_spec.rb +15 -0
- data/spec/unit/veritas/sql/generator/logic/visit_veritas_logic_predicate_less_than_spec.rb +15 -0
- data/spec/unit/veritas/sql/generator/logic/visit_veritas_logic_proposition_contradiction_spec.rb +15 -0
- data/spec/unit/veritas/sql/generator/logic/visit_veritas_logic_proposition_tautology_spec.rb +15 -0
- data/spec/unit/veritas/sql/generator/relation/binary/base/to_subquery_spec.rb +35 -0
- data/spec/unit/veritas/sql/generator/relation/binary/base/visit_veritas_base_relation_spec.rb +22 -0
- data/spec/unit/veritas/sql/generator/relation/binary/class_methods/subquery_spec.rb +42 -0
- data/spec/unit/veritas/sql/generator/relation/binary/to_s_spec.rb +35 -0
- data/spec/unit/veritas/sql/generator/relation/binary/to_subquery_spec.rb +35 -0
- data/spec/unit/veritas/sql/generator/relation/binary/visit_veritas_algebra_join_spec.rb +138 -0
- data/spec/unit/veritas/sql/generator/relation/binary/visit_veritas_algebra_product_spec.rb +139 -0
- data/spec/unit/veritas/sql/generator/relation/class_methods/subquery_spec.rb +33 -0
- data/spec/unit/veritas/sql/generator/relation/class_methods/visit_spec.rb +61 -0
- data/spec/unit/veritas/sql/generator/relation/name_spec.rb +30 -0
- data/spec/unit/veritas/sql/generator/relation/set/to_s_spec.rb +55 -0
- data/spec/unit/veritas/sql/generator/relation/set/to_subquery_spec.rb +55 -0
- data/spec/unit/veritas/sql/generator/relation/set/visit_veritas_algebra_difference_spec.rb +138 -0
- data/spec/unit/veritas/sql/generator/relation/set/visit_veritas_algebra_intersection_spec.rb +138 -0
- data/spec/unit/veritas/sql/generator/relation/set/visit_veritas_algebra_union_spec.rb +138 -0
- data/spec/unit/veritas/sql/generator/relation/to_sql_spec.rb +52 -0
- data/spec/unit/veritas/sql/generator/relation/unary/to_s_spec.rb +55 -0
- data/spec/unit/veritas/sql/generator/relation/unary/to_subquery_spec.rb +75 -0
- data/spec/unit/veritas/sql/generator/relation/unary/visit_veritas_algebra_projection_spec.rb +138 -0
- data/spec/unit/veritas/sql/generator/relation/unary/visit_veritas_algebra_rename_spec.rb +136 -0
- data/spec/unit/veritas/sql/generator/relation/unary/visit_veritas_algebra_restriction_spec.rb +157 -0
- data/spec/unit/veritas/sql/generator/relation/unary/visit_veritas_base_relation_spec.rb +21 -0
- data/spec/unit/veritas/sql/generator/relation/unary/visit_veritas_relation_operation_limit_spec.rb +125 -0
- data/spec/unit/veritas/sql/generator/relation/unary/visit_veritas_relation_operation_offset_spec.rb +125 -0
- data/spec/unit/veritas/sql/generator/relation/unary/visit_veritas_relation_operation_order_spec.rb +136 -0
- data/spec/unit/veritas/sql/generator/relation/unary/visit_veritas_relation_operation_reverse_spec.rb +125 -0
- data/spec/unit/veritas/sql/generator/relation/visit_spec.rb +54 -0
- data/spec/unit/veritas/sql/generator/relation/visited_spec.rb +35 -0
- data/spec/unit/veritas/sql/generator/visitor/class_methods/handler_for_spec.rb +71 -0
- data/spec/unit/veritas/sql/generator/visitor/visit_spec.rb +12 -0
- data/spec/unit/veritas/sql/generator/visitor/visited_spec.rb +11 -0
- data/tasks/quality/ci.rake +2 -0
- data/tasks/quality/flay.rake +41 -0
- data/tasks/quality/flog.rake +45 -0
- data/tasks/quality/heckle.rake +203 -0
- data/tasks/quality/metric_fu.rake +26 -0
- data/tasks/quality/reek.rake +9 -0
- data/tasks/quality/roodi.rake +15 -0
- data/tasks/quality/yardstick.rake +23 -0
- data/tasks/spec.rake +38 -0
- data/tasks/yard.rake +9 -0
- data/veritas-sql-generator.gemspec +222 -0
- metadata +285 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe SQL::Generator::Literal, '#visit_enumerable' do
|
|
6
|
+
subject { object.visit_enumerable(enumerable) }
|
|
7
|
+
|
|
8
|
+
let(:described_class) { Class.new(SQL::Generator::Visitor) { include SQL::Generator::Literal } }
|
|
9
|
+
let(:enumerable) { [ 1, 2 ].freeze }
|
|
10
|
+
let(:object) { described_class.new }
|
|
11
|
+
|
|
12
|
+
it_should_behave_like 'a generated SQL expression'
|
|
13
|
+
|
|
14
|
+
its(:to_s) { should eql('(1, 2)') }
|
|
15
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe SQL::Generator::Literal, '#visit_false_class' do
|
|
6
|
+
subject { object.visit_false_class(false) }
|
|
7
|
+
|
|
8
|
+
let(:described_class) { Class.new(SQL::Generator::Visitor) { include SQL::Generator::Literal } }
|
|
9
|
+
let(:object) { described_class.new }
|
|
10
|
+
|
|
11
|
+
it_should_behave_like 'a generated SQL expression'
|
|
12
|
+
|
|
13
|
+
its(:to_s) { should eql('FALSE') }
|
|
14
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe SQL::Generator::Literal, '#visit_nil_class' do
|
|
6
|
+
subject { object.visit_nil_class(nil) }
|
|
7
|
+
|
|
8
|
+
let(:described_class) { Class.new(SQL::Generator::Visitor) { include SQL::Generator::Literal } }
|
|
9
|
+
let(:object) { described_class.new }
|
|
10
|
+
|
|
11
|
+
it_should_behave_like 'a generated SQL expression'
|
|
12
|
+
|
|
13
|
+
its(:to_s) { should eql('NULL') }
|
|
14
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe SQL::Generator::Literal, '#visit_numeric' do
|
|
6
|
+
subject { object.visit_numeric(numeric) }
|
|
7
|
+
|
|
8
|
+
let(:described_class) { Class.new(SQL::Generator::Visitor) { include SQL::Generator::Literal } }
|
|
9
|
+
let(:object) { described_class.new }
|
|
10
|
+
|
|
11
|
+
context 'with an Integer' do
|
|
12
|
+
let(:numeric) { 1 }
|
|
13
|
+
|
|
14
|
+
it_should_behave_like 'a generated SQL expression'
|
|
15
|
+
|
|
16
|
+
its(:to_s) { should eql('1') }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
context 'with a Float' do
|
|
20
|
+
let(:numeric) { 1.0 }
|
|
21
|
+
|
|
22
|
+
it_should_behave_like 'a generated SQL expression'
|
|
23
|
+
|
|
24
|
+
its(:to_s) { should eql('1.0') }
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
context 'with a BigDecimal' do
|
|
28
|
+
let(:numeric) { BigDecimal('1.0') }
|
|
29
|
+
|
|
30
|
+
it_should_behave_like 'a generated SQL expression'
|
|
31
|
+
|
|
32
|
+
its(:to_s) { should eql('0.1E1') }
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe SQL::Generator::Literal, '#visit_string' do
|
|
6
|
+
subject { object.visit_string(string) }
|
|
7
|
+
|
|
8
|
+
let(:described_class) { Class.new(SQL::Generator::Visitor) { include SQL::Generator::Literal } }
|
|
9
|
+
let(:object) { described_class.new }
|
|
10
|
+
|
|
11
|
+
context 'with a string containing no quotes' do
|
|
12
|
+
let(:string) { 'string'.freeze }
|
|
13
|
+
|
|
14
|
+
it_should_behave_like 'a generated SQL expression'
|
|
15
|
+
|
|
16
|
+
its(:to_s) { should eql("'string'") }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
context 'with a string containing quotes' do
|
|
20
|
+
let(:string) { "string'name".freeze }
|
|
21
|
+
|
|
22
|
+
it_should_behave_like 'a generated SQL expression'
|
|
23
|
+
|
|
24
|
+
its(:to_s) { should eql("'string''name'") }
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe SQL::Generator::Literal, '#visit_time' do
|
|
6
|
+
subject { object.visit_time(time) }
|
|
7
|
+
|
|
8
|
+
# Time#iso8601 is currently broken in JRuby 1.6.1 when fractional seconds are not 0
|
|
9
|
+
def self.time_iso8601_broken?
|
|
10
|
+
RUBY_PLATFORM =~ /java/ && JRUBY_VERSION <= '1.6.1' && RUBY_VERSION >= '1.9.2'
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
let(:described_class) { Class.new(SQL::Generator::Visitor) { include SQL::Generator::Literal } }
|
|
14
|
+
let(:object) { described_class.new }
|
|
15
|
+
|
|
16
|
+
before :all do
|
|
17
|
+
@original_tz = ENV['TZ']
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
after :all do
|
|
21
|
+
ENV['TZ'] = @original_tz
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
context 'when the Time is UTC' do
|
|
25
|
+
context 'and the microseconds are equal to 0' do
|
|
26
|
+
let(:usec) { 0 }
|
|
27
|
+
let(:time) { Time.utc(2010, 12, 31, 23, 59, 59, usec).freeze }
|
|
28
|
+
|
|
29
|
+
it_should_behave_like 'a generated SQL expression'
|
|
30
|
+
|
|
31
|
+
its(:to_s) { should eql("'2010-12-31T23:59:59.000000000Z'") }
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
context 'and the microseconds are greater than 0' do
|
|
35
|
+
let(:usec) { 1 }
|
|
36
|
+
let(:time) { Time.utc(2010, 12, 31, 23, 59, 59, usec).freeze }
|
|
37
|
+
|
|
38
|
+
it_should_behave_like 'a generated SQL expression'
|
|
39
|
+
|
|
40
|
+
unless time_iso8601_broken?
|
|
41
|
+
its(:to_s) { should eql("'2010-12-31T23:59:59.000001000Z'") }
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
context 'when the Time is local, and the local time zone is UTC' do
|
|
47
|
+
before :all do
|
|
48
|
+
ENV['TZ'] = 'UTC'
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
context 'and the microseconds are equal to 0' do
|
|
52
|
+
let(:usec) { 0 }
|
|
53
|
+
let(:time) { Time.local(2010, 12, 31, 23, 59, 59, usec).freeze }
|
|
54
|
+
|
|
55
|
+
it_should_behave_like 'a generated SQL expression'
|
|
56
|
+
|
|
57
|
+
its(:to_s) { should eql("'2010-12-31T23:59:59.000000000Z'") }
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
context 'and the microseconds are greater than 0' do
|
|
61
|
+
let(:usec) { 1 }
|
|
62
|
+
let(:time) { Time.local(2010, 12, 31, 23, 59, 59, usec).freeze }
|
|
63
|
+
|
|
64
|
+
it_should_behave_like 'a generated SQL expression'
|
|
65
|
+
|
|
66
|
+
unless time_iso8601_broken?
|
|
67
|
+
its(:to_s) { should eql("'2010-12-31T23:59:59.000001000Z'") }
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
context 'when the Time is local, and the local time zone is not UTC' do
|
|
73
|
+
before :all do
|
|
74
|
+
ENV['TZ'] = 'America/Vancouver'
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
context 'and the microseconds are equal to 0' do
|
|
78
|
+
let(:usec) { 0 }
|
|
79
|
+
let(:time) { Time.local(2010, 12, 31, 15, 59, 59, usec).freeze }
|
|
80
|
+
|
|
81
|
+
it_should_behave_like 'a generated SQL expression'
|
|
82
|
+
|
|
83
|
+
its(:to_s) { should eql("'2010-12-31T23:59:59.000000000Z'") }
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
context 'and the microseconds are greater than 0' do
|
|
87
|
+
let(:usec) { 1 }
|
|
88
|
+
let(:time) { Time.local(2010, 12, 31, 15, 59, 59, usec).freeze }
|
|
89
|
+
|
|
90
|
+
it_should_behave_like 'a generated SQL expression'
|
|
91
|
+
|
|
92
|
+
unless time_iso8601_broken?
|
|
93
|
+
its(:to_s) { should eql("'2010-12-31T23:59:59.000001000Z'") }
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe SQL::Generator::Literal, '#visit_true_class' do
|
|
6
|
+
subject { object.visit_true_class(true) }
|
|
7
|
+
|
|
8
|
+
let(:described_class) { Class.new(SQL::Generator::Visitor) { include SQL::Generator::Literal } }
|
|
9
|
+
let(:object) { described_class.new }
|
|
10
|
+
|
|
11
|
+
it_should_behave_like 'a generated SQL expression'
|
|
12
|
+
|
|
13
|
+
its(:to_s) { should eql('TRUE') }
|
|
14
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe SQL::Generator::Logic, '#visit_veritas_logic_connective_conjunction' do
|
|
6
|
+
subject { object.visit_veritas_logic_connective_conjunction(conjunction) }
|
|
7
|
+
|
|
8
|
+
let(:described_class) { Class.new(SQL::Generator::Visitor) { include SQL::Generator::Logic } }
|
|
9
|
+
let(:attribute) { Attribute::Integer.new(:id) }
|
|
10
|
+
let(:conjunction) { attribute.eq(1).and(attribute.ne(2)) }
|
|
11
|
+
let(:object) { described_class.new }
|
|
12
|
+
|
|
13
|
+
it_should_behave_like 'a generated SQL expression'
|
|
14
|
+
|
|
15
|
+
its(:to_s) { should eql('("id" = 1 AND "id" <> 2)') }
|
|
16
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe SQL::Generator::Logic, '#visit_veritas_logic_connective_disjunction' do
|
|
6
|
+
subject { object.visit_veritas_logic_connective_disjunction(disjunction) }
|
|
7
|
+
|
|
8
|
+
let(:described_class) { Class.new(SQL::Generator::Visitor) { include SQL::Generator::Logic } }
|
|
9
|
+
let(:attribute) { Attribute::Integer.new(:id) }
|
|
10
|
+
let(:disjunction) { attribute.eq(1).or(attribute.eq(2)) }
|
|
11
|
+
let(:object) { described_class.new }
|
|
12
|
+
|
|
13
|
+
it_should_behave_like 'a generated SQL expression'
|
|
14
|
+
|
|
15
|
+
its(:to_s) { should eql('("id" = 1 OR "id" = 2)') }
|
|
16
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe SQL::Generator::Logic, '#visit_veritas_logic_connective_negation' do
|
|
6
|
+
subject { object.visit_veritas_logic_connective_negation(negation) }
|
|
7
|
+
|
|
8
|
+
let(:described_class) { Class.new(SQL::Generator::Visitor) { include SQL::Generator::Logic } }
|
|
9
|
+
let(:attribute) { Attribute::Integer.new(:id) }
|
|
10
|
+
let(:negation) { Logic::Connective::Negation.new(attribute.eq(1)) }
|
|
11
|
+
let(:object) { described_class.new }
|
|
12
|
+
|
|
13
|
+
it_should_behave_like 'a generated SQL expression'
|
|
14
|
+
|
|
15
|
+
its(:to_s) { should eql('NOT "id" = 1') }
|
|
16
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe SQL::Generator::Logic, '#visit_veritas_logic_predicate_equality' do
|
|
6
|
+
subject { object.visit_veritas_logic_predicate_equality(equality) }
|
|
7
|
+
|
|
8
|
+
let(:described_class) { Class.new(SQL::Generator::Visitor) { include SQL::Generator::Logic } }
|
|
9
|
+
let(:attribute) { Attribute::Integer.new(:id) }
|
|
10
|
+
let(:object) { described_class.new }
|
|
11
|
+
|
|
12
|
+
context 'when the right operand is not nil' do
|
|
13
|
+
let(:equality) { attribute.eq(1) }
|
|
14
|
+
|
|
15
|
+
it_should_behave_like 'a generated SQL expression'
|
|
16
|
+
|
|
17
|
+
its(:to_s) { should eql('"id" = 1') }
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
context 'when the right operand is nil' do
|
|
21
|
+
let(:equality) { attribute.eq(nil) }
|
|
22
|
+
|
|
23
|
+
it_should_behave_like 'a generated SQL expression'
|
|
24
|
+
|
|
25
|
+
its(:to_s) { should eql('"id" IS NULL') }
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe SQL::Generator::Logic, '#visit_veritas_logic_predicate_exclusion' do
|
|
6
|
+
subject { object.visit_veritas_logic_predicate_exclusion(exclusion) }
|
|
7
|
+
|
|
8
|
+
let(:described_class) { Class.new(SQL::Generator::Visitor) { include SQL::Generator::Logic } }
|
|
9
|
+
let(:attribute) { Attribute::Integer.new(:id) }
|
|
10
|
+
let(:object) { described_class.new }
|
|
11
|
+
|
|
12
|
+
context 'when right operand is an inclusive Range' do
|
|
13
|
+
let(:exclusion) { attribute.exclude(1..10) }
|
|
14
|
+
|
|
15
|
+
it_should_behave_like 'a generated SQL expression'
|
|
16
|
+
|
|
17
|
+
its(:to_s) { should eql('"id" NOT BETWEEN 1 AND 10') }
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
context 'when right operand is an exclusive Range' do
|
|
21
|
+
let(:exclusion) { attribute.exclude(1...10) }
|
|
22
|
+
|
|
23
|
+
it_should_behave_like 'a generated SQL expression'
|
|
24
|
+
|
|
25
|
+
its(:to_s) { should eql('("id" < 1 OR "id" >= 10)') }
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
context 'when right operand is an Array' do
|
|
29
|
+
let(:exclusion) { attribute.exclude([ 1, 2 ]) }
|
|
30
|
+
|
|
31
|
+
it_should_behave_like 'a generated SQL expression'
|
|
32
|
+
|
|
33
|
+
its(:to_s) { should eql('"id" NOT IN (1, 2)') }
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
context 'when right operand is an empty Array' do
|
|
37
|
+
let(:exclusion) { attribute.exclude([]) }
|
|
38
|
+
|
|
39
|
+
it_should_behave_like 'a generated SQL expression'
|
|
40
|
+
|
|
41
|
+
its(:to_s) { should eql('1 = 1') }
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe SQL::Generator::Logic, '#visit_veritas_logic_predicate_greater_than_or_equal_to' do
|
|
6
|
+
subject { object.visit_veritas_logic_predicate_greater_than_or_equal_to(greater_than_or_equal_to) }
|
|
7
|
+
|
|
8
|
+
let(:described_class) { Class.new(SQL::Generator::Visitor) { include SQL::Generator::Logic } }
|
|
9
|
+
let(:greater_than_or_equal_to) { Attribute::Integer.new(:id).gte(1) }
|
|
10
|
+
let(:object) { described_class.new }
|
|
11
|
+
|
|
12
|
+
it_should_behave_like 'a generated SQL expression'
|
|
13
|
+
|
|
14
|
+
its(:to_s) { should eql('"id" >= 1') }
|
|
15
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe SQL::Generator::Logic, '#visit_veritas_logic_predicate_greater_than' do
|
|
6
|
+
subject { object.visit_veritas_logic_predicate_greater_than(greater_than) }
|
|
7
|
+
|
|
8
|
+
let(:described_class) { Class.new(SQL::Generator::Visitor) { include SQL::Generator::Logic } }
|
|
9
|
+
let(:greater_than) { Attribute::Integer.new(:id).gt(1) }
|
|
10
|
+
let(:object) { described_class.new }
|
|
11
|
+
|
|
12
|
+
it_should_behave_like 'a generated SQL expression'
|
|
13
|
+
|
|
14
|
+
its(:to_s) { should eql('"id" > 1') }
|
|
15
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe SQL::Generator::Logic, '#visit_veritas_logic_predicate_inclusion' do
|
|
6
|
+
subject { object.visit_veritas_logic_predicate_inclusion(inclusion) }
|
|
7
|
+
|
|
8
|
+
let(:described_class) { Class.new(SQL::Generator::Visitor) { include SQL::Generator::Logic } }
|
|
9
|
+
let(:attribute) { Attribute::Integer.new(:id) }
|
|
10
|
+
let(:object) { described_class.new }
|
|
11
|
+
|
|
12
|
+
context 'when right operand is an inclusive Range' do
|
|
13
|
+
let(:inclusion) { attribute.include(1..10) }
|
|
14
|
+
|
|
15
|
+
it_should_behave_like 'a generated SQL expression'
|
|
16
|
+
|
|
17
|
+
its(:to_s) { should eql('"id" BETWEEN 1 AND 10') }
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
context 'when right operand is an exclusive Range' do
|
|
21
|
+
let(:inclusion) { attribute.include(1...10) }
|
|
22
|
+
|
|
23
|
+
it_should_behave_like 'a generated SQL expression'
|
|
24
|
+
|
|
25
|
+
its(:to_s) { should eql('("id" >= 1 AND "id" < 10)') }
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
context 'when right operand is an Array' do
|
|
29
|
+
let(:inclusion) { attribute.include([ 1, 2 ]) }
|
|
30
|
+
|
|
31
|
+
it_should_behave_like 'a generated SQL expression'
|
|
32
|
+
|
|
33
|
+
its(:to_s) { should eql('"id" IN (1, 2)') }
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
context 'when right operand is an empty Array' do
|
|
37
|
+
let(:inclusion) { attribute.include([]) }
|
|
38
|
+
|
|
39
|
+
it_should_behave_like 'a generated SQL expression'
|
|
40
|
+
|
|
41
|
+
its(:to_s) { should eql('1 = 0') }
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe SQL::Generator::Logic, '#visit_veritas_logic_predicate_inequality' do
|
|
6
|
+
subject { object.visit_veritas_logic_predicate_inequality(inequality) }
|
|
7
|
+
|
|
8
|
+
let(:described_class) { Class.new(SQL::Generator::Visitor) { include SQL::Generator::Logic } }
|
|
9
|
+
let(:object) { described_class.new }
|
|
10
|
+
|
|
11
|
+
context 'and the left attribute is optional' do
|
|
12
|
+
let(:attribute) { Attribute::Integer.new(:age, :required => false) }
|
|
13
|
+
let(:inequality) { attribute.ne(1) }
|
|
14
|
+
|
|
15
|
+
it_should_behave_like 'a generated SQL expression'
|
|
16
|
+
|
|
17
|
+
its(:to_s) { should eql('("age" <> 1 OR "age" IS NULL)') }
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
context 'and the right attribute is optional' do
|
|
21
|
+
let(:attribute) { Attribute::Integer.new(:age, :required => false) }
|
|
22
|
+
let(:inequality) { Logic::Predicate::Inequality.new(1, attribute) }
|
|
23
|
+
|
|
24
|
+
it_should_behave_like 'a generated SQL expression'
|
|
25
|
+
|
|
26
|
+
its(:to_s) { should eql('(1 <> "age" OR "age" IS NULL)') }
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
context 'and the left is a value' do
|
|
30
|
+
let(:attribute) { Attribute::Integer.new(:id) }
|
|
31
|
+
let(:inequality) { Logic::Predicate::Inequality.new(1, attribute) }
|
|
32
|
+
|
|
33
|
+
it_should_behave_like 'a generated SQL expression'
|
|
34
|
+
|
|
35
|
+
its(:to_s) { should eql('1 <> "id"') }
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
context 'and the right is a value' do
|
|
39
|
+
let(:attribute) { Attribute::Integer.new(:id) }
|
|
40
|
+
let(:inequality) { attribute.ne(1) }
|
|
41
|
+
|
|
42
|
+
it_should_behave_like 'a generated SQL expression'
|
|
43
|
+
|
|
44
|
+
its(:to_s) { should eql('"id" <> 1') }
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
context 'and the right is a nil value' do
|
|
48
|
+
let(:attribute) { Attribute::Integer.new(:id) }
|
|
49
|
+
let(:inequality) { attribute.ne(nil) }
|
|
50
|
+
|
|
51
|
+
it_should_behave_like 'a generated SQL expression'
|
|
52
|
+
|
|
53
|
+
its(:to_s) { should eql('"id" IS NOT NULL') }
|
|
54
|
+
end
|
|
55
|
+
end
|