Test Driven Development and Teenage Sex 9
Twenty years ago, I learned about sex for the first time. All my friends said they were doing it, although I think most of them were full of it and just wanted to look cool. I didn't know much about sex back then but I'd read about it in The Joy of Sex and watched it on TV. There's something about actually doing it that you don't understand through those other mediums.
Learning about testing has been a very similar experience for me. I've known about it for awhile, all my programmer friends say they're doing it, and I've even read Test Driven Development By Example by Kent Beck. But doing it for the first time is a completely different experience. At first, I didn't know exactly what I was doing, I was aimlessly exploring the inputs and outputs, and before I knew it, I'd had my first testing orgasm. The tests I was writing discovered a serious bug in my code. That's when it clicked for me, really understanding what test driven development is about. If I had written the tests first, the specific bug they revealed wouldn't have existed in the first place.
Now that I've popped my testing cherry, I want to keep doing it, and much like my first sexual partner, Rails makes it easy. And when you get comfortable with your new partner, you can introduce great toys like ZenTest that will improve your experience.
Rush to Rails 1.2 Adds Tons of New Features 12
- Access nested attributes in RJS templates. Now you can use syntax like this: page[:foo][:style][:color] which will generate javascript like: $('foo').style.color
- Michael Koziarski is my hero for this change. If you've ever tried to use a 'quote' column in your model, you quickly found out that it conflicted with AR's quote column method. No longer is this an issue. def quote has been changed to def quote_value
- Calling image_tag without the file extension now raises a Deprecation warning. In 2.0, it will no longer append .png to the file name. This is welcome change, unneeded magic is well...unneeded.
- UPDATE: This change has been reverted for the time being. Now you can access the locals hash directly. In your partials, you can check if a local varialbe was passed in by doing:
if locals[:local_var] then ... - In 2.0, the default for foreign_keys will be the association name, rather than the class name. So if you specify a :class_name with no :foreign_key on your belongs_to associations, it will throw a Deprecation warning. The tests explain this pretty well:
def test_deprecated_inferred_foreign_key assert_not_deprecated { Company.belongs_to :firm } assert_not_deprecated { Company.belongs_to :client, :foreign_key => "firm_id" } assert_not_deprecated { Company.belongs_to :firm, :class_name => "Firm", :foreign_key => "client_of" } assert_deprecated("inferred foreign_key name") { Company.belongs_to :client, :class_name => "Firm" } end - The Ruby/MySQL driver that ships with Rails has been updated to work with the new authentication in MySQL 4.1+. Of course, everyone uses the Ruby C bindings to MySQL right?
- My own patch to distance_of_time_in_words was applied. What does this mean to you? Nothing at all, I just wanted to tell you about it.
- Some nice additions to Prototype Element Handling. You can now traverse the DOM using the new Element.up, Element.down, Element.previous and Element.next methods. To make debugging easier, you can use Element.inspect. Check out the changeset for more useful changes.
Examples: <div id="sidebar"> -> $('nav').up() or $('menu').up('div') <ul id="nav"> -> $('sidebar').down() or $('sidebar').down('ul') or $('menu').previous() <li>...</li> -> $('sidebar').down(1) or $('sidebar').down('li') <li>...</li> -> $('sidebar').down(2) or $('sidebar').down('li', 2) or $('sidebar').down('li').next('li') <li class="selected">...</li> -> $('sidebar').down('li.selected') </ul> <ul id="menu"> -> $('sidebar').down('ul').next() - Rails will actually use the 500.html thats been sitting in public for awhile when your application fails to catch an exception not related to routing.
- In the testing department, assert_tag has been deprecated in favor of the new assert_select family of assertions.
- Another one of my patches got applied. radio_button_tag now generates a unique id attribute based on the name_value pattern.
- And plenty of other deprecation warnings throughout Rails...those you can figure out for yourself.
LiteSpeed Web Server 2.2 includes Rails Support 20
LiteSpeed offers a Standard Edition which is free for private and commercial use, the only restriction being that your site can't serve content related to pornography, warez or illegal activities. This is an odd restriction, but I guess it's cool that they stand by their principles.
To keep things DRY, I won't repeat LiteSpeeds feature set here. Instead, I'll "show" you why I choose LiteSpeed and why I think you should give it a test drive as well. I've put together two screencasts for your viewing pleasure. The first will demonstrate just how easy it is to get up and running with LiteSpeed. From installing the server to a fully deployed Rails application in under 4 minutes. Live and uncut. It moves along pretty fast, but I felt it was a good demonstration of the effort the LiteSpeed developers have put into supporting Ruby on Rails. In the second screencast, we'll take a more in-depth look at some of the cool features of LiteSpeed Web Server. Hope you enjoy them, I had fun making them.
Up and Running with Rails in Under 4 Minutes - 3:25 runtime - Flash
LiteSpeed In-Depth - 21:35 runtime - Flash
UPDATE: The screencasts show that you have to copy dispatch.lsapi into your public directory, with the 2.2 release, this requirement is lifted. The ruby-lsapi gem still needs to be installed, but LiteSpeed will handle the dispatching to Rails through their LSAPI automatically.UPDATE: When running the script to restart LiteSpeed, make sure you run it as a user with root priviledges. So for Mac users: sudo lswsctrl restart
More reasons for Rails NOT to be mainstream 11

What happened next is hard to describe but it's like a pack of wolves came out and shredded him apart. Not sure where these "Rails" programmers came from but I hope they don't stick around. Besides, how can you get upset at a guy that looks like a cute little chia pet?
LiteSpeed 2.2 eases Rails Configuration
Once you define the defaults for RoR applications on your webserver, you can setup and deploy a site in just a few clicks. Prior to the 2.2 release you had several options for getting LiteSpeed to redirect requests to dispatch.lsapi, you could use rewrites or 404 redirects. Now in 2.2 you can just use the new Rails context feature. LiteSpeed will handle the connections to dispatch.lsapi.
Speed plus agility, what a great combination. Check out their Wiki for some quick start instructions on getting up and running with Ruby on Rails on their platform. I'm interested in seeing what performance benefits I will receive with their Enterprise Version running Rails on the new SMP server, hope they offer educational discounts.
Rails Documentation Fund 2
Rails Documentation Fund
Installing Raspell on Intel Mac 8
Most of the work for a Rails based Spell Checker has been done already by Dee Zsombor in his How to build an AJAX-ed spellchecker with Ruby On Rails article. In his article he shows how to use Raspell (the Ruby ASpell bindings) to implement an AJAX based spell checker in Rails. While his tutorial worked great on Linux, Raspell failed to compile (manually or using the gem) on Intel Mac. The compiler was complaining of multiple symbol errors defined in raspell.h. Even though it had pre-processor IFNDEF statements, it still acted like it was including the header multiple times. While there may be another way to fix this, the quick and simple way was to take all the code from dictinfo.c and aspell.c and inject it into raspell.c. Problem solved.
Hopefully, in a few weeks, I'll be able to release a Rails SpellChecker Plugin which will enable spell checking on any text field/area with a simple Rails helper method.
RailsConf Update 3
Mike Clarks Introduction to Capistrano was pretty good. Although I don't personally plan to use it until it works in parallel, it's still a pretty nice piece of software, although I still prefer my multicast notification and ftp-diff pull solution better. Maybe I should make Castripano???
The next session doesn't even deserve any mention, if you were stuck in it then you know what I'm talking about.
Dr. Stefan Kaes' session on Optimizing Rails had a lot of excellent material presented, although his presentation style was pretty dry. Much better talking to him in person.
I'm sure Martin Fowlers keynote was filled with insight, unfortunately, most of the caboosers were busy negotiating how many and what type of pizzas to get for dinner.
Afterwards, we acquired a room in the hotel and had some famous Chicago Deep Dish pizza from Giordanos. Think this is the first time in my life 2 pieces of pizza has filled me up, gotta love Chicago pizza!
Paul Graham's poetic speech was excellent and dealt with some items that I struggle with, mainly about taking risk. I have a lot of good ideas for applications, but my inner self talks me out of them before I even start coding.
To cap off the night, Why the lucky stiff did his thing. While I can certainly appreciate Why's artistic creativity, it was beyond the scope of my understanding. The only thing that I understood was Robert Scoble killing David Heinemeier Hansson. Others really seemed to enjoy it though. I imagine better acoustics would have improved the act.
Let's hope tomorrow continues to improve on the quality of the sessions and keynotes.
Hello Chicago!
I haven't flown anywhere for quite awhile and I guess lighters are on the "banned" list of items for carry on (ironically, matches are ok????). So after my lighters got confiscated, I had to pay $6 for a pack of matches. The good news is, they came with a free pack of cigarettes.
More later as the conference progresses....
Handling Invalid Dates with ActiveRecord Date Helpers 3
In controller.rb:
def create
begin
@client = Client.new(params[:client])
# Catch the exception from AR::Base
rescue ActiveRecord::MultiparameterAssignmentErrors => ex
# Iterarate over the exceptions and remove the invalid field components from the input
ex.errors.each { |err| params[:client].delete_if { |key, value| key =~ /^#{err.attribute}/ } }
# Recreate the Model with the bad input fields removed
@client = Client.new(params[:client])
end
if @client.save
flash[:notice] = 'Client was successfully created.'
redirect_to :action => 'list'
else
render :action => 'new'
end
end
In model.rb:
validates_presence_of :date_field_name, :message => 'must be a valid date'
Older posts: 1 2