The Passionate Craftsman

Ruby, PHP, MySql, Software engineering and more.

Saturday, 20 November 2010

Test unique values in Rails model with Rspec

I wanted to test 'validates_uniqueness_of' for this model:

class CourseItem < ActiveRecord::Base
validates_presence_of :course_id, :day, :url
validates_uniqueness_of :course_id, :scope => :day,
:message => "- this day has been already created."
end

I tried to create two objects with the same value and I was getting the validetion error when creating the second value, the spec was failing and I did not know you to test it. There is a custom matcher to test the uniqueness of fields and it is available with a gem developed by Bogdan Gusiev. This blog post will help you to get started: http://gusiev.com/2010/06/ultimate-rspec-matcher-to-test-validation/. That gem has other useful matchers too.

I checked that model with the following code:

Labels: , ,

Monday, 2 August 2010

Kitty - a funny gem

I found a new screencast on Rubypulse about a gem named kitty. If you install the gem, then you will have a kitty command that will print a random ASCII-art cat. For instance:


Labels: ,

Tuesday, 24 November 2009

How to install mysql gem on Mac

Download and install the x86 version of MySql, the run the following command:

sudo env ARCHFLAGS="-arch i386" gem install mysql -- \
--with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib \
--with-mysql-include=/usr/local/mysql/include

This should be enough to have the mysql gem installed

Labels: , ,