Sha256: 2645b1437ec900a96a423c2883db0b11ec19ccfb5077ce0914a1696bbeaf1da1

Contents?: true

Size: 1.52 KB

Versions: 23

Compression:

Stored size: 1.52 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe Praxis::MultipartParser do
  let(:form) do
    form_data = MIME::Multipart::FormData.new

    destination_path = MIME::Text.new('/etc/defaults')
    form_data.add destination_path, 'destination_path'

    form_data
  end

  let(:headers) { form.headers.headers }
  let(:body) { form.body.to_s }

  let(:parser) { Praxis::MultipartParser.new(headers, body) }

  subject(:parts) { parser.parse[1] }

  context 'with simple parts' do
    it { should be_kind_of(Array) }
    it { should have(1).item }

    context 'the parsed parts' do
      subject(:part) { parts.first }

      its(:name) { should eq 'destination_path' }
      its(:body) { should eq '/etc/defaults' }
    end
  end

  context 'with a file part' do
    before do
      text = MIME::Text.new('DOCKER_HOST=tcp://127.0.0.1:2375')
      form.add text, 'file', 'docker'
    end

    subject(:part) { parts.find { |p| p.name == 'file' } }
    # subject(:part_body) { part.body }

    its(:payload) { should be_kind_of(Tempfile) }
    its(:filename) { should eq('docker') }
    its(:name) { should eq('file') }

    context 'headers' do
      subject(:part_headers) { part.headers }
      its(['Content-Type']) { should eq('text/plain') }
      its(['Content-Disposition']) { should match(/filename=docker/) }
    end

    it 'saves the value to the tempfile' do
      expect(File.exist?(part.payload.path)).to be(true)

      part.payload.rewind
      expect(part.payload.read).to eq('DOCKER_HOST=tcp://127.0.0.1:2375')
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
praxis-2.0.0 spec/praxis/multipart/parser_spec.rb
praxis-2.0.pre.40 spec/praxis/multipart/parser_spec.rb
praxis-2.0.pre.39 spec/praxis/multipart/parser_spec.rb
praxis-2.0.pre.38 spec/praxis/multipart/parser_spec.rb
praxis-2.0.pre.37 spec/praxis/multipart/parser_spec.rb
praxis-2.0.pre.36 spec/praxis/multipart/parser_spec.rb
praxis-2.0.pre.35 spec/praxis/multipart/parser_spec.rb
praxis-2.0.pre.34 spec/praxis/multipart/parser_spec.rb
praxis-2.0.pre.33 spec/praxis/multipart/parser_spec.rb
praxis-2.0.pre.32 spec/praxis/multipart/parser_spec.rb
praxis-2.0.pre.31 spec/praxis/multipart/parser_spec.rb
praxis-2.0.pre.30 spec/praxis/multipart/parser_spec.rb
praxis-2.0.pre.29 spec/praxis/multipart/parser_spec.rb
praxis-2.0.pre.28 spec/praxis/multipart/parser_spec.rb
praxis-2.0.pre.27 spec/praxis/multipart/parser_spec.rb
praxis-2.0.pre.26 spec/praxis/multipart/parser_spec.rb
praxis-2.0.pre.25 spec/praxis/multipart/parser_spec.rb
praxis-2.0.pre.24 spec/praxis/multipart/parser_spec.rb
praxis-2.0.pre.23 spec/praxis/multipart/parser_spec.rb
praxis-2.0.pre.22 spec/praxis/multipart/parser_spec.rb