dbd4 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/dbd4 +5 -5
- data/lib/dbd4/dbd4_model_file.rb +96 -48
- data/lib/dbd4/rails_migration_file.rb +44 -4
- data/lib/dbd4/rails_model_file.rb +13 -16
- data/tests/unit/test_dbd4.rb +30 -14
- data/tests/unit/test_dbd4_model_file.rb +1 -0
- metadata +2 -2
data/bin/dbd4
CHANGED
@@ -21,7 +21,7 @@
|
|
21
21
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
22
|
#--
|
23
23
|
|
24
|
-
DBD4VERSION = '1.0.
|
24
|
+
DBD4VERSION = '1.0.5'
|
25
25
|
|
26
26
|
require 'getoptlong'
|
27
27
|
require 'dbd4/dbd4_model_file'
|
@@ -141,10 +141,10 @@ class DBD4Import
|
|
141
141
|
dbmf.generateModelFiles unless $validate_only == true
|
142
142
|
puts "Done!"
|
143
143
|
end
|
144
|
-
rescue Exception => ex
|
145
|
-
|
146
|
-
|
147
|
-
|
144
|
+
#rescue Exception => ex
|
145
|
+
# puts "dbmodel aborted!"
|
146
|
+
# puts ex
|
147
|
+
# exit(1)
|
148
148
|
end
|
149
149
|
end
|
150
150
|
end
|
data/lib/dbd4/dbd4_model_file.rb
CHANGED
@@ -92,7 +92,7 @@ module DBD4
|
|
92
92
|
@comments = table.attributes['Comments']
|
93
93
|
@name = table.attributes['Tablename']
|
94
94
|
@modelname = Inflector.singularize(@name)
|
95
|
-
@nm_table =
|
95
|
+
@nm_table = table.attributes['nmTable'];
|
96
96
|
@primary_key = nil;
|
97
97
|
|
98
98
|
@relation_starts = Array.new
|
@@ -100,7 +100,15 @@ module DBD4
|
|
100
100
|
@columns = Columns.new(self)
|
101
101
|
@non_standard_name = false
|
102
102
|
end
|
103
|
-
|
103
|
+
|
104
|
+
def self.createJoinTableName(t1, t2)
|
105
|
+
if t1.name < t2.name
|
106
|
+
"#{t1.name}_#{t2.name}"
|
107
|
+
else
|
108
|
+
"#{t2.name}_#{t1.name}"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
104
112
|
def addColumnFromXml(column_xml)
|
105
113
|
column = Column.new(column_xml, self)
|
106
114
|
@primary_key = column if column.primary_key? and ! @primary_key
|
@@ -116,20 +124,25 @@ module DBD4
|
|
116
124
|
end
|
117
125
|
|
118
126
|
def validate(messages)
|
119
|
-
if @nm_table
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
expected_name = "#{t1.name}_#{t2.name}"
|
127
|
+
if @nm_table == '1'
|
128
|
+
if @relation_ends.size != 2
|
129
|
+
messages[:warnings] << "Warning : join table #{name} must have only 2 foreign keys with one2many types."
|
130
|
+
elsif @relation_ends.values[0].type != :many2many or relation_ends.values[1].type != :many2many
|
131
|
+
messages[:warnings] << "Warning : join table #{name} has a relation that is not many2many"
|
125
132
|
else
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
133
|
+
t1 = @relation_ends.values[0].source_table
|
134
|
+
t2 = @relation_ends.values[1].source_table
|
135
|
+
expected_name = Table.createJoinTableName(t1, t2)
|
136
|
+
if @name != expected_name then
|
137
|
+
messages[:warnings] << "Warning : join table #{name} differs from expected #{expected_name}"
|
138
|
+
@non_standard_name = true
|
139
|
+
end
|
131
140
|
end
|
132
141
|
else
|
142
|
+
if @columns.size == 2 and @columns.foreign_keys.size == 2 and @relation_ends.values.size == 2 and @relation_ends.values[0].type == :one2many and @relation_ends.values[1].type == :one2many
|
143
|
+
messages[:warnings] << "Warning : table name #{name} seems to be a join table (many2many) please specify 'is nm_table' in DBDesigner"
|
144
|
+
end
|
145
|
+
|
133
146
|
if @modelname == @name
|
134
147
|
messages[:warnings] << "Warning : table name #{name} is not in a valid plural form, should be #{Inflector.pluralize(name)}"
|
135
148
|
@non_standard_name = true
|
@@ -152,28 +165,28 @@ module DBD4
|
|
152
165
|
tmp = Relations.new
|
153
166
|
@relation_ends.each { |r| tmp<<allObjects[:relations][r.id] }
|
154
167
|
@relation_ends = tmp
|
155
|
-
if @
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
@relation_ends.values[1].destination_table = @relation_ends.values[0].source_table
|
163
|
-
@relation_ends.values[1].join_table = self
|
164
|
-
@relation_ends.values[0].type = :many2many
|
165
|
-
@relation_ends.values[1].type = :many2many
|
166
|
-
end
|
167
|
-
end
|
168
|
-
end
|
168
|
+
if @relation_ends.values.size == 2 and @nm_table == '1' then
|
169
|
+
@relation_ends.values[0].destination_table = @relation_ends.values[1].source_table
|
170
|
+
@relation_ends.values[0].join_table = self
|
171
|
+
@relation_ends.values[1].destination_table = @relation_ends.values[0].source_table
|
172
|
+
@relation_ends.values[1].join_table = self
|
173
|
+
@relation_ends.values[0].type = :many2many
|
174
|
+
@relation_ends.values[1].type = :many2many
|
169
175
|
end
|
170
176
|
end
|
171
177
|
|
172
178
|
def generateModelFile
|
173
179
|
m = RailsModelFile.new({:modelname => @modelname})
|
174
|
-
m.update(self) unless @nm_table
|
180
|
+
m.update(self) unless @nm_table == '1'
|
175
181
|
m = RailsMigrationFile.new({:tablename => @name})
|
176
182
|
m.update(self)
|
183
|
+
|
184
|
+
@relation_starts.each_value do |rs|
|
185
|
+
if rs.type == :many2many and rs.join_table == nil
|
186
|
+
m = RailsMigrationFile.new({:virtual => true, :tablename => Table.createJoinTableName(self, rs.destination_table)})
|
187
|
+
m.update_implicit_join_table(rs)
|
188
|
+
end
|
189
|
+
end
|
177
190
|
end
|
178
191
|
|
179
192
|
def to_str
|
@@ -273,33 +286,61 @@ module DBD4
|
|
273
286
|
when '5'
|
274
287
|
@type = :one2one
|
275
288
|
when '2'
|
276
|
-
@type = :one2many
|
289
|
+
@type = :one2many
|
290
|
+
when '3'
|
291
|
+
@type = :many2many
|
277
292
|
end
|
278
293
|
@source_table = relation.attributes['SrcTable']
|
279
294
|
@destination_table = relation.attributes['DestTable']
|
280
295
|
end
|
281
|
-
|
296
|
+
|
282
297
|
def resolve(allObjects)
|
283
298
|
@source_table = allObjects[:tables][@source_table]
|
284
299
|
@destination_table = allObjects[:tables][@destination_table]
|
285
|
-
@
|
286
|
-
|
300
|
+
if @type != :many2many
|
301
|
+
@source_column = @source_table.columns.primary_keys[@fk_fields[0].source_field]
|
302
|
+
@destination_column = @destination_table.columns.foreign_keys[@fk_fields[0].destination_field]
|
303
|
+
end
|
287
304
|
end
|
288
305
|
|
289
306
|
def validate(messages)
|
307
|
+
if @type == nil
|
308
|
+
messages[:warnings] << "Warning : between table #{@destination_table.name} and table #{@source_table.name}, type #{@kind} is invalid"
|
309
|
+
end
|
310
|
+
|
290
311
|
if @fk_fields.size > 1
|
291
|
-
messages[:warnings] << "Warning : between table #{@
|
312
|
+
messages[:warnings] << "Warning : between table #{@destination_table.name} and table #{@source_table.name}, relation #{name} targets more than 1 foreign_key"
|
292
313
|
end
|
293
314
|
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
315
|
+
if !( @type != nil and @type == :many2many and @join_table == nil )
|
316
|
+
expected_fkey_name = Inflector.singularize(@source_table.name) + "_id"
|
317
|
+
if @destination_column.name != expected_fkey_name and @destination_column.polymorphic == nil then
|
318
|
+
messages[:warnings] << "Warning : table #{@destination_column.table.name}, foreign key #{@destination_column.name} does not match expected name #{expected_fkey_name}"
|
319
|
+
@destination_column.non_standard_name = true
|
320
|
+
end
|
298
321
|
end
|
299
322
|
end
|
300
323
|
|
301
324
|
def to_str
|
302
|
-
"Relation(id=#{id}, name=#{name}, type=#{type},
|
325
|
+
result = "Relation(id=#{id}, name=#{name}, type=#{type},"
|
326
|
+
if source_column != nil
|
327
|
+
result += " src_col=#{source_column.name},"
|
328
|
+
else
|
329
|
+
result += " src_col=nil,"
|
330
|
+
end
|
331
|
+
if destination_column != nil
|
332
|
+
result += " dst_col=#{destination_column.name},"
|
333
|
+
else
|
334
|
+
result += " dst_col=nil,"
|
335
|
+
end
|
336
|
+
result += " src=#{source_table.name}, dst=#{destination_table.name}, fk=#{fk_fields.to_str},"
|
337
|
+
if join_table != nil
|
338
|
+
result += " join_table=#{join_table.name}"
|
339
|
+
else
|
340
|
+
result += " join_table=nil"
|
341
|
+
end
|
342
|
+
result += ")"
|
343
|
+
result
|
303
344
|
end
|
304
345
|
end
|
305
346
|
|
@@ -444,8 +485,9 @@ module DBD4
|
|
444
485
|
|
445
486
|
def <<(column)
|
446
487
|
column.table = @table
|
447
|
-
|
488
|
+
|
448
489
|
if column.primary_key?
|
490
|
+
@primary_key = column
|
449
491
|
@primary_keys[column.name] = column
|
450
492
|
end
|
451
493
|
if column.foreign_key?
|
@@ -464,16 +506,22 @@ module DBD4
|
|
464
506
|
end
|
465
507
|
|
466
508
|
def validate(messages)
|
467
|
-
if @
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
509
|
+
if @table.nm_table == '0'
|
510
|
+
if @primary_key == nil then
|
511
|
+
messages[:errors] << "Error : table #{@table.name} has no primary keys, you need at least 1"
|
512
|
+
else
|
513
|
+
if @primary_keys.size > 1 then
|
514
|
+
messages[:warnings] << "Warning : table #{@table.name} has more than 1 primary key, only the first one will be considered"
|
515
|
+
end
|
516
|
+
|
517
|
+
if @primary_key.name != 'id'
|
518
|
+
messages[:warnings] << "Warning : table #{@table.name} primary key #{@primary_key.name} differs from expected name id"
|
519
|
+
@primary_key.non_standard_name = true
|
520
|
+
end
|
472
521
|
end
|
473
|
-
|
474
|
-
if @primary_key
|
475
|
-
messages[:warnings] << "Warning : table #{@table.name}
|
476
|
-
@primary_key.non_standard_name = true
|
522
|
+
else
|
523
|
+
if @primary_key != nil then
|
524
|
+
messages[:warnings] << "Warning : table #{@table.name} is a many2many join table, it cannot have a primary key"
|
477
525
|
end
|
478
526
|
end
|
479
527
|
each_value { |v| v.validate(messages) }
|
@@ -32,15 +32,29 @@ module DBD4
|
|
32
32
|
@warnings = Array.new
|
33
33
|
@infos = Array.new
|
34
34
|
@tablename = options[:tablename]
|
35
|
+
@virtual = options[:virtual]
|
35
36
|
|
36
37
|
if options[:tablename]
|
37
38
|
if Inflector.singularize(@tablename) == @tablename
|
38
39
|
raise RailsModelFileError, "MigrationModelFile : tablename #{@tablename} is not valid, it must be plural, not singular"
|
39
40
|
end
|
40
|
-
partial_name = "_create_" + Inflector.underscore(Inflector.camelize(@tablename)) + ".rb"
|
41
|
-
fileList = Dir.new(File.join('db', 'migrate')).entries.delete_if { |e| e !~ /#{partial_name}/ }
|
41
|
+
partial_name = "_create_" + Inflector.underscore(Inflector.camelize(@tablename)) + ".rb"
|
42
|
+
fileList = Array.new(Dir.new(File.join('db', 'migrate')).entries).delete_if { |e| e !~ /#{partial_name}/ }
|
42
43
|
if fileList.size == 0
|
43
|
-
|
44
|
+
if @virtual == true
|
45
|
+
cmdline = ['migration', "create_" + Inflector.underscore(Inflector.camelize(@tablename)) ]
|
46
|
+
puts "Calling generator: #{cmdline.join(' ')}"
|
47
|
+
Rails::Generator::Scripts::Generate.new.run(cmdline)
|
48
|
+
fileList = Array.new(Dir.new(File.join('db', 'migrate')).entries).delete_if { |e| e !~ /#{partial_name}/ }
|
49
|
+
if fileList.size == 0
|
50
|
+
raise "Could not find generated migration file starting with #{partial_name} in dir db/migrate"
|
51
|
+
end
|
52
|
+
if fileList.size > 1
|
53
|
+
raise "Found more than 1 migration file starting with #{partial_name} in dir db/migrate"
|
54
|
+
end
|
55
|
+
else
|
56
|
+
raise "Could not find migration file starting with #{partial_name} in dir db/migrate"
|
57
|
+
end
|
44
58
|
end
|
45
59
|
if fileList.size > 1
|
46
60
|
raise "Found more than 1 migration file starting with #{partial_name} in dir db/migrate"
|
@@ -100,7 +114,7 @@ module DBD4
|
|
100
114
|
new_migration_file_content = <<"MIGRATIONFILE"
|
101
115
|
class Create#{c} < ActiveRecord::Migration
|
102
116
|
def self.up
|
103
|
-
create_table :#{
|
117
|
+
create_table :#{@tablename} do |t|
|
104
118
|
#{columnsToString(table)}
|
105
119
|
end
|
106
120
|
end
|
@@ -119,6 +133,32 @@ MIGRATIONFILE
|
|
119
133
|
end
|
120
134
|
end
|
121
135
|
|
136
|
+
def update_implicit_join_table(relation)
|
137
|
+
raise "MigrationFile : migration file name not given" if ! @migrationfile
|
138
|
+
c = Inflector.camelize(@tablename)
|
139
|
+
new_migration_file_content = <<"MIGRATIONFILE"
|
140
|
+
class Create#{c} < ActiveRecord::Migration
|
141
|
+
def self.up
|
142
|
+
create_table :#{@tablename}, :id => false do |t|
|
143
|
+
t.column :#{relation.source_table.modelname}_id, :integer
|
144
|
+
t.column :#{relation.destination_table.modelname}_id, :integer
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
def self.down
|
149
|
+
drop_table :#{@tablename}
|
150
|
+
end
|
151
|
+
end
|
152
|
+
MIGRATIONFILE
|
153
|
+
|
154
|
+
old_migration_file_content = IO.readlines(@migrationfile).join("")
|
155
|
+
if (old_migration_file_content != new_migration_file_content)
|
156
|
+
puts "Updating migration file for table #{@tablename} (file : #{@migrationfile})..."
|
157
|
+
newFile = File.open(@migrationfile, "w")
|
158
|
+
newFile.puts new_migration_file_content
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
122
162
|
def to_str
|
123
163
|
@lines.join("")
|
124
164
|
end
|
@@ -39,7 +39,6 @@ module DBD4
|
|
39
39
|
'has_one' => {},
|
40
40
|
'has_many' => {},
|
41
41
|
'belongs_to' => {},
|
42
|
-
'habtm' => {},
|
43
42
|
'has_and_belongs_to_many' => {},
|
44
43
|
'class' => {},
|
45
44
|
'primary_key' => {},
|
@@ -112,21 +111,17 @@ module DBD4
|
|
112
111
|
else
|
113
112
|
@elements['table_name'] = { :start => i, :name => $~[1] }
|
114
113
|
end
|
115
|
-
elsif l.match(/^\s*(has_one|has_many|has_and_belongs_to_many|
|
114
|
+
elsif l.match(/^\s*(has_one|has_many|has_and_belongs_to_many|belongs_to)\s+:([a-zA-Z_0-9]+)/)
|
116
115
|
r_type = $~[1]
|
117
116
|
t_name = $~[2]
|
118
117
|
|
119
|
-
if r_type == 'has_and_belongs_to_many'
|
120
|
-
r_type = 'habtm'
|
121
|
-
end
|
122
|
-
|
123
118
|
if @elements[r_type][t_name]
|
124
119
|
@warnings << "Warning in file #{@modelfile} at line #{i + 1}:"
|
125
120
|
@warnings << " Duplicate declaration #{r_type}, it is already defined at line #{@elements[r_type][t_name][:start] + 1}"
|
126
121
|
@lines[i] = "#" + @lines[i]
|
127
122
|
i += 1
|
128
123
|
while i < @lines.size
|
129
|
-
break if @lines[i].match(/^\s*(?:has_one|has_many|has_and_belongs_to_many|
|
124
|
+
break if @lines[i].match(/^\s*(?:has_one|has_many|has_and_belongs_to_many|belongs_to|def|end)/)
|
130
125
|
@lines[i] = "#" + @lines[i] if @lines[i] !~ /^\s*#/
|
131
126
|
i += 1
|
132
127
|
end
|
@@ -141,7 +136,7 @@ module DBD4
|
|
141
136
|
i += 1
|
142
137
|
while i < @lines.size
|
143
138
|
l2 = @lines[i]
|
144
|
-
break if @lines[i].match(/^\s*(?:has_one|has_many|has_and_belongs_to_many|
|
139
|
+
break if @lines[i].match(/^\s*(?:has_one|has_many|has_and_belongs_to_many|belongs_to|def|end)/)
|
145
140
|
r[:foreign_key] = $~ if l2.match(/:foreign_key\s*=>\s*["']([a-zA-Z_0-9]+)/)
|
146
141
|
r[:polymorphic] = $~ if l2.match(/:polymorphic\s*=>\s*true/)
|
147
142
|
r[:as] = $~ if l2.match(/:as\s*=>\s*([a-zA-Z_0-9]+)/)
|
@@ -191,13 +186,13 @@ module DBD4
|
|
191
186
|
|
192
187
|
etype = 'has_one' if r.type == :one2one
|
193
188
|
etype = 'has_many' if r.type == :one2many
|
194
|
-
etype = '
|
189
|
+
etype = 'has_and_belongs_to_many' if r.type == :many2many
|
195
190
|
element = @elements[etype][dname]
|
196
191
|
|
197
192
|
#If the line exists
|
198
193
|
if element
|
199
194
|
if element[:as]
|
200
|
-
if r.destination_column.polymorphic
|
195
|
+
if r.destination_column and r.destination_column.polymorphic
|
201
196
|
for i in (element[:start] .. element[:end])
|
202
197
|
@lines[i].sub!(/(:as\s*=>\s*["']?)[a-zA-Z_0-9]+/, "\\1#{r.destination_column.polymorphic}")
|
203
198
|
end
|
@@ -207,12 +202,14 @@ module DBD4
|
|
207
202
|
end
|
208
203
|
end
|
209
204
|
else
|
210
|
-
|
205
|
+
if r.destination_column and r.destination_column.polymorphic
|
206
|
+
@lines[element[:start]].sub!(/(#{etype}[^,]+)/, "\\1, :as => '#{r.destination_column.polymorphic}'")
|
207
|
+
end
|
211
208
|
end
|
212
209
|
left_over[etype].delete(dname)
|
213
210
|
else
|
214
211
|
@lines[@elements['class'][:start]] += " #{etype} :#{dname}"
|
215
|
-
if r.destination_column.polymorphic
|
212
|
+
if r.destination_column and r.destination_column.polymorphic
|
216
213
|
@lines[@elements['class'][:start]] += ", :as => #{r.destination_column.polymorphic}"
|
217
214
|
end
|
218
215
|
@lines[@elements['class'][:start]] += "\n"
|
@@ -232,19 +229,19 @@ module DBD4
|
|
232
229
|
end
|
233
230
|
|
234
231
|
etype = 'belongs_to' if r.type == :one2one or r.type == :one2many
|
235
|
-
etype = '
|
232
|
+
etype = 'has_and_belongs_to_many' if r.type == :many2many
|
236
233
|
element = @elements[etype][dname]
|
237
234
|
|
238
235
|
#If the line exists
|
239
236
|
if element
|
240
237
|
if element[:polymorphic]
|
241
|
-
if ! r.destination_column.polymorphic
|
238
|
+
if r.destination_column and ! r.destination_column.polymorphic
|
242
239
|
for i in (element[:start] .. element[:end])
|
243
240
|
@lines[i].sub!(/,\s*:polymorphic\s*=>\s*["']?[a-zA-Z_0-9]+["']?/, "")
|
244
241
|
end
|
245
242
|
end
|
246
243
|
else
|
247
|
-
if r.destination_column.polymorphic
|
244
|
+
if r.destination_column and r.destination_column.polymorphic
|
248
245
|
@lines[element[:start]].sub!(/(#{etype}[^,\n]+)/, "\\1, :polymorphic => true")
|
249
246
|
else
|
250
247
|
# do nothing
|
@@ -253,7 +250,7 @@ module DBD4
|
|
253
250
|
left_over[etype].delete(dname)
|
254
251
|
else
|
255
252
|
@lines[@elements['class'][:start]] += " #{etype} :#{dname}"
|
256
|
-
if r.destination_column.polymorphic
|
253
|
+
if r.destination_column and r.destination_column.polymorphic
|
257
254
|
@elements[etype] = { dname => { :polymorphic => true, :added => true } }
|
258
255
|
@lines[@elements['class'][:start]] += ", :polymorphic => true"
|
259
256
|
end
|
data/tests/unit/test_dbd4.rb
CHANGED
@@ -22,6 +22,7 @@ $files = {
|
|
22
22
|
'app/models/dog.rb' => "class Dog < ActiveRecord::Base\nend\n",
|
23
23
|
'app/models/kid.rb' => "class Kid < ActiveRecord::Base\nend\n",
|
24
24
|
'app/models/house.rb' => "class House < ActiveRecord::Base\nend\n",
|
25
|
+
'app/models/car.rb' => "class Car < ActiveRecord::Base\nend\n",
|
25
26
|
'db/migrate/001_create_cats.rb' => "",
|
26
27
|
'db/migrate/001_create_cats.rb' => "",
|
27
28
|
'db/migrate/001_create_cats.rb' => "",
|
@@ -37,18 +38,14 @@ $files = {
|
|
37
38
|
'db/migrate/011_create_wives.rb' => "",
|
38
39
|
'db/migrate/012_create_dogs.rb' => "",
|
39
40
|
'db/migrate/013_create_kids.rb' => "",
|
40
|
-
'db/migrate/014_create_houses.rb' => ""
|
41
|
+
'db/migrate/014_create_houses.rb' => "",
|
42
|
+
'db/migrate/015_create_cars.rb' => "",
|
43
|
+
'db/migrate/104_create_cars_people.rb' => ""
|
41
44
|
}
|
42
45
|
|
43
|
-
$
|
46
|
+
$new_migration_numbers = ['100', '101', '102', '103', '104']
|
44
47
|
|
45
|
-
|
46
|
-
def initialize(dirname)
|
47
|
-
raise "Cannot open directory : #{dirname}" if dirname != File.join("db", "migrate")
|
48
|
-
end
|
49
|
-
|
50
|
-
def entries
|
51
|
-
[
|
48
|
+
$dir_entries = [
|
52
49
|
'001_create_cats.rb',
|
53
50
|
'002_create_computers_users.rb',
|
54
51
|
'003_create_computers.rb',
|
@@ -62,8 +59,19 @@ class Dir
|
|
62
59
|
'011_create_wives.rb',
|
63
60
|
'012_create_dogs.rb',
|
64
61
|
'013_create_kids.rb',
|
65
|
-
'014_create_houses.rb'
|
62
|
+
'014_create_houses.rb',
|
63
|
+
'015_create_cars.rb'
|
66
64
|
]
|
65
|
+
|
66
|
+
$files_written_to = Array.new
|
67
|
+
|
68
|
+
class Dir
|
69
|
+
def initialize(dirname)
|
70
|
+
raise "Cannot open directory : #{dirname}" if dirname != File.join("db", "migrate")
|
71
|
+
end
|
72
|
+
|
73
|
+
def entries
|
74
|
+
$dir_entries
|
67
75
|
end
|
68
76
|
end
|
69
77
|
|
@@ -207,6 +215,7 @@ INPUT
|
|
207
215
|
'app/models/dog.rb' => "class Dog < ActiveRecord::Base\nend\n",
|
208
216
|
'app/models/kid.rb' => "class Kid < ActiveRecord::Base\nend\n",
|
209
217
|
'app/models/house.rb' => "class House < ActiveRecord::Base\nend\n",
|
218
|
+
'app/models/car.rb' => "class Car < ActiveRecord::Base\nend\n",
|
210
219
|
'db/migrate/001_create_cats.rb' => "",
|
211
220
|
'db/migrate/002_create_computers_users.rb' => "",
|
212
221
|
'db/migrate/003_create_computers.rb' => "",
|
@@ -220,12 +229,14 @@ INPUT
|
|
220
229
|
'db/migrate/011_create_wives.rb' => "",
|
221
230
|
'db/migrate/012_create_dogs.rb' => "",
|
222
231
|
'db/migrate/013_create_kids.rb' => "",
|
223
|
-
'db/migrate/014_create_houses.rb' => ""
|
232
|
+
'db/migrate/014_create_houses.rb' => "",
|
233
|
+
'db/migrate/104_create_cars_people.rb' => "",
|
234
|
+
'db/migrate/015_create_cars.rb' => ""
|
224
235
|
}
|
225
236
|
@b.generateModelFiles
|
226
|
-
|
237
|
+
|
227
238
|
run_info = Rails::Generator::Scripts::Generate.new.run_info
|
228
|
-
assert_equal(
|
239
|
+
assert_equal(16, run_info.size)
|
229
240
|
assert_equal(1, run_info['model computer'])
|
230
241
|
assert_equal(1, run_info['model wife'])
|
231
242
|
assert_equal(1, run_info['model shoe'])
|
@@ -240,6 +251,8 @@ INPUT
|
|
240
251
|
assert_equal(1, run_info['model house'])
|
241
252
|
assert_equal(1, run_info['model dog'])
|
242
253
|
assert_equal(1, run_info['model job'])
|
254
|
+
assert_equal(1, run_info['migration create_cars_people'])
|
255
|
+
assert_equal(1, run_info['model car'])
|
243
256
|
end
|
244
257
|
|
245
258
|
def _test_comment
|
@@ -258,6 +271,7 @@ INPUT
|
|
258
271
|
'app/models/dog.rb' => "class Dog < ActiveRecord::Base\n has_many :generic_animals, :as => gogole\nend\n",
|
259
272
|
'app/models/kid.rb' => "class Kid < ActiveRecord::Base\nend\n",
|
260
273
|
'app/models/house.rb' => "class House < ActiveRecord::Base\nend\n",
|
274
|
+
'app/models/car.rb' => "class Car < ActiveRecord::Base\nend\n",
|
261
275
|
'db/migrate/001_create_cats.rb' => "",
|
262
276
|
'db/migrate/001_create_cats.rb' => "",
|
263
277
|
'db/migrate/002_create_computers_users.rb' => "",
|
@@ -272,7 +286,9 @@ INPUT
|
|
272
286
|
'db/migrate/011_create_wives.rb' => "",
|
273
287
|
'db/migrate/012_create_dogs.rb' => "",
|
274
288
|
'db/migrate/013_create_kids.rb' => "",
|
275
|
-
'db/migrate/014_create_houses.rb' => ""
|
289
|
+
'db/migrate/014_create_houses.rb' => "",
|
290
|
+
'db/migrate/104_create_cars_people.rb' => "",
|
291
|
+
'db/migrate/015_create_cars.rb' => ""
|
276
292
|
}
|
277
293
|
|
278
294
|
$files_written_to = Array.new
|
@@ -34,6 +34,7 @@ class Dbd4Test < Test::Unit::TestCase
|
|
34
34
|
|
35
35
|
def _test_with_all_errors_corrected
|
36
36
|
b = DBD4::DBD4ModelFile.new(File.join(File.dirname(__FILE__), '..', 'data', 'good_example.xml'))
|
37
|
+
puts b.messages[:warnings]
|
37
38
|
assert_equal(0, b.messages[:errors].size)
|
38
39
|
assert_equal(0, b.messages[:warnings].size)
|
39
40
|
a = b.to_str.readlines.zip(IO.readlines(File.join(File.dirname(__FILE__), '..', 'data', 'good_example.output')))
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: dbd4
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.0.
|
7
|
-
date: 2006-08-
|
6
|
+
version: 1.0.5
|
7
|
+
date: 2006-08-26 00:00:00 -04:00
|
8
8
|
summary: A package for importing DB Designer 4 xml models in rails.
|
9
9
|
require_paths:
|
10
10
|
- lib
|