Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
2 changed files
with
42 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |