diff --git a/lib/jekyll/related_posts.rb b/lib/jekyll/related_posts.rb index b6899ec3..9666b52e 100644 --- a/lib/jekyll/related_posts.rb +++ b/lib/jekyll/related_posts.rb @@ -42,7 +42,7 @@ module Jekyll end def lsi_related_posts - self.class.lsi.find_related(post.content, 11) - [post] + self.class.lsi.find_related(post, 11) end def most_recent_posts diff --git a/test/test_related_posts.rb b/test/test_related_posts.rb index 42c58279..76dc497c 100644 --- a/test/test_related_posts.rb +++ b/test/test_related_posts.rb @@ -22,12 +22,27 @@ class TestRelatedPosts < JekyllUnitTest setup do allow_any_instance_of(Jekyll::RelatedPosts).to receive(:display) @site = fixture_site({"lsi" => true}) - end - - should "use lsi for the related posts" do @site.reset @site.read require 'classifier-reborn' + Jekyll::RelatedPosts.lsi = nil + end + + should "index Jekyll::Post objects" do + @site.posts = @site.posts.first(1) + expect_any_instance_of(::ClassifierReborn::LSI).to receive(:add_item).with(kind_of(Jekyll::Post)) + Jekyll::RelatedPosts.new(@site.posts.last).build_index + end + + should "find related Jekyll::Post objects, given a Jekyll::Post object" do + post = @site.posts.last + allow_any_instance_of(::ClassifierReborn::LSI).to receive(:build_index) + expect_any_instance_of(::ClassifierReborn::LSI).to receive(:find_related).with(post, 11).and_return(@site.posts[-1..-9]) + + Jekyll::RelatedPosts.new(post).build + end + + should "use lsi for the related posts" do allow_any_instance_of(::ClassifierReborn::LSI).to receive(:find_related).and_return(@site.posts[-1..-9]) allow_any_instance_of(::ClassifierReborn::LSI).to receive(:build_index)