Sha256: e827c70185634ccabaadccd77de928cf89d35100ab6dab7d98029ac0b51c498a

Contents?: true

Size: 1.68 KB

Versions: 21

Compression:

Stored size: 1.68 KB

Contents

shared_examples_for "a sortable" do
  it 'returns empty array on nil' do
    @redises.sort(nil).should == []
  end

  context 'ordering' do
    it 'orders ascending by default' do
      @redises.sort(@key).should == ['1', '2']
    end

    it 'orders by descending when specified' do
      @redises.sort(@key, :order => "DESC").should == ['2', '1']
    end
  end

  context 'projections' do
    it 'projects element when :get is "#"' do
      @redises.sort(@key, :get => '#').should == ['1', '2']
    end

    it 'projects through a key pattern' do
      @redises.sort(@key, :get => 'mock-redis-test:values_*').should == ['a', 'b']
    end

    it 'projects through a key pattern and reflects element' do
      @redises.sort(@key, :get => ['#', 'mock-redis-test:values_*']).should == [['1', 'a'], ['2', 'b']]
    end

    it 'projects through a hash key pattern' do
      @redises.sort(@key, :get => 'mock-redis-test:hash_*->key').should == ['x', 'y']
    end
  end

  context 'weights' do
    it 'weights by projecting through a key pattern' do
      @redises.sort(@key, :by => "mock-redis-test:weight_*").should == ['2', '1']
    end

    it 'weights by projecting through a key pattern and a specific order' do
      @redises.sort(@key, :order => "DESC", :by => "mock-redis-test:weight_*").should == ['1', '2']
    end
  end

  context 'limit' do
    it 'only returns requested window in the enumerable' do
      @redises.sort(@key, :limit => [0, 1]).should == ['1']
    end
  end

  context 'store' do
    it 'stores into another key' do
      @redises.sort(@key, :store => "mock-redis-test:some_bucket").should == 2
      @redises.lrange("mock-redis-test:some_bucket", 0, -1).should == ['1', '2']
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
mock_redis-0.14.1 spec/support/shared_examples/sorts_enumerables.rb
mock_redis-0.14.0 spec/support/shared_examples/sorts_enumerables.rb
mock_redis-0.13.2 spec/support/shared_examples/sorts_enumerables.rb
mock_redis-0.13.1 spec/support/shared_examples/sorts_enumerables.rb
mock_redis-0.13.0 spec/support/shared_examples/sorts_enumerables.rb
mock_redis-0.12.1 spec/support/shared_examples/sorts_enumerables.rb
mock_redis-0.12.0 spec/support/shared_examples/sorts_enumerables.rb
mock_redis-0.11.0 spec/support/shared_examples/sorts_enumerables.rb
mock_redis-0.10.0 spec/support/shared_examples/sorts_enumerables.rb
mock_redis-0.9.0 spec/support/shared_examples/sorts_enumerables.rb
mock_redis-0.8.2 spec/support/shared_examples/sorts_enumerables.rb
mock_redis-0.8.1 spec/support/shared_examples/sorts_enumerables.rb
mock_redis-0.8.0 spec/support/shared_examples/sorts_enumerables.rb
mock_redis-0.7.0 spec/support/shared_examples/sorts_enumerables.rb
mock_redis-0.6.6 spec/support/shared_examples/sorts_enumerables.rb
mock_redis-0.6.5 spec/support/shared_examples/sorts_enumerables.rb
mock_redis-0.6.4 spec/support/shared_examples/sorts_enumerables.rb
mock_redis-0.6.3 spec/support/shared_examples/sorts_enumerables.rb
mock_redis-0.6.2 spec/support/shared_examples/sorts_enumerables.rb
mock_redis-0.6.1 spec/support/shared_examples/sorts_enumerables.rb