<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.0.4" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: Using url_for in Ruby on Rails tests</title>
	<link>http://jotthought.com/articles/2007/05/04/using-url_for-in-ruby-on-rails-tests/</link>
	<description>A place for me to speak my mind</description>
	<pubDate>Fri, 21 Nov 2008 07:56:39 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.4</generator>

	<item>
		<title>by: Ben</title>
		<link>http://jotthought.com/articles/2007/05/04/using-url_for-in-ruby-on-rails-tests/#comment-1844</link>
		<pubDate>Tue, 29 May 2007 17:46:29 +0000</pubDate>
		<guid>http://jotthought.com/articles/2007/05/04/using-url_for-in-ruby-on-rails-tests/#comment-1844</guid>
					<description>Thanks Justin. We created the bare minimum here. If you want url_for to work exactly like ActionController::Base I suggest that you take a look at the ActionController::Base.url_for source code. There is a little more checking on whether the parameter is a String, Hash or Symbol. It also provides a way to provide default options.

It is a shame that all of this behavior is not encapsulated. It may be a good patch to extract the url_for method into a helper class that ActionController::Base uses. We could then use the same helper class in our tests and ensure the functionality between ActionController::Base.url_for and the test_help.url_for remain identical.

Maybe I'll bring that up on the Ruby on Rails Core team mailing list to see if it would be worth my time.</description>
		<content:encoded><![CDATA[<p>Thanks Justin. We created the bare minimum here. If you want url_for to work exactly like ActionController::Base I suggest that you take a look at the ActionController::Base.url_for source code. There is a little more checking on whether the parameter is a String, Hash or Symbol. It also provides a way to provide default options.</p>
<p>It is a shame that all of this behavior is not encapsulated. It may be a good patch to extract the url_for method into a helper class that ActionController::Base uses. We could then use the same helper class in our tests and ensure the functionality between ActionController::Base.url_for and the test_help.url_for remain identical.</p>
<p>Maybe I&#8217;ll bring that up on the Ruby on Rails Core team mailing list to see if it would be worth my time.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: justin</title>
		<link>http://jotthought.com/articles/2007/05/04/using-url_for-in-ruby-on-rails-tests/#comment-1843</link>
		<pubDate>Tue, 29 May 2007 17:36:26 +0000</pubDate>
		<guid>http://jotthought.com/articles/2007/05/04/using-url_for-in-ruby-on-rails-tests/#comment-1843</guid>
					<description>actually, merging in :only_path =&#62; true is a better solution than overwriting the protocol and host parts.</description>
		<content:encoded><![CDATA[<p>actually, merging in <img src='http://jotthought.com/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> nly_path =&gt; true is a better solution than overwriting the protocol and host parts.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: justin</title>
		<link>http://jotthought.com/articles/2007/05/04/using-url_for-in-ruby-on-rails-tests/#comment-1842</link>
		<pubDate>Tue, 29 May 2007 17:34:38 +0000</pubDate>
		<guid>http://jotthought.com/articles/2007/05/04/using-url_for-in-ruby-on-rails-tests/#comment-1842</guid>
					<description>thanks a lot, very helpful. I added this to my test_helper

  def url_for options
    url = ActionController::UrlRewriter.new(@request, nil)
    # rewrite the url, but we don't want the protocol and host part, only the actual path
    url.rewrite(options.merge( :protocol =&#62; '', :host =&#62; '' ))
  end unless defined? url_for

I erase the protocol and host so that the returned path does NOT have the http://example.com/ part, which gets in the way.

May not be the best way to do it, but seems to fill me needs.</description>
		<content:encoded><![CDATA[<p>thanks a lot, very helpful. I added this to my test_helper</p>
<p>  def url_for options<br />
    url = ActionController::UrlRewriter.new(@request, nil)<br />
    # rewrite the url, but we don&#8217;t want the protocol and host part, only the actual path<br />
    url.rewrite(options.merge( :protocol =&gt; &#8216;&#8217;, :host =&gt; &#8216;&#8217; ))<br />
  end unless defined? url_for</p>
<p>I erase the protocol and host so that the returned path does NOT have the <a href='http://example.com/' rel='nofollow'>http://example.com/</a> part, which gets in the way.</p>
<p>May not be the best way to do it, but seems to fill me needs.
</p>
]]></content:encoded>
				</item>
</channel>
</rss>
