title: Cannot test with rspec controller POST create action( devise and cancan)
body: <p>I am having difficulty getting a rspec test for a controller to pass. I would like to test that the POST create action works.  I am using rails (3.0.3),  cancan (1.4.1), devise (1.1.5),  rspec (2.3.0)</p>
  
  <p>The model is dead simple</p>
  
  <pre><code>class Account &lt; ActiveRecord::Base
    attr_accessible :name 
  end
  </code></pre>
  
  <p>The controller is standard as well (straight out of scaffolding)</p>
  
  <pre><code>class AccountsController &lt; ApplicationController
    before_filter :authenticate_user!, :except =&gt; [:show, :index]
    load_and_authorize_resource
    ...
  
    def create
      @account = Account.new(params[:account])
  
      respond_to do |format|
        if @account.save
          format.html { redirect_to(@account, :notice =&gt; 'Account was successfully created.') }
          format.xml  { render :xml =&gt; @account, :status =&gt; :created, :location =&gt; @account }
        else
          format.html { render :action =&gt; "new" }
          format.xml  { render :xml =&gt; @account.errors, :status =&gt; :unprocessable_entity }
        end
      end
    end
  </code></pre>
  
  <p>and the rspec test I would like to pass is (excuse the title, perhaps not the most appropriate one)</p>
  
  <pre><code> it "should call create on account when POST create is called" do
     @user = Factory.create(:user)
     @user.admin = true
     @user.save
  
     sign_in @user #this is an admin
     post :create, :account =&gt; {"name" =&gt; "Jimmy Johnes"}
     response.should be_success
     sign_out @user
  
   end
  </code></pre>
  
  <p>Yet all I get is </p>
  
  <pre><code>AccountsController get index should call create on account when POST create is called
   Failure/Error: response.should be_success
   expected success? to return true, got false
   # ./spec/controllers/accounts_controller_spec.rb:46
  </code></pre>
  
  <p>Other actions can be tested and do pass (i.e. GET new)</p>
  
  <p>here is the test for GET new</p>
  
  <pre><code>it "should allow logged in admin to call new on account controller" do
    @user = Factory.create(:user)
    @user.admin=true
    @user.save
  
    sign_in @user #this is an admin
    get :new
    response.should be_success
    sign_out @user
  end
  </code></pre>
  
  <p>and for completion here is the ability file</p>
  
  <pre><code>class Ability
    include CanCan::Ability
  
    def initialize(user)
      user ||= User.new
      if user.admin?
        can :manage, :all
      else
        can :read, :all
      end
    end
  end
  </code></pre>
  
  <p>Any ideas? My guess is that I am using the wrong rspec expectation, since the code does work (it is just that the test does not perform as desired!)</p>