Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #898 from nanoc/better-modified-reps-method
Add #modified_reps and deprecate #modified
  • Loading branch information
denisdefreyne committed Jul 3, 2016
2 parents 2331305 + f785a7d commit eae92f8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/nanoc/base/views/post_compile_item_view.rb
@@ -1,7 +1,12 @@
module Nanoc
class PostCompileItemView < Nanoc::ItemWithRepsView
# @deprecated Use {#modified_reps} instead
def modified
reps.select { |rep| rep.unwrap.modified }
modified_reps
end

def modified_reps
reps.select { |rep| rep.unwrap.modified? }
end
end
end
36 changes: 36 additions & 0 deletions spec/nanoc/base/views/post_compile_item_view_spec.rb
@@ -0,0 +1,36 @@
describe Nanoc::PostCompileItemView do
shared_examples 'a method that returns modified reps only' do
let(:item) { Nanoc::Int::Item.new('blah', {}, '/foo.md') }
let(:rep_a) { Nanoc::Int::ItemRep.new(item, :no_mod) }
let(:rep_b) { Nanoc::Int::ItemRep.new(item, :modded).tap { |r| r.modified = true } }

let(:reps) do
Nanoc::Int::ItemRepRepo.new.tap do |reps|
reps << rep_a
reps << rep_b
end
end

let(:view_context) { double(:view_context, reps: reps) }
let(:view) { described_class.new(item, view_context) }

it 'returns only modified items' do
expect(subject.size).to eq(1)
expect(subject.map(&:name)).to eq(%i(modded))
end

it 'returns an array' do
expect(subject.class).to eql(Array)
end
end

describe '#modified_reps' do
subject { view.modified_reps }
it_behaves_like 'a method that returns modified reps only'
end

describe '#modified' do
subject { view.modified }
it_behaves_like 'a method that returns modified reps only'
end
end

0 comments on commit eae92f8

Please sign in to comment.