Tech Blog of T. Boyd: tips, tricks, timely thoughts -- -- -- -- -- -- -- -- -- -- -- -- --

Welcome to my blog! I hope you will find something useful.



sqlite3-ruby gem on Debian Lenny

2010/12/22



No certified package of Sqlite 3.6 available for Debian Lenny. So sqlite3-ruby gem fails with:

  sqlite3-ruby only supports sqlite3 versions 3.6.16+, please upgrade! 

I tried installing from source, but the binary didn’t work.

  undefined symbol: sqlite3_config

So I went back to the Sqlite download page again and got the precompiled binary for Linux. When I used that one instead, I was able to install the gem.


Introducing QuickNav

2010/12/16



QuickNav is an new navigation rendering library for Rails 3 with an emphasis on speed and readability. It has now reached a state where it can be easily integrated in a Rails 3 project, so I have bumped it to version 1.0.

http://www.github.com/tb0yd/quick_nav

A sample of the syntax:

  setup do
    item :forums, "/forums"
    item :blog, "/blog"
    item :sitemap, "/sitemap"
    item :contact, "/contact"
    item :search, "/search"
  end

  transformation do
    if signed_in == true
      push :privacy_settings, "/privacy" do
        push :email, "/email"
        push :profile, "/profile"
      end
    end
  end

Features:

  • straightforward, clean syntax
  • ERB menu templates
  • multiple nav levels
  • guessing selected nav item from the current page’s path
  • sets default nav item label with t()

Test for data leaks in RSpec

2010/11/26



One thing about RSpec is, before(:all) blocks do NOT run inside transactions, as explained here:

If you use before(:all), the created object will remain in the database, so it’s up to you to clean it up yourself instead of relying on ActiveRecord to do it for you.

So when writing setup code in a before(:all) block, don’t forget to tear it down in an after(:all) block.

If you are using MySQL and ActiveRecord, here’s a snippet of code you can put in your spec_helper.rb file as a reminder.

      config.before(:each) do
        if ActiveRecord::Base.connection.execute(
         "select table_rows from information_schema.tables
          where table_schema = '#{ActiveRecord::Base.connection.current_database}'
          and table_name != 'schema_migrations';"
        ).to_a.flatten.sum > 0
          raise "test database was polluted."
        end
      end

The idea here is to make the test suite fail when things get left in the database, so whoever wrote the test will fix it before checking it in.