We all know the importance of having a CI tool integrated in your project. It allows you to run your entire test suite every time you want to merge a set of changes. If you have a core project and many projects that depend on it, you want to run the tests for the core project and the dependent projects at the same time. This article explains how you can do it with Circle CI.Read more »
I have been using the capybara-webkit gem for a while now since I first tried it out after making the switch from Capybara + Selenium.
Using capybara-webkit speeds up my Selenium tests due to its headless nature, and it's very straightforward. However, I had some trouble testing a Rails based React app.
In this post, I will explain how I worked around the issues that came up when trying to use capybara-webkit with React.Read more »
Be it for performance or for readability, sometimes it's nice to be able to try out something new quickly without going through a pull request + deployment process. This is possible by modifying the $LOAD_PATH Ruby global variable and requiring the gem manually.Read more »
When working on a Rails project, you may have seen
present? calls on
ActiveRecord relationships. This might feel natural, mostly because
exists on all objects via ActiveSupport, so you expect the relationship to respond to it,
but it's actually not a very good idea. If all we want to do is check if the
scope returns any results from the database, there are better ways than using
.............................................................................................unknown OID 353414: failed to recognize type of '<field>'. It will be treated as String ...........................................................................................................................................
This Rails app uses a PostgreSQL database. After some Googling, it turns out that this is a warning from PostgreSQL. When the database doesn't recognize the type to use for a column, it casts to string by default.Read more »
Rails is a powerful framework. You can write a lot of features in a short period of time. In the process you can easily write code that performs poorly.
At Ombu Labs we like to maintain Ruby on Rails applications. In the process of maintaining them, adding features and fixing bugs, we like to improve the code and its performance (because we are good boy scouts!)
Here are some tips based on our experience.
where instead of
When you are performing a lot of calculations, you should load as little as possible into memory. Always prefer a SQL query vs. an object's method call.Read more »
When writing tests for services, you may sometimes want to use mock objects instead of real objects. In case you're using ActiveRecord and real objects, your tests may hit the database and slow down your suite. The latest release of the rspec-mocks library bundled with RSpec 3 includes at least three different ways to implement a mock object.
Let's discuss some of the differences between a
double and an
instance_double. First, the
 pry(main)> require 'rspec/mocks/standalone' => true  pry(main)> user_spy = spy(User) => #<Double User>  pry(main)> spy.whatever_method => #<Double (anonymous)>
Getting started with a new project should be as simple as possible, even for someone who is not technical. As a maintainer, you must make sure that anyone can clone your project and get it up and running in a few minutes.
After you clone a project, you should follow two steps:
There are already quite a few guides in the wild to help with the upgrade of Rails 3.2 to Rails 4.0. The official Rails guide for upgrading from Rails 3.2 to 4.0 is very thorough. With the recent release of Rails 5.0, apps currently in production running Rails 3.2 should probably be updated to any stable Rails 4 release as soon as possible.
There is even an e-book about upgrading from Rails 3 to 4, which serves as a useful guide to make this upgrade easier, and also helps understand the advantages & disadvantages of this new (soon to be old) version.
However, if you're using any non-standard gems, you're mostly on your own. Some gems stopped being maintained before Rails 4 was released, as was the case with CanCan, a well known authorization library. After many open pull requests were left unmerged, CanCanCan was released. It is a community driven effort to have a semi-official fork of CanCan. It serves as a drop-in replacement for people who want to use CanCan after upgrading to Rails 4.Read more »
Today I'm happy to introduce Pecas, time tracking leaderboards for Freckle! Pecas is an open source tool that integrates with your account and generates beautiful leaderboards per project and per teammate.
Here is a sample dashboard for all your projects:
On top of that, it will send you an email alert if you haven't tracked any hours during a work day. If it's a holiday, it won't bother you. :)Read more »
A few times in the past I've had to interact with IMAP via Ruby, and wrapping your head around its API is not so easy. Not only is the IMAP API a bit obscure and cryptic, but Ruby's IMAP documentation is not so great either.
Searching the internet for examples doesn't yield too many results, so I'll try to write down some of the things I've learned. The examples I'll show use Gmail as the target IMAP server.Read more »
I'm a big fan of having small classes. I'm not a big fan of having huge specs for a small class/object. Every time I see an opportunity to DRY my specs, I take it.
Today I wrote a spec to make sure that we gracefully ignore SPAMmy contact requests in the Ombu Labs contact page. It initially looked like this:
test "gracefully ignores spammy requests with valid attributes" do @valid_contact = contacts(:two) attributes = @valid_contact.attributes .merge(email_confirmation: @valid_contact.email) assert_no_difference("Contact.count") do post :create, contact: attributes, format: 'js' end assert_response :success end
The new behavior adds a simple SPAM trap field
that bots will usually fall for.
If a bot is submitting the
email_confirmation field (which is hidden by a CSS
class), then it is SPAM and it gracefully ignores the request.
We try to do it as much as possible at Ombu Labs. We usually keep the sessions under two hours and try to follow a regular schedule.
When we find ourselves blocked by a code problem, we use our daily scrum to coordinate a pairing session. It's quite a step up from rubberducking or using a cardboard programmer to find a solution to a problem.
As a Senior developer, I find that pairing sessions are great for coaching Junior developers. I enjoy teaching them about best practices, design patterns, frameworks, languages, code style, XP, and TDD.
From the point of view of a Junior developer, I believe it's a great opportunity to learn from someone who "has been there before". When you program with someone with more experience, you will often learn about design patterns, elegant object-oriented solutions, tips and tricks.Read more »
We decided to build a simple tool that would allow anyone with a Twitter account to report a parking violation. All you need to do is submit a geolocated tweet and a couple of photos (as evidence!)
Here is an example:
You can check out this tool over here: http://www.infractoresba.com.arRead more »