<commit_before>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 "accept header is given" do

    context 'path not excluded' do
      before do
        post '/posts', json, { 'request-json-format'  => 'underscore',
                               'response-json-format' => 'underscore',
                               'CONTENT-TYPE'         => 'application/json' }
      end

      subject { MultiJson.load(last_response.body) }

      it "converts lower camelcase to underscore params" do
        expect(last_response).to be_successful
        expect(subject).to have_key("keys")
        expect(subject["keys"]).to include("user_name")
        expect(subject["keys"]).to include("bar")
        expect(subject["keys"]).to include("lord_foo")
      end
    end

    context 'exclude paths' do
      before do
        get '/ignore', json_object, { 'CONTENT-TYPE'         => 'application/json',
                                      'request-json-format'  => 'underscore',
                                      'response-json-format' => 'underscore' }
      end

      subject { MultiJson.load(last_response.body) }

      it 'should not touch the input keys and the response' do
        expect(subject).to have_key('camelCase')
        expect(subject).to have_key('snake_case')
        expect(subject).to have_key('keys')
        keys = subject['keys']
        %w(userName lordFoo bar).each do |key|
          expect(keys).to include(key)
        end
      end
    end

    context 'converts GET url parameters' do
      before do
        get '/upcase_first_name?userOptions[firstName]=susi',
            {},
            {
              'request-json-format' => 'underscore',
              'CONTENT-TYPE'        => 'application/json'
            }
      end
      subject { MultiJson.load(last_response.body) }

      it 'should return an array as root element' do
        expect(subject).to_not have_key("user_options")
        expect(subject).to have_key("userOptions")
        expect(subject["userOptions"]).to have_key("firstName")
        expect(subject["userOptions"]["firstName"]).to eq("SUSI")
      end<commit_msg>modifies spec so that rails 4 breaks<commit_after>require 'spec_helper'

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

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

  context "accept header is given" do

    context 'path not excluded' do
      before do
        post '/posts', json, { 'request-json-format'  => 'underscore',
                               'response-json-format' => 'underscore',
                               'CONTENT-TYPE'         => 'application/json' }
      end

      subject { MultiJson.load(last_response.body) }

      it "converts lower camelcase to underscore params" do
        expect(last_response).to be_successful
        expect(subject).to have_key("keys")
        expect(subject["keys"]).to include("user_name")
        expect(subject["keys"]).to include("bar")
        expect(subject["keys"]).to include("lord_füü")
      end
    end

    context 'exclude paths' do
      before do
        get '/ignore', json_object, { 'CONTENT-TYPE'         => 'application/json',
                                      'request-json-format'  => 'underscore',
                                      'response-json-format' => 'underscore' }
      end

      subject { MultiJson.load(last_response.body) }

      it 'should not touch the input keys and the response' do
        expect(subject).to have_key('camelCase')
        expect(subject).to have_key('snake_case')
        expect(subject).to have_key('keys')
        keys = subject['keys']
        %w(userName lordFüü bar).each do |key|
          expect(keys).to include(key)
        end
      end
    end

    context 'converts GET url parameters' do
      before do
        get '/upcase_first_name?userOptions[firstName]=susi',
            {},
            {
              'request-json-format' => 'underscore',
              'CONTENT-TYPE'        => 'application/json'
            }
      end
      subject { MultiJson.load(last_response.body) }

      it 'should return an array as root element' do
        expect(subject).to_not have_key("user_options")
        expect(subject).to have_key("userOptions")
        expect(subject["userOptions"]).to have_key("firstName")
        expect(subject["userOptions"]["firstName"]).to eq("SUSI")
      end
{'fraction_non_alphanumeric': 0.12172802723983826, 'fraction_numerical': 0.0010640561821664183, 'mean_word_length': 2.0618892508143323, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1549528', 'n_tokens_mistral': 1376, 'n_tokens_neox': 1329, 'n_words': 305}