mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Fetch stats if it has not been cached.
This commit is contained in:
@@ -1,10 +1,16 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe Jobs::AboutStats do
|
||||
after do
|
||||
$redis.flushall
|
||||
end
|
||||
|
||||
it 'caches the stats' do
|
||||
stats = { "visited" => 10 }
|
||||
About.any_instance.expects(:stats).returns(stats)
|
||||
$redis.expects(:setex).with(About.stats_cache_key, 35.minutes, stats.to_json)
|
||||
stats = About.fetch_stats.to_json
|
||||
cache_key = About.stats_cache_key
|
||||
|
||||
expect($redis.get(cache_key)).to eq(nil)
|
||||
expect(described_class.new.execute({})).to eq(stats)
|
||||
expect($redis.get(cache_key)).to eq(stats)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,10 +1,18 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe Jobs::DashboardStats do
|
||||
after do
|
||||
$redis.flushall
|
||||
end
|
||||
|
||||
it 'caches the stats' do
|
||||
json = { "visited" => 10 }
|
||||
AdminDashboardData.any_instance.expects(:as_json).returns(json)
|
||||
$redis.expects(:setex).with(AdminDashboardData.stats_cache_key, 35.minutes, json.to_json)
|
||||
expect(described_class.new.execute({})).to eq(json)
|
||||
Timecop.freeze do
|
||||
stats = AdminDashboardData.fetch_stats.to_json
|
||||
cache_key = AdminDashboardData.stats_cache_key
|
||||
|
||||
expect($redis.get(cache_key)).to eq(nil)
|
||||
expect(described_class.new.execute({})).to eq(stats)
|
||||
expect($redis.get(cache_key)).to eq(stats)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user