axiom-sql-generator 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gemtest +0 -0
- data/.gitignore +37 -0
- data/.rspec +4 -0
- data/.rvmrc +1 -0
- data/.travis.yml +35 -0
- data/CONTRIBUTING.md +11 -0
- data/Gemfile +8 -0
- data/Gemfile.devtools +57 -0
- data/Guardfile +23 -0
- data/LICENSE +20 -0
- data/README.md +70 -0
- data/Rakefile +5 -0
- data/TODO +34 -0
- data/axiom-sql-generator.gemspec +25 -0
- data/config/flay.yml +3 -0
- data/config/flog.yml +2 -0
- data/config/mutant.yml +3 -0
- data/config/reek.yml +165 -0
- data/config/yardstick.yml +2 -0
- data/lib/axiom-sql-generator.rb +3 -0
- data/lib/axiom/sql/generator.rb +61 -0
- data/lib/axiom/sql/generator/attribute.rb +25 -0
- data/lib/axiom/sql/generator/core_ext/date.rb +20 -0
- data/lib/axiom/sql/generator/core_ext/date_time.rb +46 -0
- data/lib/axiom/sql/generator/direction.rb +38 -0
- data/lib/axiom/sql/generator/function.rb +55 -0
- data/lib/axiom/sql/generator/function/aggregate.rb +134 -0
- data/lib/axiom/sql/generator/function/connective.rb +53 -0
- data/lib/axiom/sql/generator/function/numeric.rb +135 -0
- data/lib/axiom/sql/generator/function/predicate.rb +266 -0
- data/lib/axiom/sql/generator/function/proposition.rb +38 -0
- data/lib/axiom/sql/generator/function/string.rb +29 -0
- data/lib/axiom/sql/generator/identifier.rb +28 -0
- data/lib/axiom/sql/generator/literal.rb +157 -0
- data/lib/axiom/sql/generator/relation.rb +240 -0
- data/lib/axiom/sql/generator/relation/base.rb +14 -0
- data/lib/axiom/sql/generator/relation/binary.rb +136 -0
- data/lib/axiom/sql/generator/relation/insertion.rb +62 -0
- data/lib/axiom/sql/generator/relation/materialized.rb +60 -0
- data/lib/axiom/sql/generator/relation/set.rb +107 -0
- data/lib/axiom/sql/generator/relation/unary.rb +379 -0
- data/lib/axiom/sql/generator/version.rb +12 -0
- data/lib/axiom/sql/generator/visitor.rb +121 -0
- data/spec/rcov.opts +7 -0
- data/spec/shared/generated_sql_behavior.rb +15 -0
- data/spec/spec_helper.rb +33 -0
- data/spec/support/config_alias.rb +3 -0
- data/spec/unit/axiom/sql/generator/attribute/visit_axiom_attribute_spec.rb +15 -0
- data/spec/unit/axiom/sql/generator/class_methods/parenthesize_spec.rb +18 -0
- data/spec/unit/axiom/sql/generator/direction/visit_axiom_relation_operation_order_ascending_spec.rb +15 -0
- data/spec/unit/axiom/sql/generator/direction/visit_axiom_relation_operation_order_descending_spec.rb +15 -0
- data/spec/unit/axiom/sql/generator/function/aggregate/visit_axiom_aggregate_count_spec.rb +16 -0
- data/spec/unit/axiom/sql/generator/function/aggregate/visit_axiom_aggregate_maximum_spec.rb +16 -0
- data/spec/unit/axiom/sql/generator/function/aggregate/visit_axiom_aggregate_mean_spec.rb +16 -0
- data/spec/unit/axiom/sql/generator/function/aggregate/visit_axiom_aggregate_minimum_spec.rb +16 -0
- data/spec/unit/axiom/sql/generator/function/aggregate/visit_axiom_aggregate_standard_deviation_spec.rb +16 -0
- data/spec/unit/axiom/sql/generator/function/aggregate/visit_axiom_aggregate_sum_spec.rb +16 -0
- data/spec/unit/axiom/sql/generator/function/aggregate/visit_axiom_aggregate_variance_spec.rb +16 -0
- data/spec/unit/axiom/sql/generator/function/connective/visit_axiom_function_connective_conjunction_spec.rb +20 -0
- data/spec/unit/axiom/sql/generator/function/connective/visit_axiom_function_connective_disjunction_spec.rb +20 -0
- data/spec/unit/axiom/sql/generator/function/connective/visit_axiom_function_connective_negation_spec.rb +20 -0
- data/spec/unit/axiom/sql/generator/function/numeric/visit_axiom_function_numeric_absolute_spec.rb +15 -0
- data/spec/unit/axiom/sql/generator/function/numeric/visit_axiom_function_numeric_addition_spec.rb +15 -0
- data/spec/unit/axiom/sql/generator/function/numeric/visit_axiom_function_numeric_division_spec.rb +15 -0
- data/spec/unit/axiom/sql/generator/function/numeric/visit_axiom_function_numeric_exponentiation_spec.rb +15 -0
- data/spec/unit/axiom/sql/generator/function/numeric/visit_axiom_function_numeric_modulo_spec.rb +15 -0
- data/spec/unit/axiom/sql/generator/function/numeric/visit_axiom_function_numeric_multiplication_spec.rb +15 -0
- data/spec/unit/axiom/sql/generator/function/numeric/visit_axiom_function_numeric_square_root_spec.rb +15 -0
- data/spec/unit/axiom/sql/generator/function/numeric/visit_axiom_function_numeric_subtraction_spec.rb +15 -0
- data/spec/unit/axiom/sql/generator/function/numeric/visit_axiom_function_numeric_unary_minus_spec.rb +15 -0
- data/spec/unit/axiom/sql/generator/function/numeric/visit_axiom_function_numeric_unary_plus_spec.rb +15 -0
- data/spec/unit/axiom/sql/generator/function/predicate/visit_axiom_function_predicate_equality_spec.rb +27 -0
- data/spec/unit/axiom/sql/generator/function/predicate/visit_axiom_function_predicate_exclusion_spec.rb +47 -0
- data/spec/unit/axiom/sql/generator/function/predicate/visit_axiom_function_predicate_greater_than_or_equal_to_spec.rb +15 -0
- data/spec/unit/axiom/sql/generator/function/predicate/visit_axiom_function_predicate_greater_than_spec.rb +15 -0
- data/spec/unit/axiom/sql/generator/function/predicate/visit_axiom_function_predicate_inclusion_spec.rb +47 -0
- data/spec/unit/axiom/sql/generator/function/predicate/visit_axiom_function_predicate_inequality_spec.rb +55 -0
- data/spec/unit/axiom/sql/generator/function/predicate/visit_axiom_function_predicate_less_than_or_equal_to_spec.rb +15 -0
- data/spec/unit/axiom/sql/generator/function/predicate/visit_axiom_function_predicate_less_than_spec.rb +15 -0
- data/spec/unit/axiom/sql/generator/function/proposition/visit_axiom_function_proposition_contradiction_spec.rb +15 -0
- data/spec/unit/axiom/sql/generator/function/proposition/visit_axiom_function_proposition_tautology_spec.rb +15 -0
- data/spec/unit/axiom/sql/generator/function/string/visit_axiom_function_string_length_spec.rb +15 -0
- data/spec/unit/axiom/sql/generator/identifier/visit_identifier_spec.rb +26 -0
- data/spec/unit/axiom/sql/generator/literal/class_methods/dup_frozen_spec.rb +23 -0
- data/spec/unit/axiom/sql/generator/literal/visit_class_spec.rb +31 -0
- data/spec/unit/axiom/sql/generator/literal/visit_date_spec.rb +15 -0
- data/spec/unit/axiom/sql/generator/literal/visit_date_time_spec.rb +55 -0
- data/spec/unit/axiom/sql/generator/literal/visit_enumerable_spec.rb +15 -0
- data/spec/unit/axiom/sql/generator/literal/visit_false_class_spec.rb +14 -0
- data/spec/unit/axiom/sql/generator/literal/visit_nil_class_spec.rb +14 -0
- data/spec/unit/axiom/sql/generator/literal/visit_numeric_spec.rb +34 -0
- data/spec/unit/axiom/sql/generator/literal/visit_string_spec.rb +26 -0
- data/spec/unit/axiom/sql/generator/literal/visit_time_spec.rb +97 -0
- data/spec/unit/axiom/sql/generator/literal/visit_true_class_spec.rb +14 -0
- data/spec/unit/axiom/sql/generator/relation/binary/base/to_subquery_spec.rb +35 -0
- data/spec/unit/axiom/sql/generator/relation/binary/base/visit_axiom_relation_base_spec.rb +22 -0
- data/spec/unit/axiom/sql/generator/relation/binary/to_s_spec.rb +35 -0
- data/spec/unit/axiom/sql/generator/relation/binary/to_subquery_spec.rb +35 -0
- data/spec/unit/axiom/sql/generator/relation/binary/visit_axiom_algebra_join_spec.rb +179 -0
- data/spec/unit/axiom/sql/generator/relation/binary/visit_axiom_algebra_product_spec.rb +183 -0
- data/spec/unit/axiom/sql/generator/relation/class_methods/visit_spec.rb +71 -0
- data/spec/unit/axiom/sql/generator/relation/insertion/to_subquery_spec.rb +15 -0
- data/spec/unit/axiom/sql/generator/relation/insertion/visit_axiom_relation_operation_insertion_spec.rb +187 -0
- data/spec/unit/axiom/sql/generator/relation/materialized/visit_axiom_relation_materialized_spec.rb +28 -0
- data/spec/unit/axiom/sql/generator/relation/materialized/visited_spec.rb +26 -0
- data/spec/unit/axiom/sql/generator/relation/name_spec.rb +30 -0
- data/spec/unit/axiom/sql/generator/relation/set/class_methods/normalize_operand_headers_spec.rb +35 -0
- data/spec/unit/axiom/sql/generator/relation/set/to_s_spec.rb +55 -0
- data/spec/unit/axiom/sql/generator/relation/set/to_subquery_spec.rb +55 -0
- data/spec/unit/axiom/sql/generator/relation/set/visit_axiom_algebra_difference_spec.rb +191 -0
- data/spec/unit/axiom/sql/generator/relation/set/visit_axiom_algebra_intersection_spec.rb +188 -0
- data/spec/unit/axiom/sql/generator/relation/set/visit_axiom_algebra_union_spec.rb +188 -0
- data/spec/unit/axiom/sql/generator/relation/to_s_spec.rb +50 -0
- data/spec/unit/axiom/sql/generator/relation/to_sql_spec.rb +52 -0
- data/spec/unit/axiom/sql/generator/relation/to_subquery_spec.rb +49 -0
- data/spec/unit/axiom/sql/generator/relation/unary/to_s_spec.rb +55 -0
- data/spec/unit/axiom/sql/generator/relation/unary/to_subquery_spec.rb +75 -0
- data/spec/unit/axiom/sql/generator/relation/unary/visit_axiom_algebra_extension_spec.rb +165 -0
- data/spec/unit/axiom/sql/generator/relation/unary/visit_axiom_algebra_projection_spec.rb +193 -0
- data/spec/unit/axiom/sql/generator/relation/unary/visit_axiom_algebra_rename_spec.rb +178 -0
- data/spec/unit/axiom/sql/generator/relation/unary/visit_axiom_algebra_restriction_spec.rb +199 -0
- data/spec/unit/axiom/sql/generator/relation/unary/visit_axiom_algebra_summarization_spec.rb +652 -0
- data/spec/unit/axiom/sql/generator/relation/unary/visit_axiom_relation_base_spec.rb +21 -0
- data/spec/unit/axiom/sql/generator/relation/unary/visit_axiom_relation_operation_limit_spec.rb +165 -0
- data/spec/unit/axiom/sql/generator/relation/unary/visit_axiom_relation_operation_offset_spec.rb +165 -0
- data/spec/unit/axiom/sql/generator/relation/unary/visit_axiom_relation_operation_order_spec.rb +183 -0
- data/spec/unit/axiom/sql/generator/relation/unary/visit_axiom_relation_operation_reverse_spec.rb +165 -0
- data/spec/unit/axiom/sql/generator/relation/visit_spec.rb +54 -0
- data/spec/unit/axiom/sql/generator/relation/visited_spec.rb +35 -0
- data/spec/unit/axiom/sql/generator/visitor/class_methods/handler_for_spec.rb +71 -0
- data/spec/unit/axiom/sql/generator/visitor/visit_spec.rb +12 -0
- data/spec/unit/axiom/sql/generator/visitor/visited_spec.rb +11 -0
- data/spec/unit/date/iso8601_spec.rb +23 -0
- data/spec/unit/date_time/iso8601_spec.rb +112 -0
- metadata +325 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe SQL::Generator::Function::String, '#visit_axiom_function_string_length' do
|
|
6
|
+
subject { object.visit_axiom_function_string_length(length) }
|
|
7
|
+
|
|
8
|
+
let(:described_class) { Class.new(SQL::Generator::Visitor) { include SQL::Generator::Function::String } }
|
|
9
|
+
let(:length) { Attribute::String.new(:name).length }
|
|
10
|
+
let(:object) { described_class.new }
|
|
11
|
+
|
|
12
|
+
it_should_behave_like 'a generated SQL expression'
|
|
13
|
+
|
|
14
|
+
its(:to_s) { should eql('LENGTH ("name")') }
|
|
15
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe SQL::Generator::Identifier, '#visit_identifier' do
|
|
6
|
+
subject { object.visit_identifier(identifier) }
|
|
7
|
+
|
|
8
|
+
let(:described_class) { Class.new(SQL::Generator::Visitor) { include SQL::Generator::Identifier } }
|
|
9
|
+
let(:object) { described_class.new }
|
|
10
|
+
|
|
11
|
+
context 'with an identifier containing no quotes' do
|
|
12
|
+
let(:identifier) { 'users' }
|
|
13
|
+
|
|
14
|
+
it_should_behave_like 'a generated SQL expression'
|
|
15
|
+
|
|
16
|
+
its(:to_s) { should eql('"users"') }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
context 'with an identifier containing quotes' do
|
|
20
|
+
let(:identifier) { 'users"name' }
|
|
21
|
+
|
|
22
|
+
it_should_behave_like 'a generated SQL expression'
|
|
23
|
+
|
|
24
|
+
its(:to_s) { should eql('"users""name"') }
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe SQL::Generator::Literal, '.dup_frozen' do
|
|
6
|
+
subject { object.dup_frozen(object_arg) }
|
|
7
|
+
|
|
8
|
+
let(:object) { SQL::Generator::Literal }
|
|
9
|
+
|
|
10
|
+
context 'with a frozen object' do
|
|
11
|
+
let(:object_arg) { Time.now.freeze }
|
|
12
|
+
|
|
13
|
+
it { should_not equal(object_arg) }
|
|
14
|
+
|
|
15
|
+
it { should == object_arg }
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
context 'with a non-frozen object' do
|
|
19
|
+
let(:object_arg) { Time.now }
|
|
20
|
+
|
|
21
|
+
it { should equal(object_arg) }
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe SQL::Generator::Literal, '#visit_class' do
|
|
6
|
+
subject { object.visit_class(klass) }
|
|
7
|
+
|
|
8
|
+
let(:described_class) { Class.new(SQL::Generator::Visitor) { include SQL::Generator::Literal } }
|
|
9
|
+
let(:object) { described_class.new }
|
|
10
|
+
|
|
11
|
+
before do
|
|
12
|
+
Object.class_eval { remove_const(:NamedClass) if const_defined?(:NamedClass) }
|
|
13
|
+
class ::NamedClass; end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
context 'with a named class' do
|
|
17
|
+
let(:klass) { NamedClass.freeze }
|
|
18
|
+
|
|
19
|
+
it_should_behave_like 'a generated SQL expression'
|
|
20
|
+
|
|
21
|
+
its(:to_s) { should eql("'NamedClass'") }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
context 'with an anonymous class' do
|
|
25
|
+
let(:klass) { described_class }
|
|
26
|
+
|
|
27
|
+
it_should_behave_like 'a generated SQL expression'
|
|
28
|
+
|
|
29
|
+
its(:to_s) { should eql('NULL') }
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe SQL::Generator::Literal, '#visit_date' do
|
|
6
|
+
subject { object.visit_date(date) }
|
|
7
|
+
|
|
8
|
+
let(:described_class) { Class.new(SQL::Generator::Visitor) { include SQL::Generator::Literal } }
|
|
9
|
+
let(:date) { Date.new(2010, 12, 31).freeze }
|
|
10
|
+
let(:object) { described_class.new }
|
|
11
|
+
|
|
12
|
+
it_should_behave_like 'a generated SQL expression'
|
|
13
|
+
|
|
14
|
+
its(:to_s) { should eql("'2010-12-31'") }
|
|
15
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe SQL::Generator::Literal, '#visit_date_time' do
|
|
6
|
+
subject { object.visit_date_time(date_time) }
|
|
7
|
+
|
|
8
|
+
let(:described_class) { Class.new(SQL::Generator::Visitor) { include SQL::Generator::Literal } }
|
|
9
|
+
let(:nsec_in_seconds) { Rational(nsec, 10**9) }
|
|
10
|
+
let(:object) { described_class.new }
|
|
11
|
+
|
|
12
|
+
context 'when the DateTime is UTC' do
|
|
13
|
+
let(:offset) { 0 }
|
|
14
|
+
|
|
15
|
+
context 'and the nanoseconds are equal to 0' do
|
|
16
|
+
let(:nsec) { 0 }
|
|
17
|
+
let(:date_time) { DateTime.new(2010, 12, 31, 23, 59, 59 + nsec_in_seconds, offset).freeze }
|
|
18
|
+
|
|
19
|
+
it_should_behave_like 'a generated SQL expression'
|
|
20
|
+
|
|
21
|
+
its(:to_s) { should eql("'2010-12-31T23:59:59.000000000+00:00'") }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
context 'and the nanoseconds are greater than 0' do
|
|
25
|
+
let(:nsec) { 1 }
|
|
26
|
+
let(:date_time) { DateTime.new(2010, 12, 31, 23, 59, 59 + nsec_in_seconds, offset).freeze }
|
|
27
|
+
|
|
28
|
+
it_should_behave_like 'a generated SQL expression'
|
|
29
|
+
|
|
30
|
+
its(:to_s) { should eql("'2010-12-31T23:59:59.000000001+00:00'") }
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
context 'when the DateTime is not UTC' do
|
|
35
|
+
let(:offset) { Rational(-8, 24) }
|
|
36
|
+
|
|
37
|
+
context 'and the nanoseconds are equal to 0' do
|
|
38
|
+
let(:nsec) { 0 }
|
|
39
|
+
let(:date_time) { DateTime.new(2010, 12, 31, 15, 59, 59 + nsec_in_seconds, offset).freeze }
|
|
40
|
+
|
|
41
|
+
it_should_behave_like 'a generated SQL expression'
|
|
42
|
+
|
|
43
|
+
its(:to_s) { should eql("'2010-12-31T23:59:59.000000000+00:00'") }
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
context 'and the nanoseconds are greater than 0' do
|
|
47
|
+
let(:nsec) { 1 }
|
|
48
|
+
let(:date_time) { DateTime.new(2010, 12, 31, 15, 59, 59 + nsec_in_seconds, offset).freeze }
|
|
49
|
+
|
|
50
|
+
it_should_behave_like 'a generated SQL expression'
|
|
51
|
+
|
|
52
|
+
its(:to_s) { should eql("'2010-12-31T23:59:59.000000001+00:00'") }
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -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.7.0.dev when fractional seconds are not 0
|
|
9
|
+
def self.time_iso8601_broken?
|
|
10
|
+
RUBY_PLATFORM.include?('java') && JRUBY_VERSION <= '1.7.0.dev' && 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,35 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe SQL::Generator::Relation::Binary::Base, '#to_subquery' do
|
|
6
|
+
subject { object.to_subquery }
|
|
7
|
+
|
|
8
|
+
let(:id) { Attribute::Integer.new(:id) }
|
|
9
|
+
let(:name) { Attribute::String.new(:name) }
|
|
10
|
+
let(:age) { Attribute::Integer.new(:age, :required => false) }
|
|
11
|
+
let(:header) { [ id, name, age ] }
|
|
12
|
+
let(:body) { [ [ 1, 'Dan Kubb', 35 ] ].each }
|
|
13
|
+
let(:base_relation) { Relation::Base.new('users', header, body) }
|
|
14
|
+
let(:object) { described_class.new }
|
|
15
|
+
|
|
16
|
+
context 'when no object visited' do
|
|
17
|
+
it_should_behave_like 'an idempotent method'
|
|
18
|
+
|
|
19
|
+
it { should respond_to(:to_s) }
|
|
20
|
+
|
|
21
|
+
it { should be_frozen }
|
|
22
|
+
|
|
23
|
+
its(:to_s) { should == '' }
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
context 'when a base relation is visited' do
|
|
27
|
+
before do
|
|
28
|
+
object.visit(base_relation)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it_should_behave_like 'a generated SQL expression'
|
|
32
|
+
|
|
33
|
+
its(:to_s) { should eql('"users"') }
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe SQL::Generator::Relation::Binary::Base, '#visit_axiom_relation_base' do
|
|
6
|
+
subject { object.visit_axiom_relation_base(base_relation) }
|
|
7
|
+
|
|
8
|
+
let(:relation_name) { 'users' }
|
|
9
|
+
let(:id) { Attribute::Integer.new(:id) }
|
|
10
|
+
let(:name) { Attribute::String.new(:name) }
|
|
11
|
+
let(:age) { Attribute::Integer.new(:age, :required => false) }
|
|
12
|
+
let(:header) { [ id, name, age ] }
|
|
13
|
+
let(:body) { [ [ 1, 'Dan Kubb', 35 ] ].each }
|
|
14
|
+
let(:base_relation) { Relation::Base.new(relation_name, header, body) }
|
|
15
|
+
let(:object) { described_class.new }
|
|
16
|
+
|
|
17
|
+
it_should_behave_like 'a generated SQL SELECT query'
|
|
18
|
+
|
|
19
|
+
its(:name) { should eql('users') }
|
|
20
|
+
|
|
21
|
+
its(:to_subquery) { should eql('"users"') }
|
|
22
|
+
end
|