From bbc53f2b86f6bc3453e1dc29cc56c2792cee9f49 Mon Sep 17 00:00:00 2001 From: James Edwards-Jones Date: Tue, 8 May 2018 22:41:09 +0100 Subject: [PATCH] Backport with_forgery_protection spec helper --- spec/support/forgery_protection.rb | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/spec/support/forgery_protection.rb b/spec/support/forgery_protection.rb index a5e7b761651..fa87d5fa881 100644 --- a/spec/support/forgery_protection.rb +++ b/spec/support/forgery_protection.rb @@ -1,11 +1,18 @@ +module ForgeryProtection + def with_forgery_protection + ActionController::Base.allow_forgery_protection = true + yield + ensure + ActionController::Base.allow_forgery_protection = false + end + + module_function :with_forgery_protection +end + RSpec.configure do |config| config.around(:each, :allow_forgery_protection) do |example| - begin - ActionController::Base.allow_forgery_protection = true - + ForgeryProtection.with_forgery_protection do example.call - ensure - ActionController::Base.allow_forgery_protection = false end end end