Categories
note to self programming ruby on rails technology tips work

OSX Passenger prefpane tip

I recently undid all my MacPorts and started using Homebrew for some software on my Macs. That meant uninstalling the Apache MacPort and switching back to the default Snow Leopard version of Apache. Everything went relatively smoothly but today a noticed that my Passenger prefpane wasn’t listing all the Rails sites it had previously been managing.

Turns out it was because in my original install of the prefpane I had used the “ports” version of a required ruby file, per instructions, since I was using the MacPort version of Apache. The easy fix is to just reinstall the prefpane. All of my sites now show up in the site listing and I can add the new site I’m currently developing.

Categories
me me me programming ruby on rails tips

Fixing Snarl and autotest_menu in windows

I’ve been trying to get ZenSpider autotest and Windows to play nice for a while. First, I had the problem where autotest would only run once and not stick around waiting for updates to my code. That was fixed by Luke Pearce. He commented on a previous post with his fix and I can confirm that it works. Thanx Luke!

I encountered another problem now. When I ran my autotest but tried to shut it down by hitting Control-C twice in a row, the tests would just reset and run again. Double Control-C is supposed to interrupt the process and allow me to shut it down. This it did not do.

Categories
me me me programming ruby on rails tips

Turning off the Rails 2.3.2 BacktraceCleaner

I had a situation today where, when running some functional tests, the error backtrace being displayed was not helpful at ALL. I was defining a layout for a controller as a symbol instead of a string like I should have been using. You use a string when you are just saying “Use this layout” and you use a symbol when you have a method to call that responds with the layout to use. The error I was getting was …

NoMethodError: undefined method `admin' for #<Admin::RegistrationsController>

but what was the first line that came up in the backtrace?

app/controllers/admin/registrations_controller.rb:18:in `show'

This was giving me fits. There’s no call to ‘admin’ in the ‘show’ method. I knew there had to be something else so I searched for how to see more of the backtrace.

The BacktraceCleaner introduced in Rails 2.3.2 cleans out backtrace lines coming from the Rails framework (Railties, etc). This is usually what you want. However, I was sure that my error was coming from somewhere in the framework. Turns out it’s really simple to turn off the backtrace cleaner. Add this line in a ‘setup’ method in your test_helper.rb file.

Rails.backtrace_cleaner.remove_silencers!

Very simple, very easy. My name is Chef Tell. 🙂

Categories
programming ruby on rails tips

Rails 2.3.2 and testing with assert_select_email

I upgraded a project to Rails 2.3.2 a while back and have been getting the following error when running some unit tests…

NoMethodError: undefined method `assert_select_email' for #<UserMailerTest>

I posted to the rubyonrails-talk google group but never got a response, and I was not the first to post about this problem to that group. However I found someone else commenting on this in an rspec lighthouse ticket and they’d fixed it for their setup. It was an easy conversion to non-rspec and here’s the line you need to add to your test/test_helper.rb file

include ActionController::Assertions::SelectorAssertions

I’m not sure why it’s broken but it appears to have regressed in one of the Rails 2.3.2 RCs.

Categories
note to self programming ruby on rails technology work

log_buddy and Windows

I recently started playing around with the log_buddy gem for Rails and because my development machine is on windows, the “d” method wasn’t playing nice with some paths.  it didn’t like paths that included the drive letter.

this is a sample of a line that would cause log_buddy to barf.  it just so happens to also be the line that causes the error.  🙂

c:/ruby/lib/ruby/gems/1.8/gems/log_buddy-0.0.5/lib/log_buddy.rb:98:in `read_line'

the original line looked like this…

file, line_number = frame.split(/:/, 2)

the fix is to replace that line with

file, line_number = frame.reverse.split(/:/, 3)[1..2].map(&:reverse).reverse

yeah.  ugly, and maybe could be written better but it works for me.

now if only I could get log_buddy to output good inspections of objects I toss to it… like “current_user”.  I’m prolly using it wrong right now, but this isn’t helpful…

current_user = '#<User:0x47143d8>'

just saying.  🙂

UPDATE: I monkeypatched log_buddy to fix this functionality. I created a “RAILS_ROOT/lib/log_buddy_extensions.rb” file with the following code.

class LogBuddy

  private

  # Return the calling line
  def self.read_line(frame)
    file, line_number = frame.reverse.split(/:/, 3)[1..2].map(&:reverse).reverse
    line_number = line_number.to_i
    lines = File.readlines(file)
    lines[line_number - 1]
  end

end

and I figured out that the “current_user” line above shouldn’t be …

d { current_user }

it should be

d { current_user.inspect }

that outputs what I want …

current_user.inspect = '#<User id: 1, login: "matte", email: "matte@localhost", crypted_password: "...", salt: "...", created_at: "2007-08-30 18:23:32", updated_at: "2008-07-08 18:57:45", remember_token: "...", remember_token_expires_at: "2008-07-22 18:57:45", name: "...", password_reset_code: nil, company_id: 2, active: true>'

Categories
programming ruby on rails

before_create gotcha with BetterNestedSet plugin

I’m using BetterNestedSet at work in my Rails work but I’ve been having trouble understanding why my code was giving me an error of “Impossible move, target node cannot be inside moved tree”.