Hacking Journal [2006/01/30]
h3. Hi ho, hi ho, Refactor as I go
[2006/01/30]
Today I tried to slim down my huge test code for my project at work. Slimming down 1500 lines of working test is hard. That is where test_helper.rb comes in; any assertion added in there is accessible to all your tests. Since I have layers of users in my application, one major test is to make sure they can see or not see certain pieces of content. Using a test_helper.rb custom assertion:
def assert_online(id, action='show')
get action, :id => id
assert_response :success
assert_template action
assert_not_nil assigns(:content)
assert assigns(:content).valid?
end
I can replace
def test_show_user
@request.session[:user] = @user
get :show, :id => 1
assert_response :success
assert_template action
assert_not_nil assigns(:content)
assert assigns(:content).valid?
end
with
def test_show_user
@request.session[:user] = @user
assert_online(1)
end
It also works on other methods if I use assert_online(6, ‘show’).
I also had a chance to hack on eXPlainPMT a bit tonight. Since the head developer is in the middle of the move I had the chance to just hack on some of the code that I wanted to. The codebase for it changed again (this time back to the 1.3.x version) so I know have to relearn how everything is connecting. Needless to say I will be picking the low hanging fruit for a while until I get back up to speed.
Eric Davis
