<?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>A Waage Blog &#187; Ruby on Rails</title>
	<atom:link href="http://qugstart.com/blog/tag/ruby-on-rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://qugstart.com/blog</link>
	<description>Ruby, Rails, Life</description>
	<lastBuildDate>Thu, 10 Nov 2011 00:35:02 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Rails 3 &#8211; How to Rename a Project</title>
		<link>http://qugstart.com/blog/ruby-and-rails/rails-3-how-to-rename-a-project/</link>
		<comments>http://qugstart.com/blog/ruby-and-rails/rails-3-how-to-rename-a-project/#comments</comments>
		<pubDate>Mon, 28 Feb 2011 21:17:06 +0000</pubDate>
		<dc:creator>Andrew Waage</dc:creator>
				<category><![CDATA[Ruby and Rails]]></category>
		<category><![CDATA[grep]]></category>
		<category><![CDATA[rails3]]></category>
		<category><![CDATA[rename project]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://qugstart.com/blog/?p=78</guid>
		<description><![CDATA[As opposed to previous versions of Rails, Rails 3 namespaces your entire project according to your project name. As an example, notice that in your config/routes.rb file, the first line is:

ProjectName::Application.routes.draw do
...

This means that changing a project name involves changing a number of files to reference the new project name as well. Here&#8217;s a quick [...]]]></description>
			<content:encoded><![CDATA[<p>As opposed to previous versions of Rails, Rails 3 namespaces your entire project according to your project name. As an example, notice that in your config/routes.rb file, the first line is:</p>
<pre class='prettyprint' lang='ruby'>
ProjectName::Application.routes.draw do
...
</pre>
<p>This means that changing a project name involves changing a number of files to reference the new project name as well. Here&#8217;s a quick list of the standard files to change:</p>
<pre class='prettyprint' lang='bash'>
Rakefile
config.ru
config/application.rb
config/database.yml
config/environment.rb
config/environments/*.rb
config/initializers/secret_token.rb
config/initializers/session_store.rb
config/routes.rb</pre>
<p>Besides these, it&#8217;s a good idea to also check all files in config/ and config/initializers/<br />
If you want to be thorough, run this grep command in your project root, and you will get a list of all files that contain your old project name:</p>
<pre class='prettyprint' lang='bash'>
grep -Ri 'oldprojectame' * | cut -f1 -d':' | sort | uniq
</pre>
]]></content:encoded>
			<wfw:commentRss>http://qugstart.com/blog/ruby-and-rails/rails-3-how-to-rename-a-project/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Facebook base64 url decode for signed_request</title>
		<link>http://qugstart.com/blog/ruby-and-rails/facebook-base64-url-decode-for-signed_request/</link>
		<comments>http://qugstart.com/blog/ruby-and-rails/facebook-base64-url-decode-for-signed_request/#comments</comments>
		<pubDate>Tue, 08 Feb 2011 20:27:05 +0000</pubDate>
		<dc:creator>Andrew Waage</dc:creator>
				<category><![CDATA[Facebook API]]></category>
		<category><![CDATA[Ruby and Rails]]></category>
		<category><![CDATA[base64]]></category>
		<category><![CDATA[base64_url_decode]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[signed_request]]></category>

		<guid isPermaLink="false">http://qugstart.com/blog/?p=75</guid>
		<description><![CDATA[I ran into a problem as I was trying to decode and parse the Facebook signed_request for their new Registration plugin (http://developers.facebook.com/docs/plugins/registration).
Folowing the PHP example, I attempted to decode and read the signed_request returned by Facebook. Unfortunately, it seemed like the decoded JSON returned was malformed! It was missing the end hash character &#8220;}&#8221;. This [...]]]></description>
			<content:encoded><![CDATA[<p>I ran into a problem as I was trying to decode and parse the Facebook signed_request for their new Registration plugin (<a href="http://developers.facebook.com/docs/plugins/registration">http://developers.facebook.com/docs/plugins/registration</a>).</p>
<p>Folowing the PHP example, I attempted to decode and read the signed_request returned by Facebook. Unfortunately, it seemed like the decoded JSON returned was malformed! It was missing the end hash character &#8220;}&#8221;. This may not happen in all cases, but the reason is due to the padding in Base64 encoding (See <a href="http://en.wikipedia.org/wiki/Base64#URL_applications">Base64 for URLs in Wikipedia</a>).</p>
<p>To account for the padding in Base64, I used the following helper method to do the base64_url_decode. Hope it helps someone else trying to base64 decode Facebook&#8217;s signed_request in Ruby on Rails!:</p>
<pre class='prettyprint' lang='ruby'>
 def base64_url_decode(str)
   str += '=' * (4 - str.length.modulo(4))
   Base64.decode64(str.tr('-_','+/'))
 end
</pre>
<p>Notice there&#8217;s two things that must happen before decoding the string: </p>
<ol>
<li>Pad the encoded string with &#8220;=&#8221;</li>
<li>Replace the character &#8216;-&#8217; with &#8216;+&#8217;, and &#8216;_&#8217; with &#8216;/&#8217;</li>
</ol>
<p>I wish Facebook mentioned this clearly on their API !</p>
]]></content:encoded>
			<wfw:commentRss>http://qugstart.com/blog/ruby-and-rails/facebook-base64-url-decode-for-signed_request/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Resolve a hostname from an IP address in Ruby (Reverse-DNS)</title>
		<link>http://qugstart.com/blog/ruby-and-rails/resolve-a-hostname-from-an-ip-address-in-ruby-reverse-dns/</link>
		<comments>http://qugstart.com/blog/ruby-and-rails/resolve-a-hostname-from-an-ip-address-in-ruby-reverse-dns/#comments</comments>
		<pubDate>Fri, 09 Oct 2009 21:47:43 +0000</pubDate>
		<dc:creator>Andrew Waage</dc:creator>
				<category><![CDATA[Networking]]></category>
		<category><![CDATA[Ruby and Rails]]></category>
		<category><![CDATA[getaddrinfo]]></category>
		<category><![CDATA[host]]></category>
		<category><![CDATA[ip]]></category>
		<category><![CDATA[nslookup]]></category>
		<category><![CDATA[resolve]]></category>
		<category><![CDATA[reverse dns]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[socket]]></category>

		<guid isPermaLink="false">http://qugstart.com/blog/?p=10</guid>
		<description><![CDATA[It sounds easy, but I tried a lot of things before finding the solution I used.
I tried using:
`host 66.249.67.49` or
`nslookup 66.249.67.49`

These were fine, but it seems a bit hacky to use the shell. Also, it would require some sort of parsing to get the hostname that I want.
Browsing the web, I found a couple solutions [...]]]></description>
			<content:encoded><![CDATA[<p>It sounds easy, but I tried a lot of things before finding the solution I used.</p>
<p>I tried using:</p>
<pre lang="ruby" class="prettyprint">`host 66.249.67.49` or
`nslookup 66.249.67.49`
</pre>
<p>These were fine, but it seems a bit hacky to use the shell. Also, it would require some sort of parsing to get the hostname that I want.</p>
<p>Browsing the web, I found a couple solutions that almost worked.</p>
<pre lang="ruby" class="prettyprint">s = Socket.getaddrinfo('66.249.67.49',nil)
hostname = s[0][2]
</pre>
<p>This solution worked in IRB, worked in console, but for some reason would not work when I was running my mongrel server and trying to perform the exact same method call from a web-browser. ( I still don&#8217;t know why).</p>
<p>Digging around a bit more, I came up with this simple solution:</p>
<pre lang="ruby" class="prettyprint">host = Resolv.new.getname('66.249.67.49')
</pre>
<p>Is it really that easy?? Give it a shot and let me know your thoughts !!</p>
]]></content:encoded>
			<wfw:commentRss>http://qugstart.com/blog/ruby-and-rails/resolve-a-hostname-from-an-ip-address-in-ruby-reverse-dns/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Functional Testing Cookies in Ruby on Rails 1.2.3</title>
		<link>http://qugstart.com/blog/ruby-and-rails/functional-testing-cookies-in-ruby-on-rails-123/</link>
		<comments>http://qugstart.com/blog/ruby-and-rails/functional-testing-cookies-in-ruby-on-rails-123/#comments</comments>
		<pubDate>Mon, 13 Oct 2008 07:33:18 +0000</pubDate>
		<dc:creator>Andrew Waage</dc:creator>
				<category><![CDATA[Rails Testing]]></category>
		<category><![CDATA[Ruby and Rails]]></category>
		<category><![CDATA[assert_cookie]]></category>
		<category><![CDATA[cookies]]></category>
		<category><![CDATA[functional testing]]></category>
		<category><![CDATA[persistent cookies]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">http://qugstart.com/blog/?p=5</guid>
		<description><![CDATA[After spending a good couple hours + trying to figure out why my functional tests were failing when working with cookies, I came across a couple great resources for rails + testing cookies.
Here&#8217;s a good basic explanation of using cookies on Pluit solutions website.  Then I came across the Robby on Rails blog that [...]]]></description>
			<content:encoded><![CDATA[<p>After spending a good couple hours + trying to figure out why my functional tests were failing when working with cookies, I came across a couple great resources for rails + testing cookies.</p>
<p>Here&#8217;s a good basic explanation of using cookies on <a title="Pluit Solutions" href="http://www.pluitsolutions.com/2006/08/02/rails-functional-test-with-cookie/">Pluit solutions</a> website.  Then I came across the <a title="Robby on Rails" href="http://www.robbyonrails.com/articles/2006/08/28/testing-cookies-in-ruby-on-rails">Robby on Rails</a> blog that led me to understand (and misunderstand) the <a title="assert_cookie" href="http://blog.brightredglow.com/articles/2006/08/27/assert_cookie-for-ooey-gooey-fun">asssert_cookie</a> plugin.</p>
<p>However, I was still having a lot of trouble figuring out why I was setting my @request.cookies['foo'] in my functional test, but later (in the same test method) checking for cookies['foo'] and not finding anything in the cookie jar!</p>
<p>I then tried setting cookies['foo'] in my controller test, but found that when I did a check for the existance of that cookie in my actual controller code, it was not there! I thought that I should be able to set up a cookie in a test and have my controller recognize it. This is true, however, not by setting cookies['foo'].</p>
<p>So&#8230; I opened up a blank controller and functional test and began testing out different combinations to find out exactly what was going on. I hope this little example helps to save someone else&#8217;s precious time. Here it goes&#8230;</p>
<p>This is the controller I will be referring to for my example tests:</p>
<pre lang="rails" class="prettyprint">========= controller
  def foo
    if cookies['oreo'] == 'yesitis'
      @info =  "Oreos are tasty"
    else
      @info = "Only Milk here"
    end
     render :nothing => true
  end</pre>
<p>1. In your functional test, do not test for presence of a cookie after a get request to a particular action, <strong>unless </strong>the action you are testing specifically sets up that cookie.  In other words, if your controller action is not setting the cookie, do not test for that cookie&#8217;s presence.</p>
<p>In the above controller, no cookies are ever being set. Therefore, testing for the presence of a cookie after the get request (in a test method) will return false.</p>
<p>In other words, the cookie is recognized by the controller, however, notice that cookies['oreo'] is nil after the get request:</p>
<pre lang="rails" class="prettyprint">  def test_oreo
    @request.cookies['oreo'] = CGI::Cookie.new("oreo", "yesitis")
    get :foo
    assert_equal({}, @response.cookies)
    assert_equal(nil, cookies['oreo'])
    #Assert cookie will be nil here so do not test it:
    #assert_cookie <img src='http://qugstart.com/blog/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> reo
    puts assigns['info'] #"Oreos are tasty"
  end</pre>
<p>Note:<br />
1. After your get request, the @response.cookies will be empty<br />
2. After your get request, cookies['oreo'] will still be nil.<br />
3. After your get request, you cannot use assert_cookie because it will be nil</p>
<p>2. If your controller action expects a cookie to be there, you <strong>cannot </strong>set it up in your functional test by assigning:</p>
<li> cookies['oreo'] = true  (<span style="color: #ff0000;"><em>incorrect</em></span>) OR</li>
<li>@request.cookies['oreo'] = true   (<span style="color: #ff0000;"><em>incorrect</em></span>)</li>
<p>The only way to set up your cookie for a subsequent request, so that your controller will see it is:</p>
<ul>
<li>@request.cookies['oreo'] = CGI::Cookies.new(&#8217;oreo&#8217;, true)    (<span style="color: #339966;">correct</span>)</li>
</ul>
<pre lang="rails" class="prettyprint">  #INCORRECT
  def test_oreo
    cookies['oreo'] = 'yesitis'
    get :foo
    puts assigns['info'] #"Only Milk here"
  end

#INCORRECT
  def test_oreo
    cookies['oreo'] =  CGI::Cookie.new("oreo", "yesitis")
    get :foo
    puts assigns['info'] #"Only Milk here"
  end

#INCORRECT
  def test_oreo
    @request.cookies['oreo'] = 'yesitis'
    get :foo
    puts assigns['info'] #"Only Milk here"
  end</pre>
<p><strong>The only way to set up your cookie in a functional test and have your controller recognize it.</strong></p>
<pre lang="rails" class="prettyprint">#CORRECT
  def test_oreo
    @request.cookies['oreo'] = CGI::Cookie.new("oreo", "yesitis")
    get :foo
    puts assigns['info'] # Will print out "Oreos are tasty"
  end</pre>
<p>3. Avoid the temptation to use symbols in your tests with cookies.</p>
<ul>
<li> cookies[:foo]   -> BAD</li>
<li> cookies['foo']   -> GOOD</li>
</ul>
<p>4. Only use <strong>assert_cookie</strong> (plugin: see above for link) if you are testing that the controller action is creating a new cookie.</p>
<p>5. If you are testing multiple actions and redirects from one action to another action in the same controller, you do not need to set the cookie before each action, explicitly. The cookie will remain in the @request object that you created in the setup method of your test.</p>
<p>EXAMPLE TWO (Testing persistent cookies)<br />
You DONT set up the cookie for each subsequent request.<br />
It does &#8220;persist&#8221; throughout your test-method because you are<br />
using the same @request object!!</p>
<pre lang="rails" class="prettyprint">========controller
  def foo
    if cookies['oreo'] == 'yesitis'
	puts "Foo has OREO"
    else
 	puts "Foo has NOTHING"
    end
      redirect_to :action => :bar
      return true
  end

  def bar
    if cookies['oreo'] == 'yesitis'
      puts "Oreos are tasty"
    else
      puts "Only Milk here"
    end
     render :nothing => true
  end

========= Test
  def test_oreo
   @request.cookies['oreo'] =  CGI::Cookie.new('oreo', "yesitis")
    get :foo    #OUTPUTS: Foo has OREO

    # COOKIE PERSISTS HERE!!
    # Don't need to explicitly set cookie again in the
    # @request.cookies object
    get :bar   #OUTPUTS: Oreos are tasty
  end</pre>
]]></content:encoded>
			<wfw:commentRss>http://qugstart.com/blog/ruby-and-rails/functional-testing-cookies-in-ruby-on-rails-123/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Welcome new blog!</title>
		<link>http://qugstart.com/blog/qugstart/welcome-new-blog/</link>
		<comments>http://qugstart.com/blog/qugstart/welcome-new-blog/#comments</comments>
		<pubDate>Wed, 27 Aug 2008 05:28:53 +0000</pubDate>
		<dc:creator>Andrew Waage</dc:creator>
				<category><![CDATA[Qugstart]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Cubase]]></category>
		<category><![CDATA[Introduction]]></category>
		<category><![CDATA[Jazz Piano]]></category>
		<category><![CDATA[RESTful]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Web 2.0]]></category>

		<guid isPermaLink="false">http://qugstart.com/blog/?p=3</guid>
		<description><![CDATA[Hello World! (and a bit of intro)
I first created Qugstart during finals season in my 2nd year at Berkeley. Initially all I knew was PHP, and I barely knew it. Qugstart was a perfect way for me to waste my valuable study time, improve my PHP skills, while at the same time pick up some [...]]]></description>
			<content:encoded><![CDATA[<p>Hello World! (and a bit of intro)</p>
<p>I first created Qugstart during finals season in my 2nd year at Berkeley. Initially all I knew was PHP, and I barely knew it. Qugstart was a perfect way for me to waste my valuable study time, improve my PHP skills, while at the same time pick up some MySQL.</p>
<p>Well, Google has since pounced on the Qugstart idea, I have since graduated, and the combination of working full time, Cubase, and a sudden interest in Jazz piano have taken up most of my time. Thus, my poor Qugstart has not had much attention from me at all.</p>
<p>In the past year or so, I&#8217;ve been fortunate to meet Ruby and her friend Rails. Armed with a new <strong>blog</strong>, and a new confidence in my Rails skills, I have decided to re-vamp my entire site in <strong>Rails</strong>! <img src='http://qugstart.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I hope that I can post regularly as I develop, so that I can share some of my new discoveries with the world out there.</p>
<p>As for now, Qugstart is in the process of a backend (member&#8217;s section) re-vamp.</p>
<p>Stay tuned!</p>
]]></content:encoded>
			<wfw:commentRss>http://qugstart.com/blog/qugstart/welcome-new-blog/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

