Living on the edge (of Rails) #20 - script/dbconsole and flash.now now test-able

This week’s report covers changes from 5th May 2008 to 11th May 2008 (the day the corresponding Rails Envy podcast was recorded).

script/dbconsole

A script/dbconsole script has been added that allows you to connect to your database using its console client.

If you needed to connect to your production MySQL database (you better know what you are doing!), for example, you can run RAILS_ENV=production script/dbconsole and it will login to your database server using the command line MySQL client. This also works with the PostgreSQL and SQLite databases.

To use this script in your Rails app, remember to run rake rails:update:scripts after updating to edge Rails.

This nice little enhancement courtesy of Steve Purcell, who originally had a similar database console plugin.

Related changeset: http://github.com/rails/rails/commit/4a07103687084496b773e18a03b1f2f5e686f7ad

flash.now is now accessible in tests

This is something that many of us Rails developers have probably come across when writing tests for flash messages being set with flash.now, myself included. Basically, you couldn’t test the contents of your flash.now because they were always being emptied before your test could get to them.

# In your controller:
flash.now[:notice] = 'You gotta be kidding me!'

# In your test:
assert_equal 'You gotta be kidding me!', flash.now[:notice]
# FAILS because flash.now[:notice] is nil

Andreas Neuhaus took a good look at how it works and figured out how to make testing flash.now work without resorting to assert_selects.

Related changeset: http://github.com/rails/rails/commit/74eed6290e63111d1aad2b181692a84f4f040aea

There isn’t much else of note so far but if you’d like to know every gritty detail, you’d probably want to peruse the Rails commit logs. As always, let me know of any suggestions or how I can improve the Living on the Edge (of Rails) series.

3 Comments & TrackBacks (Add yours)

The paper doll icon that precedes each comment is an idea conceived by Vanessa Tan.

Paper doll icon
Juan Lupión's Gravatar

Hi, just a note to let you know that I’m translating your “Living on the edge … ” series into spanish in my blog.

Posted by: Juan Lupión on May 12, 2008 3pm

Paper doll icon
A Fresh Cup » Blog Archive » Double Shot #205's Gravatar

[…] Living on the Edge (of Rails) #20 - Things are moving slowly in edge Rails at the moment. […]

Posted by: A Fresh Cup » Blog Archive » Double Shot #205 on May 12, 2008 7pm

Paper doll icon
Ryan Bates's Gravatar

It appears that dbconsole allows you to pass the environment as the first argument. So you can do this instead of setting RAILS_ENV.

script/dbconsole production

Also, if you want to do this make sure your database.yml settings are correct for that environment so it knows how to connect.

Posted by: Ryan Bates on May 13, 2008 1am

You can subscribe to the RSS feed for comments on this post.

Post a comment

(required)

(required, but never displayed)


You can format your comments using XHTML. Your email address will not be displayed or used for nefarious purposes.

Only following tags are allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>