<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>CODETUNES</title>
	
	<link>http://codetunes.com</link>
	<description>is a development blog led by monterail.com</description>
	<lastBuildDate>Thu, 26 Jan 2012 21:30:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/CodeTunes" /><feedburner:info uri="codetunes" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><image><link>http://codetunes.com</link><url>http://codetunes.com/wp-content/uploads/2011/07/tee_small.png</url><title>Monterail.com, an offshore webdevelopment agency.</title></image><item>
		<title>A digital watercooler – easiest way to improve communication inside your team</title>
		<link>http://feedproxy.google.com/~r/CodeTunes/~3/N_xBnWY8B1c/digital-watercooler-improve-communication-inside-your-team</link>
		<comments>http://codetunes.com/2012/01/26/digital-watercooler-improve-communication-inside-your-team#comments</comments>
		<pubDate>Thu, 26 Jan 2012 19:01:39 +0000</pubDate>
		<dc:creator>Bartosz Pietrzak</dc:creator>
				<category><![CDATA[Communication]]></category>

		<guid isPermaLink="false">http://codetunes.com/?p=350</guid>
		<description><![CDATA[I have always been struggling with the goal of constantly improving the communication inside our development team. We always followed the idea that team is always more effective than any number of individuals. Since the team has grown to 15+ people &#8230; <a href="http://codetunes.com/2012/01/26/digital-watercooler-improve-communication-inside-your-team">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I have always been struggling with the goal of constantly improving the communication inside our development team. We always followed the idea that team is always more effective than any number of individuals. Since the team has grown to 15+ people and a few of us are in different physical locations throughout Poland, we had to find a way to communicate and share knowledge effectively.</p>
<p>We have tried couple different options:</p>
<ul>
<li><a href="https://www.yammer.com/">Yammer</a> &#8211; enterprise-focused twitter clone. Sluggy, overbloated and not effective for us at all &#8211; you don&#8217;t want to use a tool that you have to remember about and you find it hard to use!</li>
<li><a href="http://campfirenow.com/">Campfire</a> &#8211; 1st choice for people that find IRC not being up to the modern web. A lot of ways to integrate great tools. A lot of great mobile and desktop clients. We used it for over a year and it played well &#8211; but it&#8217;s a massive distraction generator. We&#8217;re using it right now mostly to get notifications about git commits being pushed to our repository.</li>
<li>IRC &#8211; freenode or <a href="https://grove.io/">grove.io</a>, every option had same problems as Campfire &#8211; you don&#8217;t want to get distracted by seeing an message and not knowing whether it&#8217;s important or not.</li>
<li>Jabber group chat &#8211; yes, we tried even that one. I won&#8217;t comment it.</li>
</ul>
<h2>Thanks, Captain Obvious!</h2>
<div>For couple months we&#8217;ve been using <a href="http://www.facebook.com/groups">Facebook groups</a> to share links (and funny pictures, yeah).</div>
<div><a href="http://codetunes.com/wp-content/uploads/2012/01/Zrzut-ekranu-2012-01-26-o-19.54.38.png"><img class="alignnone size-full wp-image-353" title="Zrzut ekranu 2012-01-26 o 19.54.38" src="http://codetunes.com/wp-content/uploads/2012/01/Zrzut-ekranu-2012-01-26-o-19.54.38.png" alt="" width="178" height="157" /></a></div>
<div>Stuff that&#8217;s not important to making your job done. It&#8217;s a tool that you don&#8217;t have to remember about &#8211; basically every member of our team uses Facebook, and even ones that weren&#8217;t before, have to &#8211; simply because we&#8217;re building software for / integrated with the Facebook platform (not exclusively, of course, but we still do a lot of it).</div>
<div>We use it to share some cool hacks, tools that improve our workflow, interesting gems, backbone.js libraries, design resources and even to remind about <a href="http://a2.sphotos.ak.fbcdn.net/hphotos-ak-snc7/424078_10150739559141110_542566109_12209089_281080735_n.jpg">using the water filter in a polite way</a>.</div>
<div>It&#8217;s great because it doesn&#8217;t break your workflow. It&#8217;s easy to use. You don&#8217;t have to remember about it &#8211; you&#8217;re probably using Facebook in your spare time anyway. Think of it as a digital watercooler &#8211; a place where people meet to get a few minutes of rest and have a chit-chat &#8211; simply because everyone drinks water. And if you&#8217;re <a href="http://www.youtube.com/watch?v=mAparymJ_jc">the guy that brings his own water to work</a> (or do not use Facebook for whatever reasons), you are aware that you&#8217;re missing some of the social goodness. And it&#8217;s a water cooler that you can bring home along with the people around it. And access it from your iPad. And Android device. And a feature phone.</div>
<h2>Important is important!</h2>
<p><a href="http://codetunes.com/wp-content/uploads/2012/01/noise-separated.png"><img class="size-full wp-image-352 alignnone" style="border-style: initial; border-color: initial; border-width: 0px;" title="noise separated" src="http://codetunes.com/wp-content/uploads/2012/01/noise-separated.png" alt="" width="423" height="67" /></a></p>
<p>Don&#8217;t get me wrong. We still use an group email to share updates about the office issues, absences etc. We use jabber and email (not mentioning project management tools) to communicate about day to day work. But in this case, when we get an email or an IM, we know it&#8217;s the important stuff &#8211; noise separated, achievement unlocked.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/Xyf6vr3RY0f9bu8QsDox4rtuGlM/0/da"><img src="http://feedads.g.doubleclick.net/~a/Xyf6vr3RY0f9bu8QsDox4rtuGlM/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/Xyf6vr3RY0f9bu8QsDox4rtuGlM/1/da"><img src="http://feedads.g.doubleclick.net/~a/Xyf6vr3RY0f9bu8QsDox4rtuGlM/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/CodeTunes/~4/N_xBnWY8B1c" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://codetunes.com/2012/01/26/digital-watercooler-improve-communication-inside-your-team/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://codetunes.com/2012/01/26/digital-watercooler-improve-communication-inside-your-team?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=digital-watercooler-improve-communication-inside-your-team</feedburner:origLink></item>
		<item>
		<title>Backbone.js, Rails 3 and asynchronous interfaces</title>
		<link>http://feedproxy.google.com/~r/CodeTunes/~3/JuZyNQjeuQg/backbone-js-rails-3-asynchronous-interfaces</link>
		<comments>http://codetunes.com/2012/01/03/backbone-js-rails-3-asynchronous-interfaces#comments</comments>
		<pubDate>Mon, 02 Jan 2012 22:43:44 +0000</pubDate>
		<dc:creator>Bartosz Pietrzak</dc:creator>
				<category><![CDATA[Backbone.js]]></category>
		<category><![CDATA[Frontend]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Rails 3.1]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://codetunes.com/?p=292</guid>
		<description><![CDATA[Currently at Monterail we&#8217;re building a frontend-heavy app. With a lot of cool stuff. Like preloading data for daily views so that you won&#8217;t have to wait for every surrounding day to load. Many, many interactive elements that should be really &#8230; <a href="http://codetunes.com/2012/01/03/backbone-js-rails-3-asynchronous-interfaces">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://codetunes.com/2012/01/03/backbone-js-rails-3-asynchronous-interfaces/rails-backbone" rel="attachment wp-att-301"><br />
</a><a href="http://codetunes.com/2012/01/03/backbone-js-rails-3-asynchronous-interfaces/rails-backbone-2" rel="attachment wp-att-306"><img class="size-full wp-image-306 alignright" style="border-style: initial; border-color: initial; border-width: 0px;" title="Backbone.js and Rails" src="http://codetunes.com/wp-content/uploads/2012/01/rails-backbone1.png" alt="Backbone.js and Rails" width="126" height="210" /></a>Currently at <a title="Ruby on Rails development agency" href="http://monterail.com">Monterail</a> we&#8217;re building a frontend-heavy app. With a lot of cool stuff. Like preloading data for daily views so that you won&#8217;t have to wait for every surrounding day to load. Many, many interactive elements that should be really interactive &#8211; not in an oldschool, ajax &#8220;spinner&#8221; way. And a lot of other stuff we shouldn&#8217;t talk about yet.</p>
<p>We decided to put more emphasis on <strong>Backbone.js with Rails</strong> and build most of the app with this combination.</p>
<p>Below you can find some of our findings on the topic of making those two speak to each other in a nice manner.</p>
<h1>Asset pipeline</h1>
<p>Really makes things easier. Organizing your JS code before it meant a lot of things: handling dependencies, minifying &amp; compressing the code, organizing it into a lot of different files and building connections between them. With asset pipeline and it&#8217;s awesome &#8220;require&#8221; directive, you can forget about handling it manually. You just create the structure in app/assets/javascripts. Or app/assets/javascripts/backbone. Your choice. You can have many different files in whatever directories you like &#8211; in the end you&#8217;ll get one (or more, if you decide to) JS file that has everything your webapp need.</p>
<p>Don&#8217;t forget to:</p>
<ul>
<li>gzip your JS/css assets</li>
<li>minify them!</li>
</ul>
<h1>Rails-backbone gem</h1>
<p>Also makes things easier. It puts backbone.js (&amp; underscore.js) library code into your asset pipeline. It gives you some great generators to get started if you don&#8217;t know where to start. Definitely worth including in your Gemfile.</p>
<p><a href="http://rubygems.org/gems/rails-backbone">http://rubygems.org/gems/rails-backbone</a></p>
<h1>Coffeescript &amp; underscore.js</h1>
<p>Obviously. It makes Javascript code feel fresh. You can fold, iterate and do a lot of stuff. Be sure to check out <a href="http://documentcloud.github.com/underscore/">underscore.js</a> docs. And <a href="http://coffeescript.org/">coffescript docs</a>, of course, but I bet you know it already.</p>
<h1>&#8220;V&#8221; in MVC done right</h1>
<p>Views are classes. You handle logic inside them using the hardcore code, which is receiving so much hate in Rails views. They can have many methods, they do not have to render a single &#8220;action&#8221;. And templates are templates &#8211; and nothing else. There is a lot of discussion recently on the matter of Views/Templates in Rails, but you can start implementing it right away. Go and try it. You&#8217;ll fall in love.</p>
<p>You have many options for templates &#8211; <a href="https://github.com/sstephenson/eco">eco</a>, <a href="http://www.handlebarsjs.com/">Handlebars.js</a>, <a href="https://github.com/defunkt/mustache">{{ mustache }}</a>, but we recommend <a href="https://github.com/netzpirat/haml_coffee_assets">haml_coffee_assets</a>. It gives you the HAML you (probably) already know with the ability to use coffeescript within it.</p>
<h1>Single-page app</h1>
<p>Yes. You will use Rails to render only the core view of the application. Of course, you will have to handle all things around the core of your app.</p>
<p>For example, you should probably leave out:</p>
<ul>
<li><em>authentication logic</em>: sign up / in, reset password</li>
<li><em>steps necessary to use the app</em>: billing pages</li>
</ul>
<div>But, other than that, you can use the views rendered in JS. What does that mean?</div>
<div>
<ul>
<li>if they do not include any dynamic data, they are lightning fast</li>
<li>if they include dynamic data, you can preload it and they still will be lightning fast</li>
</ul>
<div>Backbone comes with it&#8217;s own router. You can utilise <a href="http://documentcloud.github.com/backbone/#History">pushState</a> without any effort. How cool is that?</div>
<h1><span class="Apple-style-span" style="color: #000000;">Asynchronous interface</span></h1>
<p>Since you&#8217;ll be doing most of the association/validation work in background, you don&#8217;t have to worry too much about server responses. It&#8217;s the same with rendering elements: you&#8217;ll be doing it in JS, not Rails. You don&#8217;t have to wait for the request to return the rendered element to actually display them. If you create something, the UI should respond right away and the ajax request can persist the data with it&#8217;s own pace.</p>
<p>You should, however, prepare a global &#8220;something went wrong, reload the page&#8221; request rescuer &#8211; in case of network outages, backend app failures and so on. But it&#8217;s way easier to manage.</p>
<h1>API</h1>
<p>You get it for free. It doesn&#8217;t have to be public, but if you decide to, it&#8217;s a matter of adding OAuth as the way of authenticating requests and it&#8217;s done. (Or you could go with http basic auth, which is obviously bad for a lot of reasons).</p>
<p>With smart caching (give <a href="http://jodosha.github.com/redis-store">redis-store</a> a try), you&#8217;ll save tons of server power. You know, relating to the old ruby saying, &#8220;views are most resource-consuming&#8221;.</p>
<h1>Conclusion</h1>
<p>There are, obviously, downsides, which I&#8217;ll cover in future (I silently hope that there won&#8217;t be any reason to do that). And topics I haven&#8217;t covered. I&#8217;m curious about other stacks and ways of doing things. Share in the comments or ping me on Twitter!</p>
<p><a class="twitter-follow-button" href="https://twitter.com/bartoszpietrzak" data-show-count="false">Follow @bartoszpietrzak</a></p>
</div>

<p><a href="http://feedads.g.doubleclick.net/~a/acEIaeUACtTWSo0p-hZUuEh7rks/0/da"><img src="http://feedads.g.doubleclick.net/~a/acEIaeUACtTWSo0p-hZUuEh7rks/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/acEIaeUACtTWSo0p-hZUuEh7rks/1/da"><img src="http://feedads.g.doubleclick.net/~a/acEIaeUACtTWSo0p-hZUuEh7rks/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/CodeTunes/~4/JuZyNQjeuQg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://codetunes.com/2012/01/03/backbone-js-rails-3-asynchronous-interfaces/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://codetunes.com/2012/01/03/backbone-js-rails-3-asynchronous-interfaces?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=backbone-js-rails-3-asynchronous-interfaces</feedburner:origLink></item>
		<item>
		<title>wroc_love.rb</title>
		<link>http://feedproxy.google.com/~r/CodeTunes/~3/e2NjmdSetV4/wroc_love_rb</link>
		<comments>http://codetunes.com/2011/12/14/wroc_love_rb#comments</comments>
		<pubDate>Wed, 14 Dec 2011 20:29:10 +0000</pubDate>
		<dc:creator>Bartosz Pietrzak</dc:creator>
				<category><![CDATA[Conferences]]></category>
		<category><![CDATA[wroclaw]]></category>

		<guid isPermaLink="false">http://codetunes.com/?p=284</guid>
		<description><![CDATA[wroc_love.rb is a „Fresh Ruby-oriented conference in Wrocław, Poland” that happens on 10-11 March 2012. We&#8217;re proud to announce that our team got involved in co-organizing the event and one of the outcomes is the launch of the new website &#8211; &#8230; <a href="http://codetunes.com/2011/12/14/wroc_love_rb">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a title="wroc_love.rb" href="http://wrocloverb.com/">wroc_love.rb</a> is a „Fresh Ruby-oriented conference in Wrocław, Poland” that happens on 10-11 March 2012.</p>
<p>We&#8217;re proud to announce that our team got involved in co-organizing the event and one of the outcomes is the launch of the <a href="http://wrocloverb.com/">new website &#8211; go check it out</a>!</p>
<p><a href="http://wrocloverb.com/"><img class="aligncenter size-large wp-image-285" title="Zrzut ekranu 2011-12-14 o 21.18.16" src="http://codetunes.com/wp-content/uploads/2011/12/Zrzut-ekranu-2011-12-14-o-21.18.16-1024x438.png" alt="" width="584" height="249" /></a>One of the goals of the conference is to supply some solid topics that, we hope, will result in long and red hot discussions.</p>
<p>Don&#8217;t forget to <a href="http://twitter.com/wrocloverb">follow the twitter account</a>, <a href="https://www.facebook.com/wroclove.rb">like the facebook page</a>, <a href="http://blog.wrocloverb.com/">follow the tumblr blog</a> and <a href="http://c4p.wrocloverb.com/">submit a paper proposal</a> - if you have something interesting to say!</p>

<p><a href="http://feedads.g.doubleclick.net/~a/bqB-nAYXz-ej4eXEh8E7bI-mWPk/0/da"><img src="http://feedads.g.doubleclick.net/~a/bqB-nAYXz-ej4eXEh8E7bI-mWPk/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/bqB-nAYXz-ej4eXEh8E7bI-mWPk/1/da"><img src="http://feedads.g.doubleclick.net/~a/bqB-nAYXz-ej4eXEh8E7bI-mWPk/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/CodeTunes/~4/e2NjmdSetV4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://codetunes.com/2011/12/14/wroc_love_rb/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://codetunes.com/2011/12/14/wroc_love_rb?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=wroc_love_rb</feedburner:origLink></item>
		<item>
		<title>Testing AJAX-reloaded elements with Capybara</title>
		<link>http://feedproxy.google.com/~r/CodeTunes/~3/woLbbKHvggY/testing-ajax-reloaded-elements-with-capybara</link>
		<comments>http://codetunes.com/2011/08/20/testing-ajax-reloaded-elements-with-capybara#comments</comments>
		<pubDate>Sat, 20 Aug 2011 16:00:15 +0000</pubDate>
		<dc:creator>Michał Szajbe</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Test Driven Development]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[capybara]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[selenium]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://codetunes.com/?p=270</guid>
		<description><![CDATA[Capybara is a great tool for testing application flow and user interfaces. Thanks to Culerity and Selenium web drivers you can test javascript and AJAX features of your apps. However testing AJAX is not that straightforward because of asynchonous nature of these &#8230; <a href="http://codetunes.com/2011/08/20/testing-ajax-reloaded-elements-with-capybara">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a title="Capybara gem" href="https://github.com/jnicklas/capybara" target="_blank">Capybara</a> is a great tool for testing application flow and user interfaces. Thanks to Culerity and Selenium web drivers you can test javascript and AJAX features of your apps.</p>
<p>However testing AJAX is not that straightforward because of asynchonous nature of these requests. In order to test effects of AJAX calls a web driver must wait until they finish which is difficult if not impossible to detect. However this can be worked around using some tricks.</p>
<h2>Scenario 1</h2>
<p>Let&#8217;s say you want to test a link on the page that triggers an AJAX request which eventually inserts some element in DOM. This could be an &#8220;Edit&#8221; link that retrieves object&#8217;s data from database (via AJAX call) and then shows an HTML form on the page. Test scenario might look like this:</p>
<pre>@selenium
Scenario: Clicking "Edit" should show edit form
  Given I am on product's page
  And I click "Edit" link
  Then I should see form</pre>
<p>The form will not appear immediately after the link is clicked because it takes some time for your app to process the AJAX request and return the response. Capybara is intelligent enough to acknowledge this and instead of expecting a form to appear immediately it periodically looks for it in page&#8217;s DOM. You can define for how many seconds it should keep looking by setting following option:</p>
<pre>Capybara.default_wait_time = 5</pre>
<p>If the form doesn&#8217;t appear in this specified time frame, the test fails. Note that Capybara doesn&#8217;t always wait full 5 seconds, it simply moves on to the next step as soon as the form appears.</p>
<h2> Scenario 2</h2>
<p>Now you want to test a link that removes an element from DOM. This could be a &#8220;Save&#8221; link that saves object to database (via AJAX call) and then removes the form. Test scenario:</p>
<pre>@selenium
Scenario: Clicking "Save" should remove edit form
  Given I am on product's page
  And I click "Save"
  Then I should not see form</pre>
<p>This test fails even if your app works as expected. I guess you see the problem. Capybara finds the form on first lookup which is performed immediately after the click, but at that point the AJAX call has not completed yet, so the form is still there.</p>
<p>Popular solution is to explicitely tell Capybara to wait until it starts looking for changes in DOM. In other words, give the AJAX calls chance to complete. Here&#8217;s an adequate cucumber step:</p>
<pre>Given /^I wait (\d+) seconds?$/ do |sec|
  sleep(sec.to_i)
end</pre>
<p>Rebuilt scenario would look like this:</p>
<pre>@selenium
Scenario: Clicking "Save" should remove edit form
  Given I am on product's page
  And I click "Save"
  And I wait 5 seconds
  Then I should not see form</pre>
<p>The downside is that it will always wait 5 full seconds now.</p>
<h2>Other aspects</h2>
<p>Neither explicit waiting with <em>sleep</em>, nor Capybara&#8217;s <em>default_wait_time</em> option guarantees 100% success. Your tests may still ocassionally fail if the AJAX requests they perform takes longer than you assume. The time it takes for the app to process such request may be quite random as it depends on many aspects like machine load or external services it hits (database, search engines, etc.). So remember to set the option to a value high enough for your app.</p>
<p><a href="https://twitter.com/szajbus" class="twitter-follow-button" data-show-count="false">Follow @szajbus</a><br />
<script src="//platform.twitter.com/widgets.js" type="text/javascript"></script></p>

<p><a href="http://feedads.g.doubleclick.net/~a/M8liG5MOYVp8YXwuF_UQwLSKZ4g/0/da"><img src="http://feedads.g.doubleclick.net/~a/M8liG5MOYVp8YXwuF_UQwLSKZ4g/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/M8liG5MOYVp8YXwuF_UQwLSKZ4g/1/da"><img src="http://feedads.g.doubleclick.net/~a/M8liG5MOYVp8YXwuF_UQwLSKZ4g/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/CodeTunes/~4/woLbbKHvggY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://codetunes.com/2011/08/20/testing-ajax-reloaded-elements-with-capybara/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://codetunes.com/2011/08/20/testing-ajax-reloaded-elements-with-capybara?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=testing-ajax-reloaded-elements-with-capybara</feedburner:origLink></item>
		<item>
		<title>Chosen: multiple choice select inputs made easy</title>
		<link>http://feedproxy.google.com/~r/CodeTunes/~3/INzol4TiDsU/chosen</link>
		<comments>http://codetunes.com/2011/08/01/chosen#comments</comments>
		<pubDate>Mon, 01 Aug 2011 06:00:38 +0000</pubDate>
		<dc:creator>Bartosz Pietrzak</dc:creator>
				<category><![CDATA[Frontend]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://codetunes.com/?p=264</guid>
		<description><![CDATA[http://harvesthq.github.com/chosen/ Great tool for enhancing selects, multiple selects, grouped selects etc. made by the Harvest team (great timetracking tool we&#8217;re using on a daily basis). We&#8217;re all about using native controls as much as possible, but multiple select boxes were &#8230; <a href="http://codetunes.com/2011/08/01/chosen">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://harvesthq.github.com/chosen/">http://harvesthq.github.com/chosen/</a></p>
<p>Great tool for enhancing selects, multiple selects, grouped selects etc. made by the <a href="http://getharvest.com">Harvest</a> team (great timetracking tool we&#8217;re using on a daily basis).<br />
<a href="http://harvesthq.github.com/chosen/"><img class="aligncenter size-full wp-image-265" title="Zrzut ekranu 2011-07-31 o 11.26.40" src="http://codetunes.com/wp-content/uploads/2011/07/Zrzut-ekranu-2011-07-31-o-11.26.40.png" alt="" width="383" height="230" /></a>We&#8217;re all about using native controls as much as possible, but multiple select boxes were always a non-usable pain in the ass. This one is a great solution in tight areas where you can&#8217;t afford displaying a list with checkboxes.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>

<p><a href="http://feedads.g.doubleclick.net/~a/cyaXHWynDAN6dO_BduMy-vK2GAs/0/da"><img src="http://feedads.g.doubleclick.net/~a/cyaXHWynDAN6dO_BduMy-vK2GAs/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/cyaXHWynDAN6dO_BduMy-vK2GAs/1/da"><img src="http://feedads.g.doubleclick.net/~a/cyaXHWynDAN6dO_BduMy-vK2GAs/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/CodeTunes/~4/INzol4TiDsU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://codetunes.com/2011/08/01/chosen/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://codetunes.com/2011/08/01/chosen?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=chosen</feedburner:origLink></item>
		<item>
		<title>Outbound API rate limits: the nginx way</title>
		<link>http://feedproxy.google.com/~r/CodeTunes/~3/H4mN9-iKRrk/outbound-api-rate-limits-the-nginx-way</link>
		<comments>http://codetunes.com/2011/07/26/outbound-api-rate-limits-the-nginx-way#comments</comments>
		<pubDate>Tue, 26 Jul 2011 19:10:01 +0000</pubDate>
		<dc:creator>Bartosz Pietrzak</dc:creator>
				<category><![CDATA[Web Servers]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[api calls throttling]]></category>
		<category><![CDATA[api rate limits]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://codetunes.com.mhs1.monterail.eu/?p=1</guid>
		<description><![CDATA[Implementing external API rate limits can be painful. There are some solutions that aim at this problem &#8211; let&#8217;s take Slow Web for example &#8211; but things tend to complicate when we start using background jobs, or even oldschool cron-rake &#8230; <a href="http://codetunes.com/2011/07/26/outbound-api-rate-limits-the-nginx-way">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Implementing external API rate limits can be painful. There are some solutions that aim at this problem &#8211; let&#8217;s take <a href="https://github.com/benbjohnson/slowweb" target="_blank">Slow Web</a> for example &#8211; but things tend to complicate when we start using background jobs, or even oldschool cron-rake setup. Slow web takes care of one environment at a time, not to mention that it relies on Net::HTTP so you can forget using more powerful stuff like <a href="https://github.com/dbalatero/typhoeus" target="_blank">Typhoeus</a>.</p>
<p>Recently we started working on a project that uses heavily an API that limits our development calls to one per 500ms and production calls to one per 200ms (our first thought and initial information was that we can do five requests per second, but those are not the same). Inspired by a great post, „<a href="http://www.gabrielweinberg.com/blog/2011/07/nginx-json-hacks.html" target="_blank">nginx JSON hacks</a>”, an idea came to our minds. What if we could use nginx to implement limiting the API? Here comes the built-in nginx module, the <a href="http://wiki.nginx.org/HttpLimitReqModule" target="_blank">HttpLimitReqModule</a>. Let&#8217;s take a quick look.</p>
<pre>http {
  limit_req_zone  $binary_remote_addr  zone=one:10m   rate=110r/m;

  server {
    listen       8080;
    server_name  localhost;

    location / {
      limit_req   zone=one  burst=100;

      proxy_pass        http://api.example.com/;
    }
  }
}</pre>
<p><em>(Please bear in mind that this configuration is merely an example and you probably want a more comprehensive setup. You can <a href="http://monterail.com">hire us to do the job for you</a>).</em></p>
<p>We set a simple proxy on localhost:8080, configure the limit_req_zone option, apply the zone, set the burst rate to 100 (depending on how you want to handle huge load, this could be smaller or bigger). We set the rate to 110 requests per minute for a little margin. Our benchmarks went fine, as we expected &#8211; no API calls were dropped. Setting it to exact 120r/m (or 2r/s) gave us some 403s, though.</p>
<p>Okay, so what about those cool examples in the post mentioned above? Let&#8217;s apply some caching!</p>
<pre>http {
    limit_req_zone  $binary_remote_addr  zone=one:10m   rate=110r/m;
    proxy_cache_path  /tmp/nginx_cache levels=1:2 keys_zone=STATIC:64m inactive=60m max_size=128m;

    server {
        listen       8080;
        server_name  localhost;

        location /without_cache {
          limit_req   zone=one  burst=100;

          proxy_pass        http://api.example.com/;
        }

        location / {
            proxy_pass        http://localhost:8080/without_cache;

            proxy_cache STATIC;
            proxy_cache_methods POST GET PUT; # allow POST caching which is not allowed by default
            proxy_cache_valid 10s; # cache every API request for 10 seconds
            proxy_cache_key "$host$request_uri$request_body";
        }
    }
}</pre>
<p>Why two locations, you may ask? It&#8217;s because we don&#8217;t want to have a rate limit for our cached version. In this case, when the first request finishes, every other gets an ultra-speed boost from being stored in a local cache.</p>
<p>We don&#8217;t have to worry about implementing API rate limits in every place in the app. We don&#8217;t have to worry about sharing those limits between different environments. All we need to do is to change the API host and enjoy pure coding goodness.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/DGiQhfKIbagpSLDuVvDs13YsC9M/0/da"><img src="http://feedads.g.doubleclick.net/~a/DGiQhfKIbagpSLDuVvDs13YsC9M/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/DGiQhfKIbagpSLDuVvDs13YsC9M/1/da"><img src="http://feedads.g.doubleclick.net/~a/DGiQhfKIbagpSLDuVvDs13YsC9M/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/CodeTunes/~4/H4mN9-iKRrk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://codetunes.com/2011/07/26/outbound-api-rate-limits-the-nginx-way/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://codetunes.com/2011/07/26/outbound-api-rate-limits-the-nginx-way?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=outbound-api-rate-limits-the-nginx-way</feedburner:origLink></item>
		<item>
		<title>CakePHP moved to Github!</title>
		<link>http://feedproxy.google.com/~r/CodeTunes/~3/T-U0eDYnk_E/cakephp-moved-to-github</link>
		<comments>http://codetunes.com/2009/12/11/cakephp-moved-to-github#comments</comments>
		<pubDate>Fri, 11 Dec 2009 17:56:00 +0000</pubDate>
		<dc:creator>Michał Szajbe</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[cakephp]]></category>
		<category><![CDATA[github]]></category>

		<guid isPermaLink="false">http://codetunes.com/?p=136</guid>
		<description><![CDATA[After two of the core developers, Nate Abele and Gwoo, left the project lately, many feared the worst. Now it&#8217;s a different story! The CakePHP core team decided to move the project to Github. I&#8217;d say: finally! Now it&#8217;s truly &#8230; <a href="http://codetunes.com/2009/12/11/cakephp-moved-to-github">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>After two of the core developers, Nate Abele and Gwoo, left the project lately, <a title="The end of CakePHP?" href="http://cakebaker.42dh.com/2009/10/23/the-end-of-cakephp/">many</a> feared the worst. Now it&#8217;s a different story! The CakePHP core team decided to move the project to <a title="CakePHP on Github" href="http://github.com/cakephp">Github</a>.</p>
<p>I&#8217;d say: finally!</p>
<p>Now it&#8217;s truly open to the community. That&#8217;s because Github makes it so easy to collaborate on open source projects. All you need to do is to fork a project, merge your changes, and send a pull request to project&#8217;s maintainer. Can&#8217;t imagine more painless process.</p>
<p>What I expect now is a real boost in CakePHP development, with many great features delivered by the community. Just check how other projects benefited from the move, for example <a title="Ruby on Rails" href="http://github.com/rails/rails">Ruby on Rails</a> that has more than 700 forks now. So&#8230;</p>
<p>Let&#8217;s fork it! <img src='http://codetunes.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>

<p><a href="http://feedads.g.doubleclick.net/~a/r5xME7Hb6IftxAg1Hwczp0dZZP0/0/da"><img src="http://feedads.g.doubleclick.net/~a/r5xME7Hb6IftxAg1Hwczp0dZZP0/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/r5xME7Hb6IftxAg1Hwczp0dZZP0/1/da"><img src="http://feedads.g.doubleclick.net/~a/r5xME7Hb6IftxAg1Hwczp0dZZP0/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/CodeTunes/~4/T-U0eDYnk_E" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://codetunes.com/2009/12/11/cakephp-moved-to-github/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://codetunes.com/2009/12/11/cakephp-moved-to-github?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=cakephp-moved-to-github</feedburner:origLink></item>
		<item>
		<title>Fixtures without validation with Factory Girl</title>
		<link>http://feedproxy.google.com/~r/CodeTunes/~3/TH7P6x2aeCs/fixtures-without-validation-with-factory-girl</link>
		<comments>http://codetunes.com/2009/11/05/fixtures-without-validation-with-factory-girl#comments</comments>
		<pubDate>Thu, 05 Nov 2009 12:29:34 +0000</pubDate>
		<dc:creator>Michał Szajbe</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Test Driven Development]]></category>
		<category><![CDATA[factory girl]]></category>
		<category><![CDATA[fixtures]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://codetunes.com/?p=132</guid>
		<description><![CDATA[Factory Girl is my fixture replacement library of choice. It improves tests readability and maintainability. It&#8217;s also customizable. There are sometimes situations when you want to create test scenarios that checks how your app is handling invalid data (not user &#8230; <a href="http://codetunes.com/2009/11/05/fixtures-without-validation-with-factory-girl">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://github.com/thoughtbot/factory_girl">Factory Girl</a> is my fixture replacement library of choice. It improves tests readability and maintainability. It&#8217;s also customizable.</p>
<p>There are sometimes situations when you want to create test scenarios that checks how your app is handling invalid data (not user input, but invalid records that already sit in your database). To do this you first need to put this invalid data to your db.</p>
<p>You could accomplish this with such line:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#0066ff; font-weight:bold;">@user</span> = Factory<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:user</span>, <span style="color:#ff3333; font-weight:bold;">:email</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">&quot;not a correct email address&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>However, factory girl would raise an exception here, because that&#8217;s the default strategy of creating new fixtures &#8211; raise exception if save fails (because of validation errors for example).</p>
<p>Thankfully we can use our own strategy of creating new fixtures, such that does save records without validation.</p>
<p>First let&#8217;s define our new strategy:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#6666ff; font-weight:bold;">Factory::Proxy::CreateWithoutValidation</span> <span style="color:#006600; font-weight:bold;">&amp;</span>lt; <span style="color:#6666ff; font-weight:bold;">Factory::Proxy::Build</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> result
    <span style="color:#0066ff; font-weight:bold;">@instance</span>.<span style="color:#9900CC;">save</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0066ff; font-weight:bold;">@instance</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> Factory
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">create_without_validation</span> <span style="color:#006600; font-weight:bold;">&#40;</span>name, overrides = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    factory_by_name<span style="color:#006600; font-weight:bold;">&#40;</span>name<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">run</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#6666ff; font-weight:bold;">Proxy::CreateWithoutValidation</span>, overrides<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></pre></div></div>

<p>Now we can use it while defining new factory:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">Factory.<span style="color:#9900CC;">define</span> <span style="color:#ff3333; font-weight:bold;">:invalid_user</span>, :<span style="color:#9966CC; font-weight:bold;">class</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; User, <span style="color:#ff3333; font-weight:bold;">:default_strategy</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#ff3333; font-weight:bold;">:create_without_validation</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span>
  ...
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>And then we can happily create invalid fixtures without any exceptions raised.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/Wz2iGHuEA_ieVlRUWO5VnuvRLig/0/da"><img src="http://feedads.g.doubleclick.net/~a/Wz2iGHuEA_ieVlRUWO5VnuvRLig/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/Wz2iGHuEA_ieVlRUWO5VnuvRLig/1/da"><img src="http://feedads.g.doubleclick.net/~a/Wz2iGHuEA_ieVlRUWO5VnuvRLig/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/CodeTunes/~4/TH7P6x2aeCs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://codetunes.com/2009/11/05/fixtures-without-validation-with-factory-girl/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://codetunes.com/2009/11/05/fixtures-without-validation-with-factory-girl?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=fixtures-without-validation-with-factory-girl</feedburner:origLink></item>
		<item>
		<title>Turning off auto timestamping for testing in Rails</title>
		<link>http://feedproxy.google.com/~r/CodeTunes/~3/p-sLiQt-1nQ/turning-off-auto-timestamping-for-testing-in-rails</link>
		<comments>http://codetunes.com/2009/05/09/turning-off-auto-timestamping-for-testing-in-rails#comments</comments>
		<pubDate>Fri, 08 May 2009 22:35:54 +0000</pubDate>
		<dc:creator>Michał Szajbe</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Test Driven Development]]></category>
		<category><![CDATA[active record]]></category>
		<category><![CDATA[factory girl]]></category>
		<category><![CDATA[fixtures]]></category>
		<category><![CDATA[model]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[timestamping]]></category>

		<guid isPermaLink="false">http://codetunes.com/?p=121</guid>
		<description><![CDATA[Suppose that you implemented a functionality that depends on values of created_at or updated_at fields of your models. How do you test it? If you use fixtures that reside in test/fixture/*.yml files then there is no problem, because the values &#8230; <a href="http://codetunes.com/2009/05/09/turning-off-auto-timestamping-for-testing-in-rails">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Suppose that you implemented a functionality that depends on values of created_at or updated_at fields of your models. How do you test it?</p>
<p>If you use fixtures that reside in test/fixture/*.yml files then there is no problem, because the values you set there for created_at and updated_at fields are saved to the database &#8216;as is&#8217;. So you can easily have an article created one week ago:</p>

<div class="wp_syntax"><div class="code"><pre class="yml" style="font-family:monospace;">article:
  title: What a great day
  created_at:
  updated_at:</pre></div></div>

<p>However, I don&#8217;t use fixtures files myself. I feel a bit dirty using them <img src='http://codetunes.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  I find fixture replacement tools far more maintainable. Namely, I love <a title="Factory Girl" href="http://github.com/thoughtbot/factory_girl">thoughtbot&#8217;s Factory Girl</a>. But here comes the problem. This won&#8217;t work as expected with Factory Girl:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">Factory<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:article</span>, <span style="color:#ff3333; font-weight:bold;">:created_at</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#006666;">1</span>.<span style="color:#9900CC;">week</span>.<span style="color:#9900CC;">ago</span>, <span style="color:#ff3333; font-weight:bold;">:updated_at</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#006666;">1</span>.<span style="color:#9900CC;">week</span>.<span style="color:#9900CC;">ago</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>That&#8217;s because ActiveRecord&#8217;s automatic timestamping feature sets Time.now for created_at and updated_at fields overriding our values. At least that&#8217;s ActiveRecord&#8217;s default behavior. Fortunately it can be disabled with:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">Article.<span style="color:#9900CC;">record_timestamps</span> = <span style="color:#0000FF; font-weight:bold;">false</span></pre></div></div>

<p>Chances are that after creating a model with a custom timestamp we&#8217;ll want to turn automatic timestamping back on. But turning it off and on in many places in your unit tests would be pretty cumbersome. Wouldn&#8217;t it be cool if you could achieve all of this with a snippet below?</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">without_timestamping_of Article <span style="color:#9966CC; font-weight:bold;">do</span>
  Factory<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:article</span>, <span style="color:#ff3333; font-weight:bold;">:created_at</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#006666;">1</span>.<span style="color:#9900CC;">week</span>.<span style="color:#9900CC;">ago</span>, <span style="color:#ff3333; font-weight:bold;">:updated_at</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#006666;">1</span>.<span style="color:#9900CC;">week</span>.<span style="color:#9900CC;">ago</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>It turns timestamping off, executes the block and turns timestamping back on. I find it clean and dry. Here&#8217;s the code to place in your test_helper.rb:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># test_helper.rb</span>
<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#CC00FF; font-weight:bold;"><span style="color:#6666ff; font-weight:bold;">Test::Unit::TestCase</span></span> <span style="color:#008000; font-style:italic;"># or class ActiveSupport::TestCase in Rails 2.3.x</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> without_timestamping_of<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">*</span>klasses<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">if</span> block_given?
      klasses.<span style="color:#9900CC;">delete_if</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>klass<span style="color:#006600; font-weight:bold;">|</span> !klass.<span style="color:#9900CC;">record_timestamps</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
      klasses.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>klass<span style="color:#006600; font-weight:bold;">|</span> klass.<span style="color:#9900CC;">record_timestamps</span> = <span style="color:#0000FF; font-weight:bold;">false</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
      <span style="color:#9966CC; font-weight:bold;">begin</span>
        <span style="color:#9966CC; font-weight:bold;">yield</span>
      <span style="color:#9966CC; font-weight:bold;">ensure</span>
        klasses.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>klass<span style="color:#006600; font-weight:bold;">|</span> klass.<span style="color:#9900CC;">record_timestamps</span> = <span style="color:#0000FF; font-weight:bold;">true</span> <span style="color:#006600; font-weight:bold;">&#125;</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></pre></div></div>

<p>Of course you can turn off timestamping for many models at once:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">without_timestamping_of Article, Comment, User <span style="color:#9966CC; font-weight:bold;">do</span>
  Factory<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:article</span>, <span style="color:#ff3333; font-weight:bold;">:created_at</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#006666;">1</span>.<span style="color:#9900CC;">week</span>.<span style="color:#9900CC;">ago</span>, <span style="color:#ff3333; font-weight:bold;">:updated_at</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#006666;">1</span>.<span style="color:#9900CC;">week</span>.<span style="color:#9900CC;">ago</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  Factory<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:comment</span>, <span style="color:#ff3333; font-weight:bold;">:created_at</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#006666;">1</span>.<span style="color:#9900CC;">day</span>.<span style="color:#9900CC;">ago</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  Factory<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:user</span>, <span style="color:#ff3333; font-weight:bold;">:updated_at</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#006666;">5</span>.<span style="color:#9900CC;">hours</span>.<span style="color:#9900CC;">ago</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Hope you like it. If so, share <img src='http://codetunes.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>

<p><a href="http://feedads.g.doubleclick.net/~a/9PD06XM-i6ddPJ7_VXU7MseAsv0/0/da"><img src="http://feedads.g.doubleclick.net/~a/9PD06XM-i6ddPJ7_VXU7MseAsv0/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/9PD06XM-i6ddPJ7_VXU7MseAsv0/1/da"><img src="http://feedads.g.doubleclick.net/~a/9PD06XM-i6ddPJ7_VXU7MseAsv0/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/CodeTunes/~4/p-sLiQt-1nQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://codetunes.com/2009/05/09/turning-off-auto-timestamping-for-testing-in-rails/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://codetunes.com/2009/05/09/turning-off-auto-timestamping-for-testing-in-rails?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=turning-off-auto-timestamping-for-testing-in-rails</feedburner:origLink></item>
		<item>
		<title>Dynamic cookie domains with Rack’s middleware</title>
		<link>http://feedproxy.google.com/~r/CodeTunes/~3/AVIRwqGeQrA/dynamic-cookie-domains-with-racks-middleware</link>
		<comments>http://codetunes.com/2009/04/17/dynamic-cookie-domains-with-racks-middleware#comments</comments>
		<pubDate>Fri, 17 Apr 2009 13:26:52 +0000</pubDate>
		<dc:creator>Michał Szajbe</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[cookies]]></category>
		<category><![CDATA[middleware]]></category>
		<category><![CDATA[multi-domain]]></category>
		<category><![CDATA[rack]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://codetunes.com/?p=117</guid>
		<description><![CDATA[Handling sessions in multi-domain environment is not the simplest things to do, because of the fact that cookies are scoped to a domain they were set by. Recently we were developing an application with such an idea in mind: Application &#8230; <a href="http://codetunes.com/2009/04/17/dynamic-cookie-domains-with-racks-middleware">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Handling sessions in multi-domain environment is not the simplest things to do, because of the fact that cookies are scoped to a domain they were set by.</p>
<p>Recently we were developing an application with such an idea in mind:</p>
<ul>
<li>Application will work as a base for other mini-applications (which we call sites)</li>
<li>Each site can be accessed via different url types: site.example.org and example.org/site</li>
<li>We want the users to remain logged in when switching from one url type to another</li>
</ul>
<p>I won&#8217;t be covering application structure, routing, etc. here, I will only write about maintaing the sessions is such an environment.</p>
<p>So this is pretty simple here &#8211; all that we needed to do was to set cookie domain to <strong>.example.org</strong> (note the &#8220;dot&#8221; at the beginning). This could be done via:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><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;">&quot;.example.org&quot;</span>
<span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>

<p>However there was an additional requirement that we need to deal with:</p>
<ul>
<li>Each site can be accessed via custom domain &#8211; site.com</li>
<li>Of course there&#8217;s no way here to keep the user logged in when he&#8217;s switching from site.com to example.org/site or site.example.org, at least it cannot be done with setting cookie domain to whatever value</li>
</ul>
<p>Technically, to access the site via site.com, that domain must point to our IP address. Then we need to detect that the site is being accessed via custom domain and set cookie domain respectively.</p>
<p>This could be done via some funky before_filters in an Application Controller, however we found much better and cleaner way.</p>
<p><strong>Rack&#8217;s middleware to the rescue</strong></p>
<p>Rack itself is a minimal interface between web server and your ruby framework. It&#8217;s used by Ruby on Rails (since 2.3) and Merb. The request comes from web server, goes through middleware layers and enters the application.</p>
<p>So we wrote a middleware layer that detects the host with which our application is accessed and sets cookie domain for the request. Here it is:</p>
<p><strong>app/middlewares/set_cookie_domain.rb</strong></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> SetCookieDomain
  <span style="color:#9966CC; font-weight:bold;">def</span> initialize<span style="color:#006600; font-weight:bold;">&#40;</span>app, default_domain<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0066ff; font-weight:bold;">@app</span> = app
    <span style="color:#0066ff; font-weight:bold;">@default_domain</span> = default_domain
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> call<span style="color:#006600; font-weight:bold;">&#40;</span>env<span style="color:#006600; font-weight:bold;">&#41;</span>
    host = env<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;HTTP_HOST&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#CC0066; font-weight:bold;">split</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">':'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">first</span>
    env<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;rack.session.options&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:domain</span><span style="color:#006600; font-weight:bold;">&#93;</span> = custom_domain?<span style="color:#006600; font-weight:bold;">&#40;</span>host<span style="color:#006600; font-weight:bold;">&#41;</span> ? <span style="color:#996600;">&quot;.#{host}&quot;</span> : <span style="color:#996600;">&quot;#{@default_domain}&quot;</span>
    <span style="color:#0066ff; font-weight:bold;">@app</span>.<span style="color:#9900CC;">call</span><span style="color:#006600; font-weight:bold;">&#40;</span>env<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> custom_domain?<span style="color:#006600; font-weight:bold;">&#40;</span>host<span style="color:#006600; font-weight:bold;">&#41;</span>
    domain = <span style="color:#0066ff; font-weight:bold;">@default_domain</span>.<span style="color:#CC0066; font-weight:bold;">sub</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span>^\.<span style="color:#006600; font-weight:bold;">/</span>, <span style="color:#996600;">''</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    host !~ <span style="color:#CC00FF; font-weight:bold;">Regexp</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;#{domain}$&quot;</span>, <span style="color:#CC00FF; font-weight:bold;">Regexp</span>::IGNORECASE<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></pre></div></div>

<p>Now we need to turn it on:</p>
<p><strong>environment.rb</strong></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">config.<span style="color:#9900CC;">load_paths</span> <span style="color:#006600; font-weight:bold;">+</span>= <span style="color:#006600; font-weight:bold;">%</span>W<span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#008000; font-style:italic;">#{RAILS_ROOT}/app/middlewares )</span></pre></div></div>

<p><strong>production.rb</strong></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">config.<span style="color:#9900CC;">middleware</span>.<span style="color:#9900CC;">use</span> <span style="color:#996600;">&quot;SetCookieDomain&quot;</span>, <span style="color:#996600;">&quot;.example.org&quot;</span></pre></div></div>

<p>.example.org is the default domain that will be used unless the application is accessed via custom domain (like site.com), we give it different values depending on environment (production/staging/development etc).</p>
<p>And since we&#8217;re fans of test driven development, here&#8217;s the test that ensures us that everything works as expected:</p>
<p><strong>tests/integration/set_cookie_domain_test.rb</strong></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'test_helper'</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> SetCookieDomainTest <span style="color:#006600; font-weight:bold;">&amp;</span>lt; <span style="color:#6666ff; font-weight:bold;">ActionController::IntegrationTest</span>
&nbsp;
  context <span style="color:#996600;">&quot;when accessing site at example.org&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    setup <span style="color:#9966CC; font-weight:bold;">do</span>
      host! <span style="color:#996600;">'example.org'</span>
      visit <span style="color:#996600;">'/'</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    should <span style="color:#996600;">&quot;set cookie_domain to .example.org&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      assert_equal <span style="color:#996600;">'.example.org'</span>, <span style="color:#0066ff; font-weight:bold;">@integration_session</span>.<span style="color:#9900CC;">controller</span>.<span style="color:#9900CC;">request</span>.<span style="color:#9900CC;">session_options</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:domain</span><span style="color:#006600; font-weight:bold;">&#93;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  context <span style="color:#996600;">&quot;when accessing site at site.com&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    setup <span style="color:#9966CC; font-weight:bold;">do</span>
      host! <span style="color:#996600;">'site.com'</span>
      visit <span style="color:#996600;">'/'</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    should <span style="color:#996600;">&quot;set cookie_domain to .site.com&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      assert_equal <span style="color:#996600;">'.site.com'</span>, <span style="color:#0066ff; font-weight:bold;">@integration_session</span>.<span style="color:#9900CC;">controller</span>.<span style="color:#9900CC;">request</span>.<span style="color:#9900CC;">session_options</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:domain</span><span style="color:#006600; font-weight:bold;">&#93;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  context <span style="color:#996600;">&quot;when accessing site at site.example.org&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    setup <span style="color:#9966CC; font-weight:bold;">do</span>
      host! <span style="color:#996600;">'site.example.org'</span>
      visit <span style="color:#996600;">'/'</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    should <span style="color:#996600;">&quot;set cookie_domain to .example.org&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      assert_equal <span style="color:#996600;">'.example.org'</span>, <span style="color:#0066ff; font-weight:bold;">@integration_session</span>.<span style="color:#9900CC;">controller</span>.<span style="color:#9900CC;">request</span>.<span style="color:#9900CC;">session_options</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:domain</span><span style="color:#006600; font-weight:bold;">&#93;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Test is sponsored by great <a title="Shoulda" href="http://thoughtbot.com/projects/shoulda/">Shoulda</a> and <a title="Webrat" href="http://github.com/brynary/webrat/tree/master">Webrat</a> gems.</p>
<p>Feel free to comment and share.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/2gjhNVlk5AZ7AV4DdSDv7-QSkb8/0/da"><img src="http://feedads.g.doubleclick.net/~a/2gjhNVlk5AZ7AV4DdSDv7-QSkb8/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/2gjhNVlk5AZ7AV4DdSDv7-QSkb8/1/da"><img src="http://feedads.g.doubleclick.net/~a/2gjhNVlk5AZ7AV4DdSDv7-QSkb8/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/CodeTunes/~4/AVIRwqGeQrA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://codetunes.com/2009/04/17/dynamic-cookie-domains-with-racks-middleware/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://codetunes.com/2009/04/17/dynamic-cookie-domains-with-racks-middleware?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=dynamic-cookie-domains-with-racks-middleware</feedburner:origLink></item>
	</channel>
</rss><!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Object Caching 935/1043 objects using memcached

Served from: codetunes.com.mh1.monterail.eu @ 2012-02-05 13:12:19 --><!-- W3 Total Cache: Page cache debug info:
Engine:             memcached
Cache key:          w3tc_codetunes.com_1_page_da6f7b5015a12fe724dc34140c8664e0_gzip
Caching:            enabled
Status:             not cached
Creation Time:      0.352s
Header info:
ETag:               "7ee9351905deadbcf9d7e5df70cb1654"
Last-Modified:      Thu, 26 Jan 2012 21:30:49 GMT
Vary:               Accept-Encoding, Cookie
X-Powered-By:       W3 Total Cache/0.9.2.3
Content-Encoding:   gzip
X-Pingback:         http://codetunes.com/xmlrpc.php
Content-Type:       text/xml; charset=UTF-8
-->

