title: Ruby tutorial Ch9 Exercise #9 - Don't Allow Admin to Delete Themselves
body: <p>I am a total newbie to Ruby and Rails which is why I am going through the Rails Tutorial by Michael Hartl.  I am stuck on Chapter 9, Exercise #9.  I have updated the def destroy code in the Users Controller to:</p>
  
  <pre><code>def destroy
    user = User.find(params[:id])
    if (current_user == user) &amp;&amp; (current_user.admin?)
      flash[:error] = "Can not delete own admin account!"
    else
      user.destroy
      flash[:success] = "User destroyed."
    end
  redirect_to users_path
  end
  </code></pre>
  
  <p>This seems to work when I test in the browser by adding the "delete" link to the current_user when admin is logged in.  But the exercise says to write a test first - which I did but does not seem to work.  Here is what I have for the test:</p>
  
  <pre><code>describe "as admin user" do
    let(:user_admin) { FactoryGirl.create(:admin) }
  
    before { sign_in user_admin }
  
    describe "submitting a DELETE request to destroy own admin account" do
      before { delete user_path(user_admin) }
      it { should have_selector('div.alert.alert-error', text: 'delete own admin') }
    end
  end
  </code></pre>
  
  <p>Maybe what I am testing should not be tested.  How do you test the modification of the def destroy code in the Users Controller?</p>