Skip to content

Commit

Permalink
Fix to respect condition on processing a derived version
Browse files Browse the repository at this point in the history
Fixes #2516
  • Loading branch information
mshibuya committed Jan 9, 2023
1 parent 743ee24 commit 1fecddc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/carrierwave/uploader/versions.rb
Expand Up @@ -263,24 +263,24 @@ def descendant_version_names
end
end

private

def active_versions
versions.select do |name, uploader|
version_exists?(name)
end
end

private

def derived_versions
active_versions.reject do |name, v|
v.class.version_options[:from_version]
end.to_a + sibling_versions.select do |name, v|
end.to_a + active_sibling_versions.select do |name, v|
v.class.version_options[:from_version] == self.class.version_names.last
end.to_a
end

def sibling_versions
parent_version.try(:versions) || []
def active_sibling_versions
parent_version&.active_versions || []
end

def full_filename(for_file)
Expand Down
10 changes: 10 additions & 0 deletions spec/uploader/versions_spec.rb
Expand Up @@ -727,6 +727,16 @@ def upcase
expect(File.read(public_path(@uploader.to_s))).not_to eq(File.read(public_path(@uploader.thumb.to_s)))
expect(File.read(public_path(@uploader.thumb.to_s))).to eq(File.read(public_path(@uploader.small_thumb.to_s)))
end

it "should not cache an inactive version" do
@uploader_class.class_eval do
def condition(_); false; end
end
@uploader_class.version(:conditional_thumb, :from_version => :thumb, :if => :condition)

@uploader.cache!(File.open(file_path('bork.txt')))
expect(@uploader.conditional_thumb.cached?).to be false
end
end

describe "#recreate_versions!" do
Expand Down

0 comments on commit 1fecddc

Please sign in to comment.