Skip to content
Browse files

Allows configuration values to be Proc instances and solves race cond…

…ition setting value or #root
  • Loading branch information...
1 parent 6619909 commit b4bc77270bd25a243e26513dac658a2f71c2d507 @jcarlson jcarlson committed Sep 5, 2011
Showing with 15 additions and 3 deletions.
  1. +3 −2 lib/carrierwave/uploader/configuration.rb
  2. +12 −1 spec/uploader/paths_spec.rb
View
5 lib/carrierwave/uploader/configuration.rb
@@ -106,7 +106,8 @@ def self.#{name}=(value)
end
def #{name}
- self.class.#{name}
+ value = self.class.#{name}
+ value.instance_of?(Proc) ? value.call : value
end
RUBY
end
@@ -149,7 +150,7 @@ def reset_config
config.ignore_processing_errors = true
config.validate_integrity = true
config.validate_processing = true
- config.root = CarrierWave.root
+ config.root = lambda { CarrierWave.root }
config.enable_processing = true
config.ensure_multipart_form = true
end
View
13 spec/uploader/paths_spec.rb
@@ -5,18 +5,29 @@
describe CarrierWave::Uploader do
before do
+ @root = CarrierWave.root
+ CarrierWave.root = nil
@uploader_class = Class.new(CarrierWave::Uploader::Base)
@uploader = @uploader_class.new
end
after do
FileUtils.rm_rf(public_path)
+ CarrierWave.root = @root
end
describe '#root' do
+
it "should default to the config option" do
@uploader.root.should == public_path
end
+
+ it "should default to the current value of CarrierWave.root" do
+ @uploader.root.should be_nil
+ CarrierWave.root = public_path
+ @uploader.root.should == public_path
+ end
+
end
-
+
end

0 comments on commit b4bc772

Please sign in to comment.
Something went wrong with that request. Please try again.