Archive for March, 2008

Code After Rcov

The report generated by rake spec:rcov is good and helps me drop some old habit that i got from other than ruby languages. Take this method for instance:

48   def status
49     case status_code
50     when 'A'
51       :active
52     when 'Z'
53       :complete
54     else
55       nil
56     end
57   end

The line 54 & 55 were never tested, because the status codes are nothing supposed to be other than A or Z.

Ruby will return nil in any other case anyway, so I rewrote it to:

48   def status
49     case status_code
50     when 'A'
51       :active
52     when 'Z'
53       :complete
54     end
55   end

nice, 100% covered.

Comments

find(:last) for what?

find(id), find(:first) and find(:all) is all fine, but why do we ever need find(:last)

It is shocking, that find(:last) patch made to the core without many “+1”.

Comments

Nastiness of restful_authentication RSpecs

I use the plugin restful_authentication to handle logged in sessions. It makes modules to include in your controller and also makes specs if you have spec directory. All fine, but I cannot live with one login session for the websites; I need “admin” and “client” area. Each session will be verified against separate models, i.e. Client and User models in this case. The problem was with the spec for these tests that were generated by the plugin.

The generator also creates authenticated test helpers, which in my case lie in their own namespace. so I have:

/lib/client/authenticated_test_helper.rb
/lib/admin/authenticated_test_helper.rb

But the typical spec generated looks like this:

require File.dirname(__FILE__) + '/../spec_helper'

# Be sure to include AuthenticatedTestHelper in spec/spec_helper.rb instead.
# Then, you can remove it from this and the functional test.
include AuthenticatedTestHelper

describe User do
...

In my case I had to modify it to include from Admin::AuthenticatedTestHelper or Client::AuthenticatedTestHelper as it fits the model.

For no obvious reason, the tests fail. I finally found the problem with the generated spec that included the module

include Client::AuthenticatedTestHelper
describe User do
...

It includes the AuthenticatedTestHelper outside the describe block. This gets into trouble with another model spec when it is also called AuthenticatedTestHelper but different namespace.

Anyway, the fix is to include with in the describe block, as in:

describe User do
  include Client::AuthenticatedTestHelper
...

Comments

Project, Tasks & Time

Previously at work I used to do lots of Excel this, Excel that work. So I have a thing for Excel and I once built a time sheet for a friend of mine then. It was a simple and flexible task management excel sheet.Oh yea, a testimonial from the user:

Makes my life easy – It records times and dates automatically. Simple and stupid – Easy to use and Allows me to make changes to the auto recorded info. It helps me to fill in our weekly time sheet to say how much time I spent on a task

It is free to download Time log excel sheet & do whatever with it.

About Macros

I suggest you set Excel Macro settings to medium, so on opening the file, it would ask your permission to enable them.  The macro is in fact only there to help you with automatic time logging, add colours and install virus… am only joking.

Update: Download Time logger Excel Sheet from Github.

Comments