Red Squirrel Reflections
Dave Hoover explores the psychology of software development

Dave Hoover
dave.hoover@gmail.com

Categories
All [Atom]
Craftsmanship [Atom]
Dynamic [Atom]
Intersection [Atom]
Learning [Atom]
Links [Atom]
Polyglot [Atom]
Projects [Atom]
XP [Atom]
Old Blog

Obtivian Blogs

Andy Maleh
Colin Harris
Fred Polgardy
Jim Breen
Kevin Taylor
Todd Webb
Turner King
Tyler Jennings

Archives

March 2009 (1)
January 2009 (1)
December 2008 (1)
October 2008 (3)
September 2008 (1)
June 2008 (4)
April 2008 (3)
March 2008 (1)
February 2008 (1)
August 2007 (1)
July 2007 (1)
June 2007 (1)
May 2007 (4)
April 2007 (3)
March 2007 (5)
February 2007 (6)
January 2007 (6)
December 2006 (10)
November 2006 (5)
October 2006 (8)
September 2006 (8)
August 2006 (5)
July 2006 (12)
June 2006 (7)
May 2006 (5)
April 2006 (5)
March 2006 (4)
February 2006 (2)
January 2006 (5)
December 2005 (5)
November 2005 (3)
October 2005 (3)
September 2005 (6)
August 2005 (4)
July 2005 (7)
June 2005 (14)
May 2005 (6)
April 2005 (8)
March 2005 (9)
February 2005 (11)
January 2005 (16)
Old Archives

 

Fri, 29 Sep 2006

Rails Across 3 Oracle Databases

Over the last couple weeks at my main client, a small revolution has begun. This medium-sized Java shop is slowly, but surely adopting Ruby and Rails. It has been exciting to be a witness to the productivity gains and the willingness of people to learn something new. (Thanks in no small part to the simplicity and power of Watir.) I'll have more stories to share about this little revolution, but first I need to tell the story of a 30-minute development episode that Tyler and I just paired on.

Short version: Rails can integrate wonderfully across multiple legacy Oracle databases.

Longer version:

Over the course of my Rails development experience, I've (wrongly) assumed that trying to get Rails to do enterprise'y things is difficult. I'm not going to go into why I assumed this, but I would bet that there are others out there who have been scared into believing that they shouldn't try to swim against the Rails' convention of a single database with specific table-naming conventions.

My assumption was blown out of the water this morning when my pair and I needed to grab data from 2 other databases for a little Rails app that we created yesterday. The app was the brain-child of our client manager who needed a way to track the status of features and bug-fixes as they progressed through QA. We use XPlanner for iteration planning and iTracker for bug tracking, so she wanted to be able to refer to an XPlanner story id and/or an iTracker issue id for each QA task. We were able to deliver this to production in about an hour (thank you Capistrano) yesterday afternoon (yes, T is approaching zero).

This morning, our client said that she didn't want to see the issue and story ids, she wanted to see the name of the issue and story. For that, we needed to grab them from the XPlanner and iTracker databases. With much wringing of hands, and prepared to see our Rails productivity plummet, we Google'd around to see how to connect to multiple databases in Rails. First, we needed to configure our databases:

config/database.yml
production:
  adapter: oci
  username: foo
  password: 
  host: FOO:5353/BAR

planner:
  adapter: oci
  username: xplanner
  password: 
  host: (DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=...

tracker:
  adapter: oci
  username: itracker
  password: 
  host: (DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=...
Then we needed models to represent the issue and story.
app/models/story.rb
class Story < ActiveRecord::Base
end

app/models/issue.rb
class Issue < ActiveRecord::Base
end
Then we needed to create the associations between a QA task and the Issue and Story.
app/models/task.rb
class Task < ActiveRecord::Base
  belongs_to :issue
  belongs_to :story
  ...
end
Then we needed to configure Rails to use the appropriate connection and table names for Issue and Story.
config/environment.rb
Story.establish_connection "planner"
Story.set_table_name "story"

Issue.establish_connection "tracker"
Issue.set_table_name "issuebean"
And this just works:
task = Task.find(1) # from prod Oracle database
puts task.story.name # from XPlanner Oracle database
puts task.issue.description # from iTracker Oracle database

[/dynamic] permanent link

Thu, 21 Sep 2006

If you've ever wanted to_bool in Ruby

class Object
  def to_bool
    !!self
  end
end

[/dynamic] permanent link

Watir on Rails Update: It's all Relative

I made a backward compatible update to the Watir on Rails plugin to allow you to get rid of those nasty fully-qualified URLs in your Watir on Rails tests. To allow for this, I added some config-like class methods to specify the server and port (defaults to http://localhost:3000) in your TestCases. Here's a simple example, relying on the defaults:
class WelcomeTest < Test::Unit::TestCase
  include WatirOnRails

  def test_salutation
    browser = open_browser
    browser.goto("/")
    assert_match /Welcome Guest/, browser.div(:id, "banner").text
  end
end
A slightly more complex example, testing against a non-standard test server configuration:
class MyAccountTest < Test::Unit::TestCase
  include WatirOnRails
  server "10.2.4.143"
  port 3001

  def test_update_preference
    browser = open_browser("/squirrels/")
    browser.link(:text, /preferences/i).click
    
    browser.text_field(:name, "user").set("dave")
    browser.text_field(:name, "pass").set("test")
    browser.button(:name, "commit").click

    assert_match /<h2>Welcome Dave<\/h2>/, browser.html

    browser.checkbox(:id, "largeFont").set
    browser.button(:name, "commit").click
    
    assert_match /<h1>Welcome Dave<\/h1>/, browser.html
  end
end
If you're serious about building up a good Watir acceptance test suite, consider developing a site-specific lanaguage (example here).

[/projects/watir] permanent link

Mon, 18 Sep 2006

I want to have fun and come home with a smile and a hug for my wife and kids...

Pete Wright's job change spurred /\ndy to blog on passionate development. From Pete:
I just want to write cool software with talented passionate people, and make a difference in the world. I want to push the boundaries again like I did in the 80ís and early 90ís. I want to have fun and come home with a smile and a hug for my wife and kids instead of trudging through the door burdened with stress induced by boredom and corporate ineptitude.
From /\ndy:
If you canít feel passionate about your organization, then perhaps itís best to follow Martin Fowlerís advice: change your organization, or change your organization.
I couldn't agree more.

Over the past few months, I've experienced what Pete is describing. I'm driving my (short) commute home and I can't stop myself from smiling. I walk through the door ready to take on the chaos that kids of 2, 5, and 7 perpetuate and relieve my weary wife. It's worth it's weight in gold. And I've managed to keep my passion for developing software strong.

I'm reminded of a Paul Graham quote that I used in my Nurture Your Passion apprenticeship pattern.
Try to keep the sense of wonder about programming that you had at age 14. If you're worried that your current job is rotting your brain, it probably is.
And for those who find themselves stuck in a sea of mediocrity and afraid to stand out, a place where so many of us have watched passion diminish or even die, I'll close out with the words of Marianne Williamson:
Your playing small doesn't serve the world. There's nothing enlightened about shrinking so that other people won't feel insecure around you. We are all meant to shine, as children do. We were born to make manifest the glory of God that is within us. It's not just in some of us; it's in everyone. And as we let our own light shine, we unconsciously give other people permission to do the same. As we're liberated from our own fear, our presence automatically liberates others.

[/craftsmanship] permanent link

Sat, 16 Sep 2006

Rails TDD Boot Camp in Chicago's Loop

After incorporating the feedback from Obtiva's first Rails/TDD course, we've released our next offering scheduled for the week of November 6th in the Loop. It's a four-day hands-on course that introduces Ruby, Test-Driven Development, Ruby on Rails, and Ajax on Rails. We're also offering an optional fifth day for Enterprise Rails, which covers deployments, scaling and integration. Sign up here.

[/training] permanent link

Thu, 07 Sep 2006

Watir on Rails Plugin

After showing some hacked up examples of Watir and Rails integration at RailsConf and last Friday's Ajax on Rails addon, I decided that I was way overdue to venture into the exciting world of Rails Plugins. And just a few hours later, Watir on Rails was born.

Here's a quickstart...

  gem install [safari]watir
  ./script/plugin install svn://rubyforge.org/var/svn/watir-on-rails
  ./script/generator watir SuccessfulLogin
  ./script/server -e test
  rake test:watir

One of my goals for this first release was to make Watir on Rails have a similar feel to Rails Integration Tests, which provide a handy open_session method you can use to decorate your session object with a site-specific language. Well, if you know anything about Watir, it should not come as a surprise that Watir on Rails provides an open_browser method that does something similar. You can use open_browser to simply open a browser and use the excellent Watir API, or you can provide an optional block and write Watir on Rails tests methods like this...

  def test_login	
    browser = open_browser
    browser.login_with :username => "dave", :password => "test"
    assert_match /Welcome Dave/, browser.div(:id, "banner").text
  end

  def open_browser
    super do |browser|
      def browser.login_with(args)
        goto("http://localhost:3000/login")
        text_field(:name, "user[name]").set(args[:username])
        password(:name, "user[password]").set(args[:password])
        button(:name, "login").click
      end      
    end
  end

[/projects/watir] permanent link

Tue, 05 Sep 2006

An Impromptu Ruby/Rails/TDD Library

One of the highlights of last week's course for me was seeing the level of interest that all of the students had in the impromptu library I assembled for them. I encouraged people to borrow the books for the week and it was cool to see them float around the room and disappear every night. As someone who has learned everything I know about programming from reading, pairing, and exploring on my own, it was gratifying to see their enthusiasm for learning. If you're interested, here's the library:

[/training] permanent link

Fri, 01 Sep 2006

Reflections on Leading Obtiva's first Rails/TDD Course

I just wrapped up the final day of our first Rails/TDD Course. What a week! I certainly have a newfound respect for teachers: after our first day my throat hurt, my feet ached, and I was totally drained. But by the end of the week I felt like I was getting the hang of it. This last day was particularly fun, as we ajaxified the Rails app that we built over the first three days. (BTW, the Rails app we built was a pseudo-replacement for XPlanner.) We wrapped up the course by creating a story/iteration management page that allowed us to drag-and-drop stories between iterations and the backlog.

A few reflections from my experiences watching an excellent bunch of Ruby/Rails newbies learn to develop in Ruby/Rails:

  • Although it's a nice idea in theory, Rails' pluralized model/table relationship causes continual typos and confusion around when something should be plural and when something should be singular.
  • Speaking of typos, although TDD mitigates some of the loss of feedback from Ruby's lack of IDE-error-highlighting support, a single typo in a Ruby program can be painfully hard to find. This is particularly painful for people accustomed to Eclipse or IDEA in Java, which go the extra mile to point directly at any problems in your code the moment you type it.
  • RadRails is a great Rails IDE. I particularly liked its Plugin tab. I highly recommend it to anyone coming into Rails from Java on Eclipse.
OK, that's all for now. I'm signing off for the rest of the holiday weekend. I need a break!

[/training] permanent link


powered by blosxom