Permalink
Browse files

Major refactoring - actually more of a re-write. Generates robust tes…

…ts (the old ones where a bit sloppy). Added Shoulda test generation.
  • Loading branch information...
1 parent 603f73c commit a0f1ab42de00da23c7387f4aa2299d049bbdbd79 @grimen committed Jul 22, 2009
Showing with 941 additions and 543 deletions.
  1. +24 −15 README.textile
  2. +17 −4 TODO.textile
  3. +14 −6 config/scaffold.yml
  4. +2 −5 generators/dry_model/USAGE
  5. +68 −145 generators/dry_model/dry_model_generator.rb
  6. +1 −1 generators/dry_model/prototypes/active_record_migration.rb
  7. +2 −2 generators/dry_model/prototypes/active_record_model.rb
  8. +3 −0 generators/dry_model/prototypes/fixture_data/active_record_fixtures.yml
  9. +4 −0 generators/dry_model/prototypes/fixture_data/factory_girl_factories.rb
  10. +8 −0 generators/dry_model/prototypes/fixture_data/machinist_blueprints.rb
  11. +0 −3 generators/dry_model/prototypes/test_data/active_record_fixtures.yml
  12. +0 −4 generators/dry_model/prototypes/test_data/factory_girl_factories.rb
  13. +0 −8 generators/dry_model/prototypes/test_data/machinist_factories.rb
  14. +20 −0 generators/dry_model/prototypes/tests/shoulda/unit_test.rb
  15. +9 −3 generators/dry_model/prototypes/tests/test_unit/unit_test.rb
  16. +2 −2 generators/dry_model/templates/models/active_record_migration.rb
  17. +1 −1 generators/dry_model/templates/models/{test_data → fixture_data}/active_record_fixtures.yml
  18. +5 −0 generators/dry_model/templates/models/fixture_data/factory_girl_factories.rb
  19. +9 −0 generators/dry_model/templates/models/fixture_data/machinist_blueprints.rb
  20. +0 −5 generators/dry_model/templates/models/test_data/factory_girl_factories.rb
  21. +0 −9 generators/dry_model/templates/models/test_data/machinist_factories.rb
  22. +23 −0 generators/dry_model/templates/models/tests/shoulda/unit_test.rb
  23. +11 −3 generators/dry_model/templates/models/tests/test_unit/unit_test.rb
  24. +4 −5 generators/dry_scaffold/USAGE
  25. +113 −145 generators/dry_scaffold/dry_scaffold_generator.rb
  26. +52 −52 generators/dry_scaffold/prototypes/controllers/action_controller.rb
  27. +4 −4 generators/dry_scaffold/prototypes/controllers/inherited_resources_controller.rb
  28. +107 −0 generators/dry_scaffold/prototypes/controllers/tests/shoulda/functional_test.rb
  29. +44 −32 generators/dry_scaffold/prototypes/controllers/tests/test_unit/functional_test.rb
  30. +1 −1 generators/dry_scaffold/prototypes/helpers/helper.rb
  31. +9 −0 generators/dry_scaffold/prototypes/helpers/tests/shoulda/unit_test.rb
  32. +5 −1 generators/dry_scaffold/prototypes/helpers/tests/test_unit/unit_test.rb
  33. +9 −9 generators/dry_scaffold/prototypes/views/builder/index.atom.builder
  34. +7 −7 generators/dry_scaffold/prototypes/views/builder/index.rss.builder
  35. +6 −6 generators/dry_scaffold/prototypes/views/haml/_item.html.haml
  36. +3 −3 generators/dry_scaffold/prototypes/views/haml/edit.html.haml
  37. +5 −5 generators/dry_scaffold/prototypes/views/haml/index.html.haml
  38. +1 −2 generators/dry_scaffold/prototypes/views/haml/layout.html.haml
  39. +3 −3 generators/dry_scaffold/prototypes/views/haml/new.html.haml
  40. +6 −6 generators/dry_scaffold/prototypes/views/haml/show.html.haml
  41. +6 −5 generators/dry_scaffold/templates/controllers/action_controller.rb
  42. +1 −1 generators/dry_scaffold/templates/controllers/inherited_resources_controller.rb
  43. +90 −0 generators/dry_scaffold/templates/controllers/tests/shoulda/functional_test.rb
  44. +47 −38 generators/dry_scaffold/templates/controllers/tests/test_unit/functional_test.rb
  45. +9 −0 generators/dry_scaffold/templates/helpers/tests/shoulda/unit_test.rb
  46. +5 −1 generators/dry_scaffold/templates/helpers/tests/test_unit/unit_test.rb
  47. +176 −0 lib/dry_generator.rb
  48. +5 −1 tasks/dry_scaffold.rake
View
@@ -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
@@ -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
@@ -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>
@@ -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@.
@@ -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:
@@ -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!
View
@@ -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'
View
@@ -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
@@ -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
Oops, something went wrong.

0 comments on commit a0f1ab4

Please sign in to comment.