Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 9dbe228750
Fetching contributors…

Cannot retrieve contributors at this time

56 lines (42 sloc) 1.645 kb
require 'test_helper'
describe Von::Counters::Current do
CurrentCounter = Von::Counters::Current
before :each do
Timecop.freeze(Time.local(2013, 01, 01, 06))
Von.config.init!
@redis = Redis.new
@redis.flushall
end
it "increments the current counter for a period" do
counter = CurrentCounter.new('foo', [ Von::Period.new(:day) ])
4.times { counter.increment }
Timecop.freeze(Time.local(2013, 01, 02))
3.times { counter.increment }
@redis.hget('von:counters:currents:foo:day', 'timestamp').must_equal '2013-01-02'
@redis.hget('von:counters:currents:foo:day', 'total').must_equal '3'
end
it "increments the current counter for multiple periods" do
counter = CurrentCounter.new('foo', [
Von::Period.new(:minute),
Von::Period.new(:week),
])
4.times { counter.increment }
Timecop.freeze(Time.local(2013, 01, 20, 06, 10))
3.times { counter.increment }
@redis.hget('von:counters:currents:foo:minute', 'timestamp').must_equal '2013-01-20 06:10'
@redis.hget('von:counters:currents:foo:minute', 'total').must_equal '3'
@redis.hget('von:counters:currents:foo:week', 'timestamp').must_equal '2013-01-14'
@redis.hget('von:counters:currents:foo:week', 'total').must_equal '3'
end
it "counts acurrent counter for a period" do
counter = CurrentCounter.new('foo', [
Von::Period.new(:minute),
Von::Period.new(:day),
])
4.times { counter.increment }
Timecop.freeze(Time.local(2013, 01, 01, 06, 10))
3.times { counter.increment }
counter.count(:minute).must_equal 3
counter.count(:day).must_equal 7
end
end
Jump to Line
Something went wrong with that request. Please try again.