<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Kabisa Blog &#187; Ruby</title>
	<atom:link href="http://blog.kabisa.nl/category/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.kabisa.nl</link>
	<description>The Ruby on Rails Experts</description>
	<lastBuildDate>Sun, 09 Oct 2011 07:54:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Kabisa at #arrrrcamp 2011</title>
		<link>http://blog.kabisa.nl/2011/10/07/kabisa-at-arrrrcamp-2011/</link>
		<comments>http://blog.kabisa.nl/2011/10/07/kabisa-at-arrrrcamp-2011/#comments</comments>
		<pubDate>Fri, 07 Oct 2011 09:05:45 +0000</pubDate>
		<dc:creator>Edwin Klesman</dc:creator>
				<category><![CDATA[Random]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Talks]]></category>

		<guid isPermaLink="false">http://blog.kabisa.nl/?p=222</guid>
		<description><![CDATA[Hi guys, We&#8217;re posting this one right at ya from Arrrrcamp 2011 in Ghent. Arrrrcamp is one of the best known RoR events in Belgium. An event Kabisa is a proud sponsor of. Our crew is sitting in the sessions and we&#8217;ll report in this post after each event. John W Long &#8211; Design workflow for Rails [...]]]></description>
			<content:encoded><![CDATA[<p>Hi guys,</p>
<p>We&#8217;re posting this one right at ya from Arrrrcamp 2011 in Ghent. Arrrrcamp is one of the best known RoR events in Belgium. An event Kabisa is a proud sponsor of. Our crew is sitting in the sessions and we&#8217;ll report in this post after each event.</p>
<p><strong>John W Long &#8211; Design workflow for Rails</strong></p>
<p>We started the day with John W Long&#8217;s session about &#8220;Design workflows for Rails&#8221;. He states that within companies there needs to be knowledge about business, design and development and that the ideal situation is having knowledge of all three aspects. The more these aspects are in synergy with eachother the better. He talked about the things that designing will improve (easier programming, better customer understanding, etc)</p>
<p>Similar to positive aspects that iterative development brings along, the designing of application&#8217;s would need to be iterative, too. An agile workflow that would look as following was presented:</p>
<ul>
<li>Create userstories</li>
<li>Design / Prototyping</li>
<li>Building</li>
<li>Verifying</li>
<li>Back to the 1st step, building new features</li>
</ul>
<p>Conclusion: Integrating designing / prototyping in the iterative daily process will make things easier and will take communication with your customers to a higher level.</p>
<p><strong>Elise Huard &#8211; Data Driven Development</strong></p>
<p>Elise talked about DDD (Date Driven Development).<br />
What we take home from her presentation:</p>
<ul>
<li>Your first hunch about how your web application is going to work out (target wise) is wrong most of the time; you need to measure interaction and your assumptions and react to that.</li>
<li>It’s good to build interactive elements (ie:buttons on key locations) that will give you user feedback and that verify if your assumption is correct.</li>
<li>Check if there is interest in your product(idea) by creating a minimal viable product that you present to the world. Create an update subscription along with that and if there IS interest, you’ll have data (subscriptions) that prove it.</li>
</ul>
<p>&nbsp;</p>
<p><strong>Jonas Nicklass &#8211; Practical testing for assorted languages</strong></p>
<p>For Ruby it isn’t acceptable to write code and NOT test it. Jonas asking the croud who works using RoR and who tests their code: all hands go up.</p>
<p>Asking this for Javascript only few hands are raised.Javascript is something that has always been neglected regarding to testing.<br />
Jonas talked about some design setups for testing Javascript; about unittesting javascript.You have to ask yourself what the goal for writing tests is. Jonas indicates he tests because it makes refactoring easier (remember the red-green-refectoring loop from TDD?). Because unittests are based on testing UNITS (it’s in the name) Jonas states that we need more units in JS; we don’t have the classes and modules that are present in Ruby.JQuery is often seen as a „way of building apps”, but it really is NOT.It doesn’t provided the structure needed for creating the units.<br />
Jonas showed some possible solutions for providing structure to JS, giving some pros and cons along with all the options (think Mootools, CoffeeScript, Backbone, etc).</p>
<p><span style="text-decoration: underline;">Unittesting JS</span><br />
Jonas recommends using Jasmine („the best JS testing framework out there”) for unittesting in JS. It is the only stable solution out there at the moment.It is small but full featured.</p>
<p>When it comes to building JS using a packaged Jasmine solution Jonas build a rails gem (Evergreen) that makes integrating a breeze.This can be used for testing JS. It has nice syntax and can use CoffeeScript if you’d like. Add evergreen to your Gemfile, run the server and you’re good to go!<br />
Running tests can be done in multiple ways:</p>
<ul>
<li>In browsers (/evergreen)</li>
<li>Terminal (using a capybara driver); you can use Selenium, Webkit or ENVJS.</li>
</ul>
<p>Jonas gave a demo using both execution methods. Evergreen showed all the tests present for JS. Clicking on one of them (or the „all” option) runs the test(s) and shows the outcome. Terminal execution was demoed as well and integrated nicely with Selenium.</p>
<p><span style="text-decoration: underline;">Suggestions for writing JS unittests</span><br />
Structure your JS code into functions and classesMostly test event bindingsWrite custom matchers like in RspecIsolate AJAX into seperate components (don’t test or use mocks) to avoid shaky testsTreate templates as fixtures (update them manually) by isolating JS as much as possible from the Ruby code. This depends on JS being setup Simplify your DOM &amp; Templates<br />
Integration testing JS codeJonas talked about Capybare to simulate JS interaction performed by the user and demoed it using Cucumber.</p>
<p>At Kabisa we already use this. Check it out at the web for more info:https://github.com/jnicklas/capybara</p>
<p>Finally, Jonas gave some tips for a better JS integrations test setup:</p>
<ul>
<li>avoid asserting on urls, cookies, session, application state</li>
<li>Asserting to what you can see (interfacing) makes the test more stable. It avoids one for having to update the integration tests constantly.</li>
<li>Be as lenient as possible (avoid specific selectors)</li>
</ul>
<p>&nbsp;</p>
<p><strong>Roy Tomeij &#8211; Stop Swashbucklin&#8217; and Shipshape yer Front-end</strong></p>
<p>Roy talked about Frontend meta languages and The Rails 3.1 asset pipeline.The target audience were people with little Haml experience.<br />
Roy’s statement: compilers don’t create bad code, coders do (regarding Haml output HTML)<br />
A few motivations for using front-end meta language:</p>
<ul>
<li>Quick results</li>
<li>DRY (!)</li>
<li>Unforgiving compilers, so less errors</li>
<li>Better performance „out of the box”</li>
<li>Maintainable code</li>
</ul>
<p>The front-end meta languages Roy talked about were Haml, Sass(&amp;Compass) &amp; CoffeeScript. He showed examples alongside the output that these language generate (it being HTML, CSS or Javascript).</p>
<p>Roy finalized his talk about Rails 3.1 asset pipelines and where to put all the various assets.</p>
<p>In conclusion: frontend meta languages keep your code clean and maintainable so it won&#8217;t hurt to take them into serious consideration!</p>
<p>&nbsp;</p>
<p><strong>Andrew Nesbitt &#8211; A/B Testing everything with Split</strong></p>
<p>Andrew talked about the question: are you making the best out of your pages?<br />
A/B testing is the process of sharing two designs with your users and learning what works best.<br />
Andrew also showed an example of a salespitch text that &#8211; by simply showing another title &#8211; made +30% sales.</p>
<p>Some existing  A/B testing frameworks out there:</p>
<ul>
<li>Abingo</li>
<li>niceSevenMinuteAbs</li>
<li>Vanity</li>
</ul>
<p>Because these frameworks didn’t go all the way, Andrew wrote the Split library.</p>
<p>Some approaches that could be used for A/B testing:</p>
<ul>
<li>Swap css stylesheets</li>
<li>Render different templates / partials</li>
<li>Set different variables at the controller level</li>
<li>Hack the page with JS</li>
</ul>
<p>Split depends on two classes: Split::Experiment and Split::Alternative. These two, accompanied with a CRUD interface make up Split.</p>
<p>Andrew showed an example using an ab_test statement that showed one of two button images (50% chance you see either option a or b).<br />
In the controller’s signup function a „finished” statement was added, after which you can check in the CRUD interface what option is most chosen / successful.The example showed how simple but powerfull this works.</p>
<p>A new feature of Split is weighted averages; you can now define ratio’s in which to serve option A or B.<br />
Another nice feature of Split is the option to ignore certain IP adresses. This helps preventing your stats being mangled by colleagues who develop or test around.</p>
<p><span style="text-decoration: underline;">Some tips regarding to A/B Testing</span></p>
<ul>
<li>If you would want to get definitive favored choices from your users, test BIG changes. The bigger the change the more you’ll see the preffered version.</li>
<li>A typical A/B test would be ~2 weeks. Mind that this has to be longer if you have a low volume website.</li>
<li>Don’t run 2 tests that cross eachother’s stream. This will make the results inconclusive.</li>
</ul>
<p>Conclusion: having trouble discussing the best solution to put out there? Use A/B testing to give all the options a try and let the stats choose a winner.</p>
<p>&nbsp;</p>
<p><strong>Cory Haines &#8211; Fast Rails Tests</strong></p>
<p>Cory started right on with showing the not-so-speedy process of running Rspec tests.Right after that Cory kicks off some tests that show all greens  „near-instantly”&#8230;<br />
Cory talked about the fact that it’s crazy to see such a key element taking up so much time.Thinking back on where we were years ago, thinks aren’t all that bad (referring to the time were an optionally filled /test map resided in projects).Rails changed all that by introducing ways to implement unittesting and integration testing.<br />
He described the evolution of coding; moving business related code to the models. Good for the code, not so good for the speed of tests.</p>
<p>The difference between the Test First and TDD approach is that with TDD,  after you feel the pain, the whole design of the code is corrected instead of the test itself. After that, Cory talked about what „good design” is. His definition of a good design is: a design that is easy to change. He referred to businesses and their need to adapt themselves to their surroundings.<br />
The core pain with Rails testsuites is not „the databases”, even though FactoryGirl or in-memory db’s are trying to create faster experiences. The actual pain of slow tests is Rails itself. Rails is the biggest 3th party dependency in our apps.</p>
<p>Cory demonstrated a way to run rspec on a new directory (fast_spec/speedy_shop/calculates_total_price.rb) in which a ruby file, with only the business logic from the shopping cart model in it,  requires the original codefile followed by the Rspec tests. Using this implementation, spec_helper (that starts rails, and generates all this stuff for you) is not used so you don’t have to wait for the time that would normally take.</p>
<p>He states that one shouldn’t be testing Rails itself and one certainly should not test database interaction by using mocks, because the best test for functionality that interacts with the db IS interacting with the DB (2 db records, one for failing and one for success scenario).<br />
Testing the regular Rspec stuff mostly includes testing the rails configuration that you have put up for your app. This needs to be tested, but not in your main developing circle: build speedy tests to test the business logic in a fast way, and make that process a lot faster (without the accompanying sough).</p>
<p>Conclusion: extracting your business functionality and getting them on track with speedy rspec tests will improve your day-to-day developing cycle and make it less intensive to change simple things and having to run heavy tests.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.kabisa.nl/2011/10/07/kabisa-at-arrrrcamp-2011/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Custom Array#uniq for ActiveRecord results</title>
		<link>http://blog.kabisa.nl/2011/06/03/custom-arrayuniq-for-activerecord-results/</link>
		<comments>http://blog.kabisa.nl/2011/06/03/custom-arrayuniq-for-activerecord-results/#comments</comments>
		<pubDate>Fri, 03 Jun 2011 12:44:04 +0000</pubDate>
		<dc:creator>Ariejan de Vroom</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://blog.kabisa.nl/?p=217</guid>
		<description><![CDATA[You may be aware of the uniq method in Ruby: &#91;1,2,3,4,4,6,2&#93;.uniq =&#62; &#91;1,2,3,4,6&#93; This does not work for arrays of ActiveRecord objects, especially if you want uniqueness on a arbitrary property. Here&#8217;s a snippet that allows you to uniquify an Array using an arbitrary property: Hash&#91;*arrayname.map &#123;&#124;obj&#124; &#91;obj.name, obj&#93;&#125;.flatten&#93;.values Basically you create a new Hash, [...]]]></description>
			<content:encoded><![CDATA[<p>You may be aware of the <code>uniq</code> method in Ruby:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span>,<span style="color:#006666;">2</span>,<span style="color:#006666;">3</span>,<span style="color:#006666;">4</span>,<span style="color:#006666;">4</span>,<span style="color:#006666;">6</span>,<span style="color:#006666;">2</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">uniq</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span>,<span style="color:#006666;">2</span>,<span style="color:#006666;">3</span>,<span style="color:#006666;">4</span>,<span style="color:#006666;">6</span><span style="color:#006600; font-weight:bold;">&#93;</span></pre></div></div>

<p>This does not work for arrays of ActiveRecord objects, especially if you want uniqueness on a arbitrary property. Here&#8217;s a snippet that allows you to uniquify an Array using an arbitrary property:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC00FF; font-weight:bold;">Hash</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">*</span>arrayname.<span style="color:#9900CC;">map</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>obj<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#006600; font-weight:bold;">&#91;</span>obj.<span style="color:#9900CC;">name</span>, obj<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">flatten</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">values</span></pre></div></div>

<p>Basically you create a new Hash, using the unique value as the key and the actual object as value. Then you convert the Hash#values back to an Array. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.kabisa.nl/2011/06/03/custom-arrayuniq-for-activerecord-results/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Share sessions between Rails 2 and Rails 3 applications</title>
		<link>http://blog.kabisa.nl/2010/10/27/share-sessions-between-rails-2-and-rails-3-applications/</link>
		<comments>http://blog.kabisa.nl/2010/10/27/share-sessions-between-rails-2-and-rails-3-applications/#comments</comments>
		<pubDate>Wed, 27 Oct 2010 17:44:34 +0000</pubDate>
		<dc:creator>Patrick Baselier</dc:creator>
				<category><![CDATA[Random]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://blog.kabisa.nl/?p=156</guid>
		<description><![CDATA[This week we started building a Rails 3 application for one of our customers which had to share data with their existing Rails applications, which were built with version 2.1.2 and 2.3.8. Although session configuration differs from version 2 to 3, getting this done wasn&#8217;t such a hard job, mainly thanks to this blogpost written [...]]]></description>
			<content:encoded><![CDATA[<p>This week we started building a Rails 3 application for one of our customers which had to share data with their existing Rails applications, which were built with version 2.1.2 and 2.3.8.</p>
<p>Although session configuration differs from version 2 to 3, getting this done wasn&#8217;t such a hard job, mainly thanks to <a href="http://random-rails.blogspot.com/2010/08/sharing-sessions-between-rails-2-and.html" target="_blank">this blogpost</a> written by Dan McNevin.</p>
<p>Basically this means the sessions are configured as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># Rails 2.1.2</span>
<span style="color:#008000; font-style:italic;"># config/environment.rb</span>
...
<span style="color:#6666ff; font-weight:bold;">Rails::Initializer</span>.<span style="color:#9900CC;">run</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>config<span style="color:#006600; font-weight:bold;">|</span>
  config.<span style="color:#9900CC;">action_controller</span>.<span style="color:#9900CC;">session</span> = <span style="color:#006600; font-weight:bold;">&#123;</span>
    <span style="color:#ff3333; font-weight:bold;">:session_key</span>    =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">'_sso_session'</span>,
    <span style="color:#ff3333; font-weight:bold;">:secret</span>         =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">'a really long hex string'</span>
  <span style="color:#006600; font-weight:bold;">&#125;</span>
  config.<span style="color:#9900CC;">action_controller</span>.<span style="color:#9900CC;">session_store</span> = <span style="color:#ff3333; font-weight:bold;">:cookie_store</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#6666ff; font-weight:bold;">ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:session_domain</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">'.rails.local'</span>
<span style="color:#008000; font-style:italic;"># End of Rails 2.1.2</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># Rails 2.3.8 (and probably 2.3.x)</span>
<span style="color:#008000; font-style:italic;"># config/initializers/session_store.rb</span>
<span style="color:#6666ff; font-weight:bold;">ActionController::Base</span>.<span style="color:#9900CC;">session</span> = <span style="color:#006600; font-weight:bold;">&#123;</span>
  <span style="color:#ff3333; font-weight:bold;">:domain</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">'.rails.local'</span>,
  <span style="color:#ff3333; font-weight:bold;">:key</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">'_sso_session'</span>,
  <span style="color:#ff3333; font-weight:bold;">:secret</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">'the same really long hex string'</span>
<span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#008000; font-style:italic;"># End of Rails 2.3.8</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># Rails 3.0.1</span>
<span style="color:#008000; font-style:italic;"># config/initializers/session_store.rb</span>
<span style="color:#006600; font-weight:bold;">&#91;</span>AppName<span style="color:#006600; font-weight:bold;">&#93;</span>::Application.<span style="color:#9900CC;">config</span>.<span style="color:#9900CC;">session_store</span> <span style="color:#ff3333; font-weight:bold;">:cookie_store</span>, <span style="color:#006600; font-weight:bold;">&#123;</span>
 <span style="color:#ff3333; font-weight:bold;">:key</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">'_sso_session'</span>,
 <span style="color:#ff3333; font-weight:bold;">:domain</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">'.rails.local'</span>
<span style="color:#006600; font-weight:bold;">&#125;</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># config/initializers/secret_token.rb</span>
<span style="color:#006600; font-weight:bold;">&#91;</span>AppName<span style="color:#006600; font-weight:bold;">&#93;</span>::Application.<span style="color:#9900CC;">config</span>.<span style="color:#9900CC;">secret_token</span> = <span style="color:#996600;">'the same really long hex string'</span>
<span style="color:#008000; font-style:italic;"># End of Rails 3.0.1</span></pre></div></div>

<p>Session sharing between 2.1.2 and 2.3.8 worked fine, however when swapping to the 3.0.1 application I got the error:</p>
<blockquote><p>ActionDispatch::Session::SessionRestoreError (Session contains objects whose class definition isn&#8217;t available.<br />
Remember to require the classes for all objects kept in the session.<br />
(Original exception: uninitialized constant ActionController::Flash::FlashHash [NameError])<br />
):</p></blockquote>
<p>In other words (or actually, my own words): the session contains an object (<strong>ActionController::Flash::FlashHash</strong>) which is unfamiliar to Rails 3.</p>
<p>To solve this problem, I added the class:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># Rails 3.0.1</span>
<span style="color:#008000; font-style:italic;"># config/initializers/session_store.rb</span>
<span style="color:#9966CC; font-weight:bold;">module</span> ActionController
  <span style="color:#9966CC; font-weight:bold;">module</span> Flash
    <span style="color:#9966CC; font-weight:bold;">class</span> FlashHash <span style="color:#006600; font-weight:bold;">&amp;</span>lt; <span style="color:#CC00FF; font-weight:bold;">Hash</span>
      <span style="color:#9966CC; font-weight:bold;">def</span> method_missing<span style="color:#006600; font-weight:bold;">&#40;</span>m, <span style="color:#006600; font-weight:bold;">*</span>a, <span style="color:#006600; font-weight:bold;">&amp;</span>amp;b<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#008000; font-style:italic;"># End of Rails 3.0.1</span></pre></div></div>

<p>Now, the error didn&#8217;t show up anymore and so was the session&#8230; I <em>was</em> able to switch from Rails 2 to Rails 3, but now the session didn&#8217;t contain a single keys!?!?<br />
Assuming there is a <strong>require_user</strong> method doing the authentication, I added a</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># Rails 3.0.1</span>
<span style="color:#008000; font-style:italic;"># app/controllers/application_controller.rb</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> require_user
    y request
  ...
<span style="color:#008000; font-style:italic;"># End of Rails 3.0.1</span></pre></div></div>

<p>to this controller action (which is short for <em>puts request.to_yaml</em>) and I was surprised to find the keys, which were stored by the Rails 2 app., in the <strong>env</strong> object in it&#8217;s <strong>action_dispatch.request.unsigned_session_cookie</strong> key:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># Rails 3.0.1</span>
  y request.<span style="color:#9900CC;">env</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'action_dispatch.request.unsigned_session_cookie'</span><span style="color:#006600; font-weight:bold;">&#93;</span>
  <span style="color:#008000; font-style:italic;"># =&amp;gt; ---</span>
      serial: <span style="color:#006666;">0</span>
      _csrf_token: nTHGmUfA0sKh1rDZWvt<span style="color:#006600; font-weight:bold;">+</span>1tLZmG3fCWlhf8pkiHGMU5I=
      last_quote_time_en_US: !timestamp
        at: <span style="color:#996600;">&quot;2010-10-27 14:52:15.736034 +02:00&quot;</span>
        <span style="color:#996600;">&quot;@marshal_with_utc_coercion&quot;</span>: <span style="color:#0000FF; font-weight:bold;">true</span>
      session_id: ef4c356efc12113792ecccbde65bba7a
      user_id: <span style="color:#006666;">35</span>
      lang: en_US
      shown_quotes_en_US:
      <span style="color:#006600; font-weight:bold;">-</span> <span style="color:#006666;">17688</span>
      ...
<span style="color:#008000; font-style:italic;"># End of Rails 3.0.1</span></pre></div></div>

<p>Pretty hopeless by now, I decided to get the keys I needed out of this Hash and add them to the Rails 3 session manually:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># Rails 3.0.1</span>
  session<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:user_id</span><span style="color:#006600; font-weight:bold;">&#93;</span> = request.<span style="color:#9900CC;">env</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'action_dispatch.request.unsigned_session_cookie'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'user_id'</span><span style="color:#006600; font-weight:bold;">&#93;</span>
<span style="color:#008000; font-style:italic;"># End of Rails 3.0.1</span></pre></div></div>

<p>But this surprised me even more, finding a fully populated session only after adding one key.</p>
<p>Time to investigate the <strong>actionpack</strong> gem.<br />
When you add a key to the session object, this will call the <strong>[]=</strong>-method in the <strong>ActionDispatch::Session::SessionHash</strong> class. The <strong>[]=</strong>-method internally calls a private method <strong>load_for_write!</strong>. My thinking was (since diving deeper into the code didn&#8217;t come to my mind) that the Rails 3 session is fully populated, but not yet loaded when going or returning to the Rails 3 application.</p>
<p>This was an easy one, I just had to reload the session before using it:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># Rails 3.0.1</span>
<span style="color:#008000; font-style:italic;"># app/controllers/application_controller.rb</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> require_user
    session.<span style="color:#9900CC;">send</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:load_for_write</span>!<span style="color:#006600; font-weight:bold;">&#41;</span>
  ...
<span style="color:#008000; font-style:italic;"># End of Rails 3.0.1</span></pre></div></div>

<p>Problem solved? Well, not completely. I was able to successfully browse from the Rails 2 app. to Rails 3, without losing my session, but going back to the Rails 2 app. introduced another problem: keys initially stored as symbols were now turned into string because of the Rails 3 app.</p>
<p>Initially, I tried to solve this by converting all keys back into symbols, but this should introduce another problem, since I was not sure if all session keys were stored as symbols. Rails itself stores the Flash object in the session into the &#8220;flash&#8221; key, instead of :flash.</p>
<p>A better approach is to patch the CGI::Session object and make sure all keys can be stored and retrieved as both string and symbols:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># Rails 2.1.2 and 2.3.x</span>
<span style="color:#008000; font-style:italic;"># config/initializers/load_patches.rb</span>
<span style="color:#008000; font-style:italic;">#</span>
<span style="color:#008000; font-style:italic;"># Loads patches stored in lib/patches.</span>
<span style="color:#CC00FF; font-weight:bold;">Dir</span><span style="color:#006600; font-weight:bold;">&#91;</span>RAILS_ROOT <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot;/lib/patches/**/*.rb&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>file<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#CC0066; font-weight:bold;">require</span> file <span style="color:#006600; font-weight:bold;">&#125;</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># lib/patches/cgi/session.rb</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'cgi/session'</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># Patching CGI:Session so that it on longer matters if you retrieve a session</span>
<span style="color:#008000; font-style:italic;"># value using a String, Symbol, ... This in order to make it play nicely</span>
<span style="color:#008000; font-style:italic;"># together with Rails 3.</span>
<span style="color:#008000; font-style:italic;">#</span>
<span style="color:#008000; font-style:italic;"># = Examples</span>
<span style="color:#008000; font-style:italic;">#</span>
<span style="color:#008000; font-style:italic;">#  session[:foo] = &quot;Bar&quot;</span>
<span style="color:#008000; font-style:italic;">#  session[:foo] # =&amp;gt; &quot;Bar&quot;</span>
<span style="color:#008000; font-style:italic;">#  session[&quot;foo&quot;] # =&amp;gt; &quot;Bar&quot;</span>
<span style="color:#008000; font-style:italic;">#</span>
<span style="color:#008000; font-style:italic;">#  session[&quot;qux&quot;] = &quot;Baz&quot;</span>
<span style="color:#008000; font-style:italic;">#  session[:qux] # =&amp;gt; &quot;Baz&quot;</span>
<span style="color:#008000; font-style:italic;">#  session[&quot;qux&quot;] # =&amp;gt; &quot;Baz&quot;</span>
<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#CC00FF; font-weight:bold;">CGI</span> <span style="color:#008000; font-style:italic;">#:nodoc:</span>
  <span style="color:#9966CC; font-weight:bold;">class</span> Session <span style="color:#008000; font-style:italic;">#:nodoc:</span>
    <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#40;</span>key<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#0066ff; font-weight:bold;">@data</span> <span style="color:#006600; font-weight:bold;">||</span>= <span style="color:#0066ff; font-weight:bold;">@dbman</span>.<span style="color:#9900CC;">restore</span>
      <span style="color:#0066ff; font-weight:bold;">@data</span><span style="color:#006600; font-weight:bold;">&#91;</span>key.<span style="color:#9900CC;">to_s</span><span style="color:#006600; font-weight:bold;">&#93;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span>=<span style="color:#006600; font-weight:bold;">&#40;</span>key, val<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#0066ff; font-weight:bold;">@write_lock</span> <span style="color:#006600; font-weight:bold;">||</span>= <span style="color:#0000FF; font-weight:bold;">true</span>
      <span style="color:#0066ff; font-weight:bold;">@data</span> <span style="color:#006600; font-weight:bold;">||</span>= <span style="color:#0066ff; font-weight:bold;">@dbman</span>.<span style="color:#9900CC;">restore</span>
      <span style="color:#0066ff; font-weight:bold;">@data</span><span style="color:#006600; font-weight:bold;">&#91;</span>key.<span style="color:#9900CC;">to_s</span><span style="color:#006600; font-weight:bold;">&#93;</span> = val
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># End of Rails 2.1.2 and 2.3.x</span></pre></div></div>

<p>Now it worked! I am able to share sessions between Rails 2.1, 2.3.x and Rails 3.0 application.</p>
<p>To wrap things up:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># Rails 2.1.2</span>
<span style="color:#008000; font-style:italic;"># config/environment.rb</span>
...
<span style="color:#6666ff; font-weight:bold;">Rails::Initializer</span>.<span style="color:#9900CC;">run</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>config<span style="color:#006600; font-weight:bold;">|</span>
  config.<span style="color:#9900CC;">action_controller</span>.<span style="color:#9900CC;">session</span> = <span style="color:#006600; font-weight:bold;">&#123;</span>
    <span style="color:#ff3333; font-weight:bold;">:session_key</span>    =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">'_sso_session'</span>,
    <span style="color:#ff3333; font-weight:bold;">:secret</span>         =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">'a really long hex string'</span>
  <span style="color:#006600; font-weight:bold;">&#125;</span>
  config.<span style="color:#9900CC;">action_controller</span>.<span style="color:#9900CC;">session_store</span> = <span style="color:#ff3333; font-weight:bold;">:cookie_store</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#6666ff; font-weight:bold;">ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:session_domain</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">'.rails.local'</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># config/initializers/load_patches.rb</span>
<span style="color:#CC00FF; font-weight:bold;">Dir</span><span style="color:#006600; font-weight:bold;">&#91;</span>RAILS_ROOT <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot;/lib/patches/**/*.rb&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>file<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#CC0066; font-weight:bold;">require</span> file <span style="color:#006600; font-weight:bold;">&#125;</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># lib/patches/cgi/session.rb</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'cgi/session'</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#CC00FF; font-weight:bold;">CGI</span> <span style="color:#008000; font-style:italic;">#:nodoc:</span>
  <span style="color:#9966CC; font-weight:bold;">class</span> Session <span style="color:#008000; font-style:italic;">#:nodoc:</span>
    <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#40;</span>key<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#0066ff; font-weight:bold;">@data</span> <span style="color:#006600; font-weight:bold;">||</span>= <span style="color:#0066ff; font-weight:bold;">@dbman</span>.<span style="color:#9900CC;">restore</span>
      <span style="color:#0066ff; font-weight:bold;">@data</span><span style="color:#006600; font-weight:bold;">&#91;</span>key.<span style="color:#9900CC;">to_s</span><span style="color:#006600; font-weight:bold;">&#93;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span>=<span style="color:#006600; font-weight:bold;">&#40;</span>key, val<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#0066ff; font-weight:bold;">@write_lock</span> <span style="color:#006600; font-weight:bold;">||</span>= <span style="color:#0000FF; font-weight:bold;">true</span>
      <span style="color:#0066ff; font-weight:bold;">@data</span> <span style="color:#006600; font-weight:bold;">||</span>= <span style="color:#0066ff; font-weight:bold;">@dbman</span>.<span style="color:#9900CC;">restore</span>
      <span style="color:#0066ff; font-weight:bold;">@data</span><span style="color:#006600; font-weight:bold;">&#91;</span>key.<span style="color:#9900CC;">to_s</span><span style="color:#006600; font-weight:bold;">&#93;</span> = val
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#008000; font-style:italic;"># End of Rails 2.1.2</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># Rails 2.3.8 (and probably 2.3.x)</span>
<span style="color:#008000; font-style:italic;"># config/initializers/session_store.rb</span>
<span style="color:#6666ff; font-weight:bold;">ActionController::Base</span>.<span style="color:#9900CC;">session</span> = <span style="color:#006600; font-weight:bold;">&#123;</span>
  <span style="color:#ff3333; font-weight:bold;">:domain</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">'.rails.local'</span>,
  <span style="color:#ff3333; font-weight:bold;">:key</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">'_sso_session'</span>,
  <span style="color:#ff3333; font-weight:bold;">:secret</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">'the same really long hex string'</span>
<span style="color:#006600; font-weight:bold;">&#125;</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># config/initializers/load_patches.rb</span>
<span style="color:#CC00FF; font-weight:bold;">Dir</span><span style="color:#006600; font-weight:bold;">&#91;</span>RAILS_ROOT <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot;/lib/patches/**/*.rb&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>file<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#CC0066; font-weight:bold;">require</span> file <span style="color:#006600; font-weight:bold;">&#125;</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># lib/patches/cgi/session.rb</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'cgi/session'</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#CC00FF; font-weight:bold;">CGI</span> <span style="color:#008000; font-style:italic;">#:nodoc:</span>
  <span style="color:#9966CC; font-weight:bold;">class</span> Session <span style="color:#008000; font-style:italic;">#:nodoc:</span>
    <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#40;</span>key<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#0066ff; font-weight:bold;">@data</span> <span style="color:#006600; font-weight:bold;">||</span>= <span style="color:#0066ff; font-weight:bold;">@dbman</span>.<span style="color:#9900CC;">restore</span>
      <span style="color:#0066ff; font-weight:bold;">@data</span><span style="color:#006600; font-weight:bold;">&#91;</span>key.<span style="color:#9900CC;">to_s</span><span style="color:#006600; font-weight:bold;">&#93;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span>=<span style="color:#006600; font-weight:bold;">&#40;</span>key, val<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#0066ff; font-weight:bold;">@write_lock</span> <span style="color:#006600; font-weight:bold;">||</span>= <span style="color:#0000FF; font-weight:bold;">true</span>
      <span style="color:#0066ff; font-weight:bold;">@data</span> <span style="color:#006600; font-weight:bold;">||</span>= <span style="color:#0066ff; font-weight:bold;">@dbman</span>.<span style="color:#9900CC;">restore</span>
      <span style="color:#0066ff; font-weight:bold;">@data</span><span style="color:#006600; font-weight:bold;">&#91;</span>key.<span style="color:#9900CC;">to_s</span><span style="color:#006600; font-weight:bold;">&#93;</span> = val
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#008000; font-style:italic;"># End of Rails 2.3.8</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># Rails 3.0.1</span>
<span style="color:#008000; font-style:italic;"># config/initializers/session_store.rb</span>
<span style="color:#006600; font-weight:bold;">&#91;</span>AppName<span style="color:#006600; font-weight:bold;">&#93;</span>::Application.<span style="color:#9900CC;">config</span>.<span style="color:#9900CC;">session_store</span> <span style="color:#ff3333; font-weight:bold;">:cookie_store</span>, <span style="color:#006600; font-weight:bold;">&#123;</span>
 <span style="color:#ff3333; font-weight:bold;">:key</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">'_sso_session'</span>,
 <span style="color:#ff3333; font-weight:bold;">:domain</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">'.rails.local'</span>
<span style="color:#006600; font-weight:bold;">&#125;</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">module</span> ActionController
  <span style="color:#9966CC; font-weight:bold;">module</span> Flash
    <span style="color:#9966CC; font-weight:bold;">class</span> FlashHash <span style="color:#006600; font-weight:bold;">&amp;</span>lt; <span style="color:#CC00FF; font-weight:bold;">Hash</span>
      <span style="color:#9966CC; font-weight:bold;">def</span> method_missing<span style="color:#006600; font-weight:bold;">&#40;</span>m, <span style="color:#006600; font-weight:bold;">*</span>a, <span style="color:#006600; font-weight:bold;">&amp;</span>amp;b<span style="color:#006600; font-weight:bold;">&#41;</span>; <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># config/initializers/secret_token.rb</span>
<span style="color:#006600; font-weight:bold;">&#91;</span>AppName<span style="color:#006600; font-weight:bold;">&#93;</span>::Application.<span style="color:#9900CC;">config</span>.<span style="color:#9900CC;">secret_token</span> = <span style="color:#996600;">'the same really long hex string'</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># app/controllers/application_controller.rb</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> require_user
    session.<span style="color:#9900CC;">send</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:load_for_write</span>!<span style="color:#006600; font-weight:bold;">&#41;</span>
  ...
<span style="color:#008000; font-style:italic;"># End of Rails 3.0.1</span></pre></div></div>

<p>Next job is to upgrade the legacy code to Rails 3&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.kabisa.nl/2010/10/27/share-sessions-between-rails-2-and-rails-3-applications/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Running cucumber features with sunspot_rails</title>
		<link>http://blog.kabisa.nl/2010/02/03/running-cucumber-features-with-sunspot_rails/</link>
		<comments>http://blog.kabisa.nl/2010/02/03/running-cucumber-features-with-sunspot_rails/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 07:57:15 +0000</pubDate>
		<dc:creator>Patrick Baselier</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://blog.kabisa.nl/?p=75</guid>
		<description><![CDATA[We wanted to integrate the sunspot_rails gem into our cucumber features. I found a ticket where mat adviced to call Sunspot::Rails::Server.start / stop in one of the available cucumber hooks. Code found in features/support/env.rb is run when Cucumber begins and exits so this seemed the right place to start Solr: Sunspot::Rails::Server.new.start &#160; at_exit do Sunspot::Rails::Server.new.stop [...]]]></description>
			<content:encoded><![CDATA[<p>We wanted to integrate the <a href="http://github.com/outoftime/sunspot" target="_blank">sunspot_rails gem</a> into our cucumber features. I found a <a href="http://outoftime.lighthouseapp.com/projects/20339/tickets/59-cucumber-testing-and-solr_rails" target="_blank">ticket</a> where <a href="http://outoftime.lighthouseapp.com/users/24899" target="_blank">mat</a> adviced to call <strong>Sunspot::Rails::Server.start / stop</strong> in one of the available cucumber hooks.</p>
<p>Code found in <strong>features/support/env.rb</strong> is run when Cucumber begins and exits so this seemed the right place to start Solr:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#6666ff; font-weight:bold;">Sunspot::Rails::Server</span>.<span style="color:#9900CC;">new</span>.<span style="color:#9900CC;">start</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">at_exit</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  <span style="color:#6666ff; font-weight:bold;">Sunspot::Rails::Server</span>.<span style="color:#9900CC;">new</span>.<span style="color:#9900CC;">stop</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Also, make sure you&#8217;ve added a cucumber environment to the <strong>config/sunspot.yml</strong> file; we copied the test-environment for that:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">test: <span style="color:#006600; font-weight:bold;">&amp;</span>amp;TEST
  solr:
    hostname: localhost
    port: <span style="color:#006666;">8981</span>
    log_level: WARNING
&nbsp;
cucumber:
  <span style="color:#006600; font-weight:bold;">&amp;</span>lt;<span style="color:#006600; font-weight:bold;">&amp;</span>lt;: <span style="color:#006600; font-weight:bold;">*</span>TEST</pre></div></div>

<p>Running cucumber will let all scenarios fail unfortunately and we got a &#8216;<strong>Connection refused &#8211; connect(2) (RSolr::RequestError)</strong>&#8216; in our console.</p>
<p>The reason for this is simple (after I stepped into the sunspot_rails gem to be honest): the <strong>Sunspot::Rails::Server.new.start</strong> method will eventually launch a Java Servlet Container (Jetty) with the Solr WAR and uses the port defined in your <strong>sunspot.yml</strong>.<br />
Now, starting up a server could take some time, so if cucumber&#8217;s features are run before the Solr server is up and running, the &#8216;Connection refused&#8217; sounds trivial then.<br />
First I added a sleep after starting up the server:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#6666ff; font-weight:bold;">Sunspot::Rails::Server</span>.<span style="color:#9900CC;">new</span>.<span style="color:#9900CC;">start</span>
<span style="color:#CC0066; font-weight:bold;">sleep</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">5</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>and this will work for most cases, but I thought it would be better to let cucumber wait just long enough until the server is up and running. When the server is up, you can open up your browser and enter <em>http://localhost:8981/solr</em> to administering Solr. This we can use to find out if we&#8217;ve waited long enough and start our features. I&#8217;ve put this into a seperate class named <strong>CukeSunspot</strong> and created this file in the <strong>features/support</strong> directory:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">&quot;net/http&quot;</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> CukeSunspot
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> initialize
    <span style="color:#0066ff; font-weight:bold;">@server</span> = <span style="color:#6666ff; font-weight:bold;">Sunspot::Rails::Server</span>.<span style="color:#9900CC;">new</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> start
    <span style="color:#0066ff; font-weight:bold;">@started</span> = <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span>
    <span style="color:#0066ff; font-weight:bold;">@server</span>.<span style="color:#9900CC;">start</span>
    up
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  private
  <span style="color:#9966CC; font-weight:bold;">def</span> port
    <span style="color:#0066ff; font-weight:bold;">@server</span>.<span style="color:#9900CC;">port</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> uri
    <span style="color:#996600;">&quot;http://0.0.0.0:#{port}/solr/&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> up
    <span style="color:#9966CC; font-weight:bold;">while</span> starting
      <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Sunspot server is starting...&quot;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Sunspot server took #{'%.2f' % (Time.now - @started)} sec. to get up and running. Let's cuke!&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> starting
    <span style="color:#9966CC; font-weight:bold;">begin</span>
      <span style="color:#CC0066; font-weight:bold;">sleep</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      request = <span style="color:#6666ff; font-weight:bold;">Net::HTTP</span>.<span style="color:#9900CC;">get_response</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">URI</span>.<span style="color:#9900CC;">parse</span><span style="color:#006600; font-weight:bold;">&#40;</span>uri<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#0000FF; font-weight:bold;">false</span>
    <span style="color:#9966CC; font-weight:bold;">rescue</span> <span style="color:#CC00FF; font-weight:bold;">Errno</span>::ECONNREFUSED
      <span style="color:#0000FF; font-weight:bold;">true</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Now we can the alternative start method and remove the explicit sleep statement in our global before hook. <strong>features/support/env.rb</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">CukeSunspot.<span style="color:#9900CC;">new</span>.<span style="color:#9900CC;">start</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">at_exit</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  <span style="color:#6666ff; font-weight:bold;">Sunspot::Rails::Server</span>.<span style="color:#9900CC;">new</span>.<span style="color:#9900CC;">stop</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>And voila, if you run cucumber, you scenario&#8217;s should run successfully. On my machine:</p>
<pre>Sunspot server is starting...
Sunspot server is starting...
Sunspot server took 3.74 sec. to get up and running. Let's cuke!</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.kabisa.nl/2010/02/03/running-cucumber-features-with-sunspot_rails/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Using transactions with Ruby DataMapper</title>
		<link>http://blog.kabisa.nl/2010/01/21/using-transactions-with-ruby-datamapper/</link>
		<comments>http://blog.kabisa.nl/2010/01/21/using-transactions-with-ruby-datamapper/#comments</comments>
		<pubDate>Thu, 21 Jan 2010 19:25:38 +0000</pubDate>
		<dc:creator>Ludo van den Boom</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://blog.kabisa.nl/?p=52</guid>
		<description><![CDATA[With DataMapper, it can be quite a challenge to perform tasks that seem so simple at first. DataMapper is an object-relational mapper (ORM) written in Ruby, with a lot of great features and innovative approaches to common ORM-tasks. But it lacks documentation for some of the less-used features and even the more popular search engines [...]]]></description>
			<content:encoded><![CDATA[<p>With <a href="http://datamapper.org">DataMapper</a>, it can be quite a challenge to perform tasks that seem so simple at first. DataMapper is an object-relational mapper (ORM) written in Ruby, with a lot of great features and innovative approaches to common ORM-tasks. But it lacks documentation for some of the less-used features and even the more popular search engines don&#8217;t have the answer to all questions.</p>
<p>Note: the following examples have been tested with DataMapper version 0.10.2.</p>
<p>One of the questions I had was how to perform multiple queries within a single (database) transaction, so that I can &#8216;stage&#8217; a number of database queries and commit (or rollback) them all in one go. Fortunately, after some investigation of the DataMapper source code, it turns out to be an extremely simple task:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">User.<span style="color:#9900CC;">transaction</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  User.<span style="color:#9900CC;">first</span>.<span style="color:#9900CC;">update</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:name</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">&quot;John Smith&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  Address.<span style="color:#9900CC;">first</span>.<span style="color:#9900CC;">update</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:street</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">&quot;&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#008000; font-style:italic;"># Invalid: street must not be blank</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>With this code neither the address nor the user will be updated in the database if one of the updates fails. The syntax is actually the same as for the <a href="http://api.rubyonrails.org/classes/ActiveRecord/Transactions/ClassMethods.html">ActiveRecord</a> ORM. However, triggering a rollback is done differently, as can be seen in the following example.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">User.<span style="color:#9900CC;">transaction</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>t<span style="color:#006600; font-weight:bold;">|</span>
  User.<span style="color:#9900CC;">first</span>.<span style="color:#9900CC;">update</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:name</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">&quot;John Smith&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  Address.<span style="color:#9900CC;">first</span>.<span style="color:#9900CC;">update</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:street</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">&quot;Oak St. 400&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  t.<span style="color:#9900CC;">rollback</span> <span style="color:#008000; font-style:italic;"># Transaction will be rolled back even when updates are OK.</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>That&#8217;s it for now. I&#8217;m sure there are some additional features that I haven&#8217;t mentioned here, but this is all I had to know at this point.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.kabisa.nl/2010/01/21/using-transactions-with-ruby-datamapper/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to setup Ruby on Rails, Apache and Passenger on Debian Linux</title>
		<link>http://blog.kabisa.nl/2009/12/08/how-to-setup-ruby-on-rails-apache-and-passenger-on-debian-linux/</link>
		<comments>http://blog.kabisa.nl/2009/12/08/how-to-setup-ruby-on-rails-apache-and-passenger-on-debian-linux/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 21:05:05 +0000</pubDate>
		<dc:creator>Harm</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[lenny]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[passenger]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://blog.kabisa.nl/?p=40</guid>
		<description><![CDATA[For this article I&#8217;m going to install a single (virtual) server to run a standard Ruby on Rails application. I will be using Apache2 and passenger for the webserver stack and MySQL as a database server. Let&#8217;s start by installing Ruby and all tools: # apt-get install build-essential # apt-get install ruby irb ri rdoc [...]]]></description>
			<content:encoded><![CDATA[<p>For this article I&#8217;m going to install a single (virtual) server to run a standard Ruby on Rails application. I will be using Apache2 and passenger for the webserver stack and MySQL as a database server. </p>
<p>Let&#8217;s start by installing Ruby and all tools:</p>
<pre><code>
# apt-get install build-essential
# apt-get install ruby irb ri rdoc libopenssl-ruby ruby1.8-dev
# ruby -v
# cd /usr/local/src
# wget http://rubyforge.org/frs/download.php/60718/rubygems-1.3.5.tgz # replace with latest version of rubygems
# tar xfvz rubygems-1.3.5.tgz
# cd rubygems-1.3.5
# ruby setup.rb
# ln -s /usr/bin/gem1.8 /usr/bin/gem
# gem -v
# gem install gemcutter
# gem tumble
# apt-get install mysql-server # this will ask for a password during installation
# apt-get install libmysqlclient15-dev
# gem install mysql
# gem install rails
# apt-get install git-core
# apt-get install apache2
# gem install passenger
# passenger-install-apache2-module</code></pre>
<p>Copy the following lines from the output and paste them at the end of the file /etc/apache2/apache2.conf. They should look something like this:</p>
<pre><code>
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.2.7/ext/apache2/mod_passenger.so
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.2.7
PassengerRuby /usr/bin/ruby1.8
</code></pre>
<p>Finally let&#8217;s restart apache2: </p>
<pre><code>/etc/init.d/apache2 restart</pre>
<p></code></p>
<p>Phew! That's it... We now have all the software we need on the server that's required to deploy your Ruby on Rails app on Debian Linux (Lenny)!</p>
<p>In a future article I'll cover the basics of deployment using <a href="http://capify.org">Capistrano</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.kabisa.nl/2009/12/08/how-to-setup-ruby-on-rails-apache-and-passenger-on-debian-linux/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Ruby and SSL Certificate Validation</title>
		<link>http://blog.kabisa.nl/2009/12/04/ruby-and-ssl-certificate-validation/</link>
		<comments>http://blog.kabisa.nl/2009/12/04/ruby-and-ssl-certificate-validation/#comments</comments>
		<pubDate>Fri, 04 Dec 2009 14:35:38 +0000</pubDate>
		<dc:creator>Ariejan de Vroom</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[openssl]]></category>
		<category><![CDATA[ssl]]></category>

		<guid isPermaLink="false">http://blog.kabisa.nl/?p=31</guid>
		<description><![CDATA[If your ruby app is doing SSL, you have probably seen one of the following errors: doc = Hpricot(open("https://www.cert.org/blogs/vuls/rss.xml")) # => /usr/lib/ruby/1.8/net/http.rb:590:in `connect': certificate verify failed (OpenSSL::SSL::SSLError) or warning: peer certificate won't be verified in this SSL session The solution is to make sure ruby has access to the right set of root certificates. The [...]]]></description>
			<content:encoded><![CDATA[<p>If your ruby app is doing SSL, you have probably seen one of the following errors:</p>
<p><code>doc = Hpricot(open("https://www.cert.org/blogs/vuls/rss.xml")) # => /usr/lib/ruby/1.8/net/http.rb:590:in `connect': certificate verify failed (OpenSSL::SSL::SSLError)</code></p>
<p>or</p>
<p><code>warning: peer certificate won't be verified in this SSL session</code></p>
<p>The solution is to make sure ruby has access to the right set of root certificates.<br />
<span id="more-31"></span><br />
The easiest way to get hold of those root certificates is by downloading this file <a href="http://curl.haxx.se/ca/cacert.pem">cacert.pem</a> (<a href="http://curl.haxx.se/docs/caextract.html">details</a>) (updated weekly by the developers of CURL, based on the Mozilla browser). Download this file and store it somewhere in your app. </p>
<p>If you&#8217;re really keen on security, don&#8217;t trust the guys from CURL and download the different root certificates from their providers manually. However, in most cases, the file from CURL will suffice.</p>
<p>Then, in your ruby code, setup the connection like this and you&#8217;ll have a validated SSL connection:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#! /usr/bin/env ruby</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'net/https'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'uri'</span>
&nbsp;
uri = <span style="color:#CC00FF; font-weight:bold;">URI</span>.<span style="color:#9900CC;">parse</span><span style="color:#006600; font-weight:bold;">&#40;</span>ARGV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">||</span> <span style="color:#996600;">'https://localhost/'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
http = <span style="color:#6666ff; font-weight:bold;">Net::HTTP</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>uri.<span style="color:#9900CC;">host</span>, uri.<span style="color:#9900CC;">port</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">if</span> uri.<span style="color:#9900CC;">scheme</span> == <span style="color:#996600;">&quot;https&quot;</span>  <span style="color:#008000; font-style:italic;"># enable SSL/TLS</span>
  http.<span style="color:#9900CC;">use_ssl</span> = <span style="color:#0000FF; font-weight:bold;">true</span>
  <span style="color:#008000; font-style:italic;"># Only needed for ruby 1.8.6</span>
  <span style="color:#008000; font-style:italic;"># http.enable_post_connection_check = true</span>
  http.<span style="color:#9900CC;">verify_mode</span> = <span style="color:#6666ff; font-weight:bold;">OpenSSL::SSL::VERIFY_PEER</span>
  http.<span style="color:#9900CC;">ca_file</span> = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">dirname</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">__FILE__</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#996600;">&quot;cacert.pem&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
http.<span style="color:#9900CC;">start</span> <span style="color:#006600; font-weight:bold;">&#123;</span>
  http.<span style="color:#9900CC;">request_get</span><span style="color:#006600; font-weight:bold;">&#40;</span>uri.<span style="color:#9900CC;">path</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>res<span style="color:#006600; font-weight:bold;">|</span>
    <span style="color:#CC0066; font-weight:bold;">print</span> res.<span style="color:#9900CC;">body</span>
  <span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.kabisa.nl/2009/12/04/ruby-and-ssl-certificate-validation/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Giving Love To the Community</title>
		<link>http://blog.kabisa.nl/2009/11/27/giving-love-to-the-community/</link>
		<comments>http://blog.kabisa.nl/2009/11/27/giving-love-to-the-community/#comments</comments>
		<pubDate>Fri, 27 Nov 2009 11:09:27 +0000</pubDate>
		<dc:creator>Ludo van den Boom</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[conference]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[railsconf]]></category>
		<category><![CDATA[rumble]]></category>

		<guid isPermaLink="false">http://blog.kabisa.nl/?p=3</guid>
		<description><![CDATA[Earlier this month Kabisa attended the Ruby en Rails 2009 conference in Amsterdam. Ruby en Rails is the largest dedicated Ruby and Rails conference in the Netherlands. For the first time in its history Ruby en Rails was a multiple day event. The first day, October 31, was packed with interesting presentations on various Ruby [...]]]></description>
			<content:encoded><![CDATA[<p>Earlier this month Kabisa attended the <a title="Ruby en Rails 2009 Homepage" href="http://2009.rubyenrails.nl">Ruby en Rails 2009</a> conference in Amsterdam. Ruby en Rails is the largest dedicated Ruby and Rails conference in the Netherlands.</p>
<p>For the first time in its history Ruby en Rails was a multiple day event. The first day, October 31, was packed with interesting presentations on various Ruby and Rails related topics, by great speakers including renowned community idols like Yehuda Katz, Jeremy Kemper, Jonathan Weiss and many more. The second day (the &#8216;geek-day&#8217;) focused on more practical sessions and lightning talks. On this day another event was held: The RubyEnRails Rumble (RERR), a competition where teams of two had to complete an assignment within a certain time.<br />
<span id="more-3"></span><br />
Since we from Kabisa consider ourselves to be Ruby programmers we wanted to take the challenge and see how we would do in this competition. Michel de Graaf and Ludo van den Boom were given the honor to rumble for Kabisa. This post will describe how we prepared for the RubyEnRails Rumble and how we have experienced it.</p>
<h2>Rumble Preparations</h2>
<p>After deciding that we would partake in the Rumble we knew that we would have to prepare ourselves as good as possible so that we could utilize our time at the Rumble as efficiently as possible. Neither of us had ever participated in an event like this, so we started of with a session in which we tried to decide what we could do to help us prepare for the Rumble. Together with our Kabisa colleagues we made a list of items and topics that could prove to be handy during the Rumble.</p>
<p>The hard part was that we had no experience and that we did not know what the assignment would be, so we dove into a broad range of subjects. With help from our colleagues we were able to refresh our knowledge of Ruby and Rails related technologies and built up a collection of snippets/links to quickly be able to perform standard tasks like retrieving tweets from Twitter and adding jQuery UI sugar to an application. In the end we prepared a <a href="http://github.com/ludo/rerr_template">Rails application template</a> so that we would be able to quickly set-up a Rails skeleton application including basic functionality like authentication and authorization. Besides this template we also prepared a user interface template builder that could help us to quickly apply a &#8216;theme/skin&#8217; to an application (<a href="http://github.com/michel/interfaceLift">interfaceLift</a>).</p>
<p>For scaffolding we used <a href="http://github.com/grimen/dry_scaffold">dry_scaffold</a>: This gem contains a rails generator that will replace the default rails scaffolding with more up to date DRY controllers and views. Controllers are implemented using <a href="http://github.com/josevalim/inherited_resources/tree/master">inherited_resources</a>. And the views are generated in <a href="http://haml-lang.com/">haml</a> that make use of <a href="http://github.com/justinfrench/formtastic">Formtastic Forms</a> to generate nice looking forms. The <a href="http://github.com/michel/dry_scaffold">fork</a> we where using also generated a search form that was implemented using <a href="http://github.com/binarylogic/searchlogic">searchlogic</a>.</p>
<p>Another challenge was that we had not worked together before. So, apart from the technical toolkit that we set-up, we also had to find a way to get more acquainted with each others good and bad sides. We decided that the best way to do this would be to simulate a Rumble, and that&#8217;s what we did. Our colleague Ralph came up with an assignment that we worked on for about six hours. In these six hours we managed to crank out some decent results and learned how we could best divide the development tasks to our individual skill sets. This simulation prepared us for lots of things but it did not really simulate the most vital element of a competition: stress.</p>
<h2>Rumble Ramblings</h2>
<p>Some hints on what the assignment would be were dropped during the presentations on the first day. Still, we could only guess what exactly to expect. At the start of the Rumble the assignment was introduced and explained, the assignment was titled &#8216;Community Love&#8217;. It turned out that we had to create a system that would keep users of Ruby libraries up-to-date with updates about these libraries. The assignment was kept vague on purpose so that the teams had the ability to put their creative minds to work with finding a solution to the problems laid out in the assignment description.</p>
<p>So, now we had a little under eight hours left to design and build something that would convince the jury of our programming skills. After a short stand-up meeting we came up with a rough idea for what we would create.</p>
<h3>The Plan&#8230;</h3>
<p>As a Ruby/Rails developer you will probably make use of lots of gems in your application. You can specify these gem dependencies in your Rails configuration. Or make use of the awesome gem <a href="http://github.com/wycats/bundler">bundler</a>. This will help you manage gem dependencies but they will not inform you when there are updates to the gems you are using. We figured that, as a developer who uses gems in a Ruby project you should be able to send a list of gem dependencies you use in a specific application to a service that will inform you when there are updates to the gems that you are using. An update could, for example, be a new version, a reported security vulnerability or a blog post. Since we had only one day to build something, we decided to focus on Rubygems exclusively. Mostly because there are already good centralized repositories where we would be able to easily find information about gems (gemcutter).</p>
<h3>&#8230; And the Solution &#8230;</h3>
<p>Our solution consists of three parts: (1) a gem that you use locally to update the list of gems you use in particular applications, (2) an online service (Rails application) where you can see the gems you use and (3) notification channels (i.e. email and twitter) through which news about gems is pushed to you. We named our solution &#8216;gemstreamer&#8217;, for it would stream information about gems to you as a user of these gems. For those of you who are interested to see what we actually made: you can see the &#8216;online service&#8217; Rails application that is used as the central &#8216;information hub&#8217; where information is gathered and distributed at <a href="http://github.com/ludo/rerr2009">http://github.com/ludo/rerr2009</a>. For the gem that you would use locally to push the gems you use to the central hub see <a href="http://github.com/michel/gemstreamer">http://github.com/michel/gemstreamer</a>. We deliberately kept the code as simple as possible and leveraged as many existing tools as possible to be able to quickly get things done. The end result is pretty simple, but the ideas behind it might actually be useful when extended and polished for real-life usage. This was also one of the comments from the jury, where they believed that something like this could make a great extension to <a href="http://gemcutter.org">http://gemcutter.org</a>.</p>
<h3>&#8230; At a Price</h3>
<p>Did we mention the stress? Apparently we were both not very satisfied with how we made progress. There was so much that we wanted to do, and so little time to do it all. This is probably the biggest flaw in how we approached the Rumble. Before the Rumble we had already discussed that it would be best to make something small that works instead of something big that does not work. This reasoning sounded really good before the Rumble and after the Rumble, but we actually forgot it during the Rumble&#8230; Still, we managed to get our main ideas implemented which we were able to present at the end of the day.</p>
<h2>Rumble Opponents</h2>
<p>With five pretty strong teams the competition was fierce. It was interesting to see that every team approached the assignment from a different angle. Where our end result can be seen as an interesting prototype, others had created something that could be of use to developers right away. Here is a short summary of what the other teams created:</p>
<ul>
<li>The Fingertips team created <a href="http://www.fngtps.com/2009/11/apprise">Apprise</a> for which they patched <a href="http://github.com/wycats/bundler">Bundler</a>. This patch to was applied to Bundler By Yehuda the very next day.</li>
<li>Iain Hecker and Marcel de Graaf built an extension to Webistrano that shows outdated gems, named &#8216;<a href="http://github.com/Thyraon/rer09">deproll</a>&#8216;.</li>
<li>The i76 team (Tom-Eric Gerritsen and Rik Tonnard) built a Rails plugin that you can hook-up in your application so that you can see the dependencies that your app uses through a web interface (<a href="http://github.com/i76/rrrer2009">http://github.com/i76/rrrer2009</a>).</li>
<li>Leon Berenschot and Klaas-Jan Wierenga gave a cool presentation and won the Twitter vote (<a href="http://github.com/LeipeLeon/Dev-Enter">http://github.com/LeipeLeon/Dev-Enter</a>).</li>
</ul>
<h2>Rumble Results</h2>
<p>Victory! Completely unexpected we were awarded the first prize: two tickets to <a title="RailsConf 2010 Homepage" href="http://en.oreilly.com/rails2010">RailsConf 2010</a> in Baltimore, MD. The winner was selected by a jury and through public voting via Twitter. In the Twitter vote we ended as third, which we thought was already a great achievement. But the professional jury had unanimously picked us! These two votes combined made us the overall winners of the Ruby en Rails Rumble 2009: awesome!</p>
<p>In hindsight we can conclude that our plan was a little too ambitious as it turned out that eight hours is really not that much. Nonetheless, the rumble turned out to be a great experience that was really fun doing. It was a crazy day with a lot of stress, but it was also an interesting experiment to see how we would do against some other very good teams. The end result turned out to be even better than what we&#8217;ve hoped for. We want to thank the jury for choosing us as well as the people who voted for us on Twitter. Last but not least many thanks to the people who made Ruby en Rails possible this year, we had a great time!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.kabisa.nl/2009/11/27/giving-love-to-the-community/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

