Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes download test for count/day over month boundary. #477

Merged
merged 1 commit into from
Nov 4, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions test/unit/download_test.rb
Original file line number Original file line Diff line number Diff line change
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) assert_equal downloads, Download.counts_by_day_for_versions([@version_1, @version_2, @version_3], 2)
end 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 should "find counts per day for versions in range" do
@rubygem_1 = create(:rubygem) @rubygem_1 = create(:rubygem)
@version_1 = create(:version, :rubygem => @rubygem_1) @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) Download.incr(@rubygem_1, @version_1.full_name)


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


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


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