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?
-----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-----
On Nov 19, 2005, at 8:06 PM, Matthew Thill wrote:> 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.bodyIn 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> > 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? > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails
That was it, thank you for the replies Jeremy and Jamis. Matthew Thill wrote:> 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? > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails