|
1 | 1 | # frozen_string_literal: true |
| 2 | + |
2 | 3 | require "spec_helper" |
3 | 4 |
|
4 | 5 | describe Jekyll::Avatar do |
|
8 | 9 | let(:text) { "#{username} #{args}".squeeze(" ") } |
9 | 10 | let(:content) { "{% avatar #{text} %}" } |
10 | 11 | let(:rendered) { subject.render(nil) } |
| 12 | + let(:tokenizer) { Liquid::Tokenizer.new("") } |
| 13 | + let(:parse_context) { Liquid::ParseContext.new } |
11 | 14 | let(:output) do |
12 | 15 | doc.content = content |
13 | 16 | doc.output = Jekyll::Renderer.new(doc.site, doc).run |
14 | 17 | end |
15 | | - subject { Jekyll::Avatar.send(:new, "avatar", text, nil) } |
| 18 | + subject { described_class.parse "avatar", text, tokenizer, parse_context } |
16 | 19 |
|
17 | 20 | it "has a version number" do |
18 | 21 | expect(Jekyll::Avatar::VERSION).not_to be nil |
|
40 | 43 | end |
41 | 44 |
|
42 | 45 | it "builds the host" do |
43 | | - expect(subject.send(:host)).to eql("avatars3.githubusercontent.com") |
| 46 | + expect(subject.send(:host)).to eql("https://avatars3.githubusercontent.com") |
| 47 | + end |
| 48 | + |
| 49 | + context "with a custom host" do |
| 50 | + context "with subdomain isolation" do |
| 51 | + it "builds the host" do |
| 52 | + with_env("PAGES_AVATARS_URL", "http://avatars.example.com") do |
| 53 | + expect(subject.send(:host)).to eql("http://avatars.example.com") |
| 54 | + end |
| 55 | + end |
| 56 | + |
| 57 | + it "builds the URL" do |
| 58 | + with_env("PAGES_AVATARS_URL", "http://avatars.example.com") do |
| 59 | + expect(subject.send(:url).to_s).to eql("http://avatars.example.com/hubot?v=3&s=40") |
| 60 | + end |
| 61 | + end |
| 62 | + end |
| 63 | + |
| 64 | + context "without subdomain isolation" do |
| 65 | + it "builds the URL" do |
| 66 | + with_env("PAGES_AVATARS_URL", "http://github.example.com/avatars/") do |
| 67 | + expected = "http://github.example.com/avatars/hubot?v=3&s=40" |
| 68 | + expect(subject.send(:url).to_s).to eql(expected) |
| 69 | + end |
| 70 | + end |
| 71 | + end |
44 | 72 | end |
45 | 73 |
|
46 | 74 | it "builds the path" do |
|
53 | 81 |
|
54 | 82 | it "builds the URL" do |
55 | 83 | expected = "https://avatars3.githubusercontent.com/hubot?v=3&s=40" |
56 | | - expect(subject.send(:url)).to eql(expected) |
| 84 | + expect(subject.send(:url).to_s).to eql(expected) |
57 | 85 | end |
58 | 86 |
|
59 | 87 | it "builds the params" do |
60 | 88 | attrs = subject.send(:attributes) |
61 | 89 | expect(attrs[:class]).to eql("avatar avatar-small") |
62 | 90 | expect(attrs[:alt]).to eql("hubot") |
63 | | - expect(attrs[:src]).to eql("https://avatars3.githubusercontent.com/hubot?v=3&s=40") |
| 91 | + expect(attrs[:src].to_s).to eql("https://avatars3.githubusercontent.com/hubot?v=3&s=40") |
64 | 92 | expect(attrs[:width]).to eql(40) |
65 | 93 | expect(attrs[:height]).to eql(40) |
66 | 94 | end |
|
76 | 104 |
|
77 | 105 | it "builds the URL with a scale" do |
78 | 106 | expected = "https://avatars3.githubusercontent.com/hubot?v=3&s=80" |
79 | | - expect(subject.send(:url, 2)).to eql(expected) |
| 107 | + expect(subject.send(:url, 2).to_s).to eql(expected) |
80 | 108 | end |
81 | 109 |
|
82 | 110 | it "builds the srcset" do |
|
0 commit comments