mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
improve metrics gathered using in our traffic section
this also pulls out the middleware into its own home and inserts in front
This commit is contained in:
@ -16,21 +16,6 @@ describe Middleware::AnonymousCache::Helper do
|
||||
Middleware::AnonymousCache::Helper.new(env(opts))
|
||||
end
|
||||
|
||||
context "log_request" do
|
||||
it "can log requests correctly" do
|
||||
freeze_time Time.now
|
||||
|
||||
ApplicationRequest.clear_cache!
|
||||
|
||||
Middleware::AnonymousCache.log_request(env "HTTP_USER_AGENT" => "AdsBot-Google (+http://www.google.com/adsbot.html)")
|
||||
Middleware::AnonymousCache.log_request(env)
|
||||
|
||||
ApplicationRequest.write_cache!
|
||||
|
||||
ApplicationRequest.crawler.first.count.should == 1
|
||||
ApplicationRequest.anon.first.count.should == 1
|
||||
end
|
||||
end
|
||||
|
||||
context "cachable?" do
|
||||
it "true by default" do
|
||||
|
38
spec/components/middleware/request_tracker_spec.rb
Normal file
38
spec/components/middleware/request_tracker_spec.rb
Normal file
@ -0,0 +1,38 @@
|
||||
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!
|
||||
|
||||
Middleware::RequestTracker.log_request(["200"], env(
|
||||
"HTTP_USER_AGENT" => "AdsBot-Google (+http://www.google.com/adsbot.html)",
|
||||
"action_dispatch.request.path_parameters" => {controller: "topics", action: "show"}
|
||||
))
|
||||
Middleware::RequestTracker.log_request(["200"], env(
|
||||
"action_dispatch.request.path_parameters" => {controller: "topics", action: "show"}
|
||||
))
|
||||
|
||||
ApplicationRequest.write_cache!
|
||||
|
||||
ApplicationRequest.total.first.count.should == 2
|
||||
ApplicationRequest.success.first.count.should == 2
|
||||
|
||||
ApplicationRequest.topic_anon.first.count.should == 1
|
||||
ApplicationRequest.topic_crawler.first.count.should == 1
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user