From efab79681724a93302e2b533ac2af873ddca65ca Mon Sep 17 00:00:00 2001 From: Ben Balter Date: Fri, 7 Apr 2017 16:27:41 -0400 Subject: [PATCH] add image specs --- lib/jekyll-seo-tag/drop.rb | 2 +- spec/jekyll_seo_tag/drop_spec.rb | 55 ++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/lib/jekyll-seo-tag/drop.rb b/lib/jekyll-seo-tag/drop.rb index 7bb12a1..c968ebc 100644 --- a/lib/jekyll-seo-tag/drop.rb +++ b/lib/jekyll-seo-tag/drop.rb @@ -143,7 +143,7 @@ module Jekyll return @image if defined?(@image) image = page["image"] - return unless image + return @image = nil unless image image = { "path" => image } if image.is_a?(String) image["path"] ||= image["facebook"] || image["twitter"] diff --git a/spec/jekyll_seo_tag/drop_spec.rb b/spec/jekyll_seo_tag/drop_spec.rb index 3008fb7..61aa773 100644 --- a/spec/jekyll_seo_tag/drop_spec.rb +++ b/spec/jekyll_seo_tag/drop_spec.rb @@ -359,6 +359,61 @@ RSpec.describe Jekyll::SeoTag::Drop do end context "image" do + let(:page) { make_page({"image" => image })} + + context "with image as a string" do + let(:image) { "image.png" } + + it "returns a hash" do + expect(subject.image).to be_a(Hash) + end + + it "returns the image" do + expect(subject.image["path"]).to eql("/image.png") + end + + context "with site.url" do + let(:site) { make_site({"url" => "http://example.com"})} + + it "makes the path absolute" do + expect(subject.image["path"]).to eql("http://example.com/image.png") + end + end + + context "with a URL-escaped path" do + let(:image) { "some image.png" } + + it "URL-escapes the image" do + expect(subject.image["path"]).to eql("/some%20image.png") + end + end + end + + context "with image as a hash" do + context "with a path" do + let(:image) { { "path" => "image.png" } } + + it "returns the image" do + expect(subject.image["path"]).to eql("/image.png") + end + end + + context "with facebook" do + let(:image) { { "facebook" => "image.png" } } + + it "returns the image" do + expect(subject.image["path"]).to eql("/image.png") + end + end + + context "with twitter" do + let(:image) { { "twitter" => "image.png" } } + + it "returns the image" do + expect(subject.image["path"]).to eql("/image.png") + end + end + end end context "lang" do