-
Notifications
You must be signed in to change notification settings - Fork 166
/
layout_spec.rb
79 lines (64 loc) · 2.16 KB
/
layout_spec.rb
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
require "spec_helper"
describe Onebox::Layout do
let(:cache) { Moneta.new(:Memory, expires: true, serializer: :json) }
let(:record) { {} }
let(:onebox) { described_class.new("amazon", record, cache) }
let(:html) { onebox.to_html }
describe ".template_path" do
let(:template_path) { onebox.template_path }
before(:each) do
Onebox.options.load_paths << "directory_a"
Onebox.options.load_paths << "directory_b"
end
context "when template exists in directory_b" do
before(:each) do
allow_any_instance_of(described_class).to receive(:template?) { |_,path| path == "directory_b" }
end
it "returns directory_b" do
expect(template_path).to eq("directory_b")
end
end
context "when template exists in directory_a" do
before(:each) do
allow_any_instance_of(described_class).to receive(:template?) { |_,path| path == "directory_a" }
end
it "returns directory_a" do
expect(template_path).to eq("directory_a")
end
end
context "when template doesn't exist in directory_a or directory_b" do
it "returns default path" do
expect(template_path).to include("template")
end
end
after(:each) do
Onebox.options.load_paths.pop(2)
end
end
describe "#to_html" do
class OneboxEngineLayout
include Onebox::Engine
def data
"new content"
end
end
it "reads from cache if rendered template is cached" do
described_class.new("amazon", record, cache).to_html
expect(cache).to receive(:fetch)
described_class.new("amazon", record, cache).to_html
end
it "contains layout template" do
expect(html).to include(%|class="onebox|)
end
it "contains the view" do
record = { link: "foo" }
html = described_class.new("amazon", record, cache).to_html
expect(html).to include(%|"foo"|)
end
it "rewrites relative image path" do
record = { image: "/image.png", link: "https://discourse.org" }
klass = described_class.new("whitelistedgeneric", record, cache)
expect(klass.view.record[:image]).to include("https://discourse.org")
end
end
end