FEATURE: allow view exclusion using custom header

Set Discourse-Track-View to either "0" or "false" to exclude request
This commit is contained in:
Sam
2015-02-26 11:40:57 +11:00
parent 3e2ba5b30b
commit cbe18eb0df
2 changed files with 29 additions and 3 deletions

View File

@ -13,10 +13,30 @@ describe Middleware::RequestTracker do
end
context "log_request" do
it "can log requests correctly" do
before do
freeze_time Time.now
ApplicationRequest.clear_cache!
end
def log_tracked_view(val)
data = Middleware::RequestTracker.get_data(env(
"HTTP_DISCOURSE_TRACK_VIEW" => val
), ["200",{"Content-Type" => 'text/html'}])
Middleware::RequestTracker.log_request(data)
end
it "can exclude/include based on custom header" do
log_tracked_view("true")
log_tracked_view("1")
log_tracked_view("false")
log_tracked_view("0")
ApplicationRequest.write_cache!
ApplicationRequest.page_view_anon.first.count.should == 2
end
it "can log requests correctly" do
data = Middleware::RequestTracker.get_data(env(
"HTTP_USER_AGENT" => "AdsBot-Google (+http://www.google.com/adsbot.html)"