Showing the git commit SHA that is currently deployed

I cannot count how many times I (or others) have asked the following question:

What is the difference between master and the production version?

We deploy about 3-5 times a day and we merge code about twice as much into master (some days, even more then that).

We deploy to servers with Capistrano, Capistrano has a very useful feature to write a REVISION file to the root of the project, this file contains a single line with the commit sha.

So, I thought I might set up a controller that will read this file and display it when I want.

So, I spec’d it out:

And this is the controller code:


10 Things You Didn’t Know Rails Could do

James Eduard Grey published a presentation of a talk he did in RailsConf.

It is pure gold, so many tips and tricks, I promise you, some of these will be new even to the most experienced of Rails developers.

10 Things You Didn’t Know Rails Could do // Speaker Deck.

Pivotal Tracker Git integration with ease

This post makes 2 assumptions

  1. You are working with Git
  2. You are working with Pivotal Tracker

At Gogobot, we work with Pivotal Tracker (for various reasons).

Pivotal Tracker has very good Git integration, when you commit (and push), the commits can show up as comments to the story.

Another very good thing is that you can change the status of a story just by a commit, you can finish, deliver or anything else you might want.

Usually, you need to add the story id (#12123123) to the commit message yourself, obviously, I never remember to do that.

So, the link in the bottom is a gem that integrates git with Pivotal Tracker very easily and effortlessly.


It has a very good README so keep on reading there.

Decorating Devise’s current_user with Draper –

A great trick to decorate the current_user method from devise using Draper.

IMHO it’s actually applicable to any authentication system out there that is using current_user but that requires some testing.

Decorators are an awesome way to remove logic from the view or the models, so the models have real business logic and the rest can be “decorated” with another class.

If you are looking for more information about decorators, Ryan Bates has a great screencast about it here:


Decorating Devise’s current_user with Draper –

A Baseline for Front-End Developers – Adventures in JavaScript Development

I stumbled upon this terrific post on Twitter.

This post goes into details (very deeply) about what it takes to be a Front End developer these days.

The amount of things and tools you need to know are overwhelming.

I recommend taking the time and reading it, it’s long, but worth every second you put into it.

A Baseline for Front-End Developers – Adventures in JavaScript Development.

Find the source location of a method in your project

Ruby/Rails project sometimes make it hard to find the source location of a method.

Sometimes, Duck typing, meta-programming and just plain bad design make it really hard to find where a method was defined and how.

Luckily, there’s an easy way around this.

So, here’s an example.

A few moments ago, I came across this line:

First thing I did (obviously) was going to the user class and searching for this method. Obvious enough (or this post would not exist) I could not find it.

I immediately realized it’s being defined by some cache mechanism we have.

So, I opened up a console and typed this:

And it returned

So, the method IS defined on the user somewhere, you can see exactly where like so:

This will give you an exact location where the method is defined, I found this line:

This trick saves me time, hope it will save you some browsing around helplessly, especially in bigger non-single-dev projects

EDIT: 12 APR 2012 10:51PM
I posted a link to this post in the dev chat room on Campfire.

Steve, had an awesome comment:

Campfire conversation

We are using Octopus gem in our application (Gogobot), this gem is used to connect to databases with master/slave architecture.

Just as a general warning, you may get some results like that. but if you follow the source location, it’s usually a very good hint of where the method is actually defined and in any case, I think those Proxy situations are rare.

Awesome comment nonetheless, so I though I might update the post with it.

EDIT: 12 APR 2012 11:01PM

Jonathan Jackson replied to me on twitter, he said, that if you are using Pry (which you should) you can actually do it even better.

if you open up the console and do:

This will open up the default editor (Vim in my case) in the exact location where the method is defined and you are able to edit it in place.

Another awesome comment that was worth a post update :-)

Testing the Notifier class with Rspec

Today, I needed to spec the Notifier (mailer) class in a Rails project.

I don’t mean to spec the view, I just needed to test if the Notifier class method was being called with some params.

For example, I had this user story

As a User
When I am an owner of an issue
And the issue status changes
I want to get an email

So, all I had to to in my spec, is to test if the Notifier class was being called, I am testing the view in the notifier_spec, so no need to test it twice.

So, I wrote this code.

When I ran the spec, I was surprised to see this error:

After scratching my head for a while, I realized that since I used mocks and expectations for the Notifier class, the underlying code was never called, so it wasn’t returning the Mail::Message class.

I fixed it by doing this:

And now I have a happy spec file, that is only testing the messages between the classes, which is what I wanted to do in the first place.

Run your specs in logical groups

I stumbled upon this StackOverflow question: testing – Organizing rspec 2 tests into ‘unit’ and ‘integration’ categories in rails – Stack Overflow.

Basically, the guy asks how he can run specs isolated into logical groups, running the unit without running the integration and so on.

At Gogobot, we have exactly that, since we run our specs in the CI, we can decide which to run, and they run one after the other and dependent on each other, so if you fail UNIT, the build fails, no need to continue on.

You can run the rakes like so


This is what our spec.rake looks like


With GOV.UK, British government redefines the online government platform – O’Reilly Radar

Reading this article made me realize there’s hope in making government sites better.

The state of the government sites in Israel for example is shameful, all written in .Net, no standards and no cross-platform consideration.

It’s a very good read.

Why create an open source stack? “Why not?” asked Bracken. “It’s a government platform, and as such it belongs to us all and we want people to contribute and share in its development.”

via With GOV.UK, British government redefines the online government platform – O’Reilly Radar.

Submit any form with a keyboard shortcut

Say you have a simple form like “Add comment” similar to this image

Add comment form

Now, this is a text-area, so the ENTER key will break rows and will not automatically submit the form to the server.

I want to create a flexible way to send the form to the server with a keyboard shortcut like CTRL+ENTER.

Thanks to an awesome library by Thomas Fuchs called KeyMaster it turned out to be quite simple.

By default, Keymaster ignores all keyboard shortcuts if it’s inside an input or textarea or even a select box, obviously that is not what I wanted or needed.

Luckily, you can override that behavior with a filter function, like so


Now, all you need to do is listen to the event, and when it’s fired, submit the parent form. like so:


That’s it, now every text-input, input or select box can submit the form with this shortcut, it’s super useful and your users will certainly like it.