diff --git a/.rubocop.yml b/.rubocop.yml index d9db543..43c3eb4 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -5,7 +5,7 @@ inherit_gem: rubocop-bridgetown: .rubocop.yml AllCops: - TargetRubyVersion: 2.5 + TargetRubyVersion: 2.7 Exclude: - vendor/**/* diff --git a/bridgetown-seo-tag.gemspec b/bridgetown-seo-tag.gemspec index d4ca950..69b6734 100644 --- a/bridgetown-seo-tag.gemspec +++ b/bridgetown-seo-tag.gemspec @@ -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 diff --git a/lib/bridgetown-seo-tag.rb b/lib/bridgetown-seo-tag.rb index e89cbcc..c89da41 100644 --- a/lib/bridgetown-seo-tag.rb +++ b/lib/bridgetown-seo-tag.rb @@ -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( diff --git a/spec/bridgetown_seo_tag/author_drop_spec.rb b/spec/bridgetown_seo_tag/author_drop_spec.rb index f7f48be..65905af 100644 --- a/spec/bridgetown_seo_tag/author_drop_spec.rb +++ b/spec/bridgetown_seo_tag/author_drop_spec.rb @@ -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 diff --git a/spec/bridgetown_seo_tag/drop_spec.rb b/spec/bridgetown_seo_tag/drop_spec.rb index b464bf0..ac1ea09 100644 --- a/spec/bridgetown_seo_tag/drop_spec.rb +++ b/spec/bridgetown_seo_tag/drop_spec.rb @@ -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 diff --git a/spec/bridgetown_seo_tag/filters_spec.rb b/spec/bridgetown_seo_tag/filters_spec.rb index e24e4ba..8f843bb 100644 --- a/spec/bridgetown_seo_tag/filters_spec.rb +++ b/spec/bridgetown_seo_tag/filters_spec.rb @@ -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 diff --git a/spec/bridgetown_seo_tag_integration_spec.rb b/spec/bridgetown_seo_tag_integration_spec.rb index 6ac9e53..14c16e3 100755 --- a/spec/bridgetown_seo_tag_integration_spec.rb +++ b/spec/bridgetown_seo_tag_integration_spec.rb @@ -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 @@ -139,7 +139,7 @@ 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!! expect(output).to match(expected) end @@ -147,7 +147,7 @@ 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!! expect(output).to match(expected) end @@ -191,9 +191,9 @@ let(:site_config) { { "url" => "http://example.invalid" } } it "uses the site url to build the seo url" do - expected = %r!! + expected = %r!! expect(output).to match(expected) - expected = %r!! + expected = %r!! expect(output).to match(expected) end @@ -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!! + it "uses base_path to build the seo url" do + expected = %r!! expect(output).to match(expected) - expected = %r!! + expected = %r!! expect(output).to match(expected) end end @@ -297,8 +295,8 @@ Foo - - + + HTML expect(output).to match(expected) diff --git a/spec/bridgetown_seo_tag_spec.rb b/spec/bridgetown_seo_tag_spec.rb index cb54f53..e8e59ad 100644 --- a/spec/bridgetown_seo_tag_spec.rb +++ b/spec/bridgetown_seo_tag_spec.rb @@ -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 diff --git a/spec/fixtures/config/initializers.rb b/spec/fixtures/config/initializers.rb new file mode 100644 index 0000000..65c6b3e --- /dev/null +++ b/spec/fixtures/config/initializers.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +Bridgetown.configure do + init :"bridgetown-seo-tag" +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ef8bbc1..07b57d3 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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