Skip to content

Commit

Permalink
Major refactoring - actually more of a re-write. Generates robust tes…
Browse files Browse the repository at this point in the history
…ts (the old ones where a bit sloppy). Added Shoulda test generation.
  • Loading branch information
grimen committed Jul 22, 2009
1 parent 603f73c commit a0f1ab4
Show file tree
Hide file tree
Showing 46 changed files with 936 additions and 538 deletions.
39 changes: 24 additions & 15 deletions README.textile
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,19 @@ h3. Optional:

h4. Controllers/Views

* "*will_paginate*":http://github.com/mislav/will_paginate - Pagination
* "*formtastic*":http://github.com/justinfrench/formtastic - DRY and semantic forms
* "*inherited_resources*":http://github.com/josevalim/inherited_resources - DRY/Resourceful controllers
* "*formtastic*":http://github.com/justinfrench/formtastic - DRY and semantic forms
* "*will_paginate*":http://github.com/mislav/will_paginate - Pagination

h4. Models

* "*factory_girl*":http://github.com/thoughtbot/factory_girl - Fixture-replacement
* "*machinist*":http://github.com/notahat/machinist - Fixture-replacement
* "*object_daddy*":http://github.com/flogic/object_daddy - Fixture-replacement

h4. Testing

* "*Shoulda*":http://github.com/thoughtbot/shoulda - Testing framework

h2. Features

Expand All @@ -47,7 +51,7 @@ The most characteristic features:
* Collection pagination using will_paginate by default. Note: Can be turned off.
* Optionally specify what actions/views to generate (stubs for specified REST-actions will be generated).
* Optionally specify what respond_to-formats to generate (stubs for the most common respond_to-formats will be generated).
* Generates default helpers/models/migrations, and REST-routes.
* Generates default helpers/models/migrations, and REST-routes (if not already defined).

h3. Formtastic Forms

Expand Down Expand Up @@ -211,7 +215,7 @@ h4. Manual
Get the gems...you want:

<pre>sudo gem install haml
sudo gem install will_paginate
sudo gem install mislav-will_paginate
sudo gem install justinfrench-formtastic
sudo gem install josevalim-inherited_resources</pre>

Expand All @@ -224,13 +228,13 @@ config.gem 'josevalim-inherited_resources', :lib => 'inherited_resources', :sour

h2. Usage

<pre>./script/generate dry_scaffold ModelName [attribute:type attribute:type] [_actions:new,create,...] [_formats:html,json,...] [_indexes:attribute,...] [--skip-pagination] [--skip-resourceful] [--skip-formtastic] [--skip-views] [--skip-helpers] [--skip-tests] [--include-layout] [--fixtures] [--fgirl] [--machinist] [--odaddy] [--skip-migration] [--skip-timestamps]</pre>
<pre>./script/generate dry_scaffold ModelName [attribute:type attribute:type] [_actions:new,create,...] [_formats:html,json,...] [_indexes:attribute,...] [--skip-pagination] [--skip-resourceful] [--skip-formtastic] [--skip-views] [--skip-helpers] [--skip-migration] [--skip-timestamps] [--skip-tests] [--layout] [--tunit] [--shoulda] [--fixtures] [--fgirl] [--machinist] [--odaddy]</pre>

...or use the alias @dscaffold@ instead of @dry_scaffold@.

For generating just a *model*, then use:

<pre>./script/generate dry_model ModelName [attribute:type attribute:type] [_indexes:attribute,...] [--fixtures] [--fgirl] [--machinist] [--odaddy] [--skip-migration] [--skip-timestamps] [--skip-tests]</pre>
<pre>./script/generate dry_model ModelName [attribute:type attribute:type] [_indexes:attribute,...] [--skip-migration] [--skip-timestamps] [--skip-tests] [--tunit] [--shoulda] [--fixtures] [--fgirl] [--machinist] [--odaddy]</pre>

...or use the alias @dmodel@ instead of @dry_model@.

Expand Down Expand Up @@ -380,24 +384,29 @@ These are the options for the scaffold-generator.
* @--skip-formtastic@ - Don't generate formtastic forms in views, i.e. don't use *formtastic*.
* @--skip-views@ - Don't generate views.
* @--skip-helpers@ - Don't generate helpers.
* @--skip-tests@ - Don't generate tests (functional/unit/...).
* @--skip-builders@ - Don't generate builders.
* @--layout@ - Generate layout.

h4. Model

These are the options for the model/scaffold-generators.

* @--fixtures@ - Generate fixtures.
* @--fgirl@ - Generate *factory_girl* factories.
* @--machinist@ - Generate *machinist* blueprints (factories).
* @--odaddy@ - Generate *object_daddy* generator/factory methods.
* @--skip-timestamps@ - Don't add timestamps to the migration file.
* @--skip-migration@ - Skip generation of migration file.

h4. All

* @--skip-tests@ - Don't generate tests (functional/unit/...).
* @--tunit@ - Generate/Use test_unit tests. Note: Rails default.
* @--shoulda@ - Generate/Use *shoulda* tests.
* @--fixtures@ - Generate/Use fixtures. Note: Rails default.
* @--fgirl@ - Generate/Use *factory_girl* factories.
* @--machinist@ - Generate/Use *machinist* blueprints (factories).
* @--odaddy@ - Generate/Use *object_daddy* generator/factory methods.

As DryScaffold is built upon Rails generator, the default generator options is available as well. For more details; see Rails documentation.

h3. Setting Defaults
h3. Setting Defaults

You can set defaults for the generator args/options in @config/scaffold.yml@. To generate this file, simply do:

Expand All @@ -410,11 +419,11 @@ No need for more samples here, just create a new Rails project, install DryScaff
For your inspiration, you could try the following:

<pre>./script/generate dry_scaffold Zebra name:string about:text --skip-resourceful
./script/generate dry_scaffold Kangaroo name:string about:text --skip-formtastic
./script/generate dscaffold Kangaroo name:string about:text --skip-formtastic
./script/generate dscaffold Duck name:string about:text _actions:new,create,index,quack
./script/generate dscaffold Parrot name:string about:text _formats:html,xml,yml
./script/generate dscaffold GoldFish name:string about:text _indexes:name --fgirl
./script/generate dry_model Frog name:string about:text _indexes:name,name+about --fixtures</pre>
./script/generate dmodel GoldFish name:string about:text _indexes:name --fgirl
./script/generate dmodel Frog name:string about:text _indexes:name,name+about --fixtures</pre>

...or just go crazy!

Expand Down
21 changes: 17 additions & 4 deletions TODO.textile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,24 @@ h1. TODO
h2. Next

* Feature: Handle belongs_to, i.e. specify MODEL --belongs-to PARENT_MODEL, which generates proper routes, proper before-filters if inherited_resources-controller, adding belongs_to-association in model, and correct form_for arguments.
* Choose test suits: testunit/shoulda/rspec

h2. Maybe later

* Clean-up: Comment the code a bit more =)
* Refactor: Break up in different generators: dry_controller, dry_views, etc., and use as dependencies in dry_scaffold?
* Feature: Check for overridden templates in: RAILS_ROOT/lib/dry_scaffold/templates/
* Feature: Builder for podcast-feed, similar to RSS/Atom-builders. http://wiki.github.com/radiant/radiant/host-a-podcast
* Feature: Builder for podcast-feed, similar to RSS/Atom-builders. http://wiki.github.com/radiant/radiant/host-a-podcast

h2. Issues

ActionController::RoutingError: parrot_url failed to generate from {:controller=>"parrots", :id=>#<Parrot id: nil, name: "Hello", created_at: "2009-07-21 18:53:25", updated_at: "2009-07-21 18:53:25">, :action=>"show"}, expected: {:controller=>"parrots", :action=>"show"}, diff: {:id=>#<Parrot id: nil, name: "Hello", created_at: "2009-07-21 18:53:25", updated_at: "2009-07-21 18:53:25">}
(eval):16:in `parrot_url'
/opt/local/lib/ruby/gems/1.8/gems/josevalim-inherited_resources-0.7.3/lib/inherited_resources/url_helpers.rb:194:in `resource_url'
/opt/local/lib/ruby/gems/1.8/gems/josevalim-inherited_resources-0.7.3/lib/inherited_resources/base_helpers.rb:311:in `send'
/opt/local/lib/ruby/gems/1.8/gems/josevalim-inherited_resources-0.7.3/lib/inherited_resources/base_helpers.rb:311:in `parse_redirect_url'
/opt/local/lib/ruby/gems/1.8/gems/josevalim-inherited_resources-0.7.3/lib/inherited_resources/base.rb:79:in `create'
/opt/local/lib/ruby/gems/1.8/gems/josevalim-inherited_resources-0.7.3/lib/inherited_resources/respond_to.rb:301:in `call'
/opt/local/lib/ruby/gems/1.8/gems/josevalim-inherited_resources-0.7.3/lib/inherited_resources/respond_to.rb:301:in `respond_any'
/opt/local/lib/ruby/gems/1.8/gems/josevalim-inherited_resources-0.7.3/lib/inherited_resources/respond_to.rb:233:in `respond_to'
/opt/local/lib/ruby/gems/1.8/gems/josevalim-inherited_resources-0.7.3/lib/inherited_resources/base_helpers.rb:283:in `respond_to_with_dual_blocks'
/opt/local/lib/ruby/gems/1.8/gems/josevalim-inherited_resources-0.7.3/lib/inherited_resources/base.rb:78:in `create'
haml (2.0.9) rails/./lib/sass/plugin/rails.rb:19:in `process'
/test/functional/parrots_controller_test.rb:8:in `test_create'
20 changes: 14 additions & 6 deletions config/scaffold.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,26 @@ dry_scaffold:
formats: html,js,xml,json
options:
formtastic: true
resourceful: true
resourceful: false
pagination: true
layout: false
views: true
helpers: true
tests: true
layout: false
dry_model:
options:
fixtures: false
tunit: true
shoulda: false
fixtures: true
fgirl: false
machinist: false
object_daddy: false
dry_model:
options:
migration: true
timestamps: true
tests: true
tests: true
tunit: true
shoulda: false
fixtures: true
fgirl: false
machinist: false
object_daddy: false
7 changes: 2 additions & 5 deletions generators/dry_model/USAGE
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,5 @@ DESCRIPTION
A replacement for the Rails model generator - a part of the dry_generator toolset.

EXAMPLE
./script/generate dry_model ModelName [attribute:type attribute:type] [_index:name,owner_id+owner_type,active,...] [--fixtures] [--fgirl] [--machinist] [--odaddy] [--skip-timestamps] [--skip-migration] [--skip-tests]

...or the shortcut version:

./script/generate dmodel ...
./script/generate dmodel GoldFish name:string about:text _indexes:name --fgirl
./script/generate dmodel Frog name:string about:text _indexes:name,name+about --fixtures
Loading

0 comments on commit a0f1ab4

Please sign in to comment.