“resource libraries” polemic!

I’ve been off for a while but I’m planning to come back now that I resolved most of my personal and professional life issues that were not letting any time for me to write here.

I’ve been fond of Resource Libraries since I discovered resource_controller devolved by James Golick.

I’ve read some good stuff about ResourceLogic by Ben Johnson (the creator of Authlogic).

More recently emerged Inherited Resources by José Valim that claims to resolve many issues that resource_controller and ResourceLogic had.

I did not have time to study Inherited Resources or even to use it yet, but I suggest that you read the reasons why Ben Johnson decided to discontinue ResourceLogic development.

My personal opinion is: I’ll still use Resource Libraries when it is appropriate. Like everything, you must always ask yourself if it is pertinent to use it for this particular task, piece of code, controller, application, plugin, gem…

, , ,

No Comments

TDD on Rails #4: RSpec, Authlogic, Factory_girl and resource_controller

So well, I decided to use RSpec, Authlogic, Factory_Girl and resource_controller on my new application! But I’ve encountered some problems making all these working together. I mean I did not find any good tutorial showing how to do it step by step, so there it is!

Read the rest of this entry »

, , , , ,

11 Comments

Pimp my test on Mac with Growl

Please see this very good tip on how to integrate ZenTest autotest with growl: Pimp You .autotest

Splendid!

, , , ,

1 Comment

TDD on Rails #3 – Fixtures

Yet a little post here… maybe I should gather more information and experience and write bigger post… But that will do for now… I think that in the end, I’ll try to find time to write a big article about TDD on rails, with my whole experience… I’ll just let it documented here.

Next step for my TDD application: using fixtures. Fixtures permit you to populate you database before running some tests. For example, you want to see if your User.find_admin stuff works the way you want, then you’ll just populate your database with a couple of Admin users and check if your method retrieves them from the database correctly.

Rails ships with its out of the box fixtures solution called fixtures. But reading some articles, search through the github projects and learning how the default fixtures implementation works made me realize that it can be a pain… And there is some fixtures replacement, here is a non exhaustive list:
- fixjour
- replacefixtures
- machinist
- object_daddy
- factory_girl
- …

And much more. That disconcerting, so much options. I quickly read the github (if github hosted) readme file and even before reading this prediction I choosed factory_girl because of its simplicity.

What do I mean with simplicity? INHO you should have a good idea of what the plugin/gem/code is doing giving a quick look at the github project home. Fixtures are something quite simple and the fixture replacement should quite simples too. And factory_girl caught my attention excatly because of this: clear, clean, easy to understand and to use.

, , , ,

No Comments

TDD on Rails #2

In my new app that started as a POC of TDD, I’m going to use Authlogic. And I followed the doc and some post here .

Again, I did lots of behavior thinking without TDD/BDD in mind…. The result was that I was with some controllers and my model created without any test related thing going on…

The thought of the day is: never user ./script/generate [model|controller|...] anymore… use ./script/generate [rspec_controller|rspec_model|...]

No Comments

Install passenger on Debian

Need packages to be able to install Passenger on Debian sid:

- ruby1.8-dev
- make

, , ,

No Comments

Rails 2.3 on Debian

I decided to install a new Rails environment in a VM using Debian (testing) to be able to code when I don’t have my Macbook.

This is my experience. Read the whole article before running any command you find in here.

I thought that it would be as easy as:

1
2
3
4
5
debian~:# aptitude install ruby rubygems
debian~:# gem install rails
debian~:# rails myapp
debian~:# cd myapp
debian~:# ./script/server

But the result was not as expected:

1
Rails requires RubyGems >= 1.3.1 (you have 1.2.0). Please `gem update --system` and try again.

Well, let’s do as told:

1
2
3
debian:~/myapp# gem update --system
ERROR:  While executing gem ... (RuntimeError)
gem update --system is disabled on Debian. RubyGems can be updated using the official Debian repositories by aptitude or apt-get.

No good… What now? Let’s google it. Yeah there is a gem that allows you to update rubygems to the latest version:

1
2
3
4
debian:~/myapp# gem install rubygems-update
debian:~/myapp# update_rubygems
debian:~/myapp# gem install rails
debian:~/myapp# ./script/server

Voila!  (almost)
Did we need to reinstall the Rails gem? Well, yeah… Debian’s version of rubygems stores his stuff in the /var/lig/gems folder while this new updated version stores in /usr/lib/ruby(…).
A good thing with this rubygems installation is that we do not need to edit the path anymore as the bin (rails…) are now in the /usr/bin folder.

Now that we have solved the rubygems version problem, let see what problem is showing now:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
debian:~/myapp# ./script/server
=> Booting WEBrick
=> Rails 2.3.2 application starting on http://0.0.0.0:3000
/usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/initializer.rb:269:in `require_frameworks': no such file to load -- net/https (RuntimeError)
from /usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/initializer.rb:134:in `process'
from /usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/initializer.rb:113:in `send'
from /usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/initializer.rb:113:in `run'
from /root/myapp/config/environment.rb:9
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:156:in `require'
from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:521:in `new_constants_in'
from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:156:in `require'
from /usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/commands/server.rb:84
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from ./script/server:3

net/http??? Google, my friend, what’s going on? After finding articles about recompiling ssl, i found this solution, much more convinient:

1
2
debian:~myapp/# aptitude install libopenssl-ruby1.8
debian:~/myapp# ./script/server

Voilà!!! It’s working at last! I must admit that I am a little desapointed. I thought it would be much easier to have rails 2.3 running on debian.

My next step is to have Vim configured so it would be very close to using Textmate!

, ,

2 Comments

TDD on Rails #1

Back here, talking about my journey learning Ruby and Rails.

What would be Rails without TDD? And what is TDD? BDD? Test Driven Development and Behaviour Driven Development… Well, I won’t explain these 2 concept here, there is Pliny of articles about it: http://en.wikipedia.org/wiki/Test-driven_development

So I began learning about TDD and BDD and what is the common way to do this in Rails… RSpec is the answer!

As I’ve been working with traditional Java/J2EE/RUP way of life, when I first read: write your test first, I thought: what the fuck? And my first steps (beside learning how works RSpec) were:

- Create a test! Done! It fails! Great!!
- Write some code (a rails model)! Done! The test succeeded! Great!!!
- Think about what must be the behaviour of the model! Great!!
- Write the code before the test! DAMN!!!!

So It’s gonna be hard… Bad habits.. But This is the way to go, trust me!

, ,

No Comments

Ruby Enumerable#every

Martin Aumont created a gem that add an every method to enumerable: see his post.

The result is quite nice:

1
2
enum = [1.4, 2.4 ,3.4]
enum.every.floor        # [1, 2, 3]

, ,

No Comments

Browsers performance and benchmark

Here I am, reading this post> Safari 4 Beta vs Firefox 3.1 Beta. Another benchmark that does not (as pointed out) represent real life. Real life browsing experience is impossible to reproduce, and I did not find a good benchmark that got nearly close to it.

I don’t really care if a single page opens 200ms faster in safari or chrome. What I and my wife really care is how the browser behave after few hours of browsing. How it handles many many opened tabs.
As my wife business has nothing to do with TI, we have a completely different experience about browsing.

I usually browse TI and games oriented site. Few ads, few flash… My wife mainly browse sites that overuse Flash and that are full of Ads…

It is common for me to have over 30 opened tabs, things that I want to read later, things that I am currently reading, and “sticky” tabs like gmail, google-reader, Rails api, etc… Depending of the browser and the opened sites, I end up with my browser consuming 200-400MB and using 5-30% of my Dual Core cpu…

My wife usually have the same number of tabs opened, but her experience is quite different, she ends ups with her browser using up to 1GB, and rarely less than 400MB. She mainly use firefox, and even if there were great improvements in the 3.x version, closing tabs does not free all the memory, she need to restart the browser once in a while (that will open all the tabs that was opened before and go back eating up memory and cpu). Of course the browser frequently gets to his limit point and become unresponsive, only restarting it fixes it.

This was completely off-topic, sorry about that! ;-)

, ,

4 Comments