Created
October 25, 2011 23:08
-
-
Save adammck/1314693 to your computer and use it in GitHub Desktop.
Temporarily patch the Rails configuration for the duration of a block
This file contains hidden or 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
| # 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