Showing posts from December, 2006

Rails Tests With Fixtures Suddenly Stopped Working From Command Line?

Now, this is a weird one. I'm hoping someone might have a clue as to why this started. All of my Rails tests work fine in RadRails . However, if I try to run them from the command line via `rake`, they fail. After much searching, turns out that only the tests with fixtures were failing. And after even more investigation, it turns out that the method `setup_with_fixtures` was never being called. This method is defined in `fixtures.rb`, which also aliases the `setup` method to `setup_with_fixtures`. To get my tests which use fixtures to work again, I had to place a call to `super` inside my test's `setup` method. This kicked off `setup_with_fixtures` just fine. Now, here's the weird part. This all works without the explicit call to `super` in RadRails. Also, apparently I don't need this call because the builtin generators don't include that call. So, something is happening in the load order on the command line with is altering the behavior of `setup` in tests

Great Plugin For Eclipse Finds and Opens Any File With a Hotkey

The GotoFile Eclipse Plugin is great for opening a file with a simple hotkey. I often need to open a file for which I already know the name and I don't want to browse around my project for it. It's often easier just to hit `Ctl-Alt-N` and then start typing. The plugin even supports fuzzy matching. This plugin works in RadRails , too!

validates_date_time Not Ready for Prime Time

Just a warning to those that might be looking to use `validates_date_time` for Rails . It turns out that it implements its own date and time parsing. This is separate from the current date and time parsing in Rails, which is currently handled by the DB driver. This dual reality is very confusing, and creates two different parsing logics and semantics in your application. I fought for an hour trying to figure out why '2006-1-1' was not a valid date. It was working before this plugin. Reason? My current database, MySQL knows what '2006-1-1' is and thus was able to parse it. But the plugin doesn't know this format. I'm not saying that I approve of the fact that the date/time conversion is handled by the database driver. In fact, I know it's not very portable. But this plugin should rely on that behavior, or be much more liberal and understand 2006-1-1, or use any existing Date or Time parsing. Another odd thing about this plugin is that `validates_date

Testing Rails ActionMailers

The Exciter has a great post for testing Rails ActionMailer fixtures . It tells you to throw out the generated fixtures and tests that come from the generators, and to write very simple tests that check bits and pieces of the email's content.

Sometimes, You Just Don’t Need a Plugin

I loved this blog post by Obie Fernandez because it illustrates how we, as developers, sometimes choose the more technically challenging way to do things instead of just the simple way. In blog entry, this developer needed to solve a problem, and ended up writing a whole rails plugin for it. If you read through the comments, you'll realize he took the difficult route. His problem could have been solved by some simple OOP. Read the blog entry, from top to bottom including the comments. I love it because it shows how sometimes you just need to write a few lines of code. :)

Locking Rows in SQL Server 2005

There turns out to be a few different ways to lock rows in SQL Server 2005. The `SERIALIZABLE` tag is one of the options. Here are a few more: SQL Server Row Locking Strategies As an aside, Rails (and Hibernate ) support object locking with database locking semantics. In Rails 1.1.x, only optimistic locking was supported. Rails 1.2 added support for pesimistic locking . Hibernate accomplishes the row lock with: return tableName + " with (updlock, rowlock)"; AFAICT, Rails punts on this. I can't find the locking syntax in the connection adapter. There is an add_lock! But it expects the locking syntax string unless you can use the default (`FOR UPDATE`, which of course SQL Server doesn't support). That's pretty lame on Rails' part. But anyway...

When Local is Remote in Rails, and Other Tales of Eccentric Error Enforcement

(*Note*: This applies to Rails 1.1.6) Yesterday I was adding custom error pages that can be rendered like any other page in our application, and came across some very odd (and imho broken) logic deep inside Rails . In today's "What's Really Reird with Rails", I'll show when a local connection is not a local connection and hope you can't always believe the documentation. To set the stage, I first need to explain the theoretical difference between a local request and a remote (or public) request. In Rails, a local request gets special treatment on error. When your request is local, you will see handy dandy debug messages full of stack trace goodness. The idea here is that if you're a local request, you must be a developer and you would want to see just what caused the error. In contrast, a public request is considered not coming from a developer, and a user friendly error page will be displayed instead of the debug stack traces. Just what is considered a