Skip to content

Instantly share code, notes, and snippets.

@adammck
Created October 25, 2011 23:08
Show Gist options
  • Save adammck/1314693 to your computer and use it in GitHub Desktop.
Save adammck/1314693 to your computer and use it in GitHub Desktop.
Temporarily patch the Rails configuration for the duration of a block
# Temporarily patch the Rails configuration for the duration of a block.
# For example:
#
# test "should create a resque job when background_jobs is true" do
# with_config :background_jobs=>true do
# repo = Repo.create :url=>TEST_CLONE_URL
# assert_queued(CloneJob, [repo.pk])
# end
# end
#
def with_config(opts)
old_config = {}
opts.each do |key, value|
old_config[key] = Rails.configuration.send(key)
Rails.configuration.send("#{key}=", value)
end
begin
yield
ensure
old_config.each do |key, value|
Rails.configuration.send("#{key}=", value)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment