Skip to content

Commit

Permalink
fixup! Do not reuse cached binary content
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdefreyne committed Mar 5, 2017
1 parent ba1396b commit 196199c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/nanoc/base/services/compiler/phases/cache.rb
Expand Up @@ -30,7 +30,7 @@ def can_reuse_content_for_rep?(rep, is_outdated:)
false
else
cache = @compiled_content_cache[rep]
cache && cache.none? { |_snapshot_name, content| content.binary? }
cache ? cache.none? { |_snapshot_name, content| content.binary? } : false
end
end
end
Expand Down
39 changes: 37 additions & 2 deletions spec/nanoc/base/services/compiler/phases/cache_spec.rb
Expand Up @@ -69,12 +69,12 @@ def run(rep, is_outdated:) # rubocop:disable Lint/UnusedMethodArgument
context 'not outdated' do
let(:is_outdated) { false }

context 'cached compiled content available' do
context 'textual cached compiled content available' do
before do
compiled_content_cache[rep] = { last: Nanoc::Int::TextualContent.new('cached') }
end

it 'reuses content from cache' do
it 'writes content to cache' do
expect { subject }
.to change { snapshot_repo.get(rep, :last) }
.from(nil)
Expand All @@ -99,6 +99,41 @@ def run(rep, is_outdated:) # rubocop:disable Lint/UnusedMethodArgument
end
end

context 'binary cached compiled content available' do
let(:binary_content) { 'b1n4ry' }
let(:binary_filename) { Tempfile.open('test') { |fn| fn << binary_content }.path }

before do
compiled_content_cache[rep] = { last: Nanoc::Int::BinaryContent.new(binary_filename) }
end

it 'writes content to cache' do
expect { subject }
.to change { snapshot_repo.get(rep, :last) }
.from(nil)
.to(some_textual_content('wrapped content'))
end

it 'marks rep as compiled' do
expect { subject }
.to change { rep.compiled? }
.from(false)
.to(true)
end

it 'changes compiled content cache' do
expect { subject }
.to change { compiled_content_cache[rep] }
.from(last: some_binary_content(binary_content))
.to(last: some_textual_content('wrapped content'))
end

it 'does not send notification' do
expect(Nanoc::Int::NotificationCenter).not_to receive(:post).with(:cached_content_used, rep)
subject
end
end

context 'no cached compiled content available' do
include_examples 'calls wrapped'
end
Expand Down

0 comments on commit 196199c

Please sign in to comment.