ddl_parser 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,100 +1,111 @@
1
- require_relative '../../../spec/spec_helper'
2
- require_relative '../../../lib/ddl_parser/translator/column'
3
-
4
- describe 'DDLParser::Translator::Column' do
5
-
6
- let(:int_column) {
7
- DDLParser::Translator::Column.new({:field=> 'int_field', :data_type=> 'int', :options=> ''})
8
- }
9
-
10
- let(:char_column) {
11
- DDLParser::Translator::Column.new(
12
- {:field=> 'char_field',
13
- :data_type=>{:char=>{:length=>{:integer=> '4'}}},
14
- :options=> [{:default_clause=>[{:string => "'foobar'"}]}]}
15
- )
16
- }
17
-
18
- let(:decimal_column) {
19
- DDLParser::Translator::Column.new(
20
- {:field=> 'decimal_field',
21
- :data_type=>{:decimal=>{:precision=>{:total=>{:integer=> '15'}, :scale=>{:integer=> '2'}}}},
22
- :options=>[{:column_option=> 'not null'}, {:default_clause=>[{:integer=> '0'}]}]
23
- })
24
- }
25
-
26
- let(:decimal_no_scale_column) {
27
- DDLParser::Translator::Column.new(
28
- {:field=> 'decimal_field',
29
- :data_type=>{:decimal=>{:precision=>{:total=>{:integer=> '15'}}}},
30
- :options=>[{:column_option=> 'not null'}, {:default_clause=>[{:integer=> '0'}]}]
31
- })
32
- }
33
-
34
- let(:decimal_no_precision_column) {
35
- DDLParser::Translator::Column.new(
36
- {:field=> 'decimal_field',
37
- :data_type=>{:decimal=>"decimal"},
38
- :options=>[{:column_option=> 'not null'}, {:default_clause=>[{:integer=> '0'}]}]
39
- })
40
- }
41
-
42
- it 'must receive hash' do
43
- DDLParser::Translator::Column.new('').to_hash.should == {}
44
- DDLParser::Translator::Column.new({:foo => :bar}).to_hash.should == {:foo => :bar}
45
- end
46
-
47
- it 'should return name' do
48
- int_column.name.should == 'int_field'
49
- char_column.name.should == 'char_field'
50
- decimal_column.name.should == 'decimal_field'
51
- end
52
-
53
- it 'should return data_type' do
54
- int_column.data_type.should == :int
55
- char_column.data_type.should == :char
56
- decimal_column.data_type.should == :decimal
57
- end
58
-
59
- it 'should return length' do
60
- int_column.length.should == nil
61
- char_column.length.should == 4
62
- decimal_column.length.should == 15.2
63
- end
64
-
65
- it 'should return precision' do
66
- int_column.precision.should == nil
67
- char_column.precision.should == nil
68
- decimal_column.precision.should == 15
69
- decimal_no_scale_column.precision.should == 15
70
- decimal_no_precision_column.precision.should == 5
71
- end
72
-
73
- it 'should return scale' do
74
- int_column.scale.should == nil
75
- char_column.scale.should == nil
76
- decimal_column.scale.should == 2
77
- decimal_no_scale_column.scale.should == 0
78
- decimal_no_precision_column.scale.should == 0
79
- end
80
-
81
- it 'should return options' do
82
- int_column.options.should == nil
83
- char_column.options.should == [{:default_clause=>[{:string =>"'foobar'"}]}]
84
- decimal_column.options.should == [{:column_option=> 'not null'}, {:default_clause=>[{:integer=> '0'}]}]
85
- end
86
-
87
- it 'should return not null' do
88
- int_column.not_null.should == false
89
- char_column.not_null.should == false
90
- decimal_column.not_null.should == true
91
- end
92
-
93
- it 'should return default clause' do
94
- int_column.default_clause.should == nil
95
- char_column.default_clause.should == "'foobar'"
96
- decimal_column.default_clause.should == 0
97
- end
98
-
99
-
1
+ require_relative '../../../spec/spec_helper'
2
+ require_relative '../../../lib/ddl_parser/translator/column'
3
+
4
+ describe 'DDLParser::Translator::Column' do
5
+
6
+ let(:unique_no_column) {
7
+ DDLParser::Translator::Column.new({:field=> 'unique_no', :data_type=> 'integer', :options=>[{:column_option=> 'identity'}, {:identity=>{:start_value=>{:integer=> '1'}, :increment_value=>{:integer=> '1'}, :cache_value=>{:integer=> '20'}}}]})
8
+ }
9
+
10
+ let(:int_column) {
11
+ DDLParser::Translator::Column.new({:field=> 'int_field', :data_type=> 'int', :options=> ''})
12
+ }
13
+
14
+ let(:char_column) {
15
+ DDLParser::Translator::Column.new(
16
+ {:field=> 'char_field',
17
+ :data_type=>{:char=>{:length=>{:integer=> '4'}}},
18
+ :options=> [{:default_clause=>[{:string => "'foobar'"}]}]}
19
+ )
20
+ }
21
+
22
+ let(:decimal_column) {
23
+ DDLParser::Translator::Column.new(
24
+ {:field=> 'decimal_field',
25
+ :data_type=>{:decimal=>{:precision=>{:total=>{:integer=> '15'}, :scale=>{:integer=> '2'}}}},
26
+ :options=>[{:column_option=> 'not null'}, {:default_clause=>[{:integer=> '0'}]}]
27
+ })
28
+ }
29
+
30
+ let(:decimal_no_scale_column) {
31
+ DDLParser::Translator::Column.new(
32
+ {:field=> 'decimal_field',
33
+ :data_type=>{:decimal=>{:precision=>{:total=>{:integer=> '15'}}}},
34
+ :options=>[{:column_option=> 'not null'}, {:default_clause=>[{:integer=> '0'}]}]
35
+ })
36
+ }
37
+
38
+ let(:decimal_no_precision_column) {
39
+ DDLParser::Translator::Column.new(
40
+ {:field=> 'decimal_field',
41
+ :data_type=>{:decimal=>"decimal"},
42
+ :options=>[{:column_option=> 'not null'}, {:default_clause=>[{:integer=> '0'}]}]
43
+ })
44
+ }
45
+
46
+ it 'must receive hash' do
47
+ DDLParser::Translator::Column.new('').to_hash.should == {}
48
+ DDLParser::Translator::Column.new({:foo => :bar}).to_hash.should == {:foo => :bar}
49
+ end
50
+
51
+ it 'should return name' do
52
+ int_column.name.should == 'int_field'
53
+ char_column.name.should == 'char_field'
54
+ decimal_column.name.should == 'decimal_field'
55
+ end
56
+
57
+ it 'should return data_type' do
58
+ int_column.data_type.should == :int
59
+ char_column.data_type.should == :char
60
+ decimal_column.data_type.should == :decimal
61
+ end
62
+
63
+ it 'should return length' do
64
+ int_column.length.should == nil
65
+ char_column.length.should == 4
66
+ decimal_column.length.should == 15.2
67
+ end
68
+
69
+ it 'should return precision' do
70
+ int_column.precision.should == nil
71
+ char_column.precision.should == nil
72
+ decimal_column.precision.should == 15
73
+ decimal_no_scale_column.precision.should == 15
74
+ decimal_no_precision_column.precision.should == 5
75
+ end
76
+
77
+ it 'should return scale' do
78
+ int_column.scale.should == nil
79
+ char_column.scale.should == nil
80
+ decimal_column.scale.should == 2
81
+ decimal_no_scale_column.scale.should == 0
82
+ decimal_no_precision_column.scale.should == 0
83
+ end
84
+
85
+ it 'should return options' do
86
+ int_column.options.should == nil
87
+ char_column.options.should == [{:default_clause=>[{:string =>"'foobar'"}]}]
88
+ decimal_column.options.should == [{:column_option=> 'not null'}, {:default_clause=>[{:integer=> '0'}]}]
89
+ end
90
+
91
+ it 'should return not null' do
92
+ int_column.not_null.should == false
93
+ char_column.not_null.should == false
94
+ decimal_column.not_null.should == true
95
+ end
96
+
97
+ it 'should return default clause' do
98
+ int_column.default_clause.should == nil
99
+ char_column.default_clause.should == "'foobar'"
100
+ decimal_column.default_clause.should == 0
101
+ end
102
+
103
+ it 'should return identity flag' do
104
+ unique_no_column.identity?.should == true
105
+ end
106
+
107
+ it 'should return start value for identity' do
108
+ unique_no_column.start_value?.should == 1
109
+ end
110
+
100
111
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ddl_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-07-15 00:00:00.000000000 Z
12
+ date: 2014-09-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: parslet
@@ -88,6 +88,7 @@ files:
88
88
  - LICENSE.txt
89
89
  - README.md
90
90
  - Rakefile
91
+ - Vagrantfile
91
92
  - ddl_parser.gemspec
92
93
  - lib/ddl_parser.rb
93
94
  - lib/ddl_parser/ddl.rb