Sha256: 3e794e8f1f7db94ad442695173a6671c4d4224735278a2ffc9e00cfd604f6887
Contents?: true
Size: 1.82 KB
Versions: 1
Compression:
Stored size: 1.82 KB
Contents
require 'spec_helper' describe PeriodicCounter do before(:all) do $db.migrate(1) $db.migrate(0) $db.migrate(1) create_counter end it "should not do anything but set up data" do start attributes = Counter.last.attributes data = attributes.delete('counter_data') data.delete('counter_last_day_at').to_s.should == Time.now.utc.to_s data.delete('counter_last_2_days_at').to_s.should == Time.now.utc.to_s data.should == { "counter_last_day"=>1, "counter_last_2_days"=>1 } attributes.should == { "id"=>1, "counter"=>1, "counter_last_day"=>0, "counter_last_2_days"=>0 } end it "should add to counter_last_day" do Counter.last.update_attribute :counter, 2 stub_time(Time.now + 1.day) start attributes = Counter.last.attributes data = attributes.delete('counter_data') data.delete('counter_last_day_at').to_s.should == Time.now.utc.to_s data.delete('counter_last_2_days_at').to_s.should == (Time.now - 1.day).utc.to_s data.should == { "counter_last_day"=>2, "counter_last_2_days"=>1 } attributes.should == { "id"=>1, "counter"=>2, "counter_last_day"=>1, "counter_last_2_days"=>0 } end it "should add to counter_last_2_days" do Counter.last.update_attribute :counter, 3 stub_time(Time.now + 2.days) start attributes = Counter.last.attributes data = attributes.delete('counter_data') data.delete('counter_last_day_at').to_s.should == Time.now.utc.to_s data.delete('counter_last_2_days_at').to_s.should == Time.now.utc.to_s data.should == { "counter_last_day"=>3, "counter_last_2_days"=>3 } attributes.should == { "id"=>1, "counter"=>3, "counter_last_day"=>1, "counter_last_2_days"=>2 } end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
periodic_counter-0.1.0 | spec/periodic_counter_spec.rb |