CustomerFu - complaint handling for small business

Posted by nick on May 08, 2008

A quick heads-up on a product we’re launching soon. CustomerFu (www.customerfu.com) is an online tool for companies to manage customer complaints.

What happens in many companies - when they’re small, its easy enough to follow up complaints through a paper-based system, or spreadsheets. But if your complaints are being received by more than one person in your organisation, or you have more than one branch or office, things quickly get out of hand. Bigger companies would start up a call-centre, or outsource to one. But that’s an expensive exercise.

So CustomerFu will provide a centralised tool for companies to manage all of their customer complaints, making sure that none of them go amiss, and that every complaint is dealt with properly. Without breaking the bank.

We’re in the home straight with development, so more information soon :)

Cool stuff with Git

Posted by ivor on May 06, 2008

We are currently in heavy development on one of our applications. We wanted to bring the existing deployment up to speed but with some very specific limitations.

I wanted others in the team to be able to clone the branch if they needed to deploy, so I created a new remote branch called ’slicehost’

git push origin origin:refs/heads/slicehost

Next I created a local branch called “slicehost”

git branch slicehost

I did a “git checkout slicehost” and proceeded to make the changes I needed to make before deploying.

I modified the deploy.rb file for capistrano2 and deprec2 to contain

set :branch, 'slicehost'

With the changes locally commited to the slicehost branch I aksed git to

git push origin slicehost

which pushed the changes to the slicehost branch in our repo.

I ssh’ed into the server with the repo to make sure it worked. With the changes ready for deployment I ran (from my local machine again)

cap deploy
cap deprec:db:migrate

and

cap deprec:mongrel:restart

That was that. I could

git checkout master

and continue with the rest of the application development.

I really simple way to solve the problem.
I’m really enjoying git - it feels right :)

Interesting behaviour in Ruby’s division and modulo operators

Posted by maurício on May 06, 2008

My copy of The Ruby Programming Language has finally arrived and of course that I started reading it. One of my first findings about the language semantics has to do with mathematics, more specifically, division and modulo.

As a long time Java programmer, most of my expectations about math in programming languages come from this background, so some of the behaviors of mathematical functions in Ruby have really scared me. Let’s start with a simple example, a basic division, imagine that you have -7 and you want to divide it in 3, as we can’t divide -7 by 3 we have to reach an approximation.

During my math classes, I learned that to do this approximation I would have to use a multiplication, multiply 3 until I have a value as close as possible to -7. The closest one I can get is with -2, as -2 multiplied by 3 is -6 and I would have a remainder of -1 as -1 plus -6 is -7.

A lot of numbers, right?

Open irb on a command line and write:

-7/3

So, are you getting -2? No?

No, you are not. In Ruby, -7/3 is -3.

How the hell does this happens?

In Ruby, differently from C/C++ and Java, the result of the division between two integers where one of them is a negative number will yield a result as if it was a floating point division that rounded towards negative infinity. There is no explanation about why it is done this way (comment if you have any hints) but other languages like Python and Tcl behave in the same way.

Ideally, A divided by B with a result of C and a remainder of D is equivalent to ((C * B) + D), so this simple division would break the whole mathematical equivalence between multiplication and division, right?

Not so fast. The modulo (%) operator also behaves differently when dealing with a negative division. If you try to run (-7 % 3) you will receive 2 and ( (-3 * 3) + 2 ) is exactly -7. So, the operators keep their values equivalent, they just don’t behave the way I was expecting them to.

Another interesting thing is that if you want a modulo operator that works just like Java’s, you can call the remainder method as in:

-7.remainder(3)

This isn’t going to blow your mind or change your life forever, but it’s an interesting behavior that I didn’t have noticed yet.

PS: If you have any idea about why this happens, just drop a comment :)

Git post-commit notification to Campfire

Posted by nick on May 05, 2008

Recently we switched from Subversion to Git, and the thing I missed the most was the post-commit notifications we had popping up in Campfire. So, I added this to the .git/hooks/post-commit file in the project I’m working on:

#!/usr/local/bin/ruby


require 'rubygems'

require 'tinder'

commit_author  = `git show --pretty=format:"%an" HEAD | sed q`.chomp
commit_log     = `git show --pretty=format:"%s" HEAD  | sed q`.chomp
commit_date    = `git show --pretty=format:"%aD" HEAD | sed q`.chomp
commit_changed = `git-diff-tree -r --name-status HEAD`

campfire = Tinder::Campfire.new 'your_account'
campfire.login 'your_username', 'your_password'
room = campfire.find_room_by_name('your_room_name')
room.paste %(Commit by #{commit_author}nDescription: #{commit_log}nnChanged Files:n#{commit_changed})

room.leave

You’ll need to install the tinder and hpricot gems too. And post-commit must be executable

chmod 744 .git/hooks/post-commit

Now this will send a notification to Campfire each time you complete a local commit.

[Thanks to this pastie for the right git commands] 

Our first Rails plugin- ActsAsModerated!

Posted by maurício on April 30, 2008

Disclaimer: This post is first about my experience writing a plugin and then about the plugin itself. If you just want to learn about the plugin scroll down to the “using the plugin” part.

Well, after a while documenting, updating and polishing here is our first Rails plugin (in fact it’s an ActiveRecord plugin =D ). It isn’t something big or something that you couldn’t live without, but it was something helpful on our last project and it doesn’t hurt to give something back to the community after everything that they gave us.

A little history

My last task was building a social community (yeah, another one, but this one is somewhat different than the others in their target audience) which I can’t talk about right now (once they have launched I promise to comment about it here), but one of the features was a moderation queue. The client wanted that every create/update/deletion were held for moderation, in the beginning of the project it looked good enough, we didn’t have a lot of models and I could write a simple moderation queue for those two or so objects.But it’s never as easy as it seems :).

Not too long later the client sent a document asking for a lot of other models (like jumping from two to a dozen) and I couldn’t just write a different moderation queue for every model, so, time to look for a plugin (search first, build later). I couldn’t find anything that worked like I wanted and the closest one needed a “clone” table to keep the models under moderation, so I thought it was too much for something as simple as a moderation queue. Afterall, this is Ruby, not Java =P

So, I couldn’t find anything that did what I wanted (and the way that I wanted).

On the shoulders of giants

Coming from my Java/C# background I was really expecting something “hard” or maybe “challenging” (I wrote a JavaServer Faces component last year, so all my sins are paid until 2010). First, I spent some time reading the “acts_as_taggable_on_steroids” and “attachment_fu” plugins.

After some time reading them I was starting to form an idea about how an acts_as plugin should behave. When you are building an acts_as plugin you have to imagine what new behaviour you will add to your models, my idea was that instead of saving/destroying the object, I could send it to the moderation queue, so, every model that acted as moderated would have a method called to_moderation that would send it to the moderation queue without touching it’s original state, only the moderation object should be saved here, not the moderated model itself.

So, I wrote the Moderation model containing the information that I needed, my idea was to keep it as simple and flexible as possible, I needed to store a lot of different models and I didn’t wanted a separate “clone” table for all of them, so the moderations table would have to store the model.But how could I do it without saving the model?There is an interesting feature on ActiveRecord that many people don’t know about that is the “serializable” attributes. You can “serialize” a complex object into a text column storing it in a YAML representation, so, instead of creating a new table for every model, I would serialize the attributes hash of every ActiveRecord model into the text column. Multiple tables problem solved :)

Going on with the development I noticed that it was really hard to test the plugin using RSpec and the way that plugins are packaged has always bothered me. In Java we did our builds using Ant or (lately) Maven and when you’re using Maven you define the version of your dependencies, so that whenever you have to switch to another machine (yep, I know this is coming in Rails 2.1), it was just a matter of installing Maven and telling it to download the dependencies again.When you’re using a Rails plugin you usually can’t find out which version it is, specially if you’re running on someone else’s code, and this isn’t really good when you just happen to fall on legacy code that you have to deal with.

Fortunately, I saw the “Plugin Patterns” e-book from Andrew Stewart and gave it a spin. Even if you are not planning to write a Rails plugin, you should absolutely check this book, there are great insights about how Rails works and you will figure out that building a plugin is as easy as anything in Ruby, it’s just a matter of knowing where to place your code.And Andrew’s book gave me the idea that was missing, bundle the plugin as a gem!

So, I set out to use Hoe (another nice tool from the Seattle.rb guys) to build my gem. Testing with RSpec became easier and I didn’t need to make crazy black magic to run my specs, it was just a spec file, a helper and a migration, “rake specs” and be done with it. Now, as I had a gem ready to go, I wrote the gem docs and also bundled a simple example application to help people figure out their way when trying to use the plugin.It wasn’t really easy because it was my first time doing it, but now that I’ve learned the quirks and have found plenty of documentation the next time it will be just another plugin.

If you find that something in your app could be moved out from it, take some of your time to move it out, you might learn a lot about your coding style and how to create reusable code in a simple and easy way.

Using the plugin

Enough talking!

Lets see how you can use this plugin to build your own moderation queue. First you have to install the gem (our Rubyforge account hasn’t been enabled yet, so you will have to get the gem here). After installing it you can start to use it in your own rails project or take a look at the example application that is available at the gem directory.Once your app is ready, you have to unpack the gem at your vendor/plugins dir, do it using the following command:

gem unpack acts_as_moderated

This should create an “acts_as_moderated-0.5.0”. After this you have to generate the moderations object migration, just type:

ruby script/generate acts_as_moderated_migration

A migration for the Moderation model object will be created. You can run your migrations to create the table:

rake db:migrations

With the table created, time to use it in your models. Imagine that you have an Article model that you want to be moderated, here’s what you have to do:

class Article
		acts_as_moderated
end

I hope you haven’t typed too much :)

With this call, instances of the Article class will now have two new methods added: to_moderation and to_moderation!. Both of these methods will create a new moderation object containing the current state of the moderated model (in this case, the Article object). The only difference is that the one ending with an exclamation sign will throw an exception if the moderation could not be created.The to_moderation object receives an options hash where you can pass complementary attributes to the moderation object. The default to actions in moderations is “save”, so, if you want to place a destroy action on the moderation queue, you will have to add it to the to_moderation method call, like this:

@article.to_moderation :action => 'destroy'

When this moderation is applied it will remove the moderated object. The only actions accepted right now are ‘save’ and ‘destroy’.And here comes some real world action, that’s how your new controller actions would look:

def create
        @article = Article.new( params[:article] )
	if @article.valid?
		@article.to_moderation # sends this object to the moderation queue
 		# the object attributes are saved with the moderation object
        flash[:notice] = 'Your change was received and placed on our moderation queue'
		redirect_to articles_path
	else
		render :action => 'new'
	end
end

And then you can “moderate” a change calling the moderate method on a Moderation object (try to say this fast!):

def moderate
	@moderation = Moderation.find( params[:id] )
	@moderation.moderate! #moderates the change, adding/updating/removing the moderated model
       	flash[:notice] = 'The changes have been applied'
	redirect_to moderations_path
end

Imagine now that you wanted to know which user tried to peform this change, how could you do that?The to_moderation method receives an array of attributes as a param and those attributes are sent to the Moderation object, so you could just create a new migration adding a new field to the Moderation model:

add_column :moderations, :user_id, :integer

And send the parameter to the to_moderation object, just like this:

@article.to_moderation( :user_id => current_user.id )

To enable this on your app, just create a file called moderation.rb on your app/models folder and add the belongs_to declaration (classes in Ruby are always open, remember?):

class Moderation
		belongs_to :user
end

And you’re done, you have your own moderation queue working for anything and you can even add the user who performed the change. Take a look at the sample app and readme that comes bundled with the gem to learn more about how to code (and even view a “diff” of the moderation object).

Scotland on Rails

Posted by nick on April 21, 2008

I’ve just returned from the excellent Scotland on Rails conference, held in Edinburgh over 2 days.

There was a good line-up of talks and the ones I attended were all interesting in one way or another. Some were nice and practical, and others were more abstract and esoteric.

Day 1:

  • Michael Koziarski talked about beautiful code, by giving examples of not so beautiful code that is in Rails source. For someone that has never looked much at Rails source code, this was pretty interesting, particularly the good explanation of how alias_method_chain is used. He also mentioned this rule-of-thumb, which is something I also subscribe to:
    • First make it work
    • Then make it beautiful
    • Know when to stop
  • Richie McMahon and Maria Gutierrez talked about integrating Rails with an existing suite of Java applications. Their experience covered using web services integration, message queuing and even sharing the database directly.
  • Andy Stewart gave practical coverage of all the options for background processing with Rails, before settling on BackgroundJob as his preferred choice.
  • Jim Weirich & Joe O’Brien did a 3-act play explaining the benefits of mocks and stubs in your tests, in particular with FlexMock.
  • Giles Bowkett gave a great talk on meta-programming, based on the underlying premise of code=data and data=code. What could have been a really dry presentation was spiced up with random insertions of Jessica Alba and Darth Vader. Hilarious!
  • Bruce Williams then explained the new features coming in Ruby 1.9. I must admit that I didn’t pay full attention, since its likely to be a while before these changes filter through to Rails.
  • Day 1 was wrapped up by Gordon Guthrie introducing Erlang and how it supports parallelism right from the insides.

Day 2:

  • David Black opened with an allegory comparing music with programming. Although it was interesting, I must say that the analogy didn’t quite work for me.
  • Jonathan Weiss gave a very straightforward talk on common Rails patterns, which you could see he’d had proper experience with. These covered handling long running tasks, dealing with large files, when to use plugins, handling dependencies, and avoiding denial-of-service attacks
  • Paul Dix did an interesting talk on collective intelligence. His example showed giving movie recommendations. Some very clever maths in use here.
  • Jim Weirich talked on “Advanced Ruby Class Design”. His target audience for this one was Java programmers, showing how to accomplish things in the Ruby Way. But the message was universal.
  • Joe O’Brien explained domain-specific languages. Not really from a technical point of view, but more from a philosophical angle.
  • And the last talk was Charles Oliver Nutter and Thomas Enebo on JRuby. As someone who’d never had a proper look at JRuby before, this presentation was really eye-opening. They gave a good intro to all the reasons why one should consider JRuby, and there are many. JRuby is definitely something we will be having a serious look at.

All in all a great conference. The organisers did a fantastic job, I learned a heck of a lot, and met some cool people. I really hope to come again next year.

PS. For slides of the various presentations have a look here, and click on the slides links.

Rails deployment with Apache and mod_rails on Ubuntu Gutsy (7.10)

Posted by maurício on April 18, 2008

If you have ever deployed a Rails app, you have probably used a mongrel cluster running behind a proxy server (usually Apache, Lighttpd or, not so probably, Nginx) while this isn’t something painfully difficult, it makes Rails applications harder to deploy when compared to PHP, where you just send your file to the server, or Java, where you bundle your app in a .war file and place it on the server’s deployment folder.

The biggest problem with the mongrel cluster approach is that you have to take care of at least two processes. Although it was possible to have only an Apache server to deploy your Rails applications (using FCGI) this wasn’t a good approach as it will hurt your application performance.

But now, we have a true option to run our Rails applications using just an Apache server, and the option is called (tadá!) mod_rails!

mod_rails (or Passenger) is an Apache module that aims to enable seamless deployment of your Rails applications using only an Apache server. No proxies, no (visible) clusters, no other processes to handle, just copy your rails application to folder defined at the Apache’s virtual host configuration and be done with it.

But how does it works?

What mod_rails does is automatically manage a cluster of rails applications inside your Apache server, so you will have all functionalities and performance advantages of running a mongrel cluster without having to manage one. And something that really makes mod_rails special is that your rails applications are independent from the Apache server, if your application blows, the main server won’t go down the tubes. If you want to have a full architectural overview of how it works, take a look at their “Passenger architecture document”.

And now, enough of talking, let’s get our hands dirty and prepare the environment to deploy a rails application to mod_rails. First, this tutorial is aimed at preparing an Ubuntu 7.10, but it should probably work if you’re running 7.04 or maybe even a 6.x, but I can’t guarantee that.

If you don’t have Ruby yet…

If you’re going to do this in a brand new (aka. virgin) server, you will have to install some things (like Ruby :P ) first, login to the machine and start typing:

sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get autoremove

This will update your system and take the garbage away. Then you go:

sudo apt-get install build-essential –y

This will install the software needed to build other things (like your native gems). After installing this, it’s time to install your database (in our case, it’s MySQL, but you can take another one, I promise I won’t feel bad about it) and Ruby, you can do this typing:


sudo apt-get install mysql-server mysql-client libmysqlclient15-dev libmysql-ruby1.8 ruby1.8-dev ruby1.8 ri1.8 rdoc1.8 irb1.8 libreadline-ruby1.8 libruby1.8 libopenssl-ruby irb1.8 libdbd-mysql-perl libdbi-perl libmysql-ruby1.8 libmysqlclient15-dev libmysqlclient15off libnet-daemon-perl libopenssl-ruby libopenssl-ruby1.8 libplrpc-perl libreadline-ruby1.8 libruby1.8 mysql-client mysql-client-5.0 mysql-common mysql-server mysql-server-5.0 rdoc1.8 ri1.8 ruby1.8 ruby1.8-dev zlib1g-dev

It’s possible that the ruby installer hasn’t added the symlinks, so, if typing “ruby”doesn’t work, try this:

sudo ln -s /usr/bin/ruby1.8 /usr/local/bin/ruby
sudo ln -s /usr/bin/rdoc1.8 /usr/local/bin/rdoc
sudo ln -s /usr/bin/ri1.8 /usr/local/bin/ri
sudo ln -s /usr/bin/irb1.8 /usr/local/bin/irb

With ruby installed, it’s time to install RubyGems. You can install RubyGems from apt, but it’s better to download it and perform a manual installation. There you go:

wget http://rubyforge.org/frs/download.php/35283/rubygems-1.1.1.tgz
tar xvzf rubygems-1.1.1.tgz
cd rubygems-1.1.1
sudo ruby setup.rb

After installing it, you also have to add a symlink:

sudo ln -s /usr/bin/gem1.8 /usr/bin/gem

Alfter all this typing, you must be really tired, so now comes the easy part..

As you’re planning to perform a Rails deployment, you are probably using Capistrano (why wouldn’t you use it?), so I have some recipes to make you type less, a LOT less. First, install the Apache 2 server, Apache’s development headers, the Apache Common Runtime, and finally the Rails and Passenger gems:


desc 'Installs apache 2 and development headers to compile passenger'
task :install, :roles => :web do
    puts 'Preparing the environment'
    puts 'Installing apache 2'
    sudo 'apt-get install apache2 apache2.2-common apache2-mpm-prefork apache2-utils libexpat1 ssl-cert libapr1 libapr1-dev   libaprutil1 libmagic1 libpcre3 libpq5 openssl apache2-prefork-dev -y'
    puts 'Installing needed gems'
    sudo 'gem install fastthread rake rails passenger'
end

This task will install the Apache 2 server (even if you already have Apache 2 installed, you should run this task to be sure that you also have the development libraries installed) and the required gems. After this, you’re almost there, login again to your server and type:

passenger-install-apache2-module

You will answer some questions (and probably you won’t need to install anything, as we have already installed all software needed) and when the script is done take note of what he’s saying, which means copy the values to your /etc/apache2/httpd.conf file, it should look like this:


LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-1.0.1/ext/apache2/mod_passenger.so
RailsSpawnServer /usr/lib/ruby/gems/1.8/gems/passenger-1.0.1/bin/passenger-spawn-server
RailsRuby /usr/bin/ruby1.8
RailsMaxPoolSize 2

On the first line, we are telling Apache to load the passenger_module (this is mod_rails), the next ones are mod_rails configurations. RailsSpawnServer is the path to the executable that starts the Rails servers, RailsRuby is where your ruby executable is and RailsMaxPoolSize is how many application instances (just like the mongrel instances) you want mod_rails to start. Don’t leave the RailsMaxPoolSize blank, as it’s default value is 20 (yeah, TWENTY) and you probably don’t have enough memory for all 20 rails applications.

And we’re done!

Well, almost :D

Now that you have apache configured and mod_rails (Passenger) being loaded, we have to tell Apache about our application, we do this using a virtual host configuration, but we are not going to write it with our own hands, oh no, so there is another task to do this for us:


desc 'Creates a virtual server configuration on apache to your application'
task :create_server_config, :roles => :web do	template = File.read( File.dirname(__FILE__) + '/vhost_config.erb' )
    buffer = ERB.new(template).result(binding)
    puts 'Rendering template file'
    put buffer, "#{shared_path}/#{application}-vhost"
    puts 'Copying virtual server config to apache folder'
    sudo "cp #{shared_path}/#{application}-vhost /etc/apache2/sites-available/#{application}-vhost"
    puts 'Enabling the site on apache'
    sudo "a2ensite #{application}-vhost"
end

This task uses an .erb file called vhost_config.erb that should be on the same directory of the file where this task is defined, here’s the template:



<VirtualHost <%= domain %>:80>

    ServerName <%= server_name %>

    DocumentRoot <%= deploy_to + '/current/public' %>

    <Directory "<%= deploy_to + '/current/public' %>">

        Options FollowSymLinks

        AllowOverride None

        Order allow,deny

        Allow from all

     </Directory>

</VirtualHost>

It uses our own configuration (from deploy.rb) to define the virtual server. When we call this task, it will not only generate this virtual host config, but also copy it to the sites-available and then call “a2ensite application-vhost” installing the application on apache.

Then, you can just restart apache with the following task:


task :restart_apache do
    puts 'Restarting the apache server'
    sudo 'apache2ctl restart'
end

And you’re done, your Ubuntu server is running your rails application without any mongrels or anything else to manage besides Apache. Once your application is running, you can restart it with the following task:


desc 'Restarting the application'
task :restart_app do
    puts 'Restarting the application'
    run "touch #{deploy_to}/current/tmp/restart.txt"
end

Whenever you want to restart you app without restarting apache, it’s just a matter of touching the “/tmp/restart.txt” file (you have to create this file manually under your “/tmp” folder, it’s just a blank text file).

After all this, when once you have another application to deploy to the same Apache server, you will just generate a new virtual host file for it and it will be running without any other configuration or anything to manage. Could this be any better?

So, what about the good old mongrels?

mod_rails isn’t going to replace Mongel all over the world, because it’s a Rails only solution (although it probably can be tweaked to run other frameworks). What the guys at mod_rails are doing is integrating the a rails cluster inside Apache itself, without the need to run a separate server cluster, but as this is a necessity generated by Rails’ mono-threaded model, other frameworks, like Merb, will keep on using mongrel as their application server.

Another reason not to just look at mod_rails is when you already have a cluster of rails applications running on many computers and proxied by a common HTTP server, as you really need to distribute the load through many machines using one as a load balancer, it will not be so easy as I’m showing here, but even with a proxy, using apache at the application servers might help the performance of static content delivery.

Acknowledgements and references

Most of the installation instructions that you found here where taken from the following post by Vince Wadhwani (Thanks Vince!).

If you are not going to install mod_rails in an Ubuntu machine, checkout the mod_rails documentation.

Unit tests don’t guarantee that your system works

Posted by maurício on March 05, 2008

Last week we had an interesting message at the RSpec users list, the most interesting part of it is the following:

“I also had to go into specs on a project I’m not working on, and found an unholy hive of database-accessing specs. It’s disheartening. Basically, it’s cargo cult development practices - using the “bestpractice” without actually understanding it.”

You might have read this before, “/specs|tests/ that access the database are evil”, but have you ever asked yourself why?

Behavior Driven Development is the next step after Test Driven Development and it borrows many best practices found in the later. The two principles that interest us most in this conversation is test-first development and unit testing.

The idea behind test-first development is that before writing your code, you should write a test stating what you want you “future” code to do. By writing the test before the code you get to work on the public interface provided by your object, the test is the first client of your code, so, if your public interface is cumbersome or difficult to use, this test will be able to catch a bad idea before it’s materialized in your code.

And where is unit testing in all this? You should be doing test-first using unit tests, as unit tests will guarantee that the code you wrote for that single unit (a method, probably) works alone. If you have more objects that need to be used to test this specific behavior, you should use mock objects (fake objects) in their places, so you won’t be testing them in your unit test. Remember, unit tests should only test a unit of code, no more than that. We should do it this way so we don’t get distracted with the other objects implementation, we focus in testing our target, not it’s dependencies.

When we’re writing specs for our objects they should usually work as unit tests, they should only assert the behaviors of a single unit of code, everything else should be done using mocks and stubs. But I said usually.

As I said before, unit tests and your common specs, should only assert the behaviors of a unit of code without considering their relationships with the other objects on the system, but this only guarantees that they work as units. This will never guarantee that they will really work when in real contact with the other objects in the system, unit testing don’t guarantee that your system works, they surely help you to reach this goal, but they aren’t enough.

And what it has to do with that message, anyway?

That spec that access the database is just like an integration test, it asserts that the code being tested works fine when integrated with the database. So, the integration tests are the ones that really show you that your code works as a system, not only as a group of lonely objects.

I’m not saying that you should leave the unit tests behind, because they have a big importance to help you design your code and be sure that it works as a unit, but you shouldn’t rely only in them to test your system, a good suite of integration tests will give you the trust that everything works fine in conjunction.

And sometimes you can’t unit test a functionality, it’s all about integration. Let’s take the “validates_uniqueness_of” validation in ActiveRecord as an example, if you’re writing a spec for your ActiveRecord model, you should add one ‘it’ statement showing that this is needed (you’re specifying how your model behaves, remember?), so here’s how it could look:

it 'Should not be valid if there is another one with the same name' do

           @common_name = 'testuser'

           @user = User.create( :name => @common_name )

           @another_user = User.new( :name => @common_name )

           @another_user.should have(1).error_on(:name)

end 

How could you perform this spec without touching the database?

First, you could look ad the “validates_uniqueness_of” source code, figure out how it works and stub it to return what you want, but this is bad because if the framework code changes your specs would break. The other way would be changing the database adapter to a mocked one and send exactly the result you wanted, but this is basically overkill. So why don’t you just leave the “purism” behind, test it in your database and be happy that your code works fine?

One important thing to notice is that integration tests are also slower to run, so you wouldn’t like to wait for the full suit run before performing a commit, usually you would run the unit and integration tests that are most likely to break if you did something wrong, the ones related to what you’re doing now and just be done with it.

So, if you’re in a project that has database accessing specs or specs that are using many real objects (and not mocks), don’t feel bad, but be sure that who wrote it knows that he is doing and that everything that can be unit tested is being unit tested. Integration tests should be written after your functionality is implemented and tested with unit tests, they are not interchangeable, nor you will replace one with the other.

And be sure to never commit your code before running your tests :)

Netbeans Color Scheme

Posted by ivor on March 05, 2008

I recently switched from Aptana to Netbeans for me ruby editing.

If you are undecided in the IDE wars, you can download the 22Mb ruby version from here: http://download.netbeans.org/netbeans/6.0/final/

I was looking for a nice color scheme that doesn’t bombard me with to many rays. I found this scheme that claims to be a textmate styled scheme for netbeans. It works for me.

To install as a plugin follow the instructions in the post. To change schemes: Tools >> Options >> Fonts and Colors (button at the top) and choose a new profile. If you followed the instructions, the Aloha option should be in the list.

Enjoy.

Capetown.rb Meeting 3

Posted by nick on February 13, 2008

Our third meeting tonight. On the menu is:

  • Jeremy Thurgood talking about “Pain in Ruby: Things that bit me and their workarounds.”
  • Peepcode screencast - RSpec user stories

We also have give-aways from Joyent and Peepcode.


ambien generic drug generic viagra online generic viagra online viagra with health men amazing blonde fucked cialis high off tramadol hcl dosage hazards of mixing xanax and valium hypnotics ambien valium photo phentermine deals 2 comparison levitra viagra cost of viagra covered by insurance cialis use with alcohol phentermine no prescrip non perscription viagra viagra bph about valium for anxiety add depression actos phentermine cvs pharmacy career get phentermine online phentermine no prescription required online consultation ending ativan using valium what if cialis does not work can you mix tramadol and benedryl viagra oral sex difference between tramadol and ultracet generic viagra cialis photo of ambien cheap cheap drug propecia tramadol weight loss clinic phentermine redondo beach acupuncture oct ivf women viagra phentermine lysergic acid diethylamide ranitidine order ambien with a prescription commview ambien ambien generic pills order free phentermine 37.5 mg 90 tablets ambien imitrex order viagra air travel viagra and alcohol buying valium online pharmacy online caverta vs viagra soma tramadol fioricet phentermine 37.5 no prossesing fee order phentermine cheap online buy viagra onli dogs tramadol artritus no doc phentermine viagra boys clips difference between meridia and phentermine beta blockers and cialis dose valium viagra 3 phentermine 37.5 diet pills 5 sildenafil viagra overnight generic viagra buy viagra online web meds viagra party drug online pharmacy with phentermine phentermine cheap script uk viagra supplier cardizem cd aciphex actos phentermine imitrex phentermine pill achat valium valium for colonoscopy compare levitra viagra cialis u 15640 cialis phentermine usa grapefruit and cialis order valium on line ambien xanax viagra aids male fertility viagra generico barato panic disorder after phentermine phentermine discussion forums purchase viagra on line take viagra who woman cheapest phentermine no presc phentermine and heart valium on line with prescription real phentermine diet pills viagra c-ring benefits of valium mixing valium with xanax discover viagra buy phentermine fedex no prescription tramadol free overnight shipping phentermine overnight delivery pharmacy online viagra overseas chep valium erections using cialis viagra best price sildenafil to buy valium cheapest generic substitute viagra when does viagra patent expire presidents in viagra commercial viagra for women cuba gooding jr cialis spoof cialis alchohol phentermine but no prescription viagra and generic drug tramadol online om cheap cialis pillstore ambien brazil miss viagra phone order ambien oklahoma phentermine sale 30mg cheap phentermine 3 cialis generic viagra mexico phentermine brand name viagra by mail viagra drug info cheap drug prescription prilosec tramadol zyrtec buy cost low viagra viagra mc mimo na jem mp3 generic valium and alert vet valium compare lunesta with ambien cr phentermine free doctor consultation no prescription 4 blue 30mg phentermine buying cheap discount sale viagra viagra priapism viagra c o d phentermine buy on-line online pharmacy phentermine free consultation cialis and suboxone trial generic viagra cheapest brand cialis ultram ultracet tramadol little helper valium 2nd day fedex phentermine phentermine online prescriptions brand generic online viagra depression phentermine cheap phentermine without prescription phentermine cheapest fioricet carisoprodol hydrocodone tramadol phentermine consultation free what nascar driver has viagra viagra soft tab 12.5 ambien cr band mitra viagra falls crushing tramadol for quick release viagra flowlan phentermine no rx overnight cheap career in pharmacy tramadol manufactures of viagra cialis levitra online contact forum buy cheap phentermine cialis discussion group phentermine without doctors script needed mixing vicodin viagra dosage for tramadol er viagra cocaine died ambien blood problems cialis comparison diflucan viagra buy medication phentermine detection drug in phentermine screen urine doesnt viagra work discount pill viagra viagra generic viagra from canada uprima viagra cialis can you take viagra with lexapro tramadol hydrochloride acetaminophen cheap price on phentermine phentermine no prescription phentramine valium point acupuncture phentermine 37 5mg online california pharmacy phentermine online diet pill tramadol without perscription cialis sale viagra for heart attack appetite suppressants and phentermine cialis cialis generic viagra generic medication cialis cheap phentermine net phentermine quick site order tramadol online express delivery cialis viagra comparisons life cialis phone free ambien online order generic ambien ambien and muscle pain diet free phentermine pill shipping generic fror ambien compare cialis viagra levitra free trial cialis drug approved buy phentermine on line doctors prescribing phentermine online cheaper viagra levitra cialis order viagra online a href tramadol drug medication phentermine with online docter consultation phentermine gained weight back herbal phentermine ingredient view more info generic viagra review vardenafil vs viagra phentermine overnight fedex no prescription 37.5 cialis qu es cheap phentermine cod pharmacy online perscription drug stores ultram tramadol online rx phentermine phentermine mastercard accepted phentermine price comparisons manufacturer of viagra tramadol hcl chemical supplier white soluble generic online pharmacy viagra risks of taking ambien and alcohol buy deal deal price viagra 180 tramadol cod valium for sale cheap valium fast buy cialis soft tabs viagra best used buy ambien buy cheap ambien online viagra triangle chicago adipex side effects phentermine hydrochloride adipex online sales phentermine order viagra prescription online adipex meridia phentermine prescription viagra get a free viagra pen drug interaction sibutramine and phentermine tramadol ultram 300ct phentermine mg index viagra portland oregon vancouver washington cheap cialis generic tramadol ultram ultram ambien and xanax together purchase tramadol with online prescription online pharmecies that sell phentermine funny picture viagra valium percoset drug generic generic viagra ambien 3 14 2007 tramadol online img available cheap cod phentermine viagra cialis heart problems cheap valium online phentermine irvington 85746 keyword phentermine online order shop baikalguide site ebaycouk kamagra viagra sildenafil ambien insert information sj lvmord tramadol the city that viagra built brand drug generic name viagra description of tramadol hcl-acetaminophen par ambien and celexa hydrocodone tramadol pain purchase viagra buy phentermine w out a prescription keyword valium buying online 150 generic cialis softtabs describe ambien cialis sublingual advantage with viagra overnight shipping ambien consultation is zora ambien ambien and expire online weight loss clinic phentermine viagra online order guide tramadol tenuate buy siesta ambien online phentermine on line pharmacy you tramdol tramadol 180 pills weightloss and phentermine compare fastin phentermine adipex phentermine and heart valve problems tramadol lethal od ambien alcohol effects thai valium viagra headaches ball forging bed buy cialis monster drinks and cialis genic viagra does public aid pay for viagra phentermine warnings ambien sleeping pills side effects cheap phentermine cheap phentermine online here phentermine buying valium united states pharmacy no prescription cod phentermine phentermine pharmacy discount phentermine tramadol is prescribed for aciphex aciphex phentermine discount pharmacy ambien zolpidem show available update lawsuit on viagra 2007 buy viagra in new zealand no rx valium cialis and levitra viagra medications internet ambien laws information on abuse of valium canada generic viagra keywords viagra mp3 liability prescription drug vioxx viagra viagra cheap online phentermine diet pills cod 30 generic cialis softtabs buy cheap phentermine onli ne ambien 7day free trial phentermine 2037.5 valium toxic dose 37.5mg phentermine no perscription tramadol seizure price of viagra compared to cialis 1cialis comparison levitra viagra order phentermine online cheap canada no prescription viagra which is best viagra livetra cialis cheap 30mg phentermine without prescription zoloft and viagra buy online viagra where valium at american pharmacy valium us brand name online does herbal phentermine work viagara and cialis cialis liver problems phentermine no scripts getting a valium enema investment returns for viagra tramadol hcl 200mg 6 free viagra cialis addiction buy online phentermine xenical ambien on line consulatation overnight cialis tadalafil php cheapest online tramadol buy in uk valium buy viagra online 35008 buy side effects of ambien sun sensitivity zolpidem vs ambien phentermine without dr ssri and phentermine drugs you shouldn't take with viagra buy phentermine no prescription required viagra makes you last longer cheap phentermine no prescription photos of viagra effect cialis and viagra together phentermine cod next day delivery what brand phentermine is the best tadalafil vs generic viagra phentermine onlien viagra cialis phentermine soma picture of phentermine capsule phentermine online overnight cardizem cd actos phentermine norvasc phentermine serotonin buying tramadol with paypal generic cialis uk online pharmacy pill price viagra viagra drug store best buys viagra drink affect side valium generic review viagra mg phentermine without prescription viagra cod phentermine delivered cod no prescription get viagra dont visit a doctor viagra for paxil side effects cialis und viagra forum cialis sex tramadol best buy 120 tramadol and free shipping ambien and manufacturer cialis viagra joint corporate renewal orn viagra phentermine xenical diet pill buying cialis generic mt viagra side effects dangers online ambien prescription ambien works tramadol maximum dosage cialis tablet which is better meridia or phentermine ambien interaction average price of phentermine florida online phentermine resident sold tucson cialis viagra from uk buy phentermine 37.5 tennessee overnight ship viagra selges phentermine no shipping to kentucky valium type drugs taking phentermine and chantrex together least expensive phentermine online name brand viagra viagra stafford po box viagra comics phentermine is it safe to intra nasal viagra cialis genuinerx net viagra viagra viagra online valium prescriptions cialis viagra propecia levitra erectile dysfunction flonase nasonex aldara tramadol ambien solubility am buy looking overseas phentermine tramadol online cod phentermine $99 no script celexa phentermine online pills huge discounts insta phentermine valium for cats cialis side affect phentermine erection libido cardizem cd phentermine actos phentermine imitrex mixing cocaine and viagra addiction plan self tramadol treatment cialis viagra combination viagra free sites find search pages generic viagra 24 hours delivery viagra cialis generic can woman take viagra viagra phone prescription tramadol experience discount online phentermine without doctor ambien sleep walk drive sex viagra casino poker blackjack tip to purchase phentermine online cheap retin tramadol generic cialis pills best price viagra buy oonline eon labs phentermine without a script tramadol wikipedia the free encyclopedia viagra penis pump next day shipping phentermine water phentermine slow release tramadol loratadine ambien buy phentermine or adipex discount phentermine discount phentermine phentermine viagra uden recept buy phentermine online no prescription required side effects viagra tramadol line canada viagra cialis on line purchase valium quickly buy xanax valium ambien zolpidem what drug category is ambien cr pill purchase online offers diet phentermine phentermine blue no prescription needed check phentermine and wellbutrin order tramadol order lipitor doctor specialist phentermine with out a prescription cheap 30mg yellow phentermines no membership 1cialis levitra viagra vs vs cialis texas auto insurance order phentermine without calling doctor cirrhosis frequency viagra overseas mail order valium is viagra effective for hypertension bush buy porn viagra buy phentermine levitra cialis pills discussion tramadol s tramadol and phlebitis viagra dizziness phentermine aciphex aciphex phentermine actos risperdal phentermine on line consultation cialis causes high blood pressure viagra party brans of phentermine ambien correct dosage valium lorazepam 37.5mg cause hair loss phentermine will pakistan generic ambien canada buy viagra online viagra vs phentermine diet pill overview 2005 ambien mt november tbcgi phentermine phentremine viagra invention valium and wellbutrin phentermine photo pill cialis drug description tadalafil healthscout valium dosage amount ambien cr coupons online pharmacy for ambien effects of lexapro and phentermine ambien overnight prescription online pharmacy pill viagra zoloft phentermine adipex viagra tramadol withot prescriptions picture of generic phentermine no prescription cheap tramadol overnight fedex ambien prescription buying prescription phentermine ambien cr no prescription cr natural viagra vitamin world weight loss forums phentermine pcp specialist forced ejaculation male viagra buy cheap online phentermine cialis tadalafil american express phentermine ups shipping acyclovir famvir tramadol clarinex ambien questions cheap tramadol free shipping cheapest phentermine 30 mg colorado phentermine real valium cheapest place to buy viagra online nrop iop forum phentermine tadalafil cialis vs viagra buy diet phentermine pill site free trail viagra ambien sirius commercial is there any legitimate viagra detox diet buy tramadol ambien 5mg price valium phentermine no prescription fed-ex day viagra cialis levitra dose comparison phentermine suspended phentermine 37 5mg shipped to kentucky addictive phentermine ambien sleepsex viagra taken ranitidine phentermine overnight to california tramadol airmail buy cialis softtabs referers top viagra phentermine 37.5 overnight phentramine hoodia cheapest viagra tramadol hydrocodone addiction viagra free sites computer find online valium effective pain relief medical uses of a valium splitting cialis generic lunesta myonlinemedsbiz propecia viagra viagra chat physican's desk reference phentermine what does phentermine look like can ambien cause a stroke lowest phentermine 37 5 prices viagra t shirt 1buy generic cialis tramadol and gallbladder ambien hep c cheapest get phentermine combining orlistat and phentermine drug tramadol ultram cialis price uk viagra discount sale buy cialis tadalafil at horizon drugs effexor and tramadol contradictions order phentermine at rassellueban org guaranteed overnight phentermine online pharmacy viagra cialis levitra manufactures addicted ambien cialis soft tab description phen phen phentermine budget rx phentermine viagra cortisone cream and valium together phentermine and leg cramps viagra cialis levitra href page 60 10mg ambien overnight celexa and valium action ambien class lawsuit phentermine side effects menstruation phentermine online cheap money order can ambien cause priapism over night phentermine enhancing the viagra review cheap discount viagra viagra out of control price on phentermine cialis cost low tramadol apap tb can women take men's viagra adipex cheap phentermine lowest price adipex viagra new zealand free sample florida phentermine online viagra and zyban canada generic cialis buy ambien cr no rx buy phentermine 37 5mg cialis and adverse effects tramadol and flushed feeling oral phentermine hydrochloride buy card debit online phentermine comparison viagra levitra cialis valium injectable addictive drugstore ambien cheap overnight phentermine phentermine and soma online pharmacy geberic viagra 50mg n phentermine best online pharmacy add buy comment line phentermine combined phentermine sibutramine 1cheapest cialis viagra for geritol song ambien baikalguide buy keyword phentermine interaction tramadol hcl-acetaminophen par weight viagra rx phentermine or meridia viagra shorts best buy tramadol cheap phentermine without a presription pfizer viagra and its cautions tramadol dog pain search results generic online viagra tramadol ultracet online accept paypal phentermine and meridia gambling tramadol phentermine carisoprodol casino valium alcohol one glass wine phentermine alternatives us licensed pharmacies tramadol ultram opiate drug testing no perscrirtion diet pills phentermine buy phentermine online overnight shipping cheap phentermine hci buy tramadol without prescription viagra can cause reduced eye pressure phentermine information mexican name disebsin college pharmacy pre tramadol buy phentermine now carisoprodol phenthermine yellow buy xanax valium online discount viagra offers is ambien safe cheap online prescription phentermine viagra lanuage cheap phentermine saturday delivery ups chep tramadol and codeine allergy list generic brands of valium where is phentermine pump up the valium lyrics cold water pill extraction tramadol phentermine us pharm no rx needed pcp consult specialist letter template cialis drug levitra viagra hsn tramadol phentermine before and after hydrochloride phentermine viagra cialis and levitra viagra for men phentermine adipex no rx buy valium in tijuana coupons for viagra viagra invented by mistake phentermine no doctor prescription buy cheap phentermine mg tabs viagra extasy tables pills david crespi ambien defense cheap drug viagra viagra online href foro forum ambien sleep medication cymbalta phentermine what is better levitra viagra cialis valium healthy alternative generic viagra from india pages tramadol bill me later buy viagra in reliable online drugstore is viagra safe for women buy phentermine online no perscription low price ambien viagra opinions tramadol halflife online fastin pharmacy phentermine valium cost adhd diet phentermine pill phentermine blue white 30mg phentermine 30 mg online consult fedex overnight delivery phentermine viagra in a can tramadol 50 mg 400 viagra drug information viagra ultracet online description chemistry ingredients tramadol phentermine and mexico penrex as viagra substitute generic cialis pills email phentermine on line w o prescription cialis levitra strong strong viagra ambien shipped cod prescription phentermine 37.5 viagra alternative new drugs effects hcl side tramadol tramadol 100mg us legal purchase valium never mix viagra ambien cr 12.5 mg cialis softtabs phentermine 6 pm order cialis and levitra compare which is better viagra levitra cialis viagra and heart disease buy tramadol online cod buy ultram buy phentermine a159 cialis symptoms buying phentermine without perscription celexa phentermine gt cod phentermine detailed phentermine facts adipex and tramadol no prescription needed fast overnight phentermine does cialis delay ejaculation cod pay tramadol ambien and dxm what does viagra do for you lose weight pill diet phentermine cialis adderall online valium sales patrick kennedy ambien ambien effects long term 120 cheap pharmacy tramadol valium paid for by check generic cialis experiences cheap phentermine online free prescription low cost authentic viagra find cheapest tramadol ambien phentermine next day no prescription fedex xanax valium side effects of snorting viagra legally purchase viagra phentermine no prescripti phentermine obesity phenermine dish network phentermine viagra phentermine usa pharmacy fda cialis pill splitting tramadol wellbutrin retin-a cheap ultram ambien 10 phentermine phentermine successful stories online viagra cialis levitra compare cheap online pharmacy tramadol manufacturers of phentermine phentermine package insert improved effect of viagra amaryl phentermine nasonex altace 1 cialis tadalafil cialis with viagra mental problems caused by ambien mix cocaine and viagra valium prescriptions online agcode buy tramadol tramadol buy on line what colors are valiums in man uk viagra cheapest cialis onlinecom buy phentermine without prior prescription valium gentic valium street names consultation online pharmacy phentermine inhailing tramadol cialis ads cod no online prescription tramadol online prescription viagra phentermine meridia adipex cheap 37 5 phentermine forex trading tramadol phentermine overnight without a prescription tramadol cod 120 apos sildenafil citrate viagra generic cheap online pharmacy and phentermine overnight no prescription needed true phentermine phentermine cod delivery cialis flomax and ambien thread free online samples fo cialis candian meds viagra ambien klonpin interaction non phentermine prescription viagra pharmaceutical company making tramadol ambien lexapro phentermine foods valium wisdom tooth phentermine customs peyronie's cialis 1 50mg tramadol tramadol withdrwal symptoms generic viagra us licensed online pharmacy generic valium identification tramadol 50mg picture generic ambien when nexium phentermine pravachol viagra patent litigation phentermine and gastrointestinal disturbances doctor online order viagra visit best search web site 13 phentermine ambien used for chronic pain management interaction tramadol warfarin good screw with viagra href cialis information for viagra prescription drug ambien free sample phentermine cheap no rx career in pharmacy phentermine diet pill ambien dosage 40mg generic viagra versus cialis pills online valium without a prescription no doctor consultation phentermine cheap generic cialis tadalafil viagra anxiety can't order phentermine anymore cialis multiple erection percription free phentermine where to order cialis in mexico ambien cr online pharmacy phentermine 37.5 $93 zenegra cheapest viagra substitute sildenafil deal discount viagra cialis compare levitra performance viagra viagra information adipex phentermine weight loss buy phentermine online ambien on airline flights heart problems related phentermine phentermine generic 90 pills overnight ebay viagra spiro c no rx valium or diazapam valtrex nasonex tramadol sinnequan vs ambien valium addiction and withdrawal cialis compare levitra viagra canadian pharmacies for phentermine can you take phentermine with klonopin ambien electronics free cialis free levitra free viagra viagra do don'ts generic brands viagra online phentermine 37.5mg x 90 tabs buy phentermine no perception by cialis march posted viagra etc 5 cialis generic viagra online prescription renova tramadol zithromax cialis versus regalis buy phentermine overnight saturday delivery valium mg best online pharmacy buy viagra online off pharmacy prices ambien cr and achohol ambien danger ambien danger giant viagra pill viagra protocol actos foradil phentermine actos pharmacy nassau viagra purchase on line medical report about viagra viagra expiration dates phentermine drug buyers forum pfizer viagra uk my ebay bidding buy tramadol discount herbal herbal viagra viagra viagra tramadol valium together real substitute viagra info on tramadol 37.5 phentermine no prescription viagra free sites results high blood pressure and tramadol ambien sleep after surgery ambien 25 mg cheap viagra canada 900 mg phentermine overdose face tingling after using viagra produts generex viagra buy overnight valium actos phentermine pravachol cheap phentermine with free shipping catalog foam memory tramadol tramadol prescription online fedex delivery phentermine phentermine drug interaction description of viagra meridia or phentermine generic viagra drugstore india cheap refill on phentermine 30mg phentermine online medical phentermine no prescribtion weight loss tips with phentermine tramadol for dog pain written prescription for viagra tramadol facts tablet valium information about cialis and livetra difference between valium and clonazepam buy cialis pills generic buy phentermine cheap on-line physician tramadol good for depression phentermine chemical enhancement cheap tramadol 300ct 50mg no prescripion 40mg dose of cialis viagra cialis store cialis medication online vicodin and valium back muscle spasm ambien hypertension special offer buy viagra online viagra substitutes phentermine online 37.5 discount purchase viagra uk cialis comparison levitra viagra tramadol hypothroidism meltabs generic viagra free trial viagra levetra viagra marketing tools buy tramadol online cod ultram adipex adipex phentermine adipex cheap pharmaceutical viagra cialis by fedex k-9 tramadol hcl cause rebound weight gain phentermine valium versed pharmacology buy phentermine 37 5 mg viagra tramadol phentermine email advertise message 0px site cialis ambien early labor facts about ambien cr mix with ambien viagra seller cialis v s viagra phentermine carisoprodol phenthermine yellow ambien and vicodin combination tramadol hcl and dog 2cialis compare levitra ambien ativan drug interactions cheap cialis tadalafil cheap drug retin tramadol viagra buy valium us pharmacy hrt phentermine cialis cialis genuinerx net viagra viagra viagra 24 hours delivery suggested dose in cialis viagra pfitzer phentermine w online consultation advertisement for viagra phentermine with hoodia viagra uk online viagra patent last better cialis levitra viagra which discount meridia phentermine buy viagra online pharmacy false positive drug tests ambien medical dictionary valium buying viagra online in australia phentermine 30mg blue without prescription hydrocodone 10 650 phentermine diet effects phentermine pill side pravachol phentermine pet pharmacy viagra patent expiration date infromation about tramadol cialis what is it used for phentermine 15mg overnight