Skip to content

Commit

Permalink
Fixes download test for count/day over month boundary.
Browse files Browse the repository at this point in the history
The download_test.rb test for getting counts by day for a date range
was calling the method with strings instead of date objects. Actual
code uses dates. Changed the test to use dates so date arithmetic
is reliable. Fixed with @jaredonline. Issue #465.
  • Loading branch information
mildmojo committed Nov 4, 2012
1 parent 4be9f37 commit ad86e15
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions test/unit/download_test.rb
Expand Up @@ -164,6 +164,30 @@ class DownloadTest < ActiveSupport::TestCase
assert_equal downloads, Download.counts_by_day_for_versions([@version_1, @version_2, @version_3], 2)
end

should "find counts per day for versions in range across month boundary" do
Timecop.freeze(Time.parse("2012-10-01")) do
@rubygem_1 = create(:rubygem)
@version_1 = create(:version, :rubygem => @rubygem_1)

Timecop.freeze(1.day.ago) do
create :version_history, :version => @version_1, :count => 5
end

Download.incr(@rubygem_1, @version_1.full_name)

start = 2.days.ago.to_date
fin = Time.zone.today

downloads = ActiveSupport::OrderedHash.new.tap do |d|
d[start.to_s] = 0
d["#{Date.yesterday}"] = 5
d[fin.to_s] = 1
end

assert_equal downloads, Download.counts_by_day_for_version_in_date_range(@version_1, start, fin)
end
end

should "find counts per day for versions in range" do
@rubygem_1 = create(:rubygem)
@version_1 = create(:version, :rubygem => @rubygem_1)
Expand All @@ -174,13 +198,13 @@ class DownloadTest < ActiveSupport::TestCase

Download.incr(@rubygem_1, @version_1.full_name)

start = 2.days.ago.to_date.to_s
fin = Time.zone.today.to_s
start = 2.days.ago.to_date
fin = Time.zone.today

downloads = ActiveSupport::OrderedHash.new.tap do |d|
d[start] = 0
d[start.to_s] = 0
d["#{Date.yesterday}"] = 5
d[fin] = 1
d[fin.to_s] = 1
end

assert_equal downloads, Download.counts_by_day_for_version_in_date_range(@version_1, start, fin)
Expand Down

0 comments on commit ad86e15

Please sign in to comment.