Show Me The Money-5 - Feeling lucky today??

Iteration#1 : Day 5/10

Hmmm... I'm not getting the right vibe from our acceptance test.
An inflow entry would have a Date and a Description in addition to the amount. Our AccTest does not seem to indicate that.

Seems like we should be replacing our current table, with an ActionFixture+RowFixture combo. (Not its not a ploy to get the remaining fixture types into this example.)

An ActionFixture would simulate how the user would use an imaginary system, adding records one at a time.

The RowFixture would verify that all the inflow records have been persisted. Hmm.. I’ll quickly write up the tables and write the fixtures later post implementation of this feature. (I know I’ll be ambushed again. I’m gonna lie on the couch and get my strength back.. too much fitnesse for now.)

File: http://localhost:2345/ShowMeTheMoneyMain.TestsForTrackingInflowsS6

!define COMMAND_PATTERN {ruby -I %p "L:/ruby_home/lib/ruby/gems/1.8/gems/fit-1.1/bin/FitServer.rb" -v}
!path "L:/Gishu/Ruby/Rails/ShowMeTheMoney"

# Lucky Charm : Sample Test Fixture to check if Ruby FitServer is reachable
!|eg.ArithmeticFixture|
|x|y|+|-|*|/|
|1|1|2|0|1|1|

#!|AcceptanceTests.TestTrackInflows|
#|amountReceived|currentBalance()|
#|100|100|
#|500|600|
#|1200|1800|

!|fit.ActionFixture|
|start|EnterInflowRecords|
|enter|inflow|2008-01-13|PayDay|5000|
|check|currentBalance|5000|
|enter|inflow|2008-01-15|Interest|1000|
|check|currentBalance|6000|
|enter|inflow|2008-02-13|PayDay|5000|
|check|currentBalance|11000|

!|GetInflowRecords|
|receivedOn|description|amount|
|2008-01-13|PayDay|5000|
|2008-01-15|Interest|1000|
|inflow|2008-02-13|PayDay|5000|
Let take a look at our schedule..
We get 1 point each for 'Iteration planning',‘Setting up Fitnesse’ and ‘Write Acceptance Tests’. Making the tests pass would be part of the implementation task.
Burndown charts are brutally honest. The Y axis shows ideal hours pending (We now have 13 ideal hours of work left in this iteration) The X axis shows days into the iteration (We are at end of Day 4). We can easily create one from our iteration plan and the items we have completed.
As of now looks like we'll slightly overshoot.

So lets get cracking.. I’m upbeat.. feeling lucky today
First thing, the UI. The inflow record as mentioned before has 3 fields. From the CRUD (Create, Retrieve, Update and Delete) - we would need Create for sure. So lets start with that first.

Switch to our rails project dir.
First create our DB called money. Rails uses 3 DBs for different purposes as shown below.
I’m sloppy and impatient. After some mistakes and furious rectification.. Now I have to drop the Db and create it again. This time, we’ll put in a text file to save typing if something like this happens again.

File: ShowMeTheMoney/db/CreateDB.sql

drop database if exists money_development;
drop database if exists money_test;
drop database if exists money_production;
create database money_development;
create database money_test;
create database money_production;
grant all on money_development.* to 'gishu'@'localhost' identified by 'kaChing';
grant all on money_test.* to 'gishu'@'localhost';
grant all on money_production.* to 'gishu'@'localhost';

Now lets create the table. We’ll call it ‘credits’. So once again, we create a file DB\Create.sql like in the book.

File: ShowMeTheMoney/db/Create.sql

drop table if exists credits;
create table credits (
id int not null auto_increment,
created_at datetime not null,
description varchar(100) not null,
amount decimal(10,2) not null,
primary key (id)
);
Note: created_at is a special name which will get Rails to update that column auto-magically with the time of record creation. See Pg 227 of AWDWR First Ed

Next get it into the db, at the command prompt
  • >mysql -u gishu -p money_development
Now edit the config\database.yml file to help rails find-n-use our 3 DBs, modify each of the three groups in there as shown below.

File: ShowMeTheMoney/db/config.yml

development:
adapter: mysql
database:
money_development
host:
localhost
username:

password:
Now we run the Rails generate script to auto-create our classes. Rails 2.0.2 says it needs gem 0.9.4+ So lets get in from the online store
  • >gem update --system
  • >ruby script/generate scaffold Credit Inflow

Now it says --- "wrong number of arguments (1 for 2)"
We’re nearing the straw that will break this camel’s back. It’s times like these I’m relieved I don’t have a gun. Google Google.. Oh my god Rails 2.0 has real sharp horns – so much for ‘No surprises’. Scaffolding has been banished to an on-demand plugin! The only good blog-post (by Fairleads) I find recommends going back to 1.2 if you need to work with old tutorials / books etc.
Since I don't have the luxury of learning rails 2.0 just yet... You don’t have to ask me again.. Excuse me while I rollback my dev environment. Rails 1.2.6 it is. Install, create project, run scaffold generator.
“Can't connect to MySQL server on 'server' (10061)”

Just Great ! I guess I wasn’t that lucky today after all.
MySql though has great docs - http://dev.mysql.com/doc/refman/5.0/en/can-not-connect-to-server.html
Trying all those diagnostic steps showed me a diff. My port setting is 3307 not 3306 as in the doc. Edit database.yml, Add port: 3307 to all 3 groups. Restart Webrick.
Run scaffold generator again. Done. Browse to http://localhost:3000/Inflow and I can See! I can see the blessed view!!
Phew! That's it for today.. .

No comments:

Post a Comment