Sha256: 72930918a1d66c470c0bfa3e56d9ff2b8f2944717bf50ef257705fd940576e78

Contents?: true

Size: 1.83 KB

Versions: 6

Compression:

Stored size: 1.83 KB

Contents

require 'spec_helper'

require_relative '../../../lib/locomotive/steam/middlewares/path'

describe Locomotive::Steam::Middlewares::Path do

  let(:allow_dots_in_slugs) { false }
  let(:site)            { instance_double('Site', allow_dots_in_slugs: allow_dots_in_slugs) }
  let(:routes)          { {} }
  let(:url)             { 'http://models.example.com' }
  let(:path)            { 'hello-world' }
  let(:app)             { ->(env) { [200, env, 'app'] } }
  let(:middleware)      { described_class.new(app) }

  subject do
    env = env_for(url, 'steam.site' => site)
    env['steam.path']         = path
    env['steam.locale']       = 'en'
    env['steam.request']      = Rack::Request.new(env)
    code, env = middleware.call(env)
    env['steam.path']
  end

  describe 'allow_dots_in_slugs is off' do
    context 'html extension' do
      let(:path) { 'foo.html' }
      it { is_expected.to eq 'foo' }
    end

    context 'the path stores a version' do
      let(:path) { 'foo-v1.0' }
      it { is_expected.to eq 'foo-v1.0' }
    end

    context 'prefixed by 3 letters word' do
      let(:path) { 'foo.bar' }
      it { is_expected.to eq 'foo' }  
    end

    context 'starting by a dot' do
      let(:path) { '.well-known' }
      it { is_expected.to eq '.well-known' }  
    end
  end

  describe 'allow_dots_in_slugs is on' do
    let(:allow_dots_in_slugs) { true }

    context 'html extension' do
      let(:path) { 'foo.html' }
      it { is_expected.to eq 'foo' }
    end

    context 'prefixed by a version' do
      let(:path) { 'foo-v1.0' }
      it { is_expected.to eq 'foo-v1.0' }  
    end

    context 'prefixed by 3 letters word' do
      let(:path) { 'foo.bar' }
      it { is_expected.to eq 'foo.bar' }  
    end

    context 'starting by a dot' do
      let(:path) { '.well-known' }
      it { is_expected.to eq '.well-known' }  
    end
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
locomotivecms_steam-1.8.0.alpha2 spec/unit/middlewares/path_spec.rb
locomotivecms_steam-1.8.0.alpha1 spec/unit/middlewares/path_spec.rb
locomotivecms_steam-1.7.1 spec/unit/middlewares/path_spec.rb
locomotivecms_steam-1.7.0 spec/unit/middlewares/path_spec.rb
locomotivecms_steam-1.6.1 spec/unit/middlewares/path_spec.rb
locomotivecms_steam-1.6.0 spec/unit/middlewares/path_spec.rb