File: redirectable_spec.rb

package info (click to toggle)
ruby-jekyll-redirect-from 0.16.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 284 kB
  • sloc: ruby: 659; sh: 17; makefile: 4
file content (63 lines) | stat: -rw-r--r-- 1,468 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
62
63
# frozen_string_literal: true

class RedirectableTestHelper
  include JekyllRedirectFrom::Redirectable
  attr_reader :to_liquid

  def initialize(data)
    @to_liquid = data
  end
end

RSpec.describe JekyllRedirectFrom::Redirectable do
  let(:data) { "" }
  subject { RedirectableTestHelper.new(data) }

  context "with strings" do
    let(:data) { { "redirect_from" => "/foo", "redirect_to" => "/bar" } }

    it "returns redirect_from" do
      expect(subject.redirect_from).to eql(["/foo"])
    end

    it "returns redirect_to" do
      expect(subject.redirect_to).to eql("/bar")
    end
  end

  context "with arrays" do
    let(:data) { { "redirect_from" => ["/foo"], "redirect_to" => ["/bar"] } }

    it "returns redirect_from" do
      expect(subject.redirect_from).to eql(["/foo"])
    end

    it "returns redirect_to" do
      expect(subject.redirect_to).to eql("/bar")
    end
  end

  context "with fields missing" do
    let(:data) { {} }

    it "returns an empty array for redirect_from" do
      expect(subject.redirect_from).to eql([])
    end

    it "returns nil for redirect_to" do
      expect(subject.redirect_to).to be_nil
    end
  end

  context "with nils" do
    let(:data) { { "redirect_from" => nil, "redirect_to" => nil } }

    it "returns an empty array for redirect_from" do
      expect(subject.redirect_from).to eql([])
    end

    it "returns nil for redirect_to" do
      expect(subject.redirect_to).to be_nil
    end
  end
end