Freezing gems with architectures

•January 24, 2008 • Leave a Comment

So I don’t ever lose this reference again (hopefully), here’s a reminder to myself (and maybe to you) that I want to freeze all my gems, and accommodate different architectures, so I should be using gems_with_architecture. See
usage, and browse the
repository.

Beanstalk Dashboard

•January 24, 2008 • 1 Comment

Since I’ve failed to get the beanstalk dashboard to display in my comments, here’s the “team leader” view that Mark was asking about in the last post:

Cogent Consulting Pty Ltd_ Dashboard — Beanstalk-1

Excellent support from Beanstalk

•January 23, 2008 • 3 Comments

We’ve started evaluating Beanstalk for our subversion repositories, and I had a problem this morning trying to commit to my second repository (the detail is that I was getting the message “Can’t create directory ‘/var/lib/subversion/beanstalk.storage/1911/webistrano/db/transactions/1-1.txn’: Permission denied”). Apparently this is a recurring problem on some accounts – probably a teething problem with the service.

Of course I’d rather not have any problems at all, but when I got this message I logged into the Beanstalk Campfire conversation, and within 10 minutes (9 of which were me getting a drink while Chris worked) Chris Nagele has fixed my problem and I was up and running again. Great stuff!

Interesting behaviour for defined?

•January 17, 2008 • Leave a Comment

I’ve been working with Pete Yandell’s Not-a-mock plugin, which I like a lot, and this morning a failing spec led me to some interesting behaviour for the Ruby defined? operator. Try these two things:

defined? arbitrary_attribute

defined? arbitrary_attribute=

With Ruby 1.8.5 on my Mac, the second one fails! From experimenting, it doesn’t seem like you can use any setter. The workaround (which I haven’t confirmed with Pete yet) is to use ’self.methods.include?(“arbitrary_attribute-”).

Don’t be dogmatic about dogma

•January 14, 2008 • Leave a Comment

A colleague of mine recently passed around a reference to “The Way of Testivus” from Agitar, and as promised on the front page I did indeed find that it was filled with “good advice on developer and unit testing” [although personally I haven't found testing my developers to be so useful :-) ]. But there was one page that I thought would be dangerous in the wrong hands, and it started like this….

Don’t get stuck on unit testing dogma

Dogma says:
“Do this.
Do only this.
Do it only this way.
And do it because I tell you.”

Dogma is infl exible.
Testing needs fl exibility.

Dogma kills creativity.
Testing needs creativity.

I’ve got a good grasp of what the author means, and I agree with the sentiment quite strongly. But I’m also confident that out there somewhere is someone new to automated testing who’s saying “oh, I’ve seen how other people do testing, and how could they have gotten it so wrong? I’m going to do things completely differently – I’m going to be creative”. The trouble with rejecting dogma is that “dogma” is often a great approach to 80% of the problem, and it often contains a great deal of wisdom that isn’t obvious to a newcomer.

I’m all in favour of rejecting dogma, but only after you’ve understood why those ideas might have become dogma in the first place, and you’re confident that you understand the reasons that particular dogma doesn’t apply in your specific context. Otherwise you’re just being dogmatic about rejecting dogma.

Installing Postgres on Leopard

•January 8, 2008 • Leave a Comment

Excellent article on installing Postgres from binaries on Leopard. Just make sure you have XCode installed first.

Installing Git on my Mac

•November 30, 2007 • 5 Comments

Inspired by Dr Nic’s post I wanted to install git on my Intel-based Mac. Why? There were two motivations – I frequently do work on the train or tram, and less often on planes, which is the reason Nic describes, but I also wanted to be able to commit mini-milestones on my local machine that I’m not really ready to commit to the “point of truth” on svn. This is the point where I reveal that I don’t do all of my programming test first, but that’s a longer thread. Suffice it to say that there are periods where I need to work to get the test coverage back over the threshold (currently set to 99.2%) and I don’t want to commit to svn until the test coverage is back there.

I installed git-core from MacPorts, but when I ran git-svn I didn’t have a “clone” command, which is what all the cool kids are talking about. I’m still not sure that I know precisely why that was the case, but in poking around on the web I found a few places with installation instructions, and eventually things were working, so I’ll add what I did to the pool (my main motivation is letting you know the problem I was trying to fix though).

  1. Followed the instructions from http://www.beyondthetype.com/2007/6/15/guide-to-installing-git-on-a-intel-based-mac to install the latest version of Git from source
  2. Re-installed subversion using the package from http://downloads.open.collab.net/binaries.html. Why? Because the last step in the previous instructions (setting the PERL5LIB) didn’t help, and I couldn’t find the svn-perl libraries anywhere. The instructions on http://speirs.org/2007/07/22/getting-git-svn-working-on-the-mac/ were helpful. After the subversion installation I had a directory /usr/local/lib/svn-perl, which did the job.
  3. Added export PERL5LIB=’/usr/local/lib/svn-perl’ to my .profile
  4. Added /usr/local/git-1.5.2.1 to PATH in my ,profile (early on, to make sure git was found here first)
  5. When I tried git-svn I got an error concerning Term::ReadKey when perl tried to prompt me for a password. I tried to install Term::ReadKey from CPAN interactively (sudo perl -MCPAN -e ’shell’
    , then ‘install Term::ReadKey’, but got “Can’t exec “./make”: No such file or directory at /System/Library/Perl/5.8.6/CPAN.pm line 4566.”. The answer was to change directory to ~/.cpan/build/TermReadKey-2.30 and execute the following commands: sudo perl MakeFile.pl; sudo make; sudo make test; sudo make install. Now I have the Term::ReadKey module installed!
  6. When I tried to ‘gitify’ after that, I got this message : “error: More than one value for the key svn-remote.svn.fetch: :refs/remotes/git-svn”. This seems to have been caused by previous failed attempts – removing the xxx.git file and running ‘gitify’ again seemed to work.

For people like me who are less than clear about the result, here’s what you get:

  1. A copy of your project in ‘../project_name.git’. This is your git working directory.
  2. Your repository is in .git in the git working directory.
  3. Change into the git working directory and start doing your stuff
  4. You’ll probably find these commands useful:
    • git status : tells you what’s uncommitted
    • git add : adds a new file to version control. “git add *” seems to do everything you’d want :-)
    • git checkout -f : reverts local changes
    • git commit -a : commits any modifications (but not new files) to the repository
    • git-svn rebase : merge svn changes into your git repository
    • git-svn dcommit : commits all your changes back to svn

And if I’d known it was going to be this hard when I started, I wouldn’t have.

Active Scaffold

•August 20, 2007 • Leave a Comment

After quite a bit of writing and business related non-programming work, I’ve got my hands back onto Rails. I’m actually crossing a few boundaries by writing an application to help me manage the invoices and employee payments for Cogent (the accounting system does a great job from a purely financial perspective, but I need something that can reflect our internal policies and procedures, which still makes it sound much grander than it is). I’ve also made a personal commitment to try to understand more about the gems and plugins that I’m using, which brings me to Active Scaffold.

I’ve used ActiveScaffold in the past for the administrative part consumer facing applications, but this time around I decided to have a closer look at what I could do with it. It’s still an exercise in progress, but I’ve been very impressed with what I’ve seen so far. Let’s look at three simple things first – ordering columns, changing the format of a column value, and filtering the displayed rows.

You tell a controller us use Active Scaffold for CRUD actions by adding a line to your controller. For example, if I want to use ActiveScaffold to maintain the Sale model object then I could set up a controller like this:

active_scaffold :sale

However, the active_scaffold method also takes an optional block, which you can use to customise the behaviour of the scaffold. In particular, there is a method to set the columns in the list view, that you can use like this:

active_scaffold :sale do |config|
config.list.columns = [:invoice_number, :customer, :amount, :status, :salary_package, :entry]
end

In this case I’ve specified that there will be six columns in the list view, in precisely the order specified in the array, where the symbols in the array correspond to accessor methods on the Sale model object.

Changing the format of a column is done outside the scaffold configuration, in a helper method. The :amount column is some amount of money, so it would be nicer to format is as a currency amount. The formatter needs to be named {column_name}_column, and it receives the entire model object as its only parameter, so a method to format the amount column in the Admin::SalesScaffoldController would look like this:

module Admin::SalesScaffoldHelper
def amount_column(sale)
number_to_currency(sale.amount)
end
end

Finally, filtering the displayed rows is so simple that I stumbled across the functionality by accident. In my Sales model, the status attribute is an enumerated value that contains, among other values, ‘Open’ and ‘Closed’. I set up a link to the controller like this

link_to :controller => 'admin/sales_scaffold', :action => 'index', :status => 'Open'

and expected to need to explicitly provide some filtering inside the controller. Instead, it worked before I’d done any coding at all! It turns out that any parameters that correspond to attributes are used to filter the results in the table. You can specify a single parameter, or you can specify multiple parameters, in which case they’ll be and’d together.

I’m really impressed with the capabilities of Active Scaffold, and I intend to explore them in more depth for applications where the tabular presentation of Active Scaffold is a good fit, and for providing functionality quickly while a user interface design is refined.

Introduction to Rails Workshop

•July 6, 2007 • 1 Comment

It’s been quite a while since I blogged, mainly because I’ve had my head down writing new workshop material. We’re running an introductory Ruby On Rails workshop on July 21 (just two weeks away now), and although it’s been a lot of effort I’m pretty happy with the way the material is working out.

One day isn’t very long to look at the equivalent of Java and a full Java web development stack, so rather than simply repeat what’s already available in books and screencasts we’re going to cover things that we find useful in our day to day development work. We’ll be giving attendees a whirlwind tour of Ruby, a brief guide to Rails, and then we’ll focus on tools and practices that aren’t quite so accessible to the ruby newbie.

So if you’ve heard about Ruby and/or Rails but haven’t made the plunge yet, or you know someone like that, go have a look at the course description, check out our pricing policies and send us a bid. At the moment all you need to bid is $100, so you may be getting some really cheap training!

New introduction to agile methods

•June 10, 2007 • 1 Comment

It’s been a while since I posted, and it’s mainly because I’ve been busy updating our introduction to agile methods. It’s done now, at least well enough to show people. Warning – this is a large (7mb) pdf file. It’s not intended to stand alone – the real value comes from someone talking it through – but you may still find it interesting, and there may be parts you can use (with accreditation please).