Blank: A Starter App for r_c and shoulda Users 13

Posted by james
on Thursday, October 09

Bort was released recently. Peter Cooper speculated that "...it could well catch on as the de facto bare bones / generic Rails application". But, what about us non-RSpec users? There are dozens of us, I tell you. Dozens!

We build a lot of apps at GiraffeSoft — we love to experiment with whatever ideas excite us on any given day. We're all sick of editing restful_auth code, and moving tests over to Shoulda and the one assertion per test pattern. Bort doesn't suit our needs. So, blank was born.

Right now, it's pretty simple. It has authentication, and forgot password. That's about it. But, it's no biggie. Since blank creates your new app as a git repo that shares history with blank's repo, you can pull in changes we make at any time. So, when we finally get around to implementing openid support, you'll get it for free, if you start with blank.

Vendored

All of our standard tools (and rails) are vendored:

  • active_presenter
  • andand
  • attribute_fu
  • hoptoad
  • mocha
  • rake
  • restful_authentication
  • ruby-openid
  • will_paginate

Installation

Installing blank is as easy as running a rake task. Except that blank uses thor instead, because it’s the new hotness, and it supports remote tasks.

Just install thor:

$ sudo gem install thor

…then install blank’s thor tasks:

$ thor install http://github.com/giraffesoft/blank/tree/master%2Fthorfiles%2Fblank.thor?raw=true

…then you’re ready to create a new app with blank:

$ thor blank:new_app the_name_of_my_app the@git.repo.it.will.live.in

That’s it! The thorfile will display a couple of rake notes where you should replace blank app with your app's name. Also, you'll want to fill in your hoptoad API key in config/initializers/hoptoad.rb.

If we improve the thor file, all you have to do is run:

$ thor update blank

before creating your next app, and you’ll get the changes automagically.

Development

All development will be done at the github repo. Fork away :)

Credits

Blank was created by me, with contributions from Daniel Haran.

Comments

Leave a response

  1. Lucas HúngaroOctober 09, 2008 @ 10:34 PM

    Yeah, you know, Shoulda is waaaay better than RSpec! ;)

    But, wait, where's factory_girl???

  2. NileshOctober 10, 2008 @ 12:37 AM

    Check out appstarter ( http://appstarter.latticepurple.com ). It comes with a few more additional niceties that we tend to repeat anyway.

    • Blueprint based CSS layout
    • Front controller with a welcome page
    • Admin interface using scaffolding_extensions gem - protected behind admin login
    • PNG javascript and CSS fixes for IE
    • protection against mass assignment attacks
    • RAWK production log analyzer
    • Hoptoad
    • and my fork of resource_controller which provides permission methods inside models and views that adapt to it.

    cheers nilesh

  3. Peter CooperOctober 10, 2008 @ 01:35 AM

    Awesome. But what's r_c?

  4. Jim NeathOctober 10, 2008 @ 02:26 AM

    @Peter - rc is resourcecontroller: http://jamesgolick.com/tags/resource_controller

    @James - It's good to see other people creating starter apps. We've been using Bort internally for a while and it easily knocks off between half a day to a day when it comes to new projects. Keeping it DRY yo!

  5. Alistair HoltOctober 10, 2008 @ 04:21 AM

    @Lucas - I totally agree, where is factory_girl??

  6. Dan CroakOctober 10, 2008 @ 08:00 AM

    These Rails templates are a great idea and Blank is a great name for one. Been hearing rumblings of thor, but now I "get it." Like what you did there.

    We've been working on one at thoughtbot, as well, called suspenders: http://github.com/thoughtbot/suspenders which we'll release sometime before the Rails Rumble, which I think will be the welcome party for these templates.

    One thing we're still missing in our template that I want is better Rails scaffolding with Shoulda and Factory Girl. Does Blank have anything like that?

  7. Mathieu MartinOctober 10, 2008 @ 08:14 AM

    @Lucas and @Alistair

    There's not factory girl, indeed. Look however at lib/testdatafactory.rb. It's a simple pattern we're using at GiraffeSoft to generate helpers. Putting the following in the test_helper.rb:

    data_factory :post, :title => "Blank Rocks", :body => 'lorem'

    gives you 4 methods: createsite (does a create!), buildsite (does new) and hashforsite (both as an instance and a class method).

    All of these accept an options hash to override the defaults we specify to datafactory in the testhelper.

    In the test_helper, we always make sure to include all the parameters necessary to create a valid instance.

    So in our tests, when we just need the bare minimum to have a valid object -- whatever its attributes -- we use any of these with no parameters:

    create_post

    When our test is going to depend on a specific attribute being set, we specify that one:

    build_post :title => nil

    Our factory is extremely straightforward and does the job well for us, and it's under 25 lines of code :-)

    http://github.com/giraffesoft/blank/tree/master/lib/testdatafactory.rb

  8. Mathieu MartinOctober 10, 2008 @ 08:17 AM

    @James

    Your comments support Markdown or what?

    This is a test :-)

    test_data_factory.rb

  9. James GolickOctober 10, 2008 @ 08:17 AM

    Thanks for the feedback guys.

    Factory girl is very cool, but I find it to be overkill for my purposes. I use a ~10-line macro that you can find in the lib directory of blank, called data_factory.

    @Dan - resource_controller has scaffolding that automatically adapts to your toolset. If shoulda is installed, it spits out shoulda tests. Same with RSpec, and Haml. If you're looking for a starting point for better scaffolding, you should check out the r_c scaffold_resource generator.

  10. Daniel HaranOctober 10, 2008 @ 08:31 AM

    Here's to hoping lots of people fork Blank.

  11. Lucas HúngaroOctober 10, 2008 @ 09:03 AM

    @Mathieu and @James - nice factory solution. Once again, congrats! :)

  12. KeeKeeOctober 11, 2008 @ 07:41 PM

    I'm totally and utterly lost. What's r_c and who or what is factory girl. I must have missed soemthing. Got any suggestions?

  13. Alex SharpNovember 02, 2008 @ 01:37 AM

    Awesome, awesome, awesome. Did I mention this is awesome?! Great work, thanks a lot guys.

Comment






Clicky Web Analytics