Building Tempo with Rails, Part II
Posted by Brian Sam-Bodden

Welcome back to part II of this series. Like I mentioned at the end of the first post; now we start the real work.
BDD, TDD and DDD
The sentence below summarizes what our development strategy will be:
"We are going to flesh the domain (DDD) with behaviours using (BDD) that we will express as tests (TDD) before writing any code"
We are going to be using RSpec, a Ruby XUnit framework that facilitates the writing of tests that test behavior rather than state, in the spirit of Behavior-Driven Development (BDD). With RSpec we will write the tests that will guide the development of our application. We will try to stick with Test-Driven Development (TDD) as closely as possible. RSpec can be thought of as a domain specific language for behavior testing via expectations.
If you have been using Test::Unit and you want to use RSpec you don't have to chose one over the other. Although if you have to make a choice, RSpec will give you more readable tests.
If you want to get some background on the ideas behind BDD take a peek at
Installing RSpec
As we did with Restful Authentication plugin we'll use Piston to install RSpec:
piston import svn://rubyforge.org/var/svn/rspec/tags/CURRENT/rspec vendor/plugins/rspec Exported r2563 from 'svn://rubyforge.org/var/svn/rspec/tags/CURRENT/rspec' to 'vendor/plugins/rspec'
Installing RSpec On Rails
An RSpec plugin that integrates with Rails exist which gives you the ability to create specs (read behavior tests) for your models, views, controllers and helpers. To install the RSpec On Rails plugin we again use Piston:
piston import svn://rubyforge.org/var/svn/rspec/tags/CURRENT/rspec_on_rails vendor/plugins/rspec_on_rails Exported r2563 from 'svn://rubyforge.org/var/svn/rspec/tags/CURRENT/rspec_on_rails' to 'vendor/plugins/rspec_on_rails'
To create the necessary RSpec directories and bootstrap code you need to run the rspec rake task:
script/generate rspec
exists spec
create spec/spec_helper.rb
create spec/spec.opts
create previous_failures.txt
create script/spec_server
create script/spec
Building Tempo's Domain
Now we are ready to tackle the domain of the application
Initial Domain Model
I know it is a cliché but I actually modelled the domain on a paper towel which I later scanned (Jim Weirich is much more classy and uses fine napkins). Below is my first pass at the nouns that immediately came to mind when thinking about tracking time in the context of a project at a consulting firm:

Based on the noun list above I created a simple UML-like diagram (in later issues of this blog I'll create something nicer):

The list below spells out what my thinking was when creating this model:
- A User is associated with a Person *
- A User can be part of zero or more Projects
- A Project belongs to a Client *
- A Project has some Project Activities associated which are a subset of a global list of Activities
- A TimeEntry represents time entered against a project by a User in the context of a particular Activity
(1*) my thinking here is that I would have non-user entities in the system therefore I wanted to separate the Person/People (3*) don't know yet if a Client is a Person, User or other Entity
Read more...

