Archive for the ‘ruby’ Category

Great BDD for Rails tutorial

Wednesday, August 30th, 2006

I’ve kind of put behavioral-driven development in the “interesting but a bit whacky”-bucket. Maybe something will get out of it but right now it’s not compelling enough for me to use it and certainly not to involve myself.

That said, this great tutorial by Luke Redpath did impress me. Those tests specs certainly look more better than normal Rails unit tests.

On the other hand, I am a bit cautious about doing super-detailed unit-testing of validations. I always get suspicious when the test code is orders of magnitude more lines of code than the actual application code.

Rubby on Rails

Monday, August 14th, 2006

They fight with the Javacs all the time and even though they are basicaly Camp this does not mean they do not kick ass! They have a religion that is called ‘Getting Real’ that costs 20 dollars and is based on Zen (like Rubby).

Hilarious!

Mailing list for RBatis

Thursday, May 25th, 2006

For any questions regarding iBatis for Ruby please use the development list of the iBatis project on Apache as described here. Archives are here. Please do let us know how you use RBatis and what features you would like to see the most.

When we get a real release we will set up a user support list specifically for the Ruby port.

Expect an early access release before RailsConf.

Speaking of RailsConf, I won’t make it this year but I will send my proxy Badrinath Janakiraman, an extremely talented developer from our India offices, to answer all your questions. He is currently placed in Chicago which is a bit closer than the other side of the planet where I am. (Sydney is truly an amazing place to live, but sometimes it just feels so far away from everything.)

iBatis for Ruby now in Apache Subversion repositories

Tuesday, May 23rd, 2006

iBatis for Ruby (aka RBatis) is now finally available in the Apache Subversion repositories on this Subversion URL:

https://svn.apache.org/repos/asf/ibatis/trunk/rb/

For those of you that doesn’t know what iBatis is: It’s a very simple O/R mapper that allows for complete flexibility when it comes to O/R mapping. It doesn’t make any assumptions about the database at all so can therefor handle virtually any (relational) database schema in existance. This flexibility comes to a cost of course, using iBatis is several times more time-consuming and error prone compared to ActiveRecord.

You should not use iBatis unless you really have to: use ActiveRecord instead. I warn you, do not underestimate how much more work it can be to do manual O/R mapping. Or as Chad Fowler so eloquently put it on Rails Core:

Jon, I like what you’re doing, but by God I hope I never have to use it.

Here’s a simple example of a model object implemented using iBatis:

class Product < RBatis::Base
attr_reader :product_id
attr_reader :name
attr_reader :items
attr_reader :description

resultmap :default,
:product_id => [“productid”, String],
:name => [“name”, String],
:description => [“descn”, String],
:items => RBatis::LazyAssociation.new(
:to => Item,
:select => :find_by_product,
:key => :product_id)

statement :select_one, :find do |productid|
[“SELECT * FROM product WHERE productid = ?”, productid]
end
statement :select, :find_by_category_with_limit_and_offset
do |category, limit, offset|
[“SELECT * FROM product WHERE category = ? LIMIT ?, ?”,
category, offset, limit]
end
statement :select, :find_by_category do |category|
[“SELECT * FROM product WHERE category = ?”, category]
end
statement :select_value, :count_in_category,
:result_type => Fixnum
do |category|
[“SELECT COUNT FROM product WHERE category = ?”, category]
end
end

There is a complete application implemented as a demo. It’s a reimplementation of the good old PetStore app, which is also used as a demo for the Java version of iBatis. The PetStore database schema is (in)famous for it’s utter quirkiness database schema, for example one of the domain objects is scattered over three tables. Even if the Ruby on Rails (with iBatis) implementation is significantly more complex than a normal Rails application it’s significantly simpler than the Java counterpart (and just trust me when I say it took significantly shorter time to write). Check out the demo here, it should show how to use iBatis for Ruby in most simple cases (for the complex ones you’re on your own for the time being):

https://svn.apache.org/repos/asf/ibatis/trunk/rb/rpetstore/

You should be able to install the plugin by simply doing:

script/plugin install \
      https://svn.apache.org/repos/asf/ibatis/trunk/rb/rbatis/

I have a lot planned for this one but unfortunately just too little time to do it at the moment (something that should hopefully change soon). I want to support things like: outer join fetching, prepared statements and stored procedures. Some of this can be implemented in RBatis but some needs changes to be done in ActiveRecord and in adapters if they are to support this (prepared statements are for example very important with Oracle databases). I am planning at least a beta release before RailsConf. Watch this space for more details. This is an Apache project, so normal Apache procedures will be followed for patches, committership and so forth.

Like this article? Digg it!

Simon Harris on the Rails

Monday, May 1st, 2006

Simon Harris, friend and ex-ThoughtWorker, is on the Rails. Simon is by far one of the smartest persons I’ve met, with him joining up Rails brain power has just increased a significant step. Simon is just warming up but has already written a couple of insightful blog entries. I would subscribe to his feed straight away if I was you.

Messaging for Rails

Monday, April 10th, 2006

So, Obie let the cat out of the bag. :-)

Here’s the official story: Yes, we’ve been working on a messaging plugin for Rails. Yes, it works, it will be in production this or the next week. Yes, it’s pretty cool.

And, no, it’s not ready for general consumption.

That much for release early, release often, huh?

We’re calling it a13g (A-thirteen letters-g or ActiveMessaging) because names with numbers in them are soooo Web 2.0. Obie doesn’t like it but oh well, can’t please everybody.

Stay tuned for my next blog post: How to integrate Rails with CICS applications running in your trusty OS/390 box. Doesn’t get more enterprise ready than that! :-)

(Joking aside, I can actually write a blog post about that if anyone is interested. But they would have to be damn interested as it’s not exactly a ride in the park.)

See you in Campfire.

’scoped_access’ plugin, Ruby 1.8.2 and Rails 1.1

Wednesday, April 5th, 2006

If you get the following error while using the scoped_access plugin:

NoMethodError: protected method `scoped_methods' called for Member:Class

Then you need to upgrade from Ruby 1.8.2 to Ruby 1.8.4. I’ve been fighting this problem for a couple of hours now, so I thought I’d just add this solution to the Google hive mind.

Selenium and Rails

Monday, February 6th, 2006

Jonas Bengtsson has produced a great Rails plugin for all you Selenium users out there. I strongly recommend you check it out.

For all of you that haven’t started using Selenium yet, please give it a ride too! You’re not going to regret it. There has traditionally been a bit of fiddling around to get Selenium running in a project as the JavaScript needs to run inside the same web application (or at least on the same domain).

Not so after Jonas’ great work! Installing Selenium support into a Rails project is simply a case of:

gem install selenium
script/plugin install http://andthennothing.net/svn/public/selenium_on_rails/

As an added bonus the TestSuite.html files gets generated automatically and you can also write your tests in Selenese (RedCloth style tables) rather than those dreadful HTML tables (my T, R and D buttons are getting worn down on my keyboard).

Truly great stuff!

Mmmm, monkey patching

Wednesday, February 1st, 2006

Hearing something like this makes me happy I jumped the Rails band wagon.

There’s a mix of forces in play here. First of all there’s some very powerful technology. In Ruby you can re-open any class and “monkey patch” it, that is change whatever’s going on inside it. (“Monkey patching” is a phrase coined by Pythonistas, definitely derrogatory, I’m expecting it to become a phrase in the Ruby community too, definitely not derrogatory.)

This is a very powerful feature of Ruby and with all great power comes great responsibility. In the hands of the wrong people this could go “k

Easier ad hoc stubbing with OpenStruct

Monday, January 30th, 2006

In Rails, you want to write a test for an object that uses some methods on another object but you don’t necessarily want to test that other object. You can try to set up complicated fixtures or you can crank up your favorite mock object framework.

Or…

You can just use OpenStruct to stub out the underlying object. Like this, where I stub out a SimpleRSS item:

e = Episode.new(OpenStruct.new(:title =>
     "Battlestar Galactica 2x14 (DSRip-UMD)[VTV]"))
assert_equal("Battlestar Galactica", e.show)
assert_equal(2, e.season)
assert_equal(14, e.episode)

For the nomenclature freak, this is not mocking as I really don’t care how the Episode interacts with the item. This is stubbing, I replace an existing implementation with a dummy implementation for the sole purpose of easing unit test set up.