Thursday, March 30, 2006

create YAML Fixtures

Very cool.
This makes it very simple to convert your data into YAML fixtures to be used in tests.

Saturday, March 25, 2006

Test Databases - do a rake migrate if you change the structure

Some of the functional tests were failing because of a missing column in a table. Took us some time to figure out the real issue.

Added an extra column 'x' using rails migration. Ran the functional tests to make sure that they all pass.

They failed, complaining that there was no column 'x' present.

Decided to check the test_database to see if that new column was created in the table. And it was not.

The way rails handles testing, it creates a test_database using the structure of the tables in the development_database and populates the tables using the fixtures. Hence if the development_database is not current (w.r.t the migration scripts) then the test database too does not have the latest structure.

Ran the migrate task. Got the development_database synched up and ran the tests.
Voila. All passed :-)

Tuesday, March 21, 2006

Puzzling behavior

Was debugging some code today that was working on a windows box, but was not working in a Linux box.

class MapController
model :Roads

def draw_roads
render :text => "No Routes to show" if no_roads
end
end
On the linux box, draw_roads would always look for a draw_roads.rhtml template and go ahead with the execution. Whereas in a Windows box, the check would be performed and accordingly a render of "No Routes to Show" would happen or draw_roads.rhtml would have gotten rendered.

After some debugging and placing of puts statements in the code figured that the issue was with the

model :Roads

bit. It should have been

model :roads

But still not sure why this worked on a windows box and not a linux box !!

Javascript development

Stumbled upon an interesting Plugin for Eclipse today. JSEclipse. Very useful when you dabble a bit in Javascript at work and during play

Saturday, March 18, 2006

Ruby Hacking Guide

Awesome News.

Vincent has started translating the Ruby Hacking Guide into English !!
Currently only one chapter has been translated. And its awesome. The original book is in Japanese. Had tried converting it into English using Google Translate, but things did not make too much sense.

After reading the chapter on Objects in the translated version, lotsa small things started falling into place. Like for example I finally understood why we have symbols in Ruby.

Great going Vincent.

Tuesday, March 07, 2006

require 'pain_in_the_ass'

disclaimer: I might be doing something wrong, hence the experience.

Using Stubs in Rails has been one hell-of-an-experience.
The concept of using mocks/stubs in Rails is very simple (just open a class and add stuff to it). But in practise, this has never been the experience. Whenever I have tried to use mocks, trying to require the original file has been very painful.

For example I have this file called song_search.rb under app/controllers
Tried writing a mock under /test/mock

require File.dirname(__FILE__) + '/../../../app/controllers/song_search'
class SongSearch
def page
end
end

But the tests indicated that this file was not being picked up !! Tried all combinations to get the require right. To no avail. Im sure Im doing something wrong. It cant be that difficult.

Anyways in the end, I just added this to the test class

require 'song_search'
class SongSearch; def page() @page end; end

That worked. But gotto find a better way to do this. :-(

sqlite3 database meta information

After being pretty unsuccesful trying to read the docs for sqlite3 table metadata, last evening we managed to pull these sql statements out of the rails sqlite3 adatapter code:

PRAGMA table_info(table_name)
SELECT name FROM sqlite_master WHERE type = 'table'
PRAGMA index_list(table_name)
PRAGMA index_info('index_name')



Thursday, March 02, 2006

Faster testing with Rails

Just came across this article Faster testing with Rails 1.0 by Mike Clark
Decided to check out the impact of it on our application.

Currently we are using both transactional_fixtures as well as instantiated_fixtures.

UnitTests
Finished in 2.197282 seconds.
48 tests, 247 assertions, 0 failures, 0 errors

Functional Tests
Finished in 3.798338 seconds.
56 tests, 226 assertions, 0 failures, 0 errors

on turning off instantiated_fixtures (as suggested by Mike)

UnitTests
Finished in 1.999902 seconds.
48 tests, 247 assertions, 0 failures, 0 errors

Functional Tests
Finished in 3.59077 seconds.
56 tests, 226 assertions, 0 failures, 0 errors

Not too much of a difference. But then we still dont have too many tests and I guess every second counts.

Extension vs Mixin