ChicagoRuby meeting ‘Test Prescriptions’ recap

The ChicagoRuby users group (not to be confused with chirb.org another great Chicago Ruby user group) held their second meeting at their downtown location.
While the meetings out in Elmhurst are always informative and helpful, the downtown location may allow for a bigger crowd, and the weekday time might work better for more people. Plus, the Illinois Technology Association - Tech Nexus is right next to Union Station which works great for people that still have to go out to the suburbs.
Noel Rappin's talk covered some of the most common questions he gets through the Pathfinder Development Blog, and his own site RailsPrescriptions site RailsRX.com dedicated exclusivly to testing.
There's too much detail to cover here, but at a high-level, Noel covered:
- The why, how, when, and where questions that make the foundation of a good testing approach
- Testing techniques for legacy projects
- A good review of the different testing frameworks, what their differences are, and some discussion about each (test::unit, shoulda, rspec, cucumber)
- A solid review of different factory tools that go beyond standard fixtures (Factory Girl, Fixture Replacement, Machinist, and Object Daddy)
- Strategies for migrating from Fixtures
- Differences between the mocking frameworks: Flexmock, mocha, rspec, and RR (double ruby)
- Finding the right balance, and avoiding the pitfalls of 'over mocking'
- Cucumber testing workflow (and where cucumber doesn't work well)
The audience seemed to have a wide range of experience, but all had opinions to share about what they've learned about testing. After the talk everyone seemed fell into small groups to network and exchange ideas and contact info, and a group gathered around Ray and Noel as they tossed around some ideas on potential future meeting topics "Ruby IDE/Editor review", "Rails Jumpstart", "Coding Dojo".
The organizers took a stab at hosting the meeting virtually over gotomeeting (not sure if it was recorded or not).
Their next meeting is scheduled for July 18th, details can be found in their meetup.com group.

The organizers of the ChicagoRuby.com group are also the organizers of the 2nd annual WindyCityRails Conference right here in Chicago, on Sept, 12th, which Noel will be presenting at.
Topics: chicagoruby, chirb windycityrails, factory, fixturereplacement, fixtures, flexmock, mocking, rails, railsrx, rspec, ruby, shoulda, tdd, test::unit, Testing
Uploading Files to Rails Metal
I was fooling around with Rails Metal earlier today to get a better feel for it. One of the most obvious uses for me is disassociating an upload task from your application; a single Rails instance blocks while waiting for an upload to finish, so particularly for very large file uploads, your application can stop responding to users if all instances are taken up by uploaders.
With Metal, you can spawn separate tasks on different process IDs: then when you need to upload, Rails calls to them and that Metal handles the upload (and blocks), while the application instance itself is free to service other requests. This article was super helpful in describing how to use Rackup to start a Metal piece as a separate process. But in all my searching I didn't find anything clearly delineated on the Internet for how to make Metal work with file uploads, so this is how I did it.
Topics: metal, rails, ruby, Ruby on Rails
deprec is good, but needs taming.
I recently had to work on some deployment tasks and used deprec gem to check out how it can help. deprec is one of the most admired gem outside of pure rails application deployment arena. It is one of the most successful attempts at demonstrating how capistrano can be used as a more generic deployment tool and not just for deploying rails apps.
However, there are a few design choices that I think warrants more thought if I were to continue to use it successfully for all my deployment needs.
Continue reading »
Topics: capistrano, deployment, deprec, rails, ruby
handling CRLF in git
If you use git on windows or cygwin, I am sure you've encountered this.
$ git add dir/newfile fatal: LF would be replaced by CRLF in dir/newfile
While there is much confusion/discussion around how to handle this using core.autocrlf and core.safecrlf config attributes, I have lately settled with this recommendation:
Continue reading »
getting user.home in ruby
If File.open("~/etc/my_config_file") doesn't work for you, try File.open(File.expand_path("~/etc/my_config_file"))
Not sure, why File.open() does not handle this internally?
ActionMailer Callbacks: In the Spirit of ActionController Filters
One of the most useful features of ActionController is the ability to add filters before, after, or around actions. This tool is made even more powerful by the ability to chain filters together. Allowing an AOP approach is indispensable for addressing cross cutting concerns (or simply separating concerns), and is one of the things which makes a framework valuable to a developer (Spring is an excellent example of this).
A while back, I had a requirement to persist a record of which email addresses were sent an email through the system. I expected to find callback support for ActionMailer, but was surprised to find that it didn't exist.
I had three options: put the logic inline in each ActionMailer method which is not DRY and muddles concerns, put the logic in the ActionContoller as filters which break encapsulation in terrible ways (and is at the wrong layer), or extend ActionMailler to allow callback methods.
I choose the latter...
Topics: ActionMailer, rails, Ruby on Rails
Escaping the Iterative Development Trap

While designing software it's easy to fall into the trap of iterative development. Iterative development allows us to work quickly, exchanging rigorous requirements-gathering for rapid design and development -- and as good developers, it is our responsibility to make sure that the code we create now works well with future iterations of our program. However, I find that code created as part of this process can frequently be too complicated, too generalized, or both. When creating agile software we must keep in mind the requirements of the future, but design strictly for the requirements of the present. If we are snared by the trap of iterative development, we risk wasting time, money, and people on code that may not be useful in the future -- or, even worse, code that the client doesn't want and can't use.
ActiveRecord create_or_update based on natural-key
Have you often run into a situation where you have a hash full of properties and you want to either create a new ActiveRecord object (if it doesn't exist) or update one (if it exists)?
For example,
class User
# has properties: ssn, first_name, :last_name, :age, :email, :password
def create_or_update_by_ssn(params)
user = Disease.find_by_ssn(params[:ssn])
if user.nil?
user = User.create(params)
else
user.update_attributes!(params)
end
end
end
Here, the business rule states that a user's SSN is unique, so called natural-key.
If we can identify what constitutes a natural-key for each model object in our domain-model, when we could DRY out this functionality.
Topics: activerecord, natural key, primary key, rails, ruby, surrogate key
How to serve static websites and Passenger Rails projects from the same Mac OS X Apache instance
When your http://localhost/~username/ sites go haywire, it's time to dig into your Apache config files
As Rails pros know, Phusion Passenger allows you to serve multiple Rails apps on the same Apache webserver instance with few configuration or deployment headaches. When you install it in your local Mac dev environment, you can easily work on a bunch of Rails projects simultaneously without having to manually start and stop individual server instances all the time. The OS X Passenger preference pane makes deployment even easier. Just add a project, give it a custom local URL, and point it at a directory. You're good to go.
But what happens if you're already using OS X's built-in Apache webserver to dish up local content such as PHP applications or static HTML? When I first got Passenger up and running, all of my local sites in /Users/<username>/Sites/ stopped working. It took a bunch of digging, but I eventually realized that something in my Apache configuration had gotten messed up during the Passenger installation process. I was missing the configuration file for my OS X user account. OS X generates this file the first time you enable web sharing for any individual user. It's responsible for mapping your /Sites subdirectory to localhost URLs, so that http://localhost/~<username>/myapplication/ points to /Sites/myapplication/index.html.
acts_without_database: Leverage ActiveRecord with Non-Database Backed Objects
ActiveRecord comes with a lot of nice things that aren't really dependent on having a database backed model. The most obvious example of this is the validation framework baked into ActiveRecord. Also, there are several plugins which add some useful behavior to ActiveRecord objects but don't rely on having a database.
In the future, I believe the rails team aims to make certain things more modular and easier to pull out and use separately from ActiveRecord (validation being one of those). However, if you are working on a project which is locked into a certain version of rails or you're impatient, there is a very simple plugin which can solve your needs.
Enter acts_without_database...
Continue reading »
Topics: activerecord, metaprogramming, plugin, rails, Ruby on Rails
Scriptaculous Drag and Drop with AJAX Update Fix for IE
If you have used scriptaculous to do drag and drop interactions which result in a replacement of the DOM element you are dropping into, you may have noticed that you can only do one drag and drop before it breaks in IE. The problem occurs when you replace a DOM element which is defined as a Droppable; IE will fail because it will still have the original element registered as a Droppable but it does not handle the fact that it no longer exists in the DOM. Firefox and safari have no issue with this, so this is another frustrating IE specific issue.
Fortunately, this problem is easily solved with a single line of javascript.
Continue reading »
Topics: IE, rails, Ruby on Rails, Scriptaculous
Ask the readers: How do I fire native browser events in Prototype.js?
I've been pairing with my colleague Noel Rappin on a cool Rails project lately, which has helped me turn a bunch of conceptual knowledge into real-world experience. I'm writing Ruby code, doing things the Rails way, and hewing faithfully to test-driven development.
I'm also returning to Prototype for my JavaScript needs after almost 15 months of daily jQuery use. The framework has matured nicely while I've been away. One surprise popped up today, however: Prototype 1.6 lacks the ability to simulate native browser events. jQuery offers this in the form of jQuery.trigger, which can simulate both native and custom events. But Prototype's Element#fire supports only namespaced custom events. (Read this mailing-list thread for more analysis.)
I did a couple hours of digging around today - including a trip to Scripteka - and haven't really found a canned, cross-browser solution to this issue. I'm looking for something that offers jQuery's native event firing in a tidy little Prototype extension. Anyone know of such a tool?
Topics: Javascript, jQuery, Prototype, rails, ruby
From JSP to Ruby on Rails: First thoughts on front-end coding conventions
Now that I've got a few Ruby on Rails projects under my belt, I finally feel qualified to comment on Rails front-end coding conventions. As a UI specialist coming to Rails from the JSP world, I find a lot of room for improvement in the RoR approach to view-layer code. I love working on the non-view aspects of RoR projects, but I find I've got to do tons of cleanup at the ERB layer. Expect to see some open-source components from Pathfinder to help ease this pain. In the meantime, let me articulate my pain points:
Code organization
If I'm filling a front-end role on a Rails project, most of the files I need are in /app/views and /public. I dig that. Likewise, I appreciate the underscore naming conventions for partials. However, I wish /layouts weren't just another subdirectory of /app/views. Layouts are inherently different from standard view templates. A better hierarchy within /app/views would help drive this home. Likewise, I wish partials and full templates each had their own directory within a specific controller's view folder. That would help keep directories manageable on big projects. The /public directory, on the other hand, offers just the right amount of organization.
Installing Edge Ferret/acts_as_ferret
If you do a gem install ferret, you will be getting 0.11.6. The latest stable version of acts_as_ferret is 0.4.3. Both of these versions were released nearly a year ago in November 2007. Since then, there have been various performance improvements and bug fixes which you'll be missing out on. In order to get the latest versions, you'll need to do a little bit of work but I would recommend it if an update is feasible for you.
Since it will be the easiest, let's begin with acts_as_ferret.
Continue reading »
Topics: acts_as_ferret, ferret, rails
Speed Up Ferret/acts_as_ferret Bulk Indexing
Those of you using ferret 0.11.6 (the latest released gem) and acts_as_ferret 0.4.3 (the latest stable version) may have noticed that rebuilding an index can be painfully slow when working with a large number of documents. Even if each document contains a relatively small amount of text, indexing crawls with a large set of documents. The problem is a result of how bulk update works; "bulk indexing" processes a single document at a time! Fortunately, there is a simple patch which will provide a significant speed boost.
Topics: acts_as_ferret, ferret, fulltext search, rails
About Pathfinder
Follow the Blog
-
Get a monthly update on best practices for delivering successful software.
Subscribe via email
Subscribe via RSS
Categories
Topics
Archives
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
- June 2007
- May 2007
- April 2007
- March 2007
- February 2007
- January 2007
- December 2006
- November 2006
- October 2006
- September 2006
- August 2006
- July 2006
- June 2006
- May 2006
- April 2006
- March 2006
Blogroll
Recent
- Elements of Testing Style
- Aesthetics and Web Design
- Asterisk-Java Testing with Groovy
- 3 Misuses of Code Comments
- Fluently NHibernate
- Digging a Hole and Covering it with Leaves — The Software Development Version
- The Importance of User Experience - Do You Understand It in Your Bones?
- Writing Your Own Protocol With NSURLProtocol
- What’s In Your Dock: iPhone edition
- Feature Fatigue





