Commit dc9b9abe authored by Rajendra Kadam's avatar Rajendra Kadam

Add specs for min/max in utils

parent 17f4f482
......@@ -36,6 +36,7 @@
module Gitlab
module Utils
module UsageData
include Gitlab::Utils::StrongMemoize
extend self
FALLBACK = -1
......@@ -209,17 +210,17 @@ module Gitlab
Gitlab::UsageDataCounters::HLLRedisCounter.track_event(event_name.to_s, values: values)
end
def maximum_id(relation)
key = :"#{relation.name.downcase}_maximum_id"
def maximum_id(model)
key = :"#{model.name.downcase}_maximum_id"
strong_memoize(key) do
relation.maximum(:id)
model.maximum(:id)
end
end
def minimum_id(relation)
key = :"#{relation.name.downcase}_minimum_id"
def minimum_id(model)
key = :"#{model.name.downcase}_minimum_id"
strong_memoize(key) do
relation.minimum(:id)
model.minimum(:id)
end
end
......
......@@ -479,4 +479,22 @@ RSpec.describe Gitlab::Utils::UsageData do
expect { described_class.track_usage_event(unknown_event, value) }.to raise_error(Gitlab::UsageDataCounters::HLLRedisCounter::UnknownEvent)
end
end
describe 'min/max' do
let(:model) { double(:relation) }
it 'returns min from the model' do
allow(model).to receive(:minimum).and_return(2)
allow(model).to receive(:name).and_return('sample_min_model')
expect(described_class.minimum_id(model)).to eq(2)
end
it 'returns max from the model' do
allow(model).to receive(:maximum).and_return(100)
allow(model).to receive(:name).and_return('sample_max_model')
expect(described_class.maximum_id(model)).to eq(100)
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