Using RSpec and Cancan, I have this test which fails with:
Failure/Error: User.should_receive(:new).and_return(@user)
expected: 1 time
received: 2 times
because
load_and_authorize_resource seems to call ‘new’ on the object as well. How do I work around this?
it "creates a new staff member" do
User.should_receive(:new).and_return(@user)
get :new, :format => "js"
end
–
class Admin::UsersController < ApplicationController
load_and_authorize_resource
def new
@user = User.new()
respond_to do |format|
format.js { render :action => "new" }
end
end
end
Well:
load_and_authorize_resourcewithauthorize_resourceOr:
@user = User.new()(which bears unnecessary parentheses)You’re definitely doing things twice here.