title: RSpec controller spec fails on update with invalid params
body: <p>One of the tests in a scaffold-generated RSpec controller spec fails, and it looks to me as if it must always fail by design, but of course it is surely supposed to succeed.</p>
  
  <p>I develop a Rails 4 app with RSpec specs generated by <code>rails g scaffold</code>.</p>
  
  <p>The controller spec for my <code>SkillsController</code> requires me to fill in a 'valid attributes' hash and an 'invalid attributes' hash for my model, which I did.</p>
  
  <p>The tests <em>all</em> succeed <em>except</em> for "PUT update with invalid params re-render the 'edit' template":</p>
  
  <pre><code> 1) SkillsController PUT update with invalid params re-renders the 'edit' template
      Failure/Error: expect(response).to render_template("edit")
        expecting &lt;"edit"&gt; but rendering with &lt;[]&gt;
      # ./spec/controllers/skills_controller_spec.rb:139:in `block (4 levels) in &lt;top (required)&gt;'
  </code></pre>
  
  <p>In the Rails console, I confirmed that my <code>invalid_params</code> hash contains invalid parameters (<code>{ hack: 'hack' }</code>).</p>
  
  <p>The controller calls the <code>skill_params</code> method which returns an empty hash because my <code>invalid_params</code> hash contains only invalid parameters.</p>
  
  <p>Calling <code>skill.update(skill_params)</code> with an empty <code>skill_params</code> hash returns true, so that the <code>else</code> part will never execute, and the 'new' template will not be rendered:</p>
  
  <pre><code>  def update
      respond_to do |format|
        if @skill.update(skill_params) # empty hash due to invalid params!
          format.html { redirect_to @skill, notice: 'Skill was successfully updated.' }
          format.json { render :show, status: :ok, location: @skill }
        else
          format.html { render :edit }
          format.json { render json: @skill.errors, status: :unprocessable_entity }
        end
      end
    end
  </code></pre>
  
  <p>To summarize: The spec PUTs a hash with invalid parameters to my SkillController. The SkillController's 'skill_params' cleans up this hash, returning an empty hash. <code>skill.update</code> with an empty hash is a no-op (confirmed on the console), and the method returns <code>true</code>.</p>
  
  <p>Therefore, the assertion that the 'edit' template should be rendered will never, ever be true, and the default controller spec for the update action with invalid params will never turn green.</p>
  
  <p>What am I missing here?</p>