I've customized the Shoulda Generator gem from technicalpickles with my own views and defaults. I'm not a fan of haml and will eventually remove it from this fork. I also do not require blueprint so that will be removed as well.
One night at a Boston Ruby hackfest, I finally got sick of using the Rails default generators, and then having to twiddle them to meet my needs and tastes. This includes using things like:
The next morning, I was struck awake at 5am with the inspiration to start implementing it. shoulda_generator is the result of this effort.
- A new model
- A migration for the model
- Skip using --skip-migration
- A factory defined with factory_girl
- Skip using --skip-factory
- A shoulda unit test with a few simple 'should's
- shoulda installed as a plugin
- factory_girl gem installed
- factory_girl_on_rails installed as a plugin
- Everything included in shoulda_model
- A controller (sans unnecessary comments)
- Choice of haml or ERB (default)
- Specify which with the --templating option
- Skip using --skip-layout
- A helper
- A shoulda functional test using factory_girl factory, using should_be_restful or not
- Specify with --functional-test-style, accepts basic and should_be_restful
- shoulda installed as a plugin
- factory_girl gem installed
- factory_girl_on_rails installed as a plugin
shoulda_generator is available as a gem via GitHub. If you haven't done so already, you need to setup GitHub as a gem source:
$ gem sources -a http://gems.github.com
Now you can install it:
$ sudo gem install jeffleeismyhero-shoulda_generator
Usage is the same as the default Rails generators.
$ script/generate shoulda_model post title:string body:text published:boolean
$ script/generate shoulda_scaffold post title:string body:text published:boolean
You can override the default values for templating and functional_test_style by placing a .shoulda_generator file in your home directory.
Here's an example .shoulda_generator
:
:templating: erb # supported options: haml|erb
:functional_test_syle: basic # supported options: should_be_restful|basic
Source is hosted on GitHub: https://github.com/jeffleeismyhero/shoulda_generator/tree/master
You can do the usual fork/commit cycle until you have something ready to share. Send pull requests my way.