Sha256: ccf8944cec38f110e319c48017a66a7f23bf229f9c75074cd0103fc8664ef14d

Contents?: true

Size: 1.68 KB

Versions: 10

Compression:

Stored size: 1.68 KB

Contents

require 'spec_helper'

require_relative '../../../lib/locomotive/steam/middlewares/thread_safe'
require_relative '../../../lib/locomotive/steam/middlewares/helpers'
require_relative '../../../lib/locomotive/steam/middlewares/entry_submission'

describe Locomotive::Steam::Middlewares::EntrySubmission do

  let(:app)         { ->(env) { [200, env, ['app']] } }
  let(:site)        { instance_double('Site', default_locale: 'en', locales: ['en']) }
  let(:middleware)  { described_class.new(app) }
  let(:service)     { instance_double('EntrySubmission') }
  let(:services)    { instance_double('Services', entry_submission: service, :locale= => 'en') }
  let(:session)     { {} }
  let(:method)      { 'POST' }

  before do
    allow_any_instance_of(described_class).to receive(:csrf_field).and_return('csrf_field')
  end

  describe '#call' do

    let(:rack_env) { build_env }

    before do
      expect(service).to receive(:submit).with('contacts', { email: 'john@doe.net' }).and_return(entry)
    end

    subject { middleware.call(rack_env) }

    context 'the creation of a content entry returns nil' do

      let(:form)  { { content_type_slug: 'contacts', content: { email: 'john@doe.net' } } }
      let(:entry) { nil }

      it 'raises an exception' do
        expect { subject }.to raise_exception('Unknown content type "contacts" or public_submission_enabled property not true')
      end

    end

  end

  def build_env
    env_for('http://example.com/contact-us', params: form, method: method).tap do |env|
      env['steam.request']    = Rack::Request.new(env)
      env['steam.site']       = site
      env['steam.services']   = services
      env['rack.session']     = session
    end
  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
locomotivecms_steam-1.4.1 spec/unit/middlewares/entry_submission_spec.rb
locomotivecms_steam-1.4.0 spec/unit/middlewares/entry_submission_spec.rb
locomotivecms_steam-1.4.0.rc2 spec/unit/middlewares/entry_submission_spec.rb
locomotivecms_steam-1.4.0.rc1 spec/unit/middlewares/entry_submission_spec.rb
locomotivecms_steam-1.4.0.pre.rc.1 spec/unit/middlewares/entry_submission_spec.rb
locomotivecms_steam-1.3.0 spec/unit/middlewares/entry_submission_spec.rb
locomotivecms_steam-1.3.0.rc2 spec/unit/middlewares/entry_submission_spec.rb
locomotivecms_steam-1.2.1 spec/unit/middlewares/entry_submission_spec.rb
locomotivecms_steam-1.3.0.rc1 spec/unit/middlewares/entry_submission_spec.rb
locomotivecms_steam-1.2.0 spec/unit/middlewares/entry_submission_spec.rb