Skip to content

Commit

Permalink
Fix return value of cached? according to document
Browse files Browse the repository at this point in the history
  • Loading branch information
kmiyake committed Sep 24, 2020
1 parent d41ad71 commit b1dbd7c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/carrierwave/uploader/cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def clean_cached_files!(seconds=60*60*24)
# [Bool] whether the current file is cached
#
def cached?
@cache_id
!!@cache_id
end

##
Expand Down
16 changes: 16 additions & 0 deletions spec/uploader/cache_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -325,4 +325,20 @@ def filename
expect(CarrierWave.generate_cache_id.split('-')[2].length).to eq(4)
end
end

describe '#cached?' do
context 'when cache_id is present' do
before { uploader.cache!(test_file) }

it 'returns true' do
expect(uploader).to be_cached
end
end

context 'when cache_id is NOT present' do
it 'returns false' do
expect(uploader).not_to be_cached
end
end
end
end

0 comments on commit b1dbd7c

Please sign in to comment.