Shoulda Macro for acts_as_tree

I love writing tests and I love Shoulda.  Here is an acts_as_tree macro I threw together.


class Test::Unit::TestCase

  def self.should_act_as_tree(opts = {})
    klass = self.name.gsub(/Test$/, '').constantize

    foreign_key = get_options!([{:foreign_key => 'parent_id'}.merge(opts)], :foreign_key)

    context "To support acts_as_tree" do
      should have_db_column(foreign_key).of_type(:integer)
    end

    should "include ActsAsTree methods" do
      assert klass.include?(ActiveRecord::Acts::Tree::InstanceMethods)
      assert klass.methods.include? "root"
      assert klass.methods.include? "roots"
    end
  end
end

Popularity: 1%

Notes On Upgrading To Rails 2.3

I am upgrading from Rails 2.2.2 to 2.3.2 on a project today.  Here’s what I’ve found so far.

  1.  RAILS_ROOT/app/controllers/application.rb has been renamed to application_controller.rb.  Upon upgrading if you see /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:443:in `load_missing_constant':NameError: uninitialized constant ApplicationController, that’s the change you need to make.
  2. Test::Unit::TestCase is now ActiveSupport::TestCase. The error you’ll see is undefined method `use_transactional_fixtures=.
  3. Using fixture_file_upload stops working unless you include ActionController::TestProcess.

More as I find them…

Popularity: 18%