Skip to content

Commit

Permalink
Fix remaining tests and one real bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredcwhite committed Jan 8, 2023
1 parent 686c43c commit 7fd30de
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ inherit_gem:
rubocop-bridgetown: .rubocop.yml

AllCops:
TargetRubyVersion: 2.5
TargetRubyVersion: 2.7
Exclude:
- vendor/**/*

Expand Down
1 change: 1 addition & 0 deletions bridgetown-seo-tag.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "rake", "~> 13.0"
spec.add_development_dependency "rspec", "~> 3.5"
spec.add_development_dependency "rubocop-bridgetown", "~> 0.3"
spec.metadata["rubygems_mfa_required"] = "true"
end
4 changes: 3 additions & 1 deletion lib/bridgetown-seo-tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ def options
end

def payload
paginator = context.registers[:page].pager if context.registers[:page].respond_to?(:pager)
if context.registers[:page].respond_to?(:paginator)
paginator = context.registers[:page].paginator
end

# site_payload is an instance of UnifiedPayloadDrop
Bridgetown::Utils.deep_merge_hashes(
Expand Down
4 changes: 3 additions & 1 deletion spec/bridgetown_seo_tag/author_drop_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@
end

it "uses the author from the front matter default" do
expect(subject["name"]).to eql("front matter default")
site # init new config
defaults_page = Bridgetown::SeoTag::AuthorDrop.new(page: make_resource_page.to_liquid, site: site_payload.to_liquid)
expect(defaults_page["name"]).to eql("front matter default")
end
end

Expand Down
5 changes: 4 additions & 1 deletion spec/bridgetown_seo_tag/drop_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,10 @@
end

it "uses the author from the front matter default" do
expect(subject.author["name"]).to eql("front matter default")
site # init new config
contxt = make_context(page: make_resource_page.to_liquid, site: site)
defaults_page = Bridgetown::SeoTag::Drop.new("", contxt)
expect(defaults_page.author["name"]).to eql("front matter default")
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/bridgetown_seo_tag/filters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
end

it "stores the context" do
expect(subject.instance_variable_get("@context")).to be_a(Liquid::Context)
expect(subject.instance_variable_get(:@context)).to be_a(Liquid::Context)
end

it "exposes bridgetown filters" do
Expand Down
26 changes: 12 additions & 14 deletions spec/bridgetown_seo_tag_integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
end
let(:paginator) { { "previous_page" => true, "previous_page_path" => "foo", "next_page" => true, "next_page_path" => "bar" } }
let(:page) do
make_page.yield_self do |page|
make_page.then do |page|
page.paginator = paginator
page
end
Expand Down Expand Up @@ -139,15 +139,15 @@

context "with page.date" do
let(:page) { make_page("date" => Date.new) }
it 'outputs open graph type article' do
it "outputs open graph type article" do
expected = %r!<meta property="og:type" content="article" />!
expect(output).to match(expected)
end
end

context "without page.date" do
let(:page) { make_page("date" => nil) }
it 'outputs open graph type website' do
it "outputs open graph type website" do
expected = %r!<meta property="og:type" content="website" />!
expect(output).to match(expected)
end
Expand Down Expand Up @@ -191,9 +191,9 @@
let(:site_config) { { "url" => "http://example.invalid" } }

it "uses the site url to build the seo url" do
expected = %r!<link rel="canonical" href="http://example.invalid/page.html" />!
expected = %r!<link rel="canonical" href="http://example.invalid/page/" />!
expect(output).to match(expected)
expected = %r!<meta property="og:url" content="http://example.invalid/page.html" />!
expected = %r!<meta property="og:url" content="http://example.invalid/page/" />!
expect(output).to match(expected)
end

Expand All @@ -209,15 +209,13 @@
end
end

context "with site.baseurl" do
let(:site_config) { { "url" => "http://example.invalid", "baseurl" => "/foo" } }
context "with site.base_path" do
let(:site_config) { { "url" => "http://example.invalid", "base_path" => "/foo" } }

it "uses baseurl to build the seo url" do
skip "FIXME: very strange issue with RSpec and cached site data"

expected = %r!<link rel="canonical" href="http://example.invalid/foo/page.html" />!
it "uses base_path to build the seo url" do
expected = %r!<link rel="canonical" href="http://example.invalid/foo/page/" />!
expect(output).to match(expected)
expected = %r!<meta property="og:url" content="http://example.invalid/foo/page.html" />!
expected = %r!<meta property="og:url" content="http://example.invalid/foo/page/" />!
expect(output).to match(expected)
end
end
Expand Down Expand Up @@ -297,8 +295,8 @@
<title>Foo</title>
<meta property="og:title" content="Foo" />
<meta property="og:locale" content="en_US" />
<link rel="canonical" href="http://example.invalid/page.html" />
<meta property="og:url" content="http://example.invalid/page.html" />
<link rel="canonical" href="http://example.invalid/page/" />
<meta property="og:url" content="http://example.invalid/page/" />
<meta property="og:site_name" content="Foo" />
HTML
expect(output).to match(expected)
Expand Down
2 changes: 1 addition & 1 deletion spec/bridgetown_seo_tag_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

subject do
tag = described_class.parse(tag_name, text, tokenizer, parse_context)
tag.instance_variable_set("@context", render_context)
tag.instance_variable_set(:@context, render_context)
tag
end

Expand Down
5 changes: 5 additions & 0 deletions spec/fixtures/config/initializers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

Bridgetown.configure do
init :"bridgetown-seo-tag"
end
17 changes: 13 additions & 4 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,27 @@ def make_page(options = {})
page
end

def make_resource_page(options = {})
origin = Bridgetown::Model::RepoOrigin.new_with_collection_path(:pages, "page.md")
page = Bridgetown::Model::Base.new(origin.read).to_resource
page.data.merge!(options)
page
end

def make_post(options = {})
filename = File.expand_path("_posts/2015-01-01-post.md", CONFIG_DEFAULTS["source"])
config = { site: site, collection: site.collections["posts"] }
# filename = File.expand_path("_posts/2015-01-01-post.md", CONFIG_DEFAULTS["source"])
# config = { site: site, collection: site.collections["posts"] }
origin = Bridgetown::Model::RepoOrigin.new_with_collection_path(:posts, "_posts/2015-01-01-post.md")
page = Bridgetown::Model::Base.new(origin.read).to_resource
# page = Bridgetown::Resource::Base.new filename, config
# page = Bridgetown::Resource::Base.new filename, config
page.data.merge!(options)
page
end

def make_site(options = {}, site_config = {})
config = Bridgetown.configuration CONFIG_DEFAULTS.merge(site_config)
config = Bridgetown.configuration(CONFIG_DEFAULTS.merge(site_config)).tap do |conf|
conf.run_initializers! context: :static
end
site = Bridgetown::Site.new(config)
site.data["site_metadata"] = options
site
Expand Down

0 comments on commit 7fd30de

Please sign in to comment.