<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Dharana Software</title>
	<atom:link href="http://blog.dharanasoft.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.dharanasoft.com</link>
	<description>We create awesome software</description>
	<lastBuildDate>Wed, 18 Apr 2012 05:06:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='blog.dharanasoft.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://0.gravatar.com/blavatar/4001f41c63b37d4ac63f5b3d8125a6d4?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Dharana Software</title>
		<link>http://blog.dharanasoft.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://blog.dharanasoft.com/osd.xml" title="Dharana Software" />
	<atom:link rel='hub' href='http://blog.dharanasoft.com/?pushpress=hub'/>
		<item>
		<title>A search spider in Ruby using Capybara-webkit.</title>
		<link>http://blog.dharanasoft.com/2012/03/19/a-search-spider-in-ruby-using-capybara-webkit/</link>
		<comments>http://blog.dharanasoft.com/2012/03/19/a-search-spider-in-ruby-using-capybara-webkit/#comments</comments>
		<pubDate>Mon, 19 Mar 2012 03:17:57 +0000</pubDate>
		<dc:creator>Deepak Prasanna</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.dharanasoft.com/?p=309</guid>
		<description><![CDATA[When I first looked at Nokogiri, it was a redefining moment(atleast for me!) on how to screen scrap. Recently I found my love with cucumber and capybara-webkit. For newbies to capybara-webkit, it is a capybara driver which simulates a webkit browser for running tests. Perks? You get a simulated browser running in a headless mode, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.dharanasoft.com&amp;blog=21048031&amp;post=309&amp;subd=dharanasoft&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>When I first looked at <a href="http://nokogiri.org/">Nokogiri</a>, it was a redefining moment(atleast for me!) on how to screen scrap. Recently I found my love with <a href="http://cukes.info/">cucumber</a> and <a href="https://github.com/thoughtbot/capybara-webkit">capybara-webkit</a>. For newbies to capybara-webkit, it is a capybara driver which simulates a webkit browser for running tests. Perks? You get a simulated browser running in a headless mode, it supports javascript and its bloody fast! For more info, please checkout a previous article on <a href="http://blog.dharanasoft.com/2012/01/28/gearing-up-cucumber-and-capybara-for-testing-javascript/">how to get started</a>. I was extremely bored this weekend, and all of a sudden an idea was born. I created a simple search spider using capybara-webkit which would fetch search results from google. And here is how I did it.</p>
<p><pre class="brush: ruby;">
require 'rubygems'
require 'capybara'
require 'capybara/dsl'
require 'capybara-webkit'

Capybara.run_server = false
Capybara.current_driver = :webkit
Capybara.app_host = &quot;http://www.google.com/&quot;

module Spider 
  class Google
    include Capybara::DSL

    def search
    visit('/')
    fill_in &quot;q&quot;, :with =&gt; ARGV[0] || &quot;I love Ruby!&quot;  
    click_button &quot;Google Search&quot;
    all(&quot;li.g h3&quot;).each do |h3| 
      a = h3.find(&quot;a&quot;)
      puts &quot;#{h3.text}  =&gt;  #{a[:href]}&quot;
    end
    end
  end
end

spider = Spider::Google.new
spider.search
</pre></p>
<p>The above code is self explanatory and here is how the results looked.</p>
<p><a href="http://dharanasoft.files.wordpress.com/2012/03/spider.png"><img src="http://dharanasoft.files.wordpress.com/2012/03/spider.png?w=1024&#038;h=261" alt="" title="spider" width="1024" height="261" class="alignnone size-large wp-image-310" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dharanasoft.wordpress.com/309/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dharanasoft.wordpress.com/309/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dharanasoft.wordpress.com/309/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dharanasoft.wordpress.com/309/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dharanasoft.wordpress.com/309/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dharanasoft.wordpress.com/309/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dharanasoft.wordpress.com/309/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dharanasoft.wordpress.com/309/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dharanasoft.wordpress.com/309/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dharanasoft.wordpress.com/309/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dharanasoft.wordpress.com/309/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dharanasoft.wordpress.com/309/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dharanasoft.wordpress.com/309/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dharanasoft.wordpress.com/309/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.dharanasoft.com&amp;blog=21048031&amp;post=309&amp;subd=dharanasoft&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.dharanasoft.com/2012/03/19/a-search-spider-in-ruby-using-capybara-webkit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/28f9b07f601d16896c45b61efdfc6151?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dotrb</media:title>
		</media:content>

		<media:content url="http://dharanasoft.files.wordpress.com/2012/03/spider.png?w=1024" medium="image">
			<media:title type="html">spider</media:title>
		</media:content>
	</item>
		<item>
		<title>Faster loading times with Ruby 1.9.3 and Rails 3.2</title>
		<link>http://blog.dharanasoft.com/2012/02/18/faster-loading-times-with-ruby-1-9-3-and-rails-3-2/</link>
		<comments>http://blog.dharanasoft.com/2012/02/18/faster-loading-times-with-ruby-1-9-3-and-rails-3-2/#comments</comments>
		<pubDate>Sat, 18 Feb 2012 02:57:28 +0000</pubDate>
		<dc:creator>Deepak Prasanna</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.dharanasoft.com/?p=301</guid>
		<description><![CDATA[There are lots of performance improvements which got pushed with the release of Ruby 1.9.3 and Rails 3.2. I am writing about 2 major changes which has improved the Rails bootup time by upto 36% and faster development mode. Problem with Ruby 1.9.2 When you look at the codebase of Rails, it is pretty huge [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.dharanasoft.com&amp;blog=21048031&amp;post=301&amp;subd=dharanasoft&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://dharanasoft.files.wordpress.com/2012/02/matrix.jpg"><img src="http://dharanasoft.files.wordpress.com/2012/02/matrix.jpg?w=590&#038;h=309" alt="" title="matrix" width="590" height="309" class="alignnone size-full wp-image-302" /></a></p>
<p>There are lots of performance improvements which got pushed with the release of Ruby 1.9.3 and Rails 3.2. I am writing about 2 major changes which has improved the Rails bootup time by upto 36% and faster development mode.</p>
<p><strong>Problem with Ruby 1.9.2</strong><br />
When you look at the codebase of Rails, it is pretty huge and it has lot of &#8216;require&#8217; statements hanging around. So what is the problem? We all know that, ruby&#8217;s require statement by itself is quite interesting. How? When you do a require in ruby, ruby will actually require the content only if it is not required before. Which means if your require something which was already required, ruby skips it. Let me show you an example.</p>
<p><a href="http://dharanasoft.files.wordpress.com/2012/02/require.png"><img src="http://dharanasoft.files.wordpress.com/2012/02/require.png?w=590" alt="" title="require"   class="alignnone size-full wp-image-304" /></a></p>
<p>When there were talks on how to improve the rails load time, they found that the problem was with Ruby core itself. The way ruby manages the required file information was quite aweful. Thanks to Xavier for his <a href="https://gist.github.com/996418">patch</a>, which did the magic.</p>
<p><pre class="brush: ruby;">
#ruby 1.9.2 way of requiring the files
def require(file)
  $loaded.each do |x|
    return false if x == file
  end
  load(file)
  $loaded.push(file)
end

#ruby 1.9.3 way of requiring the files
def require(file)
  return false if $loaded[file]
  load(file)
  $loaded[file] = true
end
</pre></p>
<p>The above code represents the rubyish way what actually Xavier&#8217;s patch is actually doing. It was that hash look-up which entirely changed the way ruby handled the require(s) and improved the performance by upto 36%. I did a benchmark by myself, both with 1.9.2 and 1.9.3, and I found it to be pretty fast. Checkout my screenshots below. Awesome! So upgrade to 1.9.3 and get a 36% faster rails bootup time.</p>
<p><a href="http://dharanasoft.files.wordpress.com/2012/02/1-9-2_bm.png"><img src="http://dharanasoft.files.wordpress.com/2012/02/1-9-2_bm.png?w=590" alt="" title="1.9.2_bm"   class="alignnone size-full wp-image-305" /></a></p>
<p><a href="http://dharanasoft.files.wordpress.com/2012/02/1-9-3_bm.png"><img src="http://dharanasoft.files.wordpress.com/2012/02/1-9-3_bm.png?w=590&#038;h=228" alt="" title="1.9.3_bm" width="590" height="228" class="alignnone size-full wp-image-306" /></a></p>
<p><strong>Faster development mode in Rails 3.2</strong><br />
Atlast I am happy that it was not just me who got pissed of with slower developement mode in Rails. <a href="https://github.com/paneq/active_reload">ActiveReload</a> is the new candidate in Rails 3.2 which fastens your development mode. How? Well Rails is little stupid, it just forgets the code it executed after it processed the request. For the next request Rails again loads your code entirely. I hope you know this is how you have been skipping your server restart in dev. Now the big deal is imagine if you have changed only 1 out of 10 models, Rails is going to load all the 10 models again for the next request. ActiveReload does something interesting, it tells rails to reload only the files which has changed. So only the changed file gets loaded again. Thats cool!! Checkout Rails 3.2 release notes for further information. Happy coding. </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dharanasoft.wordpress.com/301/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dharanasoft.wordpress.com/301/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dharanasoft.wordpress.com/301/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dharanasoft.wordpress.com/301/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dharanasoft.wordpress.com/301/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dharanasoft.wordpress.com/301/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dharanasoft.wordpress.com/301/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dharanasoft.wordpress.com/301/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dharanasoft.wordpress.com/301/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dharanasoft.wordpress.com/301/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dharanasoft.wordpress.com/301/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dharanasoft.wordpress.com/301/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dharanasoft.wordpress.com/301/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dharanasoft.wordpress.com/301/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.dharanasoft.com&amp;blog=21048031&amp;post=301&amp;subd=dharanasoft&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.dharanasoft.com/2012/02/18/faster-loading-times-with-ruby-1-9-3-and-rails-3-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/28f9b07f601d16896c45b61efdfc6151?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dotrb</media:title>
		</media:content>

		<media:content url="http://dharanasoft.files.wordpress.com/2012/02/matrix.jpg" medium="image">
			<media:title type="html">matrix</media:title>
		</media:content>

		<media:content url="http://dharanasoft.files.wordpress.com/2012/02/require.png" medium="image">
			<media:title type="html">require</media:title>
		</media:content>

		<media:content url="http://dharanasoft.files.wordpress.com/2012/02/1-9-2_bm.png" medium="image">
			<media:title type="html">1.9.2_bm</media:title>
		</media:content>

		<media:content url="http://dharanasoft.files.wordpress.com/2012/02/1-9-3_bm.png" medium="image">
			<media:title type="html">1.9.3_bm</media:title>
		</media:content>
	</item>
		<item>
		<title>cancan permissions on backbone.js</title>
		<link>http://blog.dharanasoft.com/2012/02/17/cancan-permissions-on-backbone-js/</link>
		<comments>http://blog.dharanasoft.com/2012/02/17/cancan-permissions-on-backbone-js/#comments</comments>
		<pubDate>Fri, 17 Feb 2012 11:55:56 +0000</pubDate>
		<dc:creator>Deepak Prasanna</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.dharanasoft.com/?p=298</guid>
		<description><![CDATA[Writing a plugin/gem which does authorization is quite challenging, especially when it comes to a multi-tenant application, it is quite complicated. Sometime back we wrote a plugin overriding authlogic, which takes of both authentication and setting up authorization rules for a user. We called it watchman. Its pretty old now. And then we found our [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.dharanasoft.com&amp;blog=21048031&amp;post=298&amp;subd=dharanasoft&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Writing a plugin/gem which does authorization is quite challenging, especially when it comes to a multi-tenant application, it is quite complicated. Sometime back we wrote a plugin overriding <a href="https://github.com/binarylogic/authlogic">authlogic</a>, which takes of both authentication and setting up authorization rules for a user. We called it <a href="https://github.com/artha42/watchman/">watchman</a>. Its pretty old now. And then we found our love with <a href="https://github.com/ryanb/cancan">cancan</a>. While working on a <a href="http://documentcloud.github.com/backbone/">backbone.js</a> project, we needed the use of the <a href="http://rubydoc.info/github/ryanb/cancan/master/CanCan/ControllerAdditions#can%3F-instance_method">can?</a> method provided by cancan on the javascript layer.And that application involved user permissions which are controlled by a site admin for different roles. Basically we store the permissions on the database with a set of Booleans. First approach was to write a javascript helper which will do an ajax call and find out of the access. It was slowwwwwwwwwwwwwww.The next approach was to create a backbone model which holds the permissions. It worked really well!! An example on how we did that.</p>
<p><pre class="brush: ruby;">
//views/layouts/application.html.haml
:javascript
  -if current_user
    :javascript
      $(document).ready(function() {
        window.Permission = Backbone.Model.extend({
          defaults: {
          &quot;canDestroyBlog&quot;: #{can? :destroy, Blog},
          &quot;canCreateComment&quot;: #{can? :create, Comment},
          &quot;canEditComment&quot;: #{can? :edit, Comment},
          &quot;canCreateProject&quot;: #{can? :create, Project},
          &quot;canViewProject&quot;: #{can? :view, Project}
          }
        });
      }); 
</pre></p>
<p><pre class="brush: jscript;">
//in your javascript
permission = new window.Permission
permission.attributes.canEditComment
=&gt; true

permission.attributes.canCreateProject
=&gt; false
</pre></p>
<p>PS: The permissions don&#8217;t get updated unless there is a page refresh at the user side.<br />
This may not be a perfect solution, but it reduces much noise and complexity at the javascript layer.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dharanasoft.wordpress.com/298/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dharanasoft.wordpress.com/298/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dharanasoft.wordpress.com/298/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dharanasoft.wordpress.com/298/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dharanasoft.wordpress.com/298/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dharanasoft.wordpress.com/298/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dharanasoft.wordpress.com/298/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dharanasoft.wordpress.com/298/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dharanasoft.wordpress.com/298/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dharanasoft.wordpress.com/298/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dharanasoft.wordpress.com/298/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dharanasoft.wordpress.com/298/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dharanasoft.wordpress.com/298/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dharanasoft.wordpress.com/298/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.dharanasoft.com&amp;blog=21048031&amp;post=298&amp;subd=dharanasoft&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.dharanasoft.com/2012/02/17/cancan-permissions-on-backbone-js/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/28f9b07f601d16896c45b61efdfc6151?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dotrb</media:title>
		</media:content>
	</item>
		<item>
		<title>Git bisect is my friend</title>
		<link>http://blog.dharanasoft.com/2012/02/11/git-bisect-is-my-friend/</link>
		<comments>http://blog.dharanasoft.com/2012/02/11/git-bisect-is-my-friend/#comments</comments>
		<pubDate>Sat, 11 Feb 2012 05:01:52 +0000</pubDate>
		<dc:creator>Deepak Prasanna</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.dharanasoft.com/?p=269</guid>
		<description><![CDATA[Recently when I did a merge on one of my projects, large number of commits got merged. I found that my tests were broken. It became a tedious task for me to find out which commit exactly broke the tests among those which got merged. Into the scene: Vagmi Mudumbai(CTO of Dharana) &#8220;Git-bisect should be [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.dharanasoft.com&amp;blog=21048031&amp;post=269&amp;subd=dharanasoft&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Recently when I did a merge on one of my projects, large number of commits got merged. I found that my tests were broken. It became a tedious task for me to find out which commit exactly broke the tests among those which got merged.</p>
<p>Into the scene: Vagmi Mudumbai(CTO of Dharana)</p>
<blockquote><p>&#8220;Git-bisect should be your friend.&#8221;</p></blockquote>
<p>I have never tried git-bisect, I thought I will give a try. Tasting the sweet of awesomeness. Git-bisect takes in a good commit(a commit where your tests passed) and a bad commit(a commit where your tests failed, mostly HEAD). Git-bisect allows you to run tests in between your commits and will ask you to mark them good or bad based on which you can narrow down your search. Aaahh, now I see you remember binary search!!!! Yeah, thats exactly what git-bisect does and here is how you do it.</p>
<p><pre class="brush: bash;">
$ git bisect start
$ git bisect good 9ef9b9a64a
$ git bisect bad b5e38ab73b
&gt; Bisecting: 60 revisions left to test after this (roughly 6 steps)
</pre></p>
<p>What happens now is little interesting, git will put you on to a &#8216;bisect&#8217; branch that is somewhere in between your good and bad commit. Now all you have do is to run the tests and find out if it still fails or not. Lets assume your tests failed, so you have to tell git that this commit is bad.(If it passes you have to say its good.)</p>
<p><pre class="brush: bash;">
$ git bisect bad
&gt; Bisecting: 29 revisions left to test after this (roughly 5 steps)
</pre></p>
<p>You have now got a different commit to test, and you have only 29 commits left to check. The idea is to make you not to step through every single commit to find that bad commit. Now run the tests again and tell git if this commit is good or bad. When you continue doing this you will eventually find out the commit which broke the tests, and wait git will also estimate how many steps are roughly required to find out that bad commit. Awesome!!!!!</p>
<p><pre class="brush: bash;">
&gt; 6247d67284798e40182034500305b282dccf4a6a is the first bad commit
</pre></p>
<p>Tadaaaaa, now you can go and fight with that guy who broke all your tests. Finally if you see that your boss was the one who broke your tests, and you want to go back to current state and fix it all by yourself, you have to say,</p>
<p><pre class="brush: bash;">$ git bisect reset
</pre></p>
<p>Happy fighting, happy testing.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dharanasoft.wordpress.com/269/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dharanasoft.wordpress.com/269/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dharanasoft.wordpress.com/269/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dharanasoft.wordpress.com/269/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dharanasoft.wordpress.com/269/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dharanasoft.wordpress.com/269/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dharanasoft.wordpress.com/269/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dharanasoft.wordpress.com/269/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dharanasoft.wordpress.com/269/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dharanasoft.wordpress.com/269/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dharanasoft.wordpress.com/269/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dharanasoft.wordpress.com/269/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dharanasoft.wordpress.com/269/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dharanasoft.wordpress.com/269/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.dharanasoft.com&amp;blog=21048031&amp;post=269&amp;subd=dharanasoft&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.dharanasoft.com/2012/02/11/git-bisect-is-my-friend/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/28f9b07f601d16896c45b61efdfc6151?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dotrb</media:title>
		</media:content>
	</item>
		<item>
		<title>Cucumber + Capybara show rails exceptions</title>
		<link>http://blog.dharanasoft.com/2012/02/08/cucumber-capybara-show-rails-exceptions/</link>
		<comments>http://blog.dharanasoft.com/2012/02/08/cucumber-capybara-show-rails-exceptions/#comments</comments>
		<pubDate>Wed, 08 Feb 2012 06:06:39 +0000</pubDate>
		<dc:creator>Deepak Prasanna</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.dharanasoft.com/?p=259</guid>
		<description><![CDATA[Whenever there is an exception that is raised in Rails, Capybara will show only a blank page on the simulated browser. It becomes quite difficult to find out what went wrong. To get the exception on your console while running the test, just this patch to your features/support/env.rb. Happy testing.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.dharanasoft.com&amp;blog=21048031&amp;post=259&amp;subd=dharanasoft&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Whenever there is an exception that is raised in Rails, Capybara will show only a blank page on the simulated browser. It becomes quite difficult to find out what went wrong. To get the exception on your console while running the test, just this patch to your <strong>features/support/env.rb</strong>.</p>
<p><pre class="brush: ruby;">
#If your running mongrel
Capybara.server do |app, port|
  require 'rack/handler/mongrel'
  Rack::Handler::Mongrel.run(app, : Port =&amp;gt; port)
end

#If your are running thin
module Thin::Logging
  def log_error(e=$!)
    STDERR.print &quot;#{e}\n\t&quot; + e.backtrace.join(&quot;\n\t&quot;)
  end
end
</pre></p>
<p>Happy testing.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dharanasoft.wordpress.com/259/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dharanasoft.wordpress.com/259/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dharanasoft.wordpress.com/259/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dharanasoft.wordpress.com/259/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dharanasoft.wordpress.com/259/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dharanasoft.wordpress.com/259/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dharanasoft.wordpress.com/259/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dharanasoft.wordpress.com/259/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dharanasoft.wordpress.com/259/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dharanasoft.wordpress.com/259/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dharanasoft.wordpress.com/259/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dharanasoft.wordpress.com/259/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dharanasoft.wordpress.com/259/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dharanasoft.wordpress.com/259/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.dharanasoft.com&amp;blog=21048031&amp;post=259&amp;subd=dharanasoft&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.dharanasoft.com/2012/02/08/cucumber-capybara-show-rails-exceptions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/28f9b07f601d16896c45b61efdfc6151?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dotrb</media:title>
		</media:content>
	</item>
		<item>
		<title>Cucumber + Capybara driver gotchas</title>
		<link>http://blog.dharanasoft.com/2012/02/08/cucumber-capybara-driver-gotchas/</link>
		<comments>http://blog.dharanasoft.com/2012/02/08/cucumber-capybara-driver-gotchas/#comments</comments>
		<pubDate>Wed, 08 Feb 2012 03:42:15 +0000</pubDate>
		<dc:creator>Deepak Prasanna</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.dharanasoft.com/?p=239</guid>
		<description><![CDATA[Cucumber and Capybara has always been our best buddies when it comes to writing integration tests. We use it quite actively on most of our projects. The power of Capybara is that it gives you options for several browser simulators, equipping you with a flexible toolkit for testing all parts of your application, from the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.dharanasoft.com&amp;blog=21048031&amp;post=239&amp;subd=dharanasoft&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Cucumber and Capybara has always been our best buddies when it comes to writing integration tests. We use it quite actively on most of our projects. The power of Capybara is that it gives you options for several browser simulators, equipping you with a flexible toolkit for testing all parts of your application, from the simplest to the most complex pages and also with javascript heavy pages.</p>
<p>Capybara comes with &#8220;rack_test&#8221; as the default driver which doesn&#8217;t support javascript. I am not going to talk much about which driver to choose, it is upto you based on your need. You can change which driver you want to use in <strong>features/support/env.rb</strong>. It can be quite confusing when you find out there are 3 different Capybara settings can play around different drivers while running the test.</p>
<blockquote><p><code>#Driver settings<br />
Capybara.default_driver(uses rack_test as default)<br />
Capybara.javascript_driver(uses selenium as default)<br />
Capybara.current_driver</code></p>
<p>#features/sample.feature<br />
Scenario: Creating a user<br />
Given I go to the new user page<br />
And I fill in &#8220;Name&#8221; with &#8220;TDD Ninja&#8221;<br />
And I fill in &#8220;Email&#8221; with &#8220;gmail@ninja.com&#8221;<br />
And I press &#8220;Create&#8221;<br />
Then I should see &#8220;User created&#8221;</p>
<p>@javascript<br />
Scenario: AJAX pagination<br />
Given 10 blogs exist<br />
When I go to the blogs page<br />
Then I should see 5 blogs<br />
When I follow &#8220;More&#8221;<br />
Then I should see 10 blogs</p></blockquote>
<p>In the above example, the first scenario runs with &#8216;rack_test&#8217; and the second scenario runs with &#8220;selenium&#8221;. Suppose you want to set :webkit as your javascript driver, all you have to do is to set</p>
<blockquote><p>Capybara.javascript_driver = :webkit</p></blockquote>
<p>And from then on whenever you use @javascript in your scenario, Capybara will use <strong>:webkit</strong> as its javascript_driver instead of <strong>:selenium</strong>. Capybara also allows you to change your driver temporarily using <strong>Capybara.current_driver</strong> setting.</p>
<blockquote><p><code>Capybara.current_driver = :webkit # temporarily select different driver<br />
... tests ...<br />
Capybara.use_default_driver # switch back to default driver</code></p></blockquote>
<p>Please note that switching between drivers will create a new session, so make sure where you switch! The ideal place its to switch in the Before hook. Capybara makes it really convenient to switch between the drivers. Apart from that you can also tweek with your own settings using the API it exposes. This is how we tweeked and made selenium to use chrome.</p>
<blockquote><p><code>#features/support/env.rb</code></p>
<p>Capybara.register_driver :selenium_chrome do |app|<br />
Capybara::Selenium::Driver.new(app, :browser =&gt; :chrome)<br />
end</p>
<p>Capybara.javascript_driver = :selenium_chrome</p></blockquote>
<p>There are tons of other information in <a href="http://code.google.com/p/selenium/wiki/RubyBindings">Selenium wiki</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dharanasoft.wordpress.com/239/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dharanasoft.wordpress.com/239/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dharanasoft.wordpress.com/239/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dharanasoft.wordpress.com/239/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dharanasoft.wordpress.com/239/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dharanasoft.wordpress.com/239/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dharanasoft.wordpress.com/239/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dharanasoft.wordpress.com/239/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dharanasoft.wordpress.com/239/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dharanasoft.wordpress.com/239/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dharanasoft.wordpress.com/239/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dharanasoft.wordpress.com/239/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dharanasoft.wordpress.com/239/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dharanasoft.wordpress.com/239/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.dharanasoft.com&amp;blog=21048031&amp;post=239&amp;subd=dharanasoft&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.dharanasoft.com/2012/02/08/cucumber-capybara-driver-gotchas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/28f9b07f601d16896c45b61efdfc6151?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dotrb</media:title>
		</media:content>
	</item>
		<item>
		<title>Gearing up cucumber and capybara for testing javascript.</title>
		<link>http://blog.dharanasoft.com/2012/01/28/gearing-up-cucumber-and-capybara-for-testing-javascript/</link>
		<comments>http://blog.dharanasoft.com/2012/01/28/gearing-up-cucumber-and-capybara-for-testing-javascript/#comments</comments>
		<pubDate>Sat, 28 Jan 2012 10:23:04 +0000</pubDate>
		<dc:creator>Deepak Prasanna</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.dharanasoft.com/?p=225</guid>
		<description><![CDATA[With the explosion of rich internet applications, the usage of javascript is kind of becoming mandatory  for all of the web applications these days. We at Dharana, work extensively on backbone.js which is a javascript MVC framework. While we worked on backbone.js, we also found that writing a tests for javascript can be extremely exciting and challenging. Being a cucumber and capybara fan [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.dharanasoft.com&amp;blog=21048031&amp;post=225&amp;subd=dharanasoft&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>With the explosion of rich internet applications, the usage of javascript is kind of becoming mandatory  for all of the web applications these days. We at Dharana, work extensively on <a href="http://documentcloud.github.com/backbone/">backbone.js</a> which is a javascript MVC framework. While we worked on backbone.js, we also found that writing a tests for javascript can be extremely exciting and challenging. Being a <a href="http://cukes.info/">cucumber</a> and <a href="https://github.com/jnicklas/capybara">capybara</a> fan boys, we looked at many solutions like <a href="http://seleniumhq.org/">selenium</a>, <a href="http://github.com/langalex/culerity">celerity</a>, <a href="http://celerity.rubyforge.org/">culerity</a>, <a href="http://www.envjs.com/">envjs</a>, <a href="https://github.com/bernerdschaefer/akephalos">akephalos</a> browser simulators which supports javascript.</p>
<p>We found selenium to work well with our previous projects. But the problem with selenium is that, it is little heavy and most of all it simulates the entire browser on the GUI which makes it extremely slow. Thanks to <a href="https://github.com/thoughtbot">thoughtbot</a> for releasing the <a href="https://github.com/thoughtbot/capybara-webkit">capybara-webkit</a>. Capybara-webkit is just a rendering engine coupled with a DOM implementation and full javascript support. And it runs on a headless mode(no GUI). Here is why you should capybara-webkit,</p>
<p>1. Runs bloody fast.</p>
<p>2. Runs on a headless mode.</p>
<p>3. console.log support. You can see the javascript console.log outputs while running the tests from your  console.</p>
<p>4. Uses webkit.</p>
<p>5. Setting up is super easy.</p>
<p><code><br />
capybara-webkit depends on qtwebkit, make sure you have qtwebkit before you install capybara-webkit.<br />
qtwebkit:<br />
apt-get install libqt4-dev libqtwebkit-dev</code></p>
<p><code><br />
Gemfile:<br />
capybara-webkit</code></p>
<p><code><br />
features/support/env:<br />
Capybara.javascript_driver = :webkit</code></p>
<p>In my next post I will probably write about some useful tips which I learnt during writing javascript tests. Thanks.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dharanasoft.wordpress.com/225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dharanasoft.wordpress.com/225/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dharanasoft.wordpress.com/225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dharanasoft.wordpress.com/225/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dharanasoft.wordpress.com/225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dharanasoft.wordpress.com/225/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dharanasoft.wordpress.com/225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dharanasoft.wordpress.com/225/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dharanasoft.wordpress.com/225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dharanasoft.wordpress.com/225/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dharanasoft.wordpress.com/225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dharanasoft.wordpress.com/225/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dharanasoft.wordpress.com/225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dharanasoft.wordpress.com/225/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.dharanasoft.com&amp;blog=21048031&amp;post=225&amp;subd=dharanasoft&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.dharanasoft.com/2012/01/28/gearing-up-cucumber-and-capybara-for-testing-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/28f9b07f601d16896c45b61efdfc6151?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dotrb</media:title>
		</media:content>
	</item>
		<item>
		<title>Polymorphic Many-to-Many Associations in Rails</title>
		<link>http://blog.dharanasoft.com/2011/09/06/polymorphic-many-to-many-associations-in-rails/</link>
		<comments>http://blog.dharanasoft.com/2011/09/06/polymorphic-many-to-many-associations-in-rails/#comments</comments>
		<pubDate>Tue, 06 Sep 2011 12:44:54 +0000</pubDate>
		<dc:creator>ramachandranv</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://blog.dharanasoft.com/?p=208</guid>
		<description><![CDATA[Rails has various Active Record associations that can be defined between models. First of all why do we need associations between models? Association between models helps us to perform certain common operations very simple and easy in our Rails code. Basically Rails supports six types of Associations namely: belongs_to has_one has_one :through has_many has_many :through [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.dharanasoft.com&amp;blog=21048031&amp;post=208&amp;subd=dharanasoft&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Rails has various Active Record associations that can be defined between models.</p>
<p>First of all why do we need associations between models? Association between models helps us to perform certain common operations very simple and easy in our Rails code.</p>
<p>Basically Rails supports six types of Associations namely:</p>
<ul>
<li>belongs_to</li>
<li>has_one</li>
<li>has_one :through</li>
<li>has_many</li>
<li>has_many :through</li>
<li>has_and_belongs_to_many</li>
</ul>
<p>In the above <strong>has_many</strong> and <strong>belongs_to</strong> associations are both commonly used Active Record associations in Rails.</p>
<p>Recently I learnt one more association in Rails which is known as Polymorphic association. I found it very interesting and would like to share it.</p>
<p><strong>Polymorphic Association</strong></p>
<p>In polymorphic association a model belong to more than one other model on a single association.</p>
<p>In one of the project which I was working on, I had to implement polymorphic many-to-many association between the models. The implementation of polymorphic many-to-many association in Rails is very simple.</p>
<p>Let me explain about polymorphic many-to-many association with an simple example.</p>
<p>Consider an example application which has two models namely <strong>Book</strong> and <strong>Article</strong>. These two models are associated to a common model called <strong>Tag</strong>. Book and Article has many tags. But a tag can have many books and also a tag can have many articles. In this case we have many-to-many relationship.</p>
<p>The implementation of above scenario will be like below.</p>
<p>First we have the models <strong>Book</strong> and <strong>Article</strong></p>
<p><pre class="brush: ruby;">

class Book &lt; ActiveRecord::Base

has_many :tags, :through =&gt; :taggings

has_many :taggings, :through =&gt; :taggable

end

class Article &lt; ActiveRecord::Base

has_many :tags, :through =&gt; :taggings

has_many :taggings, :through =&gt; :taggable

end

</pre></p>
<p>Then we have the <strong>Tag</strong> model</p>
<p><pre class="brush: ruby;">

class Tag &lt; ActiveRecord::Base

has_many :books, :through =&gt; :taggings, :source =&gt; :taggable, :source_type =&gt; &quot;Book&quot;

has_many :articles, :through =&gt; :taggings, :source =&gt; :taggable, :source_type =&gt; &quot;Article&quot;

has_many :taggings

end

</pre></p>
<p>Finally we have our join model <strong>Tagging</strong></p>
<p><pre class="brush: ruby;">

class Tagging &lt; ActiveRecord::Base

belongs_to :tag

belongs_to :taggable, :polymorphic =&gt; true

end

</pre></p>
<p>From the above implementation we can access tags of books and articles as</p>
<p><pre class="brush: ruby;">

book.tags

article.tags

</pre></p>
<p>We can also access the books and articles based on a tag</p>
<p><pre class="brush: ruby;">

tag.books

tag.articles

</pre></p>
<p>We can also get the taggings and taggable of a tag</p>
<p><pre class="brush: ruby;">

tag.taggings

tag.taggable

</pre></p>
<p>In the above example we have join model which has the fields namely <strong>name, taggable_id and taggable_type</strong>. The <strong>taggable_type</strong> field defines that to which model the tag is associated.</p>
<p>Finally let me explain how we get books or articles with respect to a tag. In tag model we have defined has_many relations to books and articles. But there are other options mentioned.</p>
<p>The <strong>:through</strong> option defines through which model we can access the books or articles. In the above example it is <strong>taggings</strong>.</p>
<p>The <strong>:source</strong> option tells the Rails to consider the taggable association instead of expecting an association on taggings.</p>
<p>The <strong>:source_type</strong> specifies the class of type of polymorphic association that we want to retrieve.</p>
<p>The above is an simple example explaining the implementation of polymorphic many-to-many association in Rails. I hope the above article is interesting and useful.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dharanasoft.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dharanasoft.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dharanasoft.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dharanasoft.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dharanasoft.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dharanasoft.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dharanasoft.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dharanasoft.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dharanasoft.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dharanasoft.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dharanasoft.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dharanasoft.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dharanasoft.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dharanasoft.wordpress.com/208/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.dharanasoft.com&amp;blog=21048031&amp;post=208&amp;subd=dharanasoft&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.dharanasoft.com/2011/09/06/polymorphic-many-to-many-associations-in-rails/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8a27f3c4d0e00c23748a77fcaf2a7bd4?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ramachandranv</media:title>
		</media:content>
	</item>
		<item>
		<title>Sending Meeting Requests with Rails and Action Mailer</title>
		<link>http://blog.dharanasoft.com/2011/08/18/sending-meeting-requests-with-rails/</link>
		<comments>http://blog.dharanasoft.com/2011/08/18/sending-meeting-requests-with-rails/#comments</comments>
		<pubDate>Thu, 18 Aug 2011 07:39:53 +0000</pubDate>
		<dc:creator>Dhiren Gupta</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.dharanasoft.com/?p=193</guid>
		<description><![CDATA[As a part of our Recruitment Tracking Solution, we send interview appointments as meeting requests to integrate with various calendar solutions like Outlook, Apple iCal and Google Calendar. If you want to send a meeting request through email, you can do it in two ways. First, you can directly mention the meeting date and time [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.dharanasoft.com&amp;blog=21048031&amp;post=193&amp;subd=dharanasoft&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>As a part of our <a title="Keep Recruiting" href="http://www.keeprecruiting.com/" target="_blank">Recruitment Tracking Solution</a>, we send interview appointments as meeting requests to integrate with various calendar solutions like Outlook, Apple iCal and Google Calendar.</p>
<p>If you want to send a meeting request through email, you can do it in two ways. First, you can directly mention the meeting date and time in the email body which people do it usually. Second, you can send a calendar request along with the email which looks like this</p>
<p><a href="http://dhirengupta.files.wordpress.com/2011/08/screenshot-2.png"><img title="Screenshot-2" src="http://dhirengupta.files.wordpress.com/2011/08/screenshot-2.png?w=640&#038;h=207" alt="" width="640" height="207" /></a></p>
<p>Isn&#8217;t it cool!!</p>
<p>To implement this in ruby on rails, you need icalendar gem, a ruby library for dealing with icalendar files having extension .ics. It&#8217;s pretty simple to implement. Add the following line in your gemfile</p>
<p><pre class="brush: ruby;">gem 'icalendar'</pre></p>
<p>then run bundle</p>
<p>Suppose you have a mailer MeetingNotification, you would just need to add the format.ics block as mentioned below</p>
<p><pre class="brush: ruby;">
class MeetingNotification &lt; ActionMailer::Base
   def meeting_request_with_calendar
     mail(:to =&gt; &quot;any_email@example.com&quot;, :subject =&gt; &quot;iCalendar&quot;,
                  :from =&gt; &quot;any_email@example.com&quot;) do |format|
       format.ics {
       ical = Icalendar::Calendar.new
       e = Icalendar::Event.new
       e.start = DateTime.now.utc
       e.start.icalendar_tzid=&quot;UTC&quot; # set timezone as &quot;UTC&quot;
       e.end = (DateTime.now + 1.day).utc
       e.end.icalendar_tzid=&quot;UTC&quot;
       e.organizer &quot;any_email@example.com&quot;
       e.uid &quot;MeetingRequest#{unique_value}&quot;
       e.summary &quot;Scrum Meeting&quot;
       e.description &lt;&lt;-EOF
         Venue: Office
         Date: 16 August 2011
         Time: 10 am
       EOF
       ical.add_event(e)
       i cal.publish
       ical.to_ical
       render :text =&gt; ical, :layout =&gt; false
      }
    end
  end
end

</pre></p>
<p>If you want to know little more about  how it happens, then lets delve into this. If you run the above code in rails console, you would see</p>
<p><a href="http://dhirengupta.files.wordpress.com/2011/08/screenshot-1.png"><img title="Screenshot-1" src="http://dhirengupta.files.wordpress.com/2011/08/screenshot-1.png?w=605&#038;h=671" alt="" width="605" height="671" /></a></p>
<p>It&#8217;s almost self explanatory. Although I would like to point out few things like the<em> DTEND and DTSTART which has Z(indicates UTC)</em> appended, it&#8217;s there because we have set the timezone to UTC.</p>
<p>iCalendar auto-generates UID with value as combination of date and time. But recently Google has updated it&#8217;s code and  it does not parse it properly. So you have to explicitly add UID . Also You should add unique value to e.uid like <em>&#8220;MeetingRequest-#{unique_value}&#8221;</em> inorder to distinguish between the request you send and update otherwise you might end up messing up the wrong request.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dharanasoft.wordpress.com/193/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dharanasoft.wordpress.com/193/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dharanasoft.wordpress.com/193/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dharanasoft.wordpress.com/193/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dharanasoft.wordpress.com/193/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dharanasoft.wordpress.com/193/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dharanasoft.wordpress.com/193/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dharanasoft.wordpress.com/193/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dharanasoft.wordpress.com/193/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dharanasoft.wordpress.com/193/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dharanasoft.wordpress.com/193/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dharanasoft.wordpress.com/193/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dharanasoft.wordpress.com/193/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dharanasoft.wordpress.com/193/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.dharanasoft.com&amp;blog=21048031&amp;post=193&amp;subd=dharanasoft&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.dharanasoft.com/2011/08/18/sending-meeting-requests-with-rails/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6d8a60ec037e700817356fa5ceccbd71?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dhirengupta</media:title>
		</media:content>

		<media:content url="http://dhirengupta.files.wordpress.com/2011/08/screenshot-2.png" medium="image">
			<media:title type="html">Screenshot-2</media:title>
		</media:content>

		<media:content url="http://dhirengupta.files.wordpress.com/2011/08/screenshot-1.png" medium="image">
			<media:title type="html">Screenshot-1</media:title>
		</media:content>
	</item>
		<item>
		<title>Fasten your TDD red-green-refactor cycles</title>
		<link>http://blog.dharanasoft.com/2011/07/26/fasten-your-tdd-red-green-refactor-cycles/</link>
		<comments>http://blog.dharanasoft.com/2011/07/26/fasten-your-tdd-red-green-refactor-cycles/#comments</comments>
		<pubDate>Tue, 26 Jul 2011 13:27:10 +0000</pubDate>
		<dc:creator>Dhruva Sagar</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.dharanasoft.com/?p=166</guid>
		<description><![CDATA[Having recently been bit by the TDD bug, I&#8217;ve been researching a lot about best practices when it comes to testing and speeding up the red-green-refactor process and I recently came across a really neat way to fasten the cycles further. Guard - is a command line tool that allows you to handle events on file modifications. What that [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.dharanasoft.com&amp;blog=21048031&amp;post=166&amp;subd=dharanasoft&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Having recently been bit by the TDD bug, I&#8217;ve been researching a lot about best practices when it comes to testing and speeding up the red-green-refactor process and I recently came across a really neat way to fasten the cycles further.</p>
<p><a title="Guard" href="http://github.com/guard/guard" target="_blank">Guard</a> - is a command line tool that allows you to handle events on file modifications. What that means is you can essentially configure it to monitor for modifications to specific files on your file system and perform corresponding actions. It is a great utility and can be used for carrying out a wide variety of actions.</p>
<p>There is a big list of &#8216;Guards&#8217; available, which are essentially extensions for guard to guard specific types of files, you can find the list here in the <a title="Guard Wiki" href="https://github.com/guard/guard/wiki/List-of-available-Guards" target="_blank">Guard Wiki</a></p>
<p>Installation :</p>
<p>I would recommend you to use bundler to maintain your gem dependies, if you are doing so, simply add the following in your Gemfile</p>
<p><pre class="brush: ruby; wrap-lines: false;">
gem 'guard'
gem 'guard-rspec'
gem 'guard-cucumber'

gem 'rb-inotify'
gem 'libnotify' # This is optional for notifications on linux, for other OS' please look at https://github.com/guard/guard#readme for details for other OS'
</pre></p>
<p>Or if you&#8217;re not using bundler, simply install the above mentioned gems<br />
manually. After having done that you can perform the following steps to setup<br />
guard and configure it for both rspec &amp; cucumber</p>
<p><pre class="brush: bash; wrap-lines: false;">
    $ guard init          # This creates an empty Guardfile in the project's root, which it uses for configurations.
    $ guard init rspec    # This adds rspec guard to the Guardfile
    $ guard init cucumber # This adds cucumber guard to the Guardfile
</pre></p>
<p>If you now look at your Guardfile, you will see something like this :</p>
<p><pre class="brush: ruby; wrap-lines: false;">
    # A sample Guardfile
    # More info at https://github.com/guard/guard#readme

    guard 'cucumber' do
      watch(%r{^features/.+\.feature$})
      watch(%r{^features/support/.+$}) { 'features' }
      watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join(&quot;**/#{m[1]}.feature&quot;)][0] || 'features' }
    end

    guard 'rspec', :version =&gt; 2 do
      watch(%r{^spec/.+_spec\.rb$})
      watch(%r{^lib/(.+)\.rb$}) { |m| &quot;spec/lib/#{m[1]}_spec.rb&quot; }
      watch('spec/spec_helper.rb') { &quot;spec&quot; }

      # Rails example
      watch(%r{^spec/.+_spec\.rb$})
      watch(%r{^app/(.+)\.rb$}) { |m| &quot;spec/#{m[1]}_spec.rb&quot; }
      watch(%r{^lib/(.+)\.rb$}) { |m| &quot;spec/lib/#{m[1]}_spec.rb&quot; }
      watch(%r{^app/controllers/(.+)_(controller)\.rb$})  { |m| [&quot;spec/routing/#{m[1]}_routing_spec.rb&quot;, &quot;spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb&quot;, &quot;spec/acceptance/#{m[1]}_spec.rb&quot;] }
      watch(%r{^spec/support/(.+)\.rb$}) { &quot;spec&quot; }
      watch('spec/spec_helper.rb') { &quot;spec&quot; }
      watch('config/routes.rb') { &quot;spec/routing&quot; }
      watch('app/controllers/application_controller.rb') { &quot;spec/controllers&quot; } # Capybara request specs
      watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| &quot;spec/requests/#{m[1]}_spec.rb&quot; }
    end
</pre></p>
<p>The Guardfile is quite self-explanatory, but you can have a look at<br />
<a title="Guard Readme" href="https://github.com/guard/guard#readme" target="_blank"> https://github.com/guard/guard#readme</a> for more details.</p>
<p>After having done that, all you need to do is start guard by issuing :</p>
<p><pre class="brush: bash;">
guard [start] # start is optional
</pre></p>
<p>Now whenever you create or modify either your spec or cucumber feature files, guard will automatically run the tests for your for the individual file that has been modified / added. This is really cool since all you need to do is write your tests and save the files and it will automatically run your tests.</p>
<p>If you have installed the library for notifications (libnotify in linux), you will see a cool notification of the tests instantly, indicating with the help of an icon whether the tests passed or failed. This is indeed a faster approach to following the red-green-refactor TDD cycles.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dharanasoft.wordpress.com/166/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dharanasoft.wordpress.com/166/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dharanasoft.wordpress.com/166/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dharanasoft.wordpress.com/166/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dharanasoft.wordpress.com/166/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dharanasoft.wordpress.com/166/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dharanasoft.wordpress.com/166/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dharanasoft.wordpress.com/166/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dharanasoft.wordpress.com/166/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dharanasoft.wordpress.com/166/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dharanasoft.wordpress.com/166/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dharanasoft.wordpress.com/166/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dharanasoft.wordpress.com/166/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dharanasoft.wordpress.com/166/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.dharanasoft.com&amp;blog=21048031&amp;post=166&amp;subd=dharanasoft&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.dharanasoft.com/2011/07/26/fasten-your-tdd-red-green-refactor-cycles/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8dd5d3f6afa97634b647fc6c3c5703cb?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dhruvasagar</media:title>
		</media:content>
	</item>
	</channel>
</rss>
