home icon contact icon rss icon

Textmode

tools I use

Official Ruby on Rails Security Guide

Finally there is an official (?) Ruby on Rails Security Guide available, on rubyonrails.org

It seems to be pretty up-to-date and covers a variety of current issues quite detailed.

I consider this a must read for everyone, especially when developing public applications. There is an online version as well as a free e-book available.

There are even more Guides available at guides.rubyonrails.org

Braid: Simple vendor git/svn vendor branch tracking

I came across a new gem to simplify vendor branch management in a Ruby/Rails Project under GIT: Braid

Braid helps you to manage GIT and SVN vendor branches, a simple example for rails:


# add rails:
braid add git://github.com/rails/rails.git vendor/rails

# add some plugins:
braid add git://github.com/tablatom/hobo.git -p
braid add  git://github.com/dchelimsky/rspec.git -p
braid add git://github.com/thoughtbot/factory_girl.git -p

# updating rails
braid update vendor/rails


Braid also supports:

  • revisions
  • full (History) or squashed mirrors
  • diff information
  • locking/unlocking of mirrors

Looks like it could really save some time – especially when working with both, Git and SVN.

Give it a try: Braid

JRuby is cool even if you don't like Java

I don’t really like Java, although we use it a lot at university. This is the reason I never looked at JRuby.

Andreas, of zargony.com had exactly the same opinion, except that he did give JRuby a try.. :)

So go, and read about the coolness of JRuby even if you don’t like Java.

Ruby Refactoring Book

Some time ago I wrote about a pretty good refactoring book, and complained that there are no Ruby related refactoring books or tools.

Well, time changes, and here it is: Refactoring: Ruby Edition. It’s available for pre-order, go get it :)

Factory Girl - Rails fixture replacement

I think you all know that, when using fixtures in your test, you keep switching between files to see what fixtures there are, always struggling with dependencies and conflicts.

There are a couple of helpers that solve this, but this is the best one I came across until know: Factory Girl

As the names says, it provides some kind of factory for your objects and instances.

The following snippet illustrates the definition of such a factory:


# define an incremental username
Factory.sequence :user do |n|
  "user#{n}" 
end

# define a user factory
Factory.define :user do |u|
  u.admin      false
  u.username { Factory.next(:user) } # lazy loaded
end

# define a project factory with associated user
Factory.define :project do |p|
  p.title 'myproject'
  p.creator   {|a| a.association(:user) } # again lazy loaded
end

Now, this factory can be used in your tests:


it "should do something" do
  Factory.create(:user) # creates a user
  Factory(:user) # creates another user (note the shortcut)
  @u = Factory.build(:user, :username => 'customuser') # only build, no save
  Factory.create (:project, :creator => @u)
end

I think you get the basic idea behind it, it’s actually pretty clean and makes tests a lot more readable without looking at fixtures.

Note: At the time of this writing, the attribute name does not work since there is a conflict (that will be resolved soon). Instead you have to use:


Factory.define :project do |p|
  p.add_attribute :name, "myname" 
end

Free Book: Object-Oriented Reengineering Patterns

Some weeks ago we had a course about object oriented refactoring at university, held by Serge Demeyer which was really interesting.

He released a book about this topic with two other authors:

Object-Oriented Reengineering Patterns collects and distills successful techniques in planning a reengineering project, reverse-engineering, problem detection, migration strategies and software redesign.

This book was recently made available as a PDF for free, if you are interested in learning techniques about refactoring and reengineering, check it out.