[rspec-devel] [ rspec-Bugs-15282 ] POST, PUT and DELETE incorrectly append params to the request_uri

noreply at rubyforge.org noreply at rubyforge.org
Fri Nov 2 07:25:05 EDT 2007


Bugs item #15282, was opened at 2007-11-02 08:07
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3149&aid=15282&group_id=797

Category: rails plugin
Group: None
>Status: Closed
>Resolution: Rejected
Priority: 3
Submitted By: Jeff Dean (jefdean)
>Assigned to: David Chelimsky (dchelimsky)
Summary: POST, PUT and DELETE incorrectly append params to the request_uri

Initial Comment:
Given this form:

<pre><code>
<form action="/sessions/baz" method="post">
  <input type="text" name="foo" value="bar" />
  <input type="submit" />
</form>
</code></pre>

And this action:

<pre><code>
 class SessionsController < ApplicationController
  def baz
    render :text => "#{request.request_uri}<br/>#{params.inspect}"
  end
 end
</code></pre>

Submitting the form yields this output:

<pre><code>
/sessions/baz
{"action"=>"baz", "foo"=>"bar", "controller"=>"sessions"}
</code></pre>

This spec:

<pre><code>
describe SessionsController do
 it "should not append params to POST" do
  post :baz, :foo => :bar
  request.request_uri.should == "/sessions/baz"
 end
end
</code></pre>

Fail with this message:

<pre><code>
expected: "/sessions/baz",
     got: "/sessions/baz?foo=bar" (using ==)
</code></pre>

Notice how in the real app, rails properly interprets the request.request_uri, but in rspec_on_rails, the POST parameters are appended to the request_uri like GET paramaters. 

This is a bug because the spec does not correctly represent the behavior of rails.  I came up against this as I was trying to write a redirect that was based on the url of a page that was posted to, i.e.:

User posts form
Site recognizes that user is not logged in
Site redirects to login page, but stores params and request_uri
After login, repost the params to the request_uri

And I couldn't find a way to spec that.

----------------------------------------------------------------------

>Comment By: David Chelimsky (dchelimsky)
Date: 2007-11-02 11:25

Message:
RSpec controller specs wrap Rails functional tests, which handle this request.

Here's a similar test in Rails:

  def test_should_not_append_params_to_post
    post :baz, :foo => :bar
    assert_equal "/sessions/baz", @request.request_uri
  end

And here's the output:

  <"/sessions/baz"> expected but was
  <"/sessions/baz?foo=bar">.

I'd recommend posting this but to the Rails tracker.

----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3149&aid=15282&group_id=797


More information about the rspec-devel mailing list