Sha256: 08045ffd8ac078748499ed4a2d1a3c0127856f676c918b00265203d7dc472592

Contents?: true

Size: 1.69 KB

Versions: 3

Compression:

Stored size: 1.69 KB

Contents

require 'spec_helper'

describe "camel caser middleware for Rails", type: :rails do

  let(:json_object) do
    {
      userName: 'dsci',
      bar:      { lordFoo: 12 },
      "DE"      => 'german'
    }
  end
  let(:json) { MultiJson.dump(json_object) }

    context "camel caser middleware for Rails with accept header " do

      before do
        Sparrow.configure do |config|
          config.allowed_accepts = %w[foo/bar]
        end
      end

      after do
        Sparrow.configure do |config|
          config.allowed_accepts = [nil]
        end
      end


      it 'does not process the request if the accept header is not allowed' do

        post '/posts', json, { 'request-json-format'  => 'underscore',
                               'response-json-format' => 'underscore',
                               'CONTENT-TYPE'         => 'application/json',
                               'ACCEPT'               => 'text/html' }

        last_json = MultiJson.load(last_response.body)
        expect(last_json['keys']).to include('userName')
        expect(last_json['keys']).to include('bar')
        expect(last_json['keys']).to include('DE')
      end

      it 'does process the request if the accept header is allowed' do

        post '/posts', json, { 'request-json-format'  => 'underscore',
                               'response-json-format' => 'underscore',
                               'CONTENT-TYPE'         => 'application/json',
                               'ACCEPT'               => 'foo/bar, gate/protect' }

        last_json = MultiJson.load(last_response.body)
        expect(last_json['keys']).to include('user_name')
        expect(last_json['keys']).to include('de')
      end
    end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cp-sparrow-0.0.14 spec/integration/rails/camel_caser_accept_header_spec.rb
cp-sparrow-0.0.12 spec/integration/rails/camel_caser_accept_header_spec.rb
cp-sparrow-0.0.11 spec/integration/rails/camel_caser_accept_header_spec.rb