Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
84 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 2 additions & 4 deletions
6
...te/001_counters_without_starting_value.rb → spec/db/migrate/001_counters.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,98 +1,66 @@ | ||
require 'spec_helper' | ||
|
||
describe PeriodicCounter do | ||
describe "without starting value" do | ||
|
||
before(:each) do | ||
$db.migrate(1) | ||
$db.migrate(0) | ||
$db.migrate(1) | ||
create_counter | ||
end | ||
|
||
it "should add to counter_last_day" do | ||
stub_time(Time.now + 1.day) | ||
start | ||
Counter.last.counter_last_day.should == 2 | ||
Counter.last.counter_last_2_days.should == 1 | ||
Counter.last.counter_last_week.should == 1 | ||
Counter.last.counter_last_2_weeks.should == 1 | ||
end | ||
|
||
it "should add to counter_last_2_days" do | ||
stub_time(Time.now + 2.days) | ||
start | ||
Counter.last.counter_last_day.should == 2 | ||
Counter.last.counter_last_2_days.should == 2 | ||
Counter.last.counter_last_week.should == 1 | ||
Counter.last.counter_last_2_weeks.should == 1 | ||
end | ||
|
||
it "should add to counter_last_week" do | ||
stub_time(Time.now + 1.week) | ||
start | ||
Counter.last.counter_last_day.should == 2 | ||
Counter.last.counter_last_2_days.should == 2 | ||
Counter.last.counter_last_week.should == 2 | ||
Counter.last.counter_last_2_weeks.should == 1 | ||
end | ||
|
||
it "should add to counter_last_2_weeks" do | ||
stub_time(Time.now + 2.weeks) | ||
start | ||
Counter.last.counter_last_day.should == 2 | ||
Counter.last.counter_last_2_days.should == 2 | ||
Counter.last.counter_last_week.should == 2 | ||
Counter.last.counter_last_2_weeks.should == 2 | ||
end | ||
|
||
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('computed_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('computed_at').to_s.should == Time.now.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 | ||
|
||
describe "with starting value" do | ||
|
||
before(:each) do | ||
$db.migrate(2) | ||
$db.migrate(0) | ||
$db.migrate(2) | ||
Counter.reset_column_information | ||
create_counter | ||
start | ||
Counter.last.update_attribute :counter, 6 | ||
end | ||
|
||
it "should add to counter_last_day" do | ||
stub_time(Time.now + 1.day) | ||
start | ||
Counter.last.counter_last_day.should == 2 | ||
Counter.last.counter_last_2_days.should == 1 | ||
Counter.last.counter_last_week.should == 1 | ||
Counter.last.counter_last_2_weeks.should == 1 | ||
end | ||
|
||
it "should add to counter_last_2_days" do | ||
stub_time(Time.now + 2.days) | ||
start | ||
Counter.last.counter_last_day.should == 2 | ||
Counter.last.counter_last_2_days.should == 2 | ||
Counter.last.counter_last_week.should == 1 | ||
Counter.last.counter_last_2_weeks.should == 1 | ||
end | ||
|
||
it "should add to counter_last_week" do | ||
stub_time(Time.now + 1.week) | ||
start | ||
Counter.last.counter_last_day.should == 2 | ||
Counter.last.counter_last_2_days.should == 2 | ||
Counter.last.counter_last_week.should == 2 | ||
Counter.last.counter_last_2_weeks.should == 1 | ||
end | ||
|
||
it "should add to counter_last_2_weeks" do | ||
stub_time(Time.now + 2.weeks) | ||
start | ||
Counter.last.counter_last_day.should == 2 | ||
Counter.last.counter_last_2_days.should == 2 | ||
Counter.last.counter_last_week.should == 2 | ||
Counter.last.counter_last_2_weeks.should == 2 | ||
end | ||
it "should add to counter_last_2_days" do | ||
Counter.last.update_attribute :counter, 3 | ||
stub_time(Time.now + 3.days) | ||
start | ||
attributes = Counter.last.attributes | ||
data = attributes.delete('counter_data') | ||
data.delete('computed_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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters