the page repository now works with both a MongoDB and a Filesystem repository

did committed Feb 26, 2015
commit cb9261943b415d23eaee4be950e36a4bb5872bc4
Showing 3 changed files with 22 additions and 1 deletions
locomotive/steam/adapters/filesystem/sanitizers/page.rb b/lib/locomotive/steam/adapters/filesystem/sanitizers/page.rb +2 -0
@@ @@ -42,6 +42,8 @@ module Locomotive::Steam
# when this is called, the @ids hash has been populated completely
def set_parent_id(page)
+ return if page.not_found?
+
parent_key = parent_fullpath(page)
page[:parent_ids] = @parent_ids[parent_key] || []
locomotive/steam/adapters/filesystem/yaml_loaders/page.rb b/lib/locomotive/steam/adapters/filesystem/yaml_loaders/page.rb +1 -1
@@ @@ -123,7 +123,7 @@ module Locomotive
def find_editable_element(leaf, name)
leaf[:editable_elements].find do |el|
- [el[:block], el[:slug]].join('/') == name
+ [el[:block], el[:slug]].join('/') == name.to_s
end
end
spec/integration/repositories/page_repository_spec.rb +19 -0
@@ @@ -48,6 +48,25 @@ describe Locomotive::Steam::PageRepository do
it { expect(subject.title[:en]).to eq 'Home page' }
end
+ describe '#ancestors_of' do
+ let(:page) { repository.by_handle('about-us') }
+ subject { repository.ancestors_of(page) }
+ it { expect(subject.size).to eq 2 }
+ it { expect(subject.first.title[:en]).to eq 'Home page' }
+ end
+
+ describe '#children_of' do
+ let(:page) { repository.root }
+ subject { repository.children_of(page) }
+ it { expect(subject.size).to eq 14 }
+ end
+
+ describe '#editable_element_for' do
+ let(:page) { repository.by_handle('about-us') }
+ subject { repository.editable_element_for(page, 'banner', 'pitch') }
+ it { expect(subject.content[:en]).to eq '<h2>About us</h2><p>Lorem ipsum...</p>' }
+ end
+
end
context 'MongoDB' do