How to Deploy Ruby on Rails With The Opscode Chef Application Cookbook

by on August 25, 2010 · 2 comments

I already wrote about how to get started with the Opscode Chef Platform. In this article I want to show you a very elegant way to deploy a Ruby on Rails stack with Chef. One of the strengths of Chef is the decent set of available cookbooks. @jtimberman does an especially excellent job in writing them. His chef cookbooks really help you to configure your systems neatly. One of his cookbooks is the Application cookbook. It enables data driven application deployment. Currently, it supports Ruby on Rails apps. The preferred stack is currently Matz Ruby with Unicorn, but, in a later post, I’ll show you how to use it cleanly with Ruby Enterprise Edition (REE).
Let’s get started!
[Read more…]

Far Future Expires Headers For Ruby On Rails With Nginx

by on July 20, 2010 · 2 comments

Browsers load static images from your website again and again if your web server does not send an expires header with a date far in the future. To avoid that unnecessary traffic on your servers and unnecessary load times for your users, it’s a good idea to let your nginx send those expires headers. But, what if you tell the browser not to come back for your css files until next year and now you change some style within it? The Rails URL helpers automatically attach a timestamp representing the last modification date to each URL (like ?2345346654). That changes the URL every time you deploy making the browser load the modified file. In this post, I want to show you all the not so obvious things to consider when you introduce far future expires headers with rails and nginx.
[Read more…]

Rethinking code reuse with Modularity for Ruby

by on March 26, 2010 · 2 comments

This is a guest post by our friends over at makandra, a cool Ruby on Rails development shop. Today they announce a great new Ruby gem for dealing with separating concerns in your ActiveRecord models.

Reusing code is hard. But although we knew that high-level components don’t work, we found ourselves rewriting similar code again and again for different projects. Was there maybe another angle from which to slice our code into reusable pieces?

We sat down and looked at what was truly worth sharing. Here are some of the many things we found:

[Read more…]

RSpec Tips & Tricks

by on February 18, 2010 · 0 comments

Throughout the last couple of days, I did a bigger refactoring of our Ruby on Rails application. As I changed quite a few moving parts, I covered everything I did with RSpec. It’s really an incredible feeling to have all your bases covered with automated tests when you finally start the manual regression test. Along the way, I came across a few things I wanted to share with you.

Structuring Your RSpec

When you’re writing specs you want to bring order to them sooner or later. I really use nested describe-blocks a lot. Let’s look into a Controller spec to see what I do:
[Read more…]

Aegis: Role-based Permissions for your Ruby on Rails application

by on July 5, 2009 · 20 comments

This is a guest post by our friends over at makandra, a cool Ruby on Rails development shop. Today they announce a great new Ruby gem for dealing with role-based permissions.
You know the game!
Each time you start a new application the same procedure starts over again: You set up your tools like git, trac & co. and prepare to get going. Then you look into your backlog and plan your first iteration:

  • “As a moderator I should be able to edit and delete all posts in case somebody …”
  • “As a superuser I want to create, edit and delete moderators and users.”
  • “As a department director I should be able to allow or deny requests for leave for employees in my department.”

In almost every project we at makandra were involved with during the past year, some kind of role-based permission-system was required.

[Read more…]

Setting up a test database on a ruby on rails continuous integration server using SQL instead of schema.rb

by on June 18, 2009 · 4 comments

For developing our Ruby on Rails based web site, we usually take regular SQL dumps from our production servers (of course, anonymizing sensitive customer data along the way). Always having a fresh dump allows us to be on the safe side when writing database migrations. Having an up to date development database enables us to run our test suite as well; it’s just a matter of rake db:test:prepare to get our test database up-to-date. So far, so good.
[Read more…]

webrat: Automated Acceptance Testing with RSpec or Cucumber

by on June 11, 2009 · 4 comments

Recently, I was looking deeper into how we could add some automated acceptance tests to our Ruby on Rails based website. We’re using RSpec since quite a while now for TDD, but doing some high level acceptance tests was not on our agenda so far.

DRY Cucumber Scenarios

The new cool kid on the block is Cucumber. One of its main features is that you can describe acceptance tests in nearly plain English (or any other language) simplifying discussions with the product managers and other, non-technical stake holders. I’m really impressed by the ease, with which you can describe DRY scenarios like our login feature:
[Read more…]

Seed Data In Ruby On Rails

by on May 28, 2009 · 12 comments

To run automated tests for your Ruby on Rails webapp, not only do you need your latest database structure deployed to the test database (created by rake db:test:prepare), but you also need some seed data for lookup tables, e.g. like zip codes.

Common approaches like adding seed data through rails migrations are discouraged, and plugins like seed_fu only work for small amounts of seed data. In seed_fu, you can specify a seed method for your ActiveRecord models like so:

User.seed(:login, :email) do |s|
      s.login = "bob"
      s.email = "[email protected]"
      s.first_name = "Bob"
      s.last_name = "Bobson"
    end

Running the rake db:seed task provided by seed_fu will add all defined models to your test database.

DHH has even standardized a way to load seed data for Rails 3, making the rake db:seed task part of rails and setting up a file called db/seeds.rb for maintaining your seeding code. Using that file, you can load your seed data however you see fit, e.g. seed_fu.

How to Deal With Big Amounts of Seed Data

[Read more…]

Acceptance Testing with Cucumber

by on May 22, 2009 · 0 comments

Pivotal Labs - Jeff Dean - Making a Case for Cucumber
After watching a Pivotal Labs Tech Talk Making a Case for Cucumber, I decided to give it a try. Especially the seamless integration with rails and webrat made me curious. Webrat is a headless browser simulator, which can execute UI tests for you. You even can use the same syntax to drive a real browser using Selenium if you need Javascript support for some of your tests.
[Read more…]