<?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>casperfabricius.com &#187; rails</title>
	<atom:link href="http://casperfabricius.com/site/category/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://casperfabricius.com/site</link>
	<description>expert ruby on rails development</description>
	<lastBuildDate>Sun, 06 Jun 2010 08:43:31 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Delayed Job with i18n</title>
		<link>http://casperfabricius.com/site/2010/06/06/delayed-job-with-i18n/</link>
		<comments>http://casperfabricius.com/site/2010/06/06/delayed-job-with-i18n/#comments</comments>
		<pubDate>Sun, 06 Jun 2010 08:43:31 +0000</pubDate>
		<dc:creator>Casper Fabricius</dc:creator>
				<category><![CDATA[rails]]></category>

	<!-- AutoMeta Start -->
	<category>locale</category>
	<category>delayed</category>
	<category>usermailer</category>
	<category>message</category>
	<category>send_later_with_i18n</category>
	<category>send_later</category>
	<category>recipient</category>
	<category>darebusters</category>
	<!-- AutoMeta End -->
	
		<guid isPermaLink="false">http://casperfabricius.com/site/?p=325</guid>
		<description><![CDATA[I have darebusters.com running on Heroku and I have a worker running Delayed Job (DJ) activated. This allows me to handle heavy tasks such as video processing and payment transactions asynchronously, so the dynos can get right back to serving requests.
I also use DJ to send out emails, and a typical asynchronous call sending a [...]]]></description>
			<content:encoded><![CDATA[<p>I have <a href="http://darebusters.com/">darebusters.com</a> running on <a href="http://heroku.com/">Heroku</a> and I have a worker running <a href="http://github.com/tobi/delayed_job">Delayed Job</a> (DJ) activated. This allows me to handle heavy tasks such as video processing and payment transactions asynchronously, so the dynos can get right back to serving requests.</p>
<p>I also use DJ to send out emails, and a typical asynchronous call sending a message from one user to another &#8211; scheduling a delayed job &#8211; used to look like this:</p>
<pre><code>UserMailer.send_later(
  :deliver_message,
   @recipient,
  current_user,
  params[:message]
)
</code></pre>
<p>Since darebusters.com is an internationalized website currently offering users the choice between English and German, this has proved a slight challenge, however. We have the usual internationalization (i18n) bells and whistles: Flags to select the language, and remembering the user&#8217;s language selection in session, cookie and in the users database table. By default, a delayed job will simply run with the default locale of the site. It has no way of accessing the context it was invoked in, so it cannot set the locale from session or cookie. The job only knows what it can work it from the arguments it was created with.</p>
<p><span id="more-325"></span></p>
<p>It looks like an easy problem to solve. DJ shouldn&#8217;t have to know about locales, the code should just set <code>I18n.locale</code> from <code>@recipient.locale</code>. That&#8217;s exactly how I initially thought I had solved it: In the <code>UserMailer.message</code> method I set the locale, and then passed parameters to render the mail. The catch is, however, that I use <a href="http://blog.andischacke.com/2009/10/localized-actionmailer-templates-for.html">a slight hack</a> to get support for localized ActionMailer templates, i.e. when the locale is set to <code>de</code> it will render the <code>message.de.text.plain.erb</code> view rather than the <code>message.en.text.plain.erb</code> view. The template to render is selected <i>before</i> <code>UserMailer.message</code> is invoked, so at that time it&#8217;s too late to set the correct locale. In fact, I needed the entire job to run in a locale specified when the job as scheduled.</p>
<p>For this purpose, I created a custom delayed method to be invoked by DJ: LocalizedJob.</p>
<p><script src="http://gist.github.com/427425.js?file=localized_job.rb"></script></p>
<p>This code should be placed in <code>/lib/</code>. I want the <code>send_later_with_i18n</code> to be available on all objects just like DJ&#8217;s own <code>send_later</code>, so I also also created an initializer to extend the <code>Object</code> class:</p>
<p><script src="http://gist.github.com/427428.js?file=delayed_job.rb"></script></p>
<p>This code should be placed in <code>/config/initializers/</code>. I am now able to replace all my <code>send_later</code> calls with <code>send_later_with_i18n</code> calls, storing the required locale with job to be extracted when it&#8217;s run:</p>
<pre><code>UserMailer.send_later_with_i18n(
  :deliver_message,
  @recipient.locale,
  @recipient,
  current_user,
  params[:message]
)
</code></pre>
<p>So on darebusters.com, Germans get all their mails in German &#8211; no matter what locale the sender used (although the actual message written by the sender is of course not translated ;) &#8211; and everyone else gets mails in English. Now that was a real Ruby fairytale.</p>
]]></content:encoded>
			<wfw:commentRss>http://casperfabricius.com/site/2010/06/06/delayed-job-with-i18n/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bundler and Rails 3 environments</title>
		<link>http://casperfabricius.com/site/2010/04/17/bundler-and-rails-3-environments/</link>
		<comments>http://casperfabricius.com/site/2010/04/17/bundler-and-rails-3-environments/#comments</comments>
		<pubDate>Sat, 17 Apr 2010 13:50:44 +0000</pubDate>
		<dc:creator>Casper Fabricius</dc:creator>
				<category><![CDATA[deployment]]></category>
		<category><![CDATA[rails]]></category>

	<!-- AutoMeta Start -->
	<category>bundler</category>
	<category>bundler</category>
	<category>environments</category>
	<category>gem</category>
	<category>debug</category>
	<category>debug</category>
	<category>beta</category>
	<category>gems</category>
	<!-- AutoMeta End -->
	
		<guid isPermaLink="false">http://casperfabricius.com/site/?p=312</guid>
		<description><![CDATA[I usually write very long blog posts. Not this time! This is just a small tip, the first of hopefully many learnings I&#8217;ll make as I am working with my first project in Rails 3.
Bundler (Github &#124; Website) is the new way to manage gem dependencies in Rails and other Ruby applications. If you haven&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>I usually write very long blog posts. Not this time! This is just a small tip, the first of hopefully many learnings I&#8217;ll make as I am working with my first project in Rails 3.</p>
<p>Bundler (<a href="http://github.com/carlhuda/bundler">Github</a> | <a href="http://gembundler.com">Website</a>) is the new way to manage gem dependencies in Rails and other Ruby applications. If you haven&#8217;t heard about it, there is (of course) a <a href="http://railscasts.com/episodes/201-bundler">great introduction at Railcasts</a>. It&#8217;s pretty easy and straight-forward to use, especially if you are used to the <code>config.gem</code> format of Rails.</p>
<p>However, one very common use case in Bundler&#8217;s <code>Gemfile</code> that is not explicitly documented anywhere I&#8217;ve seen, is how to configure gems to be installed in <i>both development and test environments, but not in staging and production environments</i>. You have probably seen the examples of how you can assign a gem to a specific environment using the <code>:group</code> option or method. So you&#8217;d probably write something like this:</p>
<pre>
group :test do
  gem "rspec-rails", ">= 2.0.0.beta.1"
end

group :development do
  gem "ruby-debug"
end
</pre>
<p><span id="more-312"></span></p>
<p>The gems you don&#8217;t need on the server are usually all those related to testing, debugging and perhaps generating fake data and so on. But wait a minute. You also need the RSpec in the development environment so you can use it&#8217;s generators, right? And you need Ruby Debug in the test environment so you can put breakpoints in your tests.</p>
<p>Luckily there is a very easy, and &#8211; once you know it &#8211; obvious solution to this: You can pass multiple environments to the </code>group</code> method, just like this:</p>
<pre>
group :development, :test do
  gem "rspec-rails", ">= 2.0.0.beta.1"
  gem "ruby-debug"
end
</pre>
<p>And that's probably the only grouping of gems you'll need in many Rails projects. Most gems installed and required in all environments, and a few just in the development and test environments. Happy Rails 3 coding.</p>
]]></content:encoded>
			<wfw:commentRss>http://casperfabricius.com/site/2010/04/17/bundler-and-rails-3-environments/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Community Day &#8216;10 is coming up</title>
		<link>http://casperfabricius.com/site/2010/02/19/community-day-10-is-coming-up/</link>
		<comments>http://casperfabricius.com/site/2010/02/19/community-day-10-is-coming-up/#comments</comments>
		<pubDate>Fri, 19 Feb 2010 21:59:17 +0000</pubDate>
		<dc:creator>Casper Fabricius</dc:creator>
		<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/cfp/casperfabricius.com/site/wp-content/plugins/autometa/autometa.php</b> on line <b>324</b><br />
		<category><![CDATA[ironruby]]></category>
		<category><![CDATA[rails]]></category>

	<!-- AutoMeta Start -->
	<!-- AutoMeta End -->
	
		<guid isPermaLink="false">http://casperfabricius.com/site/?p=282</guid>
		<description><![CDATA[I did a well-received talk on ActiveRecord at last year&#8217;s Community Day. Community Day &#8216;09 was the first of its kind in Copenhagen, and it was quite successful in bringing developers with different technical backgrounds together as well as attracting students &#8211; probably because of the free beer :)
Community Day in Copenhagen is back again [...]]]></description>
			<content:encoded><![CDATA[<p>I did a well-received talk on ActiveRecord at <a href="http://casperfabricius.com/site/2009/05/31/community-day-2009-in-copenhagen/">last year&#8217;s Community Day</a>. Community Day &#8216;09 was the first of its kind in Copenhagen, and it was quite successful in bringing developers with different technical backgrounds together as well as attracting students &#8211; probably because of the free beer :)</p>
<p><a href="http://communityday.in/copenhagen/">Community Day in Copenhagen</a> is back again this year, so reserve May 27 if you are near Copenhagen and like free tech-talks, networking and beer. This year <a href="http://danielfrost.dk/">Daniel Frost</a>, the Microsoft evangelist that makes it happen, has involved me and several other developers actively in the planning of the day. With CD &#8216;10 we have raised the level of ambition &#8211; bigger venue, more people, more talks and if course more fun.</p>
<p>We will have <a href="http://communityday.in/copenhagen/Home/Agenda">20 sessions</a> distributed on four concurrent tracks covering a surprisingly wide number of topics &#8211; very few of the talks are on Microsoft-technologies, in fact so few that we might loose a few of those .NET consultants who thinks anything non-MS are not worth listening to ;) Still, if you are doing anything at all related to the web (and most of us are, right?) you will surely find topics such as HTML 5, Single Sign On, Azure, Advanced jQuery etc. interesting.</p>
<p><span id="more-282"></span></p>
<p>I will be giving a talk with the rather bold title &#8220;Replace ASP.NET with IronRuby on Rails&#8221;. It will give me an excuse to seriously dive into IronRuby and how to make a Rails site talk fluently with .NET libraries and assemblies. Coming from a serious amount of ASP.NET development myself, I really think a lot of web-based .NET projects could benefit from Ruby on Rails. The only time I was really happy with ASP.NET was when I switched to that from classic ASP &#8211; but since then, it hasn&#8217;t evolved that much. Granted, ASP.NET MVC has rescued developers from the annyoing &#8220;webform&#8221; structure, but it still has a long way to go.</p>
<p>I&#8217;m getting ahead of myself here, come watch the session &#8211; <a href="http://cd10.eventbrite.com">sign up for Community Day &#8216;10 now</a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://casperfabricius.com/site/2010/02/19/community-day-10-is-coming-up/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Multiple Ruby versions with RVM</title>
		<link>http://casperfabricius.com/site/2010/01/24/multiple-ruby-versions-with-rvm/</link>
		<comments>http://casperfabricius.com/site/2010/01/24/multiple-ruby-versions-with-rvm/#comments</comments>
		<pubDate>Sun, 24 Jan 2010 11:47:47 +0000</pubDate>
		<dc:creator>Casper Fabricius</dc:creator>
		<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/cfp/casperfabricius.com/site/wp-content/plugins/autometa/autometa.php</b> on line <b>324</b><br />
		<category><![CDATA[rails]]></category>

	<!-- AutoMeta Start -->
	<!-- AutoMeta End -->
	
		<guid isPermaLink="false">http://casperfabricius.com/site/?p=276</guid>
		<description><![CDATA[Rails 3 is just around the corner. It is optimized for the better performance and superior features of Ruby 1.9, but it also plays nicely with version 1.8.7. Ruby 1.8.6, on the other hand, cannot run Rails 3. This might not be a problem for you at all. If you are on a Mac, you [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://github.com/rails/rails/">Rails 3</a> is just around the corner. It is optimized for the better performance and superior features of Ruby 1.9, but it also plays nicely with version 1.8.7. Ruby 1.8.6, on the other hand, cannot run Rails 3. This might not be a problem for you at all. If you are on a Mac, you were probably faced with Ruby 1.8.7 last year at the latest, when the upgrade to Snow Leopard changed the built-in Ruby version from 1.8.6 to 1.8.7. Most applications built for 1.8.6 runs fine on 1.8.7 &#8211; but many servers and deployment environments still runs only 1.8.6.</p>
<p>For me, the situation is like this: My standard version of Ruby on my development machine is 1.8.7. I deploy to many different environments, some (the ones I have a degree of control over) runs 1.8.7 and others (such as Heroku and some customer&#8217;s servers) runs 1.8.6. I can test and code away happily only to get some ugly exceptions when I deploy because I have called <code>count</code> on an array instead of <code>length</code>. Further, I also want to play with the new features of Ruby 1.9 and run Rails 3 on it. And that&#8217;s not to mention that I also use alternative Ruby implementations such as JRuby for projects where I need to tap into Java libraries.</p>
<p><span id="more-276"></span></p>
<p>So that&#8217;s at least four different versions and implementations of Ruby I want to use at various times. I need to compile gems separately for each of them, and I don&#8217;t want them to clutter up my default and very functional Ruby 1.8.7 installation which I still use most of the time. </p>
<p><a href="http://rvm.beginrescueend.com/">Ruby Version Manager</a> (rvm) to the rescue! This very welcome open source project allows us to easily install, manage and switch between multiple Ruby versions and implementations with a single command. The software itself is also easy to install:</p>
<pre><code>
sudo gem install rvm
rvm-install
</code></pre>
<p>Once you have followed the instructions and pasted the line of script into the correct file and restarted (or sourced) your shell, I recommend that you upgrade to the edge version of rvm by running this command:</p>
<pre><code>
rvm update --head
</code></pre>
<p>This gives you access to the newest versions of the installation scripts, and that is needed if you for instance want to install JRuby:</p>
<pre><code>
rvm install jruby
rvm jruby
</code></pre>
<p>That second line is all you need to switch between ruby implementations &#8211; here we switch to JRuby. Note that this is <i>not</i> a system-wide change &#8211; the switch is done simply by changing a few environment variables in your current shell so <code>ruby</code>, <code>rake</code> and so on now refers to the JRuby versions.</p>
<p>One gotcha is that gem will installed the wrong place if you have the <code>—user-install</code> flag in your <code>.gemrc</code> file. The only current resolution I know is to remove the flag.</p>
<p>Never the less, I will highly recommend that you install Ruby Version Manager and play with different Ruby version and implementations &#8211; it has never been easier.</p>
]]></content:encoded>
			<wfw:commentRss>http://casperfabricius.com/site/2010/01/24/multiple-ruby-versions-with-rvm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Happy New Year</title>
		<link>http://casperfabricius.com/site/2010/01/01/happy-new-year-2/</link>
		<comments>http://casperfabricius.com/site/2010/01/01/happy-new-year-2/#comments</comments>
		<pubDate>Fri, 01 Jan 2010 15:14:26 +0000</pubDate>
		<dc:creator>Casper Fabricius</dc:creator>
		<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/cfp/casperfabricius.com/site/wp-content/plugins/autometa/autometa.php</b> on line <b>324</b><br />
		<category><![CDATA[rails]]></category>

	<!-- AutoMeta Start -->
	<!-- AutoMeta End -->
	
		<guid isPermaLink="false">http://casperfabricius.com/site/?p=270</guid>
		<description><![CDATA[
Enjoy the new decade &#8211; take care of our world.
]]></description>
			<content:encoded><![CDATA[<p><object width="400" height="225"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=8456985&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=8456985&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="225"></embed></object></p>
<p>Enjoy the new decade &#8211; take care of our world.</p>
]]></content:encoded>
			<wfw:commentRss>http://casperfabricius.com/site/2010/01/01/happy-new-year-2/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Introducing darebusters.com</title>
		<link>http://casperfabricius.com/site/2009/12/28/introducing-darebusters/</link>
		<comments>http://casperfabricius.com/site/2009/12/28/introducing-darebusters/#comments</comments>
		<pubDate>Mon, 28 Dec 2009 12:24:21 +0000</pubDate>
		<dc:creator>Casper Fabricius</dc:creator>
		<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/cfp/casperfabricius.com/site/wp-content/plugins/autometa/autometa.php</b> on line <b>324</b><br />
		<category><![CDATA[rails]]></category>

	<!-- AutoMeta Start -->
	<!-- AutoMeta End -->
	
		<guid isPermaLink="false">http://casperfabricius.com/site/?p=265</guid>
		<description><![CDATA[Most of us enjoy getting a link to something entertaining once in a while. In the early days of the World Wide Web, we send each other funny pictures via emails &#8211; today, we share our favorite videos via Twitter, Facebook and other social media. Most of these are so called &#8220;user-generated content&#8221; &#8211; that [...]]]></description>
			<content:encoded><![CDATA[<p>Most of us enjoy getting a link to something entertaining once in a while. In the early days of the World Wide Web, we send each other funny pictures via emails &#8211; today, we share our favorite videos via Twitter, Facebook and other social media. Most of these are so called &#8220;user-generated content&#8221; &#8211; that is; videos made by you and me for our own amusement and to get some feedback from other people. Many videos are &#8211; to put it nicely &#8211; mediocre, but the ones that spread and go viral are usually really good. Not because they necessarily feature great talent or professionalism, but simply because they are so damn entertaining.</p>
<p>For some reason &#8211; and I am sure people with a bit more insight into the human psyche than me can tell you exactly why &#8211; videos where people do something really stupid, disgusting, dangerous or daring are amongst the most popular. But what reward do the people who makes these videos get for their hard work? A lot of views and comments on Youtube? That&#8217;s nice, sure, but couldn&#8217;t we get something even better if the makers actually earned some money on entertaining the rest of us?</p>
<p><span id="more-265"></span></p>
<p><a href="http://darebusters.com">darebusters.com</a> is where this is happening right now. We have created a platform where people who wants to show how truly talented or crazy they are rewarded for their hard work in cash &#8211; we call them darebusters. darebusters.com is not the next Youtube or Vimeo &#8211; rather, it is intended to be a sprouting community of people with crazy ideas for dares, people willing to sponsor those dares on video and &#8211; of course &#8211; the darebusters making it all happen.</p>
<p>Here is how it works: A darebuster uploads a teaser video where he explains what kind of dare he has in mind &#8211; or a user suggests a dare for somebody else to complete. Either way, the dare now has a certain time period to collect the required amount of money through micropayments from other users who thinks that idea is cool enough to support. When the amount is reached, the darebuster must now complete the dare and the ratings the completion video receives decides how much money the he gets out of it.</p>
<p>The business model for darebusters.com is simple &#8211; there is no subscription fee or price tag for watching specific videos. Rather, users are required to sponsor a dare at least every two weeks to continually have access to all completion videos. This way, the users decides which dares are really worth making and a higher quality of entertainment is reached.</p>
<p>I am a founding partner of darebusters.com and I have developed the entire site in Ruby on Rails during the last couple of months (well, except for the fantastic graphical design). We are currently testing the site in a closed beta, but if you signup for a beta invitation or contact me, we will let you in to play around with it: <a href="http://darebusters.com">darebusters.com</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://casperfabricius.com/site/2009/12/28/introducing-darebusters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get a copy of all outgoing ActionMailer emails</title>
		<link>http://casperfabricius.com/site/2009/11/06/get-a-copy-of-all-outgoing-actionmailer-emails/</link>
		<comments>http://casperfabricius.com/site/2009/11/06/get-a-copy-of-all-outgoing-actionmailer-emails/#comments</comments>
		<pubDate>Fri, 06 Nov 2009 17:21:38 +0000</pubDate>
		<dc:creator>Casper Fabricius</dc:creator>
		<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/cfp/casperfabricius.com/site/wp-content/plugins/autometa/autometa.php</b> on line <b>324</b><br />
		<category><![CDATA[rails]]></category>

	<!-- AutoMeta Start -->
	<!-- AutoMeta End -->
	
		<guid isPermaLink="false">http://casperfabricius.com/site/?p=259</guid>
		<description><![CDATA[People care about emails. They don&#8217;t like to be bothered with emails they find unimportant, especially not if they are sent by mistake, have the wrong content or looks weird.
Many of the applications we build send out a lot of emails, and for some, it is a critical part of the system. Lokalebasen is such [...]]]></description>
			<content:encoded><![CDATA[<p>People care about emails. They don&#8217;t like to be bothered with emails they find unimportant, especially not if they are sent by mistake, have the wrong content or looks weird.</p>
<p>Many of the applications we build send out a lot of emails, and for some, it is a critical part of the system. <a href="http://www.lokalebasen.dk/">Lokalebasen</a> is such an application, and the people behind wanted to monitor all outgoing mail, whether generated by a page request, a cron job, an administrator or anything else.</p>
<p>I built a clever little monkey-patch for the Ruby on Rails ActionMailer that makes sure that all outgoing emails has a certain email address put on BCC. This is not visible to the recipient, but it allows you to keep an archive of all outgoing mail, which is certainly useful &#8211; especially for support and bug-tracking.</p>
<p><span id="more-259"></span></p>
<p>Drop this into your lib-folder (remember to change the email address):</p>
<p><script src="http://gist.github.com/227365.js"></script></p>
<p>- and be sure to enable it by adding this line to environment/production.rb (you probably don&#8217;t want to BCC mails sent in development and test mode):</p>
<p><code>
<pre>ActionMailer::Base.send(:include, BccAllMails)</pre>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://casperfabricius.com/site/2009/11/06/get-a-copy-of-all-outgoing-actionmailer-emails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hosting a Spree webshop on Heroku</title>
		<link>http://casperfabricius.com/site/2009/10/18/hosting-a-spree-webshop-on-heroku/</link>
		<comments>http://casperfabricius.com/site/2009/10/18/hosting-a-spree-webshop-on-heroku/#comments</comments>
		<pubDate>Sun, 18 Oct 2009 13:09:46 +0000</pubDate>
		<dc:creator>Casper Fabricius</dc:creator>
		<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/cfp/casperfabricius.com/site/wp-content/plugins/autometa/autometa.php</b> on line <b>324</b><br />
		<category><![CDATA[deployment]]></category>
		<category><![CDATA[rails]]></category>

	<!-- AutoMeta Start -->
	<!-- AutoMeta End -->
	
		<guid isPermaLink="false">http://casperfabricius.com/site/?p=246</guid>
		<description><![CDATA[Spree is the webshop solution for Ruby on Rails, and Heroku is the place to host your Rails-applications &#8211; especially if you like free hosting :)
Finding myself in the need of a webshop, I decided to try to deploy Spree to Heroku. It wasn&#8217;t too hard, but it did take a few tricks to get [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://spreecommerce.com/">Spree</a> is <em>the</em> webshop solution for <a href="http://www.rubyonrails.com/">Ruby on Rails</a>, and <a href="http://heroku.com/">Heroku</a> is <em>the</em> place to host your Rails-applications &#8211; especially if you like free hosting :)</p>
<p>Finding myself in the need of a webshop, I decided to try to deploy Spree to Heroku. It wasn&#8217;t too hard, but it did take a few tricks to get Spree running on a server that doesn&#8217;t allow you to write to the file system.</p>
<p>I can&#8217;t say I have too much hands-on experience with Spree yet, but it seems to be have borrowed its extension concept from <a href="http://radiantcms.org/">Radiant CMS</a>, which happens to be one of my areas of expertise. So I put together an <a href="http://github.com/RSpace/spree-heroku/">extension</a> for Spree that will easily allow you to deploy the e-commerce system to Heroku.</p>
<p>Just follow the instructions in the <a href="http://github.com/RSpace/spree-heroku/">README on Github</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://casperfabricius.com/site/2009/10/18/hosting-a-spree-webshop-on-heroku/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Manage and rollback Heroku deployments Capistrano-style</title>
		<link>http://casperfabricius.com/site/2009/09/20/manage-and-rollback-heroku-deployments-capistrano-style/</link>
		<comments>http://casperfabricius.com/site/2009/09/20/manage-and-rollback-heroku-deployments-capistrano-style/#comments</comments>
		<pubDate>Sun, 20 Sep 2009 14:36:17 +0000</pubDate>
		<dc:creator>Casper Fabricius</dc:creator>
		<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/cfp/casperfabricius.com/site/wp-content/plugins/autometa/autometa.php</b> on line <b>324</b><br />
		<category><![CDATA[deployment]]></category>
		<category><![CDATA[rails]]></category>

	<!-- AutoMeta Start -->
	<!-- AutoMeta End -->
	
		<guid isPermaLink="false">http://casperfabricius.com/site/?p=241</guid>
		<description><![CDATA[If you are a Rails-developer, and you don&#8217;t know about Heroku, now would definitely be a good time. Heroku is a platform for hosting web-based Ruby applications in &#8220;the cloud&#8221;, in this case Amazon EC2, making you able to scale your application in an effortless and cost-effective manner without worrying about the hardware behind. Heroku [...]]]></description>
			<content:encoded><![CDATA[<p>If you are a Rails-developer, and you don&#8217;t know about <a href="http://heroku.com/">Heroku</a>, now would definitely be a good time. Heroku is a platform for hosting web-based Ruby applications in &#8220;the cloud&#8221;, in this case <a href="http://aws.amazon.com/ec2/">Amazon EC2</a>, making you able to scale your application in an effortless and cost-effective manner without worrying about the hardware behind. Heroku differs from competition by offering by far the fastest and easiest way to deploy your Rails-application. You simply create your application from Heroku&#8217;s web interface or using their API, and then push your git-repository to Heroku&#8217;s git-server. Heroku takes care of the rest, and you can get back to coding.</p>
<p>I use Heroku for <a href="http://darebusters.com>My Big Secret Project</a> (now not so secret anymore ;), and I am quite happy with not just the ease of deployment it offers, but in fact also with the choices and the constraints that the platform imposes on me. I like writing <code>git push heroku</code> and see my code live immediately. This is of course not that different from <a href="http://www.capify.org/">Capistrano</a>, once that has been setup with the right recipes and the server has been setup to corporate and serve our web application properly. But that can also take some time, especially on a brand new server.</p>
<p><span id="more-241"></span></p>
<p>I did miss one important feature of Capistrano when I started using Heroku: Rollback. Writing <code>cap deploy:rollback</code> has saved my behind many, many times. Granted, it has often been because of bad server configuration which shouldn&#8217;t happen with Heroku, but there has also been cases of genuine bugs resulting in all pages returning errors. When we do mess up, it is really nice to have the application back up in a matter of seconds, and then being able to take you to fix the error &#8211; perhaps even do the right thing and write a failing test for that particular bug before you fix the error.</p>
<p>With Heroku you don&#8217;t get rollback per se, as the application always displays the <code>HEAD</code> version of the <code>master</code> branch in the git repository on Heroku&#8217;s servers. However, with git we have the ability to roll back to the state of every single commit ever done. It&#8217;s just not very convenient having to figure out which commit was your last one working, especially not in a situation where your application is down. Also, we need this to be automated like everything else.</p>
<p>The solution I came up with was to tag each release with a timestamp &#8211; just like Capistrano names its release directories. This gives me a series of tags that should all point to successful deployments, and when my hour of distress arise, I can simply tell the <code>master</code> branch on Heroku to point to the previous release. If I further delete the tag of my current release, I have effectively rolled back to my previous release, and hopefully my application is now up and running again.</p>
<p><script src="http://gist.github.com/307479.js"></script></p>
<p>If you want this functionality in your Heroku application, just copy the above code into a <code>.rake</code> in your <code>lib</code> directory. You deploy your application with this command <code>rake deploy</code> and roll back with <code>rake rollback</code>.</p>
<p>Please note that the script also runs migrations on each deploy, but feel free to delete that line. Suggestions and improvements are very welcome. Enjoy.</p>
<p><strong>Update:</strong> Nicola Junior Vitto pointed out that my rollback code was not working correctly, and managed to fix it. <a href="http://gist.github.com/362873">His fork</a> of the deployment script also features support for both a production and a staging environment &#8211; I&#8217;ve updated mine so rollback work, but kept it more simple without support for multiple environments.</p>
]]></content:encoded>
			<wfw:commentRss>http://casperfabricius.com/site/2009/09/20/manage-and-rollback-heroku-deployments-capistrano-style/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Test-driven Rails development with RSpec, RR, Shoulda, Factory Girl and Stubble</title>
		<link>http://casperfabricius.com/site/2009/07/25/test-driven-rails-development-with-rspec-rr-shoulda-factory-girl-and-stubble/</link>
		<comments>http://casperfabricius.com/site/2009/07/25/test-driven-rails-development-with-rspec-rr-shoulda-factory-girl-and-stubble/#comments</comments>
		<pubDate>Sat, 25 Jul 2009 16:44:45 +0000</pubDate>
		<dc:creator>Casper Fabricius</dc:creator>
		<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/cfp/casperfabricius.com/site/wp-content/plugins/autometa/autometa.php</b> on line <b>324</b><br />
		<category><![CDATA[rails]]></category>

	<!-- AutoMeta Start -->
	<!-- AutoMeta End -->
	
		<guid isPermaLink="false">http://casperfabricius.com/site/?p=236</guid>
		<description><![CDATA[When I recently started development of a new, big Rails project, I spend some time researching and considering the many different testing frameworks that are available in the Ruby community today. I have grown very satisfied with the fail/pass rhythm of test-driven development (TDD) &#8211; write a test that fails, then write just enough code [...]]]></description>
			<content:encoded><![CDATA[<p>When I recently started development of a new, big Rails project, I spend some time researching and considering the many different testing frameworks that are available in the Ruby community today. I have grown very satisfied with the fail/pass rhythm of test-driven development (TDD) &#8211; write a test that fails, then write just enough code to make it pass. I also like <a href="http://rspec.info/">RSpec</a> a lot, so some would say that I am fact doing behaviour-driven development (BDD) &#8211; to me, the only real difference between TDD and BDD is the syntax, and I tend to find RSpec&#8217;s examples slightly more readable TestUnit&#8217;s tests. TDD gives me a small gratification &#8211; a sense of accomplishment, albeit on a small scale &#8211; every time a test passes in my autospec terminal.</p>
<p>Howver, TDD&#8217;s basic rule of always writing a failing test before writing any new code, doesn&#8217;t always leave me feeling very productive. For this reason I have mostly abandoned testing views in isolation (as made possible by RSpec&#8217;s view tests), as well as testing Rails helpers with the exception of complicated helper methods with some business logic in them. I still tests views by, behold, viewing them in the browser, and I haven&#8217;t been swept away by <a href="http://wiki.github.com/aslakhellesoy/cucumber/ruby-on-rails">Cucumber</a>, <a href="http://wiki.github.com/brynary/webrat">Webrat</a>, <a href="http://seleniumhq.org/">Selenium</a> and their fellow high-level test frameworks yet &#8211; but I am open.</p>
<p><span id="more-236"></span></p>
<p>I can skip view-testing without feeling too bad about it (wonder how many potential customers that statement scared away), but although I live and breath by the <a href="http://www.therailsway.com/2007/6/1/railsconf-recap-skinny-controllers">Skinny Controller &#8211; Fat Models</a> notion, I still find functional testing of my controllers to be a must in Rails TDD. Unfortunately, I have never really gotten along with RSpec&#8217;s default way of testing controllers. It feels bloated, and the RSpec mocking framework seems to &#8211; yes &#8211; mock me as I add more and more stubs and expectations to avoid tests from failing. So in my research for testing frameworks, I knew I had to find a better way to feel productive and happy about writing controller code again.</p>
<p>Many people hate test fixtures in a very intense and passionate way. I actually kind of like them, I just think they are a bit too stupid and hard to maintain. I also love all the good stuff coming from the <a href="http://www.thoughtbot.com/projects/">thoughtbot</a> guys, and their alternative to Rails&#8217; fixtures &#8211; <a href="http://www.thoughtbot.com/projects/factory_girl">Factory Girl</a> &#8211; is really, really good. Not just because it has a pretty name and a fancy syntax, but because it is really nothing more than Rails&#8217; fixtures done right.</p>
<p>I am getting ahead of myself here. Testing seems to be something people have very different opinions about, and as such I don&#8217;t the perfect mix of testing frameworks for everyone exists. RSpec has probably come closest, and I am sticking with in my test setup while adding and replacing parts of it with newer and better solutions. The mix has come like this:</p>
<ul>
<li><a href="http://rspec.info/">RSpec</a> as the overall testing framework</li>
<li><a href="http://github.com/btakita/rr/tree/master">RR</a> (DoubleRuby) for mocking and stubbing</li>
<li><a href="http://www.thoughtbot.com/projects/shoulda">Shoulda</a> to get sweet test macros</li>
<li><a href="http://www.thoughtbot.com/projects/factory_girl">Factory Girl</a> to create test data</li>
<li><a href="http://github.com/dchelimsky/stubble/">Stubble</a> for easing my controller spec pains</li
</ul>
<p>Do I really need five testing frameworks to be productive with TDD? Not at all, Rails is bundled with all I need to do TDD. But along the way, I have seen the need to make my tests DRY&#8217;er, more readable and easier to maintain, and these frameworks help me with that in different ways. I have already touched on the RSpec vs. TestUnit issue: It comes down to personal taste, and RR, Shoulda, Factory Girl and Stubble all works with both of these frameworks &#8211; isn&#8217;t that nice?</p>
<p>I initially chose to try RR because it seemed to be what the cool kids are using at the moment (and that often turns out to be good), but now that I am getting into it, I am really starting appreciate its compact syntax and advanced features. You could argue that RR&#8217;s syntax:</p>
<pre>
  mock(User).find { @user }
</pre>
<p>- is much harder to read than, say, RSpec&#8217;s mocking syntax:</p>
<pre>
  User.should_receive(:find).and_return(@user)
</pre>
<p>- but I&#8217;d say that RR&#8217;s syntax is actually more &#8220;Ruby-ish&#8221; than RSpec&#8217;s. If you really understand Ruby, RR will most likely appeal to you.</p>
<p>I use Shoulda mainly to get DRY&#8217;er tests that are easier to read, than when I write macros myself. Shoulda has defined a set macros that are quickly becoming a standard, and as something quite new, they also exists as RSpec matchers. Statements such as:</p>
<pre>
  it { should validate_presence_of(:state) }
</pre>
<p>- simply makes TDD faster and more enjoyable, because it would feel wrong to have to write 3-5 lines of test code to test a single line of Rails code.</p>
<p>I can&#8217;t say if Factory Girl is better than, say, <a href="http://github.com/notahat/machinist/tree/master">Machinist</a> (which is actually heavily inspired by the former, according to the creator), but it is without a about much better than Rails&#8217; fixtures from maintenance point of view, the syntax is pretty and it feels productive to use.</p>
<p>If you already knew about everything else mention in this article, chances are that Stubble will still be news to you. Not even released in a version 0.0.1 yet, this project is a small testing framework aimed at making stubbing and mocking in controller tests much easier. When the author, David Chelimsky &#8211; who is also behind RSpec &#8211; mentioned this in passing at a presentation at RailsConf 2009, my curiosity was immediately piqued.  Could this be solution to functional testing woes? Short answer: I&#8217;m not really sure yet. It&#8217;s still too early to say. Currently, I can only get Stubble to work in very simple cases like this:</p>
<pre>
  describe "on GET to :show" do
    def do_get(params = {})
      stubbing(Teaser) do |teaser|
        get :show, {:id => teaser.id}.merge(params)
        yield(teaser)
      end
    end

    it { do_get { |teaser| should assign_to(:teaser).with(teaser) } }
    it { do_get { |teaser| should render_template('show') } }
  end
</pre>
<p>- where I have even had to wrap the <code>stubbing</code>, which is the core of Stubble, in my own method to get the compact testing style I like. I don&#8217;t think I use Stubble in the way it is intended, but I&#8217;d like to be able to simply wrap do my entire outer describe in the stubbing statement, this having the magical <code>teaser</code> variable available in all my tests, helper methods and before-statements. Also, I have not yet managed to mock or stub anything on the magical <code>teaser</code> variable, so if I for example want to verify that some method is called on <code>teaser</code>, I can&#8217;t use Stubble in that test. Again, to be fair, Stubble is in very early development, and I still need to learn about it, but if these two problems are solved, I think Stubble is going to ease a lot of my controller testing pain.</p>
<p>If you, dear reader, feel that you have a better, or simply different, mix of testing frameworks, I&#8217;d love a comment from you about your choices and reasons for going with one thing over the other.</p>
]]></content:encoded>
			<wfw:commentRss>http://casperfabricius.com/site/2009/07/25/test-driven-rails-development-with-rspec-rr-shoulda-factory-girl-and-stubble/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
