Sha256: 7dd9c940c5c1496d0ece23eaa84b850bc13c27673e06c4289863fc78fb59d2e1

Contents?: true

Size: 1.8 KB

Versions: 13

Compression:

Stored size: 1.8 KB

Contents

require 'spec_helper'

require_relative '../../../lib/locomotive/steam/middlewares/thread_safe'
require_relative '../../../lib/locomotive/steam/middlewares/concerns/helpers'
require_relative '../../../lib/locomotive/steam/middlewares/sitemap'

describe Locomotive::Steam::Middlewares::Sitemap do

  let(:site)            { instance_double('Site', locales: ['en', 'fr'], default_locale: 'en') }
  let(:pages)           { [] }
  let(:page_repository) { instance_double('PageRepository', published: pages, :locale= => 'en') }
  let(:app)             { ->(env) { [200, env, 'app'] }}
  let(:middleware)      { described_class.new(app) }

  before do
    allow_any_instance_of(described_class).to receive(:site).and_return(site)
    allow_any_instance_of(described_class).to receive(:base_url).and_return('http://localhost/')
    allow_any_instance_of(described_class).to receive(:page_repository).and_return(page_repository)
  end

  describe '#call' do

    let(:env) { { 'PATH_INFO' => '/sitemap.xml', 'steam.page' => nil, 'steam.site' => site } }
    subject { middleware.call(env) }

    describe 'no pages' do

      it 'renders a blank sitemap' do
        is_expected.to eq [200, { "Content-Type"=>"text/plain" }, ["<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\" xmlns:xhtml=\"http://www.w3.org/1999/xhtml\">\n\n</urlset>\n"]]
      end

    end

    describe 'only layouts' do

      let(:pages) { [instance_double('Page', index?: false, not_found?: false, layout?: true)] }

      it 'renders a blank sitemap' do
        is_expected.to eq [200, { "Content-Type"=>"text/plain" }, ["<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\" xmlns:xhtml=\"http://www.w3.org/1999/xhtml\">\n\n</urlset>\n"]]
      end

    end

  end

end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
locomotivecms_steam-1.6.1 spec/unit/middlewares/sitemap_spec.rb
locomotivecms_steam-1.6.0 spec/unit/middlewares/sitemap_spec.rb
locomotivecms_steam-1.6.0.rc1 spec/unit/middlewares/sitemap_spec.rb
locomotivecms_steam-1.6.0.beta1 spec/unit/middlewares/sitemap_spec.rb
locomotivecms_steam-1.5.3 spec/unit/middlewares/sitemap_spec.rb
locomotivecms_steam-1.5.2 spec/unit/middlewares/sitemap_spec.rb
locomotivecms_steam-1.5.1 spec/unit/middlewares/sitemap_spec.rb
locomotivecms_steam-1.5.0 spec/unit/middlewares/sitemap_spec.rb
locomotivecms_steam-1.5.0.rc1 spec/unit/middlewares/sitemap_spec.rb
locomotivecms_steam-1.5.0.rc0 spec/unit/middlewares/sitemap_spec.rb
locomotivecms_steam-1.5.0.beta3 spec/unit/middlewares/sitemap_spec.rb
locomotivecms_steam-1.5.0.beta2 spec/unit/middlewares/sitemap_spec.rb
locomotivecms_steam-1.5.0.beta1 spec/unit/middlewares/sitemap_spec.rb