Sha256: 21b5d7a708fa3bc2e0309829e7c0e3e44d0f4f710559bd167cbe188fbaae7ba8

Contents?: true

Size: 1.5 KB

Versions: 3

Compression:

Stored size: 1.5 KB

Contents

require 'redis_dedupe'
require 'mock_redis'
require 'spec_helper'

describe RedisDedupe::Set do
  it "is initialized with a redis client and key" do
    dedupe = RedisDedupe::Set.new(:redis, :key)
    expect(dedupe.key).to eq(:key)
  end

  it "defaults expires_in to 7 days" do
    dedupe = RedisDedupe::Set.new(:redis, :key)
    expect(dedupe.expires_in.to_i).to eq(7 * 24 * 60 * 60)
  end

  it "optionally receives an expires_in seconds value" do
    dedupe = RedisDedupe::Set.new(:redis, :key, 60)
    expect(dedupe.expires_in.to_i).to eq(60)
  end
end

describe RedisDedupe::Set, "#check" do
  it "prevents a block from yielding multiple times for the same member" do
    dedupe1 = RedisDedupe::Set.new(MockRedis.new, 'spec_key:1')
    dedupe2 = RedisDedupe::Set.new(MockRedis.new, 'spec_key:2')

    @results = []

    dedupe1.check('1') { @results << 'A' }
    dedupe1.check('1') { @results << 'B' }
    dedupe2.check('1') { @results << 'C' }

    expect(@results).to eq(['A', 'C'])
  end

  it "sets the set to expire so it cleans up if the process never completes" do
    redis  = MockRedis.new
    dedupe = RedisDedupe::Set.new(redis, 'spec_key:1', 10)

    dedupe.check('1') {  }

    expect(redis.ttl 'spec_key:1').to be_within(1).of(10)
  end
end

describe RedisDedupe::Set, "#finish" do
  it "removes the set to free up memory" do
    redis  = MockRedis.new
    dedupe = RedisDedupe::Set.new(redis, 'spec_key:1')

    dedupe.check('1') {  }
    dedupe.finish

    expect(redis.exists 'spec_key:1').to be(0)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
redis_dedupe-0.0.6 spec/redis_dedupe_spec.rb
redis_dedupe-0.0.5 spec/redis_dedupe_spec.rb
redis_dedupe-0.0.4 spec/redis_dedupe_spec.rb