Sha256: 622e0e2645d5c5f819f0288c25b06ccfa1373d94d991a7e93c46b55dfaff6ffd

Contents?: true

Size: 1.31 KB

Versions: 5

Compression:

Stored size: 1.31 KB

Contents

RSpec.describe Evil::Client::Middleware::StringifyForm do
  let(:stack) { described_class.new(app) }
  let(:app)   { double :app }

  def update!(env)
    @result = env
  end

  before  { allow(app).to receive(:call) { |env| update! env } }
  subject { stack.call env }

  context "with a non-empty body:" do
    let(:env) do
      {
        body:   { foo: :FOO, bar: [:BAR], baz: { qux: :QUX }, qux: nil },
        format: "form"
      }
    end

    it "stringifies the body" do
      subject
      expect(@result[:body_string]).to eq "foo=FOO&bar[]=BAR&baz[qux]=QUX&qux="
    end

    it "adds content-type header" do
      subject
      expect(@result[:headers])
        .to eq "content-type" => "application/x-www-form-urlencoded"
    end
  end

  context "when format is not a form:" do
    let(:env) do
      {
        body:   { foo: :FOO, bar: [:BAR], baz: { qux: :QUX }, qux: nil },
        format: "json"
      }
    end

    it "does nothing" do
      subject
      expect(@result).to eq env
    end
  end

  context "with empty body:" do
    let(:env) { { body: {}, format: "form" } }

    it "does nothing" do
      subject
      expect(@result).to eq env
    end
  end

  context "without a body:" do
    let(:env) { { format: "form" } }

    it "does nothing" do
      subject
      expect(@result).to eq env
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
evil-client-0.3.1 spec/unit/evil/client/middleware/stringify_form_spec.rb
evil-client-0.3.0 spec/unit/evil/client/middleware/stringify_form_spec.rb
evil-client-0.2.3 spec/unit/evil/client/middleware/stringify_form_spec.rb
evil-client-0.2.2 spec/unit/evil/client/middleware/stringify_form_spec.rb
evil-client-0.2.1 spec/unit/evil/client/middleware/stringify_form_spec.rb