Multiplay Labs

tech hits and tips from Multiplay

Archive for the ‘Ruby’ tag

Missing cattr_accessor on FreeBSD

with one comment

I’ve recently had trouble with a fresh Ruby install on a new FreeBSD box. Passenger wouldn’t start the app, and script/console gave the following warnings:

Loading development environment (Rails 2.2.2)
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:394:NoMethodError: undefined method `cattr_accessor' for ActiveRecord::Base:Class
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/testing/setup_and_teardown.rb:14:in `included':NameError: uninitialized constant ActiveSupport::Callbacks
/usr/local/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/console_with_helpers.rb:19:NoMethodError: undefined method `require_dependency' for main:Object

Doing rake -T threw up an iconv error. Simply installing the converters/ruby-iconv port fixed all the problems 🙂

Written by Boffbowsh

January 20th, 2009 at 9:46 pm

Posted in Code

Tagged with , ,

Shoulda woulda gotcha: setup doesn’t run when you think it runs

without comments

Lots of hair tearing over the last few hours due to a totally unexpected gotcha. Take the following code from a shoulda functional test:

context "Logging in as an inactive user" do
	setup do
		@user = Factory(:inactive_user)
		post :create, :login => "", :password => "monkee"
	should_redirect_to "users_activate_url(#{})"

On first glance, you’d think this would work right? Wrong. The setup isn’t called until after our should macro is evaluated, and so #{} fails with a nice WhinyNil error.

This would ideally be worked around by a block deferring the execution a-la factory_girl deferred blocks. I’ll have a think about how best to accomplish this and submit it to the Thoughtbot guys. In the meantime, the unfortunate workaround is to use an instance variable from your controller, like so:

should_redirect_to "users_activate_url("

Written by Boffbowsh

December 2nd, 2008 at 10:31 am

Posted in Code,Hackery

Tagged with , ,