Skip to content

Commit

Permalink
Fix not respecting the parent's #enable_processing value after readin…
Browse files Browse the repository at this point in the history
…g its own

Fixes #2676
  • Loading branch information
mshibuya committed Jul 22, 2023
1 parent 73bacd2 commit 2df0f53
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/carrierwave/uploader/versions.rb
Expand Up @@ -27,6 +27,17 @@ def build(superclass)
@klass.processors = []
@klass.version_options = @options
@klass.class_eval <<-RUBY, __FILE__, __LINE__ + 1
# Define the enable_processing method for versions so they get the
# value from the parent class unless explicitly overwritten
def self.enable_processing(value=nil)
self.enable_processing = value if value
if defined?(@enable_processing) && !@enable_processing.nil?
@enable_processing
else
superclass.enable_processing
end
end
# Regardless of what is set in the parent uploader, do not enforce the
# move_to_cache config option on versions because it moves the original
# file to the version's target file.
Expand Down
7 changes: 7 additions & 0 deletions spec/uploader/versions_spec.rb
Expand Up @@ -111,6 +111,13 @@ def store_dir
expect(@uploader.thumb.enable_processing).to be_truthy
end

it "should use the enable processing value of the parent after reading its own value" do
@uploader_class.version :thumb
@uploader.cache!(File.open(file_path('test.jpg')))
@uploader_class.enable_processing = false
expect(@uploader.thumb.class.enable_processing).to be_falsey
end

it "should reopen the same class when called multiple times" do
@uploader_class.version :thumb do
def self.monkey
Expand Down

0 comments on commit 2df0f53

Please sign in to comment.