Sha256: b42a5f36e1b89565b9834ebd5914bb3db6cb2bdc807f52c01834046070a3ef24

Contents?: true

Size: 1.5 KB

Versions: 1

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(false)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
redis_dedupe-0.0.3 spec/redis_dedupe_spec.rb