Skip to content

Instantly share code, notes, and snippets.

@tispratik
Forked from caike/application_controller.rb
Created December 9, 2013 22:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tispratik/7882444 to your computer and use it in GitHub Desktop.
Save tispratik/7882444 to your computer and use it in GitHub Desktop.
class ApplicationController < ActionController::Base
protect_from_forgery
protected
def handle_unverified_request
super
raise ActionController::InvalidAuthenticityToken
end
end
require 'spec_helper'
describe JobsController do
it 'raises error with invalid authenticity token' do
with_forgery_protection do
expect { post :create }.to raise_error
end
end
private
def with_forgery_protection
_old_value = @controller.allow_forgery_protection
@controller.allow_forgery_protection = true
yield
ensure
@controller.allow_forgery_protection = _old_value
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment