Fat Models? Fat Controllers? Services to the rescue!!!

MVC has become the “de facto” standard for building web (and not only web) application. Enforcing the separation of concerns between presentation and business logic, MVC has become a sort of “common land” that makes easy to follow the application flow in a cross language manner.

Fake xhr request from rspec

I discovered today that I had no idea of how to fake an xhr request in an Rspec controller test. I need this cause some of my layout strategy behaves on the request.xhr? method. As expected Rspec solved the issue in a cool and elegant way.

ruby alias vs alias_method

While alias and alias_method looks very similar at first they hide a substantial different behaviour. Look at the following code.

Railo 4 beta released

Railo 4 beta has been released. See more info in Railo blog. Many improvements and new features:

Redis cache extension for Railo

I have recently had occasion to work with Redis and I got really impressed by how is fast and reliable. Redis is a nosql key/value store quite commonly used in the Ruby world where I am digging these days. Many well known projects like Resque, Sidekiq and others make a wide use of Redis for storing any kind of data. What makes Redis really shining, over being so fast, is the ability to manage typed data like hashes, sets and lists. This feature makes the engine suitable to be used in many more situations than a plain key value store.

Rspec rails views tips

In the last days I faced some new challenge in testing rails views with rspec. Here is what I learned. I am useing the veru handy rails controller prepend_view_path helper to be able to choose dynamically what views to use to render the actual request. A sample code is the following:

Ruby tip. Double association in a ternary operator

I found myself today in the opportunity to use a double association in a ternary operator. Basically I wanted to assign 2 variables based on a certain condition. Normal ruby double assignment works easy like this:

Rails migration redo

A very good practice, when writing a rails migration, is to be sure that the down methods works as expected. Once the migration is ready you should make it run and, if anything is fine, you should  rollback it and run it again. In this way you are sure that both the up and down migration works as you planned. To make it faster you can use the following command

Monitor resque workers via upstart

Resque is a Redis-backed Ruby library for creating background jobs, placing them on multiple queues, and processing them later. Resque works firing up a set number of workers than will coninuously look for job to be processed and will execute them following the rules defined when the workers are launched. You can have a single worker process any queue or having a single worker processing a single queue or even fire up more workers that will look forward to a single queue. Read more about resque. A very important topic is to be sure that the workers are always available and that any time your application is deployed also the workers are restarted. This is crucial cause the worker load an instance of your application and will then process the jobs against this application instance. If you deploy a new version of your application but you do not restart your workers the jobs will be run on an outdated code version and this is clearly something you do not want!

Git rebase --onto to the rescue ( part 1 )

I am now using git since more than a year as my primary scm. I tend to use it also against svn repo,  I can so focusing on git  becoming always more comfortable using it. To be honest up to now my git use has always been quite basic, while projects I was working on never needed more that a master/develop/topic branches workflow. Recently I faced a more complex issue related to the necessary  support for proper support branch that was going to diverge for a long time from the develop branch.