acts_as_enumerated Blowing Up Your Testing Spot?

If acts_as_enumerated classes are borking when you run your tests, here's a nasty workaround I did that just might work for you:

class MembershipStatus < ActiveRecord::Base
  if RAILS_ENV == 'test'
    def self.[](label)
      case label
      when :pending
        MembershipStatus.new(:id => 1)
      when :accepted
        MembershipStatus.new(:id => 2)
      when :denied
        MembershipStatus.new(:id => 3)
      when :invited
        MembershipStatus.new(:id => 4)
      end
    end
  else
    acts_as_enumerated
  end
end
Written on Thursday, December 24, 2009 | Tags: ruby, rails, testing, development