We use Cucumber-Nagios at The Frontier Group to monitor live web applications and web sites. It’s the natural extension to the integration testing we conduct on our applicaitons as we develop them, and it gives us a deeper insight into an applications real-time availability and responsiveness… or so I thought.
Due to an oversight on my part, the Cucumber feature that we use to search this blog was failing “in real life” but passing according to Cucumber-Nagios. I was searching for a text string that should have appeared only after conducting a successful search of the articles, however it was also appearing in the list of popular articles on the sidebar. Whoops!
After the test started failing for real, because the blog post was no longer referenced in the sidebar, I dug deeper in an attempt to find the problem.
In the end Aaron did most of the hard work, and tracked the problem down to webrat not submitting the form properly. As such the response data that was being parsed was incorrect.
The trick that we used (and it is a nasty hack, to be sure) is to fool webrat into operating in “Rails mode”, whereby it POSTs the form properly. I added the last four lines to features/support/env.rb and it’s done the trick.
So if you’re having a problem with webrat posting data, maybe this will help you. Alternatively, if you have a suggestion on how this could be fixed in a cleaner way, please leave a comment.
Every organisation has to continuously solve a set of legal, financial, technical and social problems in order to survive. Small businesses have limited resources and prioritise problem solving in their main fields of endeavour. For example, software development companies like The Frontier Group constantly buy programming books, refine development practices, research new technologies and send their employees to technical training and conferences to expand their skill sets.
However, quite frequently it’s the social problems that businesses face that can make or break them. Many employees lack the skills to communicate, to work effectively in teams and to manage others. Fresh graduates may not know how to work at all. The failure to address and solve these social problems results in reduced operational efficiency, inadequate management and poor employee morale.
The stereotypical programmer is an introvert with plenty of technical skills, but few social skills. How often do you hear about software development companies conducting training in non-technical fields such as leadership, team management, project management, dispute resolution and sales? It’s rare. When it comes to employee skill sets, most companies, especially small ones, focus on improving strengths instead of addressing weaknesses.
The Frontier Group recognises that its employees can’t cut code all the time, no matter how much we love doing it. Our team leaders and project managers require excellent skills to ensure every project hits its targets. We’ve partnered with local company Alive and Kicking for management and sales training for our staff, and look forward to learning from them.
Improvements in management skills are difficult to quantify, and spending cash on training when budgets are tight is difficult to justify. As always, the adage “you have to spend money to make money” applies. Small businesses can only grow as fast as their employees will let them, and The Frontier Group is grooming its employees for success.
Sending iOS push notifications from a Rails application is very easy to do these days, thankfully there are many great Ruby gems that can be used to handle most of the magic for you. Recently I ran into the apn_sender gem which handles sending push notifications in a really neat way.
Sending push notifications directly from a Rails application can be slow and we probably don’t want to have the user waiting until the notification is sent, instead apn_sender can be setup to run a worker which is constantly connected to the apple push notification service. When there are new notifications to send, the notifications are queued up and sent through the always open connection that is maintained by the worker.
apn_sender uses redis as a message queue to keep track of the notifications waiting to be sent, you’ll need to install it before using the gem.
To add apn_sender in your Rails 3 application, just add the gem to your Gemfile. We’re going to need the daemons gem too so we’ll include that as well.
Now we can create our daemon which we will be using for sending push notifications, this can be placed anywhere, I’ve put mine in script/apn_sender. Make sure to add execute permission to the file after creating so we can run it.
Before the daemon can start running we’ll need to put our iOS push certificate into the application. Instructions for generating the certificates are available at the Apple Developer site. The certificates need to be placed inside of /config/certs and should be named apn_development.pem or apn_production.pem for production.
Once the certificates are in their correct locations, we can start up the daemon. The daemon does not know about the Rails environment so we need to specify this when starting it up. The daemon supports start, stop and restart commands. There is a verbose flag available to output more information (which can be helpful when debugging).
Our application is now set up to send push notifications, this can now easily be performed by adding a new notification to the queue. The notify method on the APN class will take a push notification token and then our parameters, we can specify the alert message to show the user, whether or not we want sound as well as the number to display on the badge icon. Anything else we pass to notify will be sent as metadata in the push notification. Here’s an example of creating a notification.
The worker should pick up the notification within a few seconds and send it off. The apn_sender has many other features that I haven’t covered, you can view the full documentation over at https://github.com/kdonovan/apn_sender.
CarrierWave is a great gem for adding image uploading and basic processing abilities to your Rails applications. By default there is no way to set the quality of the resized images, which could be a very useful feature.
One of the applications that we’re currently building has a requirement to resize and compress images to produce smaller file sizes, as well as stripping out any personal information that may be stored in the uploaded images.
Out of the box CarrierWave provides a consistent interface to process images using RMagick, MiniMagick or ImageScience. Resizing and cropping is supported for all three image processing engines but setting the quality or removing personal data is not supported. Thankfully, CarrierWave provides an easy way to extend the default functionality so we can do more.
For the examples I’ll be adding extra functionality to RMagick processing. If you’re using MiniMagick or ImageScience the methods will need to be altered to work correctly. We’ll start by adding a new initializer into our application.
You may be wondering about the fix_exif_rotation method. Well, some modern cameras always take photos upright, in portrait. When you take a photo in landscape mode the photo is actually saved as a portrait, but the photo will contain some extra orientation metadata. When we remove the embedded data in the photo this value gets removed, so as a result we need to manually rotate the photo, which is what this method does.
The application server will need to be restarted before the new initializer can be used. Once restarted the new filters can be used in an uploader like so: