Skip to content

Commit

Permalink
fixup! Disallow full identifiers from ending with a slash
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdefreyne committed Aug 22, 2017
1 parent 2a25f37 commit 655c981
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 59 deletions.
2 changes: 1 addition & 1 deletion spec/nanoc/base/services/executor_spec.rb
Expand Up @@ -653,7 +653,7 @@ def run(_content, params = {})
let(:arg) { '/default' }

let(:layouts) do
[Nanoc::Int::Layout.new('head <%= @foo %> foot', {}, '/default/')]
[Nanoc::Int::Layout.new('head <%= @foo %> foot', {}, Nanoc::Identifier.new('/default/', type: :legacy))]
end

it { is_expected.to eq(layouts[0]) }
Expand Down
2 changes: 1 addition & 1 deletion spec/nanoc/base/views/document_view_spec.rb
Expand Up @@ -312,7 +312,7 @@

subject { view.hash }

it { should == described_class.hash ^ '/foo/'.hash }
it { should == described_class.hash ^ '/foo'.hash }
end

describe '#raw_content' do
Expand Down
4 changes: 2 additions & 2 deletions spec/nanoc/base/views/item_rep_view_spec.rb
Expand Up @@ -52,7 +52,7 @@
let(:view) { described_class.new(item_rep, view_context) }

context 'comparing with item rep with same identifier' do
let(:other_item) { double(:other_item, identifier: '/foo/') }
let(:other_item) { double(:other_item, identifier: '/foo') }
let(:other) { double(:other_item_rep, item: other_item, name: :jacques) }

it 'is ==' do
Expand Down Expand Up @@ -404,6 +404,6 @@

subject { view.inspect }

it { is_expected.to eql('<Nanoc::ItemRepView item.identifier=/foo/ name=jacques>') }
it { is_expected.to eql('<Nanoc::ItemRepView item.identifier=/foo name=jacques>') }
end
end
30 changes: 19 additions & 11 deletions spec/nanoc/base/views/item_view_spec.rb
Expand Up @@ -53,15 +53,15 @@
subject { view.parent }

context 'with parent' do
let(:parent_item) do
Nanoc::Int::Item.new('parent', {}, '/parent/')
end

context 'full identifier' do
let(:identifier) do
Nanoc::Identifier.new('/parent/me.md')
end

let(:parent_item) do
Nanoc::Int::Item.new('parent', {}, '/parent.md')
end

it 'raises' do
expect { subject }.to raise_error(Nanoc::Int::Errors::CannotGetParentOrChildrenOfNonLegacyItem)
end
Expand All @@ -72,6 +72,10 @@
Nanoc::Identifier.new('/parent/me/', type: :legacy)
end

let(:parent_item) do
Nanoc::Int::Item.new('parent', {}, Nanoc::Identifier.new('/parent/', type: :legacy))
end

it 'returns a view for the parent' do
expect(subject.class).to eql(Nanoc::ItemWithRepsView)
expect(subject.unwrap).to eql(parent_item)
Expand Down Expand Up @@ -134,10 +138,6 @@
Nanoc::Int::Item.new('me', {}, identifier)
end

let(:children) do
[Nanoc::Int::Item.new('child', {}, '/me/child/')]
end

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

let(:items) do
Expand All @@ -157,6 +157,10 @@
Nanoc::Identifier.new('/me.md')
end

let(:children) do
[Nanoc::Int::Item.new('child', {}, '/me/child.md')]
end

it 'raises' do
expect { subject }.to raise_error(Nanoc::Int::Errors::CannotGetParentOrChildrenOfNonLegacyItem)
end
Expand All @@ -167,6 +171,10 @@
Nanoc::Identifier.new('/me/', type: :legacy)
end

let(:children) do
[Nanoc::Int::Item.new('child', {}, Nanoc::Identifier.new('/me/child/', type: :legacy))]
end

it 'returns views for the children' do
expect(subject.size).to eql(1)
expect(subject[0].class).to eql(Nanoc::ItemWithRepsView)
Expand Down Expand Up @@ -209,7 +217,7 @@
let(:view) { described_class.new(item, view_context) }

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

let(:reps) do
Expand Down Expand Up @@ -356,11 +364,11 @@
end

describe '#inspect' do
let(:item) { Nanoc::Int::Item.new('content', {}, '/asdf/') }
let(:item) { Nanoc::Int::Item.new('content', {}, '/asdf') }
let(:view) { described_class.new(item, nil) }

subject { view.inspect }

it { is_expected.to eql('<Nanoc::ItemWithRepsView identifier=/asdf/>') }
it { is_expected.to eql('<Nanoc::ItemWithRepsView identifier=/asdf>') }
end
end
4 changes: 2 additions & 2 deletions spec/nanoc/base/views/layout_view_spec.rb
Expand Up @@ -6,11 +6,11 @@
it_behaves_like 'a document view'

describe '#inspect' do
let(:item) { Nanoc::Int::Layout.new('content', {}, '/asdf/') }
let(:item) { Nanoc::Int::Layout.new('content', {}, '/asdf') }
let(:view) { described_class.new(item, nil) }

subject { view.inspect }

it { is_expected.to eql('<Nanoc::LayoutView identifier=/asdf/>') }
it { is_expected.to eql('<Nanoc::LayoutView identifier=/asdf>') }
end
end
10 changes: 5 additions & 5 deletions spec/nanoc/base/views/mutable_item_collection_view_spec.rb
Expand Up @@ -12,7 +12,7 @@

describe '#create' do
let(:item) do
Nanoc::Int::Layout.new('content', {}, '/asdf/')
Nanoc::Int::Layout.new('content', {}, '/asdf')
end

let(:wrapped) do
Expand All @@ -22,21 +22,21 @@
let(:view) { described_class.new(wrapped, nil) }

it 'creates an object' do
view.create('new content', { title: 'New Page' }, '/new/')
view.create('new content', { title: 'New Page' }, '/new')

expect(view.unwrap.size).to eq(2)
expect(view.unwrap['/new/'].content.string).to eq('new content')
expect(view.unwrap['/new'].content.string).to eq('new content')
end

it 'does not update wrapped' do
view.create('new content', { title: 'New Page' }, '/new/')
view.create('new content', { title: 'New Page' }, '/new')

expect(wrapped.size).to eq(1)
expect(wrapped['/new']).to be_nil
end

it 'returns self' do
ret = view.create('new content', { title: 'New Page' }, '/new/')
ret = view.create('new content', { title: 'New Page' }, '/new')
expect(ret).to equal(view)
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/nanoc/base/views/mutable_item_view_spec.rb
Expand Up @@ -4,7 +4,7 @@
let(:entity_class) { Nanoc::Int::Item }
it_behaves_like 'a mutable document view'

let(:item) { entity_class.new('content', {}, '/asdf/') }
let(:item) { entity_class.new('content', {}, '/asdf') }
let(:view) { described_class.new(item, nil) }

it 'does have rep access' do
Expand All @@ -14,11 +14,11 @@
end

describe '#inspect' do
let(:item) { Nanoc::Int::Item.new('content', {}, '/asdf/') }
let(:item) { Nanoc::Int::Item.new('content', {}, '/asdf') }
let(:view) { described_class.new(item, nil) }

subject { view.inspect }

it { is_expected.to eql('<Nanoc::MutableItemView identifier=/asdf/>') }
it { is_expected.to eql('<Nanoc::MutableItemView identifier=/asdf>') }
end
end
10 changes: 5 additions & 5 deletions spec/nanoc/base/views/mutable_layout_collection_view_spec.rb
Expand Up @@ -12,7 +12,7 @@

describe '#create' do
let(:layout) do
Nanoc::Int::Layout.new('content', {}, '/asdf/')
Nanoc::Int::Layout.new('content', {}, '/asdf')
end

let(:wrapped) do
Expand All @@ -22,21 +22,21 @@
let(:view) { described_class.new(wrapped, nil) }

it 'creates an object' do
view.create('new content', { title: 'New Page' }, '/new/')
view.create('new content', { title: 'New Page' }, '/new')

expect(view.unwrap.size).to eq(2)
expect(view.unwrap['/new/'].content.string).to eq('new content')
expect(view.unwrap['/new'].content.string).to eq('new content')
end

it 'does not update wrapped' do
view.create('new content', { title: 'New Page' }, '/new/')
view.create('new content', { title: 'New Page' }, '/new')

expect(wrapped.size).to eq(1)
expect(wrapped['/new']).to be_nil
end

it 'returns self' do
ret = view.create('new content', { title: 'New Page' }, '/new/')
ret = view.create('new content', { title: 'New Page' }, '/new')
expect(ret).to equal(view)
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/nanoc/base/views/mutable_layout_view_spec.rb
Expand Up @@ -5,11 +5,11 @@
it_behaves_like 'a mutable document view'

describe '#inspect' do
let(:item) { Nanoc::Int::Item.new('content', {}, '/asdf/') }
let(:item) { Nanoc::Int::Item.new('content', {}, '/asdf') }
let(:view) { described_class.new(item, nil) }

subject { view.inspect }

it { is_expected.to eql('<Nanoc::MutableLayoutView identifier=/asdf/>') }
it { is_expected.to eql('<Nanoc::MutableLayoutView identifier=/asdf>') }
end
end
2 changes: 1 addition & 1 deletion spec/nanoc/data_sources/filesystem_spec.rb
Expand Up @@ -47,7 +47,7 @@

expect(subject[0].content.string).to eq('test 1')
expect(subject[0].attributes).to eq(expected_attributes)
expect(subject[0].identifier).to eq(Nanoc::Identifier.new('/bar/'))
expect(subject[0].identifier).to eq(Nanoc::Identifier.new('/bar/', type: :legacy))
expect(subject[0].checksum_data).to be_nil
expect(subject[0].attributes_checksum_data).to be_a(String)
expect(subject[0].attributes_checksum_data.size).to eq(20)
Expand Down
36 changes: 18 additions & 18 deletions spec/nanoc/helpers/blogging_spec.rb
Expand Up @@ -10,13 +10,13 @@
subject { helper.articles }

before do
ctx.create_item('blah', { kind: 'item' }, '/0/')
ctx.create_item('blah blah', { kind: 'article' }, '/1/')
ctx.create_item('blah blah blah', { kind: 'article' }, '/2/')
ctx.create_item('blah', { kind: 'item' }, '/0')
ctx.create_item('blah blah', { kind: 'article' }, '/1')
ctx.create_item('blah blah blah', { kind: 'article' }, '/2')
end

it 'returns the two articles' do
expect(subject.map(&:identifier)).to match_array(['/1/', '/2/'])
expect(subject.map(&:identifier)).to match_array(['/1', '/2'])
end
end

Expand All @@ -25,28 +25,28 @@

before do
attrs = { kind: 'item' }
ctx.create_item('blah', attrs, '/0/')
ctx.create_item('blah', attrs, '/0')

attrs = { kind: 'article', created_at: (Date.today - 1).to_s }
ctx.create_item('blah blah', attrs, '/1/')
ctx.create_item('blah blah', attrs, '/1')

attrs = { kind: 'article', created_at: (Time.now - 500).to_s }
ctx.create_item('blah blah blah', attrs, '/2/')
ctx.create_item('blah blah blah', attrs, '/2')
end

it 'returns the two articles in descending order' do
expect(subject.map(&:identifier)).to eq(['/2/', '/1/'])
expect(subject.map(&:identifier)).to eq(['/2', '/1'])
end
end

describe '#url_for' do
subject { helper.url_for(ctx.items['/stuff/']) }
subject { helper.url_for(ctx.items['/stuff']) }

let(:item_attributes) { {} }

before do
ctx.create_item('Stuff', item_attributes, '/stuff/')
ctx.create_rep(ctx.items['/stuff/'], '/rep/path/stuff.html')
ctx.create_item('Stuff', item_attributes, '/stuff')
ctx.create_rep(ctx.items['/stuff'], '/rep/path/stuff.html')

ctx.config[:base_url] = base_url
end
Expand Down Expand Up @@ -98,10 +98,10 @@
let(:item_attributes) { {} }

before do
ctx.create_item('Feed', item_attributes, '/feed/')
ctx.create_rep(ctx.items['/feed/'], '/feed.xml')
ctx.create_item('Feed', item_attributes, '/feed')
ctx.create_rep(ctx.items['/feed'], '/feed.xml')

ctx.item = ctx.items['/feed/']
ctx.item = ctx.items['/feed']
ctx.config[:base_url] = base_url
end

Expand Down Expand Up @@ -166,15 +166,15 @@
end

describe '#atom_tag_for' do
subject { helper.atom_tag_for(ctx.items['/stuff/']) }
subject { helper.atom_tag_for(ctx.items['/stuff']) }

let(:item_attributes) { { created_at: '2015-05-19 12:34:56' } }
let(:item_rep_path) { '/stuff.xml' }
let(:base_url) { 'http://url.base' }

before do
ctx.create_item('Stuff', item_attributes, '/stuff/')
ctx.create_rep(ctx.items['/stuff/'], item_rep_path)
ctx.create_item('Stuff', item_attributes, '/stuff')
ctx.create_rep(ctx.items['/stuff'], item_rep_path)

ctx.config[:base_url] = base_url
end
Expand All @@ -186,7 +186,7 @@

context 'item without path' do
let(:item_rep_path) { nil }
it { is_expected.to eql('tag:url.base,2015-05-19:/stuff/') }
it { is_expected.to eql('tag:url.base,2015-05-19:/stuff') }
end

context 'bare URL without subdir' do
Expand Down
16 changes: 8 additions & 8 deletions spec/nanoc/helpers/link_to_spec.rb
Expand Up @@ -36,21 +36,21 @@

context 'with rep' do
before do
ctx.create_item('content', {}, '/target/')
ctx.create_rep(ctx.items['/target/'], '/target.html')
ctx.create_item('content', {}, '/target')
ctx.create_rep(ctx.items['/target'], '/target.html')
end

let(:target) { ctx.items['/target/'].reps[:default] }
let(:target) { ctx.items['/target'].reps[:default] }

it { is_expected.to eql('<a href="/target.html">Text</a>') }
end

context 'with item' do
before do
ctx.create_item('content', {}, '/target/')
ctx.create_item('content', {}, '/target')
end

let(:target) { ctx.items['/target/'] }
let(:target) { ctx.items['/target'] }

before do
ctx.create_rep(target, '/target.html')
Expand All @@ -77,11 +77,11 @@

context 'with nil path' do
before do
ctx.create_item('content', {}, '/target/')
ctx.create_rep(ctx.items['/target/'], nil)
ctx.create_item('content', {}, '/target')
ctx.create_rep(ctx.items['/target'], nil)
end

let(:target) { ctx.items['/target/'].reps[:default] }
let(:target) { ctx.items['/target'].reps[:default] }

it 'raises' do
expect { subject }.to raise_error(RuntimeError)
Expand Down

0 comments on commit 655c981

Please sign in to comment.