Skip to content

Commit

Permalink
model generator: cleaned up formatting of model file
Browse files Browse the repository at this point in the history
  • Loading branch information
drnic committed Apr 25, 2008
1 parent acd068d commit 6f5abd3
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 10 deletions.
11 changes: 10 additions & 1 deletion hobofields/Manifest
Expand Up @@ -17,9 +17,18 @@ lib/hobo_fields/textile_string.rb
lib/hobo_fields.rb
lib/hobofields.rb
LICENSE.txt
Manifest
rails_generators/hobofield_model/hobofield_model_generator.rb
rails_generators/hobofield_model/templates/fixtures.yml.erb
rails_generators/hobofield_model/templates/model.rb.erb
rails_generators/hobofield_model/templates/test.rb.erb
rails_generators/hobofield_model/USAGE
README.txt
script/destroy
script/generate
test/hobofields.rdoctest
test/hobofields_api.rdoctest
test/migration_generator.rdoctest
test/rich_types.rdoctest
Manifest
test/test_generator_helper.rb
test/test_hobofield_model_generator.rb
@@ -1,3 +1,4 @@
require File.dirname(__FILE__) + '/../../lib/hobofields'
class HoboMigrationGenerator < Rails::Generator::Base

def initialize(runtime_args, runtime_options = {})
Expand Down
Expand Up @@ -12,11 +12,11 @@ def manifest
m.directory File.join('test/fixtures', class_path)

# Create stubs
m.template "model.rb.erb", "app/models/#{name}.rb"
m.template "test.rb.erb", "test/unit/#{name}_test.rb"
m.template "model.rb.erb", "app/models/#{file_name}.rb"
m.template "test.rb.erb", "test/unit/#{file_name}_test.rb"

unless options[:skip_fixture]
m.template 'fixtures.yml.erb', File.join('test/fixtures', "#{table_name}.yml")
m.template 'fixtures.yml.erb', File.join('test/fixtures', "#{file_name}.yml")
end

end
Expand Down
@@ -1,10 +1,10 @@
class <%= class_name %> < ActiveRecord::Base
fields do
<% for attribute in attributes -%>
<%= attribute.type %> :<%= attribute.name %>
<% end -%>
<% unless options[:skip_timestamps] %>
<% for attribute in attributes -%>
<%= attribute.name %> :<%= attribute.type %>
<% end -%>
<% unless options[:skip_timestamps] %>
timestamps
<% end -%>
<% end -%>
end
end
15 changes: 14 additions & 1 deletion hobofields/test/test_hobofield_model_generator.rb
Expand Up @@ -27,7 +27,7 @@ def teardown
# bare_setup - place this in setup method to create the APP_ROOT folder for each test
# bare_teardown - place this in teardown method to destroy the TMP_ROOT or APP_ROOT folder after each test

def test_generator_without_options
def test_generator_underscore_name
name = "my_model"
run_generator('hobofield_model', [name], sources)
assert_generated_file("app/models/my_model.rb")
Expand All @@ -40,6 +40,19 @@ def test_generator_without_options
end
end

def test_generator_camelcase
name = "MyModel"
run_generator('hobofield_model', [name], sources)
assert_generated_file("app/models/my_model.rb")
assert_generated_class("app/models/my_model") do |body|
end

assert_generated_file("test/unit/my_model_test.rb")
assert_generated_class("test/unit/my_model_test") do |body|
assert_has_method "test_truth"
end
end

private
def sources
[RubiGen::PathSource.new(:test, File.join(File.dirname(__FILE__),"..", generator_path))
Expand Down

0 comments on commit 6f5abd3

Please sign in to comment.