Skip to content

Commit

Permalink
Add a method to finder to find unpublished documents
Browse files Browse the repository at this point in the history
This method allows the scraper route to send the unpublished
documents to the view so that they can be scraped and pushed to
the static repo, so that they can be loaded as a preview without
being accessible for users or linked from the site
  • Loading branch information
octopusinvitro committed Apr 11, 2017
1 parent c776561 commit 5cdb86c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/document/finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@ def find_or_empty
end

def find_all
filenames.map { |filename| create_document(filename) }.select(&:published?)
create_documents.select(&:published?)
end

def find_previews
create_documents.reject(&:published?)
end

def find_featured
find_all.select(&:featured?)
create_documents.select(&:featured?)
end

def multiple?
Expand All @@ -49,6 +53,10 @@ def raise_error_if_no_files_found
raise Document::NoFilesFoundError, message if none?
end

def create_documents
@create_documents ||= filenames.map { |filename| create_document(filename) }
end

def filenames
@filenames ||= Dir.glob(pattern).sort
end
Expand Down
12 changes: 12 additions & 0 deletions tests/document/finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@
end
end

it 'can find unpublished documents' do
published = '---
published: true
---'
unpublished = '---
published: false
---'
Dir.stub :glob, [new_tempfile(published), new_tempfile(unpublished)] do
finder.find_previews.count.must_equal(1)
end
end

it 'creates a document with the right url' do
contents = '---
slug: a-slug
Expand Down

0 comments on commit 5cdb86c

Please sign in to comment.