<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Moves On Rails: Category Rails</title>
    <link>http://www.movesonrails.com/articles/category/rails</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>New ways to look at software</description>
    <item>
      <title>Rails log analyzer</title>
      <description>&lt;p&gt;You've probably all been there: your application is running slow, but why? What views or actions are clogging up the mongrels? Or are the mongrels just waiting for the database?&lt;/p&gt;

&lt;p&gt;Rails log analyzer is a simple but very powerful command-line analysis tool to quickly determine what is taking time, on all kinds of different levels. At the moment it can tell you the following statistics:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Top 10 most requested actions&lt;/li&gt;
&lt;li&gt;Top 10 actions by time - cumulative&lt;/li&gt;
&lt;li&gt;Top 10 actions by time - per request mean&lt;/li&gt;
&lt;li&gt;Top 10 worst DB offenders - cumulative time&lt;/li&gt;
&lt;li&gt;Top 10 worst DB offenders - mean time&lt;/li&gt;
&lt;li&gt;Mongrel process blockers (&gt; 1.0 seconds) - frequency&lt;/li&gt;
&lt;li&gt;Requests graph - requests per hour&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For an example run, or the analyzer take a look at the github.
&lt;a href="http://github.com/wvanbergen/rails-log-analyzer/"&gt;http://github.com/wvanbergen/rails-log-analyzer/&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Thu, 14 Aug 2008 22:58:00 +0200</pubDate>
      <guid isPermaLink="false">urn:uuid:af66f557-bf78-4b31-b5aa-60618aaf455e</guid>
      <author>bart.tenbrinke@movesonrails.com (Bart ten Brinke)</author>
      <link>http://www.movesonrails.com/articles/2008/08/14/rails-log-analyzer</link>
      <category>Rails</category>
      <category>Ruby</category>
      <category>log</category>
      <category>analyzer</category>
      <category>command</category>
      <category>line</category>
    </item>
    <item>
      <title>Background processing with WorkerQueue</title>
      <description>&lt;p&gt;Yes, I know there are a lot of background runners available for rails (I tried most of them), and they all seemed to have their downsides:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;BackgroundRB -&gt; Major memory leaks when performing large tasks and bloaty.&lt;/li&gt;
&lt;li&gt;Spawn -&gt; I really do not want to fork on every request. I use merb for that.&lt;/li&gt;
&lt;li&gt;Starling -&gt; Memcache and only does sequential processing.&lt;/li&gt;
&lt;li&gt;ActiveMessaging -&gt; Round hole Square peg.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Also non of these can handle big file uploads nicely and reliable.
That is when I decided to create my own: WorkerQueue.&lt;/p&gt;

&lt;p&gt;Main features:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Simple&lt;/li&gt;
&lt;li&gt;Fast&lt;/li&gt;
&lt;li&gt;Works via a rake task and prefers cron&lt;/li&gt;
&lt;li&gt;Can handle large amounts of data&lt;/li&gt;
&lt;li&gt;Sequential and Parallel execution on demand&lt;/li&gt;
&lt;li&gt;Simple error reporting&lt;/li&gt;
&lt;li&gt;Offload tasks to other or multiple machines&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can clone a copy here:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  git clone git://github.com/barttenbrinke/worker_queue.git vendor/plugins/worker_queue
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Or visit &lt;a href="http://github.com/barttenbrinke/worker_queue/tree/master/README"&gt;github&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;UPDATE:
WorkerQueue 1.0 Stable is now available on Github.&lt;/p&gt;</description>
      <pubDate>Wed, 13 Aug 2008 21:08:00 +0200</pubDate>
      <guid isPermaLink="false">urn:uuid:7a88acf9-b4fa-45a2-9c8a-959bb6153ca5</guid>
      <author>bart.tenbrinke@movesonrails.com (Bart ten Brinke)</author>
      <link>http://www.movesonrails.com/articles/2008/08/13/background-processing-with-workerqueue</link>
      <category>Rails</category>
      <category>background</category>
      <category>process</category>
      <category>worker</category>
      <category>queue</category>
    </item>
    <item>
      <title>Nested include has major memory leak (Rails 2.0.1).</title>
      <description>&lt;p&gt;As our mongrels were using up quite a lot of memory, so I tried to figure out what was causing this.&lt;/p&gt;

&lt;p&gt;When running the app locally I found out that one certain page caused the mongrel to grow from 60 to 190 megabytes. A whopping 130 megabytes!&lt;/p&gt;

&lt;p&gt;After commenting out some of the code, I realized that a single line was causing all of the memory usage &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;contracts = Contract.find( :all, 
  :conditions =&amp;gt; ['contracts.employee_id IN (?) ', employees ],
  :include =&amp;gt; [:expertise_profile =&amp;gt; :qualifications ] )
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Ouch! The nested include of rails somehow leaks a large amount of memory.
The fix was a piece of cake.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;contracts = Contract.find( :all, 
  :conditions =&amp;gt; ['contracts.employee_id IN (?) ', employees ],
  :include =&amp;gt; :expertise_profile )
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now my mongrel stays at 60 megabytes. I don't know if this issue persists in the new 2.1 Rails, but I'll check that soon!&lt;/p&gt;</description>
      <pubDate>Wed, 02 Jul 2008 15:59:00 +0200</pubDate>
      <guid isPermaLink="false">urn:uuid:1a3ee134-137c-49b9-9d0d-9d868a301f41</guid>
      <author>bart.tenbrinke@movesonrails.com (Bart ten Brinke)</author>
      <link>http://www.movesonrails.com/articles/2008/07/02/nested-include-has-major-memory-leak-rails-2-0-1</link>
      <category>Rails</category>
      <category>find</category>
      <category>nested</category>
      <category>include</category>
      <category>memory</category>
      <category>rails</category>
    </item>
    <item>
      <title>Campfire Notifier for cruisecontrol.rb</title>
      <description>&lt;p&gt;We added a campfire notifier to our build of cruisecontrol. Click on the link to download the builder plugin. It uses tinder as an API.&lt;/p&gt;

&lt;p&gt;&lt;center&gt;&lt;a href="http://www.movesonrails.com/files/campfire_notifier.zip"&gt;&lt;img src="http://www.movesonrails.com/files/bear_force.png" style="border:1px solid #ddd;"/&gt;&lt;/a&gt;&lt;/center&gt;&lt;/p&gt;</description>
      <pubDate>Thu, 17 Apr 2008 13:37:00 +0200</pubDate>
      <guid isPermaLink="false">urn:uuid:f82cc823-d89e-4d35-a09f-503334ceab3e</guid>
      <author>andre.foeken@movesonrails.com (Andre Foeken)</author>
      <link>http://www.movesonrails.com/articles/2008/04/17/campfire-notifier-for-cruisecontrol-rb</link>
      <category>Rails</category>
    </item>
    <item>
      <title>Optimizing math</title>
      <description>&lt;p&gt;As you might have guessed from Bart's previous article we've been looking at ways to speed up our Rails app. We've been profiling and query optimizing but at some point we reached a dead end.&lt;/p&gt;

&lt;p&gt;Our app needs to calculate a lot of distances between geo locations. Until now we've been happy using a home-grown Ruby method to calculate these distances but our profiling showed that it was (as one may suspect) horribly slow.&lt;/p&gt;

&lt;p&gt;We now have several options:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;We could try to built a faster Ruby method (but that would be hard since it's pure math and not really a lot can be done here)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We could use the database (mysql in our case) to calculate our distances (A lot more db connections in our case, since we need distances between lots of points. Not the standard stuff that gems like acts_as_mappable can handle)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use RubyInline to create a faster C based method&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We decided to look at RubyInline. A gem that enabled C code to be used right inside a Ruby script. We rewrote the method in C. A simple benchmark proved that our inline C method was 2.3 times faster!&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;pre&gt;
require 'inline'
inline do |builder|
    builder.include '&amp;lt;math.h&amp;gt;'
    builder.c "double calc_distance_between(...) { ... }"
end
&lt;/pre&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Although this result is very good, it does complicate your app and makes it less readable. These inline methods have to be used with care. But in our simple (and very localized) case we decided to keep the C method in favor of the pure Ruby call.&lt;/p&gt;</description>
      <pubDate>Thu, 10 Apr 2008 22:43:00 +0200</pubDate>
      <guid isPermaLink="false">urn:uuid:341a43a2-ff84-429a-b541-ca10ccb44f5d</guid>
      <author>andre.foeken@movesonrails.com (Andre Foeken)</author>
      <link>http://www.movesonrails.com/articles/2008/04/10/optimizing-math</link>
      <category>Rails</category>
      <category>Ruby</category>
      <category>rubyinline</category>
      <category>C</category>
      <category>math</category>
      <category>profile</category>
      <category>speed</category>
      <category>distance</category>
    </item>
    <item>
      <title>Optimizing the queries of your rails app</title>
      <description>&lt;p&gt;When you are developing your application, you should allways look for the following line in your development console.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Processing EmployeesController#index[GET]
Employee Load (0.055003) 
SELECT * FROM `people` WHERE `people`.`type` = 'Employee'

 select_type | key_len | type | Extra       |
---------------------------------------------  =&amp;gt;
 SIMPLE      |         | ALL  | Using where |

| id | possible_keys | rows | table  | ref | key
--------------------------------------------------
| 1  |               | 6965 | people |     |
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The type ALL means that you are preforming a full table scan in a query. This is usually not a problem when you are in development mode, but what is you have millions of people in your database?&lt;/p&gt;

&lt;p&gt;Usually it is pretty straight forward to find out where you were calling this from, as you will probably remember what the request was you did. If you are having a hard time, install the query_trace plugin. This gives the following result:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;vendor/plugins/query_analyzer/lib/query_analyzer.rb:38:in `select'
app/controllers/employees_controller.rb:71:in `find'
app/controllers/employees_controller.rb:71:in `index'
vendor/plugins/browser-prof/lib/browser-prof.rb:32:in `process'
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Looking at line 71 of the employees controller is a good idea here as you might be doing something stupid. As line 71 just reads: @employees = Employee.find(:all)) we have to turn to your database.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;mysql -u root --database myapp_development

mysql&amp;gt; EXPLAIN SELECT * FROM `people` WHERE `people`.`type` = 'Employee';
+----+-------------+--------+------+------------------+
| id | select_type | table  | type | possible_keys    |
+----+-------------+--------+------+------------------+ =&amp;gt;
|  1 | SIMPLE      | people | ALL  |                  |
+----+-------------+--------+------+------------------+

+------+---------+------+------+-------------+
| key  | key_len | ref  | rows | Extra       |
+------+---------+------+------+-------------+
| NULL | NULL    | NULL | 6873 | Using where |
+---------+------+------+------+-------------+
1 row in set (0.00 sec)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;As you can see we are not hitting any indexes. Lets try adding an index.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;mysql&amp;gt; create index people_type_test on people (type);
Query OK, 6715 rows affected (1.38 sec)
Records: 6715  Duplicates: 0  Warnings: 0
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now we run the explain again:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;mysql&amp;gt; EXPLAIN SELECT * FROM `people` WHERE `people`.`type` = 'Employee' ;
+----+-------------+--------+------+------------------+
| id | select_type | table  | type | possible_keys    |
+----+-------------+--------+------+------------------+ =&amp;gt;
|  1 | SIMPLE      | people |range | people_type_test |
+----+-------------+--------+------+------------------+

+------------------+---------+-------+------+-------------+
| key              | key_len | ref   | rows | Extra       |
+------------------+---------+-------+------+-------------+
| people_type_test | 768     | const | 2496 | Using where |
+------------------+---------+-------+------+-------------+
1 row in set (0.00 sec)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Thats more like it, now we need to add this to our app trough a migration.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;class CreatePeopleIndices &amp;lt; ActiveRecord::Migration
  def self.up
    add_index :people, :type
  end

  def self.down
    remove_index :people, :type    
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;After a db:migrate and a restart of the server, we now see the following in the development console:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Employee Load (0.027666)
SELECT * FROM `people` WHERE `people`.`type` = 'Employee'
Analyzing Employee Load

 select_type | key_len | type | Extra       |
---------------------------------------------  =&amp;gt;
 SIMPLE      | 768     | ref  | Using where |

| id | possible_keys        | rows | table  | ref   | key
----------------------------------------------------------------------
| 1  | index_people_on_type | 2496 | people | const | people_type_test
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Success! Also note that the load on the database has been cut in half.&lt;/p&gt;</description>
      <pubDate>Wed, 09 Apr 2008 21:47:00 +0200</pubDate>
      <guid isPermaLink="false">urn:uuid:a4f47013-7652-428a-819b-32ba4474e97f</guid>
      <author>bart.tenbrinke@movesonrails.com (Bart ten Brinke)</author>
      <link>http://www.movesonrails.com/articles/2008/04/09/optimizing-the-queries-of-your-rails-app</link>
      <category>Rails</category>
      <category>indexes</category>
      <category>database</category>
      <category>mysql</category>
      <category>slow</category>
      <category>performance</category>
    </item>
    <item>
      <title>Gettextgenerators update</title>
      <description>&lt;p&gt;Gettext generators for rails 2.0 is out. It was available from the trunk for a long time, but now it was actually tagged. Note that it should work with the latest Gettext (1.90), but I have not yet tested this myself.&lt;/p&gt;</description>
      <pubDate>Mon, 31 Mar 2008 20:29:00 +0200</pubDate>
      <guid isPermaLink="false">urn:uuid:f81afda8-255a-4bb9-bd5a-c8e341dd7d21</guid>
      <author>bart.tenbrinke@movesonrails.com (Bart ten Brinke)</author>
      <link>http://www.movesonrails.com/articles/2008/03/31/gettextgenerators-update</link>
      <category>Rails</category>
    </item>
    <item>
      <title>attr_accessor_with_default</title>
      <description>&lt;p&gt;What a marvelous feature, but be wary! It can cause some unexpected behavior if you don't know what you are doing.&lt;/p&gt;

&lt;p&gt;This morning we found a rather suspicious bug that lead to unexpected things. Here is an example:&lt;/p&gt;

&lt;blockquote&gt;
    &lt;p&gt;&lt;code&gt;
    class Person ; attr_accessor_with_default :things, {} ; end&lt;br/&gt;
    john = Person.new&lt;br/&gt;
    john.things[:table] = true&lt;br/&gt;
    ...&lt;br/&gt;
    jim = Person.new&lt;br/&gt;
    jim.things =&gt; {:table =&gt; true} # huh??&lt;br/&gt;
    &lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;As it would seem attr_accessor_with_default has some problems with collections. Since we are sharing the instance over the entire class. Peter Williams noted this problem several month ago in his &lt;a href="http://pezra.barelyenough.org/blog/2007/09/things-to-be-suspicious-of-attr_accessor_with_default-with-a-collection/"&gt;article&lt;/a&gt; (which we didn't read until it was too late), however the solution he provided still left us with some very undesireable behaviour.&lt;/p&gt;

&lt;blockquote&gt;
    &lt;p&gt;&lt;code&gt;
    class Person ; attr_accessor_with_default :things, {{}} ; end # note the extra brackets!&lt;br/&gt;
    &lt;br/&gt;&lt;br/&gt;
    john = Person.new&lt;br/&gt;
    john.things[:table] = true&lt;br/&gt;
    &lt;br/&gt;
    ...&lt;br/&gt;
    &lt;br/&gt;
    jim = Person.new&lt;br/&gt;
    jim.things =&gt; {} # okay!&lt;br/&gt;
    john.things =&gt; {} # uhm... not okay!
    &lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The variable would only &lt;em&gt;stick&lt;/em&gt; if we actually assigned it.&lt;/p&gt;

&lt;blockquote&gt;
    &lt;p&gt;&lt;code&gt;
    john.things = {:table =&gt; true}&lt;br/&gt;
    john.things =&gt; {:table =&gt; true} # yay!
    &lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But doing this every time is not only a pain but also introduces &lt;strong&gt;very&lt;/strong&gt; hard to debug errors, since the assignment does not fail...it just doesn't work!&lt;/p&gt;

&lt;p&gt;We solved it by going old-school. Back to the normal accessor for collections.&lt;/p&gt;

&lt;blockquote&gt;
    &lt;p&gt;&lt;code&gt;
    class Person &lt;br/&gt;
       attr_accessor :things&lt;br/&gt;
     &lt;br/&gt;
       &amp;nbsp;def initialize attributes=nil&lt;br/&gt;
       &amp;nbsp;&amp;nbsp;super&lt;br/&gt;
       &amp;nbsp;&amp;nbsp;self.things = {}&lt;br/&gt;
       &amp;nbsp;end&lt;br/&gt;
    &lt;br/&gt;
    end
    &lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now the code works as expected and we can use all operators (like &gt;&gt;, []) from the get go.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt; It seems this had no effect on ActiveRecord objects that were created using finders so here is the fix for any those:&lt;/p&gt;

&lt;blockquote&gt;
    &lt;p&gt;&lt;code&gt;
    class Person &amp;lt; ActiveRecord::Base&lt;br/&gt;
       attr_accessor :things&lt;br/&gt;
     &lt;br/&gt;
       &amp;nbsp;def after_initialize&lt;br/&gt;
       &amp;nbsp;&amp;nbsp;self.things = {}&lt;br/&gt;
       &amp;nbsp;end&lt;br/&gt;
    &lt;br/&gt;
    end
    &lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;</description>
      <pubDate>Wed, 05 Mar 2008 09:37:00 +0100</pubDate>
      <guid isPermaLink="false">urn:uuid:830e2280-fc19-42e0-a443-5cd1b6eb4377</guid>
      <author>andre.foeken@movesonrails.com (Andre Foeken)</author>
      <link>http://www.movesonrails.com/articles/2008/03/05/attr_accessor_with_default</link>
      <category>Rails</category>
      <category>Ruby</category>
      <category>attr_accessor_with_default</category>
      <category>collection</category>
      <category>weird</category>
    </item>
    <item>
      <title>Javascript testing problems</title>
      <description>&lt;p&gt;A few months ago I got the assignment to set up and build javascripts-tests for the scheduling view of moves. At first I had to select a testing-framework where the test would be written in. The framework had to be able to run both unit and integrations tests. Also it would be very nice if we can run these test automatically through the command-line instead of clicking around in the browser (autotest).&lt;/p&gt;

&lt;p&gt;After reviewing some frameworks, I chose the Crosscheck framework (http://www.thefrontside.net/crosscheck). Crosscheck is a javascript-testing-framework written in java. It is crossplatform and you can control it from the command-line. It is even able to emulate the behavior of multiple popular browsers like ie6, Firefox 1.0 and Firefox 1.5. Sounds like the ultimate testing framework!&lt;/p&gt;

&lt;p&gt;So after my decision I started playing around and implementing tests. However, when the tests became more complex I ran into trouble. Some basic browser features like document.write() (ie6) and the Option object where missing. I was able to work around these problems,  but the real trouble began with the integration tests. As our application relies heavily on ajax through the prototype framework, testing this functionality is crucial. However, I was not able to do this. Performing one hack after another, I finally gave up.&lt;/p&gt;

&lt;p&gt;The crosscheck framework was clearly not mature enough to satisfy my needs. My conclusion is: Using crosscheck for unit-testing is doable, but the framework is not mature enough for the use of integration tests. So what are the problems with crosscheck? As mentioned earlier, it is written in Java, so it tries to emulate the browser behavior based on it's specifications. The advantages of this approach is that you can emulate more than one browser, the disadvantages are that the emulation is an approach, so you will never really get the real behavior of the browser.&lt;/p&gt;

&lt;p&gt;If a browser changes its implementation, the framework is always outdated. You don't get the browsers quirks, so if it your tests pass in the test framework, there is no guarantee it will work in the real-browser world. Another problem with crosscheck is that is seems to be abandoned. The last changes are from end-2007 and as far as I can see none of the reported bugs have been fixed yet. Firefox 3.x and ie7 are becoming standard, but these browsers are not available as a test-browser in crosscheck (and there are no clues they will be soon).&lt;/p&gt;

&lt;p&gt;What can we expect from the continuity of crosscheck? If you, like us, want to be able to test a long-term project, then it is important that your test-framework is long-term too. So what does my ideal javascript-test-framework look like?&lt;/p&gt;

&lt;p&gt;It should:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Run from the command line&lt;/li&gt;
&lt;li&gt;Represent the browser realistically&lt;/li&gt;
&lt;li&gt;Emulate ajax responses&lt;/li&gt;
&lt;li&gt;Mock objects&lt;/li&gt;
&lt;li&gt;Run implementation tests&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As far as I know, no such framework exists. However, in my view, it shouldn't be too hard to realize. We could embed the mozilla tree in an application. That way we always have the latest version of the mozilla engine and an exact copy of the behavior including it's quirks. Through the Mozilla API we can access the DOM and other functions. The framework should be able to easily load tests and run them (for this part it's important to take a good look at the x-unit patterns).&lt;/p&gt;

&lt;p&gt;At this moment I don't have a clue how easy it is to emulate the ajax responses through mozilla API calls. Furthermore the framework should be give a rich toolkit for testing including abilities to mock objects. You start the framework via the command-line for easy integration with test-runners like autotest. Of course this application should be released under the GPL-licence. Now we only need someone to implement this for us!&lt;/p&gt;

&lt;p&gt;Steven van der Vegt (s.vandervegt TA student.utwente.nl)&lt;/p&gt;

&lt;p&gt;Ps we are offering an internship for the development of the described plugin at Nedap healthcare. Interrested? bart.tenbrinke@movesonrails.com International students welcome!&lt;/p&gt;</description>
      <pubDate>Tue, 04 Mar 2008 17:02:00 +0100</pubDate>
      <guid isPermaLink="false">urn:uuid:d683e0b3-e11a-4c99-a754-a7cef2863ffc</guid>
      <author>Steven van der Vegt</author>
      <link>http://www.movesonrails.com/articles/2008/03/04/javascript-testing-problems</link>
      <category>Rails</category>
      <category>Ruby</category>
      <category>Rspec</category>
      <category>autotest</category>
      <category>crosscheck</category>
      <category>javascript</category>
      <category>problems</category>
    </item>
    <item>
      <title>libXML for Active Resource 2.0</title>
      <description>&lt;p&gt;I received an email from Stevie Clifton today, asking about our libXML patch for rails 2.0. As we have been running 2.0 for quite some time now, I never realised I forgot to post the new overrides.&lt;/p&gt;

&lt;p&gt;The file below goes into /config/initializers/libxml.rb&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;# This is actally a fix for activeresource as it
# will behave incorrectly when it encounters
# Complex xml files. This override fixes this,
# but it should be submitted to rails trunk.
module ActiveResource
  module Formats
    module XmlFormat
      private
      def from_xml_data(data)
          if data.is_a?(Hash) &amp;amp;&amp;amp; data.keys.size == 1
            from_xml_data(data.values.first)
          else
            data
          end
        end      
    end
  end
end

module Nedap #:nodoc:
  module Hash #:nodoc:
    module Conversions

      def self.included(klass)
        require 'xml/libxml'
        klass.extend(ClassMethods)
      end

      module ClassMethods

        # Hash from_xml mixin that uses libxml.
        # This ensures a 20x speed increase
        # Compared to libxml. Plus it is less ugly.
        def from_xml(xml) 
          result = XML::Parser.string(xml).parse 
          return { result.root.name.to_s =&amp;gt; xml_node_to_hash(result.root)} 
        end 

        def xml_node_to_hash(node) 
          # If we are at the root of the document, start the hash 
          if node.element? 
           if node.children? 
              result_hash = {} 

              node.each_child do |child| 
                result = xml_node_to_hash(child) 

              if child.name == "text"
                if !child.next? and !child.prev?
                  return result
                end
              elsif result_hash[child.name] 
                  if result_hash[child.name].is_a?(Object::Array) 
                    result_hash[child.name] &amp;lt;&amp;lt; result 
                  else 
                    result_hash[child.name] = [result_hash[child.name]] &amp;lt;&amp;lt; result 
                  end 
                else 
                  result_hash[child.name] = result 
                end              
              end 

              return result_hash 
            else 
              return nil 
           end 
           else 
            return node.content.to_s 
          end 
        end          

      end        
    end
  end
end 

Hash.send :include, Nedap::Hash::Conversions
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;There you go. You now have a blazingly fast active resource!
If you want some more bang out of your resource, add the following mixins to the initializer too:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;# Add inflate to NET class (zLib support)
module Net
  class HTTPResponse
     def inflate!
       require 'zlib'
       @body = Zlib::Inflate.inflate(@body)
     end
   end
 end

# Increase timeout and buffersize for big XML files
module Net
  class BufferedIO 
    def rbuf_fill
      timeout(3000) { 
        @rbuf &amp;lt;&amp;lt; @io.sysread(32768) 
      }
    end 
  end
end
&lt;/code&gt;&lt;/pre&gt;</description>
      <pubDate>Mon, 25 Feb 2008 09:11:00 +0100</pubDate>
      <guid isPermaLink="false">urn:uuid:f2d4e2ca-f6d1-43ef-a819-d12afcd42615</guid>
      <author>bart.tenbrinke@movesonrails.com (Bart ten Brinke)</author>
      <link>http://www.movesonrails.com/articles/2008/02/25/libxml-for-active-resource-2-0</link>
      <category>Rails</category>
      <category>Active</category>
      <category>Resource</category>
      <category>ARES</category>
      <category>2.0</category>
    </item>
  </channel>
</rss>
