<?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</title>
	<atom:link href="http://blog.kabisa.nl/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.kabisa.nl</link>
	<description>The Ruby on Rails Experts</description>
	<lastBuildDate>Tue, 15 May 2012 14:43:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Een mooie elektrische ervaring!</title>
		<link>http://blog.kabisa.nl/2012/05/15/een-mooie-elektrische-ervaring/</link>
		<comments>http://blog.kabisa.nl/2012/05/15/een-mooie-elektrische-ervaring/#comments</comments>
		<pubDate>Tue, 15 May 2012 14:41:27 +0000</pubDate>
		<dc:creator>rosian</dc:creator>
				<category><![CDATA[Random]]></category>

		<guid isPermaLink="false">http://blog.kabisa.nl/?p=251</guid>
		<description><![CDATA[Wij, de medewerkers van Kabisa, mochten een maand lang rondrijden in de gekste elektrische voertuigen zoals de Twike, de e-scooter, de Floow, de e-bike, de PG Bike en een e-car. Na het invullen van de enquete over elektrisch rijden en energieverbruik was het dan zover; Frank Nienhaus van Stichting Limburg Elektrisch deelde de voertuigen uit [...]]]></description>
			<content:encoded><![CDATA[<p>Wij, de medewerkers van Kabisa, mochten een maand lang rondrijden in de gekste elektrische voertuigen zoals de Twike, de e-scooter, de Floow, de e-bike, de PG Bike en een e-car.</p>
<p>Na het invullen van de enquete over elektrisch rijden en energieverbruik was het dan zover; Frank Nienhaus van Stichting Limburg Elektrisch deelde de voertuigen uit onder het personeel.</p>
<p>Natuurlijk was het een dolle boel. We probeerden direct alles uit. Heel benieuwd was ik naar de Citroen C-zero. Hoe rijdt zo’n elektrische auto nou? Het leek net of ik over de weg zweefde, zo weinig geluid kwam er uit die auto.</p>
<p>Harm was verknocht aan de stoere PG Bike die wel 40 kilometer per uur ging. Maar zelfs de ‘gewone’ e-bike haalde een snelheid van 30 kilometer per uur gemakkelijk. Trots fietse ik alle top wielrenners voorbij zonder een druppel zweet op mijn voorhoofd.</p>
<p>Helaas zijn de prijzen van elektrische voertuigen nog erg hoog en kan de elektrische auto maar 100 kilometer rijden voordat hij weer aan de laadpaal moet. Toch vond ik het een mooie ervaring die veel enthousiaste reacties heeft opgeleverd. Dus bij deze: Kabisa en Stichting Limburg Elektrisch bedankt!</p>
<p>Groetjes,</p>
<p>Rosian Custers</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.kabisa.nl/2012/05/15/een-mooie-elektrische-ervaring/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Kabisa aan de stekker</title>
		<link>http://blog.kabisa.nl/2012/04/19/kabisa-aan-de-stekker/</link>
		<comments>http://blog.kabisa.nl/2012/04/19/kabisa-aan-de-stekker/#comments</comments>
		<pubDate>Thu, 19 Apr 2012 11:57:35 +0000</pubDate>
		<dc:creator>rosian</dc:creator>
				<category><![CDATA[Random]]></category>

		<guid isPermaLink="false">http://blog.kabisa.nl/?p=239</guid>
		<description><![CDATA[Kabisa ICT zet als eerste organisatie in de regio elektrische voertuigen in voor het personeel. Dit doet Kabisa in samenwerking met Stichting Limburg Elektrisch. Vier weken lang mogen medewerkers per elektrische auto, e-scooter of e-bike naar hun werk komen en hier ervaring mee opdoen.  De elektrische voertuigen zijn een stuk minder afhankelijk van fossiele brandstoffen [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-247" title="Even de Citroën C-Zero opladen" src="http://blog.kabisa.nl/wp-content/uploads/2012/04/2012-04-19-12.43.55.jpg" alt="" width="300" height="402" align="right" /><strong>Kabisa ICT zet als eerste organisatie in de regio elektrische voertuigen in voor het personeel. Dit doet Kabisa in samenwerking met Stichting Limburg Elektrisch. Vier weken lang mogen medewerkers per elektrische auto, e-scooter of e-bike naar hun werk komen en hier ervaring mee opdoen. </strong></p>
<p>De elektrische voertuigen zijn een stuk minder afhankelijk van fossiele brandstoffen en daarom een goede keuze als vervoersmiddel. Het zou goed zijn als meer bedrijven, net als Kabisa, het inzetten van elektrische voertuigen als serieus alternatief gaan zien. Dat zou de wereld een stuk schoner, gezonder en stiller maken. Medewerkers die na de proefperiode besluiten een elektrisch voertuig te kopen krijgen een aantrekkelijke korting. Daarnaast krijgen ze ook nog een jaar lang een bijdrage per kilometer.</p>
<p>Stichting Limburg Elektrisch wil met deze projecten het  gebruik van elektrische vervoersmiddelen promoten omdat dit beter is voor de gezondheid van de medewerkers en voor het milieu. Ook willen ze door middel van ervaringen meer kennis vergaren over de wensen en behoeften van de medewerkers.</p>
<p>Medewerker Joost Saanen van Kabisa probeert direct de Twike uit, een elektrisch voertuig op drie wielen. &#8220;Het voertuig ziet er leuk uit en het is ook nog eens milieubewust&#8221;, zegt Joost. Hij moet per dag 30 kilometer reizen voor naar zijn werk te komen. Dus dat tikt lekker aan bij de huidige brandstofprijzen. Of hij er ook gezonder van wordt nog blijken. &#8220;Ik zal eens wat vaker op de weegschaal gaan staan in de komende weken&#8221; vertelt hij lachend.</p>
<div></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.kabisa.nl/2012/04/19/kabisa-aan-de-stekker/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>kabisa</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>&#8220;No architectures to compile&#8221; in Xcode 4</title>
		<link>http://blog.kabisa.nl/2011/06/03/no-architectures-to-compile-in-xcode-4/</link>
		<comments>http://blog.kabisa.nl/2011/06/03/no-architectures-to-compile-in-xcode-4/#comments</comments>
		<pubDate>Fri, 03 Jun 2011 06:18:50 +0000</pubDate>
		<dc:creator>kabisa</dc:creator>
				<category><![CDATA[iOS]]></category>
		<category><![CDATA[ios]]></category>
		<category><![CDATA[xcode]]></category>

		<guid isPermaLink="false">http://blog.kabisa.nl/?p=206</guid>
		<description><![CDATA[XCode 4 has a new, improved project structure. But sometimes, when you open an older project format (like XCode 3) you&#8217;ll face a little challenge before you can get to coding again. After opening an Xcode 3 project in Xcode 4, we received the message: &#8220;No architectures to compile for (ARCHS=i386, VALID_ARCHS=armv6 armv7).&#8221; Since all [...]]]></description>
			<content:encoded><![CDATA[<p>XCode 4 has a new, improved project structure. But sometimes, when you open an older project format (like XCode 3) you&#8217;ll face a little challenge before you can get to coding again.</p>
<p><span id="more-206"></span></p>
<p>After opening an Xcode 3 project in Xcode 4, we received the message:</p>
<p><strong><em>&#8220;No architectures to compile for (ARCHS=i386, VALID_ARCHS=armv6 armv7).&#8221; </em></strong></p>
<p>Since all the architecture settings are configurable from the Build settings that was the first place to look. Strange enough, there were the settings that claimed to let the project build for the &#8220;armv6 armv7&#8243; architecture. So why didn&#8217;t this compile like it supposed to?</p>
<p>As it seems, Xcode 4 doesn&#8217;t always read these settings correct from the older project format. So here&#8217;s how we fixed this settings related issue:</p>
<ul>
<li>Remove both the <strong><em>armv6</em></strong> and <strong><em>armv7 </em></strong>items from the <strong><em>Valid Architectures </em></strong>build setting (for both the project AND the target)</li>
<li>Create a new value and set it to: <em><strong>$(ARCHS_STANDARD_32_BIT)</strong></em></li>
<li><span style="font-family: mceinline;">Clean the project builds and rebuild the project</span></li>
<li><span style="font-family: mceinline;">The project should build using the correct architecture setting</span></li>
</ul>
<p>Hopefully, this info will save you some time when coding on <em>ye olde Xcode 3 projects</em>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.kabisa.nl/2011/06/03/no-architectures-to-compile-in-xcode-4/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Xcode4: Attaching to MyApp</title>
		<link>http://blog.kabisa.nl/2011/05/24/xcode4-attaching-to-myapp/</link>
		<comments>http://blog.kabisa.nl/2011/05/24/xcode4-attaching-to-myapp/#comments</comments>
		<pubDate>Tue, 24 May 2011 08:27:21 +0000</pubDate>
		<dc:creator>Ariejan de Vroom</dc:creator>
				<category><![CDATA[iOS]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[ios]]></category>
		<category><![CDATA[xcode]]></category>

		<guid isPermaLink="false">http://blog.kabisa.nl/?p=195</guid>
		<description><![CDATA[Today I imported an iOS project, originally written in Xcode3 into Xcode4. I ran into an issue that prevented me from debugging the app both in the iOS Simulator and on my own iPhone 4. When hitting &#8216;Run&#8217;, all Xcode would do is show the message &#8220;Attaching to MyApp&#8221;. The simulator and my iPhone both [...]]]></description>
			<content:encoded><![CDATA[<p>Today I imported an iOS project, originally written in Xcode3 into Xcode4. I ran into an issue that prevented me from debugging the app both in the iOS Simulator and on my own iPhone 4. </p>
<p>When hitting &#8216;Run&#8217;, all Xcode would do is show the message &#8220;Attaching to MyApp&#8221;. The simulator and my iPhone both didn&#8217;t do anything, the app didn&#8217;t even get installed on the devices.<br />
<span id="more-195"></span><br />
The solution is quite simple. Xcode4 is a bit picky about the name of your project.</p>
<ul>
<li>Go to Project > Build Settings</li>
<li>Search for &#8220;Product name&#8221;</li>
</ul>
<p>Here you&#8217;ll find the names for the debug en release versions of your app. Now compare those the name of your project. Here&#8217;s what I found:</p>
<ul>
<li>Project name: <strong>myapp-iphone</strong></li>
<li>Product name: <strong>Multiple values</strong></li>
<li>Debug: <strong>MyApp-DEV</strong></li>
<li>Release: <strong>MyApp</strong></li>
</ul>
<p>The solution to the &#8220;Attaching to MyApp&#8221; problem is very easy. Simple update the &#8220;Product name&#8221; value to <code>$(TARGET_NAME)</code>. After that, clean your app by pressing <code>⇧⌘K</code>.</p>
<p>Now, when you press &#8216;Run&#8217;, your app should start as you&#8217;d expect.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.kabisa.nl/2011/05/24/xcode4-attaching-to-myapp/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Long running migrations? Use the right tool for the job!</title>
		<link>http://blog.kabisa.nl/2011/05/19/long-running-migrations-use-the-right-tool-for-the-job/</link>
		<comments>http://blog.kabisa.nl/2011/05/19/long-running-migrations-use-the-right-tool-for-the-job/#comments</comments>
		<pubDate>Thu, 19 May 2011 07:47:29 +0000</pubDate>
		<dc:creator>Ariejan de Vroom</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[activerecord]]></category>
		<category><![CDATA[migrations]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://blog.kabisa.nl/?p=187</guid>
		<description><![CDATA[Rails migrations are awesome, even for updating data after a migration to keep everything consistent. Arguably, you should not update data in migrations, but it is useful in some scenarios. If done incorrectly, however, data migrations can take a long time, causing unnecessary downtime of your application. The Problem Updating data can take a very [...]]]></description>
			<content:encoded><![CDATA[<p>Rails migrations are awesome, even for updating data after a migration to keep everything consistent. Arguably, you should not update data in migrations, but it is useful in some scenarios. If done incorrectly, however, data migrations can take a long time, causing unnecessary downtime of your application.<br />
<span id="more-187"></span></p>
<h2>The Problem</h2>
<p>Updating data can take a <em>very</em> long time, especially if done incorrectly. Consider the following example:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">Photo.<span style="color:#9900CC;">all</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>photo<span style="color:#006600; font-weight:bold;">|</span>
  photo.<span style="color:#9900CC;">update_attribute</span> <span style="color:#ff3333; font-weight:bold;">:order</span>, <span style="color:#006666;">999</span> <span style="color:#9966CC; font-weight:bold;">if</span> photo.<span style="color:#9900CC;">order</span>.<span style="color:#0000FF; font-weight:bold;">nil</span>?
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>This might look nice and all and work okay on your development machine. However, if you run this on your production database with 78k photos&#8230; </p>
<p>You guessed it, it takes for ever. What happens is that Rails will fetch all photos from the database and instantiate 78k Photo objects. Then for each object it will issue an update-query if necessary. </p>
<p>Running this took at least ten minutes or more. Bad!</p>
<h2>The Alternative</h2>
<p>There is, luckily, an alternative that is quite a bit faster.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">Photo.<span style="color:#9900CC;">update_all</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;`order` = 999&quot;</span>, <span style="color:#996600;">&quot;`order` IS NULL&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>This alternative issues exactly one update-query to the database and achieves the same end result as the previous code example. Also, this query took about 20 seconds to run!</p>
<p>You may want to look into http://apidock.com/rails/ActiveRecord/Base/update_all/class for more information about the <code>update_all</code> method.</p>
<h2>Conclusion</h2>
<p>Thinking about the code you put in your migrations, especially when manipulating data, is very important and will pay you back in less database downtime during deployments.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.kabisa.nl/2011/05/19/long-running-migrations-use-the-right-tool-for-the-job/feed/</wfw:commentRss>
		<slash:comments>4</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>4</slash:comments>
		</item>
		<item>
		<title>Handle CMYK colorspace uploads with Paperclip</title>
		<link>http://blog.kabisa.nl/2010/06/17/handle-cmyk-colorspace-uploads-with-paperclip/</link>
		<comments>http://blog.kabisa.nl/2010/06/17/handle-cmyk-colorspace-uploads-with-paperclip/#comments</comments>
		<pubDate>Thu, 17 Jun 2010 11:13:56 +0000</pubDate>
		<dc:creator>Ariejan de Vroom</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[CMYK]]></category>
		<category><![CDATA[paperclip]]></category>
		<category><![CDATA[RGB]]></category>

		<guid isPermaLink="false">http://blog.kabisa.nl/?p=148</guid>
		<description><![CDATA[When saving images in general, and JPEG in particular, a colorspace is used. The two most commonly used colorspaces are RGB and CMYK. RGB is used for screens (e.g. television, monitors, phones). Screens work by combining different light colors (red, green or blue) into one color we can actually see. CMYK is used in print [...]]]></description>
			<content:encoded><![CDATA[<p>When saving images in general, and JPEG in particular, a <em>colorspace</em> is used. The two most commonly used colorspaces are RGB and CMYK. </p>
<p>RGB is used for screens (e.g. television, monitors, phones). Screens work by combining different light colors (red, green or blue) into one color we can actually see. </p>
<p>CMYK is used in print often. Instead of sending out light, paper must reflect light to give it color. If you check your own printer you&#8217;ll see there are three colors: cyan, magenta and yellow. Again, these three colors can be combined to *absorb* colors, and thus reflect the color you want. </p>
<p>The problem is that not all web browsers are capable of handling JPEGs that use the CMYK colorspace. Internet Explorer is the most notorious one. Internet Explorer users will see an &#8216;image not found&#8217;-error &#8211; or red cross &#8211; instead.</p>
<p>If you&#8217;re using <a href="http://github.com/thoughtbot/paperclip">thoughtbot&#8217;s Paperclip</a>, the solution is easy.<br />
By adding some custom ImageMagick `convert` options you can make sure that all generated thumbnails are in the RGB colorspace.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">has_attached_file <span style="color:#ff3333; font-weight:bold;">:avatar</span></pre></div></div>

<p>would become:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">has_attached_file <span style="color:#ff3333; font-weight:bold;">:avatar</span> 
   <span style="color:#ff3333; font-weight:bold;">:convert_options</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:all</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'-strip -colorspace RGB'</span><span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>

<p>Easy right? </p>
<p>If you have a lot of CMYK images already, you don&#8217;t have to delete them, you can easily reprocess them when you made the above change:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">User.<span style="color:#9900CC;">find_each</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>user<span style="color:#006600; font-weight:bold;">|</span> user.<span style="color:#9900CC;">avatar</span>.<span style="color:#9900CC;">reprocess</span>! <span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.kabisa.nl/2010/06/17/handle-cmyk-colorspace-uploads-with-paperclip/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Headless Cucumbers and Capybaras with Selenium and Hudson</title>
		<link>http://blog.kabisa.nl/2010/05/24/headless-cucumbers-and-capybaras-with-selenium-and-hudson/</link>
		<comments>http://blog.kabisa.nl/2010/05/24/headless-cucumbers-and-capybaras-with-selenium-and-hudson/#comments</comments>
		<pubDate>Mon, 24 May 2010 18:01:14 +0000</pubDate>
		<dc:creator>Ludo van den Boom</dc:creator>
				<category><![CDATA[Continuous Integration]]></category>
		<category><![CDATA[capybara]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[hudson]]></category>

		<guid isPermaLink="false">http://blog.kabisa.nl/?p=94</guid>
		<description><![CDATA[Nowadays software engineers can&#8217;t live without their favorite test frameworks. But what a software engineer does not want is having to put a lot of effort in keeping these test run. Neither do teams of software engineers want to spent much time on making their test results visible to the entire team. More and more [...]]]></description>
			<content:encoded><![CDATA[<p>Nowadays software engineers can&#8217;t live without their favorite test frameworks. But what a software engineer does not want is having to put a lot of effort in keeping these test run. Neither do teams of software engineers want to spent much time on making their test results visible to the entire team.</p>
<p>More and more useful applications, libraries and plugins are appearing that take away some of the pain that is sometimes involved in making software tests useful for entire teams. Examples of excellent tools that we have at our disposal right now are <a href="http://hudson-ci.org/">Hudson</a> for continuous integration, <a href="http://cukes.info">Cucumber</a> for integration tests and <a href="http://seleniumhq.org/">Selenium</a> for automated testing of web applications in an actual browser. But making all these play together nicely involves more and more setting up of build servers and configuration.</p>
<p>Our goal is to document the steps required to overcome one of the hurdles that we kept running into, namely running our full Cucumber test suite including all Selenium scenarios on our Hudson integration server.</p>
<h2>Ingredients</h2>
<p>We&#8217;re going to use the following ingredients in this post:</p>
<ul>
<li>1 Debian 5.0.4 &#8216;Lenny&#8217; installation</li>
<li>1 installation of <a href="http://en.wikipedia.org/wiki/Xvfb">Xvfb</a></li>
<li>1 web browser (in our case <a href="http://www.geticeweasel.org/">iceweasel</a>, Firefox rebranded by Debian)</li>
<li>1 Ruby on Rails 2.3.7 application</li>
<li>1 Capybara 0.3.8 gem</li>
<li>As many Cucumbers (0.7.3) as necessary</li>
</ul>
<p>We won&#8217;t go into the details of creating a Rails application, installing the gems and writing the Cucumber scenarios here. Their manuals are perfect guides for this.</p>
<h2>Installing required packages</h2>
<p>We start with installing a couple of packages that allow us to run headless tests in a web browser.</p>
<h3>Virtual framebuffer with Xvfb</h3>
<blockquote><p><em>&#8220;In the X Window System, Xvfb or X virtual framebuffer is an X11 server that performs all graphical operations in memory, not showing any screen output.&#8221;</em> <small>Source: <a href="http://en.wikipedia.org/wiki/Xvfb">http://en.wikipedia.org/wiki/Xvfb</a></small></p></blockquote>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> xvfb</pre></div></div>

<h3>Web browser</h3>
<p>After installing Xvfb we can go ahead and install a web browser.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> iceweasel</pre></div></div>

<p>Before we continue we want to configure our browser profile so that it doesn&#8217;t whine about tabs being closed or not resuming correctly after it has crashed. If we don&#8217;t do this, our test suite might crash or run forever.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span>.mozilla<span style="color: #000000; font-weight: bold;">/</span>firefox<span style="color: #000000; font-weight: bold;">/</span>xxxxxxxx.default<span style="color: #000000; font-weight: bold;">/</span>
$ <span style="color: #c20cb9; font-weight: bold;">vim</span> user.js</pre></div></div>

<p>Now put the following two lines in the user.js file:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">user_pref(&quot;browser.sessionstore.enabled&quot;, false);
user_pref(&quot;browser.sessionstore.resume_from_crash&quot;, false);</pre></div></div>

<h3>Test Display</h3>
<p>Before we start running our tests we will ant to verify that all packages were installed successfully. To do so start a virtual framebuffer (an Xvfb session) on display 99 with screen 0:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ Xvfb :<span style="color: #000000;">99</span> <span style="color: #660033;">-ac</span> <span style="color: #660033;">-screen</span> <span style="color: #000000;">0</span> 1024x768x16</pre></div></div>

<p>In a different terminal window do:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #007800;">DISPLAY</span>=:<span style="color: #000000;">99.0</span> iceweasel http:<span style="color: #000000; font-weight: bold;">//</span>example.org</pre></div></div>

<p>This will start our web browser in the virtual framebuffer and open the example.com homepage in this browser. Next up is makinga &#8216;screenshot&#8217; so that we can see what is going on inside our virtual framebuffer.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ xwd <span style="color: #660033;">-root</span> <span style="color: #660033;">-display</span> :<span style="color: #000000;">99.0</span> <span style="color: #660033;">-out</span> xwdout</pre></div></div>

<p>And subsequently view the screenshot using:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ xwud <span style="color: #660033;">-in</span> xwdout</pre></div></div>

<p>Do you see the example.org homepage? Then Xvfb and iceweasel were installed successfully and we are now ready to do some testing.</p>
<div id="attachment_125" class="wp-caption aligncenter" style="width: 538px"><a href="http://blog.kabisa.nl/wp-content/uploads/2010/05/xwud.jpg"><img class="size-full wp-image-125" title="Iceweasel in Xvfb" src="http://blog.kabisa.nl/wp-content/uploads/2010/05/xwud.jpg" alt="Iceweasel in Xvfb" width="528" height="411" /></a><p class="wp-caption-text">Iceweasel in Xvfb</p></div>
<h2>Running cucumbers</h2>
<p>Before we integrate this setup into our continuous integration environment we do a test run to see if the cucumbers work with our new configuration. We can do this using the following command, keep in mind that we have to explicitly tell the cucumbers to use our virtual framebuffer display:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #007800;">DISPLAY</span>=:<span style="color: #000000;">99.0</span> rake cucumber</pre></div></div>

<p>If all goes well then we will see that all scenarios passed. If not all scenarios pass first check if they do run on in a non-headless situation.</p>
<h2>Configuring Hudson</h2>
<p>Now we have come to the point where we can tie all strings together. We need to add a new build step to the job that needs to run headless cucumbers. But, before adding this build step, we will create a start/stop script for our virtual framebuffer. This script can be used to start a buffer before running the scenarios, and stop the buffer after the scenarios completed. You can save this script to /etc/init.d. Make sure that the permissions are set so that the user that runs Hudson can execute it.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">XVFB</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>Xvfb
<span style="color: #007800;">XVFBARGS</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$DISPLAY</span> -ac -screen 0 1024x768x16&quot;</span>
<span style="color: #007800;">PIDFILE</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>hudson<span style="color: #000000; font-weight: bold;">/</span>xvfb_<span style="color: #800000;">${DISPLAY:1}</span>.pid
<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">in</span>
  start<span style="color: #7a0874; font-weight: bold;">&#41;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Starting virtual X frame buffer: Xvfb&quot;</span>
    <span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>start-stop-daemon <span style="color: #660033;">--start</span> <span style="color: #660033;">--quiet</span> <span style="color: #660033;">--pidfile</span> <span style="color: #007800;">$PIDFILE</span> <span style="color: #660033;">--make-pidfile</span> <span style="color: #660033;">--background</span> <span style="color: #660033;">--exec</span> <span style="color: #007800;">$XVFB</span> <span style="color: #660033;">--</span> <span style="color: #007800;">$XVFBARGS</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;.&quot;</span>
    <span style="color: #000000; font-weight: bold;">;;</span>
  stop<span style="color: #7a0874; font-weight: bold;">&#41;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Stopping virtual X frame buffer: Xvfb&quot;</span>
    <span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>start-stop-daemon <span style="color: #660033;">--stop</span> <span style="color: #660033;">--quiet</span> <span style="color: #660033;">--pidfile</span> <span style="color: #007800;">$PIDFILE</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;.&quot;</span>
    <span style="color: #000000; font-weight: bold;">;;</span>
  restart<span style="color: #7a0874; font-weight: bold;">&#41;</span>
    <span style="color: #007800;">$0</span> stop
    <span style="color: #007800;">$0</span> start
    <span style="color: #000000; font-weight: bold;">;;</span>
  <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Usage: /etc/init.d/xvfb {start|stop|restart}&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">esac</span>
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span></pre></div></div>

<p><small>Source: <a href="http://marc.info/?l=tomcat-user&#038;m=102335321103262&#038;w=2">http://marc.info/?l=tomcat-user&#038;m=102335321103262&#038;w=2</a></small></p>
<p>Final step is to add an &#8216;Execute shell&#8217; build script to our Hudson job. You can use the following set of commands to run your cucumbers.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">DISPLAY</span>=:<span style="color: #000000;">99</span>
<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>xvfb start
rake cucumber
<span style="color: #007800;">RESULT</span>=<span style="color: #007800;">$?</span>
<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>xvfb stop
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$RESULT</span></pre></div></div>

<p>After adding this build step we save our job and let Hudson build it. If all goes well the cucumber scenarios should now be running as part of our continuous integration process. You can check the &#8216;Console output&#8217; page of a Build in Hudson for hints when it didn&#8217;t run successfully.</p>
<h2>Conclusion</h2>
<p>If you have followed along with this post then you should have a working, headless setup by now. The advantage of this setup is that it is pretty light-weight and easy to setup. But this setup is not suited for you if you need to test across multiple browsers on different browsers. For such a setup you will want to have a look at virtual machines and Hudson slave agents.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.kabisa.nl/2010/05/24/headless-cucumbers-and-capybaras-with-selenium-and-hudson/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

