Posts Tagged ‘1rad’
0×1e – Components, revisited
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 [...]
Filed under: Uncategorized | Leave a Comment
Tags: 1rad, components, distribute, performance, rails, xc2
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 [...]
Filed under: 1rad, Debugging Tools, ruby | 1 Comment
Tags: 1rad, Functional Test, rails, ruby, Testing
0×07: More bodywork
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 [...]
Filed under: 1rad, ruby | Leave a Comment
Tags: 1rad, controller, rails, ruby
0×04: Atomic science
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 [...]
Filed under: 1rad, ruby | Leave a Comment
Tags: 1rad, ruby
0×03: Advisory Locking
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 [...]
Filed under: 1rad, ruby | Leave a Comment
Tags: 1rad, ruby