Skip to content

Commit

Permalink
add name to object, containing its underscored-lowercased modelname, …
Browse files Browse the repository at this point in the history
…change title to keep the human model name
  • Loading branch information
schorsch committed Mar 5, 2013
1 parent 97bb848 commit 2470b1c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/schema_builder/writer.rb
Expand Up @@ -15,7 +15,7 @@ def write
out = {:new => [], :old => [] }
create_out_path
models_as_hash.each do |model|
file = File.join( out_path, "#{model['title'].downcase}.json")
file = File.join( out_path, "#{model['name'].downcase}.json")
if File.exist? file
out[:old] << file
else
Expand All @@ -36,7 +36,8 @@ def models_as_hash
out = []
models.each do |model|
obj = schema_template
obj['title'] = model.name
obj['name'] = model.name.underscore
obj['title'] = model.model_name.human
props = {}
model.columns_hash.each do |name, col|
prop = {}
Expand Down Expand Up @@ -103,7 +104,8 @@ def schema_template
hsh = {}
hsh['type'] = 'object'
hsh['title'] = ''
hsh['description'] = 'object'
hsh['name'] = ''
hsh['description'] = 'the object description'
hsh['properties'] = {}
hsh['links'] = []
hsh
Expand Down
15 changes: 15 additions & 0 deletions spec/schema_builder/writer_spec.rb
Expand Up @@ -21,6 +21,21 @@
end
end

context 'model naming' do
before :each do
@writer = SchemaBuilder::Writer.new
@user_hash = @writer.models_as_hash.first
end

it 'should set title to model human name' do
@user_hash['title'].should == 'User'
end

it 'should set name to lowercase model name' do
@user_hash['name'].should == 'user'
end
end

context 'file writing' do
before :each do
@writer = SchemaBuilder::Writer.new
Expand Down

0 comments on commit 2470b1c

Please sign in to comment.