Pivotal Labs

Kelly Felkins's blog



Standup 7/28/2008

edit Posted by Kelly Felkins on Monday July 28, 2008 at 04:17PM

Interesting

Ask for Help

We upgraded to rails 2.1 and polonium and our rspecs are not running on CI, but run fine if you simply use rake on the command line.

Check to see if you are using the rake extensions in pivotal core bundle.

Using setTimeout() to wait for DOM to update in JsUnit does not work.

Using setTimeout in tests is not going to do what you want, unless you mock setTimeout. Basically, setTimeout kicks off another thread which is not likely to effect the current test.

Standup 7/24/2008

edit Posted by Kelly Felkins on Thursday July 24, 2008 at 04:45PM

Interesting

mysqldump and load

  • There was war story told involving software that's not generally available. However, one tidbit that may be of general interest is a reminder that you don't necessarily get a perfect copy of your mysql database when restoring from a dump of that database. Mysqldump by default writes the data of each table preceded by a DROP TABLE IF EXISTS and a CREATE TABLE statement. This covers you in most situations, but misses when new tables have been created since the dump was made -- those new tables are not deleted. They may not cause problems, but some systems are sensitive to the existence of those tables, such as rails and the schema_info and schema_migrations tables.

Ask for Help

  • question: Is merb hosting different from rails hosting?
    • answer: no

Standup 5/9/2008

edit Posted by Kelly Felkins on Friday May 09, 2008 at 05:43PM

Interesting

  • attr_readonly marks an attribute as, ah, read only -- use it to tell ActiveRecord that an attribute should not be a part of update operations. Rails uses attr_readonly internally with counter caches (search for "counter_cache" under ActiveRecord::Associations::ClassMethods) since counter caches are incremented/decremented directly in the database with sql. Without attr_readonly, subsequent updates of the counter_cache'd model would revert the counter to the value of the counter at the time the model was loaded.

Note: attr_readonly was either buggy or not exposed prior to 1.2.3. If you are using a version of rails prior to 1.2.3 you can do this instead:

def attributes_with_quotes(include_primary_key = true)
  attributes.inject({}) do |quoted, (name, value)|
    if column = column_for_attribute(name)
      # original:
      # quoted[name] = quote_value(value, column) unless !include_primary_key && column.primary
      quoted[name] = quote_value(value, column) unless !include_primary_key &&
          (column.primary || ["your_attributes", "listed_here"].include?(column.name))
    end
    quoted
  end
end

Ask for Help

  • help: Looking for recommendations on converting an existing schema to a new schema. We are considering dumping the existing schema to yaml (using ar_fixtures) and making the transformations there.
    • answer #1: One recent project had a "liberate" script that extracted information from the legacy database via sql statements and constructed AR model objects as necessary. The liberate script grew to some 1500 lines of code and was refactored many times.
    • answer #2: Another project did the data migration by first importing the legacy database and then using rails migrations as needed to transform the data to the new schema. Most of the migrations used sql for the transformations. These migrations did not have associated unit tests.
    • Please offer your suggestions in the comments.

Standup 5/8/2008

edit Posted by Kelly Felkins on Thursday May 08, 2008 at 04:25PM

Interesting

Ask for Help

Standup 5/7/2008

edit Posted by Kelly Felkins on Wednesday May 07, 2008 at 04:24PM

Interesting

  • "JsUnit has been updated" A new feature available on trunk is a "modern" ui. The modern ui has 2 panes, with errors and failures listed on the left. Clicking on an error displays details on the right. Get this by 1) installing trunk, and 2) specifying "ui=modern" as a parameter.

Screen grab of old and new ui for jsunit

Ask for Help

  • help: "Selecting an iframe with Selenium RC fu" It appears that selenium has the ability to select an iframe, but it doesn't work in selenium rc fu.
    • answer: Apparently the selenium provided in selenium rc fu is an older version

Standup 5/6/2008

edit Posted by Kelly Felkins on Tuesday May 06, 2008 at 04:21PM

Ask for Help

  • "RSpec only Hoe?" How do you convince Hoe to only run specs and not tests?
    • In the distance a dog barks...
  • "Is there a fun way to learn Ruby?" I have a 500 page book, but is there a fun way to learn Ruby?
    • (various pivots look at each other) "Pairing...of course"
  • "Use RSpec to verify deployment?" Previously I used Rspec with JRuby to create stories for a java project. It would be nice to have a deployment story. The plan would say "apache goes here", "mongrel goes there", "mysql goes over there". You could show the plan to your customer printed on a piece of paper and you could run it to do the deployment.

Standup 05/05/2008

edit Posted by Kelly Felkins on Monday May 05, 2008 at 04:36PM

Interesting Things

  • Interesting things were all about internal Pivotal Labs activities this week.

Ask for Help

  • Window.frames['name'] If we add a frame, then remove it, then add it again, it's still there.

    • [silence]
  • "What's that gem that draws a graph of your models?"

Sample RailRoad Output, model names changed to protect the innocent

Happy Path Testing With Selenium RC Fu

edit Posted by Kelly Felkins on Tuesday February 05, 2008 at 03:51AM

Selenium RC Fu is a fantastic system for testing Ruby On Rails applications. It is the blending of xUnit testing with Selenium. Selenium is a cool system that operates your browser as if a human were sitting there moving the mouse pressing buttons and keys.

Selenium RC Fu is also a remarkable example of the power of open source. It's selenium remotely controlled by rails and ruby. You can learn more about it by viewing the slides for Full-stack webapp testing with Selenium and Rails presented by my colleagues Alex Chaffee and Brian Takita at the SDForum Silicon Valley Ruby Conference.

Now that you are excited about Selenium RC Fu, by law I must inform you that this wonderful testing tool comes with some costs. First, this is the daisy cutter of testing -- problems will be detected, but it won't be too specific about those problems. A failed selenium test will likely only tell you some expected text was not present on the page -- you have to do some digging to discover the real problem.

It's also slow. To be fair, a lot of software is running to do this testing.

So use selenium testing sparingly. A good strategy is to restrict selenium testing to "happy path" testing. These happy path tests become a compliment to other more focused and faster unit and integration tests.

Teaching Your Tests To Report Unused Parameters

edit Posted by Kelly Felkins on Wednesday January 23, 2008 at 07:06PM

Recently I was about to check in some changes and did a last minute click through of the application. All of a sudden I'm staring at a stack trace. My tests were green and I had functional tests for the failing controller/action.

Tests are like pants -- they cover your backside while you focus on other things like adding features to your application. Suddenly I felt a breeze on my cheeks. Something was amiss.