-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbridgetown-cloudinary_spec.rb
103 lines (86 loc) · 3.9 KB
/
bridgetown-cloudinary_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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# frozen_string_literal: true
require "spec_helper"
module TestValues
class << self
attr_accessor :config
end
end
describe(Bridgetown::Cloudinary) do
let(:config) {
TestValues::config ||= Bridgetown.configuration(Bridgetown::Utils.deep_merge_hashes({
"full_rebuild" => true,
"root_dir" => root_dir,
"source" => source_dir,
"destination" => dest_dir
}, overrides)).tap do |conf|
conf.run_initializers! context: :static
end
}
describe "plugin behavior" do
let(:overrides) { {} }
let(:metadata_overrides) { {} }
let(:metadata_defaults) do
{
"name" => "My Awesome Site",
"author" => {
"name" => "Ada Lovejoy",
}
}
end
let(:site) { Bridgetown::Site.new(config) }
let(:contents) { File.read(dest_dir("index.html")) }
before(:each) do
metadata = metadata_defaults.merge(metadata_overrides).to_yaml.sub("---\n", "")
File.write(source_dir("_data/site_metadata.yml"), metadata)
site.process
FileUtils.rm(source_dir("_data/site_metadata.yml"))
end
context "Liquid tag" do
it "outputs with an inline id" do
expect(contents).to match '<img alt="This is inline" src="https://res.cloudinary.com/bridgetown_test/image/upload/c_fill,g_face:center,w_1600,h_900,q_50/inline_id.jpg" />'
end
it "outputs with a page variable" do
expect(contents).to match '<img alt="This is page" src="https://res.cloudinary.com/bridgetown_test/image/upload/c_fill,g_face:center,w_1600,h_900,q_50/the_id_123.jpg" />'
end
it "outputs with a local object" do
expect(contents).to match '<img alt="This is local object" src="https://res.cloudinary.com/bridgetown_test/image/upload/c_fill,g_face:center,w_1600,h_900,q_50/the_id_123.jpg" />'
end
it "outputs with a local variable" do
expect(contents).to match '<img alt="This is local variable" src="https://res.cloudinary.com/bridgetown_test/image/upload/c_fill,g_face:center,w_1600,h_900,q_50/local_id.jpg" />'
end
it "escapes alt text" do
expect(contents).to match '<img alt="Alt text " class="badclass" src="https://res.cloudinary.com/bridgetown_test/image/upload/w_4096,c_limit,q_65/local_id.jpg" />'
end
end
context "transformations" do
it "outputs a custom transformation" do
expect(contents).to match '<img alt="Transformation" src="https://res.cloudinary.com/bridgetown_test/image/upload/w_4096,c_limit,q_65/local_id.jpg" />'
end
end
context "Liquid filter" do
it "outputs a URL" do
expect(contents).to match "https://res.cloudinary.com/bridgetown_test/image/upload/c_fill,g_face:center,w_1600,h_900,q_50/filtered_id.jpg"
end
it "outputs a URL with custom transformation" do
expect(contents).to match "https://res.cloudinary.com/bridgetown_test/image/upload/w_1200,c_limit,q_80/filtered_id_max.jpg"
end
end
context "image generator" do
it "sets the page's image variable default path" do
expect(contents).to match "image: https://res.cloudinary.com/bridgetown_test/image/upload/c_fill,g_face:center,w_1600,h_900,q_50/the_id_123.jpg"
end
it "sets the page's image variable tiny path" do
expect(contents).to match "tiny: https://res.cloudinary.com/bridgetown_test/image/upload/w_300,c_limit,q_90/the_id_123.jpg"
end
it "supports custom transformations" do
expect(contents).to match "maxsize: https://res.cloudinary.com/bridgetown_test/image/upload/w_4096,c_limit,q_65/the_id_123.jpg"
end
end
context "check resource engine too" do
let(:overrides) { { content_engine: "resource" } }
it "sets the page's image variable default path" do
expect(contents).to match "image: https://res.cloudinary.com/bridgetown_test/image/upload/c_fill,g_face:center,w_1600,h_900,q_50/the_id_123.jpg"
end
end
end
end