forked from karmi/hide
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Hide::Updater to return updated pages and blog posts based on G…
…it log
- Loading branch information
Showing
4 changed files
with
71 additions
and
2 deletions.
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
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,8 +1,6 @@ | ||
module Hide | ||
class Page | ||
|
||
attr_reader :meta | ||
|
||
def initialize(page) | ||
@page = page | ||
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,35 @@ | ||
module Hide | ||
class Updater | ||
|
||
def initialize(site, sha1, sha2) | ||
@site, @sha1, @sha2 = site, sha1, sha2 | ||
end | ||
|
||
def git | ||
Git.new @site.path, @sha1, @sha2 | ||
end | ||
|
||
def updated_pages | ||
updated_pages = [] | ||
@site.pages.each do |page| | ||
updated_paths.each { |path| updated_pages << page if page.url.include?(path) } | ||
end | ||
updated_pages | ||
end | ||
|
||
def updated_posts | ||
updated_posts = [] | ||
@site.posts.each do |post| | ||
updated_paths.each { |path| updated_posts << post if post.url.include?(path) } | ||
end | ||
updated_posts | ||
end | ||
|
||
def updated_paths | ||
git.changed_files.map do |file| | ||
[ File.dirname(file), File.basename(file, '.*') ].join('/') | ||
end | ||
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,35 @@ | ||
require 'test_helper' | ||
|
||
module Hide | ||
|
||
class UpdaterTest < Test::Unit::TestCase | ||
|
||
context "Updater" do | ||
|
||
setup do | ||
@site = Hide::Site.new path_to_test_site, :pages_directories => ['guide'] | ||
@updater = Updater.new @site, 'abc123', 'def456' | ||
end | ||
|
||
should "return updated paths based on sha1 and sha2" do | ||
Git.any_instance.expects(:changed_files).returns( %w|blog/_posts/2011-02-08-percolator.textile guide/appendix/clients.textile| ) | ||
assert_equal %w|blog/_posts/2011-02-08-percolator guide/appendix/clients|, @updater.updated_paths | ||
end | ||
|
||
should "return selected pages based on updated paths" do | ||
@updater.stubs(:updated_paths).returns( ['guide/reference/api/search/request-body'] ) | ||
assert_equal 1, @updater.updated_pages.size | ||
assert_equal 'Search API - Request Body', @updater.updated_pages.first.title | ||
end | ||
|
||
should "return selected blog posts based on updated paths" do | ||
@updater.stubs(:updated_paths).returns( ['blog/2010/02/08/youknowforsearch'] ) | ||
assert_equal 1, @updater.updated_posts.size | ||
assert_equal 'You Know, for Search', @updater.updated_posts.first.title | ||
end | ||
|
||
end | ||
|
||
end | ||
|
||
end |