Sha256: e87f746365c0162d41b75ac23b93bee1da139fa89d54898a3302482664e903c0

Contents?: true

Size: 1.27 KB

Versions: 1

Compression:

Stored size: 1.27 KB

Contents

require 'spec_helper'

require_relative '../../../lib/locomotive/steam/middlewares/threadsafe'
require_relative '../../../lib/locomotive/steam/middlewares/helpers'
require_relative '../../../lib/locomotive/steam/middlewares/site'

describe Locomotive::Steam::Middlewares::Site do

  let(:render_404)      { true }
  let(:configuration)   { instance_double('SimpleConfiguration', render_404_if_no_site: render_404) }
  let(:services)        { instance_double('SimpleServices', configuration: configuration) }
  let(:url)             { 'http://models.example.com' }
  let(:app)             { ->(env) { [200, env, 'app'] } }
  let(:middleware)      { Locomotive::Steam::Middlewares::Site.new(app) }

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

  describe 'no site' do

    before { expect(services).to receive(:current_site).and_return(nil) }

    describe 'render_404 option on' do
      it { is_expected.to eq [404, nil] }
    end

    describe 'render_404 option off' do

      let(:render_404) { false }

      it 'raises an exception' do
        expect { subject }.to raise_exception(Locomotive::Steam::NoSiteException)
      end

    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
locomotivecms_steam-1.0.0.pre.beta.3 spec/unit/middlewares/site_spec.rb