table_maker 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -10,6 +10,7 @@ group :development do
10
10
  gem "bundler", "~> 1.0.0"
11
11
  gem "jeweler", "~> 1.5.2"
12
12
  gem "rcov", ">= 0"
13
+ gem "test-unit"
13
14
 
14
15
  if RUBY_PLATFORM == 'java'
15
16
  gem 'jdbc-sqlite3'
@@ -11,6 +11,7 @@ GEM
11
11
  rcov (0.9.9-java)
12
12
  sequel (3.20.0)
13
13
  sqlite3 (1.3.3)
14
+ test-unit (2.2.0)
14
15
 
15
16
  PLATFORMS
16
17
  java
@@ -22,3 +23,4 @@ DEPENDENCIES
22
23
  rcov
23
24
  sequel
24
25
  sqlite3
26
+ test-unit
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -7,6 +7,7 @@ class TableMaker
7
7
  @column_info = []
8
8
  @column_names = []
9
9
  @data = []
10
+ @has_primary_key = false
10
11
  parse_layout(layout)
11
12
  create_table
12
13
  import_data
@@ -27,7 +28,12 @@ class TableMaker
27
28
  md = str.match(/(\w+)\((\w+)\)/)
28
29
  name = md[1].to_sym
29
30
  type = Object.module_eval("::#{md[2]}", __FILE__, __LINE__)
30
- @column_info << { :name => name, :type => type }
31
+ opts = { :name => name, :type => type }
32
+ if name == :id
33
+ opts[:primary_key] = true
34
+ @has_primary_key = true
35
+ end
36
+ @column_info << opts
31
37
  @column_names << name
32
38
  end
33
39
  else
@@ -38,8 +44,11 @@ class TableMaker
38
44
 
39
45
  def create_table
40
46
  column_info = @column_info
47
+ has_primary_key = @has_primary_key
41
48
  @db.create_table(@table_name) do
42
- primary_key :id
49
+ if !has_primary_key
50
+ primary_key :id
51
+ end
43
52
  @columns = column_info
44
53
  end
45
54
  end
@@ -29,7 +29,7 @@ class TestTableMaker < Test::Unit::TestCase
29
29
  assert_equal expected, ds.select(:id, :foo, :bar, :baz).order(:id).all
30
30
  end
31
31
 
32
- def test_manually_specified_id
32
+ def test_manually_specified_integer_id
33
33
  db = Sequel.connect("#{RUBY_PLATFORM == 'java' ? "jdbc:" : ""}sqlite::memory:")
34
34
  TableMaker.new(db, :foo, <<-EOF)
35
35
  +-------------+-------------+-------------+--------------+
@@ -49,6 +49,30 @@ class TestTableMaker < Test::Unit::TestCase
49
49
  {:id => 73, :foo => 'mno', :bar => 'pqr', :baz => 789}
50
50
  ]
51
51
  assert_equal expected, ds.select(:id, :foo, :bar, :baz).order(:id).all
52
+ assert db.schema(:foo).assoc(:id)[1][:primary_key]
53
+ end
54
+
55
+ def test_manually_specified_string_id
56
+ db = Sequel.connect("#{RUBY_PLATFORM == 'java' ? "jdbc:" : ""}sqlite::memory:")
57
+ TableMaker.new(db, :foo, <<-EOF)
58
+ +------------+-------------+-------------+--------------+
59
+ | id(String) | foo(String) | bar(String) | baz(Integer) |
60
+ +============+=============+=============+==============+
61
+ | abc | abc | def | 123 |
62
+ | 123 | ghi | jkl | 456 |
63
+ | do re | mno | pqr | 789 |
64
+ | mi | stu | vwx | 000 |
65
+ +-------------+-------------+-------------+--------------+
66
+ EOF
67
+ ds = db[:foo]
68
+ expected = [
69
+ {:id => '123', :foo => 'ghi', :bar => 'jkl', :baz => 456},
70
+ {:id => 'abc', :foo => 'abc', :bar => 'def', :baz => 123},
71
+ {:id => 'do re', :foo => 'mno', :bar => 'pqr', :baz => 789},
72
+ {:id => 'mi', :foo => 'stu', :bar => 'vwx', :baz => 000}
73
+ ]
74
+ assert_equal expected, ds.select(:id, :foo, :bar, :baz).order(:id).all
75
+ assert db.schema(:foo).assoc(:id)[1][:primary_key]
52
76
  end
53
77
 
54
78
  def test_blank_cells_are_null
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: table_maker
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 1
9
- version: 0.0.1
4
+ prerelease:
5
+ version: 0.0.2
10
6
  platform: ruby
11
7
  authors:
12
8
  - Jeremy Stephens
@@ -14,7 +10,7 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2011-03-01 00:00:00 -06:00
13
+ date: 2011-03-15 00:00:00 -05:00
18
14
  default_executable:
19
15
  dependencies:
20
16
  - !ruby/object:Gem::Dependency
@@ -24,8 +20,6 @@ dependencies:
24
20
  requirements:
25
21
  - - ">="
26
22
  - !ruby/object:Gem::Version
27
- segments:
28
- - 0
29
23
  version: "0"
30
24
  type: :runtime
31
25
  prerelease: false
@@ -37,10 +31,6 @@ dependencies:
37
31
  requirements:
38
32
  - - ~>
39
33
  - !ruby/object:Gem::Version
40
- segments:
41
- - 1
42
- - 0
43
- - 0
44
34
  version: 1.0.0
45
35
  type: :development
46
36
  prerelease: false
@@ -52,10 +42,6 @@ dependencies:
52
42
  requirements:
53
43
  - - ~>
54
44
  - !ruby/object:Gem::Version
55
- segments:
56
- - 1
57
- - 5
58
- - 2
59
45
  version: 1.5.2
60
46
  type: :development
61
47
  prerelease: false
@@ -67,25 +53,32 @@ dependencies:
67
53
  requirements:
68
54
  - - ">="
69
55
  - !ruby/object:Gem::Version
70
- segments:
71
- - 0
72
56
  version: "0"
73
57
  type: :development
74
58
  prerelease: false
75
59
  version_requirements: *id004
76
60
  - !ruby/object:Gem::Dependency
77
- name: sqlite3
61
+ name: test-unit
78
62
  requirement: &id005 !ruby/object:Gem::Requirement
79
63
  none: false
80
64
  requirements:
81
65
  - - ">="
82
66
  - !ruby/object:Gem::Version
83
- segments:
84
- - 0
85
67
  version: "0"
86
68
  type: :development
87
69
  prerelease: false
88
70
  version_requirements: *id005
71
+ - !ruby/object:Gem::Dependency
72
+ name: sqlite3
73
+ requirement: &id006 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: "0"
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: *id006
89
82
  description: Simple ASCII table importer for Sequel
90
83
  email: viking@pillageandplunder.net
91
84
  executables: []
@@ -120,7 +113,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
120
113
  requirements:
121
114
  - - ">="
122
115
  - !ruby/object:Gem::Version
123
- hash: 3180758858338140348
116
+ hash: -850477941164118927
124
117
  segments:
125
118
  - 0
126
119
  version: "0"
@@ -129,13 +122,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
122
  requirements:
130
123
  - - ">="
131
124
  - !ruby/object:Gem::Version
132
- segments:
133
- - 0
134
125
  version: "0"
135
126
  requirements: []
136
127
 
137
128
  rubyforge_project:
138
- rubygems_version: 1.3.7
129
+ rubygems_version: 1.6.0
139
130
  signing_key:
140
131
  specification_version: 3
141
132
  summary: Simple ASCII table importer for Sequel