<commit_before>
require 'rest-core/test'

describe RC::DefaultQuery do
  describe 'when given query' do
    before do
      @app = RC::DefaultQuery.new(RC::Dry.new, {})
    end

    def app
      @app
    end

    should 'do nothing' do
      app.call({}){ |r| r[RC::REQUEST_QUERY].should.eq({}) }
    end

    should 'merge query' do
      app.instance_eval{@query = {'q' => 'uery'}}

      app.call({}){ |r| r.should.eq({RC::REQUEST_QUERY => {'q' => 'uery'}}) }

      format = {'format' => 'json'}
      env    = {RC::REQUEST_QUERY => format}

      app.call(env){ |r|
        r.should.eq({RC::REQUEST_QUERY => {'q' => 'uery'}.merge(format)}) }
    end
  end

  describe 'when not given query' do
    before do
      @app = RC::DefaultQuery.new(RC::Dry.new)
    end

    def app
      @app
    end

    should 'merge query with {}' do
      app.call({}){ |r| r.should.eq({RC::REQUEST_QUERY => {}}) }
    end<commit_msg>move before filter to top level<commit_after>
require 'rest-core/test'

describe RC::DefaultQuery do
  before do
    @app = RC::DefaultQuery.new(RC::Dry.new, {})
  end

  describe 'when given query' do
    should 'do nothing' do
      @app.call({}){ |r| r[RC::REQUEST_QUERY].should.eq({}) }
    end

    should 'merge query' do
      @app.instance_eval{@query = {'q' => 'uery'}}

      @app.call({}){ |r| r.should.eq({RC::REQUEST_QUERY => {'q' => 'uery'}}) }

      format = {'format' => 'json'}
      env    = {RC::REQUEST_QUERY => format}

      @app.call(env){ |r|
        r.should.eq({RC::REQUEST_QUERY => {'q' => 'uery'}.merge(format)}) }
    end
  end

  describe 'when not given query' do
    should 'merge query with {}' do
      @app.call({}){ |r| r.should.eq({RC::REQUEST_QUERY => {}}) }
    end
{'fraction_non_alphanumeric': 0.19281991893456862, 'fraction_numerical': 0.0, 'mean_word_length': 2.6844349680170576, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5365723', 'n_tokens_mistral': 642, 'n_tokens_neox': 624, 'n_words': 145}