Commit 8f0e6dfd authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'fix-for-page-limiter-counter' into 'master'

Actually increment the PageLimiter counter

See merge request gitlab-org/gitlab!23778
parents eddb1dac 6bb2573f
...@@ -63,6 +63,6 @@ module PageLimiter ...@@ -63,6 +63,6 @@ module PageLimiter
controller: params[:controller], controller: params[:controller],
action: params[:action], action: params[:action],
bot: dd.bot? bot: dd.bot?
) ).increment
end end
end end
...@@ -71,19 +71,23 @@ describe PageLimiter do ...@@ -71,19 +71,23 @@ describe PageLimiter do
describe "#default_page_out_of_bounds_response" do describe "#default_page_out_of_bounds_response" do
subject { instance.send(:default_page_out_of_bounds_response) } subject { instance.send(:default_page_out_of_bounds_response) }
after do
subject
end
it "returns a bad_request header" do it "returns a bad_request header" do
expect(instance).to receive(:head).with(:bad_request) expect(instance).to receive(:head).with(:bad_request)
subject
end end
end end
describe "#record_page_limit_interception" do describe "#record_page_limit_interception" do
subject { instance.send(:record_page_limit_interception) } subject { instance.send(:record_page_limit_interception) }
it "records a metric counter" do let(:counter) { double("counter", increment: true) }
before do
allow(Gitlab::Metrics).to receive(:counter) { counter }
end
it "creates a metric counter" do
expect(Gitlab::Metrics).to receive(:counter).with( expect(Gitlab::Metrics).to receive(:counter).with(
:gitlab_page_out_of_bounds, :gitlab_page_out_of_bounds,
controller: "explore/projects", controller: "explore/projects",
...@@ -93,5 +97,11 @@ describe PageLimiter do ...@@ -93,5 +97,11 @@ describe PageLimiter do
subject subject
end end
it "increments the counter" do
expect(counter).to receive(:increment)
subject
end
end end
end end
...@@ -90,8 +90,12 @@ describe Explore::ProjectsController do ...@@ -90,8 +90,12 @@ describe Explore::ProjectsController do
end end
describe "metrics recording" do describe "metrics recording" do
after do subject { get endpoint, params: { page: page_limit + 1 } }
get endpoint, params: { page: page_limit + 1 }
let(:counter) { double("counter", increment: true) }
before do
allow(Gitlab::Metrics).to receive(:counter) { counter }
end end
it "records the interception" do it "records the interception" do
...@@ -101,6 +105,8 @@ describe Explore::ProjectsController do ...@@ -101,6 +105,8 @@ describe Explore::ProjectsController do
action: endpoint.to_s, action: endpoint.to_s,
bot: false bot: false
) )
subject
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment