2019-04-29 19:27:42 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-27 21:27:38 -05:00
|
|
|
RSpec.describe WebCrawlerRequest do
|
2018-03-15 16:10:45 -05:00
|
|
|
before do
|
2022-02-22 10:45:25 -06:00
|
|
|
CachedCounting.reset
|
|
|
|
CachedCounting.enable
|
2018-03-15 16:10:45 -05:00
|
|
|
end
|
|
|
|
|
2022-02-22 10:45:25 -06:00
|
|
|
after { CachedCounting.disable }
|
2018-03-15 16:10:45 -05:00
|
|
|
|
2022-02-22 10:45:25 -06:00
|
|
|
it "can log crawler requests" do
|
|
|
|
freeze_time
|
|
|
|
d1 = Time.now.utc.to_date
|
2018-03-15 16:10:45 -05:00
|
|
|
|
2022-02-22 10:45:25 -06:00
|
|
|
4.times { WebCrawlerRequest.increment!("Googlebot") }
|
2018-03-15 16:10:45 -05:00
|
|
|
|
2022-02-22 10:45:25 -06:00
|
|
|
WebCrawlerRequest.increment!("Bingbot")
|
2018-03-15 16:10:45 -05:00
|
|
|
|
2022-02-22 10:45:25 -06:00
|
|
|
freeze_time 1.day.from_now
|
|
|
|
d2 = Time.now.utc.to_date
|
2018-03-15 16:10:45 -05:00
|
|
|
|
2022-02-22 10:45:25 -06:00
|
|
|
WebCrawlerRequest.increment!("Googlebot")
|
|
|
|
WebCrawlerRequest.increment!("Superbot")
|
2018-03-15 16:10:45 -05:00
|
|
|
|
2022-02-22 10:45:25 -06:00
|
|
|
CachedCounting.flush
|
2018-03-15 16:10:45 -05:00
|
|
|
|
2022-02-22 10:45:25 -06:00
|
|
|
expect(WebCrawlerRequest.find_by(date: d2, user_agent: "Googlebot").count).to eq(1)
|
|
|
|
expect(WebCrawlerRequest.find_by(date: d2, user_agent: "Superbot").count).to eq(1)
|
2018-03-15 16:10:45 -05:00
|
|
|
|
2022-02-22 10:45:25 -06:00
|
|
|
expect(WebCrawlerRequest.find_by(date: d1, user_agent: "Googlebot").count).to eq(4)
|
|
|
|
expect(WebCrawlerRequest.find_by(date: d1, user_agent: "Bingbot").count).to eq(1)
|
2018-03-15 16:10:45 -05:00
|
|
|
end
|
|
|
|
end
|