2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-27 22:27:38 -04:00
|
|
|
RSpec.describe WebCrawlerRequest do
|
2018-03-15 17:10:45 -04:00
|
|
|
before do
|
2022-02-22 11:45:25 -05:00
|
|
|
CachedCounting.reset
|
|
|
|
CachedCounting.enable
|
2018-03-15 17:10:45 -04:00
|
|
|
end
|
|
|
|
|
2022-02-22 11:45:25 -05:00
|
|
|
after { CachedCounting.disable }
|
2018-03-15 17:10:45 -04:00
|
|
|
|
2022-02-22 11:45:25 -05:00
|
|
|
it "can log crawler requests" do
|
|
|
|
freeze_time
|
|
|
|
d1 = Time.now.utc.to_date
|
2018-03-15 17:10:45 -04:00
|
|
|
|
2022-02-22 11:45:25 -05:00
|
|
|
4.times { WebCrawlerRequest.increment!("Googlebot") }
|
2018-03-15 17:10:45 -04:00
|
|
|
|
2022-02-22 11:45:25 -05:00
|
|
|
WebCrawlerRequest.increment!("Bingbot")
|
2018-03-15 17:10:45 -04:00
|
|
|
|
2022-02-22 11:45:25 -05:00
|
|
|
freeze_time 1.day.from_now
|
|
|
|
d2 = Time.now.utc.to_date
|
2018-03-15 17:10:45 -04:00
|
|
|
|
2022-02-22 11:45:25 -05:00
|
|
|
WebCrawlerRequest.increment!("Googlebot")
|
|
|
|
WebCrawlerRequest.increment!("Superbot")
|
2018-03-15 17:10:45 -04:00
|
|
|
|
2022-02-22 11:45:25 -05:00
|
|
|
CachedCounting.flush
|
2018-03-15 17:10:45 -04:00
|
|
|
|
2022-02-22 11:45:25 -05: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 17:10:45 -04:00
|
|
|
|
2022-02-22 11:45:25 -05: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 17:10:45 -04:00
|
|
|
end
|
|
|
|
end
|