I was looking for the best way to test named scopes in Rails using Rspec and I ran across the following answer by David Chelimsky (Rspec’s creator) in the Rspec Google Group:

describe User, ".admins" do 
  it "includes users with admin flag" do 
    admin = User.create! :admin => true 
    User.admin.should include(admin) 
  it "excludes users without admin flag" do 
    non_admin = User.create! :admin => false 
    User.admin.should_not include(non_admin) 
class User < ActiveRecord::Base 
  named_scope :admins, :conditions => {:admin => true} 

Read the entire thread for context.

About me

I live in the greater Kansas City area with my beautiful wife, our two great kids, and our dog. I've been programming using Open Source technologies since '97 and I'm currently an independent software developer specializing in Ruby on Rails and iOS. I am for hire.

Freelancing Digest

The Freelancing Digest is a curated newsletter aimed specifically at freelancers. Delivered on the 1st and 15th of the month, each issues contains links to some of the best articles on the web to help you establish and grow your freelancing business.