2015-02-05 00:08:52 -05:00
|
|
|
require "spec_helper"
|
|
|
|
require_dependency "middleware/request_tracker"
|
|
|
|
|
|
|
|
describe Middleware::RequestTracker do
|
|
|
|
|
|
|
|
def env(opts={})
|
|
|
|
{
|
|
|
|
"HTTP_HOST" => "http://test.com",
|
|
|
|
"REQUEST_URI" => "/path?bla=1",
|
|
|
|
"REQUEST_METHOD" => "GET",
|
|
|
|
"rack.input" => ""
|
|
|
|
}.merge(opts)
|
|
|
|
end
|
|
|
|
|
|
|
|
context "log_request" do
|
|
|
|
it "can log requests correctly" do
|
|
|
|
freeze_time Time.now
|
|
|
|
|
|
|
|
ApplicationRequest.clear_cache!
|
|
|
|
|
2015-02-05 22:39:04 -05:00
|
|
|
Middleware::RequestTracker.log_request(["200",{"Content-Type" => 'text/html'}], env(
|
|
|
|
"HTTP_USER_AGENT" => "AdsBot-Google (+http://www.google.com/adsbot.html)"
|
2015-02-05 00:08:52 -05:00
|
|
|
))
|
2015-02-05 22:39:04 -05:00
|
|
|
Middleware::RequestTracker.log_request(["200",{}], env(
|
|
|
|
"HTTP_DISCOURSE_TRACK_VIEW" => "1"
|
2015-02-05 00:08:52 -05:00
|
|
|
))
|
|
|
|
|
|
|
|
ApplicationRequest.write_cache!
|
|
|
|
|
2015-02-05 22:39:04 -05:00
|
|
|
ApplicationRequest.http_total.first.count.should == 2
|
|
|
|
ApplicationRequest.http_2xx.first.count.should == 2
|
2015-02-05 00:08:52 -05:00
|
|
|
|
2015-02-05 22:39:04 -05:00
|
|
|
ApplicationRequest.page_view_anon.first.count.should == 1
|
|
|
|
ApplicationRequest.page_view_crawler.first.count.should == 1
|
2015-02-05 00:08:52 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|