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

<channel>
	<title>Tatva-Artha &#187; Technology</title>
	<atom:link href="http://www.tatvartha.com/category/technology/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tatvartha.com</link>
	<description>meaning of &#34;it&#34;</description>
	<lastBuildDate>Sat, 22 Oct 2011 22:00:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Upgrading to ruby 1.9: rbx-require-relative requires Ruby version ~&gt; 1.8.7</title>
		<link>http://www.tatvartha.com/2011/08/upgrading-to-ruby-1-9-rbx-require-relative-requires-ruby-version-1-8-7/</link>
		<comments>http://www.tatvartha.com/2011/08/upgrading-to-ruby-1-9-rbx-require-relative-requires-ruby-version-1-8-7/#comments</comments>
		<pubDate>Sun, 21 Aug 2011 18:55:49 +0000</pubDate>
		<dc:creator>Sharad</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[gemfile]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.tatvartha.com/?p=493</guid>
		<description><![CDATA[If you are upgrading from ruby 1.8 or Ruby Enterprise 1.8.7 to ruby 1.9.2, you may encounter this error. Installing rbx-require-relative (0.0.5) Unfortunately, a fatal error has occurred. Please report this error to the Bundler issue tracker at https://github.com/carlhuda/ bundler/issues so that we can fix it. Thanks!/Users/sjain/.rvm/rubies/ruby-1.9.2-p290/ lib/ruby/site_ruby/1.9.1/rubygems/ installer.rb:364:in `ensure_required_ruby_version_met': rbx-require-relative requires Ruby version ~> [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>If you are upgrading from ruby 1.8 or Ruby Enterprise 1.8.7 to ruby 1.9.2, you may encounter this error.</p>
<pre land="bash">
Installing rbx-require-relative (0.0.5) Unfortunately, a fatal error has occurred.
Please report this error to the Bundler issue tracker at https://github.com/carlhuda/
bundler/issues so that we can fix it. Thanks!/Users/sjain/.rvm/rubies/ruby-1.9.2-p290/
lib/ruby/site_ruby/1.9.1/rubygems/ installer.rb:364:in `ensure_required_ruby_version_met':
rbx-require-relative requires Ruby version ~> 1.8.7. (Gem::InstallError)
</pre>
<p>This most likely happens because you are declaring a dependency on ruby-debug gem in your Gemfile.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">group <span style="color:#ff3333; font-weight:bold;">:development</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  gem <span style="color:#996600;">'ruby-debug'</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>With ruby 1.9, you need to update this with new gem name ruby-debug19.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">group <span style="color:#ff3333; font-weight:bold;">:development</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  gem <span style="color:#996600;">'ruby-debug19'</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>This will eliminate the dependency on rbx-require-relative and fix the issue.</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.tatvartha.com/2011/08/upgrading-to-ruby-1-9-rbx-require-relative-requires-ruby-version-1-8-7/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting environment variables in Max OSX</title>
		<link>http://www.tatvartha.com/2011/05/setting-environment-variables-in-max-osx/</link>
		<comments>http://www.tatvartha.com/2011/05/setting-environment-variables-in-max-osx/#comments</comments>
		<pubDate>Mon, 16 May 2011 15:12:25 +0000</pubDate>
		<dc:creator>Sharad</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[environment variable]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[osx]]></category>

		<guid isPermaLink="false">http://www.tatvartha.com/?p=481</guid>
		<description><![CDATA[Any a developer switching from linux to mac, the way to set environment variables is similar yet different enough that is annoying at times. I have so far failed to find a good documentation on where and how to set those in mac osx. Today I found one here. My takeaway: Mac OS X applies [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>Any a developer switching from linux to mac, the way to set environment variables is similar yet different enough that is annoying at times. I have so far failed to find a good documentation on where and how to set those in mac osx. Today I found one <a href="http://devnet.jetbrains.net/docs/DOC-1160">here</a>.</p>
<p><strong>My takeaway:</strong></p>
<p>Mac OS X applies .bash_profile and .profile only for Terminal.app environment and  Apple&#8217;s technical documentation suggests using ~/.MacOSX/environment.plist for other applications. So, by default  PATH value will differ for RubyMine and the console.</p>
<p>For managing the global environments, it also recommends a <a href="http://www.apple.com/downloads/macosx/system_disk_utilities/environmentvariablepreferencepane.html">system preference pane app</a>. This worked for me.</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.tatvartha.com/2011/05/setting-environment-variables-in-max-osx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript Garden</title>
		<link>http://www.tatvartha.com/2011/03/javascript-garden/</link>
		<comments>http://www.tatvartha.com/2011/03/javascript-garden/#comments</comments>
		<pubDate>Sat, 19 Mar 2011 05:12:30 +0000</pubDate>
		<dc:creator>Sharad</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.tatvartha.com/?p=472</guid>
		<description><![CDATA[If you consider yourself a beginner or intermediate Javascript developer and feel the need to advance, here&#8217;s something that may be right up you ally: Javascript Garden. No related posts. Related posts brought to you by Yet Another Related Posts Plugin.


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>If you consider yourself a beginner or intermediate Javascript developer and feel the need to advance, here&#8217;s something that may be right up you ally: <a href="http://bonsaiden.github.com/JavaScript-Garden/">Javascript Garden</a>.</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.tatvartha.com/2011/03/javascript-garden/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mocha unexpected invocation errors</title>
		<link>http://www.tatvartha.com/2011/03/mocha-unexpected-invocation-errors/</link>
		<comments>http://www.tatvartha.com/2011/03/mocha-unexpected-invocation-errors/#comments</comments>
		<pubDate>Sat, 12 Mar 2011 04:38:39 +0000</pubDate>
		<dc:creator>Sharad</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[mocha]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.tatvartha.com/?p=470</guid>
		<description><![CDATA[If you find that your tests pass when run alone but fail with &#8220;unexpected invocation&#8221; inside &#8220;rake test&#8221;, you are most likely seeing behavior that is caused by mocha load order. This is a documented gotcha with mocha. And also discussed here. It happens when mocha gem is listed as library dependency inside rails app. [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>If you find that your tests pass when run alone but fail with &#8220;unexpected invocation&#8221; inside &#8220;rake test&#8221;, you are most likely seeing behavior that is caused by mocha load order.</p>
<p>This is a <a href="http://mocha.rubyforge.org/">documented</a> gotcha with mocha. And also discussed <a href="http://blog.agoragames.com/2010/09/10/rails-3-mocha-load-order-gotcha/">here</a>.</p>
<p>It happens when mocha gem is listed as library dependency inside rails app. The library gets loaded too soon. The fix is to load mocha after rails has booted up.</p>
<p>For rails < 3.0.0, this means removing -- config.gem 'mocha' -- entry from config/environment.rb and adding -- require 'mocha' -- at the bottom of test/test_helper.rb.</p>
<p>For rails >= 3.0.0, this means adding &#8212; :require => false &#8212; inside Gemfile entry as follows.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># Gemfile</span>
group <span style="color:#ff3333; font-weight:bold;">:test</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  gem <span style="color:#996600;">'mocha'</span>, <span style="color:#ff3333; font-weight:bold;">:require</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>And then adding following line at the bottom of test/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:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'mocha'</span></pre></div></div>



<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.tatvartha.com/2011/03/mocha-unexpected-invocation-errors/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing RMagick gem on Mac OSX</title>
		<link>http://www.tatvartha.com/2011/03/installing-rmagick-gem-on-mac-osx/</link>
		<comments>http://www.tatvartha.com/2011/03/installing-rmagick-gem-on-mac-osx/#comments</comments>
		<pubDate>Wed, 09 Mar 2011 04:41:36 +0000</pubDate>
		<dc:creator>Sharad</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[gem]]></category>
		<category><![CDATA[rmagick]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.tatvartha.com/?p=468</guid>
		<description><![CDATA[Commands for installing image-magick package and rmagick gem on max osx: sudo port install tiff -macosx imagemagick +q8 +gs +wmf sudo gem install rmagick Reference: http://rmagick.rubyforge.org/install-osx.html No related posts. Related posts brought to you by Yet Another Related Posts Plugin.


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>Commands for installing image-magick package and rmagick gem on max osx:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> port <span style="color: #c20cb9; font-weight: bold;">install</span> tiff <span style="color: #660033;">-macosx</span> imagemagick +q8 +<span style="color: #c20cb9; font-weight: bold;">gs</span> +wmf
<span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> rmagick</pre></div></div>

<p>Reference: <a href="http://rmagick.rubyforge.org/install-osx.html">http://rmagick.rubyforge.org/install-osx.html</a></p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.tatvartha.com/2011/03/installing-rmagick-gem-on-mac-osx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ActiveRecord::MissingAttributeError: missing attribute &#8212; a bug or a feature?</title>
		<link>http://www.tatvartha.com/2011/03/activerecordmissingattributeerror-missing-attribute-a-bug-or-a-features/</link>
		<comments>http://www.tatvartha.com/2011/03/activerecordmissingattributeerror-missing-attribute-a-bug-or-a-features/#comments</comments>
		<pubDate>Fri, 04 Mar 2011 02:07:49 +0000</pubDate>
		<dc:creator>Sharad</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[activerecord]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.tatvartha.com/?p=464</guid>
		<description><![CDATA[Sooner or later, the need arises to assign default values to model attributes. In rails this is usually done in model&#8217;s after_initialize() with a new_record? guard. Something like: class User def after_initialize if new_record? self.country = &#34;US&#34; end end end This initializes the object with proper default so the UI form gets properly populated and [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p><img src="http://4.bp.blogspot.com/_uyrxeugtbV0/RmlE-LeMZfI/AAAAAAAABII/JW3gs6QO3qw/s320/irannVVV.JPG" style="margin: 10px; height: 150px;"/></p>
<p>Sooner or later, the need arises to assign default values to model attributes. In rails this is usually done in model&#8217;s after_initialize() with a new_record? guard.</p>
<p>Something like:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> User
  <span style="color:#9966CC; font-weight:bold;">def</span> after_initialize
    <span style="color:#9966CC; font-weight:bold;">if</span> new_record?
      <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">country</span> = <span style="color:#996600;">&quot;US&quot;</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>This initializes the object with proper default so the UI form gets properly populated and the database gets proper default if user hasn&#8217;t overridden it.</p>
<p>Sometimes, you realize that you have (pre-existing?) objects in database that also need the same default if the current value is nil. In such case, you may modify your initializer like this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> User
  <span style="color:#9966CC; font-weight:bold;">def</span> after_initialize
    <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">country</span> <span style="color:#006600; font-weight:bold;">||</span>= <span style="color:#996600;">&quot;US&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>This works for both scenarios: User.new and User.find.</p>
<p>However, it introduces a behavior that may not be apparant immediately.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ script<span style="color: #000000; font-weight: bold;">/</span>console
ree<span style="color: #000000; font-weight: bold;">&gt;</span> User.find<span style="color: #7a0874; font-weight: bold;">&#40;</span>u.id<span style="color: #7a0874; font-weight: bold;">&#41;</span>
  User Load <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.9ms<span style="color: #7a0874; font-weight: bold;">&#41;</span>   SELECT <span style="color: #000000; font-weight: bold;">*</span> FROM <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">users</span><span style="color: #000000; font-weight: bold;">`</span> WHERE <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">users</span><span style="color: #000000; font-weight: bold;">`</span>.<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">id</span><span style="color: #000000; font-weight: bold;">`</span> = <span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> 
ree<span style="color: #000000; font-weight: bold;">&gt;</span> User.exists?<span style="color: #7a0874; font-weight: bold;">&#40;</span>:<span style="color: #c20cb9; font-weight: bold;">id</span> =<span style="color: #000000; font-weight: bold;">&gt;</span> u.id<span style="color: #7a0874; font-weight: bold;">&#41;</span>
  RateSearch Load <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.6ms<span style="color: #7a0874; font-weight: bold;">&#41;</span>   SELECT <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">users</span><span style="color: #000000; font-weight: bold;">`</span>.id FROM <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">users</span><span style="color: #000000; font-weight: bold;">`</span> WHERE <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">users</span><span style="color: #000000; font-weight: bold;">`</span>.<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">id</span><span style="color: #000000; font-weight: bold;">`</span> = <span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> LIMIT <span style="color: #000000;">1</span>
ActiveRecord::MissingAttributeError: missing attribute: country
<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>prj<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #000000; font-weight: bold;">/</span>app<span style="color: #000000; font-weight: bold;">/</span>models<span style="color: #000000; font-weight: bold;">/</span>User.rb:<span style="color: #000000;">3</span>:<span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span>after_initialize<span style="color: #ff0000;">'</span></pre></div></div>

<p>A closer look reveals that ActiveRecord tries to be smart and only fetch &#8216;id&#8217; column when performing Model.exists? call.</p>
<p>Many people have tripped this and logged it as <a href="https://rails.lighthouseapp.com/projects/8994/tickets/3165-activerecordmissingattributeerror-after-update-to-rails-v-234">a bug</a>. The report has been silently ignored, and I believe, for good/performance reasons.</p>
<p>So, what do we get around it? Here&#8217;s one way.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> User
  <span style="color:#9966CC; font-weight:bold;">def</span> after_initialize
    <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">country</span> <span style="color:#006600; font-weight:bold;">||</span>= <span style="color:#996600;">&quot;US&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">rescue</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::MissingAttributeError</span>
    <span style="color:#008000; font-style:italic;"># this should only happen on Model.exists?() call. It can be safely ignored.</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>As they say, it is not a bug, it is a feature.</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.tatvartha.com/2011/03/activerecordmissingattributeerror-missing-attribute-a-bug-or-a-features/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Online Regular Expression Tool</title>
		<link>http://www.tatvartha.com/2011/03/online-regular-expression-tool/</link>
		<comments>http://www.tatvartha.com/2011/03/online-regular-expression-tool/#comments</comments>
		<pubDate>Thu, 03 Mar 2011 00:14:25 +0000</pubDate>
		<dc:creator>Sharad</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[regexp]]></category>
		<category><![CDATA[regular expression]]></category>
		<category><![CDATA[rubular]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.tatvartha.com/?p=462</guid>
		<description><![CDATA[Rubular, is a tool that you may find handy when developing ruby regular expression for scraping unstructured data needs. http://rubular.com/ Good one! No related posts. Related posts brought to you by Yet Another Related Posts Plugin.


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>Rubular, is a tool that you may find handy when developing ruby regular expression for scraping unstructured data needs.</p>
<p><a href="http://rubular.com/">http://rubular.com/</a></p>
<p>Good one!</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.tatvartha.com/2011/03/online-regular-expression-tool/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Login as multiple users simultaneously for testing</title>
		<link>http://www.tatvartha.com/2010/05/login-as-multiple-users-simultaneously-for-testing/</link>
		<comments>http://www.tatvartha.com/2010/05/login-as-multiple-users-simultaneously-for-testing/#comments</comments>
		<pubDate>Thu, 27 May 2010 01:40:18 +0000</pubDate>
		<dc:creator>Sharad</dc:creator>
				<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.tatvartha.com/?p=435</guid>
		<description><![CDATA[Ever wondered how to login as two different users at the same time? The situation manifests in any project where you want to be able to test a workflow involving several actors with different roles. The problem is that browsers allow only one login for a given domain at any one time. So, you are [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p><img src="http://farm3.static.flickr.com/2793/4028160820_0292417df2.jpg" style="float: left; height: 160px; width: 240px; padding: 2px; border: 1px solid black;"/></p>
<p>Ever wondered how to login as two different users at the same time? The situation manifests in any project where you want to be able to test a workflow involving several actors with different roles. The problem is that browsers allow only one login for a given domain at any one time. So, you are required to logout as current_user before logging in as another. One of the solution people use is install multiple browsers.</p>
<p><span id="more-435"></span></p>
<p><strong>Solution: Multiple Browsers</strong></p>
<p>So, lets say your favorite browser is firefox. And you also have IE7 installed by default on your windows machine. And you have a google chrome installed just so you can try out the new and blazing contribution by google. Most developers, I assume, more than a single browser installed on their system. Given this, you can login as different user in each browser.</p>
<p>This works but here is another solution that, as you will quickly realize, is better.</p>
<p><strong>Solution: Multiple names for your &#8220;localhost&#8221;</strong></p>
<p>Just update your /etc/hosts file to add more names for your local machine. Lets take a concrete example:</p>
<p>So, on a project, realted to mortgage industry, I have several actors like borrower, realtor, loan officer, mortgage-broker. I updated my /etc/hosts file (on linux) from this line:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">127.0.0.1 localhost</pre></div></div>

<p>to this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">127.0.0.1 localhost r lo mb b</pre></div></div>

<p>With this above line, I can access my local application using following URLs:</p>
<p>http://r:3000 (for realtor)<br />
http://lo:3000 (for loan officer)<br />
http://b:3000 (for borrower)<br />
http://mb:3000 (for mortage broker)</p>
<p>Now, I can open 4 tabs in a browser each with different URL and login as different users. Coupled this with password saving feature of browser, I don&#8217;t even have to type username/password for each user as long as I am disciplined about not cross-logging in as realtor inside borrower url (b:3000). Go ahead, leave yourself logged in and never logout!</p>
<p>This simple trick is better than multiple browser solution since it doesn&#8217;t require as many browser and you can have as many unique URLs as you want. And you are not limited to using this trick for local testing. If you have a staging server at http://staging.project.com that resolves to an IP, say, 192.1.2.3, you can repeat the same process:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># my /etc/hosts file</span>
127.0.0.1 localhost r lo mb b
192.1.2.3 staging.project.com sr slo smb sb
<span style="color: #666666; font-style: italic;"># Now I can</span>
<span style="color: #666666; font-style: italic;"># http://sr (staging realtor)</span>
<span style="color: #666666; font-style: italic;"># http://slo (staging loan officer)</span>
<span style="color: #666666; font-style: italic;"># you get the drill ...</span></pre></div></div>

<p>There you go. Happy testing!</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.tatvartha.com/2010/05/login-as-multiple-users-simultaneously-for-testing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Disabling form post in google chrome and safari</title>
		<link>http://www.tatvartha.com/2010/05/disabling-form-post-in-google-chrome-and-safari/</link>
		<comments>http://www.tatvartha.com/2010/05/disabling-form-post-in-google-chrome-and-safari/#comments</comments>
		<pubDate>Mon, 17 May 2010 22:36:07 +0000</pubDate>
		<dc:creator>Sharad</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[chrome webkit rails ajax bug]]></category>

		<guid isPermaLink="false">http://www.tatvartha.com/?p=433</guid>
		<description><![CDATA[So, I found this issue with google chrome and safari web browser and I believe this applies to any webkit based browser. When a form submit is disabled by setting the submit button to disabled=true attribute, the browser is usually expected to prevent submission when the user hits &#8220;ENTER&#8221; on any of its text fields. [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.bruceongames.com/wp-content/uploads/2009/07/Google-Chrome-Logo.jpg" style="float: right; height: 100px; width: 100px"/><br />
So, I found this issue with google chrome and safari web browser and I believe this applies to any webkit based browser. When a form submit is disabled by setting the submit button to disabled=true attribute, the browser is usually expected to prevent submission when the user hits &#8220;ENTER&#8221; on any of its text fields. This works fine in Firefor, my default browser.</p>
<p>In my rails app, I had to do this to work around this.</p>
<p>We use haml rendering engine for our project and my form looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">-</span> remote_form_for <span style="color:#0066ff; font-weight:bold;">@product_search</span>, <span style="color:#ff3333; font-weight:bold;">:url</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> product_searches_path, <span style="color:#006600; font-weight:bold;">|</span>
  <span style="color:#ff3333; font-weight:bold;">:html</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>:method <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:post</span>, <span style="color:#ff3333; font-weight:bold;">:id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'product_search_form'</span><span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>form<span style="color:#006600; font-weight:bold;">|</span></pre></div></div>

<p><span id="more-433"></span><br />
This generates a form like this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  <span style="color:#006600; font-weight:bold;">&lt;</span>form onsubmit=<span style="color:#996600;">&quot;jQuery.ajax({data:jQuery.param(jQuery(this).serializeArray()) + '&amp;amp;authenticity_token=' + encodeURIComponent('MlHm/z3dsdYtETKwtNnwQlojx1NIduLlWFMECbjntsM='), dataType:'script', type:'post', url:'/product_searches'}); return false;&quot;</span>
  method=<span style="color:#996600;">&quot;post&quot;</span> id=<span style="color:#996600;">&quot;product_search_form&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">class</span>=<span style="color:#996600;">&quot;product_search&quot;</span>
  action=<span style="color:#996600;">&quot;/product_searches&quot;</span><span style="color:#006600; font-weight:bold;">&gt;</span></pre></div></div>

<p>I was working with an ajax form but I believe the bug happens even with traditional form POST as reported by another user <a href="http://code.google.com/p/chromium/issues/detail?id=37402">here</a>.</p>
<p>So, I had to create an onSubmit javascript myself to fix the situation:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">-</span> semantic_form_for <span style="color:#0066ff; font-weight:bold;">@product_search</span>, <span style="color:#ff3333; font-weight:bold;">:url</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> product_searches_path, <span style="color:#006600; font-weight:bold;">|</span>
  <span style="color:#ff3333; font-weight:bold;">:html</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>:method <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:post</span>, <span style="color:#ff3333; font-weight:bold;">:id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'product_search_form'</span>, <span style="color:#006600; font-weight:bold;">|</span>
  <span style="color:#ff3333; font-weight:bold;">:onsubmit</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;return jQuery.productSearchOnSubmit();&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>form<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#006600; font-weight:bold;">|</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&#40;</span>function<span style="color:#006600; font-weight:bold;">&#40;</span>$<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span>
  $.<span style="color:#9900CC;">productSearchOnSubmit</span> = function<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>
    <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>$<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'#product_search_submit'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">attr</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'disabled'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>
    <span style="color:#006600; font-weight:bold;">//</span> <span style="color:#9966CC; font-weight:bold;">do</span> nothing
    <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#9966CC; font-weight:bold;">else</span> <span style="color:#006600; font-weight:bold;">&#123;</span>
      jQuery.<span style="color:#9900CC;">ajax</span><span style="color:#006600; font-weight:bold;">&#40;</span>
      <span style="color:#006600; font-weight:bold;">&#123;</span>
        data: jQuery.<span style="color:#9900CC;">param</span><span style="color:#006600; font-weight:bold;">&#40;</span>jQuery<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'#product_search_form'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">serializeArray</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">'&amp;authenticity_token='</span> <span style="color:#006600; font-weight:bold;">+</span>
        encodeURIComponent<span style="color:#006600; font-weight:bold;">&#40;</span>form_authenticity_token<span style="color:#006600; font-weight:bold;">&#41;</span>,
        dataType:<span style="color:#996600;">'script'</span>,
        type:<span style="color:#996600;">'post'</span>,
        url:<span style="color:#996600;">'/product_searches'</span>
      <span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;
    <span style="color:#006600; font-weight:bold;">&#125;</span>
    <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#0000FF; font-weight:bold;">false</span>;
  <span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#40;</span>jQuery<span style="color:#006600; font-weight:bold;">&#41;</span>;</pre></div></div>

<p>I also had to add global javascript variable for form_authenticity_token to make it available for javascript when performing submit.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">%</span>html<span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:xmlns</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;http://www.w3.org/1999/xhtml&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:lang</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;en&quot;</span>, <span style="color:#996600;">&quot;xml:lang&quot;</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;en&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
  <span style="color:#006600; font-weight:bold;">%</span>head
    <span style="color:#ff3333; font-weight:bold;">:javascript</span>
      var form_authenticity_token = <span style="color:#996600;">'#{form_authenticity_token}'</span>;</pre></div></div>

<p>If you think, this is a <a href="http://code.google.com/p/chromium/issues/detail?id=37402">bug</a> too, please vote for a fix.</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.tatvartha.com/2010/05/disabling-form-post-in-google-chrome-and-safari/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Testing Cookies in Rails</title>
		<link>http://www.tatvartha.com/2009/08/testing-cookies-in-rails/</link>
		<comments>http://www.tatvartha.com/2009/08/testing-cookies-in-rails/#comments</comments>
		<pubDate>Thu, 06 Aug 2009 14:50:43 +0000</pubDate>
		<dc:creator>Sharad</dc:creator>
				<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.tatvartha.com/?p=309</guid>
		<description><![CDATA[Testing cookies in rails have a few quirks. Some of these are documented here nicely. I ran into a different one today. In my case, I needed to set a few flashVars variables to pass to flex app (swf file) depending on presence of certain cookies. So, my test involved setting cookies on controller/request and [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>Testing cookies in rails have a few quirks. Some of these are documented <a href="http://zargony.com/2009/03/30/testing-cookies-in-rails-2-3">here</a> nicely.</p>
<p>I ran into a different one today. In my case, I needed to set a few flashVars variables to pass to flex app (swf file) depending on presence of certain cookies. So, my test involved setting cookies on controller/request and then making sure they appear as flash variables. Here is what I did.</p>
<p><strong>Test:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  should <span style="color:#996600;">&quot;render last_user_name and auth_token cookies as flashVars on new UserSession&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    controller.<span style="color:#9900CC;">request</span>.<span style="color:#9900CC;">cookies</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:last_successful_username</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;vriuser1&quot;</span>
    controller.<span style="color:#9900CC;">request</span>.<span style="color:#9900CC;">cookies</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:auth_token</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;12345&quot;</span>
    get <span style="color:#ff3333; font-weight:bold;">:new</span>
    assert_equal <span style="color:#996600;">&quot;autoLogin=true&amp;username=vriuser1&quot;</span>, assigns<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:flash_vars</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p><strong>Controller</strong></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  <span style="color:#9966CC; font-weight:bold;">def</span> new
    auth_token = cookies<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:auth_token</span><span style="color:#006600; font-weight:bold;">&#93;</span>
    last_username = cookies<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:last_successful_username</span><span style="color:#006600; font-weight:bold;">&#93;</span>
    <span style="color:#0066ff; font-weight:bold;">@flash_vars</span> = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
    <span style="color:#0066ff; font-weight:bold;">@flash_vars</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#996600;">'autoLogin=true'</span> <span style="color:#9966CC; font-weight:bold;">if</span> auth_token
    <span style="color:#0066ff; font-weight:bold;">@flash_vars</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#996600;">&quot;username=#{last_username}&quot;</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>last_username<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0066ff; font-weight:bold;">@flash_vars</span> = <span style="color:#0066ff; font-weight:bold;">@flash_vars</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;&amp;&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0066ff; font-weight:bold;">@user_session</span> = UserSession.<span style="color:#9900CC;">new</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Until I realized that setting cookies as symbols don&#8217;t work. Even though you can read cookies using symbolic-keys, you can&#8217;t set them as such in tests. I had to set them as strings.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  should <span style="color:#996600;">&quot;render last_user_name and auth_token cookies as flashVars on new UserSession&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    controller.<span style="color:#9900CC;">request</span>.<span style="color:#9900CC;">cookies</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'last_successful_username'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;vriuser1&quot;</span>
    controller.<span style="color:#9900CC;">request</span>.<span style="color:#9900CC;">cookies</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'auth_token'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;12345&quot;</span>
    get <span style="color:#ff3333; font-weight:bold;">:new</span>
    assert_equal <span style="color:#996600;">&quot;autoLogin=true&amp;username=vriuser1&quot;</span>, assigns<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:flash_vars</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>That did the trick!</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.tatvartha.com/2009/08/testing-cookies-in-rails/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

