Archive for the 'Programming' Category

Posted on July 30, 2006 at 1:20 pm

I’ve written a DBF database access library in Ruby, but so far I’ve only tested it with files created with a couple of versions of FoxPro. I need files created with different flavors of DBase, XBase, Clipper, and FoxPro in order to flesh out the test suite. Ultimately, I would like to library to handle all the known variations of the DBF file format.

The project will be available on rubyforge.com within in a couple of days. I’ll post the link as soon as it’s available. The project is hosted on Rubyforge and can be found here.

If you have any files with the following characteristics, please email them to me at keithm@infused.org. Better yet, if you want to take the time to create a fresh sample database for me that would be awesome. Here’s what I’m looking for:

  • Small dataset. Prefer less than 100 rows
  • At least one field from each of the general data types. This means:
    • At least one Character field (if using software that supports fields larger than 254 characters, also include at least one field that is larger)
    • At least one Number field
    • At least one Boolean field
    • At least one Date field
    • At least one Memo field (please include the memo file along with the dbf file)
  • Fields to include if supported by the software:
    • At least one Floating Point field
    • At least one Binary, General, or Picture field (not neccessary to have one of each)
    • At least one Currency field
    • At least one Integer field
    • At lease one DateTime field
    • At lease one Timestamp field

There are a few other data types such as VariField which I don’t really care about right now.

Special Bonus Offer:
If you have access to 3 or more of the software packages and/or versions and are willing to create good sample databases I will pay you for your efforts. Contact me at the email above for details.

Posted on July 28, 2006 at 5:56 pm

I’ve been working on a very large Rails projects at work and found myself spending a lot of time writing the same unit tests over and over again. The application has a very complex database schema and has 159 ActiveRecord models so far. With this many models, there are obviously a ton of associations. I decided that I needed a way to automatically test every association that is defined in a model.

The TestInjector plugin is the result. I still have a lot of functionality that I want to add, but it works very well and it’s ready for others to use.

I posted the details on the Rails wiki:
http://wiki.rubyonrails.org/rails/pages/TestInjector

Or just install it using the plugin manager and take a look at the README file for more details:

script/plugin install http://www.infused.org/svn/plugins/test_injector

or:

script/plugin discover
script/plugin install test_injector
Posted on July 20, 2006 at 12:09 pm

Anybody else have this problem with Anna Chan’s ScopedAccess plugin?

Using a around_filter with ScopedAccess::Filter or the scoped_access helper works fine in normal usage, but when running rake test:functionals, the scope from previously run tests carries over into later tests. In other words with_scope is being set but not removed.

Maybe this is because the controllers are not being torn down after the corresponding functional test is run? I’m tired of peppering my functional test setup methods with Whatever.reset_scope. Anybody have a quick fix for me? I have other things to do, and I’d like to avoid looking deeper into this one…

Posted on February 14, 2006 at 9:43 pm

Have you ever wanted to pass a block to an ActiveRecord model in order to pre-filter results?

module ActiveRecord
  class Base
    class < < self
      alias_method :find_without_filter, :find
      def find(*args)
        records = find_without_filter(*args)
        if block_given?
          filtered = []
          records.each do |record|
            filtered << record if yield(record)
          end
          filtered
        else
          records
        end
      end
    end
  end
end

This is a quick and dirty hack of a plugin, but it does the trick. I’m far from satisfied though. Soliciting opinions from those in the know. Email me.

Posted on January 5, 2006 at 6:40 pm

So, you’re developing Ruby on Rails apps on your shiny Mac and you want to get Growl notifications when your rake tasks are complete. Below, I will illustrate a fairly simple way to get Growl notifications when the test_units and test_functional tasks are complete. This method can be easily extended to any of the other tasks as well.

Prerequisites

  • Growl is installed and running.
  • The RubyCocoa framework is installed.
  • You also need a copy of the Ruby binding from the Growl source distribution. Go to the Growl Developer Downloads page and download the latest tarball or bzball. Extract the files and grab a copy of Growl.rb from the Bindings/ruby directory.

Integration with Rails

First, copy the Growl.rb file that you extracted from the Growl source into your Rails application’s lib directory. Name it growl.rb (all lowercase).

Next, create a new file called growl_notifications.rake in your Rails application’s lib/tasks directory. Copy and paste the following code into this file:

task :test_units do
  task_notifier 'Rake Task', 'Unit testing has completed.'
end

task :test_functional do |t|
  task_notifier 'Rake Task', 'Functional testing has completed.'
end

def task_notifier(title, message)
  begin
    require 'growl'
    n = GrowlNotifier.new('Rake',['RakeTask'],nil)
    n.register()
    n.notify('RakeTask', title, message)
  rescue
  end
end

Growl’s Ruby bindings allow you, among other things, to customize the icon that is displayed in the notification. Take a peek inside the growl.rb file for details.

I would like to extend this further to show the results from the tests in the notification message body. The results are part of a TestResult object, but I’m not sure if there is a way to get at this object by the time I create the notification. If you how I can do this, please let me know!