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