Skip to content

Instantly share code, notes, and snippets.

@roberto
Created November 16, 2012 23:52
Show Gist options
  • Save roberto/4092007 to your computer and use it in GitHub Desktop.
Save roberto/4092007 to your computer and use it in GitHub Desktop.
Rspec: Anonymous controller
class ApplicationController < ActionController::Base
protect_from_forgery
rescue_from ActiveRecord::RecordNotFound, :with => :not_found
private
def not_found
respond_to do |format|
format.html { render file: "#{Rails.root}/public/404", status: 404, layout: false}
end
true
end
end
require 'spec_helper'
describe ApplicationController do
context "when record not found" do
controller do
def index
raise ActiveRecord::RecordNotFound
end
end
it "redirects to 404" do
get :index
expect(response).to render_template(file: "#{Rails.root}/public/404")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment