Sha256: d152c966eb90b844053d43573ab95ad2216d9b69f6510cc7b7761ee0ac43cf37

Contents?: true

Size: 1.25 KB

Versions: 21

Compression:

Stored size: 1.25 KB

Contents

require 'rest-core/test'

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

  env = {RC::REQUEST_QUERY => {}}

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

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

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

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

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

    would 'string_keys in query' do
      e = {'query' => {:symbol => 'value'}}
      @app.call(env.merge(e)){ |r|
        r.should.eq({RC::REQUEST_QUERY => {'symbol' => 'value'}}.merge(e))
      }
    end

    would 'also merge the very default query' do
      @app.query = {'a' => 'b'}
      @app.call('query' => {'b' => 'c'},
               RC::REQUEST_QUERY => {'c' => 'd'}) do |r|
        r[RC::REQUEST_QUERY].should.eq 'a' => 'b', 'b' => 'c', 'c' => 'd'
      end
    end
  end

  describe 'when not given query' do
    would 'merge query with {}' do
      @app.call(env){ |r| r.should.eq(RC::REQUEST_QUERY => {}) }
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
rest-core-4.0.1 test/test_default_query.rb
rest-core-4.0.0 test/test_default_query.rb
rest-core-3.6.0 test/test_default_query.rb
rest-core-3.5.92 test/test_default_query.rb
rest-core-3.5.91 test/test_default_query.rb
rest-core-3.5.9 test/test_default_query.rb
rest-core-3.5.8 test/test_default_query.rb
rest-core-3.5.7 test/test_default_query.rb
rest-core-3.5.6 test/test_default_query.rb
rest-core-3.5.5 test/test_default_query.rb
rest-core-3.5.4 test/test_default_query.rb
rest-core-3.5.3 test/test_default_query.rb
rest-core-3.5.2 test/test_default_query.rb
rest-core-3.5.1 test/test_default_query.rb
rest-core-3.5.0 test/test_default_query.rb
rest-core-3.4.1 test/test_default_query.rb
rest-core-3.4.0 test/test_default_query.rb
rest-core-3.3.3 test/test_default_query.rb
rest-core-3.3.2 test/test_default_query.rb
rest-core-3.3.1 test/test_default_query.rb