Sha256: 21f839af3257de2a7c953a35fd6a66b3cff976ccd10d1b92f9b7b497029160e1

Contents?: true

Size: 1.7 KB

Versions: 16

Compression:

Stored size: 1.7 KB

Contents

require 'spec_helper'

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

  context 'with valid points' do
    let(:san_francisco) { [-122.5076404, 37.757815, 'SF'] }
    let(:los_angeles) { [-118.6919259, 34.0207305, 'LA'] }
    let(:expected_result) do
      [['LA', 1.364461589564902e+15], ['SF', 1.367859319053696e+15]]
    end

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

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

    it 'adds members to ZSET' do
      cities = @redises.zrange(key, 0, -1, with_scores: true)
      expect(cities).to be == expected_result
    end
  end

  context 'with invalud points' do
    context 'when number of arguments wrong' do
      let(:message) { "ERR wrong number of arguments for 'geoadd' command" }

      it 'raises Redis::CommandError' do
        expect { @redises.geoadd(key, 1, 1) }
          .to raise_error(Redis::CommandError, message)
      end
    end

    context 'when coordinates are not in allowed range' do
      let(:coords) { [181, 86] }
      let(:message) do
        formatted_coords = coords.map { |c| format('%<coords>.6f', coords: c) }
        "ERR invalid longitude,latitude pair #{formatted_coords.join(',')}"
      end

      after { @redises.zrem(key, 'SF') }

      it 'raises Redis::CommandError' do
        expect { @redises.geoadd(key, *coords, 'SF') }
          .to raise_error(Redis::CommandError, message)
      end
    end

    context 'when coordinates are not valid floats' do
      let(:coords) { ['x', 35] }
      let(:message) { 'ERR value is not a valid float' }

      it 'raises Redis::CommandError' do
        expect { @redises.geoadd key, *coords, 'SF' }
          .to raise_error(Redis::CommandError, message)
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

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