Rails: possible routing discrepancy

Hey all, I’m seeing a strange behavior in my spec that I can’t
account for. I’ve got a route that looks like this:

map.writing
‘/writing’,
:controller => ‘abstracts’, :action => ‘index’,
:index => { :select => ‘all’ }

and I have template code that looks like this:


<%= link_to_unless_current ‘Writing’, writing_path %>

and I have a spec which calls this page, and checks to see that
‘Writing’ is not a link:

describe “’/writing/’” do
controller_name :abstracts
integrate_views

it “should not link ‘Writing’” do
get ‘index’, :index => { :select => ‘new’ }
response.body.should_not have_tag( ‘a’, ‘Writing’ )
end
end

… and it fails.

Normally, I’d assume I just messed up writing my routes, which is an
easy enough mistake for me to make. But when I actually open up my
browser and go to /writing, I see that the text is not being linked.
And the params hash that’s visible in my application log shows the
same params I think I’m generating in my spec:

Parameters: {“action”=>“index”, “controller”=>“abstracts”, “index”=>
{“select”=>“all”}}

but there seems to be a discrepancy nonetheless.

Then I started poking around in action_view/helpers/url_helper.rb, in
current_page?, which is used by link_to_unless_current. Here’s that
method:

def current_page?(options)
url_string = CGI.escapeHTML(url_for(options))
request = @controller.request
if url_string =~ /^\w+:///
url_string == “#{request.protocol}#{request.host_with_port}#
{request.request_uri}”
else
url_string == request.request_uri
end
end

So here’s the rub: When I’m running current_page? with script/server,
I get “/writing” for url_string and “/writing” for
@controller.request.request_uri – meaning current_page? works
correctly, and link_to_unless_current works correctly.

But, when I’m running current_page? from my spec, I get “/writing”
for url_string and “/abstracts?index%5Bselect%5D=new” for
@controller.request.request_uri – so current_page? works incorrectly
and so does link_to_unless_current.

Looks like that @controller.request is an RSpec request of some kind.
Is it possible the RSpec request isn’t handling route generation
correctly? Or should I be writing my spec differently?

Thanks,

Francis H.
http://fhwang.net/

Arg, please disregard that last email. My route and my request are
just different; I had to actually write that crazy long email, send
it out, and then read it again to see the mistake.

Francis H.
http://fhwang.net/

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs