new provider
I decided to change my blog's hosting provider and this is the first post using the new service.
Please if you see any abnormal behaviour around here don't hesitate to contact me either at leonardoborges@leonardoborges.com or leonardoborges.rj@gmail.com
Thanks!
mock objects
When testing it's pretty common to see the need for mocking a certain object, say, a Data Access Ojbect. This way you don't need to depend on a database and you can focus on the actual logic implemented by the method being tested.
For that you have several alternatives like creating the Mock class by hand or - and this is the more common - use one of the various mocking libraries out there.
They all look the same but the past couple of days I've come accross to a new - at least for me - mocking library for Java. It's called Mockito. As the creators state, technically, Mockito is a fork of EasyMock.
I have used EasyMock already but I do think Mockito has its advantages. I find it clear and a bit less verbose to write.
From one of the stubbing examples on their website:
//You can mock concrete classes, not only interfaces
LinkedList mockedList = mock(LinkedList.class);
//stubbing - before execution
stub(mockedList.get(0)).toReturn("first");
//following prints "first"
System.out.println(mockedList.get(0));
//following prints "null" because get(999) was not stubbed
System.out.println(mockedList.get(999));
Looking forward to using it in production! ;)
passenger mod_rails and problems with custom apache installation
This week we started to test mod_rails in a couple of projects where I work on. One in production.
Of course it's too early for any conclusions, but I just wanted to share a couple of problems you might find when the installer tries to compile the Apache module.
In our case, and I believe it is the case of many servers out there, we have a custom Apache installation, what makes the installer not find it and/or not find the Apache Portable Runtime (APR) sometimes.
The first one is easy and is documented here. You just seed to export the following environment variable, pointing to your apache installation:
export APXS2=/opt/apache2/bin/apxs
The second one is a bit tricky but it happened only when I tried to install passenger in another server that had CentOS. In this case, you will also need the following environment variable, pointing to your Apache APR config:
export APR_CONFIG=/usr/local/apache2/bin/apr-1-config
It took me a fair amount of time googling around to find this answer, so I hope it'll be useful for someone. :)
presentation spring framework
Last friday I've done a small presentation about Dependency Injection and how it can improve the testing environment of a project. You can find it in the presentations page.
Hope you like it.
euruko 2008 materials available
As some of you know I went to the European Ruby Conf in Prague, this year.
The event was awesome and it's good to know they finally made available the majority of the slides, here.
They also published Matz's keynote, and more videos from the conference are being edited right now, so stay tuned to their home page!
Enjoy!
a couple of things from here
It's been some time since my last post but here I am! Where? In Spain, of course! Having a great time, I must say.
I arrived last week in Madrid and the past 2 weeks before that I spent basically packing my stuff. There is still some paperwork going on but everything is flowing well.
Besides this little feedback, I was reading this week's issue of the excellent series This Week In Ruby, from my friend Antonio Cangiano. I found something quite interesting, a plugin called HoboFields.
One of the things that bothers me in rails is the fact that by looking at your model classes, you can't tell the fields you have there. Sure, you can look at the migration script. Yeah, you can also load the development environment and inspect the object. It's a pain in the @zz! But this is the way ActiveRecord works...
Other ORM solutions like DataMapper, allows you to define the fields directly in the class. It's a much cleaner and clear way to maintain your models. And you get to know what properties you have just by looking at your classes.
That's exactly what HoboFields adds to ActiveRecord.
You define your properties and its types straight into your model class, and the plugin creates the migration scripts for you. Coming from a java world my self, I find it rather interesting, useful and it also reminds me of the way Hibernate works. You define your mappings with anotations in your class and hibernate just generate the schemas from there.
It's worth a try.
passengermod_rails released
Passenger(mod_rails) has been released.
The idea is to ease the pain on rails applications deployment. I tested myself and in less than five minutes I had my application working behind Apache!
I'm not going to say much here besides the fact that it seems like a really good option for rails deployment and people have been talking about it already, including DHH.
But I do recommend a read on the architecture overview document. Be sure to read it all, specially the part on handling concurrent requests.
To install, "it doesn't get easier than" that.
Good job guys.
time to reveal
Some of you may know. Some of you may not. Some of you may find weird. And most of you probably have no idea of what I'm talking about but the thing is: This is a year of big changes for me.
I've been hired by Mirai, a Spanish company located in Madrid, to work as a Software Engineer. Yes, it does mean I'll be moving there. Sooner than later.
Last Friday I've received the great news that my work permit has been approved so I can now request my visa in my hometown and move to Madrid, what will probably happen by the end of this month or the beginning of May.
This post probably explain something to some people. And the bottom line is that this whole story means a great step on my career and for those of you that have been following my posts, that's probably clear.
Because of that I was able to meet wonderful people , learn a bunch of new stuff and be present in important events such as QCon 2008 in London and Euruko 2008 in Prague.
That's it for now. I'll keep you posted about my new endeavor.
I'm really excited about this chance and I invite you all for a beer or two either in Rio or Madrid - Just let me know your preference... :)
jruby db2 xquery bug
Update: Follow up link to this issue on JRuby's Jira, here
As I told in my last post, it was time to give JRuby a serious try. So I took one of our rails projects at work and decided to migrate it to JRuby and see what happens.
We heavily use the XML capabilities of DB2 and this was a huge problem. Every query would work just fine through the activerecord-jdbc-adapter - part of the JRuby Extras . But every Xquery would gracefully fail!
After some debugging I got stuck and decided to get JRuby and activerecord-jdbc-adapter's source to see what was happening.
As I could see, it has a bug -in my opinion - at the java part of the code. The jdbc-adapter is a bridge to allow Active Record to talk with databases through native JDBC drivers, so it's normal that we do have a java part here. At this point, what the code does is to inspect the sql statement sent from ruby and decide if it's a select, update or insert.
I fixed the problem and submitted a patch to rubyforge. I'm not sure if it's the best solution or not, but now I got the xQueries working just fine.
I'd love to hear from people with similar environments whether this patch works for you or not. I'm sure I didn't try every possibility.
If you wanna try it, just drop me a message (e-mail in the About page) and I can send the pre-compiled jar file - for activerecord-jdbc-0.8
You can also just check out the code and compile yourself. ;)
qcon 2008 slides available
Most of last QCon's presentations are available for download here.
Highlights to Ola Bini's on JRuby(pdf) and Randy Shoup's on eBay's architectural principles(pdf).
And while we're talking about JRuby, it's impressive how it's becoming a recurrent and big subject. Fast. It had its own small space at big event like QCon and in the last Euruko in Prague, we had a presentation by the JRuby Core Developers Charles Nutter and Thomas Enebo.
Big companies are sponsoring JRuby's development indirectly or directly, like Sun. And other big companies are endorsing its production ready state, like Oracle, which has a publicly available website developed with JRuby On Rails.
It's past the time to give it a serious try...