Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I write a functional test for the update action in a controller?
    primarykey
    data
    text
    <p>With actions such as <code>:show</code> and <code>:edit</code>, I can just http GET them. But since the <code>:update</code> action has no template, I can't issue a GET without it complaining about the missing template. That makes sense, so I tried to directly call <code>@controller.update</code> in my test, but I get an error on the <code>respond_to</code> block:</p> <pre><code>NoMethodError: undefined method `parameters' for nil:NilClass </code></pre> <p>How do I specify the requested format to be <code>:html</code>? I am passing in a parameter hash for the model's attributes, FWIW. Thanks for any advice.</p> <p>Edit: I since tried invoking @controller.update (after setting params[]) in the console and that error quoted above bubbled up from here: /actionpack-2.3.8/lib/action_controller/mime_responds.rb</p> <p>I also tried PUT instead of GET, but still got "Missing Template update.erb". </p> <p>Also, I managed to find out that this error of missing template is caused by having anything other than a redirect or render in the code block marked HERE:</p> <pre><code>respond_to do |format| if @model.update_attributes(params[:model]) flash[:notice] = 'note!' format.html { **HERE** } ... </code></pre> <p>I have a method call there that is just a conditional to redirect to the proper place. I can, in principle, understand why it might look for a template to render since it may not be aware that there is a redirect further downstream, but what I don't understand is how come my web application doesn't run into the same error as my functional test.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload