Inheritance in Backbone
Backbone.js comes with a minimalist OO inheritance framework similar to the one employed by CoffeeScript. Each base class has a static method called extend that is used to create a subclass, like this:
User = Backbone.Model.extend({
// instance methods
},
{
// class methods
});
extend returns a constructor whose prototype inherits from Backbone.Model.prototype. References to all of Backbone.Model's static methods and properties (including extend) are copied to the new constructor.
Calling 'super'
The constructor also receives a __super__ property, which references its superclass.
User.__super__ === Backbone.Model
This makes it possible to call super inside of a class or and instance method:
User.prototype.save = function(attrs) {
this.beforeSave(attrs);
User.__super__.save.apply(this, arguments);
};
CoffeeScript has a super keyword that compiles to the line above, but when using Backbone with plain javascript, its a little grating to have to type that out.
A small layer of convenience
I wrote this little super method (test-driven using jasmine) which saves me having to repeat the constructor's name all over the place. You call it like this:
User.prototype.save = function(attrs) {
this.beforeSave(attrs);
this._super("save", arguments);
};
The second parameter to _super is the array of arguments to pass to the overridden method. This is to optimize for the common case of passing the arguments object straight through.
There's no way to avoid having to repeat the method name like that, unless you wrap every method definition with a helper function that either passes the overridden method as a parameter (a la Prototype.js) or reassigns a hidden super property behind the scenes (like JS.Class or John Resig's approach). These approaches won't work with Backbone's ultra-minimalist inheritance system.
Helps
CCMenu + Hudson w/o Basic Auth
"Has anyone figured out how to use CCMenu with Hudson and not have Basic Auth?"
Hudson has its own authorization mechanism, unlike Basic Auth, so it can't be used with nice desktop tools like CCMenu which shows the red/green square in your system tray.
Consider using Jenkins.
Using Symlinks with Dropbox
Using the Linux Dropbox client seems to allow symlinks to be uploaded, but they will not behave as expect anywhere else. Someone was trying to have a "latest" folder point to the latest versioned folder.
The recommendation was just to have two copies of the files as a workaround.
Interestings
Rails Bridge Outreach for Women Workshop has space
Looking to learn Rails? There's a great meetup to get you up and running. As of this writing there is still space available. Come check the event out.
Yammer Javascript Meetup on Tuesday
Yammer will be hosting a Javascript meetup, expect the usual snacks and beer, and good talks about our favorite client-side language.
You may be asking yourself why you'd want to do this in the first place. Well here's why I would want to do it.
We had some Webdriver based Cucumber tests that passed fine locally but kept failing on our CI box. Our CI box is a bit underpowered at the moment so I thought what might be happening is that our tests weren't waiting long enough for the Ajaxy stuff to happen because the Ajax responses were taking a long time.
After some poking around in the source code of jQuery, I found the $.active property. This property keeps track of the number of active Ajax requests that are going on and I thought this might help us out.
What I came up with was this gist:
I added this step right after my Cucumber step that caused the Ajax call so that Cucumber would wait to move on until I knew that everything was done.
This step solved our CI failures and all was good in our test suite again.
Helps
Busting JS Caches Better
How do I bust Javascript caches better? Changing the url params doesn't always work?
The most consistent way to bust Javascript caches is to change the path to it. Sometimes transparent proxies and some browsers won't be busted otherwise.
Busting Chrome JS Cache when running Jasmine Fixtures
Chrome is cache Jasmine fixtures and Firefox is just too slow.
No great solution. Chrome typically runs tests so fast that just mashing the refresh until your test output changes seems to work for some.
Interestings
Trajectory
Trajectory is a new product out by Thoughtbot which has been described as a cross between Tracker and Basecamp.
Pow
37Signals has come out with a native Mac app called POW. Here's a snippet from the Readme:
Pow is a zero-configuration Rack server for Mac OS X. It makes developing Rails and Rack applications as frictionless as possible. You can install it in ten seconds and have your first app up and running in under a minute. No mucking around with /etc/hosts, no compiling Apache modules, no editing configuration files or installing preference panes. And running multiple apps with multiple versions of Ruby is trivial.
A fellow Pivot also mentioned that it makes running multiple apps on the same port, and having sub-domains easier.
Firefox cacheing
There is an option in Firefox to remember the last opened tabs so when you return to your browser, it will restore your last viewed websites.
This has the unfortunate side-effect of not deleting cookies despite the opposing setting for deleting all cookies upon session exit.
Ask for Help
"What do you recommend for Devise user invitations?"
Interesting Things
- Did you know that Rubymine can search files found with a previous search? Do cmd-shift-f and do a search. Do cmd-shift-f again. In the dialog, select 'custom'. In the drop down list is 'Files in Previous Search Result'
- Former Pivot Alex Chaffee is teaching a javascript class, and there are still a few openings.
Ask for Help
"Anyone using Selenium 2 and Webdriver?"
One of our internal projects is using it.
"How to stop time in Jasmine?"
There were a couple suggestions:
- use a global function, such as 'now'
- send in your own clock object
"Whurl standalone, or more dynos?"
Apparently Whurl is running on a single dyno at Heroku, so a single bad request can tie up Whurl until the request times out. Where are you TildeWill?
"What's this called?"
Imagin these are records in a relational database, with the records on the left having a one to many relationship with the records on the right. How would you google this?

A little ditty that makes it really easy to wait for something Javascripty to happen...like a Javascript dialog to appear that gets populated from an AJAX call.
The has_css? method call will wait until the element shows up and if it doesn't show up before the Capybara timeout expires then it will return false.
Ask for Help
- Double-entry/ledger based accounting in Rails (i.e. Quickbooks in Rails for free)
Ideally would be tied in with user/role system where each accounting entry would be tied to a user, but also reconciled against a master account. Recommendations? Latest and greatest?
One suggestion was to look at the code that Wesabe open sourced code when they closed their doors.
- Error message when opening Rubymine "Invalid Git Root"
This is likely because the project included a submodule that wasn't configured correctly, fix this in under Rubymine's version control preferences.

Interesting Things
Test 404 handling (e.g.
rescue_from ActiveRecord::RecordNotFound, :with => :render_record_not_found) with Cucumber by temporarily settingActionController::Base.allow_rescue = true. This is usually set tofalseinfeatures/support/env.rbJSON.pretty_generatehates Rails 3Hashes
- Use window.postMessage to communicate between IFrames in a standard way
This should work in most modern browsers. Follow the Mozilla docs, NOT the various blog posts about this.
Since the language of the new iPhone UI Automation component is JavaScript I figured the easiest way to organize tests is to use a JavaScript testing framework, such as Jasmine. So, I created jasmine-iphone, which is little more than a few simple scripts to make UI Automation and Jasmine play nice.
Once you clone jasmine-iphone from GitHub (it includes Jasmine as a submodule, so be sure to git submodule init && git submodule update) you can copy the example-suite.js file, import your spec files, point Instruments at your suite.js and go.
As an example, I set up a trivial example in the Cedar project. The directory structure looks like this:
Project Directory
\- Spec
\- UIAutomation
\- jasmine-iphone <--- submodule
\- jasmine <--- nested submodule
\- suite.js
\- thing-spec.js
\- other-thing-spec.js
The suite.js file is relatively simple (note that I moved it up one directory from where the example-suite.js file is, so the #import statements are slightly different):
#import "jasmine-iphone/jasmine-uiautomation.js" #import "jasmine-iphone/jasmine-uiautomation-reporter.js" // Import your JS spec files here. #import "thing-spec.js" #import "other-thing-spec.js" jasmine.getEnv().addReporter(new jasmine.UIAutomation.Reporter()); jasmine.getEnv().execute();
You can write the specs themselves the same way you'd write Jasmine specs for anything else. The UIAutomation subclass of the Jasmine Reporter takes care of marking the start of each spec, as well as reporting if it passes or fails. You'll need to use the UIAutomation classes and methods for driving your application's state, of course.
That's it. Try it out and see what you think.
