Posts Tagged ‘1rad’

Lately I started looking into components again. What appealed me is that they could provide a uniform interface to parts of an application, rendering and all included. And the way they are were built into Rails they even spoke HTTP right out of the box.
Think about the possibilities! Using components you could move caching out [...]


In functional tests a controller instance should not be reused: usually controller instances hold some state, that gets discarded in the normal Rails life cycle, and our tests must reflect that. Otherwise, tests can fail even if they shouldn’t, but even worse tests could succeed when they shouldn’t.
See this testcase:

require File.dirname(__FILE__) + ‘/../test_helper’

class DuuController [...]


Now, last monday I promised to rework the bodywork code into a plugin, “tested and all”. Some clashes with git later I finally managed to push it to github, you’ll find it at github. It even comes with a nice and cute README file, so head over and check it out.
Here I want to ask [...]


find_or_create_by_<nnn>: think twice. before you race
The usually recommended way to create an item if it doesn’t exist already is by using
find_or_create_by… This, however, comes with a race condition built in. Which doesn’t always race,
so think twice when and how you use it.
This code, for example, *might* deploy the race condition:
class Model < ActiveRecord::Base
def [...]


Strangely RoR doesn’t come with support for Advisory Locking. However, a typical
rails application usually not only needs to synchronize access to the data in
the database but needs to synchronize external data as well. Given that a typical rails application has more than one parallel thread of execution, a programmer might need some tools to synchronize [...]