Joe Moore's blog
At Pivotal, some of our client projects use plugins from our home-grown social networking platform and rely on Desert to tie them all together. To test this package of plugins we created a project that contains all of our Desert plugins and wrote some rake tasks that run all of their tests. Great, right?
Mostly. We want to ensure that our plugins have the absolute minimum dependencies to function. Let's pretend we have an UserAuth plugin and a SocialPivots plugin, where UserAuth has no dependencies, but SocialPivots depends on UserAuth. We would like to test these the to plugins in isolation. But, with Desert doing it's job so well, our UserAuth plugin could have a dependency on the SocialPivots plugins' models or tables and we would never know it. Everything from SocialPivots is mixed-in and loaded into memory, and all of its migrations have executed, at the time we are running UserAuth's tests.
What we need is a way to tell Desert to load only the plugin under test, plus its dependencies listed in init.rb. Hacking Desert and Rails to allow us to specify which plugins to load turned out to be pretty easy. Check it out (full gist here):
Interesting Things
You can never return: ... except when you can. From a block, that is. Returning from a block rarely works:
result = ['one', 'two'].each do |x| return x end => LocalJumpError: unexpected returnBut, you can pass
nextandbreakarguments, which will allow you to assign return values from the block:result = ['one', 'two'].each do |x| break(x) end => "one" result = ['one', 'two'].each do |x| next(x) end => ["one", "two"]
You can return from a lambda, though.
Check out Google Page Speed, which is like Yahoo's YSlow, only "better."
Page Speed is an open-source Firefox/Firebug Add-on. Webmasters and web developers can use Page Speed to evaluate the performance of their web pages and to get suggestions on how to improve them.
Like chef? Love capistrano? Check out chef-deploy, which "... Uses the same directory layout as capistrano and steals the git remote cached deploy strategy from cap and adapts it to work without cap and under chef."
SFTUG FTW! Another successful SF Tracker User Group Meetup on 06/24. Watch for future events on the Meetup site.
Ask for Help
"Has anyone implemented mutli-table (class table) inheritance in Rails, as apposed to single table inheritance (STI)?"
- There are some plugins that nobody has tried, such as inherits_from
- What about a view to represent the super set of tables and rows?
"We're looking for a dead-simple, drop-in JS rating or 'starting' plugin."
Check out the start-rating jQuery plugin. Any other suggestions?
At Pivotal, we are passionate about test driven development, keeping things DRY, and writing readable and understandable code. Satisfying all of these desires can be challenging, especially when writing test code. In particular, ActiveRecord extensions present several challenges: which models using an extension should we test? How do we both test our extension in isolation while also testing all model's usage of that extension? Is it even worth it?
The answer is yes, it is worth it, and it's also fairly easy, readable, understandable, and DRY. I will present both a common problem and a solution, using a cumulation of technologies and techniques from multiple Pivotal projects, in particular using acts_as_fu to create laser-targeted, isolated, and disposable ActiveRecord models for testing extensions and RSpec shared behaviors to minimize the amount of duplicated test code.
Interesting Things
application.rb vs. application_controller.rb: As we all know,
ApplicationControllerbreaks with Rails convention and lives in theapplication.rbfile, notapplication_controller.rb.Be careful if you create anapplication_controller.rbfile of your own, as this can confuse Rails class loading and might result in Rails deciding not to loadapplication.rb.Google Webmaster Tools: Note that if you are using Google Webmaster Tools that statistics are different for www.example.com and example.com (sans www).

Nested Model Forms are coming in Rails 2.3! There is even a patch in progress.
Interesting Things
- Rails reminder:
flash[:notice] = "Good Job"will survive a redirect, whileflash.now[:notice] = "Good Job"will not. In general,flash.nowis used when you render a template without a redirect, such as when a form submit has validation errors. - Good Books: Several folks have recommended JavaScript: The Good Parts.
- Pro bono: Would anyone like to help out KUSF for free? Their new website project has been stalled for a year.
Ask for Help
"How do you get Selenium to work with Firefox 3?"
If you know how, pull the jar files out of a later release and use those. Good luck!
One team discovered a jaw-dropping issue with has_many :through. Given the following:
class User < ActiveRecord::Base has_many :user_photos has_many :photos, :through => :user_photosa_user.photos.createwill create and persist both a Photo object and the UserPhoto join objectphoto = a_user.photos.buildfollowed byphoto.savewill create and persist the Photo object only, and will not persist an appropriate UserPhoto join object.
Rails 2.2:
Test::Unit::TestCaseextentions have been removed from Rails Core and are now inActiveSupport::TestCase. As stated in the Groups Thread about this, useActiveSupport::TestCaseinstead ofTest::Unit::TestCasein test/test_helper.rb.
Interesting Things
- Teaser: Selenium for Flash! We've developed a Selenium-like framework for Flash. It's pre-alpha, and needs to be extracted from it's current home inside a project. Are you interested in a Selenium-like framework for Flash, or have you written one yourself? Let us know!
STI-weirdness. Rails surprise of the day: given a query of a
has_many :photoswhere Photos has STI subclasses (got that?) Rails will build a SQL query that includes the subclass types of Photo, which you might not want:foo.photos.find_by_type("Photo") # query will have "... WHERE type IN ('Photo', 'OriginalPhoto', 'ThumbnailPhoto')"It appears that the retardase_inhibitor might not work with Rails 2.1.X due to fixes in ActionMailer.
- JetBrains has been hard at work: they have released both a new Ruby plugin for IntelliJ, and a ruby-specific IDE (based on IntelliJ) named RubyMine.
Check out Pivot Jonathan's wife's art exhibit at Artist-Xchange Gallery in San Francisco, Friday 11/7 from 7-10pm:
Ask for Help
"I want to create a custom launcher for Firefox 2 and Firefox 3 with different profiles. Perhaps the real question is how do we create a custom version of a Mac application launcher, passing in the arguments we need?"
... without having to invoke it on the command line every time.
"We're trying to delete cookies in our Controller, but they keep appearing in the headers anyway."
Suggestion: make sure you are specifying your URL paths and domains correctly.
"Why won't our CSS and other assets load the first time when accessing an SSL-protected domain on Engine Yard?"
It's most likely not Engine Yard or Firefox 3's fault. More research needed.
Interesting Things
- We discovered why a Flash widget was reloading itself: changes the CSS
positionvalue. We were hiding the Flash widget by moving it's containingdivoff the page withposition: absolute; left: -9000, and removing the class that had those values to show it again. It turns out that changing thatpositionvalue causes the Flash to reload. By keeping theposition:absolutesetting when we both show and hide our container div, the Flash no longer reloads.
Ask for Help
"When using Rails's date_select helper, is there a corresponding helper method to turn that date format into a Date object in the controller?"
Some Snippets are available, but how about a Rails built-in solution?
We just implemented bookmark_fu on Pivots and the experience was very smooth, taking only a few minutes. We how have an "Iconistan" of social bookmarking chiclets for either remembering or promoting content on Digg, reddit, del.icio.us -- almost 20 sites in all.

Install via the normal plugin install process (the -x installs it as an SVN:EXTERNAL):
#> ruby script/plugin install -x svn://rubyforge.org/var/svn/pivotalrb/bookmark_fu/trunk/bookmark_fu
I did have one issue -- the script/plugin install script pulled all the code down but ultimately failed because we have multiple versions of Rails on our development machine (about 5); this seemed to confuse the install script. No problem, though: I ran the install.rb script manually:
#> script/runner vendor/plugins/bookmark_fu/install.rb

