2019-04-29 19:27:42 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-27 21:27:38 -05:00
|
|
|
RSpec.shared_examples_for "stats cacheable" do
|
2015-07-06 23:52:19 -05:00
|
|
|
describe "fetch_cached_stats" do
|
2019-12-03 03:05:53 -06:00
|
|
|
after { Discourse.redis.del(described_class.stats_cache_key) }
|
2016-04-21 01:45:16 -05:00
|
|
|
|
2015-07-06 23:52:19 -05:00
|
|
|
it "returns the cached stats" do
|
2016-04-21 01:45:16 -05:00
|
|
|
stats = described_class.fetch_stats.to_json
|
2019-12-03 03:05:53 -06:00
|
|
|
Discourse.redis.set(described_class.stats_cache_key, stats)
|
2016-04-21 01:45:16 -05:00
|
|
|
expect(described_class.fetch_cached_stats).to eq(JSON.parse(stats))
|
2015-07-06 23:52:19 -05:00
|
|
|
end
|
|
|
|
|
2016-04-21 01:45:16 -05:00
|
|
|
it "returns fetches the stats if stats has not been cached" do
|
2017-07-24 08:17:42 -05:00
|
|
|
freeze_time
|
|
|
|
|
2019-12-03 03:05:53 -06:00
|
|
|
Discourse.redis.del(described_class.stats_cache_key)
|
2017-07-24 08:17:42 -05:00
|
|
|
expect(described_class.fetch_cached_stats).to eq(
|
|
|
|
JSON.parse(described_class.fetch_stats.to_json),
|
|
|
|
)
|
2015-07-06 23:52:19 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "fetch_stats" do
|
2016-04-21 01:45:16 -05:00
|
|
|
it "has not been implemented" do
|
2015-07-06 23:52:19 -05:00
|
|
|
expect { described_class.fetch_stats }.to_not raise_error
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|