mirror of
https://github.com/freeCodeCamp/devdocs
synced 2024-11-16 19:48:10 +01:00
Don't store pages with no entries
This commit is contained in:
parent
7c1bd6b236
commit
706270d89c
4 changed files with 64 additions and 22 deletions
|
@ -34,17 +34,18 @@ module Docs
|
|||
end
|
||||
|
||||
def index_page(id)
|
||||
if page = new.build_page(id)
|
||||
if (page = new.build_page(id)) && page[:entries].present?
|
||||
yield page[:store_path], page[:output]
|
||||
index = EntryIndex.new
|
||||
index.add page[:entries]
|
||||
index
|
||||
end
|
||||
index
|
||||
end
|
||||
|
||||
def index_pages
|
||||
index = EntryIndex.new
|
||||
new.build_pages do |page|
|
||||
next if page[:entries].blank?
|
||||
yield page[:store_path], page[:output]
|
||||
index.add page[:entries]
|
||||
end
|
||||
|
|
|
@ -7,7 +7,7 @@ module Docs
|
|||
|
||||
def entries
|
||||
entries = []
|
||||
entries << default_entry if include_default_entry?
|
||||
entries << default_entry if root_page? || include_default_entry?
|
||||
entries.concat(additional_entries)
|
||||
build_entries(entries)
|
||||
end
|
||||
|
|
|
@ -129,19 +129,36 @@ class DocsDocTest < MiniTest::Spec
|
|||
end
|
||||
end
|
||||
|
||||
it "yields the page's :store_path and :output" do
|
||||
doc.index_page('') { |*args| @args = args }
|
||||
assert_equal [page[:store_path], page[:output]], @args
|
||||
context "and it has :entries" do
|
||||
it "yields the page's :store_path and :output" do
|
||||
doc.index_page('') { |*args| @args = args }
|
||||
assert_equal [page[:store_path], page[:output]], @args
|
||||
end
|
||||
|
||||
it "returns an EntryIndex" do
|
||||
assert_instance_of Docs::EntryIndex, doc.index_page('') {}
|
||||
end
|
||||
|
||||
describe "the index" do
|
||||
it "contains the page's entries" do
|
||||
index = doc.index_page('') {}
|
||||
assert_equal page[:entries], index.entries
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it "returns an EntryIndex" do
|
||||
assert_instance_of Docs::EntryIndex, doc.index_page('') {}
|
||||
end
|
||||
context "and it doesn't have :entries" do
|
||||
before do
|
||||
page[:entries] = []
|
||||
end
|
||||
|
||||
describe "the index" do
|
||||
it "contains the page's entries" do
|
||||
index = doc.index_page('') {}
|
||||
assert_equal page[:entries], index.entries
|
||||
it "doesn't yield" do
|
||||
doc.index_page('') { |*_| @yield = true }
|
||||
refute @yield
|
||||
end
|
||||
|
||||
it "returns nil" do
|
||||
assert_nil doc.index_page('') {}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -184,21 +201,39 @@ class DocsDocTest < MiniTest::Spec
|
|||
end
|
||||
end
|
||||
|
||||
it "yields each page's :store_path and :output" do
|
||||
it "yields pages that have :entries" do
|
||||
doc.index_pages { |*args| (@args ||= []) << args }
|
||||
assert_equal pages.length, @args.length
|
||||
assert_equal [page[:store_path], page[:output]], @args.first
|
||||
end
|
||||
|
||||
it "returns an EntryIndex" do
|
||||
assert_instance_of Docs::EntryIndex, doc.index_pages {}
|
||||
it "doesn't yield pages that don't have :entries" do
|
||||
pages.first[:entries] = []
|
||||
doc.index_pages { |*args| (@args ||= []) << args }
|
||||
assert_equal pages.length - 1, @args.length
|
||||
end
|
||||
|
||||
describe "the index" do
|
||||
it "contains all pages' entries" do
|
||||
index = doc.index_pages {}
|
||||
assert_equal pages.length, index.entries.length
|
||||
assert_includes index.entries, entry
|
||||
describe "and at least one has :entries" do
|
||||
it "returns an EntryIndex" do
|
||||
assert_instance_of Docs::EntryIndex, doc.index_pages {}
|
||||
end
|
||||
|
||||
describe "the index" do
|
||||
it "contains all the pages' entries" do
|
||||
index = doc.index_pages {}
|
||||
assert_equal pages.length, index.entries.length
|
||||
assert_includes index.entries, entry
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "and none have :entries" do
|
||||
before do
|
||||
pages.each { |page| page[:entries] = [] }
|
||||
end
|
||||
|
||||
it "returns nil" do
|
||||
assert_nil doc.index_pages {}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -26,7 +26,7 @@ class EntriesFilterTest < MiniTest::Spec
|
|||
|
||||
it "includes the default entry when #include_default_entry? is true" do
|
||||
stub(filter).include_default_entry? { true }
|
||||
assert_equal 1, entries.length
|
||||
refute_empty entries
|
||||
end
|
||||
|
||||
it "doesn't include the default entry when #include_default_entry? is false" do
|
||||
|
@ -34,6 +34,12 @@ class EntriesFilterTest < MiniTest::Spec
|
|||
assert_empty entries
|
||||
end
|
||||
|
||||
it "always includes the default entry when #root_page? is true" do
|
||||
stub(filter).include_default_entry? { false }
|
||||
stub(filter).root_page? { true }
|
||||
refute_empty entries
|
||||
end
|
||||
|
||||
describe "the default entry" do
|
||||
it "has the #name, #path and #type" do
|
||||
assert_equal 'name', entries.first.name
|
||||
|
|
Loading…
Reference in a new issue