Skip to content

Commit

Permalink
Rename #version_exists? to #version_active?, to reduce confusion
Browse files Browse the repository at this point in the history
Closes #1926
Refs. #1926 (comment)
  • Loading branch information
mshibuya committed Sep 22, 2024
1 parent 2d1af56 commit 21ca90a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/carrierwave/uploader/versions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,9 @@ def version_name
#
# === Returns
#
# [Boolean] True when the version exists according to its :if or :unless condition
# [Boolean] True when the version satisfy its :if or :unless condition
#
def version_exists?(name)
def version_active?(name)
name = name.to_sym

return false unless versions.has_key?(name)
Expand All @@ -222,6 +222,8 @@ def version_exists?(name)
true
end
end
alias_method :version_exists?, :version_active?
CarrierWave.deprecator.deprecate_methods(self, version_exists?: :version_active?)

##
# Copies the parent's cache_id when caching a version file.
Expand Down Expand Up @@ -299,7 +301,7 @@ def descendant_version_names

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

Expand Down
26 changes: 26 additions & 0 deletions spec/uploader/versions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,32 @@ def shorten
end
end
end

describe '#version_active?' do
before do
@file = File.open(file_path('test.jpg'))
@uploader_class.version(:preview, if: :true?)
end

it 'returns true when active' do
expect(@uploader).to receive(:true?).at_least(:once).and_return(true)
@uploader.store!(@file)
expect(@uploader.version_active?(:preview)).to be true
end

it 'returns false when inactive' do
expect(@uploader).to receive(:true?).at_least(:once).and_return(false)
@uploader.store!(@file)
expect(@uploader.version_active?(:preview)).to be false
end
end

describe '#version_exists' do
it 'shows deprecation' do
expect(CarrierWave.deprecator).to receive(:warn).with(/use version_active\? instead/, any_args)
@uploader.version_exists?(:preview)
end
end
end

describe 'with a version with option :from_version' do
Expand Down

0 comments on commit 21ca90a

Please sign in to comment.