Skip to content
Permalink
Browse files

Merge pull request #1056 from nanoc/snapshot-eh

Add #snapshot?
  • Loading branch information...
ddfreyne committed Jan 22, 2017
2 parents e8a6002 + f7483af commit 747aefd50cbf5d13bab537bf9bdb292b35a57686
@@ -44,6 +44,11 @@ def initialize(item, name)
@compiled = false
end

contract Symbol => C::Bool
def snapshot?(name)
snapshot_defs.any? { |sd| sd.name == name }
end

contract C::KeywordArgs[snapshot: C::Optional[Symbol]] => C::Maybe[String]
# Returns the item rep’s raw path. It includes the path to the output
# directory and the full filename.
@@ -46,6 +46,11 @@ def compiled_content(snapshot: nil)
@context.snapshot_repo.compiled_content(rep: unwrap, snapshot: snapshot)
end

def snapshot?(name)
@context.dependency_tracker.bounce(unwrap.item, compiled_content: true)
@item_rep.snapshot?(name)
end

# Returns the item rep’s path, as used when being linked to. It starts
# with a slash and it is relative to the output directory. It does not
# include the path to the output directory. It will not include the
@@ -1,4 +1,24 @@
describe Nanoc::Int::ItemRep do
let(:item) { Nanoc::Int::Item.new('asdf', {}, '/foo.md') }
let(:rep) { Nanoc::Int::ItemRep.new(item, :giraffe) }

describe '#snapshot?' do
subject { rep.snapshot?(snapshot_name) }

let(:snapshot_name) { raise 'override me' }

before do
rep.snapshot_defs = [Nanoc::Int::SnapshotDef.new(:donkey)]
end

context 'snapshot does not exist' do
let(:snapshot_name) { :giraffe }
it { is_expected.not_to be }
end

context 'snapshot exists' do
let(:snapshot_name) { :donkey }
it { is_expected.to be }
end
end
end
@@ -137,6 +137,73 @@
it { should == described_class.hash ^ Nanoc::Identifier.new('/foo/').hash ^ :jacques.hash }
end

describe '#snapshot?' do
subject { view.snapshot?(snapshot_name) }

let(:view) { described_class.new(rep, view_context) }

let(:rep) do
Nanoc::Int::ItemRep.new(item, :default).tap do |ir|
ir.compiled = true
ir.snapshot_defs = [
Nanoc::Int::SnapshotDef.new(:last),
]
end
end

let(:item) do
Nanoc::Int::Item.new('content', {}, '/asdf.md')
end

let(:snapshot_name) { raise 'override me' }

before do
snapshot_repo.set(rep, :last, Nanoc::Int::TextualContent.new('Hallo'))
end

context 'snapshot exists' do
let(:snapshot_name) { :last }

it 'creates a dependency' do
expect { subject }.to change { dependency_store.objects_causing_outdatedness_of(base_item) }.from([]).to([item])
end

it 'creates a dependency with the right props' do
subject
dep = dependency_store.dependencies_causing_outdatedness_of(base_item)[0]

expect(dep.props.compiled_content?).to eq(true)

expect(dep.props.raw_content?).to eq(false)
expect(dep.props.attributes?).to eq(false)
expect(dep.props.path?).to eq(false)
end

it { is_expected.to be }
end

context 'snapshot does not exist' do
let(:snapshot_name) { :donkey }

it 'creates a dependency' do
expect { subject }.to change { dependency_store.objects_causing_outdatedness_of(base_item) }.from([]).to([item])
end

it 'creates a dependency with the right props' do
subject
dep = dependency_store.dependencies_causing_outdatedness_of(base_item)[0]

expect(dep.props.compiled_content?).to eq(true)

expect(dep.props.raw_content?).to eq(false)
expect(dep.props.attributes?).to eq(false)
expect(dep.props.path?).to eq(false)
end

it { is_expected.not_to be }
end
end

describe '#compiled_content' do
subject { view.compiled_content }

0 comments on commit 747aefd

Please sign in to comment.
You can’t perform that action at this time.