-
-
Save tispratik/7882444 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationController < ActionController::Base | |
protect_from_forgery | |
protected | |
def handle_unverified_request | |
super | |
raise ActionController::InvalidAuthenticityToken | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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