Sha256: ed5aeb4aea8491acba64ce23722b57372bdb7269215314089b3e58620ece30a0

Contents?: true

Size: 1.37 KB

Versions: 20

Compression:

Stored size: 1.37 KB

Contents

require 'spec_helper'

describe '#geohash' do
  let(:key) { 'cities' }

  context 'with existing key' do
    let(:san_francisco) { [-122.5076404, 37.757815, 'SF'] }
    let(:los_angeles) { [-118.6919259, 34.0207305, 'LA'] }

    before { @redises.geoadd(key, *san_francisco, *los_angeles) }

    after { @redises.zrem(key, %w[SF LA]) }

    context 'with existing points only' do
      let(:expected_result) do
        %w[9q8yu38ejp0 9q59e171je0]
      end

      it 'returns decoded coordinates pairs for each point' do
        results = @redises.geohash(key, %w[SF LA])
        expect(results).to be == expected_result
      end

      context 'with non-existing points only' do
        it 'returns array filled with nils' do
          results = @redises.geohash(key, %w[FF FA])
          expect(results).to be == [nil, nil]
        end
      end

      context 'with both existing and non-existing points' do
        let(:expected_result) do
          ['9q8yu38ejp0', nil]
        end

        it 'returns mixture of nil and coordinates pair' do
          results = @redises.geohash(key, %w[SF FA])
          expect(results).to be == expected_result
        end
      end
    end
  end

  context 'with non-existing key' do
    before { @redises.del(key) }

    it 'returns empty array' do
      results = @redises.geohash(key, %w[SF LA])
      expect(results).to be == [nil, nil]
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
mock_redis-0.36.0 spec/commands/geohash_spec.rb
mock_redis-0.35.0 spec/commands/geohash_spec.rb
mock_redis-0.34.0 spec/commands/geohash_spec.rb
mock_redis-0.33.0 spec/commands/geohash_spec.rb
mock_redis-0.32.0 spec/commands/geohash_spec.rb
mock_redis-0.31.0 spec/commands/geohash_spec.rb
mock_redis-0.30.0 spec/commands/geohash_spec.rb
mock_redis-0.29.0 spec/commands/geohash_spec.rb
mock_redis-0.28.0 spec/commands/geohash_spec.rb
mock_redis-0.27.3 spec/commands/geohash_spec.rb
mock_redis-0.27.2 spec/commands/geohash_spec.rb
mock_redis-0.27.1 spec/commands/geohash_spec.rb
mock_redis-0.27.0 spec/commands/geohash_spec.rb
mock_redis-0.26.0 spec/commands/geohash_spec.rb
mock_redis-0.25.0 spec/commands/geohash_spec.rb
mock_redis-0.24.0 spec/commands/geohash_spec.rb
mock_redis-0.23.0 spec/commands/geohash_spec.rb
mock_redis-0.22.0 spec/commands/geohash_spec.rb
mock_redis-0.21.0 spec/commands/geohash_spec.rb
mock_redis-0.20.0 spec/commands/geohash_spec.rb