Speeding up you tests with Spork is very common when developping Rails applications. What Spork do is preloading your application in a server and copies a fork of that server whenever you run tests. It avoids reloading all the rails stack !! That is great !!! But the problem I ran into is that I …
Category Archive: metaprogramming
Jan
14
Mar
17
Rspec 2.x and Fixtures
by Hallelujah
Hello, It’s been a while when I last updated this blog. It seems that Rspec 2 can not use fixtures from Activerecord 2.3.x ! Impossible ? Not really, and thanks to ruby it was possible for me. Let’s describe the background : First of all, I had a gem built on jeweler that uses ActiveSupport::TestCase …
Nov
17
ActiveRecord like searching object in Rails form helpers
by Hallelujah
Ruby is a wonderful language. And Rails is a wonderful framework. Why ? Because of Duck typing !!! Example : You build a database application for a book store Books are classified by : Genre Author Country On a search page, you can search with a title text field, author select box, genre checkboxes. So …
Oct
20
Ruby Rails : How to bypass skip validation in Devise
by Hallelujah
Since my last post with email validations, I was looking for a solution to integrate it with devise Sadly for me, devise implements the old way of validating email with regexp : # From devise gem version 1.1.3 validates_format_of :email, :with => email_regexp, :allow_blank => true Well, as I don’t want to hack activemodel’s code, …
Aug
19
Enumerable grep method in Ruby
There is some methods that are not very known among ruby developpers. One of them is Enumerable#grep method. I would like to share one of the use case I have to face with, and how I implement grep. Purpose, I have a Hash representing a simple network I’d like to select all the people related …
Mar
11
Mysql 4.x and Rails : RELEASE SAVEPOINT issue
Today with a project using mysql 4.1.22 that I have to implement some tests, I ran this error with rails 2.3.5 and I think for 2.3.x branch. Mysql::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘RELEASE SAVEPOINT …
This post has no tag
Oct
08
gettext 2.0.4 and rails 2.3.4
Rails 2.3.4 broke gettext_activerecord 2.0.4 Well I did not test other gems of the mutoh gettext set of libraries but here is the gulty code that breaks rails. Since Activerecord::Errors changed its implementation a bit, an error like this is raised : NoMethodError: undefined method `gsub’ for #<ActiveRecord::Error:0×00000002919738> from /home/hallelujah/Jail/lib/ruby/gems/1.9.1/gems/gettext_activerecord-2.0.4/lib/gettext_activerecord/validations.rb:165:in `localize_error_message’ from /home/hallelujah/Jail/lib/ruby/gems/1.9.1/gems/gettext_activerecord-2.0.4/lib/gettext_activerecord/validations.rb:112:in `block (2 …
Sep
23
Inspectable accessors
Hey, it’s been a while I posted here. So what’s the purpose ? I commonly use script/console to debug my rails applications. Today I wanted to see the values of my custom attributes model without typing model.custom_attribute. So I took a look at ActiveRecord::Base#inspect method. and the default inspect method shows me database fields. Well, …
Jul
24
Blocks are Proc : Les procédures Proc et les blocks en ruby.
( For non-french readers : I am not giving up writing in english … Read the next post! ) Si vous venez d’un autre langage, le terme procédure (associé au terme fonction) doit vous dire quelque chose. Vaguement …. Allez quelques connaissances (méconnaissances) tirées de ma mémoire pour poser les bases. Par exemple, en PHP …

