I am using rspec-rails (2.8.1) for functional testing of a rails 3.1 application using mangoid (3.4.7) to save. I am trying to do a rescue_from check for Mongoid :: Errors :: DocumentNotFound errors in my ApplicationController in the same way as rspec-rails documentation for anonymous controllers that this can be done, But when I run the following test ...
require "spec_helper"
class ApplicationController < ActionController::Base
rescue_from Mongoid::Errors::DocumentNotFound, :with => :access_denied
private
def access_denied
redirect_to "/401.html"
end
end
describe ApplicationController do
controller do
def index
raise Mongoid::Errors::DocumentNotFound
end
end
describe "handling AccessDenied exceptions" do
it "redirects to the /401.html page" do
get :index
response.should redirect_to("/401.html")
end
end
end
I get the following unexpected error
1) ApplicationController handling AccessDenied exceptions redirects to the /401.html page
Failure/Error: raise Mongoid::Errors::DocumentNotFound
ArgumentError:
wrong number of arguments (0 for 2)
Why? How can I raise this mongoid error?
source
share