Forum: Ruby on Rails Functional testing issue

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
429e9d8e16b3c6e4ab0c954893e0334a?d=identicon&s=25 mithill (Guest)
on 2005-11-20 04:08
(Received via mailing list)
This is a really basic test, but the rails test environment does not
give me the results I expect. Hopefully someone can set me straight.

I send in a get request with one parameter and the application opens a
page to edit this object - fairly basic. On this edit view there is a
hidden field that contains the id value of the object. When I do this in
the "real" application and view the source of the rendered html page,
everything is as expected. However, when I do the same request through
the functional test, the hidden input tag is created but the value
attribute is not set. This is confirmed with an assert_tag statement and
by visual inspection of the result of "puts @response.body".

To head off the obvious, I have double checked that the appropriate
fixtures are loaded, that the object with the id I specify is in the
test database and that I am specifying the correct id.

The test database has an event with id = 1 and my dev database has an
event with an id = 5

Here is the call to "get" in the test. @session_admin is just a session
hash I've set up to have the administrator logged on.

get(:show, {'event[id]' => '1'}, @session_admin)
puts @response.body

When I look at the output, the hidden field shows up but it has no value
attribute, as follows:

<input id="event_id" name="event[id]" type="hidden" />

The hidden field is defined in the view as follows:

<%= hidden_field('event','id') %>

Now, I use the following URL while running the application logged on as
the administrator:
http://localhost:3000/events/show?event[id]=5

I view the source of the html document, and the hidden field is

<input id="event_id" name="event[id]" type="hidden" value="5" />

What's the story here?
24d2f8804e6bb4b7ea6bd11e0a586470?d=identicon&s=25 jeremy (Guest)
on 2005-11-20 04:16
(Received via mailing list)
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Nov 19, 2005, at 7:06 PM, Matthew Thill wrote:
> get(:show, {'event[id]' => '1'}, @session_admin)

See whether this helps:
   get :show, {'event' => { 'id' => '1' }}, @session_admin

Not sure about the source of the discrepancy you're seeing.

jeremy
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (Darwin)

iD8DBQFDf+mzAQHALep9HFYRAqHOAJ4syIcPhssymZZ0eWwaHwunCqlDrwCghD9W
dU45ICz7gNVIS/BsEuKHuTc=
=RJLj
-----END PGP SIGNATURE-----
992fe8c19bbbc27f2b562a9f96efc03d?d=identicon&s=25 jamis (Guest)
on 2005-11-20 04:28
(Received via mailing list)
On Nov 19, 2005, at 8:06 PM, Matthew Thill wrote:

> is created but the value attribute is not set. This is confirmed
> Here is the call to "get" in the test. @session_admin is just a
> session hash I've set up to have the administrator logged on.
>
> get(:show, {'event[id]' => '1'}, @session_admin)
> puts @response.body

In functional tests, the parameters are not parsed. You need to pass
in the hash that the parameters will be converted to:

   get :show, {:event => { :id => '1' }}, @session_admin

- Jamis
429e9d8e16b3c6e4ab0c954893e0334a?d=identicon&s=25 mithill (Guest)
on 2005-11-20 17:41
(Received via mailing list)
That was it, thank you for the replies Jeremy and Jamis.
This topic is locked and can not be replied to.