File: test_related_posts.rb

package info (click to toggle)
jekyll 3.1.6%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 3,820 kB
  • ctags: 997
  • sloc: ruby: 10,045; sh: 145; xml: 59; makefile: 28
file content (61 lines) | stat: -rw-r--r-- 1,913 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
require 'helper'

class TestRelatedPosts < JekyllUnitTest
  context "building related posts without lsi" do
    setup do
      @site = fixture_site
    end

    should "use the most recent posts for related posts" do
      @site.reset
      @site.read

      last_post     = @site.posts.last
      related_posts = Jekyll::RelatedPosts.new(last_post).build

      last_10_recent_posts = (@site.posts.docs.reverse - [last_post]).first(10)
      assert_equal last_10_recent_posts, related_posts
    end
  end

  context "building related posts with lsi" do
    setup do
      if jruby?
        skip(
          "JRuby does not perform well with CExt, test disabled."
        )
      end

      allow_any_instance_of(Jekyll::RelatedPosts).to receive(:display)
      @site = fixture_site({
        "lsi" => true
      })

      @site.reset
      @site.read
      require 'classifier-reborn'
      Jekyll::RelatedPosts.lsi = nil
    end

    should "index Jekyll::Post objects" do
      @site.posts.docs = @site.posts.docs.first(1)
      expect_any_instance_of(::ClassifierReborn::LSI).to receive(:add_item).with(kind_of(Jekyll::Document))
      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)

      assert_equal @site.posts[-1..-9], Jekyll::RelatedPosts.new(@site.posts.last).build
    end
  end
end